Code

Merge branch 'js/fetch-progress'
authorJunio C Hamano <junkio@cox.net>
Mon, 9 Apr 2007 06:27:22 +0000 (23:27 -0700)
committerJunio C Hamano <junkio@cox.net>
Mon, 9 Apr 2007 06:27:22 +0000 (23:27 -0700)
* js/fetch-progress:
  git-fetch: add --quiet

231 files changed:
.gitignore
Documentation/.gitignore
Documentation/Makefile
Documentation/RelNotes-1.5.0.4.txt [new file with mode: 0644]
Documentation/RelNotes-1.5.0.5.txt [new file with mode: 0644]
Documentation/RelNotes-1.5.0.6.txt [new file with mode: 0644]
Documentation/RelNotes-1.5.0.7.txt [new file with mode: 0644]
Documentation/RelNotes-1.5.1.1.txt [new file with mode: 0644]
Documentation/RelNotes-1.5.1.txt
Documentation/RelNotes-1.5.2.txt [new file with mode: 0644]
Documentation/asciidoc.conf
Documentation/cmd-list.perl
Documentation/config.txt
Documentation/diff-options.txt
Documentation/git-am.txt
Documentation/git-bisect.txt
Documentation/git-branch.txt
Documentation/git-checkout.txt
Documentation/git-commit.txt
Documentation/git-config.txt
Documentation/git-cvsimport.txt
Documentation/git-cvsserver.txt
Documentation/git-fast-import.txt
Documentation/git-format-patch.txt
Documentation/git-fsck.txt
Documentation/git-log.txt
Documentation/git-mergetool.txt [new file with mode: 0644]
Documentation/git-read-tree.txt
Documentation/git-receive-pack.txt
Documentation/git-rev-list.txt
Documentation/git-rev-parse.txt
Documentation/git-send-email.txt
Documentation/git-svn.txt
Documentation/git-svnimport.txt
Documentation/git.txt
Documentation/glossary.txt
Documentation/howto/use-git-daemon.txt [new file with mode: 0644]
Documentation/install-webdoc.sh
Documentation/sort_glossary.pl [deleted file]
Documentation/technical/pack-format.txt
Documentation/technical/shallow.txt [new file with mode: 0644]
Documentation/user-manual.txt
GIT-VERSION-GEN
Makefile
README
RelNotes
builtin-add.c
builtin-apply.c
builtin-archive.c
builtin-blame.c
builtin-branch.c
builtin-bundle.c
builtin-checkout-index.c
builtin-diff-files.c
builtin-diff-index.c
builtin-diff-tree.c
builtin-diff.c
builtin-fetch--tool.c [new file with mode: 0644]
builtin-fsck.c
builtin-gc.c [new file with mode: 0644]
builtin-grep.c
builtin-log.c
builtin-ls-files.c
builtin-mailinfo.c
builtin-mv.c
builtin-pack-objects.c
builtin-prune.c
builtin-push.c
builtin-read-tree.c
builtin-reflog.c
builtin-rerere.c
builtin-rev-list.c
builtin-revert.c [new file with mode: 0644]
builtin-rm.c
builtin-shortlog.c
builtin-update-index.c
builtin-write-tree.c
builtin.h
cache.h
commit.c
config.c
config.mak.in
configure.ac
connect.c
contrib/continuous/cidaemon [new file with mode: 0644]
contrib/continuous/post-receive-cinotify [new file with mode: 0644]
contrib/emacs/Makefile
contrib/emacs/git-blame.el
contrib/emacs/git.el
contrib/examples/git-gc.sh [new file with mode: 0755]
contrib/hooks/post-receive-email [new file with mode: 0644]
contrib/workdir/git-new-workdir [new file with mode: 0755]
diff-lib.c
diff.c
diff.h
dir.c
dir.h
environment.c
fast-import.c
fetch.c
git-am.sh
git-applymbox.sh
git-bisect.sh
git-checkout.sh
git-clone.sh
git-commit.sh
git-compat-util.h
git-cvsimport.perl
git-cvsserver.perl
git-fetch.sh
git-gc.sh [deleted file]
git-gui/.gitignore
git-gui/CREDITS-GEN [deleted file]
git-gui/Makefile
git-gui/git-gui.sh
git-lost-found.sh
git-merge-ours.sh
git-merge.sh
git-mergetool.sh [new file with mode: 0755]
git-parse-remote.sh
git-quiltimport.sh
git-rebase.sh
git-remote.perl
git-revert.sh [deleted file]
git-send-email.perl
git-svn.perl
git.c
git.spec.in
gitk
gitweb/INSTALL [new file with mode: 0644]
gitweb/gitweb.css
gitweb/gitweb.perl
help.c
http-fetch.c
http-push.c
index-pack.c
list-objects.c
local-fetch.c
lockfile.c
log-tree.c
merge-index.c
merge-recursive.c
merge-tree.c
object.c
pack-check.c
pack-redundant.c
pack.h
perl/Makefile
reachable.c
read-cache.c
receive-pack.c
refs.c
revision.c
revision.h
run-command.c
run-command.h
send-pack.c
setup.c
sha1_file.c
sha1_name.c
t/diff-lib.sh
t/t1000-read-tree-m-3way.sh
t/t1001-read-tree-m-2way.sh
t/t1002-read-tree-m-u-2way.sh
t/t1300-repo-config.sh
t/t3001-ls-files-others-exclude.sh
t/t3002-ls-files-dashpath.sh
t/t3100-ls-tree-restrict.sh
t/t3101-ls-tree-dirname.sh
t/t3200-branch.sh
t/t3300-funny-names.sh
t/t3900-i18n-commit.sh
t/t4006-diff-mode.sh
t/t4013-diff-various.sh
t/t4013/diff.format-patch_--attach_--stdout_initial..master
t/t4013/diff.format-patch_--attach_--stdout_initial..master^
t/t4013/diff.format-patch_--attach_--stdout_initial..side
t/t4013/diff.format-patch_--inline_--stdout_initial..master [new file with mode: 0644]
t/t4013/diff.format-patch_--inline_--stdout_initial..master^ [new file with mode: 0644]
t/t4013/diff.format-patch_--inline_--stdout_initial..side [new file with mode: 0644]
t/t4015-diff-whitespace.sh
t/t4016-diff-quote.sh
t/t4017-diff-retval.sh [new file with mode: 0755]
t/t4017-quiet.sh [new file with mode: 0755]
t/t4100-apply-stat.sh
t/t4104-apply-boundary.sh
t/t4115-apply-symlink.sh
t/t4116-apply-reverse.sh
t/t4117-apply-reject.sh
t/t4118-apply-empty-context.sh
t/t4120-apply-popt.sh [new file with mode: 0755]
t/t4200-rerere.sh
t/t5000-tar-tree.sh
t/t5100-mailinfo.sh
t/t5100/info0007 [new file with mode: 0644]
t/t5100/info0008 [new file with mode: 0644]
t/t5100/msg0007 [new file with mode: 0644]
t/t5100/msg0008 [new file with mode: 0644]
t/t5100/patch0007 [new file with mode: 0644]
t/t5100/patch0008 [new file with mode: 0644]
t/t5100/sample.mbox
t/t5300-pack-object.sh
t/t5400-send-pack.sh
t/t5401-update-hooks.sh
t/t5510-fetch.sh
t/t5515-fetch-merge-logic.sh
t/t5520-pull.sh
t/t6002-rev-list-bisect.sh
t/t6004-rev-list-path-optim.sh
t/t6006-rev-list-format.sh [new file with mode: 0755]
t/t6023-merge-file.sh
t/t6024-recursive-merge.sh
t/t6030-bisect-run.sh [new file with mode: 0755]
t/t6200-fmt-merge-msg.sh
t/t7201-co.sh
t/t9100-git-svn-basic.sh
t/t9300-fast-import.sh
templates/Makefile
templates/hooks--post-receive [new file with mode: 0644]
templates/hooks--update
trace.c
tree-diff.c
tree-walk.c
tree-walk.h
tree.c
unpack-trees.c
unpack-trees.h
upload-pack.c
usage.c
wt-status.c
xdiff/xutils.c

index 0eaba0a278df33fbef7f247ce267181d7ccba5f0..b39f78fcdf18c201d89a4e69fa24a853185e97e5 100644 (file)
@@ -1,4 +1,5 @@
 GIT-CFLAGS
+GIT-GUI-VARS
 GIT-VERSION-FILE
 git
 git-add
@@ -38,6 +39,7 @@ git-diff-tree
 git-describe
 git-fast-import
 git-fetch
+git-fetch--tool
 git-fetch-pack
 git-findtags
 git-fmt-merge-msg
@@ -75,6 +77,7 @@ git-merge-ours
 git-merge-recursive
 git-merge-resolve
 git-merge-stupid
+git-mergetool
 git-mktag
 git-mktree
 git-name-rev
@@ -139,6 +142,7 @@ git-verify-tag
 git-whatchanged
 git-write-tree
 git-core-*/?*
+gitk-wish
 gitweb/gitweb.cgi
 test-chmtime
 test-date
index 6a51331b2fbf991d16dae9d4e486463dfa567311..b98d21e98e008c79d2598c6aa9213826d26f5b0d 100644 (file)
@@ -2,6 +2,7 @@
 *.html
 *.1
 *.7
+*.made
 howto-index.txt
 doc.dep
 cmds-*.txt
index 7c1c9e1918829b90aeb4e47d10aa0f5951204b0c..a637d8d559b6a41505e5381b92d523e55f4b3be8 100644 (file)
@@ -16,8 +16,9 @@ ARTICLES += repository-layout
 ARTICLES += hooks
 ARTICLES += everyday
 ARTICLES += git-tools
+ARTICLES += glossary
 # with their own formatting rules.
-SP_ARTICLES = glossary howto/revert-branch-rebase user-manual
+SP_ARTICLES = howto/revert-branch-rebase user-manual
 
 DOC_HTML += $(patsubst %,%.html,$(ARTICLES) $(SP_ARTICLES))
 
@@ -64,6 +65,11 @@ install: man
        $(INSTALL) -m644 $(DOC_MAN7) $(DESTDIR)$(man7dir)
 
 
+../GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
+       $(MAKE) -C ../ GIT-VERSION-FILE
+
+-include ../GIT-VERSION-FILE
+
 #
 # Determine "include::" file references in asciidoc files.
 #
@@ -84,38 +90,44 @@ cmds_txt = cmds-ancillaryinterrogators.txt \
        cmds-purehelpers.txt \
        cmds-foreignscminterface.txt
 
-$(cmds_txt): cmd-list.perl $(MAN1_TXT)
+$(cmds_txt): cmd-list.made
+
+cmd-list.made: cmd-list.perl $(MAN1_TXT)
        perl ./cmd-list.perl
+       date >$@
 
 git.7 git.html: git.txt core-intro.txt
 
 clean:
-       rm -f *.xml *.html *.1 *.7 howto-index.txt howto/*.html doc.dep
-       rm -f $(cmds_txt)
+       rm -f *.xml *.xml+ *.html *.html+ *.1 *.7 howto-index.txt howto/*.html doc.dep
+       rm -f $(cmds_txt) *.made
 
 %.html : %.txt
-       $(ASCIIDOC) -b xhtml11 -d manpage -f asciidoc.conf $(ASCIIDOC_EXTRA) $<
+       rm -f $@+ $@
+       $(ASCIIDOC) -b xhtml11 -d manpage -f asciidoc.conf \
+               $(ASCIIDOC_EXTRA) -o - $< | \
+               sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' >$@+
+       mv $@+ $@
 
 %.1 %.7 : %.xml
        xmlto -m callouts.xsl man $<
 
 %.xml : %.txt
-       $(ASCIIDOC) -b docbook -d manpage -f asciidoc.conf $<
+       rm -f $@+ $@
+       $(ASCIIDOC) -b docbook -d manpage -f asciidoc.conf \
+               $(ASCIIDOC_EXTRA) -o - $< | \
+               sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' >$@+
+       mv $@+ $@
 
 user-manual.xml: user-manual.txt user-manual.conf
        $(ASCIIDOC) -b docbook -d book $<
 
 XSLT = http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl
-XSLTOPTS = --nonet --xinclude --stringparam html.stylesheet docbook-xsl.css
+XSLTOPTS = --xinclude --stringparam html.stylesheet docbook-xsl.css
 
 user-manual.html: user-manual.xml
        xsltproc $(XSLTOPTS) -o $@ $(XSLT) $<
 
-glossary.html : glossary.txt sort_glossary.pl
-       cat $< | \
-       perl sort_glossary.pl | \
-       $(ASCIIDOC) -b xhtml11 - > glossary.html
-
 howto-index.txt: howto-index.sh $(wildcard howto/*.txt)
        rm -f $@+ $@
        sh ./howto-index.sh $(wildcard howto/*.txt) >$@+
@@ -136,3 +148,5 @@ install-webdoc : html
 
 quick-install:
        sh ./install-doc-quick.sh $(DOC_REF) $(mandir)
+
+.PHONY: .FORCE-GIT-VERSION-FILE
diff --git a/Documentation/RelNotes-1.5.0.4.txt b/Documentation/RelNotes-1.5.0.4.txt
new file mode 100644 (file)
index 0000000..b727a8d
--- /dev/null
@@ -0,0 +1,24 @@
+GIT v1.5.0.4 Release Notes
+==========================
+
+Fixes since v1.5.0.3
+--------------------
+
+* Bugfixes
+
+  - git.el does not add duplicate sign-off lines.
+
+  - git-commit shows the full stat of the resulting commit, not
+    just about the files in the current directory, when run from
+    a subdirectory.
+
+  - "git-checkout -m '@{8 hours ago}'" had a funny failure from
+    eval; fixed.
+
+  - git-gui updates.
+
+* Documentation updates
+
+* User manual updates
+
+
diff --git a/Documentation/RelNotes-1.5.0.5.txt b/Documentation/RelNotes-1.5.0.5.txt
new file mode 100644 (file)
index 0000000..aa86149
--- /dev/null
@@ -0,0 +1,28 @@
+GIT v1.5.0.5 Release Notes
+==========================
+
+Fixes since v1.5.0.3
+--------------------
+
+* Bugfixes
+
+  - git-merge (hence git-pull) did not refuse fast-forwarding
+    when the working tree had local changes that would have
+    conflicted with it.
+
+  - git.el does not add duplicate sign-off lines.
+
+  - git-commit shows the full stat of the resulting commit, not
+    just about the files in the current directory, when run from
+    a subdirectory.
+
+  - "git-checkout -m '@{8 hours ago}'" had a funny failure from
+    eval; fixed.
+
+  - git-gui updates.
+
+* Documentation updates
+
+* User manual updates
+
+
diff --git a/Documentation/RelNotes-1.5.0.6.txt b/Documentation/RelNotes-1.5.0.6.txt
new file mode 100644 (file)
index 0000000..e15447f
--- /dev/null
@@ -0,0 +1,22 @@
+GIT v1.5.0.6 Release Notes
+==========================
+
+Fixes since v1.5.0.5
+--------------------
+
+* Bugfixes
+
+  - a handful small fixes to gitweb.
+
+  - build procedure for user-manual is fixed not to require locally
+    installed stylesheets.
+
+  - "git commit $paths" on paths whose earlier contents were
+    already updated in the index were failing out.
+
+* Documentation
+
+  - user-manual has better cross references.
+
+  - gitweb installation/deployment procedure is now documented.
+
diff --git a/Documentation/RelNotes-1.5.0.7.txt b/Documentation/RelNotes-1.5.0.7.txt
new file mode 100644 (file)
index 0000000..670ad32
--- /dev/null
@@ -0,0 +1,18 @@
+GIT v1.5.0.7 Release Notes
+==========================
+
+Fixes since v1.5.0.6
+--------------------
+
+* Bugfixes
+
+  - git-upload-pack failed to close unused pipe ends, resulting
+    in many zombies to hang around.
+
+  - git-rerere was recording the contents of earlier hunks
+    duplicated in later hunks.  This prevented resolving the same
+    conflict when performing the same merge the other way around.
+
+* Documentation
+
+  - a few documentation fixes from Debian package maintainer.
diff --git a/Documentation/RelNotes-1.5.1.1.txt b/Documentation/RelNotes-1.5.1.1.txt
new file mode 100644 (file)
index 0000000..b48b4bc
--- /dev/null
@@ -0,0 +1,46 @@
+GIT v1.5.1.1 Release Notes (draft)
+==========================
+
+Fixes since v1.5.1
+------------------
+
+* Documentation updates
+
+  - The --left-right option of rev-list and friends is documented.
+
+  - The documentation for cvsimport has been majorly improved.
+
+* Bugfixes
+
+  - "git send-email" produced of References header of unbounded length;
+    fixed this with line-folding.
+
+  - "git archive" to download from remote site should not
+    require you to be in a git repository, but it incorrectly
+    did.
+
+  - "git apply" ignored -p<n> for "diff --git" formatted
+    patches.
+
+  - "git rerere" recorded a conflict that had one side empty
+    (the other side adds) incorrectly; this made merging in the
+    other direction fail to use previously recorded resolution.
+
+  - t4200 test was broken where "wc -l" pads its output with
+    spaces.
+
+  - "git branch -m old new" to rename branch did not work
+    without a configuration file in ".git/config".
+
+  - The sample hook for notification e-mail was misnamed.
+
+  - gitweb did not show type-changing patch correctly in the
+    blobdiff view.
+
+* Performance Tweaks
+
+--
+exec >/var/tmp/1
+O=v1.5.1-26-ge94a4f6
+echo O=`git describe refs/heads/maint`
+git shortlog --no-merges $O..refs/heads/maint
index f374e1c2c75a597c15a9f0bbb2ff2fec6ec190df..daed3672709f6b94478fc6ad425897abe3433c9a 100644 (file)
@@ -10,11 +10,15 @@ Updates since v1.5.0
 
 * New commands and options.
 
-  - "git log" and friends take --reverse.  This makes output
-    that typically goes reverse order in chronological order.
-    "git shortlog" usually lists commits in chronological order,
-    but with "--reverse", they are shown in reverse
-    chronological order.
+  - "git log" and friends take --reverse, which instructs them
+    to give their output in the order opposite from their usual.
+    They typically output from new to old, but with this option
+    their output would read from old to new.  "git shortlog"
+    usually lists older commits first, but with this option,
+    they are shown from new to old.
+
+  - "git log --pretty=format:<string>" to allow more flexible
+    custom log output.
 
   - "git diff" learned --ignore-space-at-eol.  This is a weaker
     form of --ignore-space-change.
@@ -22,8 +26,31 @@ Updates since v1.5.0
   - "git diff --no-index pathA pathB" can be used as diff
     replacement with git specific enhancements.
 
-  - "git diff --pretty=format:<string>" to allow more flexible
-    custom log output.
+  - "git diff --no-index" can read from '-' (standard input).
+
+  - "git diff" also learned --exit-code to exit with non-zero
+    status when it found differences.  In the future we might
+    want to make this the default but that would be a rather big
+    backward incompatible change; it will stay as an option for
+    now.
+
+  - "git diff --quiet" is --exit-code with output turned off,
+    meant for scripted use to quickly determine if there is any
+    tree-level difference.
+
+  - Textual patch generation with "git diff" without -w/-b
+    option has been significantly optimized.  "git blame" got
+    faster because of the same change.
+
+  - "git log" and "git rev-list" has been optimized
+    significantly when they are used with pathspecs.
+
+  - "git branch --track" can be used to set up configuration
+    variables to help it easier to base your work on branches
+    you track from a remote site.
+
+  - "git format-patch --attach" now emits attachments.  Use
+    --inline to get an inlined multipart/mixed.
 
   - "git name-rev" learned --refs=<pattern>, to limit the tags
     used for naming the given revisions only to the ones
@@ -39,12 +66,42 @@ Updates since v1.5.0
   - "git bundle" can help sneaker-netting your changes between
     repositories.
 
+  - "git mergetool" can help 3-way file-level conflict
+    resolution with your favorite graphical merge tools.
+
   - A new configuration "core.symlinks" can be used to disable
     symlinks on filesystems that do not support them; they are
     checked out as regular files instead.
 
+  - You can name a commit object with its first line of the
+    message.  The syntax to use is ':/message text'.  E.g.
+
+    $ git show ":/object name: introduce ':/<oneline prefix>' notation"
+
+    means the same thing as:
 
-* Updated behaviour of existing commands.
+    $ git show 28a4d940443806412effa246ecc7768a21553ec7
+
+  - "git bisect" learned a new command "run" that takes a script
+    to run after each revision is checked out to determine if it
+    is good or bad, to automate the bisection process.
+
+  - "git log" family learned a new traversal option --first-parent,
+    which does what the name suggests.
+
+
+* Updated behavior of existing commands.
+
+  - "git-merge-recursive" used to barf when there are more than
+    one common ancestors for the merge, and merging them had a
+    rename/rename conflict.  This has been fixed.
+
+  - "git fsck" does not barf on corrupt loose objects.
+
+  - "git rm" does not remove newly added files without -f.
+
+  - "git archimport" allows remapping when coming up with git
+    branch names from arch names.
 
   - git-svn got almost a rewrite.
 
@@ -60,10 +117,10 @@ Updates since v1.5.0
     allow users to explicitly override this heuristic based on
     paths.
 
-  - The behaviour of 'git-apply', when run in a subdirectory,
+  - The behavior of 'git-apply', when run in a subdirectory,
     without --index nor --cached were inconsistent with that of
     the command with these options.  This was fixed to match the
-    behaviour with --index.  A patch that is meant to be applied
+    behavior with --index.  A patch that is meant to be applied
     with -p1 from the toplevel of the project tree can be
     applied with any custom -p<n> option.  A patch that is not
     relative to the toplevel needs to be applied with -p<n>
@@ -99,19 +156,216 @@ Updates since v1.5.0
   - "git fetch" (hence "git clone" and "git pull") are less
     noisy when the output does not go to tty.
 
+  - "git fetch" between repositories with many refs were slow
+    even when there are not many changes that needed
+    transferring.  This has been sped up by partially rewriting
+    the heaviest parts in C.
+
+  - "git mailinfo" which splits an e-mail into a patch and the
+    meta-information was rewritten, thanks to Don Zickus.  It
+    handles nested multipart better.  The command was broken for
+    a brief period on 'master' branch since 1.5.0 but the
+    breakage is fixed now.
+
+  - send-email learned configurable bcc and chain-reply-to.
+
+  - "git remote show $remote" also talks about branches that
+    would be pushed if you run "git push remote".
+
+  - Using objects from packs is now seriously optimized by clever
+    use of a cache.  This should be most noticeable in git-log
+    family of commands that involve reading many tree objects.
+    In addition, traversing revisions while filtering changes
+    with pathspecs is made faster by terminating the comparison
+    between the trees as early as possible.
+
+
 * Hooks
 
-  - The sample update hook to show how to send out notification
-    e-mail was updated to show only new commits that appeared in
-    the repository.  Earlier, it showed new commits that appeared
-    on the branch.
+  - The part to send out notification e-mails was removed from
+    the sample update hook, as it was not an appropriate place
+    to do so.  The proper place to do this is the new post-receive
+    hook.  An example hook has been added to contrib/hooks/.
+
+
+* Others
+
+  - git-revert, git-gc and git-cherry-pick are now built-ins.
+
+Fixes since v1.5.0
+------------------
+
+These are all in v1.5.0.x series.
+
+* Documentation updates
+
+  - Clarifications and corrections to 1.5.0 release notes.
+
+  - The main documentation did not link to git-remote documentation.
+
+  - Clarified introductory text of git-rebase documentation.
+
+  - Converted remaining mentions of update-index on Porcelain
+    documents to git-add/git-rm.
+
+  - Some i18n.* configuration variables were incorrectly
+    described as core.*; fixed.
+
+  - added and clarified core.bare, core.legacyheaders configurations.
+
+  - updated "git-clone --depth" documentation.
+
+  - user-manual updates.
+
+  - Options to 'git remote add' were described insufficiently.
+
+  - Configuration format.suffix was not documented.
+
+  - Other formatting and spelling fixes.
+
+  - user-manual has better cross references.
+
+  - gitweb installation/deployment procedure is now documented.
+
+
+* Bugfixes
+
+  - git-upload-pack closes unused pipe ends; earlier this caused
+    many zombies to hang around.
+
+  - git-rerere was recording the contents of earlier hunks
+    duplicated in later hunks.  This prevented resolving the same
+    conflict when performing the same merge the other way around.
+
+  - git-add and git-update-index on a filesystem on which
+    executable bits are unreliable incorrectly reused st_mode
+    bits even when the path changed between symlink and regular
+    file.
+
+  - git-daemon marks the listening sockets with FD_CLOEXEC so
+    that it won't be leaked into the children.
+
+  - segfault from git-blame when the mandatory pathname
+    parameter was missing was fixed; usage() message is given
+    instead.
+
+  - git-rev-list did not read $GIT_DIR/config file, which means
+    that did not honor i18n.logoutputencoding correctly.
+
+  - Automated merge conflict handling when changes to symbolic
+    links conflicted were completely broken.  The merge-resolve
+    strategy created a regular file with conflict markers in it
+    in place of the symbolic link.  The default strategy,
+    merge-recursive was even more broken.  It removed the path
+    that was pointed at by the symbolic link.  Both of these
+    problems have been fixed.
+
+  - 'git diff maint master next' did not correctly give combined
+    diff across three trees.
+
+  - 'git fast-import' portability fix for Solaris.
+
+  - 'git show-ref --verify' without arguments did not error out
+    but segfaulted.
+
+  - 'git diff :tracked-file `pwd`/an-untracked-file' gave an extra
+    slashes after a/ and b/.
+
+  - 'git format-patch' produced too long filenames if the commit
+    message had too long line at the beginning.
+
+  - Running 'make all' and then without changing anything
+    running 'make install' still rebuilt some files.  This
+    was inconvenient when building as yourself and then
+    installing as root (especially problematic when the source
+    directory is on NFS and root is mapped to nobody).
+
+  - 'git-rerere' failed to deal with two unconflicted paths that
+    sorted next to each other.
+
+  - 'git-rerere' attempted to open(2) a symlink and failed if
+    there was a conflict.  Since a conflicting change to a
+    symlink would not benefit from rerere anyway, the command
+    now ignores conflicting changes to symlinks.
+
+  - 'git-repack' did not like to pass more than 64 arguments
+    internally to underlying 'rev-list' logic, which made it
+    impossible to repack after accumulating many (small) packs
+    in the repository.
+
+  - 'git-diff' to review the combined diff during a conflicted
+    merge were not reading the working tree version correctly
+    when changes to a symbolic link conflicted.  It should have
+    read the data using readlink(2) but read from the regular
+    file the symbolic link pointed at.
+
+  - 'git-remote' did not like period in a remote's name.
+
+  - 'git.el' honors the commit coding system from the configuration.
+
+  - 'blameview' in contrib/ correctly digs deeper when a line is
+    clicked.
+
+  - 'http-push' correctly makes sure the remote side has leading
+    path.  Earlier it started in the middle of the path, and
+    incorrectly.
+
+  - 'git-merge' did not exit with non-zero status when the
+    working tree was dirty and cannot fast forward.  It does
+    now.
+
+  - 'cvsexportcommit' does not lose yet-to-be-used message file.
+
+  - int-vs-size_t typefix when running combined diff on files
+    over 2GB long.
+
+  - 'git apply --whitespace=strip' should not touch unmodified
+    lines.
+
+  - 'git-mailinfo' choke when a logical header line was too long.
+
+  - 'git show A..B' did not error out.  Negative ref ("not A" in
+    this example) does not make sense for the purpose of the
+    command, so now it errors out.
+
+  - 'git fmt-merge-msg --file' without file parameter did not
+    correctly error out.
+
+  - 'git archimport' barfed upon encountering a commit without
+    summary.
+
+  - 'git index-pack' did not protect itself from getting a short
+    read out of pread(2).
+
+  - 'git http-push' had a few buffer overruns.
+
+  - Build dependency fixes to rebuild fetch.o when other headers
+    change.
+
+  - git.el does not add duplicate sign-off lines.
+
+  - git-commit shows the full stat of the resulting commit, not
+    just about the files in the current directory, when run from
+    a subdirectory.
+
+  - "git-checkout -m '@{8 hours ago}'" had a funny failure from
+    eval; fixed.
+
+  - git-merge (hence git-pull) did not refuse fast-forwarding
+    when the working tree had local changes that would have
+    conflicted with it.
+
+  - a handful small fixes to gitweb.
+
+  - build procedure for user-manual is fixed not to require locally
+    installed stylesheets.
+
+  - "git commit $paths" on paths whose earlier contents were
+    already updated in the index were failing out.
+
 
---
-exec >/var/tmp/1
-O=v1.5.0.3-268-g3ddad98
-echo O=`git describe master`
-git shortlog --no-merges $O..master ^maint
+* Tweaks
 
-# Local Variables:
-# mode: text
-# End:
+  - sliding mmap() inefficiently mmaped the same region of a
+    packfile with an access pattern that used objects in the
+    reverse order.  This has been made more efficient.
diff --git a/Documentation/RelNotes-1.5.2.txt b/Documentation/RelNotes-1.5.2.txt
new file mode 100644 (file)
index 0000000..2e3c7bc
--- /dev/null
@@ -0,0 +1,76 @@
+GIT v1.5.2 Release Notes (draft)
+========================
+
+Updates since v1.5.1
+--------------------
+
+* New commands and options.
+
+  - "git bisect start" can optionally take a single bad commit and
+    zero or more good commits on the command line.
+
+* Updated behavior of existing commands.
+
+  - "git diff --stat" shows size of preimage and postimage blobs
+    for binary contents.  Earlier it only said "Bin".
+
+  - "git lost-found" shows stuff that are unreachable except
+    from reflogs.
+
+  - "git checkout branch^0" now detaches HEAD at the tip commit
+    on the named branch, instead of just switching to the
+    branch (use "git checkout branch" to switch to the branch,
+    as before).
+
+  - "git bisect next" can be used after giving only a bad commit
+    without giving a good one (this starts bisection half-way to
+    the root commit).  We used to refuse to operate without a
+    good and a bad commit.
+
+* Builds
+
+  - git-p4import has never been installed; now there is an
+    installation option to do so.
+
+  - gitk and git-gui can be configured out.
+
+  - Generated documentation pages automatically get version
+    information from GIT_VERSION
+
+  - Parallel build with "make -j" descending into subdirectory
+    was fixed.
+
+* Performance Tweaks
+
+  - optimized "git-rev-list --bisect" (hence "git-bisect").
+
+  - optimized "git-add $path" in a large directory, most of
+    whose contents are ignored.
+
+
+Fixes since v1.5.1
+------------------
+
+The following are all in v1.5.1.x series, unless otherwise noted.
+
+* Documentation updates
+
+* Bugfixes
+
+  - Switching branches with "git checkout" refused to work when
+    a path changes from a file to a directory between the
+    current branch and the new branch, in order not to lose
+    possible local changes in the directory that is being turned
+    into a file with the switch.  We now allow such a branch
+    switch after making sure that there is no locally modified
+    file nor un-ignored file in the directory.  This has not
+    been backported to 1.5.1.x series, as it is rather an
+    intrusive change.
+
+* Performance Tweaks
+
+--
+exec >/var/tmp/1
+O=v1.5.1-91-g640ee0d
+echo O=`git describe refs/heads/master`
+git shortlog --no-merges $O..refs/heads/master ^refs/heads/maint
index 44b1ce4c6b56348e1661b60fc923cb80cb44d4ff..fa7dc94845be148dd85dfc2265dade2093a6c11f 100644 (file)
@@ -31,6 +31,25 @@ ifdef::backend-docbook[]
 {title#}</example>
 endif::backend-docbook[]
 
+ifdef::doctype-manpage[]
+ifdef::backend-docbook[]
+[header]
+template::[header-declarations]
+<refentry>
+<refmeta>
+<refentrytitle>{mantitle}</refentrytitle>
+<manvolnum>{manvolnum}</manvolnum>
+<refmiscinfo class="source">Git</refmiscinfo>
+<refmiscinfo class="version">@@GIT_VERSION@@</refmiscinfo>
+<refmiscinfo class="manual">Git Manual</refmiscinfo>
+</refmeta>
+<refnamediv>
+  <refname>{manname}</refname>
+  <refpurpose>{manpurpose}</refpurpose>
+</refnamediv>
+endif::backend-docbook[]
+endif::doctype-manpage[]
+
 ifdef::backend-xhtml11[]
 [gitlink-inlinemacro]
 <a href="{target}.html">{target}{0?({0})}</a>
index f61c77aa7c360e12a3e11e9e5dd3ebecfad78d7e..0381590d383c4fffbf04895be4c47e407dd94e80 100755 (executable)
@@ -1,8 +1,11 @@
-#
+#!/usr/bin/perl -w
+
+use File::Compare qw(compare);
 
 sub format_one {
        my ($out, $name) = @_;
        my ($state, $description);
+       $state = 0;
        open I, '<', "$name.txt" or die "No such file $name.txt";
        while (<I>) {
                if (/^NAME$/) {
@@ -55,7 +58,14 @@ for my $cat (qw(ancillaryinterrogators
                format_one(\*O, $_);
        }
        close O;
-       rename "$out+", "$out";
+
+       if (-f "$out" && compare("$out", "$out+") == 0) {
+               unlink "$out+";
+       }
+       else {
+               print STDERR "$out\n";
+               rename "$out+", "$out";
+       }
 }
 
 __DATA__
@@ -124,6 +134,7 @@ git-merge-index                         plumbingmanipulators
 git-merge                               mainporcelain
 git-merge-one-file                      purehelpers
 git-merge-tree                          ancillaryinterrogators
+git-mergetool                           ancillarymanipulators
 git-mktag                               plumbingmanipulators
 git-mktree                              plumbingmanipulators
 git-mv                                  mainporcelain
index 5408dd67d316ce3334f2843267a604f5a4ea044b..cf1e040381a99ed458dc061fe103e3c2d2c9474c 100644 (file)
@@ -240,6 +240,19 @@ the largest projects.  You probably do not need to adjust this value.
 +
 Common unit suffixes of 'k', 'm', or 'g' are supported.
 
+core.deltaBaseCacheLimit::
+       Maximum number of bytes to reserve for caching base objects
+       that multiple deltafied objects reference.  By storing the
+       entire decompressed base objects in a cache Git is able
+       to avoid unpacking and decompressing frequently used base
+       objects multiple times.
++
+Default is 16 MiB on all platforms.  This should be reasonable
+for all users/operating systems, except on the largest projects.
+You probably do not need to adjust this value.
++
+Common unit suffixes of 'k', 'm', or 'g' are supported.
+
 alias.*::
        Command aliases for the gitlink:git[1] command wrapper - e.g.
        after defining "alias.last = cat-file commit HEAD", the invocation
@@ -272,6 +285,10 @@ branch.<name>.merge::
        `git fetch`) to lookup the default branch for merging. Without
        this option, `git pull` defaults to merge the first refspec fetched.
        Specify multiple values to get an octopus merge.
+       If you wish to setup `git pull` so that it merges into <name> from
+       another branch in the local repository, you can point
+       branch.<name>.merge to the desired branch, and use the special setting
+       `.` (a period) for branch.<name>.remote.
 
 color.branch::
        A boolean to enable/disable color in the output of
@@ -453,6 +470,11 @@ merge.summary::
        Whether to include summaries of merged commits in newly created
        merge commit messages. False by default.
 
+merge.tool::
+       Controls which merge resolution program is used by
+       gitlink:git-mergetool[l].  Valid values are: "kdiff3", "tkdiff",
+       "meld", "xxdiff", "emerge", "vimdiff"
+
 merge.verbosity::
        Controls the amount of output shown by the recursive merge
        strategy.  Level 0 outputs nothing except a final error
index d8696b7b36ff81f47214da9d7c4ec53142b97653..1689c748171a8ff48395cf432aabe0130fc6b8d2 100644 (file)
 -w::
        Shorthand for "--ignore-all-space".
 
+--exit-code::
+       Make the program exit with codes similar to diff(1).
+       That is, it exits with 1 if there were differences and
+       0 means no differences.
+
+--quiet::
+       Disable all output of the program. Implies --exit-code.
+
 For more detailed explanation on these common options, see also
 link:diffcore.html[diffcore documentation].
index 4fb1d844133ba8350361ee67d074935805a24156..148ce405681cd4f5bd38575b6a427a7e5745a109 100644 (file)
@@ -70,7 +70,7 @@ default.   You could use `--no-utf8` to override this.
        the patch.
 
 -C<n>, -p<n>::
-       These flag are passed to the `git-apply` program that applies
+       These flags are passed to the `git-apply` program that applies
        the patch.
 
 --interactive::
@@ -87,6 +87,33 @@ default.   You could use `--no-utf8` to override this.
 DISCUSSION
 ----------
 
+The commit author name is taken from the "From: " line of the
+message, and commit author time is taken from the "Date: " line
+of the message.  The "Subject: " line is used as the title of
+the commit, after stripping common prefix "[PATCH <anything>]".
+It is supposed to describe what the commit is about concisely as
+a one line text.
+
+The body of the message (iow, after a blank line that terminates
+RFC2822 headers) can begin with "Subject: " and "From: " lines
+that are different from those of the mail header, to override
+the values of these fields.
+
+The commit message is formed by the title taken from the
+"Subject: ", a blank line and the body of the message up to
+where the patch begins.  Excess whitespaces at the end of the
+lines are automatically stripped.
+
+The patch is expected to be inline, directly following the
+message.  Any line that is of form:
+
+* three-dashes and end-of-line, or
+* a line that begins with "diff -", or
+* a line that begins with "Index: "
+
+is taken as the beginning of a patch, and the commit log message
+is terminated before the first occurrence of such a line.
+
 When initially invoking it, you give it names of the mailboxes
 to crunch.  Upon seeing the first patch that does not apply, it
 aborts in the middle, just like 'git-applymbox' does.  You can
index 16ec7269b29c995fe051f74a37ba9d015d972006..5f68ee1584b294a9395f2a3d4f29e0b1208f5913 100644 (file)
@@ -12,40 +12,44 @@ SYNOPSIS
 
 DESCRIPTION
 -----------
-The command takes various subcommands, and different options
-depending on the subcommand:
+The command takes various subcommands, and different options depending
+on the subcommand:
 
- git bisect start [<paths>...]
+ git bisect start [<bad> [<good>...]] [--] [<paths>...]
  git bisect bad <rev>
  git bisect good <rev>
  git bisect reset [<branch>]
  git bisect visualize
  git bisect replay <logfile>
  git bisect log
+ git bisect run <cmd>...
 
-This command uses 'git-rev-list --bisect' option to help drive
-the binary search process to find which change introduced a bug,
-given an old "good" commit object name and a later "bad" commit
-object name.
+This command uses 'git-rev-list --bisect' option to help drive the
+binary search process to find which change introduced a bug, given an
+old "good" commit object name and a later "bad" commit object name.
+
+Basic bisect commands: start, bad, good
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 The way you use it is:
 
 ------------------------------------------------
 $ git bisect start
-$ git bisect bad                       # Current version is bad
-$ git bisect good v2.6.13-rc2          # v2.6.13-rc2 was the last version
-                                       # tested that was good
+$ git bisect bad                 # Current version is bad
+$ git bisect good v2.6.13-rc2    # v2.6.13-rc2 was the last version
+                                 # tested that was good
 ------------------------------------------------
 
-When you give at least one bad and one good versions, it will
-bisect the revision tree and say something like:
+When you give at least one bad and one good versions, it will bisect
+the revision tree and say something like:
 
 ------------------------------------------------
 Bisecting: 675 revisions left to test after this
 ------------------------------------------------
 
-and check out the state in the middle. Now, compile that kernel, and boot
-it. Now, let's say that this booted kernel works fine, then just do
+and check out the state in the middle. Now, compile that kernel, and
+boot it. Now, let's say that this booted kernel works fine, then just
+do
 
 ------------------------------------------------
 $ git bisect good                      # this one is good
@@ -57,12 +61,15 @@ which will now say
 Bisecting: 337 revisions left to test after this
 ------------------------------------------------
 
-and you continue along, compiling that one, testing it, and depending on
-whether it is good or bad, you say "git bisect good" or "git bisect bad",
-and ask for the next bisection.
+and you continue along, compiling that one, testing it, and depending
+on whether it is good or bad, you say "git bisect good" or "git bisect
+bad", and ask for the next bisection.
+
+Until you have no more left, and you'll have been left with the first
+bad kernel rev in "refs/bisect/bad".
 
-Until you have no more left, and you'll have been left with the first bad
-kernel rev in "refs/bisect/bad".
+Bisect reset
+~~~~~~~~~~~~
 
 Oh, and then after you want to reset to the original head, do a
 
@@ -70,10 +77,13 @@ Oh, and then after you want to reset to the original head, do a
 $ git bisect reset
 ------------------------------------------------
 
-to get back to the master branch, instead of being in one of the bisection
-branches ("git bisect start" will do that for you too, actually: it will
-reset the bisection state, and before it does that it checks that you're
-not using some old bisection branch).
+to get back to the master branch, instead of being in one of the
+bisection branches ("git bisect start" will do that for you too,
+actually: it will reset the bisection state, and before it does that
+it checks that you're not using some old bisection branch).
+
+Bisect visualize
+~~~~~~~~~~~~~~~~
 
 During the bisection process, you can say
 
@@ -83,9 +93,17 @@ $ git bisect visualize
 
 to see the currently remaining suspects in `gitk`.
 
-The good/bad input is logged, and `git bisect
-log` shows what you have done so far.  You can truncate its
-output somewhere and save it in a file, and run
+Bisect log and bisect replay
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The good/bad input is logged, and
+
+------------
+$ git bisect log
+------------
+
+shows what you have done so far. You can truncate its output somewhere
+and save it in a file, and run
 
 ------------
 $ git bisect replay that-file
@@ -94,12 +112,16 @@ $ git bisect replay that-file
 if you find later you made a mistake telling good/bad about a
 revision.
 
-If in a middle of bisect session, you know what the bisect
-suggested to try next is not a good one to test (e.g. the change
-the commit introduces is known not to work in your environment
-and you know it does not have anything to do with the bug you
-are chasing), you may want to find a near-by commit and try that
-instead.  It goes something like this:
+Avoiding to test a commit
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If in a middle of bisect session, you know what the bisect suggested
+to try next is not a good one to test (e.g. the change the commit
+introduces is known not to work in your environment and you know it
+does not have anything to do with the bug you are chasing), you may
+want to find a near-by commit and try that instead.
+
+It goes something like this:
 
 ------------
 $ git bisect good/bad                  # previous round was good/bad.
@@ -109,18 +131,63 @@ $ git reset --hard HEAD~3         # try 3 revs before what
                                        # was suggested
 ------------
 
-Then compile and test the one you chose to try.  After that,
-tell bisect what the result was as usual.
+Then compile and test the one you chose to try. After that, tell
+bisect what the result was as usual.
+
+Cutting down bisection by giving more parameters to bisect start
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You can further cut down the number of trials if you know what part of
+the tree is involved in the problem you are tracking down, by giving
+paths parameters when you say `bisect start`, like this:
+
+------------
+$ git bisect start -- arch/i386 include/asm-i386
+------------
+
+If you know beforehand more than one good commits, you can narrow the
+bisect space down without doing the whole tree checkout every time you
+give good commits. You give the bad revision immediately after `start`
+and then you give all the good revisions you have:
+
+------------
+$ git bisect start v2.6.20-rc6 v2.6.20-rc4 v2.6.20-rc1 --
+                   # v2.6.20-rc6 is bad
+                   # v2.6.20-rc4 and v2.6.20-rc1 are good
+------------
+
+Bisect run
+~~~~~~~~~~
 
-You can further cut down the number of trials if you know what
-part of the tree is involved in the problem you are tracking
-down, by giving paths parameters when you say `bisect start`,
-like this:
+If you have a script that can tell if the current source code is good
+or bad, you can automatically bisect using:
 
 ------------
-$ git bisect start arch/i386 include/asm-i386
+$ git bisect run my_script
 ------------
 
+Note that the "run" script (`my_script` in the above example) should
+exit with code 0 in case the current source code is good and with a
+code between 1 and 127 (included) in case the current source code is
+bad.
+
+Any other exit code will abort the automatic bisect process. (A
+program that does "exit(-1)" leaves $? = 255, see exit(3) manual page,
+the value is chopped with "& 0377".)
+
+You may often find that during bisect you want to have near-constant
+tweaks (e.g., s/#define DEBUG 0/#define DEBUG 1/ in a header file, or
+"revision that does not have this commit needs this patch applied to
+work around other problem this bisection is not interested in")
+applied to the revision being tested.
+
+To cope with such a situation, after the inner git-bisect finds the
+next revision to test, with the "run" script, you can apply that tweak
+before compiling, run the real test, and after the test decides if the
+revision (possibly with the needed tweaks) passed the test, rewind the
+tree to the pristine state.  Finally the "run" script can exit with
+the status of the real test to let "git bisect run" command loop to
+know the outcome.
 
 Author
 ------
index 3ea3b8063520fe2a6f97b767d5f2e2ac05d147d9..603f87f3b59358697da821ffe240be9caff43fa7 100644 (file)
@@ -10,7 +10,7 @@ SYNOPSIS
 [verse]
 'git-branch' [--color | --no-color] [-r | -a]
           [-v [--abbrev=<length> | --no-abbrev]]
-'git-branch' [-l] [-f] <branchname> [<start-point>]
+'git-branch' [--track | --no-track] [-l] [-f] <branchname> [<start-point>]
 'git-branch' (-m | -M) [<oldbranch>] <newbranch>
 'git-branch' (-d | -D) [-r] <branchname>...
 
@@ -26,6 +26,13 @@ It will start out with a head equal to the one given as <start-point>.
 If no <start-point> is given, the branch will be created with a head
 equal to that of the currently checked out branch.
 
+When a local branch is started off a remote branch, git can setup the
+branch so that gitlink:git-pull[1] will appropriately merge from that
+remote branch.  If this behavior is desired, it is possible to make it
+the default using the global `branch.autosetupmerge` configuration
+flag.  Otherwise, it can be chosen per-branch using the `--track`
+and `--no-track` options.
+
 With a '-m' or '-M' option, <oldbranch> will be renamed to <newbranch>.
 If <oldbranch> had a corresponding reflog, it is renamed to match
 <newbranch>, and a reflog entry is created to remember the branch
index 1ae77be45055418b9c784d15db520841dd7bdd7a..f5b2d5017b5710a08c89a7cb150d8ef45527bf99 100644 (file)
@@ -8,7 +8,7 @@ git-checkout - Checkout and switch to a branch
 SYNOPSIS
 --------
 [verse]
-'git-checkout' [-q] [-f] [-b <new_branch> [-l]] [-m] [<branch>]
+'git-checkout' [-q] [-f] [-b [--track | --no-track] <new_branch> [-l]] [-m] [<branch>]
 'git-checkout' [<tree-ish>] <paths>...
 
 DESCRIPTION
@@ -18,7 +18,8 @@ When <paths> are not given, this command switches branches by
 updating the index and working tree to reflect the specified
 branch, <branch>, and updating HEAD to be <branch> or, if
 specified, <new_branch>.  Using -b will cause <new_branch> to
-be created.
+be created; in this case you can use the --track or --no-track
+options, which will be passed to `git branch`.
 
 When <paths> are given, this command does *not* switch
 branches.  It updates the named paths in the working tree from
@@ -45,6 +46,16 @@ OPTIONS
        by gitlink:git-check-ref-format[1].  Some of these checks
        may restrict the characters allowed in a branch name.
 
+--track::
+       When -b is given and a branch is created off a remote branch,
+       setup so that git-pull will automatically retrieve data from
+       the remote branch.
+
+--no-track::
+       When -b is given and a branch is created off a remote branch,
+       force that git-pull will automatically retrieve data from
+       the remote branch independent of the configuration settings.
+
 -l::
        Create the new branch's ref log.  This activates recording of
        all changes to made the branch ref, enabling use of date
index 2187eee4164038346ed7a3ae32f563aeb74f23f7..53a7bb0895036e4d66086b8c656e74588c82c38c 100644 (file)
@@ -8,8 +8,9 @@ git-commit - Record changes to the repository
 SYNOPSIS
 --------
 [verse]
-'git-commit' [-a] [-s] [-v] [(-c | -C) <commit> | -F <file> | -m <msg> |
-           --amend] [--no-verify] [-e] [--author <author>]
+'git-commit' [-a | --interactive] [-s] [-v]
+          [(-c | -C) <commit> | -F <file> | -m <msg> | --amend]
+          [--no-verify] [-e] [--author <author>]
           [--] [[-i | -o ]<file>...]
 
 DESCRIPTION
@@ -35,6 +36,10 @@ methods:
    before, and to automatically "rm" files that have been
    removed from the working tree, and perform the actual commit.
 
+5. by using the --interactive switch with the 'commit' command to decide one
+   by one which files should be part of the commit, before finalizing the
+   operation.  Currently, this is done by invoking `git-add --interactive`.
+
 The gitlink:git-status[1] command can be used to obtain a
 summary of what is included by any of the above for the next
 commit by giving the same set of parameters you would give to
index 68de5881bd36aabd1b4b13c2bce48a226c34788e..c759efb7fc6ebb69d9c6b59e23e31f33e0596675 100644 (file)
@@ -86,7 +86,7 @@ OPTIONS
        Remove the line matching the key from config file.
 
 --unset-all::
-       Remove all matching lines from config file.
+       Remove all lines matching the key from config file.
 
 -l, --list::
        List all variables set in config file.
index 0d59c061394777c9b4655e7096b8ea372971e360..e0be8565468c0b278147abc3e83eb7d19f481a40 100644 (file)
@@ -9,9 +9,11 @@ git-cvsimport - Salvage your data out of another SCM people love to hate
 SYNOPSIS
 --------
 [verse]
-'git-cvsimport' [-o <branch-for-HEAD>] [-h] [-v] [-d <CVSROOT>] [-s <subst>]
-             [-p <options-for-cvsps>] [-C <git_repository>] [-i] [-P <file>]
-             [-m] [-M regex] [<CVS_module>]
+'git-cvsimport' [-o <branch-for-HEAD>] [-h] [-v] [-d <CVSROOT>]
+             [-A <author-conv-file>] [-p <options-for-cvsps>] [-P <file>]
+             [-C <git_repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]
+             [-a] [-m] [-M <regex>] [-S <regex>] [-L <commitlimit>]
+             [<CVS_module>]
 
 
 DESCRIPTION
@@ -30,35 +32,48 @@ any CVS branches, yourself.
 
 OPTIONS
 -------
+-v::
+       Verbosity: let 'cvsimport' report what it is doing.
+
 -d <CVSROOT>::
        The root of the CVS archive. May be local (a simple path) or remote;
        currently, only the :local:, :ext: and :pserver: access methods 
-       are supported.
+       are supported. If not given, git-cvsimport will try to read it
+       from `CVS/Root`. If no such file exists, it checks for the
+       `CVSROOT` environment variable.
+
+<CVS_module>::
+       The CVS module you want to import. Relative to <CVSROOT>.
+       If not given, git-cvsimport tries to read it from
+       `CVS/Repository`.
 
 -C <target-dir>::
         The git repository to import to.  If the directory doesn't
         exist, it will be created.  Default is the current directory.
 
+-o <branch-for-HEAD>::
+       The 'HEAD' branch from CVS is imported to the 'origin' branch within
+       the git repository, as 'HEAD' already has a special meaning for git.
+       Use this option if you want to import into a different branch.
++
+Use '-o master' for continuing an import that was initially done by
+the old cvs2git tool.
+
 -i::
        Import-only: don't perform a checkout after importing.  This option
        ensures the working directory and index remain untouched and will
        not create them if they do not exist.
 
 -k::
-       Kill keywords: will extract files with -kk from the CVS archive
+       Kill keywords: will extract files with '-kk' from the CVS archive
        to avoid noisy changesets. Highly recommended, but off by default
        to preserve compatibility with early imported trees. 
 
 -u::
        Convert underscores in tag and branch names to dots.
 
--o <branch-for-HEAD>::
-       The 'HEAD' branch from CVS is imported to the 'origin' branch within
-       the git repository, as 'HEAD' already has a special meaning for git.
-       Use this option if you want to import into a different branch.
-+
-Use '-o master' for continuing an import that was initially done by
-the old cvs2git tool.
+-s <subst>::
+       Substitute the character "/" in branch names with <subst>
 
 -p <options-for-cvsps>::
        Additional options for cvsps.
@@ -66,6 +81,10 @@ the old cvs2git tool.
 +
 If you need to pass multiple options, separate them with a comma.
 
+-z <fuzz>::
+       Pass the timestamp fuzz factor to cvsps, in seconds. If unset,
+       cvsps defaults to 300s.
+
 -P <cvsps-output-file>::
        Instead of calling cvsps, read the provided cvsps output file. Useful
        for debugging or when cvsps is being handled outside cvsimport.
@@ -77,32 +96,16 @@ If you need to pass multiple options, separate them with a comma.
 
 -M <regex>::
        Attempt to detect merges based on the commit message with a custom
-       regex. It can be used with -m to also see the default regexes. 
+       regex. It can be used with '-m' to also see the default regexes.
        You must escape forward slashes. 
 
--v::
-       Verbosity: let 'cvsimport' report what it is doing.
-
-<CVS_module>::
-       The CVS module you want to import. Relative to <CVSROOT>.
-
--h::
-       Print a short usage message and exit.
-
--z <fuzz>::
-       Pass the timestamp fuzz factor to cvsps, in seconds. If unset,
-       cvsps defaults to 300s.
-
--s <subst>::
-       Substitute the character "/" in branch names with <subst>
+-S <regex>::
+       Skip paths matching the regex.
 
 -a::
        Import all commits, including recent ones. cvsimport by default
        skips commits that have a timestamp less than 10 minutes ago.
 
--S <regex>::
-       Skip paths matching the regex.
-
 -L <limit>::
        Limit the number of commits imported. Workaround for cases where
        cvsimport leaks memory.
@@ -122,14 +125,17 @@ git-cvsimport will make it appear as those authors had
 their GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL set properly
 all along.
 +
-For convenience, this data is saved to $GIT_DIR/cvs-authors
-each time the -A option is provided and read from that same
+For convenience, this data is saved to `$GIT_DIR/cvs-authors`
+each time the '-A' option is provided and read from that same
 file each time git-cvsimport is run.
 +
 It is not recommended to use this feature if you intend to
 export changes back to CVS again later with
 gitlink:git-cvsexportcommit[1].
 
+-h::
+       Print a short usage message and exit.
+
 OUTPUT
 ------
 If '-v' is specified, the script reports what it is doing.
index e328db3797888046802b82954d8946bc8d317075..f9e0c7737952891633a1f5503f8dc5ad46fbf53f 100644 (file)
@@ -110,21 +110,21 @@ To get a checkout with the Eclipse CVS client:
 Protocol notes: If you are using anonymous access via pserver, just select that.
 Those using SSH access should choose the 'ext' protocol, and configure 'ext'
 access on the Preferences->Team->CVS->ExtConnection pane. Set CVS_SERVER to
-'git-cvsserver'. Not that password support is not good when using 'ext',
+'git-cvsserver'. Note that password support is not good when using 'ext',
 you will definitely want to have SSH keys setup.
 
 Alternatively, you can just use the non-standard extssh protocol that Eclipse
 offer. In that case CVS_SERVER is ignored, and you will have to replace
-the cvs utility on the server with git-cvsserver or manipulate your .bashrc
+the cvs utility on the server with git-cvsserver or manipulate your `.bashrc`
 so that calling 'cvs' effectively calls git-cvsserver.
 
 Clients known to work
 ---------------------
 
-CVS 1.12.9 on Debian
-CVS 1.11.17 on MacOSX (from Fink package)
-Eclipse 3.0, 3.1.2 on MacOSX (see Eclipse CVS Client Notes)
-TortoiseCVS
+CVS 1.12.9 on Debian
+CVS 1.11.17 on MacOSX (from Fink package)
+Eclipse 3.0, 3.1.2 on MacOSX (see Eclipse CVS Client Notes)
+TortoiseCVS
 
 Operations supported
 --------------------
@@ -134,9 +134,11 @@ checkout, diff, status, update, log, add, remove, commit.
 Legacy monitoring operations are not supported (edit, watch and related).
 Exports and tagging (tags and branches) are not supported at this stage.
 
-The server will set the -k mode to binary when relevant. In proper GIT
-tradition, the contents of the files are always respected.
-No keyword expansion or newline munging is supported.
+The server should set the '-k' mode to binary when relevant, however,
+this is not really implemented yet. For now, you can force the server
+to set '-kb' for all files by setting the `gitcvs.allbinary` config
+variable. In proper GIT tradition, the contents of the files are
+always respected. No keyword expansion or newline munging is supported.
 
 Dependencies
 ------------
@@ -148,13 +150,16 @@ Copyright and Authors
 
 This program is copyright The Open University UK - 2006.
 
-Authors: Martyn Smith    <martyn@catalyst.net.nz>
-         Martin Langhoff <martin@catalyst.net.nz>
-         with ideas and patches from participants of the git-list <git@vger.kernel.org>.
+Authors:
+
+- Martyn Smith    <martyn@catalyst.net.nz>
+- Martin Langhoff <martin@catalyst.net.nz>
+
+with ideas and patches from participants of the git-list <git@vger.kernel.org>.
 
 Documentation
 --------------
-Documentation by Martyn Smith <martyn@catalyst.net.nz> and Martin Langhoff <martin@catalyst.net.nz> Matthias Urlichs <smurf@smurf.noris.de>.
+Documentation by Martyn Smith <martyn@catalyst.net.nz>, Martin Langhoff <martin@catalyst.net.nz>, and Matthias Urlichs <smurf@smurf.noris.de>.
 
 GIT
 ---
index 7e3d2b1a96a3ef6819a0f3ccebf8f717de9d32dc..eaba6fd4c168564f43ce2db3994dcb7b70bd4b54 100644 (file)
@@ -462,7 +462,7 @@ in octal.  Git only supports the following modes:
 In both formats `<path>` is the complete path of the file to be added
 (if not already existing) or modified (if already existing).
 
-A `<path>` string must use UNIX-style directory seperators (forward
+A `<path>` string must use UNIX-style directory separators (forward
 slash `/`), may contain any byte other than `LF`, and must not
 start with double quote (`"`).
 
@@ -472,8 +472,8 @@ quoting should be used, e.g. `"path/with\n and \" in it"`.
 The value of `<path>` must be in canoncial form. That is it must not:
 
 * contain an empty directory component (e.g. `foo//bar` is invalid),
-* end with a directory seperator (e.g. `foo/` is invalid),
-* start with a directory seperator (e.g. `/foo` is invalid),
+* end with a directory separator (e.g. `foo/` is invalid),
+* start with a directory separator (e.g. `/foo` is invalid),
 * contain the special component `.` or `..` (e.g. `foo/./bar` and
   `foo/../bar` are invalid).
 
index 84eabebe0bc767112805d2d35c68ad000d8e1003..111d7c60bf1832bbfc27f8b819da77b8761236da 100644 (file)
@@ -9,8 +9,9 @@ git-format-patch - Prepare patches for e-mail submission
 SYNOPSIS
 --------
 [verse]
-'git-format-patch' [<common diff options>] [-n | -k] [-o <dir> | --stdout]
-                  [--attach] [--thread] [-s | --signoff] [--start-number <n>]
+'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]
+                  [--attach[=<boundary>] | --inline[=<boundary>]]
+                  [-s | --signoff] [<common diff options>] [--start-number <n>]
                   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
                   [--ignore-if-in-upstream]
                   <since>[..<until>]
@@ -70,8 +71,15 @@ include::diff-options.txt[]
        Print all commits to the standard output in mbox format,
        instead of creating a file for each one.
 
---attach::
-       Create attachments instead of inlining patches.
+--attach[=<boundary>]::
+       Create multipart/mixed attachment, the first part of
+       which is the commit message and the patch itself in the
+       second part, with "Content-Disposition: attachment".
+
+--inline[=<boundary>]::
+       Create multipart/mixed attachment, the first part of
+       which is the commit message and the patch itself in the
+       second part, with "Content-Disposition: inline".
 
 --thread::
        Add In-Reply-To and References headers to make the second and
index 058009d2fab4c73edcbfefe7b48c5f9348459da3..8c68cf037259b3abc7ea16952d232b2fb2f07a25 100644 (file)
@@ -9,7 +9,7 @@ git-fsck - Verifies the connectivity and validity of the objects in the database
 SYNOPSIS
 --------
 [verse]
-'git-fsck' [--tags] [--root] [--unreachable] [--cache]
+'git-fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
                 [--full] [--strict] [<object>*]
 
 DESCRIPTION
@@ -38,6 +38,12 @@ index file and all SHA1 references in .git/refs/* as heads.
        Consider any object recorded in the index also as a head node for
        an unreachability trace.
 
+--no-reflogs::
+       Do not consider commits that are referenced only by an
+       entry in a reflog to be reachable.  This option is meant
+       only to search for commits that used to be in a ref, but
+       now aren't, but are still in that corresponding reflog.
+
 --full::
        Check not just objects in GIT_OBJECT_DIRECTORY
        ($GIT_DIR/objects), but also the ones found in alternate
index 361eaec700bf6401f89c7e631f53414a399affe6..030edaf305a620935840b3ffdcc0ca546d4e43da 100644 (file)
@@ -38,6 +38,11 @@ include::pretty-formats.txt[]
        and <until>, see "SPECIFYING REVISIONS" section in
        gitlink:git-rev-parse[1].
 
+--first-parent::
+       Follow only the first parent commit upon seeing a merge
+       commit.  This  option gives a better overview of the
+       evolution of a particular branch.
+
 -p::
        Show the change the commit introduces in a patch form.
 
diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt
new file mode 100644 (file)
index 0000000..34288fe
--- /dev/null
@@ -0,0 +1,46 @@
+git-mergetool(1)
+================
+
+NAME
+----
+git-mergetool - Run merge conflict resolution tools to resolve merge conflicts
+
+SYNOPSIS
+--------
+'git-mergetool' [--tool=<tool>] [<file>]...
+
+DESCRIPTION
+-----------
+
+Use 'git mergetool' to run one of several merge utilities to resolve
+merge conflicts.  It is typically run after gitlink:git-merge[1].
+
+If one or more <file> parameters are given, the merge tool program will
+be run to resolve differences on each file.  If no <file> names are
+specified, 'git mergetool' will run the merge tool program on every file
+with merge conflicts.
+
+OPTIONS
+-------
+-t or --tool=<tool>::
+       Use the merge resolution program specified by <tool>.
+       Valid merge tools are:
+       kdiff3, tkdiff, meld, xxdiff, emerge, and vimdiff.
++
+If a merge resolution program is not specified, 'git mergetool'
+will use the configuration variable merge.tool.  If the
+configuration variable merge.tool is not set, 'git mergetool'
+will pick a suitable default.
+
+Author
+------
+Written by Theodore Y Ts'o <tytso@mit.edu>
+
+Documentation
+--------------
+Documentation by Theodore Y Ts'o.
+
+GIT
+---
+Part of the gitlink:git[7] suite
+
index 0ff2890c7fb76155e08eaf9e361bf1eb6cf50f25..019c8bef7af2868af150b4a13472b8ce26744ea3 100644 (file)
@@ -8,7 +8,7 @@ git-read-tree - Reads tree information into the index
 
 SYNOPSIS
 --------
-'git-read-tree' (<tree-ish> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] <tree-ish1> [<tree-ish2> [<tree-ish3>]])
+'git-read-tree' (<tree-ish> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <tree-ish1> [<tree-ish2> [<tree-ish3>]])
 
 
 DESCRIPTION
@@ -86,6 +86,18 @@ OPTIONS
        file (usually '.gitignore') and allows such an untracked
        but explicitly ignored file to be overwritten.
 
+--index-output=<file>::
+       Instead of writing the results out to `$GIT_INDEX_FILE`,
+       write the resulting index in the named file.  While the
+       command is operating, the original index file is locked
+       with the same mechanism as usual.  The file must allow
+       to be rename(2)ed into from a temporary file that is
+       created next to the usual index file; typically this
+       means it needs to be on the same filesystem as the index
+       file itself, and you need write permission to the
+       directories the index file and index output file are
+       located in.
+
 <tree-ish#>::
        The id of the tree object(s) to be read/merged.
 
index 3cf55111cc6ecf354b79dd1d2312a5a7b1f188db..6914aa59c3ae6b8174e865e3c46b68bef4d375ca 100644 (file)
@@ -40,13 +40,13 @@ OPTIONS
 pre-receive Hook
 ----------------
 Before any ref is updated, if $GIT_DIR/hooks/pre-receive file exists
-and is executable, it will be invoked once, with three parameters
-per ref to be updated:
+and is executable, it will be invoked once with no parameters.  The
+standard input of the hook will be one line per ref to be updated:
 
-       $GIT_DIR/hooks/pre-receive (refname sha1-old sha1-new)+
+       sha1-old SP sha1-new SP refname LF
 
-The refname parameter is relative to $GIT_DIR; e.g. for the master
-head this is "refs/heads/master".  The two sha1 arguments after
+The refname value is relative to $GIT_DIR; e.g. for the master
+head this is "refs/heads/master".  The two sha1 values before
 each refname are the object names for the refname before and after
 the update.  Refs to be created will have sha1-old equal to 0{40},
 while refs to be deleted will have sha1-new equal to 0{40}, otherwise
@@ -86,13 +86,14 @@ post-receive Hook
 -----------------
 After all refs were updated (or attempted to be updated), if any
 ref update was successful, and if $GIT_DIR/hooks/post-receive
-file exists and is executable, it will be invoke once with three
-parameters for each successfully updated ref:
+file exists and is executable, it will be invoke once with no
+parameters.  The standard input of the hook will be one line
+for each successfully updated ref:
 
-       $GIT_DIR/hooks/post-receive (refname sha1-old sha1-new)+
+       sha1-old SP sha1-new SP refname LF
 
-The refname parameter is relative to $GIT_DIR; e.g. for the master
-head this is "refs/heads/master".  The two sha1 arguments after
+The refname value is relative to $GIT_DIR; e.g. for the master
+head this is "refs/heads/master".  The two sha1 values before
 each refname are the object names for the refname before and after
 the update.  Refs that were created will have sha1-old equal to
 0{40}, while refs that were deleted will have sha1-new equal to
@@ -105,18 +106,17 @@ ref listing the commits pushed to the repository:
 
        #!/bin/sh
        # mail out commit update information.
-       while test $# -gt 0
+       while read oval nval ref
        do
-               if expr "$2" : '0*$' >/dev/null
+               if expr "$oval" : '0*$' >/dev/null
                then
                        echo "Created a new ref, with the following commits:"
-                       git-rev-list --pretty "$2"
+                       git-rev-list --pretty "$nval"
                else
                        echo "New commits:"
-                       git-rev-list --pretty "$3" "^$2"
+                       git-rev-list --pretty "$nval" "^$oval"
                fi |
-               mail -s "Changes to ref $1" commit-list@mydomain
-               shift; shift; shift; # discard this ref's args
+               mail -s "Changes to ref $ref" commit-list@mydomain
        done
        exit 0
 
index 4f145eaba47175e48dd592ffe5018be5cb4cb375..12b71ed0bbae2516cb67c98c96a56e6278a6f5c2 100644 (file)
@@ -21,11 +21,13 @@ SYNOPSIS
             [ \--stdin ]
             [ \--topo-order ]
             [ \--parents ]
+            [ \--left-right ]
             [ \--encoding[=<encoding>] ]
             [ \--(author|committer|grep)=<pattern> ]
             [ [\--objects | \--objects-edge] [ \--unpacked ] ]
             [ \--pretty | \--header ]
             [ \--bisect ]
+            [ \--bisect-vars ]
             [ \--merge ]
             [ \--reverse ]
             [ \--walk-reflogs ]
@@ -100,6 +102,36 @@ include::pretty-formats.txt[]
 
        Print the parents of the commit.
 
+--left-right::
+
+       Mark which side of a symmetric diff a commit is reachable from.
+       Commits from the left side are prefixed with `<` and those from
+       the right with `>`.  If combined with `--boundary`, those
+       commits are prefixed with `-`.
++
+For example, if you have this topology:
++
+-----------------------------------------------------------------------
+             y---b---b  branch B
+            / \ /
+           /   .
+          /   / \
+         o---x---a---a  branch A
+-----------------------------------------------------------------------
++
+you would get an output line this:
++
+-----------------------------------------------------------------------
+       $ git rev-list --left-right --boundary --pretty=oneline A...B
+
+       >bbbbbbb... 3rd on b
+       >bbbbbbb... 2nd on b
+       <aaaaaaa... 3rd on a
+       <aaaaaaa... 2nd on a
+       -yyyyyyy... 1st on b
+       -xxxxxxx... 1st on a
+-----------------------------------------------------------------------
+
 Diff Formatting
 ~~~~~~~~~~~~~~~
 
@@ -249,6 +281,18 @@ introduces a regression is thus reduced to a binary search: repeatedly
 generate and test new 'midpoint's until the commit chain is of length
 one.
 
+--bisect-vars::
+
+This calculates the same as `--bisect`, but outputs text ready
+to be eval'ed by the shell. These lines will assign the name of
+the midpoint revision to the variable `bisect_rev`, and the
+expected number of commits to be tested after `bisect_rev` is
+tested to `bisect_nr`, the expected number of commits to be
+tested if `bisect_rev` turns out to be good to `bisect_good`,
+the expected number of commits to be tested if `bisect_rev`
+turns out to be bad to `bisect_bad`, and the number of commits
+we are bisecting right now to `bisect_all`.
+
 --
 
 Commit Ordering
index ccc66aae7f11bafb6a56e102081020d73b5e4db7..a8bf6561e1d8059f12d1a548cf74dc4815e6a34f 100644 (file)
@@ -265,14 +265,14 @@ its all parents.
 
 Here are a handful examples:
 
-   D                A B D
-   D F              A B C D F
-   ^A G             B D
-   ^A F             B C F
-   G...I            C D F G I
-   ^B G I           C D F G I
-   F^@              A B C
-   F^! H            D F H
+   D                G H D
+   D F              G H I J D F
+   ^G D             H D
+   ^D B             E I J F B
+   B...C            G H D E B C
+   ^D B C           E I J F B C
+   C^@              I J F
+   F^! D            G H D F
 
 Author
 ------
index 35b0104e4acbe614fb274c1ee36d6a4ab2ea5849..682313e95dc9b96d3cc14f33554ad82bcede9a56 100644 (file)
@@ -40,7 +40,8 @@ The --cc option must be repeated for each user you want on the cc list.
        the first will be sent as replies to the first email sent.  When using
        this, it is recommended that the first file given be an overview of the
        entire patch series.
-       Default is --chain-reply-to
+       Default is the value of the 'sendemail.chainreplyto' configuration
+       value; if that is unspecified, default to --chain-reply-to.
 
 --compose::
        Use $EDITOR to edit an introductory message for the
@@ -59,7 +60,8 @@ The --cc option must be repeated for each user you want on the cc list.
        is not set, this will be prompted for.
 
 --no-signed-off-by-cc::
-       Do not add emails found in Signed-off-by: lines to the cc list.
+       Do not add emails found in Signed-off-by: or Cc: lines to the
+       cc list.
 
 --quiet::
        Make git-send-email less verbose.  One line per email should be
@@ -91,6 +93,26 @@ The --cc option must be repeated for each user you want on the cc list.
 The --to option must be repeated for each user you want on the to list.
 
 
+CONFIGURATION
+-------------
+sendemail.aliasesfile::
+       To avoid typing long email addresses, point this to one or more
+       email aliases files.  You must also supply 'sendemail.aliasfiletype'.
+
+sendemail.aliasfiletype::
+       Format of the file(s) specified in sendemail.aliasesfile. Must be
+       one of 'mutt', 'mailrc', 'pine', or 'gnus'.
+
+sendemail.bcc::
+       Email address (or alias) to always bcc.
+
+sendemail.chainreplyto::
+       Boolean value specifying the default to the '--chain_reply_to'
+       parameter.
+
+sendemail.smtpserver::
+       Default smtp server to use.
+
 Author
 ------
 Written by Ryan Anderson <ryan@michonline.com>
index 9b5a3d61966eaa8d24b5ee507f2e1be770a1c367..a0d34e0058d721e655fd23c36415aaaecfa0c666 100644 (file)
@@ -104,6 +104,14 @@ accepts.  However '--fetch-all' only fetches from the current
 
 Like 'git-rebase'; this requires that the working tree be clean
 and have no uncommitted changes.
++
+--
+-l;;
+--local;;
+       Do not fetch remotely; only run 'git-rebase' against the
+       last fetched commit from the upstream SVN.
+--
++
 
 'dcommit'::
        Commit each diff from a specified head directly to the SVN
index b166cf3327380a8f386825a7fbce92f2447bb54e..bdae7d87dce5d07d0d31b45f127fa43a239a6632 100644 (file)
@@ -27,7 +27,7 @@ repository, or incrementally import into an existing one.
 SVN access is done by the SVN::Perl module.
 
 git-svnimport assumes that SVN repositories are organized into one
-"trunk" directory where the main development happens, "branch/FOO"
+"trunk" directory where the main development happens, "branches/FOO"
 directories for branches, and "/tags/FOO" directories for tags.
 Other subdirectories are ignored.
 
index e875e8318d24fa046c7cddfc3e583b4c242d9302..9defc332736e1b6297ac003e491706d5ce32e834 100644 (file)
@@ -35,15 +35,23 @@ ifdef::stalenotes[]
 You are reading the documentation for the latest version of git.
 Documentation for older releases are available here:
 
-* link:v1.5.0.3/git.html[documentation for release 1.5.0.3]
+* link:RelNotes-1.5.1.txt[release notes for 1.5.1]
 
-* link:v1.5.0.3/RelNotes-1.5.0.3.txt[release notes for 1.5.0.3]
+* link:v1.5.0.7/git.html[documentation for release 1.5.0.7]
 
-* link:v1.5.0.2/RelNotes-1.5.0.2.txt[release notes for 1.5.0.2]
+* link:RelNotes-1.5.0.7.txt[release notes for 1.5.0.7]
 
-* link:v1.5.0.1/RelNotes-1.5.0.1.txt[release notes for 1.5.0.1]
+* link:RelNotes-1.5.0.6.txt[release notes for 1.5.0.6]
 
-* link:v1.5.0/RelNotes-1.5.0.txt[release notes for 1.5.0]
+* link:RelNotes-1.5.0.5.txt[release notes for 1.5.0.5]
+
+* link:RelNotes-1.5.0.3.txt[release notes for 1.5.0.3]
+
+* link:RelNotes-1.5.0.2.txt[release notes for 1.5.0.2]
+
+* link:RelNotes-1.5.0.1.txt[release notes for 1.5.0.1]
+
+* link:RelNotes-1.5.0.txt[release notes for 1.5.0]
 
 * link:v1.4.4.4/git.html[documentation for release 1.4.4.4]
 
index 9f446241e2dabee4b93f5c1625351f2260e73717..2465514e461a4a6c4e61f04ced18d6229eae0f51 100644 (file)
-alternate object database::
-       Via the alternates mechanism, a repository can inherit part of its
-       object database from another object database, which is called
-       "alternate".
-
-bare repository::
-       A bare repository is normally an appropriately named
-       directory with a `.git` suffix that does not have a
-       locally checked-out copy of any of the files under revision
-       control.  That is, all of the `git` administrative and
-       control files that would normally be present in the
-       hidden `.git` sub-directory are directly present in
-       the `repository.git` directory instead, and no other files
-       are present and checked out.  Usually publishers of public
-       repositories make bare repositories available.
-
-blob object::
-       Untyped object, e.g. the contents of a file.
-
-branch::
-       A non-cyclical graph of revisions, i.e. the complete history of
-       a particular revision, which is called the branch head. The
-       branch heads are stored in `$GIT_DIR/refs/heads/`.
-
-cache::
-       Obsolete for: index.
-
-chain::
-       A list of objects, where each object in the list contains a
-       reference to its successor (for example, the successor of a commit
-       could be one of its parents).
-
-changeset::
-       BitKeeper/cvsps speak for "commit". Since git does not store
-       changes, but states, it really does not make sense to use
-       the term "changesets" with git.
-
-checkout::
-       The action of updating the working tree to a revision which was
-       stored in the object database.
-
-cherry-picking::
-       In SCM jargon, "cherry pick" means to choose a subset of
-       changes out of a series of changes (typically commits)
-       and record them as a new series of changes on top of
-       different codebase.  In GIT, this is performed by
-       "git cherry-pick" command to extract the change
-       introduced by an existing commit and to record it based
-       on the tip of the current branch as a new commit.
-
-clean::
-       A working tree is clean, if it corresponds to the revision
-       referenced by the current head.  Also see "dirty".
-
-commit::
-       As a verb: The action of storing the current state of the index in the
-       object database. The result is a revision.
-       As a noun: Short hand for commit object.
-
-commit object::
-       An object which contains the information about a particular
-       revision, such as parents, committer, author, date and the
-       tree object which corresponds to the top directory of the
-       stored revision.
-
-core git::
-       Fundamental data structures and utilities of git. Exposes only
-       limited source code management tools.
-
-DAG::
-       Directed acyclic graph. The commit objects form a directed acyclic
-       graph, because they have parents (directed), and the graph of commit
-       objects is acyclic (there is no chain which begins and ends with the
-       same object).
-
-dangling object::
-       An unreachable object which is not reachable even from other
-       unreachable objects; a dangling object has no references to it
-       from any reference or object in the repository.
-
-dircache::
+GIT Glossary
+============
+
+[[def_alternate_object_database]]alternate object database::
+       Via the alternates mechanism, a <<def_repository,repository>> can
+       inherit part of its <<def_object_database,object database>> from another
+       <<def_object_database,object database>>, which is called "alternate".
+
+[[def_bare_repository]]bare repository::
+       A <<def_bare_repository,bare repository>> is normally an appropriately
+       named <<def_directory,directory>> with a `.git` suffix that does not
+       have a locally checked-out copy of any of the files under
+       <<def_revision,revision>> control. That is, all of the `git`
+       administrative and control files that would normally be present in the
+       hidden `.git` sub-directory are directly present in the
+       `repository.git` directory instead,
+       and no other files are present and checked out. Usually publishers of
+       public repositories make bare repositories available.
+
+[[def_blob_object]]blob object::
+       Untyped <<def_object,object>>, e.g. the contents of a file.
+
+[[def_branch]]branch::
+       A non-cyclical graph of revisions, i.e. the complete history of a
+       particular <<def_revision,revision>>, which is called the
+       branch <<def_head,head>>. The heads
+       are stored in `$GIT_DIR/refs/heads/`.
+
+[[def_cache]]cache::
+       Obsolete for: <<def_index,index>>.
+
+[[def_chain]]chain::
+       A list of objects, where each <<def_object,object>> in the list contains
+       a reference to its successor (for example, the successor of a
+       <<def_commit,commit>> could be one of its parents).
+
+[[def_changeset]]changeset::
+       BitKeeper/cvsps speak for "<<def_commit,commit>>". Since git does not
+       store changes, but states, it really does not make sense to use the term
+       "changesets" with git.
+
+[[def_checkout]]checkout::
+       The action of updating the <<def_working_tree,working tree>> to a
+       <<def_revision,revision>> which was stored in the
+       <<def_object_database,object database>>.
+
+[[def_cherry-picking]]cherry-picking::
+       In <<def_SCM,SCM>> jargon, "cherry pick" means to choose a subset of
+       changes out of a series of changes (typically commits) and record them
+       as a new series of changes on top of different codebase. In GIT, this is
+       performed by "git cherry-pick" command to extract the change introduced
+       by an existing <<def_commit,commit>> and to record it based on the tip
+       of the current <<def_branch,branch>> as a new <<def_commit,commit>>.
+
+[[def_clean]]clean::
+       A <<def_working_tree,working tree>> is <<def_clean,clean>>, if it
+       corresponds to the <<def_revision,revision>> referenced by the current
+       <<def_head,head>>. Also see "<<def_dirty,dirty>>".
+
+[[def_commit]]commit::
+       As a verb: The action of storing the current state of the
+       <<def_index,index>> in the <<def_object_database,object database>>. The
+       result is a <<def_revision,revision>>. As a noun: Short hand for
+       <<def_commit_object,commit object>>.
+
+[[def_commit_object]]commit object::
+       An <<def_object,object>> which contains the information about a
+       particular <<def_revision,revision>>, such as parents, committer,
+       author, date and the <<def_tree_object,tree object>> which corresponds
+       to the top <<def_directory,directory>> of the stored
+       <<def_revision,revision>>.
+
+[[def_core_git]]core git::
+       Fundamental data structures and utilities of git. Exposes only limited
+       source code management tools.
+
+[[def_DAG]]DAG::
+       Directed acyclic graph. The <<def_commit,commit>> objects form a
+       directed acyclic graph, because they have parents (directed), and the
+       graph of <<def_commit,commit>> objects is acyclic (there is no
+       <<def_chain,chain>> which begins and ends with the same
+       <<def_object,object>>).
+
+[[def_dangling_object]]dangling object::
+       An <<def_unreachable_object,unreachable object>> which is not
+       <<def_reachable,reachable>> even from other unreachable objects; a
+       <<def_dangling_object,dangling object>> has no references to it from any
+       reference or <<def_object,object>> in the <<def_repository,repository>>.
+
+[[def_dircache]]dircache::
        You are *waaaaay* behind.
 
-dirty::
-       A working tree is said to be dirty if it contains modifications
-       which have not been committed to the current branch.
-
-directory::
+[[def_directory]]directory::
        The list you get with "ls" :-)
 
-ent::
-       Favorite synonym to "tree-ish" by some total geeks. See
+[[def_dirty]]dirty::
+       A <<def_working_tree,working tree>> is said to be <<def_dirty,dirty>> if
+       it contains modifications which have not been committed to the current
+       <<def_branch,branch>>.
+
+[[def_ent]]ent::
+       Favorite synonym to "<<def_tree-ish,tree-ish>>" by some total geeks. See
        `http://en.wikipedia.org/wiki/Ent_(Middle-earth)` for an in-depth
-       explanation.  Avoid this term, not to confuse people.
-
-fast forward::
-       A fast-forward is a special type of merge where you have
-       a revision and you are "merging" another branch's changes
-       that happen to be a descendant of what you have.
-       In such these cases, you do not make a new merge commit but
-       instead just update to his revision. This will happen
-       frequently on a tracking branch of a remote repository.
-
-fetch::
-       Fetching a branch means to get the branch's head ref from a
-       remote repository, to find out which objects are missing from
-       the local object database, and to get them, too.
-
-file system::
-       Linus Torvalds originally designed git to be a user space file
-       system, i.e. the infrastructure to hold files and directories.
-       That ensured the efficiency and speed of git.
-
-git archive::
-       Synonym for repository (for arch people).
-
-grafts::
-       Grafts enables two otherwise different lines of development to be
-       joined together by recording fake ancestry information for commits.
-       This way you can make git pretend the set of parents a commit
-       has is different from what was recorded when the commit was created.
-       Configured via the `.git/info/grafts` file.
-
-hash::
-       In git's context, synonym to object name.
-
-head::
-       The top of a branch. It contains a ref to the corresponding
-       commit object.
-
-head ref::
-       A ref pointing to a head. Often, this is abbreviated to "head".
-       Head refs are stored in `$GIT_DIR/refs/heads/`.
-
-hook::
-       During the normal execution of several git commands,
-       call-outs are made to optional scripts that allow
-       a developer to add functionality or checking.
-       Typically, the hooks allow for a command to be pre-verified
-       and potentially aborted, and allow for a post-notification
-       after the operation is done.
-       The hook scripts are found in the `$GIT_DIR/hooks/` directory,
-       and are enabled by simply making them executable.
-
-index::
-       A collection of files with stat information, whose contents are
-       stored as objects. The index is a stored version of your working
-       tree. Truth be told, it can also contain a second, and even a third
-       version of a working tree, which are used when merging.
-
-index entry::
-       The information regarding a particular file, stored in the index.
-       An index entry can be unmerged, if a merge was started, but not
-       yet finished (i.e. if the index contains multiple versions of
-       that file).
-
-master::
-       The default development branch. Whenever you create a git
-       repository, a branch named "master" is created, and becomes
-       the active branch. In most cases, this contains the local
+       explanation. Avoid this term, not to confuse people.
+
+[[def_fast_forward]]fast forward::
+       A fast-forward is a special type of <<def_merge,merge>> where you have a
+       <<def_revision,revision>> and you are "merging" another
+       <<def_branch,branch>>'s changes that happen to be a descendant of what
+       you have. In such these cases, you do not make a new <<def_merge,merge>>
+       <<def_commit,commit>> but instead just update to his
+       <<def_revision,revision>>. This will happen frequently on a
+       <<def_tracking_branch,tracking branch>> of a remote
+       <<def_repository,repository>>.
+
+[[def_fetch]]fetch::
+       Fetching a <<def_branch,branch>> means to get the
+       <<def_branch,branch>>'s <<def_head_ref,head ref>> from a remote
+       <<def_repository,repository>>, to find out which objects are missing
+       from the local <<def_object_database,object database>>, and to get them,
+       too.
+
+[[def_file_system]]file system::
+       Linus Torvalds originally designed git to be a user space file system,
+       i.e. the infrastructure to hold files and directories. That ensured the
+       efficiency and speed of git.
+
+[[def_git_archive]]git archive::
+       Synonym for <<def_repository,repository>> (for arch people).
+
+[[def_grafts]]grafts::
+       Grafts enables two otherwise different lines of development to be joined
+       together by recording fake ancestry information for commits. This way
+       you can make git pretend the set of parents a <<def_commit,commit>> has
+       is different from what was recorded when the <<def_commit,commit>> was
+       created. Configured via the `.git/info/grafts` file.
+
+[[def_hash]]hash::
+       In git's context, synonym to <<def_object_name,object name>>.
+
+[[def_head]]head::
+       The top of a <<def_branch,branch>>. It contains a <<def_ref,ref>> to the
+       corresponding <<def_commit_object,commit object>>.
+
+[[def_head_ref]]head ref::
+       A <<def_ref,ref>> pointing to a <<def_head,head>>. Often, this is
+       abbreviated to "<<def_head,head>>". Head refs are stored in
+       `$GIT_DIR/refs/heads/`.
+
+[[def_hook]]hook::
+       During the normal execution of several git commands, call-outs are made
+       to optional scripts that allow a developer to add functionality or
+       checking. Typically, the hooks allow for a command to be pre-verified
+       and potentially aborted, and allow for a post-notification after the
+       operation is done. The <<def_hook,hook>> scripts are found in the
+       `$GIT_DIR/hooks/` <<def_directory,directory>>, and are enabled by simply
+       making them executable.
+
+[[def_index]]index::
+       A collection of files with stat information, whose contents are stored
+       as objects. The <<def_index,index>> is a stored version of your working
+       <<def_tree,tree>>. Truth be told, it can also contain a second, and even
+       a third version of a <<def_working_tree,working tree>>, which are used
+       when merging.
+
+[[def_index_entry]]index entry::
+       The information regarding a particular file, stored in the
+       <<def_index,index>>. An <<def_index_entry,index entry>> can be unmerged,
+       if a <<def_merge,merge>> was started, but not yet finished (i.e. if the
+       <<def_index,index>> contains multiple versions of that file).
+
+[[def_master]]master::
+       The default development <<def_branch,branch>>. Whenever you create a git
+       <<def_repository,repository>>, a <<def_branch,branch>> named
+       "<<def_master,master>>" is created, and becomes the active
+       <<def_branch,branch>>. In most cases, this contains the local
        development, though that is purely conventional and not required.
 
-merge::
-       To merge branches means to try to accumulate the changes since a
-       common ancestor and apply them to the first branch. An automatic
-       merge uses heuristics to accomplish that. Evidently, an automatic
-       merge can fail.
-
-object::
-       The unit of storage in git. It is uniquely identified by
-       the SHA1 of its contents. Consequently, an object can not
-       be changed.
-
-object database::
-       Stores a set of "objects", and an individual object is identified
-       by its object name. The objects usually live in `$GIT_DIR/objects/`.
-
-object identifier::
-       Synonym for object name.
-
-object name::
-       The unique identifier of an object. The hash of the object's contents
-       using the Secure Hash Algorithm 1 and usually represented by the 40
-       character hexadecimal encoding of the hash of the object (possibly
-       followed by a white space).
-
-object type::
-       One of the identifiers "commit","tree","tag" and "blob" describing
-       the type of an object.
-
-octopus::
-       To merge more than two branches. Also denotes an intelligent
-       predator.
-
-origin::
-       The default upstream repository. Most projects have at
-       least one upstream project which they track. By default
-       'origin' is used for that purpose.  New upstream updates
+[[def_merge]]merge::
+       To <<def_merge,merge>> branches means to try to accumulate the changes
+       since a common ancestor and apply them to the first
+       <<def_branch,branch>>. An automatic <<def_merge,merge>> uses heuristics
+       to accomplish that. Evidently, an automatic <<def_merge,merge>> can
+       fail.
+
+[[def_object]]object::
+       The unit of storage in git. It is uniquely identified by the
+       <<def_SHA1,SHA1>> of its contents. Consequently, an
+       <<def_object,object>> can not be changed.
+
+[[def_object_database]]object database::
+       Stores a set of "objects", and an individual <<def_object,object>> is
+       identified by its <<def_object_name,object name>>. The objects usually
+       live in `$GIT_DIR/objects/`.
+
+[[def_object_identifier]]object identifier::
+       Synonym for <<def_object_name,object name>>.
+
+[[def_object_name]]object name::
+       The unique identifier of an <<def_object,object>>. The <<def_hash,hash>>
+       of the <<def_object,object>>'s contents using the Secure Hash Algorithm
+       1 and usually represented by the 40 character hexadecimal encoding of
+       the <<def_hash,hash>> of the <<def_object,object>> (possibly followed by
+       a white space).
+
+[[def_object_type]]object type::
+       One of the identifiers
+       "<<def_commit,commit>>","<<def_tree,tree>>","<<def_tag,tag>>" or "<<def_blob_object,blob>>"
+       describing the type of an <<def_object,object>>.
+
+[[def_octopus]]octopus::
+       To <<def_merge,merge>> more than two branches. Also denotes an
+       intelligent predator.
+
+[[def_origin]]origin::
+       The default upstream <<def_repository,repository>>. Most projects have
+       at least one upstream project which they track. By default
+       '<<def_origin,origin>>' is used for that purpose. New upstream updates
        will be fetched into remote tracking branches named
        origin/name-of-upstream-branch, which you can see using
-       "git branch -r".
+       "git <<def_branch,branch>> -r".
 
-pack::
-       A set of objects which have been compressed into one file (to save
-       space or to transmit them efficiently).
+[[def_pack]]pack::
+       A set of objects which have been compressed into one file (to save space
+       or to transmit them efficiently).
 
-pack index::
+[[def_pack_index]]pack index::
        The list of identifiers, and other information, of the objects in a
-       pack, to assist in efficiently accessing the contents of a pack.
-
-parent::
-       A commit object contains a (possibly empty) list of the logical
-       predecessor(s) in the line of development, i.e. its parents.
-
-pickaxe::
-       The term pickaxe refers to an option to the diffcore routines
-       that help select changes that add or delete a given text string.
-       With the --pickaxe-all option, it can be used to view the
-       full changeset that introduced or removed, say, a particular
-       line of text.  See gitlink:git-diff[1].
-
-plumbing::
-       Cute name for core git.
-
-porcelain::
-       Cute name for programs and program suites depending on core git,
-       presenting a high level access to core git. Porcelains expose
-       more of a SCM interface than the plumbing.
-
-pull::
-       Pulling a branch means to fetch it and merge it.
-
-push::
-       Pushing a branch means to get the branch's head ref from a remote
-       repository, find out if it is an ancestor to the branch's local
-       head ref is a direct, and in that case, putting all objects, which
-       are reachable from the local head ref, and which are missing from
-       the remote repository, into the remote object database, and updating
-       the remote head ref. If the remote head is not an ancestor to the
-       local head, the push fails.
-
-reachable::
-       All of the ancestors of a given commit are said to be reachable from
-       that commit.  More generally, one object is reachable from another if
-       we can reach the one from the other by a chain that follows tags to
-       whatever they tag, commits to their parents or trees, and trees to the
-       trees or blobs that they contain.
-
-rebase::
-       To clean a branch by starting from the head of the main line of
-       development ("master"), and reapply the (possibly cherry-picked)
-       changes from that branch.
-
-ref::
-       A 40-byte hex representation of a SHA1 or a name that denotes
-       a particular object. These may be stored in `$GIT_DIR/refs/`.
-
-refspec::
-       A refspec is used by fetch and push to describe the mapping
-       between remote ref and local ref.  They are combined with
-       a colon in the format <src>:<dst>, preceded by an optional
-       plus sign, +.  For example:
-       `git fetch $URL refs/heads/master:refs/heads/origin`
-       means "grab the master branch head from the $URL and store
-       it as my origin branch head".
-       And `git push $URL refs/heads/master:refs/heads/to-upstream`
-       means "publish my master branch head as to-upstream branch
-       at $URL".   See also gitlink:git-push[1]
-
-repository::
-       A collection of refs together with an object database containing
-       all objects, which are reachable from the refs, possibly accompanied
-       by meta data from one or more porcelains. A repository can
-       share an object database with other repositories.
-
-resolve::
-       The action of fixing up manually what a failed automatic merge
-       left behind.
-
-revision::
-       A particular state of files and directories which was stored in
-       the object database. It is referenced by a commit object.
-
-rewind::
-       To throw away part of the development, i.e. to assign the head to
-       an earlier revision.
-
-SCM::
+       <<def_pack,pack>>, to assist in efficiently accessing the contents of a
+       <<def_pack,pack>>.
+
+[[def_parent]]parent::
+       A <<def_commit_object,commit object>> contains a (possibly empty) list
+       of the logical predecessor(s) in the line of development, i.e. its
+       parents.
+
+[[def_pickaxe]]pickaxe::
+       The term <<def_pickaxe,pickaxe>> refers to an option to the diffcore
+       routines that help select changes that add or delete a given text
+       string. With the --pickaxe-all option, it can be used to view the full
+       <<def_changeset,changeset>> that introduced or removed, say, a
+       particular line of text. See gitlink:git-diff[1].
+
+[[def_plumbing]]plumbing::
+       Cute name for <<def_core_git,core git>>.
+
+[[def_porcelain]]porcelain::
+       Cute name for programs and program suites depending on
+       <<def_core_git,core git>>, presenting a high level access to
+       <<def_core_git,core git>>. Porcelains expose more of a <<def_SCM,SCM>>
+       interface than the <<def_plumbing,plumbing>>.
+
+[[def_pull]]pull::
+       Pulling a <<def_branch,branch>> means to <<def_fetch,fetch>> it and
+       <<def_merge,merge>> it.
+
+[[def_push]]push::
+       Pushing a <<def_branch,branch>> means to get the <<def_branch,branch>>'s
+       <<def_head_ref,head ref>> from a remote <<def_repository,repository>>,
+       find out if it is an ancestor to the <<def_branch,branch>>'s local
+       <<def_head_ref,head ref>> is a direct, and in that case, putting all
+       objects, which are <<def_reachable,reachable>> from the local
+       <<def_head_ref,head ref>>, and which are missing from the remote
+       <<def_repository,repository>>, into the remote
+       <<def_object_database,object database>>, and updating the remote
+       <<def_head_ref,head ref>>. If the remote <<def_head,head>> is not an
+       ancestor to the local <<def_head,head>>, the <<def_push,push>> fails.
+
+[[def_reachable]]reachable::
+       All of the ancestors of a given <<def_commit,commit>> are said to be
+       <<def_reachable,reachable>> from that <<def_commit,commit>>. More
+       generally, one <<def_object,object>> is <<def_reachable,reachable>> from
+       another if we can reach the one from the other by a <<def_chain,chain>>
+       that follows <<def_tag,tags>> to whatever they tag,
+       <<def_commit_object,commits>> to their parents or trees, and
+       <<def_tree_object,trees>> to the trees or <<def_blob_object,blobs>>
+       that they contain.
+
+[[def_rebase]]rebase::
+       To reapply a series of changes from a <<def_branch,branch>> to a
+       different base, and reset the <<def_head,head>> of that branch
+       to the result.
+
+[[def_ref]]ref::
+       A 40-byte hex representation of a <<def_SHA1,SHA1>> or a name that
+       denotes a particular <<def_object,object>>. These may be stored in
+       `$GIT_DIR/refs/`.
+
+[[def_refspec]]refspec::
+       A <<def_refspec,refspec>> is used by <<def_fetch,fetch>> and
+       <<def_push,push>> to describe the mapping between remote <<def_ref,ref>>
+       and local <<def_ref,ref>>. They are combined with a colon in the format
+       <src>:<dst>, preceded by an optional plus sign, +. For example: `git
+       fetch $URL refs/heads/master:refs/heads/origin` means
+       "grab the master <<def_branch,branch>> <<def_head,head>>
+       from the $URL and store it as my origin
+       <<def_branch,branch>> <<def_head,head>>". And `git <<def_push,push>>
+       $URL refs/heads/master:refs/heads/to-upstream` means
+       "publish my master <<def_branch,branch>>
+       <<def_head,head>> as to-upstream <<def_branch,branch>> at $URL". See
+       also gitlink:git-push[1]
+
+[[def_repository]]repository::
+       A collection of refs together with an <<def_object_database,object
+       database>> containing all objects which are <<def_reachable,reachable>>
+       from the refs, possibly accompanied by meta data from one or more
+       porcelains. A <<def_repository,repository>> can share an
+       <<def_object_database,object database>> with other repositories.
+
+[[def_resolve]]resolve::
+       The action of fixing up manually what a failed automatic
+       <<def_merge,merge>> left behind.
+
+[[def_revision]]revision::
+       A particular state of files and directories which was stored in the
+       <<def_object_database,object database>>. It is referenced by a
+       <<def_commit_object,commit object>>.
+
+[[def_rewind]]rewind::
+       To throw away part of the development, i.e. to assign the
+       <<def_head,head>> to an earlier <<def_revision,revision>>.
+
+[[def_SCM]]SCM::
        Source code management (tool).
 
-SHA1::
-       Synonym for object name.
-
-shallow repository::
-       A shallow repository has an incomplete history some of
-       whose commits have parents cauterized away (in other
-       words, git is told to pretend that these commits do not
-       have the parents, even though they are recorded in the
-       commit object).  This is sometimes useful when you are
-       interested only in the recent history of a project even
-       though the real history recorded in the upstream is
-       much larger.  A shallow repository is created by giving
-       `--depth` option to gitlink:git-clone[1], and its
-       history can be later deepened with gitlink:git-fetch[1].
-
-symref::
-       Symbolic reference: instead of containing the SHA1 id itself, it
-       is of the format 'ref: refs/some/thing' and when referenced, it
-       recursively dereferences to this reference. 'HEAD' is a prime
-       example of a symref. Symbolic references are manipulated with
-       the gitlink:git-symbolic-ref[1] command.
-
-topic branch::
-       A regular git branch that is used by a developer to
-       identify a conceptual line of development.  Since branches
-       are very easy and inexpensive, it is often desirable to
-       have several small branches that each contain very well
-       defined concepts or small incremental yet related changes.
-
-tracking branch::
-       A regular git branch that is used to follow changes from
-       another repository.  A tracking branch should not contain
-       direct modifications or have local commits made to it.
-       A tracking branch can usually be identified as the
-       right-hand-side ref in a Pull: refspec.
-
-tree object::
-       An object containing a list of file names and modes along with refs
-       to the associated blob and/or tree objects. A tree is equivalent
-       to a directory.
-
-tree::
-       Either a working tree, or a tree object together with the
-       dependent blob and tree objects (i.e. a stored representation
-       of a working tree).
-
-tree-ish::
-       A ref pointing to either a commit object, a tree object, or a
-       tag object pointing to a tag or commit or tree object.
-
-tag object::
-       An object containing a ref pointing to another object, which can
-       contain a message just like a commit object. It can also
-       contain a (PGP) signature, in which case it is called a "signed
-       tag object".
-
-tag::
-       A ref pointing to a tag or commit object. In contrast to a head,
-       a tag is not changed by a commit. Tags (not tag objects) are
-       stored in `$GIT_DIR/refs/tags/`. A git tag has nothing to do with
-       a Lisp tag (which is called object type in git's context).
-       A tag is most typically used to mark a particular point in the
-       commit ancestry chain.
-
-unmerged index::
-       An index which contains unmerged index entries.
-
-unreachable object::
-       An object which is not reachable from a branch, tag, or any
-       other reference.
-
-working tree::
-       The set of files and directories currently being worked on,
-       i.e. you can work in your working tree without using git at all.
-
+[[def_SHA1]]SHA1::
+       Synonym for <<def_object_name,object name>>.
+
+[[def_shallow_repository]]shallow repository::
+       A <<def_shallow_repository,shallow repository>> has an incomplete
+       history some of whose commits have parents cauterized away (in other
+       words, git is told to pretend that these commits do not have the
+       parents, even though they are recorded in the <<def_commit_object,commit
+       object>>). This is sometimes useful when you are interested only in the
+       recent history of a project even though the real history recorded in the
+       upstream is much larger. A <<def_shallow_repository,shallow repository>>
+       is created by giving the `--depth` option to gitlink:git-clone[1], and
+       its history can be later deepened with gitlink:git-fetch[1].
+
+[[def_symref]]symref::
+       Symbolic reference: instead of containing the <<def_SHA1,SHA1>> id
+       itself, it is of the format 'ref: refs/some/thing' and when
+       referenced, it recursively dereferences to this reference. 'HEAD' is a
+       prime example of a <<def_symref,symref>>. Symbolic references are
+       manipulated with the gitlink:git-symbolic-ref[1] command.
+
+[[def_tag]]tag::
+       A <<def_ref,ref>> pointing to a <<def_tag,tag>> or
+       <<def_commit_object,commit object>>. In contrast to a <<def_head,head>>,
+       a tag is not changed by a <<def_commit,commit>>. Tags (not
+       <<def_tag_object,tag objects>>) are stored in `$GIT_DIR/refs/tags/`. A
+       git tag has nothing to do with a Lisp tag (which would be
+       called an <<def_object_type,object type>> in git's context). A
+       tag is most typically used to mark a particular point in the
+       <<def_commit,commit>> ancestry <<def_chain,chain>>.
+
+[[def_tag_object]]tag object::
+       An <<def_object,object>> containing a <<def_ref,ref>> pointing to
+       another <<def_object,object>>, which can contain a message just like a
+       <<def_commit_object,commit object>>. It can also contain a (PGP)
+       signature, in which case it is called a "signed <<def_tag_object,tag
+       object>>".
+
+[[def_topic_branch]]topic branch::
+       A regular git <<def_branch,branch>> that is used by a developer to
+       identify a conceptual line of development. Since branches are very easy
+       and inexpensive, it is often desirable to have several small branches
+       that each contain very well defined concepts or small incremental yet
+       related changes.
+
+[[def_tracking_branch]]tracking branch::
+       A regular git <<def_branch,branch>> that is used to follow changes from
+       another <<def_repository,repository>>. A <<def_tracking_branch,tracking
+       branch>> should not contain direct modifications or have local commits
+       made to it. A <<def_tracking_branch,tracking branch>> can usually be
+       identified as the right-hand-side <<def_ref,ref>> in a Pull:
+       <<def_refspec,refspec>>.
+
+[[def_tree]]tree::
+       Either a <<def_working_tree,working tree>>, or a <<def_tree_object,tree
+       object>> together with the dependent blob and <<def_tree,tree>> objects
+       (i.e. a stored representation of a <<def_working_tree,working tree>>).
+
+[[def_tree_object]]tree object::
+       An <<def_object,object>> containing a list of file names and modes along
+       with refs to the associated blob and/or tree objects. A
+       <<def_tree,tree>> is equivalent to a <<def_directory,directory>>.
+
+[[def_tree-ish]]tree-ish::
+       A <<def_ref,ref>> pointing to either a <<def_commit_object,commit
+       object>>, a <<def_tree_object,tree object>>, or a <<def_tag_object,tag
+       object>> pointing to a <<def_tag,tag>> or <<def_commit,commit>> or
+       <<def_tree_object,tree object>>.
+
+[[def_unmerged_index]]unmerged index::
+       An <<def_index,index>> which contains unmerged
+       <<def_index_entry,index entries>>.
+
+[[def_unreachable_object]]unreachable object::
+       An <<def_object,object>> which is not <<def_reachable,reachable>> from a
+       <<def_branch,branch>>, <<def_tag,tag>>, or any other reference.
+
+[[def_working_tree]]working tree::
+       The set of files and directories currently being worked on, i.e. you can
+       work in your <<def_working_tree,working tree>> without using git at all.
diff --git a/Documentation/howto/use-git-daemon.txt b/Documentation/howto/use-git-daemon.txt
new file mode 100644 (file)
index 0000000..1a1eb24
--- /dev/null
@@ -0,0 +1,52 @@
+How to use git-daemon
+
+Git can be run in inetd mode and in stand alone mode. But all you want is
+let a coworker pull from you, and therefore need to set up a git server
+real quick, right?
+
+Note that git-daemon is not really chatty at the moment, especially when
+things do not go according to plan (e.g. a socket could not be bound).
+
+Another word of warning: if you run
+
+       $ git ls-remote git://127.0.0.1/rule-the-world.git
+
+and you see a message like
+
+       fatal: The remote end hung up unexpectedly
+
+it only means that _something_ went wrong. To find out _what_ went wrong,
+you have to ask the server. (Git refuses to be more precise for your
+security only. Take off your shoes now. You have any coins in your pockets?
+Sorry, not allowed -- who knows what you planned to do with them?)
+
+With these two caveats, let's see an example:
+
+       $ git daemon --reuseaddr --verbose --base-path=/home/gitte/git \
+         --export-all -- /home/gitte/git/rule-the-world.git
+
+(Of course, unless your user name is `gitte` _and_ your repository is in
+~/rule-the-world.git, you have to adjust the paths. If your repository is
+not bare, be aware that you have to type the path to the .git directory!)
+
+This invocation tries to reuse the address if it is already taken
+(this can save you some debugging, because otherwise killing and restarting
+git-daemon could just silently fail to bind to a socket).
+
+Also, it is (relatively) verbose when somebody actually connects to it.
+It also sets the base path, which means that all the projects which can be
+accessed using this daemon have to reside in or under that path.
+
+The option `--export-all` just means that you _don't_ have to create a
+file named `git-daemon-export-ok` in each exported repository. (Otherwise,
+git-daemon would complain loudly, and refuse to cooperate.)
+
+Last of all, the repository which should be exported is specified. It is
+a good practice to put the paths after a "--" separator.
+
+Now, test your daemon with
+
+       $ git ls-remote git://127.0.0.1/rule-the-world.git
+
+If this does not work, find out why, and submit a patch to this document.
+
index b3981936e302dafb33e967b3cc17a3cab5b5659e..cd3a18eb7fa73b01e9d3a9489711292148f088e6 100755 (executable)
@@ -2,7 +2,7 @@
 
 T="$1"
 
-for h in *.html *.txt howto/*.txt howto/*.html RelNotes-*.txt
+for h in *.html *.txt howto/*.txt howto/*.html RelNotes-*.txt *.css
 do
        if test -f "$T/$h" &&
           diff -u -I'Last updated [0-9][0-9]-[A-Z][a-z][a-z]-' "$T/$h" "$h"
diff --git a/Documentation/sort_glossary.pl b/Documentation/sort_glossary.pl
deleted file mode 100644 (file)
index e0bc552..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/perl
-
-%terms=();
-
-while(<>) {
-       if(/^(\S.*)::$/) {
-               my $term=$1;
-               if(defined($terms{$term})) {
-                       die "$1 defined twice\n";
-               }
-               $terms{$term}="";
-               LOOP: while(<>) {
-                       if(/^$/) {
-                               last LOOP;
-                       }
-                       if(/^   \S/) {
-                               $terms{$term}.=$_;
-                       } else {
-                               die "Error 1: $_";
-                       }
-               }
-       }
-}
-
-sub format_tab_80 ($) {
-       my $text=$_[0];
-       my $result="";
-       $text=~s/\s+/ /g;
-       $text=~s/^\s+//;
-       while($text=~/^(.{1,72})(|\s+(\S.*)?)$/) {
-               $result.="      ".$1."\n";
-               $text=$3;
-       }
-       return $result;
-}
-
-sub no_spaces ($) {
-       my $result=$_[0];
-       $result=~tr/ /_/;
-       return $result;
-}
-
-print 'GIT Glossary
-============
-
-This list is sorted alphabetically:
-
-';
-
-@keys=sort {uc($a) cmp uc($b)} keys %terms;
-$pattern='(\b(?<!link:git-)'.join('\b|\b(?<!link:git-)',reverse @keys).'\b)';
-foreach $key (@keys) {
-       $terms{$key}=~s/$pattern/sprintf "<<ref_".no_spaces($1).",$1>>";/eg;
-       print '[[ref_'.no_spaces($key).']]'.$key."::\n"
-               .format_tab_80($terms{$key})."\n";
-}
-
-print '
-
-Author
-------
-Written by Johannes Schindelin <Johannes.Schindelin@gmx.de> and
-the git-list <git@vger.kernel.org>.
-
-GIT
----
-Part of the link:git.html[git] suite
-';
-
index 0e1ffb24276027aa54c6b04fe404367f267cc07d..9ce3c473ae1a9b5fd0b3a909fb264d8e0fff27a5 100644 (file)
@@ -21,11 +21,11 @@ GIT pack format
      which looks like this:
 
      (undeltified representation)
-     n-byte type and length (4-bit type, (n-1)*7+4-bit length)
+     n-byte type and length (3-bit type, (n-1)*7+4-bit length)
      compressed data
 
      (deltified representation)
-     n-byte type and length (4-bit type, (n-1)*7+4-bit length)
+     n-byte type and length (3-bit type, (n-1)*7+4-bit length)
      20-byte base object name
      compressed delta data
 
@@ -102,11 +102,13 @@ trailer     | | packfile checksum              |
 Pack file entry: <+
 
      packed object header:
-       1-byte type (upper 4-bit)
+       1-byte size extension bit (MSB)
+              type (next 3 bit)
               size0 (lower 4-bit) 
         n-byte sizeN (as long as MSB is set, each 7-bit)
                size0..sizeN form 4+7+7+..+7 bit integer, size0
-               is the most significant part.
+               is the least significant part, and sizeN is the
+               most significant part.
      packed object data:
         If it is not DELTA, then deflated bytes (the size above
                is the size before compression).
diff --git a/Documentation/technical/shallow.txt b/Documentation/technical/shallow.txt
new file mode 100644 (file)
index 0000000..559263a
--- /dev/null
@@ -0,0 +1,49 @@
+Def.: Shallow commits do have parents, but not in the shallow
+repo, and therefore grafts are introduced pretending that
+these commits have no parents.
+
+The basic idea is to write the SHA1s of shallow commits into
+$GIT_DIR/shallow, and handle its contents like the contents
+of $GIT_DIR/info/grafts (with the difference that shallow
+cannot contain parent information).
+
+This information is stored in a new file instead of grafts, or
+even the config, since the user should not touch that file
+at all (even throughout development of the shallow clone, it
+was never manually edited!).
+
+Each line contains exactly one SHA1. When read, a commit_graft
+will be constructed, which has nr_parent < 0 to make it easier
+to discern from user provided grafts.
+
+Since fsck-objects relies on the library to read the objects,
+it honours shallow commits automatically.
+
+There are some unfinished ends of the whole shallow business:
+
+- maybe we have to force non-thin packs when fetching into a
+  shallow repo (ATM they are forced non-thin).
+
+- A special handling of a shallow upstream is needed. At some
+  stage, upload-pack has to check if it sends a shallow commit,
+  and it should send that information early (or fail, if the
+  client does not support shallow repositories). There is no
+  support at all for this in this patch series.
+
+- Instead of locking $GIT_DIR/shallow at the start, just
+  the timestamp of it is noted, and when it comes to writing it,
+  a check is performed if the mtime is still the same, dying if
+  it is not.
+
+- It is unclear how "push into/from a shallow repo" should behave.
+
+- If you deepen a history, you'd want to get the tags of the
+  newly stored (but older!) commits. This does not work right now.
+
+To make a shallow clone, you can call "git-clone --depth 20 repo".
+The result contains only commit chains with a length of at most 20.
+It also writes an appropriate $GIT_DIR/shallow.
+
+You can deepen a shallow repository with "git-fetch --depth 20
+repo branch", which will fetch branch from repo, but stop at depth
+20, updating $GIT_DIR/shallow.
index ffd673ec335c3d85d6815dcfdc3e1bfd019f8551..d43d2377ec51e88116dbfed90bb1064d8fed05a1 100644 (file)
@@ -84,7 +84,7 @@ $ git branch -r               # list
   origin/master
   origin/next
   ...
-$ git branch checkout -b masterwork origin/master
+$ git checkout -b masterwork origin/master
 -----------------------------------------------
 
 Fetch a branch from a different repository, and give it a new
@@ -155,8 +155,8 @@ Make sure git knows who to blame:
 ------------------------------------------------
 $ cat >~/.gitconfig <<\EOF
 [user]
-name = Your Name Comes Here
-email = you@yourdomain.example.com
+       name = Your Name Comes Here
+       email = you@yourdomain.example.com
 EOF
 ------------------------------------------------
 
@@ -195,7 +195,7 @@ Importing or exporting patches:
 -----------------------------------------------
 $ git format-patch origin..HEAD # format a patch for each commit
                                # in HEAD but not in origin
-$ git-am mbox # import patches from the mailbox "mbox"
+$ git am mbox # import patches from the mailbox "mbox"
 -----------------------------------------------
 
 Fetch a branch in a different git repository, then merge into the
@@ -288,21 +288,22 @@ collection of files.  It stores the history as a compressed
 collection of interrelated snapshots (versions) of the project's
 contents.
 
-A single git repository may contain multiple branches.  Each branch
-is a bookmark referencing a particular point in the project history.
-The gitlink:git-branch[1] command shows you the list of branches:
+A single git repository may contain multiple branches.  It keeps track
+of them by keeping a list of <<def_head,heads>> which reference the
+latest version on each branch; the gitlink:git-branch[1] command shows
+you the list of branch heads:
 
 ------------------------------------------------
 $ git branch
 * master
 ------------------------------------------------
 
-A freshly cloned repository contains a single branch, named "master",
-and the working directory contains the version of the project
-referred to by the master branch.
+A freshly cloned repository contains a single branch head, named
+"master", and working directory is initialized to the state of
+the project referred to by "master".
 
-Most projects also use tags.  Tags, like branches, are references
-into the project's history, and can be listed using the
+Most projects also use <<def_tag,tags>>.  Tags, like heads, are
+references into the project's history, and can be listed using the
 gitlink:git-tag[1] command:
 
 ------------------------------------------------
@@ -320,9 +321,9 @@ v2.6.13
 ------------------------------------------------
 
 Tags are expected to always point at the same version of a project,
-while branches are expected to advance as development progresses.
+while heads are expected to advance as development progresses.
 
-Create a new branch pointing to one of these versions and check it
+Create a new branch head pointing to one of these versions and check it
 out using gitlink:git-checkout[1]:
 
 ------------------------------------------------
@@ -346,10 +347,10 @@ the current branch to point at v2.6.17 instead, with
 $ git reset --hard v2.6.17
 ------------------------------------------------
 
-Note that if the current branch was your only reference to a
+Note that if the current branch head was your only reference to a
 particular point in history, then resetting that branch may leave you
-with no way to find the history it used to point to; so use this
-command carefully.
+with no way to find the history it used to point to; so use this command
+carefully.
 
 Understanding History: Commits
 ------------------------------
@@ -437,11 +438,14 @@ We will sometimes represent git history using diagrams like the one
 below.  Commits are shown as "o", and the links between them with
 lines drawn with - / and \.  Time goes left to right:
 
+
+................................................
          o--o--o <-- Branch A
         /
  o--o--o <-- master
         \
          o--o--o <-- Branch B
+................................................
 
 If we need to talk about a particular commit, the character "o" may
 be replaced with another letter or number.
@@ -449,17 +453,15 @@ be replaced with another letter or number.
 Understanding history: What is a branch?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Though we've been using the word "branch" to mean a kind of reference
-to a particular commit, the word branch is also commonly used to
-refer to the line of commits leading up to that point.  In the
-example above, git may think of the branch named "A" as just a
-pointer to one particular commit, but we may refer informally to the
-line of three commits leading up to that point as all being part of
+When we need to be precise, we will use the word "branch" to mean a line
+of development, and "branch head" (or just "head") to mean a reference
+to the most recent commit on a branch.  In the example above, the branch
+head named "A" is a pointer to one particular commit, but we refer to
+the line of three commits leading up to that point as all being part of
 "branch A".
 
-If we need to make it clear that we're just talking about the most
-recent commit on the branch, we may refer to that commit as the
-"head" of the branch.
+However, when no confusion will result, we often just use the term
+"branch" both for branches and for branch heads.
 
 Manipulating branches
 ---------------------
@@ -577,7 +579,7 @@ cloned from, using gitlink:git-remote[1]:
 
 -------------------------------------------------
 $ git remote add linux-nfs git://linux-nfs.org/pub/nfs-2.6.git
-$ git fetch
+$ git fetch linux-nfs
 * refs/remotes/linux-nfs/master: storing branch 'master' ...
   commit: bf81b46
 -------------------------------------------------
@@ -601,8 +603,8 @@ a new stanza:
 $ cat .git/config
 ...
 [remote "linux-nfs"]
-        url = git://linux-nfs.org/~bfields/git.git
-       fetch = +refs/heads/*:refs/remotes/linux-nfs-read/*
+       url = git://linux-nfs.org/pub/nfs-2.6.git
+       fetch = +refs/heads/*:refs/remotes/linux-nfs/*
 ...
 -------------------------------------------------
 
@@ -678,7 +680,7 @@ occasionally you may land on a commit that broke something unrelated;
 run
 
 -------------------------------------------------
-$ git bisect-visualize
+$ git bisect visualize
 -------------------------------------------------
 
 which will run gitk and label the commit it chose with a marker that
@@ -763,7 +765,7 @@ We can also create a tag to refer to a particular commit; after
 running
 
 -------------------------------------------------
-$ git-tag stable-1 1b2e1d63ff
+$ git tag stable-1 1b2e1d63ff
 -------------------------------------------------
 
 You can use stable-1 to refer to the commit 1b2e1d63ff.
@@ -907,7 +909,7 @@ name based on any tag it finds pointing to one of the commit's
 descendants:
 
 -------------------------------------------------
-$ git name-rev e05db0fd
+$ git name-rev --tags e05db0fd
 e05db0fd tags/v1.5.0-rc1^0~23
 -------------------------------------------------
 
@@ -916,7 +918,7 @@ revision using a tag on which the given commit is based:
 
 -------------------------------------------------
 $ git describe e05db0fd
-v1.5.0-rc0-ge05db0f
+v1.5.0-rc0-260-ge05db0f
 -------------------------------------------------
 
 but that may sometimes help you guess which tags might come after the
@@ -1013,7 +1015,7 @@ $ git commit
 -------------------------------------------------
 
 [[how-to-make-a-commit]]
-how to make a commit
+How to make a commit
 --------------------
 
 Creating a new commit takes three steps:
@@ -1107,7 +1109,7 @@ $ git diff            # difference between the index file and your
 $ git status       # a brief per-file summary of the above.
 -------------------------------------------------
 
-creating good commit messages
+Creating good commit messages
 -----------------------------
 
 Though not required, it's a good idea to begin the commit message
@@ -1117,7 +1119,7 @@ description.  Tools that turn commits into email, for example, use
 the first line on the Subject line and the rest of the commit in the
 body.
 
-how to merge
+How to merge
 ------------
 
 You can rejoin two diverging branches of development using
@@ -1133,17 +1135,9 @@ modified in two different ways in the remote branch and the local
 branch--then you are warned; the output may look something like this:
 
 -------------------------------------------------
-$ git pull . next
-Trying really trivial in-index merge...
-fatal: Merge requires file-level merging
-Nope.
-Merging HEAD with 77976da35a11db4580b80ae27e8d65caf5208086
-Merging:
-15e2162 world
-77976da goodbye
-found 1 common ancestor(s):
-d122ed4 initial
-Auto-merging file.txt
+$ git merge next
+ 100% (4/4) done
+Auto-merged file.txt
 CONFLICT (content): Merge conflict in file.txt
 Automatic merge failed; fix conflicts and then commit the result.
 -------------------------------------------------
@@ -1304,7 +1298,7 @@ the different stages of that file will be "collapsed", after which
 git-diff will (by default) no longer show diffs for that file.
 
 [[undoing-a-merge]]
-undoing a merge
+Undoing a merge
 ---------------
 
 If you get stuck and decide to just give up and throw the whole mess
@@ -1439,7 +1433,7 @@ modifying the working directory, you can do that with
 gitlink:git-show[1]:
 
 -------------------------------------------------
-$ git show HEAD^ path/to/file
+$ git show HEAD^:path/to/file
 -------------------------------------------------
 
 which will display the given version of the file.
@@ -1703,7 +1697,7 @@ If you and maintainer both have accounts on the same machine, then
 then you can just pull changes from each other's repositories
 directly; note that all of the commands (gitlink:git-clone[1],
 git-fetch[1], git-pull[1], etc.) that accept a URL as an argument
-will also accept a local file patch; so, for example, you can
+will also accept a local directory name; so, for example, you can
 use
 
 -------------------------------------------------
@@ -1867,7 +1861,7 @@ Allow web browsing of a repository
 
 The gitweb cgi script provides users an easy way to browse your
 project's files and history without having to install git; see the file
-gitweb/README in the git source tree for instructions on setting it up.
+gitweb/INSTALL in the git source tree for instructions on setting it up.
 
 Examples
 --------
@@ -1936,25 +1930,29 @@ $ git commit
 You have performed no merges into mywork, so it is just a simple linear
 sequence of patches on top of "origin":
 
-
+................................................
  o--o--o <-- origin
         \
          o--o--o <-- mywork
+................................................
 
 Some more interesting work has been done in the upstream project, and
 "origin" has advanced:
 
+................................................
  o--o--O--o--o--o <-- origin
         \
          a--b--c <-- mywork
+................................................
 
 At this point, you could use "pull" to merge your changes back in;
 the result would create a new merge commit, like this:
 
-
+................................................
  o--o--O--o--o--o <-- origin
         \        \
          a--b--c--m <-- mywork
+................................................
  
 However, if you prefer to keep the history in mywork a simple series of
 commits without any merges, you may instead choose to use
@@ -1971,9 +1969,11 @@ point at the latest version of origin, then apply each of the saved
 patches to the new mywork.  The result will look like:
 
 
+................................................
  o--o--O--o--o--o <-- origin
                 \
                  a'--b'--c' <-- mywork
+................................................
 
 In the process, it may discover conflicts.  In that case it will stop
 and allow you to fix the conflicts; after fixing conflicts, use "git
@@ -2081,24 +2081,30 @@ The primary problem with rewriting the history of a branch has to do
 with merging.  Suppose somebody fetches your branch and merges it into
 their branch, with a result something like this:
 
+................................................
  o--o--O--o--o--o <-- origin
         \        \
          t--t--t--m <-- their branch:
+................................................
 
 Then suppose you modify the last three commits:
 
+................................................
         o--o--o <-- new head of origin
        /
  o--o--O--o--o--o <-- old head of origin
+................................................
 
 If we examined all this history together in one repository, it will
 look like:
 
+................................................
         o--o--o <-- new head of origin
        /
  o--o--O--o--o--o <-- old head of origin
         \        \
          t--t--t--m <-- their branch:
+................................................
 
 Git has no way of knowing that the new head is an updated version of
 the old head; it treats this situation exactly the same as it would if
@@ -2159,9 +2165,11 @@ commit.  Git calls this process a "fast forward".
 
 A fast forward looks something like this:
 
+................................................
  o--o--o--o <-- old head of the branch
            \
             o--o--o <-- new head of the branch
+................................................
 
 
 In some cases it is possible that the new head will *not* actually be
@@ -2169,11 +2177,11 @@ a descendant of the old head.  For example, the developer may have
 realized she made a serious mistake, and decided to backtrack,
 resulting in a situation like:
 
+................................................
  o--o--o--o--a--b <-- old head of the branch
            \
             o--o--o <-- new head of the branch
-
-
+................................................
 
 In this case, "git fetch" will fail, and print out a warning.
 
@@ -3004,9 +3012,6 @@ confusing and scary messages, but it won't actually do anything bad. In
 contrast, running "git prune" while somebody is actively changing the 
 repository is a *BAD* idea).
 
-Glossary of git terms
-=====================
-
 include::glossary.txt[]
 
 Notes and todo list for this manual
index 6abde8d7b36865c0c8f43b4489ce0074a27f24c8..48715012bee68c5df07a49e9bce83240b8631746 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v1.5.0.GIT
+DEF_VER=v1.5.1.GIT
 
 LF='
 '
index a221bdc027851270b9920373a3d9cb8d0fbac2e2..ac29c629e3927ad59142cf73d03eea501fc30962 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,8 @@
 # The default target of this Makefile is...
 all::
 
+# Define V=1 to have a more verbose compile.
+#
 # Define NO_OPENSSL environment variable if you do not have OpenSSL.
 # This also implies MOZILLA_SHA1.
 #
@@ -108,6 +110,14 @@ all::
 # Define NO_PERL_MAKEMAKER if you cannot use Makefiles generated by perl's
 # MakeMaker (e.g. using ActiveState under Cygwin).
 #
+# Define WITH_P4IMPORT to build and install Python git-p4import script.
+#
+# Define NO_TCLTK if you do not want Tcl/Tk GUI.
+#
+# The TCLTK_PATH variable governs the location of the Tck/Tk interpreter.
+# If not set it defaults to the bare 'wish'. If it is set to the empty
+# string then NO_TCLTK will be forced (this is used by configure script).
+#
 
 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -157,6 +167,7 @@ AR = ar
 TAR = tar
 INSTALL = install
 RPMBUILD = rpmbuild
+TCLTK_PATH = wish
 
 # sparse is architecture-neutral, which means that we need to tell it
 # explicitly what architecture to check for. Fix this up for yours..
@@ -175,12 +186,12 @@ BASIC_LDFLAGS =
 SCRIPT_SH = \
        git-bisect.sh git-checkout.sh \
        git-clean.sh git-clone.sh git-commit.sh \
-       git-fetch.sh git-gc.sh \
+       git-fetch.sh \
        git-ls-remote.sh \
-       git-merge-one-file.sh git-parse-remote.sh \
+       git-merge-one-file.sh git-mergetool.sh git-parse-remote.sh \
        git-pull.sh git-rebase.sh \
        git-repack.sh git-request-pull.sh git-reset.sh \
-       git-revert.sh git-sh-setup.sh \
+       git-sh-setup.sh \
        git-tag.sh git-verify-tag.sh \
        git-applymbox.sh git-applypatch.sh git-am.sh \
        git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
@@ -194,9 +205,20 @@ SCRIPT_PERL = \
        git-svnimport.perl git-cvsexportcommit.perl \
        git-send-email.perl git-svn.perl
 
+SCRIPT_PYTHON = \
+       git-p4import.py
+
+ifdef WITH_P4IMPORT
 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
          $(patsubst %.perl,%,$(SCRIPT_PERL)) \
-         git-cherry-pick git-status git-instaweb
+         $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
+         git-status git-instaweb
+else
+SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
+         $(patsubst %.perl,%,$(SCRIPT_PERL)) \
+         git-status git-instaweb
+endif
+
 
 # ... and all the rest that could be moved out of bindir to gitexecdir
 PROGRAMS = \
@@ -223,12 +245,18 @@ EXTRA_PROGRAMS =
 BUILT_INS = \
        git-format-patch$X git-show$X git-whatchanged$X git-cherry$X \
        git-get-tar-commit-id$X git-init$X git-repo-config$X \
-       git-fsck-objects$X \
+       git-fsck-objects$X git-cherry-pick$X \
        $(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS))
 
 # what 'all' will build and 'install' will install, in gitexecdir
 ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
 
+# what 'all' will build but not install in gitexecdir
+OTHER_PROGRAMS = git$X gitweb/gitweb.cgi
+ifndef NO_TCLTK
+OTHER_PROGRAMS += gitk-wish
+endif
+
 # Backward compatibility -- to be removed after 1.0
 PROGRAMS += git-ssh-pull$X git-ssh-push$X
 
@@ -239,6 +267,9 @@ endif
 ifndef PERL_PATH
        PERL_PATH = /usr/bin/perl
 endif
+ifndef PYTHON_PATH
+       PYTHON_PATH = /usr/local/bin/python
+endif
 
 export PERL_PATH
 
@@ -291,9 +322,11 @@ BUILTIN_OBJS = \
        builtin-diff-files.o \
        builtin-diff-index.o \
        builtin-diff-tree.o \
+       builtin-fetch--tool.o \
        builtin-fmt-merge-msg.o \
        builtin-for-each-ref.o \
        builtin-fsck.o \
+       builtin-gc.o \
        builtin-grep.o \
        builtin-init-db.o \
        builtin-log.o \
@@ -315,6 +348,7 @@ BUILTIN_OBJS = \
        builtin-rerere.o \
        builtin-rev-list.o \
        builtin-rev-parse.o \
+       builtin-revert.o \
        builtin-rm.o \
        builtin-runstatus.o \
        builtin-shortlog.o \
@@ -351,6 +385,7 @@ endif
 ifeq ($(uname_S),Darwin)
        NEEDS_SSL_WITH_CRYPTO = YesPlease
        NEEDS_LIBICONV = YesPlease
+       OLD_ICONV = UnfortunatelyYes
        NO_STRLCPY = YesPlease
 endif
 ifeq ($(uname_S),SunOS)
@@ -603,6 +638,35 @@ ifdef NO_PERL_MAKEMAKER
        export NO_PERL_MAKEMAKER
 endif
 
+ifeq ($(TCLTK_PATH),)
+NO_TCLTK=NoThanks
+endif
+
+QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
+QUIET_SUBDIR1  =
+
+ifneq ($(findstring $(MAKEFLAGS),w),w)
+PRINT_DIR = --no-print-directory
+else # "make -w"
+NO_SUBDIR = :
+endif
+
+ifneq ($(findstring $(MAKEFLAGS),s),s)
+ifndef V
+       QUIET_CC       = @echo '   ' CC $@;
+       QUIET_AR       = @echo '   ' AR $@;
+       QUIET_LINK     = @echo '   ' LINK $@;
+       QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
+       QUIET_GEN      = @echo '   ' GEN $@;
+       QUIET_SUBDIR0  = +@subdir=
+       QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
+                        $(MAKE) $(PRINT_DIR) -C $$subdir
+       export V
+       export QUIET_GEN
+       export QUIET_BUILT_IN
+endif
+endif
+
 # Shell quote (do not use $(call) to accommodate ancient setups);
 
 SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
@@ -616,6 +680,8 @@ prefix_SQ = $(subst ','\'',$(prefix))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
+PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
+TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
 
 LIBS = $(GITLIBS) $(EXTLIBS)
 
@@ -631,50 +697,66 @@ export prefix gitexecdir TAR INSTALL DESTDIR SHELL_PATH template_dir
 
 ### Build rules
 
-all:: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk gitweb/gitweb.cgi
+all:: $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS)
 ifneq (,$X)
        $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), rm -f '$p';)
 endif
 
 all::
-       $(MAKE) -C git-gui all
-       $(MAKE) -C perl PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all
-       $(MAKE) -C templates
+ifndef NO_TCLTK
+       $(QUIET_SUBDIR0)git-gui $(QUIET_SUBDIR1) TCLTK_PATH='$(TCLTK_PATH_SQ)' all
+endif
+       $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all
+       $(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1)
 
 strip: $(PROGRAMS) git$X
        $(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
 
+gitk-wish: gitk GIT-GUI-VARS
+       $(QUIET_GEN)rm -f $@ $@+ && \
+       sed -e '1,3s|^exec .* "$$0"|exec $(subst |,'\|',$(TCLTK_PATH_SQ)) "$$0"|' <gitk >$@+ && \
+       chmod +x $@+ && \
+       mv -f $@+ $@
+
 git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS
-       $(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
+       $(QUIET_LINK)$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
                $(ALL_CFLAGS) -o $@ $(filter %.c,$^) \
                $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
 
 help.o: common-cmds.h
 
 $(BUILT_INS): git$X
-       rm -f $@ && ln git$X $@
+       $(QUIET_BUILT_IN)rm -f $@ && ln git$X $@
 
-common-cmds.h: Documentation/git-*.txt
-       ./generate-cmdlist.sh > $@+
-       mv $@+ $@
+common-cmds.h: $(wildcard Documentation/git-*.txt)
+       $(QUIET_GEN)./generate-cmdlist.sh > $@+ && mv $@+ $@
 
 $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
-       rm -f $@ $@+
+       $(QUIET_GEN)rm -f $@ $@+ && \
        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
            -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
            -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
-           $@.sh >$@+
-       chmod +x $@+
+           $@.sh >$@+ && \
+       chmod +x $@+ && \
        mv $@+ $@
 
 $(patsubst %.perl,%,$(SCRIPT_PERL)): perl/perl.mak
 
+$(patsubst %.py,%,$(SCRIPT_PYTHON)) : % : %.py
+       rm -f $@ $@+
+       sed -e '1s|#!.*/python|#!$(PYTHON_PATH_SQ)|' \
+           -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
+           -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
+           $@.py >$@+
+       chmod +x $@+
+       mv $@+ $@
+
 perl/perl.mak: GIT-CFLAGS
-       $(MAKE) -C perl PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F)
+       $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F)
 
 $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
-       rm -f $@ $@+
+       $(QUIET_GEN)rm -f $@ $@+ && \
        INSTLIBDIR=`$(MAKE) -C perl -s --no-print-directory instlibdir` && \
        sed -e '1{' \
            -e '        s|#!.*perl|#!$(PERL_PATH_SQ)|' \
@@ -685,20 +767,15 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
            -e '}' \
            -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
-           $@.perl >$@+
-       chmod +x $@+
-       mv $@+ $@
-
-git-cherry-pick: git-revert
-       cp $< $@+
+           $@.perl >$@+ && \
+       chmod +x $@+ && \
        mv $@+ $@
 
 git-status: git-commit
-       cp $< $@+
-       mv $@+ $@
+       $(QUIET_GEN)cp $< $@+ && mv $@+ $@
 
 gitweb/gitweb.cgi: gitweb/gitweb.perl
-       rm -f $@ $@+
+       $(QUIET_GEN)rm -f $@ $@+ && \
        sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \
            -e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
            -e 's|++GIT_BINDIR++|$(bindir)|g' \
@@ -716,12 +793,12 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
            -e 's|++GITWEB_FAVICON++|$(GITWEB_FAVICON)|g' \
            -e 's|++GITWEB_SITE_HEADER++|$(GITWEB_SITE_HEADER)|g' \
            -e 's|++GITWEB_SITE_FOOTER++|$(GITWEB_SITE_FOOTER)|g' \
-           $< >$@+
-       chmod +x $@+
+           $< >$@+ && \
+       chmod +x $@+ && \
        mv $@+ $@
 
 git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
-       rm -f $@ $@+
+       $(QUIET_GEN)rm -f $@ $@+ && \
        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
            -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
@@ -729,15 +806,15 @@ git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/gitweb.css
            -e '/@@GITWEB_CGI@@/d' \
            -e '/@@GITWEB_CSS@@/r gitweb/gitweb.css' \
            -e '/@@GITWEB_CSS@@/d' \
-           $@.sh > $@+
-       chmod +x $@+
+           $@.sh > $@+ && \
+       chmod +x $@+ && \
        mv $@+ $@
 
 configure: configure.ac
-       rm -f $@ $<+
+       $(QUIET_GEN)rm -f $@ $<+ && \
        sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
-           $< > $<+
-       autoconf -o $@ $<+
+           $< > $<+ && \
+       autoconf -o $@ $<+ && \
        rm -f $<+
 
 # These can record GIT_VERSION
@@ -747,25 +824,25 @@ git$X git.spec \
        : GIT-VERSION-FILE
 
 %.o: %.c GIT-CFLAGS
-       $(CC) -o $*.o -c $(ALL_CFLAGS) $<
+       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
 %.o: %.S
-       $(CC) -o $*.o -c $(ALL_CFLAGS) $<
+       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
 
 exec_cmd.o: exec_cmd.c GIT-CFLAGS
-       $(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' $<
+       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' $<
 builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
-       $(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
+       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
 
 http.o: http.c GIT-CFLAGS
-       $(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<
+       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<
 
 ifdef NO_EXPAT
 http-fetch.o: http-fetch.c http.h GIT-CFLAGS
-       $(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $<
+       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $<
 endif
 
 git-%$X: %.o $(GITLIBS)
-       $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
+       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
 ssh-pull.o: ssh-fetch.c
 ssh-push.o: ssh-upload.c
@@ -779,11 +856,11 @@ git-imap-send$X: imap-send.o $(LIB_FILE)
 
 http.o http-fetch.o http-push.o: http.h
 git-http-fetch$X: fetch.o http.o http-fetch.o $(GITLIBS)
-       $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
+       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
                $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 
 git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
-       $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
+       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
                $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 
 $(LIB_OBJS) $(BUILTIN_OBJS) fetch.o: $(LIB_H)
@@ -791,7 +868,7 @@ $(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
 $(DIFF_OBJS): diffcore.h
 
 $(LIB_FILE): $(LIB_OBJS)
-       rm -f $@ && $(AR) rcs $@ $(LIB_OBJS)
+       $(QUIET_AR)rm -f $@ && $(AR) rcs $@ $(LIB_OBJS)
 
 XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
        xdiff/xmerge.o
@@ -799,7 +876,7 @@ $(XDIFF_OBJS): xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
        xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
 
 $(XDIFF_LIB): $(XDIFF_OBJS)
-       rm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS)
+       $(QUIET_AR)rm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS)
 
 
 perl/Makefile: perl/Git.pm perl/Makefile.PL GIT-CFLAGS
@@ -828,6 +905,20 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS
                echo "$$FLAGS" >GIT-CFLAGS; \
             fi
 
+### Detect Tck/Tk interpreter path changes
+ifndef NO_TCLTK
+TRACK_VARS = $(subst ','\'',-DTCLTK_PATH='$(TCLTK_PATH_SQ)')
+
+GIT-GUI-VARS: .FORCE-GIT-GUI-VARS
+       @VARS='$(TRACK_VARS)'; \
+           if test x"$$VARS" != x"`cat $@ 2>/dev/null`" ; then \
+               echo 1>&2 "    * new Tcl/Tk interpreter location"; \
+               echo "$$VARS" >$@; \
+            fi
+
+.PHONY: .FORCE-GIT-GUI-VARS
+endif
+
 ### Testing rules
 
 # GNU make supports exporting all variables by "export" without parameters.
@@ -868,10 +959,13 @@ install: all
        $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(bindir_SQ)'
        $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(gitexecdir_SQ)'
        $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
-       $(INSTALL) git$X gitk '$(DESTDIR_SQ)$(bindir_SQ)'
+       $(INSTALL) git$X '$(DESTDIR_SQ)$(bindir_SQ)'
        $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
        $(MAKE) -C perl prefix='$(prefix_SQ)' install
+ifndef NO_TCLTK
+       $(INSTALL) gitk-wish '$(DESTDIR_SQ)$(bindir_SQ)'/gitk
        $(MAKE) -C git-gui install
+endif
        if test 'z$(bindir_SQ)' != 'z$(gitexecdir_SQ)'; \
        then \
                ln -f '$(DESTDIR_SQ)$(bindir_SQ)/git$X' \
@@ -909,8 +1003,7 @@ dist: git.spec git-archive
        $(TAR) rf $(GIT_TARNAME).tar \
                $(GIT_TARNAME)/git.spec \
                $(GIT_TARNAME)/version \
-               $(GIT_TARNAME)/git-gui/version \
-               $(GIT_TARNAME)/git-gui/credits
+               $(GIT_TARNAME)/git-gui/version
        @rm -rf $(GIT_TARNAME)
        gzip -f -9 $(GIT_TARNAME).tar
 
@@ -940,7 +1033,7 @@ dist-doc:
 
 clean:
        rm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \
-               $(LIB_FILE) $(XDIFF_LIB)
+               test-chmtime$X $(LIB_FILE) $(XDIFF_LIB)
        rm -f $(ALL_PROGRAMS) $(BUILT_INS) git$X
        rm -f *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags
        rm -rf autom4te.cache
@@ -951,10 +1044,13 @@ clean:
        rm -f gitweb/gitweb.cgi
        $(MAKE) -C Documentation/ clean
        $(MAKE) -C perl clean
-       $(MAKE) -C git-gui clean
        $(MAKE) -C templates/ clean
        $(MAKE) -C t/ clean
-       rm -f GIT-VERSION-FILE GIT-CFLAGS
+ifndef NO_TCLTK
+       rm -f gitk-wish
+       $(MAKE) -C git-gui clean
+endif
+       rm -f GIT-VERSION-FILE GIT-CFLAGS GIT-GUI-VARS
 
 .PHONY: all install clean strip
 .PHONY: .FORCE-GIT-VERSION-FILE TAGS tags .FORCE-GIT-CFLAGS
@@ -968,7 +1064,7 @@ check-docs::
                git-merge-octopus | git-merge-ours | git-merge-recursive | \
                git-merge-resolve | git-merge-stupid | \
                git-add--interactive | git-fsck-objects | git-init-db | \
-               git-repo-config | \
+               git-repo-config | git-fetch--tool | \
                git-ssh-pull | git-ssh-push ) continue ;; \
                esac ; \
                test -f "Documentation/$$v.txt" || \
diff --git a/README b/README
index 441167cb8ad864b14c984ce9b58bf574c2b95357..548142c327a6790ff8821d67c2ee1eff7a656b52 100644 (file)
--- a/README
+++ b/README
@@ -38,3 +38,9 @@ requests, comments and patches to git@vger.kernel.org. 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.
index d5e055de6f26abba256cf32bed8dfb056bc6b29c..c543b1d1eedf821fe1e8c31d902a719bfc6ffb20 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes-1.5.1.txt
\ No newline at end of file
+Documentation/RelNotes-1.5.2.txt
\ No newline at end of file
index 87e16aa2200f90e2f12673e856040ed29ee7d119..9ec292590c49574dfd2a698772a406b5ccdc419e 100644 (file)
@@ -12,6 +12,8 @@
 static const char builtin_add_usage[] =
 "git-add [-n] [-v] [-f] [--interactive | -i] [--] <filepattern>...";
 
+static const char *excludes_file;
+
 static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
 {
        char *seen;
@@ -67,6 +69,8 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
        path = git_path("info/exclude");
        if (!access(path, R_OK))
                add_excludes_from_file(dir, path);
+       if (!access(excludes_file, R_OK))
+               add_excludes_from_file(dir, excludes_file);
 
        /*
         * Calculate common prefix for the pathspec, and
@@ -83,11 +87,23 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
        }
 
        /* Read the directory and prune it */
-       read_directory(dir, path, base, baselen);
+       read_directory(dir, path, base, baselen, pathspec);
        if (pathspec)
                prune_directory(dir, pathspec, baselen);
 }
 
+static int git_add_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "core.excludesfile")) {
+               if (!value)
+                       die("core.excludesfile without value");
+               excludes_file = xstrdup(value);
+               return 0;
+       }
+
+       return git_default_config(var, value);
+}
+
 static struct lock_file lock_file;
 
 static const char ignore_warning[] =
@@ -115,9 +131,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                exit(1);
        }
 
-       git_config(git_default_config);
+       git_config(git_add_config);
 
-       newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
+       newfd = hold_locked_index(&lock_file, 1);
 
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
@@ -189,11 +205,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        }
 
        for (i = 0; i < dir.nr; i++)
-               add_file_to_index(dir.entries[i]->name, verbose);
+               add_file_to_cache(dir.entries[i]->name, verbose);
 
        if (active_cache_changed) {
                if (write_cache(newfd, active_cache, active_nr) ||
-                   close(newfd) || commit_lock_file(&lock_file))
+                   close(newfd) || commit_locked_index(&lock_file))
                        die("Unable to write new index file");
        }
 
index dfa17167963d1318298208e880be1cae47d06ea9..fd92ef7174dae1586921ebd34233c93b381106de 100644 (file)
@@ -30,7 +30,7 @@ static int unidiff_zero;
 static int p_value = 1;
 static int p_value_known;
 static int check_index;
-static int write_index;
+static int update_index;
 static int cached;
 static int diffstat;
 static int numstat;
@@ -417,7 +417,7 @@ static int gitdiff_hdrend(const char *line, struct patch *patch)
 static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, const char *oldnew)
 {
        if (!orig_name && !isnull)
-               return find_name(line, NULL, 1, TERM_TAB);
+               return find_name(line, NULL, p_value, TERM_TAB);
 
        if (orig_name) {
                int len;
@@ -427,7 +427,7 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,
                len = strlen(name);
                if (isnull)
                        die("git-apply: bad git-diff - expected /dev/null, got %s on line %d", name, linenr);
-               another = find_name(line, NULL, 1, TERM_TAB);
+               another = find_name(line, NULL, p_value, TERM_TAB);
                if (!another || memcmp(another, name, len))
                        die("git-apply: bad git-diff - inconsistent %s filename on line %d", oldnew, linenr);
                free(another);
@@ -2308,7 +2308,7 @@ static void patch_stats(struct patch *patch)
 
 static void remove_file(struct patch *patch, int rmdir_empty)
 {
-       if (write_index) {
+       if (update_index) {
                if (remove_file_from_cache(patch->old_name) < 0)
                        die("unable to remove %s from index", patch->old_name);
                cache_tree_invalidate_path(active_cache_tree, patch->old_name);
@@ -2335,7 +2335,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
        int namelen = strlen(path);
        unsigned ce_size = cache_entry_size(namelen);
 
-       if (!write_index)
+       if (!update_index)
                return;
 
        ce = xcalloc(1, ce_size);
@@ -2355,7 +2355,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
 
 static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
 {
-       int fd;
+       int fd, converted;
        char *nbuf;
        unsigned long nsize;
 
@@ -2364,17 +2364,18 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
                 * terminated.
                 */
                return symlink(buf, path);
+
+       fd = open(path, O_CREAT | O_EXCL | O_WRONLY, (mode & 0100) ? 0777 : 0666);
+       if (fd < 0)
+               return -1;
+
        nsize = size;
        nbuf = (char *) buf;
-       if (convert_to_working_tree(path, &nbuf, &nsize)) {
-               free((char *) buf);
+       converted = convert_to_working_tree(path, &nbuf, &nsize);
+       if (converted) {
                buf = nbuf;
                size = nsize;
        }
-
-       fd = open(path, O_CREAT | O_EXCL | O_WRONLY, (mode & 0100) ? 0777 : 0666);
-       if (fd < 0)
-               return -1;
        while (size) {
                int written = xwrite(fd, buf, size);
                if (written < 0)
@@ -2386,6 +2387,8 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
        }
        if (close(fd) < 0)
                die("closing file %s: %s", path, strerror(errno));
+       if (converted)
+               free(nbuf);
        return 0;
 }
 
@@ -2659,10 +2662,10 @@ static int apply_patch(int fd, const char *filename, int inaccurate_eof)
        if (whitespace_error && (new_whitespace == error_on_whitespace))
                apply = 0;
 
-       write_index = check_index && apply;
-       if (write_index && newfd < 0)
-               newfd = hold_lock_file_for_update(&lock_file,
-                                                 get_index_file(), 1);
+       update_index = check_index && apply;
+       if (update_index && newfd < 0)
+               newfd = hold_locked_index(&lock_file, 1);
+
        if (check_index) {
                if (read_cache() < 0)
                        die("unable to read index file");
@@ -2867,9 +2870,9 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
                                whitespace_error == 1 ? "s" : "");
        }
 
-       if (write_index) {
+       if (update_index) {
                if (write_cache(newfd, active_cache, active_nr) ||
-                   close(newfd) || commit_lock_file(&lock_file))
+                   close(newfd) || commit_locked_index(&lock_file))
                        die("Unable to write new index file");
        }
 
index 2fae885f5c27f73820824b612d41fd37ab91239d..8ea6cb1efc4f988fb09051852f9e51fc88b5efd7 100644 (file)
@@ -252,6 +252,8 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 
        memset(&ar, 0, sizeof(ar));
        tree_idx = parse_archive_args(argc, argv, &ar);
+       if (prefix == NULL)
+               prefix = setup_git_directory();
 
        argv += tree_idx;
        parse_treeish_arg(argv, &ar.args, prefix);
index b51cdc71faeca467cd3a965db0ff84d1f087076d..60ec5354f11c61c49829d41e8c07d22573f16bc7 100644 (file)
@@ -180,16 +180,15 @@ struct scoreboard {
        int *lineno;
 };
 
-static int cmp_suspect(struct origin *a, struct origin *b)
+static inline int same_suspect(struct origin *a, struct origin *b)
 {
-       int cmp = hashcmp(a->commit->object.sha1, b->commit->object.sha1);
-       if (cmp)
-               return cmp;
-       return strcmp(a->path, b->path);
+       if (a == b)
+               return 1;
+       if (a->commit != b->commit)
+               return 0;
+       return !strcmp(a->path, b->path);
 }
 
-#define cmp_suspect(a, b) ( ((a)==(b)) ? 0 : cmp_suspect(a,b) )
-
 static void sanity_check_refcnt(struct scoreboard *);
 
 /*
@@ -202,7 +201,7 @@ static void coalesce(struct scoreboard *sb)
        struct blame_entry *ent, *next;
 
        for (ent = sb->ent; ent && (next = ent->next); ent = next) {
-               if (!cmp_suspect(ent->suspect, next->suspect) &&
+               if (same_suspect(ent->suspect, next->suspect) &&
                    ent->guilty == next->guilty &&
                    ent->s_lno + ent->num_lines == next->s_lno) {
                        ent->num_lines += next->num_lines;
@@ -775,7 +774,7 @@ static int find_last_in_target(struct scoreboard *sb, struct origin *target)
        int last_in_target = -1;
 
        for (e = sb->ent; e; e = e->next) {
-               if (e->guilty || cmp_suspect(e->suspect, target))
+               if (e->guilty || !same_suspect(e->suspect, target))
                        continue;
                if (last_in_target < e->s_lno + e->num_lines)
                        last_in_target = e->s_lno + e->num_lines;
@@ -795,7 +794,7 @@ static void blame_chunk(struct scoreboard *sb,
        struct blame_entry *e;
 
        for (e = sb->ent; e; e = e->next) {
-               if (e->guilty || cmp_suspect(e->suspect, target))
+               if (e->guilty || !same_suspect(e->suspect, target))
                        continue;
                if (same <= e->s_lno)
                        continue;
@@ -970,7 +969,7 @@ static int find_move_in_parent(struct scoreboard *sb,
        while (made_progress) {
                made_progress = 0;
                for (e = sb->ent; e; e = e->next) {
-                       if (e->guilty || cmp_suspect(e->suspect, target))
+                       if (e->guilty || !same_suspect(e->suspect, target))
                                continue;
                        find_copy_in_blob(sb, e, parent, split, &file_p);
                        if (split[1].suspect &&
@@ -1002,12 +1001,12 @@ static struct blame_list *setup_blame_list(struct scoreboard *sb,
        struct blame_list *blame_list = NULL;
 
        for (e = sb->ent, num_ents = 0; e; e = e->next)
-               if (!e->guilty && !cmp_suspect(e->suspect, target))
+               if (!e->guilty && same_suspect(e->suspect, target))
                        num_ents++;
        if (num_ents) {
                blame_list = xcalloc(num_ents, sizeof(struct blame_list));
                for (e = sb->ent, i = 0; e; e = e->next)
-                       if (!e->guilty && !cmp_suspect(e->suspect, target))
+                       if (!e->guilty && same_suspect(e->suspect, target))
                                blame_list[i++].ent = e;
        }
        *num_ents_p = num_ents;
@@ -1137,7 +1136,7 @@ static void pass_whole_blame(struct scoreboard *sb,
                origin->file.ptr = NULL;
        }
        for (e = sb->ent; e; e = e->next) {
-               if (cmp_suspect(e->suspect, origin))
+               if (!same_suspect(e->suspect, origin))
                        continue;
                origin_incref(porigin);
                origin_decref(e->suspect);
@@ -1443,7 +1442,7 @@ static void assign_blame(struct scoreboard *sb, struct rev_info *revs, int opt)
 
                /* Take responsibility for the remaining entries */
                for (ent = sb->ent; ent; ent = ent->next)
-                       if (!cmp_suspect(ent->suspect, suspect))
+                       if (same_suspect(ent->suspect, suspect))
                                found_guilty_entry(ent);
                origin_decref(suspect);
 
index 06d8a8ce0432134f994aa30ac4133baf4ba7fef5..7408285050a0f41a33d31c73e79c2fdefe567593 100644 (file)
@@ -12,7 +12,7 @@
 #include "builtin.h"
 
 static const char builtin_branch_usage[] =
-  "git-branch [-r] (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>] | (-m | -M) [<oldbranch>] <newbranch> | [--color | --no-color] [-r | -a] [-v [--abbrev=<length> | --no-abbrev]]";
+  "git-branch [-r] (-d | -D) <branchname> | [--track | --no-track] [-l] [-f] <branchname> [<start-point>] | (-m | -M) [<oldbranch>] <newbranch> | [--color | --no-color] [-r | -a] [-v [--abbrev=<length> | --no-abbrev]]";
 
 #define REF_UNKNOWN_TYPE    0x00
 #define REF_LOCAL_BRANCH    0x01
@@ -22,6 +22,8 @@ static const char builtin_branch_usage[] =
 static const char *head;
 static unsigned char head_sha1[20];
 
+static int branch_track_remotes;
+
 static int branch_use_color;
 static char branch_colors[][COLOR_MAXLEN] = {
        "\033[m",       /* reset */
@@ -64,6 +66,9 @@ int git_branch_config(const char *var, const char *value)
                color_parse(value, var, branch_colors[slot]);
                return 0;
        }
+       if (!strcmp(var, "branch.autosetupmerge"))
+               branch_track_remotes = git_config_bool(var, value);
+
        return git_default_config(var, value);
 }
 
@@ -309,14 +314,119 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev)
        free_ref_list(&ref_list);
 }
 
+static char *config_repo;
+static char *config_remote;
+static const char *start_ref;
+static int start_len;
+static int base_len;
+
+static int get_remote_branch_name(const char *value)
+{
+       const char *colon;
+       const char *end;
+
+       if (*value == '+')
+               value++;
+
+       colon = strchr(value, ':');
+       if (!colon)
+               return 0;
+
+       end = value + strlen(value);
+
+       /* Try an exact match first.  */
+       if (!strcmp(colon + 1, start_ref)) {
+               /* Truncate the value before the colon.  */
+               nfasprintf(&config_repo, "%.*s", colon - value, value);
+               return 1;
+       }
+
+       /* Try with a wildcard match now.  */
+       if (end - value > 2 && end[-2] == '/' && end[-1] == '*' &&
+           colon - value > 2 && colon[-2] == '/' && colon[-1] == '*' &&
+           (end - 2) - (colon + 1) == base_len &&
+           !strncmp(colon + 1, start_ref, base_len)) {
+               /* Replace the star with the remote branch name.  */
+               nfasprintf(&config_repo, "%.*s%s",
+                          (colon - 2) - value, value,
+                          start_ref + base_len);
+               return 1;
+       }
+
+       return 0;
+}
+
+static int get_remote_config(const char *key, const char *value)
+{
+       const char *var;
+       if (prefixcmp(key, "remote."))
+               return 0;
+
+       var = strrchr(key, '.');
+       if (var == key + 6)
+               return 0;
+
+       if (!strcmp(var, ".fetch") && get_remote_branch_name(value))
+               nfasprintf(&config_remote, "%.*s", var - (key + 7), key + 7);
+
+       return 0;
+}
+
+static void set_branch_merge(const char *name, const char *config_remote,
+                            const char *config_repo)
+{
+       char key[1024];
+       if (sizeof(key) <=
+           snprintf(key, sizeof(key), "branch.%s.remote", name))
+               die("what a long branch name you have!");
+       git_config_set(key, config_remote);
+
+       /*
+        * We do not have to check if we have enough space for
+        * the 'merge' key, since it's shorter than the
+        * previous 'remote' key, which we already checked.
+        */
+       snprintf(key, sizeof(key), "branch.%s.merge", name);
+       git_config_set(key, config_repo);
+}
+
+static void set_branch_defaults(const char *name, const char *real_ref)
+{
+       const char *slash = strrchr(real_ref, '/');
+
+       if (!slash)
+               return;
+
+       start_ref = real_ref;
+       start_len = strlen(real_ref);
+       base_len = slash - real_ref;
+       git_config(get_remote_config);
+       if (!config_repo && !config_remote &&
+           !prefixcmp(real_ref, "refs/heads/")) {
+               set_branch_merge(name, ".", real_ref);
+               printf("Branch %s set up to track local branch %s.\n",
+                      name, real_ref);
+       }
+
+       if (config_repo && config_remote) {
+               set_branch_merge(name, config_remote, config_repo);
+               printf("Branch %s set up to track remote branch %s.\n",
+                      name, real_ref);
+       }
+
+       if (config_repo)
+               free(config_repo);
+       if (config_remote)
+               free(config_remote);
+}
+
 static void create_branch(const char *name, const char *start_name,
-                         unsigned char *start_sha1,
-                         int force, int reflog)
+                         int force, int reflog, int track)
 {
        struct ref_lock *lock;
        struct commit *commit;
        unsigned char sha1[20];
-       char ref[PATH_MAX], msg[PATH_MAX + 20];
+       char *real_ref, ref[PATH_MAX], msg[PATH_MAX + 20];
        int forcing = 0;
 
        snprintf(ref, sizeof ref, "refs/heads/%s", name);
@@ -331,12 +441,23 @@ static void create_branch(const char *name, const char *start_name,
                forcing = 1;
        }
 
-       if (start_sha1)
-               /* detached HEAD */
-               hashcpy(sha1, start_sha1);
-       else if (get_sha1(start_name, sha1))
+       real_ref = NULL;
+       if (get_sha1(start_name, sha1))
                die("Not a valid object name: '%s'.", start_name);
 
+       switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) {
+       case 0:
+               /* Not branching from any existing branch */
+               real_ref = NULL;
+               break;
+       case 1:
+               /* Unique completion -- good */
+               break;
+       default:
+               die("Ambiguous object name: '%s'.", start_name);
+               break;
+       }
+
        if ((commit = lookup_commit_reference(sha1)) == NULL)
                die("Not a valid branch point: '%s'.", start_name);
        hashcpy(sha1, commit->object.sha1);
@@ -355,14 +476,24 @@ static void create_branch(const char *name, const char *start_name,
                snprintf(msg, sizeof msg, "branch: Created from %s",
                         start_name);
 
+       /* When branching off a remote branch, set up so that git-pull
+          automatically merges from there.  So far, this is only done for
+          remotes registered via .git/config.  */
+       if (real_ref && track)
+               set_branch_defaults(name, real_ref);
+
        if (write_ref_sha1(lock, sha1, msg) < 0)
                die("Failed to write ref: %s.", strerror(errno));
+
+       if (real_ref)
+               free(real_ref);
 }
 
 static void rename_branch(const char *oldname, const char *newname, int force)
 {
        char oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100];
        unsigned char sha1[20];
+       char oldsection[PATH_MAX], newsection[PATH_MAX];
 
        if (!oldname)
                die("cannot rename the current branch while not on any.");
@@ -391,6 +522,11 @@ static void rename_branch(const char *oldname, const char *newname, int force)
        /* no need to pass logmsg here as HEAD didn't really move */
        if (!strcmp(oldname, head) && create_symref("HEAD", newref, NULL))
                die("Branch renamed to %s, but HEAD is not updated!", newname);
+
+       snprintf(oldsection, sizeof(oldsection), "branch.%s", oldref + 11);
+       snprintf(newsection, sizeof(newsection), "branch.%s", newref + 11);
+       if (git_config_rename_section(oldsection, newsection) < 0)
+               die("Branch is renamed, but update of config-file failed");
 }
 
 int cmd_branch(int argc, const char **argv, const char *prefix)
@@ -398,11 +534,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        int delete = 0, force_delete = 0, force_create = 0;
        int rename = 0, force_rename = 0;
        int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
-       int reflog = 0;
+       int reflog = 0, track;
        int kinds = REF_LOCAL_BRANCH;
        int i;
 
        git_config(git_branch_config);
+       track = branch_track_remotes;
 
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
@@ -413,6 +550,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                        i++;
                        break;
                }
+               if (!strcmp(arg, "--track")) {
+                       track = 1;
+                       continue;
+               }
+               if (!strcmp(arg, "--no-track")) {
+                       track = 0;
+                       continue;
+               }
                if (!strcmp(arg, "-d")) {
                        delete = 1;
                        continue;
@@ -498,10 +643,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                rename_branch(head, argv[i], force_rename);
        else if (rename && (i == argc - 2))
                rename_branch(argv[i], argv[i + 1], force_rename);
-       else if (i == argc - 1)
-               create_branch(argv[i], head, head_sha1, force_create, reflog);
-       else if (i == argc - 2)
-               create_branch(argv[i], argv[i+1], NULL, force_create, reflog);
+       else if (i == argc - 1 || i == argc - 2)
+               create_branch(argv[i], (i == argc - 2) ? argv[i+1] : head,
+                             force_create, reflog, track);
        else
                usage(builtin_branch_usage);
 
index 279b8f8e582665dda3c99d800094db2f5cf5af99..d1635a0a6b009ecb6706084828abd0e3928f2b8d 100644 (file)
@@ -4,7 +4,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "list-objects.h"
-#include "exec_cmd.h"
+#include "run-command.h"
 
 /*
  * Basic handler for bundle files to connect repositories via sneakernet.
@@ -87,7 +87,7 @@ static int read_header(const char *path, struct bundle_header *header) {
                if (buffer[len - 1] == '\n')
                        buffer[len - 1] = '\0';
                if (get_sha1_hex(buffer + offset, sha1)) {
-                       warn("unrecognized header: %s", buffer);
+                       warning("unrecognized header: %s", buffer);
                        continue;
                }
                delim = buffer[40 + offset];
@@ -99,68 +99,28 @@ static int read_header(const char *path, struct bundle_header *header) {
        return fd;
 }
 
-/* if in && *in >= 0, take that as input file descriptor instead */
-static int fork_with_pipe(const char **argv, int *in, int *out)
+static int list_refs(struct ref_list *r, int argc, const char **argv)
 {
-       int needs_in, needs_out;
-       int fdin[2], fdout[2], pid;
-
-       needs_in = in && *in < 0;
-       if (needs_in) {
-               if (pipe(fdin) < 0)
-                       return error("could not setup pipe");
-               *in = fdin[1];
-       }
-
-       needs_out = out && *out < 0;
-       if (needs_out) {
-               if (pipe(fdout) < 0)
-                       return error("could not setup pipe");
-               *out = fdout[0];
-       }
+       int i;
 
-       if ((pid = fork()) < 0) {
-               if (needs_in) {
-                       close(fdin[0]);
-                       close(fdin[1]);
-               }
-               if (needs_out) {
-                       close(fdout[0]);
-                       close(fdout[1]);
-               }
-               return error("could not fork");
-       }
-       if (!pid) {
-               if (needs_in) {
-                       dup2(fdin[0], 0);
-                       close(fdin[0]);
-                       close(fdin[1]);
-               } else if (in) {
-                       dup2(*in, 0);
-                       close(*in);
-               }
-               if (needs_out) {
-                       dup2(fdout[1], 1);
-                       close(fdout[0]);
-                       close(fdout[1]);
-               } else if (out) {
-                       dup2(*out, 1);
-                       close(*out);
+       for (i = 0; i < r->nr; i++) {
+               if (argc > 1) {
+                       int j;
+                       for (j = 1; j < argc; j++)
+                               if (!strcmp(r->list[i].name, argv[j]))
+                                       break;
+                       if (j == argc)
+                               continue;
                }
-               exit(execv_git_cmd(argv));
+               printf("%s %s\n", sha1_to_hex(r->list[i].sha1),
+                               r->list[i].name);
        }
-       if (needs_in)
-               close(fdin[0]);
-       else if (in)
-               close(*in);
-       if (needs_out)
-               close(fdout[1]);
-       else if (out)
-               close(*out);
-       return pid;
+       return 0;
 }
 
-static int verify_bundle(struct bundle_header *header)
+#define PREREQ_MARK (1u<<16)
+
+static int verify_bundle(struct bundle_header *header, int verbose)
 {
        /*
         * Do fast check, then if any prereqs are missing then go line by line
@@ -179,7 +139,7 @@ static int verify_bundle(struct bundle_header *header)
                struct ref_list_entry *e = p->list + i;
                struct object *o = parse_object(e->sha1);
                if (o) {
-                       o->flags |= BOUNDARY_SHOW;
+                       o->flags |= PREREQ_MARK;
                        add_pending_object(&revs, o, e->name);
                        continue;
                }
@@ -187,7 +147,7 @@ static int verify_bundle(struct bundle_header *header)
                        error(message);
                error("%s %s", sha1_to_hex(e->sha1), e->name);
        }
-       if (revs.pending.nr == 0)
+       if (revs.pending.nr != p->nr)
                return ret;
        req_nr = revs.pending.nr;
        setup_revisions(2, argv, &revs, NULL);
@@ -202,7 +162,7 @@ static int verify_bundle(struct bundle_header *header)
 
        i = req_nr;
        while (i && (commit = get_revision(&revs)))
-               if (commit->object.flags & BOUNDARY_SHOW)
+               if (commit->object.flags & PREREQ_MARK)
                        i--;
 
        for (i = 0; i < req_nr; i++)
@@ -216,56 +176,24 @@ static int verify_bundle(struct bundle_header *header)
        for (i = 0; i < refs.nr; i++)
                clear_commit_marks((struct commit *)refs.objects[i].item, -1);
 
+       if (verbose) {
+               struct ref_list *r;
+
+               r = &header->references;
+               printf("The bundle contains %d ref%s\n",
+                      r->nr, (1 < r->nr) ? "s" : "");
+               list_refs(r, 0, NULL);
+               r = &header->prerequisites;
+               printf("The bundle requires these %d ref%s\n",
+                      r->nr, (1 < r->nr) ? "s" : "");
+               list_refs(r, 0, NULL);
+       }
        return ret;
 }
 
 static int list_heads(struct bundle_header *header, int argc, const char **argv)
 {
-       int i;
-       struct ref_list *r = &header->references;
-
-       for (i = 0; i < r->nr; i++) {
-               if (argc > 1) {
-                       int j;
-                       for (j = 1; j < argc; j++)
-                               if (!strcmp(r->list[i].name, argv[j]))
-                                       break;
-                       if (j == argc)
-                               continue;
-               }
-               printf("%s %s\n", sha1_to_hex(r->list[i].sha1),
-                               r->list[i].name);
-       }
-       return 0;
-}
-
-static void show_commit(struct commit *commit)
-{
-       write_or_die(1, sha1_to_hex(commit->object.sha1), 40);
-       write_or_die(1, "\n", 1);
-       if (commit->parents) {
-               free_commit_list(commit->parents);
-               commit->parents = NULL;
-       }
-}
-
-static void show_object(struct object_array_entry *p)
-{
-       /* An object with name "foo\n0000000..." can be used to
-        * confuse downstream git-pack-objects very badly.
-        */
-       const char *ep = strchr(p->name, '\n');
-       int len = ep ? ep - p->name : strlen(p->name);
-       write_or_die(1, sha1_to_hex(p->item->sha1), 40);
-       write_or_die(1, " ", 1);
-       if (len)
-               write_or_die(1, p->name, len);
-       write_or_die(1, "\n", 1);
-}
-
-static void show_edge(struct commit *commit)
-{
-       ; /* nothing to do */
+       return list_refs(&header->references, argc, argv);
 }
 
 static int create_bundle(struct bundle_header *header, const char *path,
@@ -273,61 +201,86 @@ static int create_bundle(struct bundle_header *header, const char *path,
 {
        int bundle_fd = -1;
        const char **argv_boundary = xmalloc((argc + 4) * sizeof(const char *));
-       const char **argv_pack = xmalloc(4 * sizeof(const char *));
-       int pid, in, out, i, status;
+       const char **argv_pack = xmalloc(5 * sizeof(const char *));
+       int i, ref_count = 0;
        char buffer[1024];
        struct rev_info revs;
+       struct child_process rls;
 
        bundle_fd = (!strcmp(path, "-") ? 1 :
-                       open(path, O_CREAT | O_WRONLY, 0666));
+                       open(path, O_CREAT | O_EXCL | O_WRONLY, 0666));
        if (bundle_fd < 0)
-               return error("Could not write to '%s'", path);
+               return error("Could not create '%s': %s", path, strerror(errno));
 
        /* write signature */
        write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
 
+       /* init revs to list objects for pack-objects later */
+       save_commit_buffer = 0;
+       init_revisions(&revs, NULL);
+
        /* write prerequisites */
        memcpy(argv_boundary + 3, argv + 1, argc * sizeof(const char *));
        argv_boundary[0] = "rev-list";
        argv_boundary[1] = "--boundary";
        argv_boundary[2] = "--pretty=oneline";
        argv_boundary[argc + 2] = NULL;
-       out = -1;
-       pid = fork_with_pipe(argv_boundary, NULL, &out);
-       if (pid < 0)
+       memset(&rls, 0, sizeof(rls));
+       rls.argv = argv_boundary;
+       rls.out = -1;
+       rls.git_cmd = 1;
+       if (start_command(&rls))
                return -1;
-       while ((i = read_string(out, buffer, sizeof(buffer))) > 0)
-               if (buffer[0] == '-')
+       while ((i = read_string(rls.out, buffer, sizeof(buffer))) > 0) {
+               unsigned char sha1[20];
+               if (buffer[0] == '-') {
                        write_or_die(bundle_fd, buffer, i);
-       while ((i = waitpid(pid, &status, 0)) < 0)
-               if (errno != EINTR)
-                       return error("rev-list died");
-       if (!WIFEXITED(status) || WEXITSTATUS(status))
-               return error("rev-list died %d", WEXITSTATUS(status));
+                       if (!get_sha1_hex(buffer + 1, sha1)) {
+                               struct object *object = parse_object(sha1);
+                               object->flags |= UNINTERESTING;
+                               add_pending_object(&revs, object, buffer);
+                       }
+               } else if (!get_sha1_hex(buffer, sha1)) {
+                       struct object *object = parse_object(sha1);
+                       object->flags |= SHOWN;
+               }
+       }
+       if (finish_command(&rls))
+               return error("rev-list died");
 
        /* write references */
-       save_commit_buffer = 0;
-       init_revisions(&revs, NULL);
-       revs.tag_objects = 1;
-       revs.tree_objects = 1;
-       revs.blob_objects = 1;
        argc = setup_revisions(argc, argv, &revs, NULL);
        if (argc > 1)
                return error("unrecognized argument: %s'", argv[1]);
+
        for (i = 0; i < revs.pending.nr; i++) {
                struct object_array_entry *e = revs.pending.objects + i;
-               if (!(e->item->flags & UNINTERESTING)) {
-                       unsigned char sha1[20];
-                       char *ref;
-                       if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
-                               continue;
-                       write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
-                       write_or_die(bundle_fd, " ", 1);
-                       write_or_die(bundle_fd, ref, strlen(ref));
-                       write_or_die(bundle_fd, "\n", 1);
-                       free(ref);
+               unsigned char sha1[20];
+               char *ref;
+
+               if (e->item->flags & UNINTERESTING)
+                       continue;
+               if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
+                       continue;
+               /*
+                * Make sure the refs we wrote out is correct; --max-count and
+                * other limiting options could have prevented all the tips
+                * from getting output.
+                */
+               if (!(e->item->flags & SHOWN)) {
+                       warning("ref '%s' is excluded by the rev-list options",
+                               e->name);
+                       continue;
                }
+               ref_count++;
+               write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
+               write_or_die(bundle_fd, " ", 1);
+               write_or_die(bundle_fd, ref, strlen(ref));
+               write_or_die(bundle_fd, "\n", 1);
+               free(ref);
        }
+       if (!ref_count)
+               die ("Refusing to create empty bundle.");
 
        /* end header */
        write_or_die(bundle_fd, "\n", 1);
@@ -336,23 +289,23 @@ static int create_bundle(struct bundle_header *header, const char *path,
        argv_pack[0] = "pack-objects";
        argv_pack[1] = "--all-progress";
        argv_pack[2] = "--stdout";
-       argv_pack[3] = NULL;
-       in = -1;
-       out = bundle_fd;
-       pid = fork_with_pipe(argv_pack, &in, &out);
-       if (pid < 0)
+       argv_pack[3] = "--thin";
+       argv_pack[4] = NULL;
+       memset(&rls, 0, sizeof(rls));
+       rls.argv = argv_pack;
+       rls.in = -1;
+       rls.out = bundle_fd;
+       rls.git_cmd = 1;
+       if (start_command(&rls))
                return error("Could not spawn pack-objects");
-       close(1);
-       dup2(in, 1);
-       close(in);
-       prepare_revision_walk(&revs);
-       mark_edges_uninteresting(revs.commits, &revs, show_edge);
-       traverse_commit_list(&revs, show_commit, show_object);
-       close(1);
-       while (waitpid(pid, &status, 0) < 0)
-               if (errno != EINTR)
-                       return -1;
-       if (!WIFEXITED(status) || WEXITSTATUS(status))
+       for (i = 0; i < revs.pending.nr; i++) {
+               struct object *object = revs.pending.objects[i].item;
+               if (object->flags & UNINTERESTING)
+                       write(rls.in, "^", 1);
+               write(rls.in, sha1_to_hex(object->sha1), 40);
+               write(rls.in, "\n", 1);
+       }
+       if (finish_command(&rls))
                return error ("pack-objects died");
        return 0;
 }
@@ -360,21 +313,19 @@ static int create_bundle(struct bundle_header *header, const char *path,
 static int unbundle(struct bundle_header *header, int bundle_fd,
                int argc, const char **argv)
 {
-       const char *argv_index_pack[] = {"index-pack", "--stdin", NULL};
-       int pid, status, dev_null;
+       const char *argv_index_pack[] = {"index-pack",
+               "--fix-thin", "--stdin", NULL};
+       struct child_process ip;
 
-       if (verify_bundle(header))
+       if (verify_bundle(header, 0))
                return -1;
-       dev_null = open("/dev/null", O_WRONLY);
-       pid = fork_with_pipe(argv_index_pack, &bundle_fd, &dev_null);
-       if (pid < 0)
-               return error("Could not spawn index-pack");
-       while (waitpid(pid, &status, 0) < 0)
-               if (errno != EINTR)
-                       return error("index-pack died");
-       if (!WIFEXITED(status) || WEXITSTATUS(status))
-               return error("index-pack exited with status %d",
-                               WEXITSTATUS(status));
+       memset(&ip, 0, sizeof(ip));
+       ip.argv = argv_index_pack;
+       ip.in = bundle_fd;
+       ip.no_stdout = 1;
+       ip.git_cmd = 1;
+       if (run_command(&ip))
+               return error("index-pack died");
        return list_heads(header, argc, argv);
 }
 
@@ -402,12 +353,12 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
 
        memset(&header, 0, sizeof(header));
        if (strcmp(cmd, "create") &&
-                       !(bundle_fd = read_header(bundle_file, &header)))
+                       (bundle_fd = read_header(bundle_file, &header)) < 0)
                return 1;
 
        if (!strcmp(cmd, "verify")) {
                close(bundle_fd);
-               if (verify_bundle(&header))
+               if (verify_bundle(&header, 1))
                        return 1;
                fprintf(stderr, "%s is okay\n", bundle_file);
                return 0;
@@ -427,4 +378,3 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
        } else
                usage(bundle_usage);
 }
-
index afe4b0e4520f47f1dace1383bfc2b364b1b1def0..8460f97b6637127d78b58caf2e29d25f3ad0b5a0 100644 (file)
@@ -202,10 +202,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
                if (!strcmp(arg, "-u") || !strcmp(arg, "--index")) {
                        state.refresh_cache = 1;
                        if (newfd < 0)
-                               newfd = hold_lock_file_for_update
-                                       (&lock_file, get_index_file(), 1);
-                       if (newfd < 0)
-                               die("cannot open index.lock file.");
+                               newfd = hold_locked_index(&lock_file, 1);
                        continue;
                }
                if (!strcmp(arg, "-z")) {
@@ -302,7 +299,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
 
        if (0 <= newfd &&
            (write_cache(newfd, active_cache, active_nr) ||
-            close(newfd) || commit_lock_file(&lock_file)))
+            close(newfd) || commit_locked_index(&lock_file)))
                die("Unable to write new index file");
        return 0;
 }
index aec83384298042fc4509605299f82e82745ae675..6ba5077a2be6619f110280622cf46a7f4cfb8b01 100644 (file)
@@ -17,6 +17,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
 {
        struct rev_info rev;
        int nongit = 0;
+       int result;
 
        prefix = setup_git_directory_gently(&nongit);
        init_revisions(&rev, prefix);
@@ -29,5 +30,6 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
                argc = setup_revisions(argc, argv, &rev, NULL);
        if (!rev.diffopt.output_format)
                rev.diffopt.output_format = DIFF_FORMAT_RAW;
-       return run_diff_files_cmd(&rev, argc, argv);
+       result = run_diff_files_cmd(&rev, argc, argv);
+       return rev.diffopt.exit_with_status ? rev.diffopt.has_changes: result;
 }
index 083599d5c4c174cfab7c148428630534e4cd8174..d90eba95a6be17bd0486e0311c2657b1f69ab7d9 100644 (file)
@@ -14,6 +14,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
        struct rev_info rev;
        int cached = 0;
        int i;
+       int result;
 
        init_revisions(&rev, prefix);
        git_config(git_default_config); /* no "diff" UI options */
@@ -42,5 +43,6 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
                perror("read_cache");
                return -1;
        }
-       return run_diff_index(&rev, cached);
+       result = run_diff_index(&rev, cached);
+       return rev.diffopt.exit_with_status ? rev.diffopt.has_changes: result;
 }
index 24cb2d7f84064d7833fa04f33aeca6eafc8b931d..0b591c87169ff4b8c2173bedb26d6ed1a8a84b68 100644 (file)
@@ -118,7 +118,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
        }
 
        if (!read_stdin)
-               return 0;
+               return opt->diffopt.exit_with_status ?
+                   opt->diffopt.has_changes: 0;
 
        if (opt->diffopt.detect_rename)
                opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
@@ -133,5 +134,5 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
                else
                        diff_tree_stdin(line);
        }
-       return 0;
+       return opt->diffopt.exit_with_status ? opt->diffopt.has_changes: 0;
 }
index 4efbb8237bd49e8717a42833b2d9b2db064b45ac..21d13f0b30359295b8385754fccb4bb71f995dba 100644 (file)
@@ -190,6 +190,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
        const char *path = NULL;
        struct blobinfo blob[2];
        int nongit = 0;
+       int result = 0;
 
        /*
         * We could get N tree-ish in the rev.pending_objects list.
@@ -292,17 +293,17 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
        if (!ents) {
                switch (blobs) {
                case 0:
-                       return run_diff_files_cmd(&rev, argc, argv);
+                       result = run_diff_files_cmd(&rev, argc, argv);
                        break;
                case 1:
                        if (paths != 1)
                                usage(builtin_diff_usage);
-                       return builtin_diff_b_f(&rev, argc, argv, blob, path);
+                       result = builtin_diff_b_f(&rev, argc, argv, blob, path);
                        break;
                case 2:
                        if (paths)
                                usage(builtin_diff_usage);
-                       return builtin_diff_blobs(&rev, argc, argv, blob);
+                       result = builtin_diff_blobs(&rev, argc, argv, blob);
                        break;
                default:
                        usage(builtin_diff_usage);
@@ -311,19 +312,21 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
        else if (blobs)
                usage(builtin_diff_usage);
        else if (ents == 1)
-               return builtin_diff_index(&rev, argc, argv);
+               result = builtin_diff_index(&rev, argc, argv);
        else if (ents == 2)
-               return builtin_diff_tree(&rev, argc, argv, ent);
+               result = builtin_diff_tree(&rev, argc, argv, ent);
        else if ((ents == 3) && (ent[0].item->flags & UNINTERESTING)) {
                /* diff A...B where there is one sane merge base between
                 * A and B.  We have ent[0] == merge-base, ent[1] == A,
                 * and ent[2] == B.  Show diff between the base and B.
                 */
                ent[1] = ent[2];
-               return builtin_diff_tree(&rev, argc, argv, ent);
+               result = builtin_diff_tree(&rev, argc, argv, ent);
        }
        else
-               return builtin_diff_combined(&rev, argc, argv,
+               result = builtin_diff_combined(&rev, argc, argv,
                                             ent, ents);
-       usage(builtin_diff_usage);
+       if (rev.diffopt.exit_with_status)
+               result = rev.diffopt.has_changes;
+       return result;
 }
diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
new file mode 100644 (file)
index 0000000..e9d6764
--- /dev/null
@@ -0,0 +1,505 @@
+#include "cache.h"
+#include "refs.h"
+#include "commit.h"
+
+#define CHUNK_SIZE 1024
+
+static char *get_stdin(void)
+{
+       int offset = 0;
+       char *data = xmalloc(CHUNK_SIZE);
+
+       while (1) {
+               int cnt = xread(0, data + offset, CHUNK_SIZE);
+               if (cnt < 0)
+                       die("error reading standard input: %s",
+                           strerror(errno));
+               if (cnt == 0) {
+                       data[offset] = 0;
+                       break;
+               }
+               offset += cnt;
+               data = xrealloc(data, offset + CHUNK_SIZE);
+       }
+       return data;
+}
+
+static void show_new(enum object_type type, unsigned char *sha1_new)
+{
+       fprintf(stderr, "  %s: %s\n", typename(type),
+               find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
+}
+
+static int update_ref(const char *action,
+                     const char *refname,
+                     unsigned char *sha1,
+                     unsigned char *oldval)
+{
+       int len;
+       char msg[1024];
+       char *rla = getenv("GIT_REFLOG_ACTION");
+       static struct ref_lock *lock;
+
+       if (!rla)
+               rla = "(reflog update)";
+       len = snprintf(msg, sizeof(msg), "%s: %s", rla, action);
+       if (sizeof(msg) <= len)
+               die("insanely long action");
+       lock = lock_any_ref_for_update(refname, oldval);
+       if (!lock)
+               return 1;
+       if (write_ref_sha1(lock, sha1, msg) < 0)
+               return 1;
+       return 0;
+}
+
+static int update_local_ref(const char *name,
+                           const char *new_head,
+                           const char *note,
+                           int verbose, int force)
+{
+       unsigned char sha1_old[20], sha1_new[20];
+       char oldh[41], newh[41];
+       struct commit *current, *updated;
+       enum object_type type;
+
+       if (get_sha1_hex(new_head, sha1_new))
+               die("malformed object name %s", new_head);
+
+       type = sha1_object_info(sha1_new, NULL);
+       if (type < 0)
+               die("object %s not found", new_head);
+
+       if (!*name) {
+               /* Not storing */
+               if (verbose) {
+                       fprintf(stderr, "* fetched %s\n", note);
+                       show_new(type, sha1_new);
+               }
+               return 0;
+       }
+
+       if (get_sha1(name, sha1_old)) {
+               char *msg;
+       just_store:
+               /* new ref */
+               if (!strncmp(name, "refs/tags/", 10))
+                       msg = "storing tag";
+               else
+                       msg = "storing head";
+               fprintf(stderr, "* %s: storing %s\n",
+                       name, note);
+               show_new(type, sha1_new);
+               return update_ref(msg, name, sha1_new, NULL);
+       }
+
+       if (!hashcmp(sha1_old, sha1_new)) {
+               if (verbose) {
+                       fprintf(stderr, "* %s: same as %s\n", name, note);
+                       show_new(type, sha1_new);
+               }
+               return 0;
+       }
+
+       if (!strncmp(name, "refs/tags/", 10)) {
+               fprintf(stderr, "* %s: updating with %s\n", name, note);
+               show_new(type, sha1_new);
+               return update_ref("updating tag", name, sha1_new, NULL);
+       }
+
+       current = lookup_commit_reference(sha1_old);
+       updated = lookup_commit_reference(sha1_new);
+       if (!current || !updated)
+               goto just_store;
+
+       strcpy(oldh, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
+       strcpy(newh, find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
+
+       if (in_merge_bases(current, &updated, 1)) {
+               fprintf(stderr, "* %s: fast forward to %s\n",
+                       name, note);
+               fprintf(stderr, "  old..new: %s..%s\n", oldh, newh);
+               return update_ref("fast forward", name, sha1_new, sha1_old);
+       }
+       if (!force) {
+               fprintf(stderr,
+                       "* %s: not updating to non-fast forward %s\n",
+                       name, note);
+               fprintf(stderr,
+                       "  old...new: %s...%s\n", oldh, newh);
+               return 1;
+       }
+       fprintf(stderr,
+               "* %s: forcing update to non-fast forward %s\n",
+               name, note);
+       fprintf(stderr, "  old...new: %s...%s\n", oldh, newh);
+       return update_ref("forced-update", name, sha1_new, sha1_old);
+}
+
+static int append_fetch_head(FILE *fp,
+                            const char *head, const char *remote,
+                            const char *remote_name, const char *remote_nick,
+                            const char *local_name, int not_for_merge,
+                            int verbose, int force)
+{
+       struct commit *commit;
+       int remote_len, i, note_len;
+       unsigned char sha1[20];
+       char note[1024];
+       const char *what, *kind;
+
+       if (get_sha1(head, sha1))
+               return error("Not a valid object name: %s", head);
+       commit = lookup_commit_reference(sha1);
+       if (!commit)
+               not_for_merge = 1;
+
+       if (!strcmp(remote_name, "HEAD")) {
+               kind = "";
+               what = "";
+       }
+       else if (!strncmp(remote_name, "refs/heads/", 11)) {
+               kind = "branch";
+               what = remote_name + 11;
+       }
+       else if (!strncmp(remote_name, "refs/tags/", 10)) {
+               kind = "tag";
+               what = remote_name + 10;
+       }
+       else if (!strncmp(remote_name, "refs/remotes/", 13)) {
+               kind = "remote branch";
+               what = remote_name + 13;
+       }
+       else {
+               kind = "";
+               what = remote_name;
+       }
+
+       remote_len = strlen(remote);
+       for (i = remote_len - 1; remote[i] == '/' && 0 <= i; i--)
+               ;
+       remote_len = i + 1;
+       if (4 < i && !strncmp(".git", remote + i - 3, 4))
+               remote_len = i - 3;
+
+       note_len = 0;
+       if (*what) {
+               if (*kind)
+                       note_len += sprintf(note + note_len, "%s ", kind);
+               note_len += sprintf(note + note_len, "'%s' of ", what);
+       }
+       note_len += sprintf(note + note_len, "%.*s", remote_len, remote);
+       fprintf(fp, "%s\t%s\t%s\n",
+               sha1_to_hex(commit ? commit->object.sha1 : sha1),
+               not_for_merge ? "not-for-merge" : "",
+               note);
+       return update_local_ref(local_name, head, note, verbose, force);
+}
+
+static char *keep;
+static void remove_keep(void)
+{
+       if (keep && *keep)
+               unlink(keep);
+}
+
+static void remove_keep_on_signal(int signo)
+{
+       remove_keep();
+       signal(SIGINT, SIG_DFL);
+       raise(signo);
+}
+
+static char *find_local_name(const char *remote_name, const char *refs,
+                            int *force_p, int *not_for_merge_p)
+{
+       const char *ref = refs;
+       int len = strlen(remote_name);
+
+       while (ref) {
+               const char *next;
+               int single_force, not_for_merge;
+
+               while (*ref == '\n')
+                       ref++;
+               if (!*ref)
+                       break;
+               next = strchr(ref, '\n');
+
+               single_force = not_for_merge = 0;
+               if (*ref == '+') {
+                       single_force = 1;
+                       ref++;
+               }
+               if (*ref == '.') {
+                       not_for_merge = 1;
+                       ref++;
+                       if (*ref == '+') {
+                               single_force = 1;
+                               ref++;
+                       }
+               }
+               if (!strncmp(remote_name, ref, len) && ref[len] == ':') {
+                       const char *local_part = ref + len + 1;
+                       char *ret;
+                       int retlen;
+
+                       if (!next)
+                               retlen = strlen(local_part);
+                       else
+                               retlen = next - local_part;
+                       ret = xmalloc(retlen + 1);
+                       memcpy(ret, local_part, retlen);
+                       ret[retlen] = 0;
+                       *force_p = single_force;
+                       *not_for_merge_p = not_for_merge;
+                       return ret;
+               }
+               ref = next;
+       }
+       return NULL;
+}
+
+static int fetch_native_store(FILE *fp,
+                             const char *remote,
+                             const char *remote_nick,
+                             const char *refs,
+                             int verbose, int force)
+{
+       char buffer[1024];
+       int err = 0;
+
+       signal(SIGINT, remove_keep_on_signal);
+       atexit(remove_keep);
+
+       while (fgets(buffer, sizeof(buffer), stdin)) {
+               int len;
+               char *cp;
+               char *local_name;
+               int single_force, not_for_merge;
+
+               for (cp = buffer; *cp && !isspace(*cp); cp++)
+                       ;
+               if (*cp)
+                       *cp++ = 0;
+               len = strlen(cp);
+               if (len && cp[len-1] == '\n')
+                       cp[--len] = 0;
+               if (!strcmp(buffer, "failed"))
+                       die("Fetch failure: %s", remote);
+               if (!strcmp(buffer, "pack"))
+                       continue;
+               if (!strcmp(buffer, "keep")) {
+                       char *od = get_object_directory();
+                       int len = strlen(od) + strlen(cp) + 50;
+                       keep = xmalloc(len);
+                       sprintf(keep, "%s/pack/pack-%s.keep", od, cp);
+                       continue;
+               }
+
+               local_name = find_local_name(cp, refs,
+                                            &single_force, &not_for_merge);
+               if (!local_name)
+                       continue;
+               err |= append_fetch_head(fp,
+                                        buffer, remote, cp, remote_nick,
+                                        local_name, not_for_merge,
+                                        verbose, force || single_force);
+       }
+       return err;
+}
+
+static int parse_reflist(const char *reflist)
+{
+       const char *ref;
+
+       printf("refs='");
+       for (ref = reflist; ref; ) {
+               const char *next;
+               while (*ref && isspace(*ref))
+                       ref++;
+               if (!*ref)
+                       break;
+               for (next = ref; *next && !isspace(*next); next++)
+                       ;
+               printf("\n%.*s", (int)(next - ref), ref);
+               ref = next;
+       }
+       printf("'\n");
+
+       printf("rref='");
+       for (ref = reflist; ref; ) {
+               const char *next, *colon;
+               while (*ref && isspace(*ref))
+                       ref++;
+               if (!*ref)
+                       break;
+               for (next = ref; *next && !isspace(*next); next++)
+                       ;
+               if (*ref == '.')
+                       ref++;
+               if (*ref == '+')
+                       ref++;
+               colon = strchr(ref, ':');
+               putchar('\n');
+               printf("%.*s", (int)((colon ? colon : next) - ref), ref);
+               ref = next;
+       }
+       printf("'\n");
+       return 0;
+}
+
+static int expand_refs_wildcard(const char *ls_remote_result, int numrefs,
+                               const char **refs)
+{
+       int i, matchlen, replacelen;
+       int found_one = 0;
+       const char *remote = *refs++;
+       numrefs--;
+
+       if (numrefs == 0) {
+               fprintf(stderr, "Nothing specified for fetching with remote.%s.fetch\n",
+                       remote);
+               printf("empty\n");
+       }
+
+       for (i = 0; i < numrefs; i++) {
+               const char *ref = refs[i];
+               const char *lref = ref;
+               const char *colon;
+               const char *tail;
+               const char *ls;
+               const char *next;
+
+               if (*lref == '+')
+                       lref++;
+               colon = strchr(lref, ':');
+               tail = lref + strlen(lref);
+               if (!(colon &&
+                     2 < colon - lref &&
+                     colon[-1] == '*' &&
+                     colon[-2] == '/' &&
+                     2 < tail - (colon + 1) &&
+                     tail[-1] == '*' &&
+                     tail[-2] == '/')) {
+                       /* not a glob */
+                       if (!found_one++)
+                               printf("explicit\n");
+                       printf("%s\n", ref);
+                       continue;
+               }
+
+               /* glob */
+               if (!found_one++)
+                       printf("glob\n");
+
+               /* lref to colon-2 is remote hierarchy name;
+                * colon+1 to tail-2 is local.
+                */
+               matchlen = (colon-1) - lref;
+               replacelen = (tail-1) - (colon+1);
+               for (ls = ls_remote_result; ls; ls = next) {
+                       const char *eol;
+                       unsigned char sha1[20];
+                       int namelen;
+
+                       while (*ls && isspace(*ls))
+                               ls++;
+                       next = strchr(ls, '\n');
+                       eol = !next ? (ls + strlen(ls)) : next;
+                       if (!memcmp("^{}", eol-3, 3))
+                               continue;
+                       if (eol - ls < 40)
+                               continue;
+                       if (get_sha1_hex(ls, sha1))
+                               continue;
+                       ls += 40;
+                       while (ls < eol && isspace(*ls))
+                               ls++;
+                       /* ls to next (or eol) is the name.
+                        * is it identical to lref to colon-2?
+                        */
+                       if ((eol - ls) <= matchlen ||
+                           strncmp(ls, lref, matchlen))
+                               continue;
+
+                       /* Yes, it is a match */
+                       namelen = eol - ls;
+                       if (lref != ref)
+                               putchar('+');
+                       printf("%.*s:%.*s%.*s\n",
+                              namelen, ls,
+                              replacelen, colon + 1,
+                              namelen - matchlen, ls + matchlen);
+               }
+       }
+       return 0;
+}
+
+int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
+{
+       int verbose = 0;
+       int force = 0;
+
+       while (1 < argc) {
+               const char *arg = argv[1];
+               if (!strcmp("-v", arg))
+                       verbose = 1;
+               else if (!strcmp("-f", arg))
+                       force = 1;
+               else
+                       break;
+               argc--;
+               argv++;
+       }
+
+       if (argc <= 1)
+               return error("Missing subcommand");
+
+       if (!strcmp("append-fetch-head", argv[1])) {
+               int result;
+               FILE *fp;
+
+               if (argc != 8)
+                       return error("append-fetch-head takes 6 args");
+               fp = fopen(git_path("FETCH_HEAD"), "a");
+               result = append_fetch_head(fp, argv[2], argv[3],
+                                          argv[4], argv[5],
+                                          argv[6], !!argv[7][0],
+                                          verbose, force);
+               fclose(fp);
+               return result;
+       }
+       if (!strcmp("native-store", argv[1])) {
+               int result;
+               FILE *fp;
+
+               if (argc != 5)
+                       return error("fetch-native-store takes 3 args");
+               fp = fopen(git_path("FETCH_HEAD"), "a");
+               result = fetch_native_store(fp, argv[2], argv[3], argv[4],
+                                           verbose, force);
+               fclose(fp);
+               return result;
+       }
+       if (!strcmp("parse-reflist", argv[1])) {
+               const char *reflist;
+               if (argc != 3)
+                       return error("parse-reflist takes 1 arg");
+               reflist = argv[2];
+               if (!strcmp(reflist, "-"))
+                       reflist = get_stdin();
+               return parse_reflist(reflist);
+       }
+       if (!strcmp("expand-refs-wildcard", argv[1])) {
+               const char *reflist;
+               if (argc < 4)
+                       return error("expand-refs-wildcard takes at least 2 args");
+               reflist = argv[2];
+               if (!strcmp(reflist, "-"))
+                       reflist = get_stdin();
+               return expand_refs_wildcard(reflist, argc - 3, argv + 3);
+       }
+
+       return error("Unknown subcommand: %s", argv[1]);
+}
index 39cfc32818dc80d8bda04ff45fbf5996d1506922..4d8b66c344422dd60c72c72bbfbc5aa87be7907e 100644 (file)
 static int show_root;
 static int show_tags;
 static int show_unreachable;
+static int include_reflogs = 1;
 static int check_full;
 static int check_strict;
 static int keep_cache_objects;
 static unsigned char head_sha1[20];
+static int errors_found;
+#define ERROR_OBJECT 01
+#define ERROR_REACHABLE 02
 
 #ifdef NO_D_INO_IN_DIRENT
 #define SORT_DIRENT 0
@@ -40,6 +44,7 @@ static int objerror(struct object *obj, const char *err, ...)
 {
        va_list params;
        va_start(params, err);
+       errors_found |= ERROR_OBJECT;
        objreport(obj, "error", err, params);
        va_end(params);
        return -1;
@@ -67,9 +72,10 @@ static void check_reachable_object(struct object *obj)
         * do a full fsck
         */
        if (!obj->parsed) {
-               if (has_sha1_file(obj->sha1))
+               if (has_sha1_pack(obj->sha1, NULL))
                        return; /* it is in pack - forget about it */
                printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
+               errors_found |= ERROR_REACHABLE;
                return;
        }
 
@@ -88,6 +94,7 @@ static void check_reachable_object(struct object *obj)
                               typename(obj->type), sha1_to_hex(obj->sha1));
                        printf("              to %7s %s\n",
                               typename(ref->type), sha1_to_hex(ref->sha1));
+                       errors_found |= ERROR_REACHABLE;
                }
        }
 }
@@ -221,8 +228,7 @@ static int fsck_tree(struct tree *item)
        const char *o_name;
        const unsigned char *o_sha1;
 
-       desc.buf = item->buffer;
-       desc.size = item->size;
+       init_tree_desc(&desc, item->buffer, item->size);
 
        o_mode = 0;
        o_name = NULL;
@@ -236,7 +242,7 @@ static int fsck_tree(struct tree *item)
 
                if (strchr(name, '/'))
                        has_full_path = 1;
-               has_zero_pad |= *(char *)desc.buf == '0';
+               has_zero_pad |= *(char *)desc.buffer == '0';
                update_tree_entry(&desc);
 
                switch (mode) {
@@ -343,11 +349,14 @@ static int fsck_tag(struct tag *tag)
        return 0;
 }
 
-static int fsck_sha1(unsigned char *sha1)
+static int fsck_sha1(const unsigned char *sha1)
 {
        struct object *obj = parse_object(sha1);
-       if (!obj)
-               return error("%s: object corrupt or missing", sha1_to_hex(sha1));
+       if (!obj) {
+               errors_found |= ERROR_OBJECT;
+               return error("%s: object corrupt or missing",
+                            sha1_to_hex(sha1));
+       }
        if (obj->flags & SEEN)
                return 0;
        obj->flags |= SEEN;
@@ -359,8 +368,10 @@ static int fsck_sha1(unsigned char *sha1)
                return fsck_commit((struct commit *) obj);
        if (obj->type == OBJ_TAG)
                return fsck_tag((struct tag *) obj);
+
        /* By now, parse_object() would've returned NULL instead. */
-       return objerror(obj, "unknown type '%d' (internal fsck error)", obj->type);
+       return objerror(obj, "unknown type '%d' (internal fsck error)",
+                       obj->type);
 }
 
 /*
@@ -507,7 +518,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
 static void get_default_heads(void)
 {
        for_each_ref(fsck_handle_ref, NULL);
-       for_each_reflog(fsck_handle_reflog, NULL);
+       if (include_reflogs)
+               for_each_reflog(fsck_handle_reflog, NULL);
 
        /*
         * Not having any default heads isn't really fatal, but
@@ -576,11 +588,16 @@ static int fsck_cache_tree(struct cache_tree *it)
        return err;
 }
 
+static const char fsck_usage[] =
+"git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] "
+"[--strict] <head-sha1>*]";
+
 int cmd_fsck(int argc, char **argv, const char *prefix)
 {
        int i, heads;
 
        track_object_refs = 1;
+       errors_found = 0;
 
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
@@ -601,6 +618,10 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
                        keep_cache_objects = 1;
                        continue;
                }
+               if (!strcmp(arg, "--no-reflogs")) {
+                       include_reflogs = 0;
+                       continue;
+               }
                if (!strcmp(arg, "--full")) {
                        check_full = 1;
                        continue;
@@ -610,7 +631,7 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
                        continue;
                }
                if (*arg == '-')
-                       usage("git-fsck [--tags] [--root] [[--unreachable] [--cache] [--full] [--strict] <head-sha1>*]");
+                       usage(fsck_usage);
        }
 
        fsck_head_link();
@@ -633,11 +654,8 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
 
                for (p = packed_git; p; p = p->next) {
                        uint32_t i, num = num_packed_objects(p);
-                       for (i = 0; i < num; i++) {
-                               unsigned char sha1[20];
-                               nth_packed_object_sha1(p, i, sha1);
-                               fsck_sha1(sha1);
-                       }
+                       for (i = 0; i < num; i++)
+                               fsck_sha1(nth_packed_object_sha1(p, i));
                }
        }
 
@@ -690,5 +708,5 @@ int cmd_fsck(int argc, char **argv, const char *prefix)
        }
 
        check_connectivity();
-       return 0;
+       return errors_found;
 }
diff --git a/builtin-gc.c b/builtin-gc.c
new file mode 100644 (file)
index 0000000..3b1f8c2
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * git gc builtin command
+ *
+ * Cleanup unreachable files and optimize the repository.
+ *
+ * Copyright (c) 2007 James Bowes
+ *
+ * Based on git-gc.sh, which is
+ *
+ * Copyright (c) 2006 Shawn O. Pearce
+ */
+
+#include "cache.h"
+#include "run-command.h"
+
+#define FAILED_RUN "failed to run %s"
+
+static const char builtin_gc_usage[] = "git-gc [--prune]";
+
+static int pack_refs = -1;
+
+static const char *argv_pack_refs[] = {"pack-refs", "--prune", NULL};
+static const char *argv_reflog[] = {"reflog", "expire", "--all", NULL};
+static const char *argv_repack[] = {"repack", "-a", "-d", "-l", NULL};
+static const char *argv_prune[] = {"prune", NULL};
+static const char *argv_rerere[] = {"rerere", "gc", NULL};
+
+static int gc_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "gc.packrefs")) {
+               if (!strcmp(value, "notbare"))
+                       pack_refs = -1;
+               else
+                       pack_refs = git_config_bool(var, value);
+               return 0;
+       }
+       return git_default_config(var, value);
+}
+
+int cmd_gc(int argc, const char **argv, const char *prefix)
+{
+       int i;
+       int prune = 0;
+
+       git_config(gc_config);
+
+       if (pack_refs < 0)
+               pack_refs = !is_bare_repository();
+
+       for (i = 1; i < argc; i++) {
+               const char *arg = argv[i];
+               if (!strcmp(arg, "--prune")) {
+                       prune = 1;
+                       continue;
+               }
+               /* perhaps other parameters later... */
+               break;
+       }
+       if (i != argc)
+               usage(builtin_gc_usage);
+
+       if (pack_refs && run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))
+               return error(FAILED_RUN, argv_pack_refs[0]);
+
+       if (run_command_v_opt(argv_reflog, RUN_GIT_CMD))
+               return error(FAILED_RUN, argv_reflog[0]);
+
+       if (run_command_v_opt(argv_repack, RUN_GIT_CMD))
+               return error(FAILED_RUN, argv_repack[0]);
+
+       if (prune && run_command_v_opt(argv_prune, RUN_GIT_CMD))
+               return error(FAILED_RUN, argv_prune[0]);
+
+       if (run_command_v_opt(argv_rerere, RUN_GIT_CMD))
+               return error(FAILED_RUN, argv_rerere[0]);
+
+       return 0;
+}
index 694da5ba09d302c1e44f863070776bc3ac7f32e2..981f3d4d8eb079f5985beaaf94014d5745c5aacc 100644 (file)
@@ -378,7 +378,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
                         * decide if we want to descend into "abc"
                         * directory.
                         */
-                       strcpy(path_buf + len + entry.pathlen, "/");
+                       strcpy(path_buf + len + tree_entry_len(entry.path, entry.sha1), "/");
 
                if (!pathspec_matches(paths, down))
                        ;
@@ -388,11 +388,13 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
                        enum object_type type;
                        struct tree_desc sub;
                        void *data;
-                       data = read_sha1_file(entry.sha1, &type, &sub.size);
+                       unsigned long size;
+
+                       data = read_sha1_file(entry.sha1, &type, &size);
                        if (!data)
                                die("unable to read tree (%s)",
                                    sha1_to_hex(entry.sha1));
-                       sub.buf = data;
+                       init_tree_desc(&sub, data, size);
                        hit |= grep_tree(opt, paths, &sub, tree_name, down);
                        free(data);
                }
@@ -408,12 +410,13 @@ static int grep_object(struct grep_opt *opt, const char **paths,
        if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
                struct tree_desc tree;
                void *data;
+               unsigned long size;
                int hit;
                data = read_object_with_reference(obj->sha1, tree_type,
-                                                 &tree.size, NULL);
+                                                 &size, NULL);
                if (!data)
                        die("unable to read tree (%s)", sha1_to_hex(obj->sha1));
-               tree.buf = data;
+               init_tree_desc(&tree, data, size);
                hit = grep_tree(opt, paths, &tree, name, "");
                free(data);
                return hit;
@@ -431,6 +434,19 @@ static const char emsg_missing_context_len[] =
 static const char emsg_missing_argument[] =
 "option requires an argument -%s";
 
+static int strtoul_ui(char const *s, unsigned int *result)
+{
+       unsigned long ul;
+       char *p;
+
+       errno = 0;
+       ul = strtoul(s, &p, 10);
+       if (errno || *p || p == s || (unsigned int) ul != ul)
+               return -1;
+       *result = ul;
+       return 0;
+}
+
 int cmd_grep(int argc, const char **argv, const char *prefix)
 {
        int hit = 0;
@@ -553,7 +569,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                                scan = arg + 1;
                                break;
                        }
-                       if (sscanf(scan, "%u", &num) != 1)
+                       if (strtoul_ui(scan, &num))
                                die(emsg_invalid_context_len, scan);
                        switch (arg[1]) {
                        case 'A':
index 1c9f7d02a8746d1d33347b7baaa85e4153a61bbb..71df957eaa0b85bd841fe3758b6efbfd51243881 100644 (file)
@@ -35,7 +35,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
                if (!prefixcmp(arg, "--encoding=")) {
                        arg += 11;
                        if (strcmp(arg, "none"))
-                               git_log_output_encoding = strdup(arg);
+                               git_log_output_encoding = xstrdup(arg);
                        else
                                git_log_output_encoding = "";
                }
@@ -482,10 +482,22 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                        memcpy(add_signoff, committer, endpos - committer + 1);
                        add_signoff[endpos - committer + 1] = 0;
                }
-               else if (!strcmp(argv[i], "--attach"))
+               else if (!strcmp(argv[i], "--attach")) {
                        rev.mime_boundary = git_version_string;
-               else if (!prefixcmp(argv[i], "--attach="))
+                       rev.no_inline = 1;
+               }
+               else if (!prefixcmp(argv[i], "--attach=")) {
+                       rev.mime_boundary = argv[i] + 9;
+                       rev.no_inline = 1;
+               }
+               else if (!strcmp(argv[i], "--inline")) {
+                       rev.mime_boundary = git_version_string;
+                       rev.no_inline = 0;
+               }
+               else if (!prefixcmp(argv[i], "--inline=")) {
                        rev.mime_boundary = argv[i] + 9;
+                       rev.no_inline = 0;
+               }
                else if (!strcmp(argv[i], "--ignore-if-in-upstream"))
                        ignore_if_in_upstream = 1;
                else if (!strcmp(argv[i], "--thread"))
index 4e1d5af634a1280288d7c8110571f1136343bf3e..74a6acacc15b416a6149a519f3a69c5facfa5067 100644 (file)
@@ -216,7 +216,7 @@ static void show_files(struct dir_struct *dir, const char *prefix)
 
                if (baselen)
                        path = base = prefix;
-               read_directory(dir, path, base, baselen);
+               read_directory(dir, path, base, baselen, pathspec);
                if (show_others)
                        show_other_files(dir);
                if (show_killed)
index f54e8752fb6dd0f7f251fe6bfe7bf3b2f8cd91f3..c95e477e831dd436f074bbca9b2b9ca5ad5a5eb1 100644 (file)
@@ -11,19 +11,22 @@ static FILE *cmitmsg, *patchfile, *fin, *fout;
 static int keep_subject;
 static const char *metainfo_charset;
 static char line[1000];
-static char date[1000];
 static char name[1000];
 static char email[1000];
-static char subject[1000];
 
 static enum  {
        TE_DONTCARE, TE_QP, TE_BASE64,
 } transfer_encoding;
-static char charset[256];
+static enum  {
+       TYPE_TEXT, TYPE_OTHER,
+} message_type;
 
-static char multipart_boundary[1000];
-static int multipart_boundary_len;
+static char charset[256];
 static int patch_lines;
+static char **p_hdr_data, **s_hdr_data;
+
+#define MAX_HDR_PARSED 10
+#define MAX_BOUNDARIES 5
 
 static char *sanity_check(char *name, char *email)
 {
@@ -137,15 +140,13 @@ static int handle_from(char *in_line)
        return 1;
 }
 
-static int handle_date(char *line)
+static int handle_header(char *line, char *data, int ofs)
 {
-       strcpy(date, line);
-       return 0;
-}
+       if (!line || !data)
+               return 1;
+
+       strcpy(data, line+ofs);
 
-static int handle_subject(char *line)
-{
-       strcpy(subject, line);
        return 0;
 }
 
@@ -177,17 +178,32 @@ static int slurp_attr(const char *line, const char *name, char *attr)
        return 1;
 }
 
-static int handle_subcontent_type(char *line)
+struct content_type {
+       char *boundary;
+       int boundary_len;
+};
+
+static struct content_type content[MAX_BOUNDARIES];
+
+static struct content_type *content_top = content;
+
+static int handle_content_type(char *line)
 {
-       /* We do not want to mess with boundary.  Note that we do not
-        * handle nested multipart.
-        */
-       if (strcasestr(line, "boundary=")) {
-               fprintf(stderr, "Not handling nested multipart message.\n");
-               exit(1);
+       char boundary[256];
+
+       if (strcasestr(line, "text/") == NULL)
+                message_type = TYPE_OTHER;
+       if (slurp_attr(line, "boundary=", boundary + 2)) {
+               memcpy(boundary, "--", 2);
+               if (content_top++ >= &content[MAX_BOUNDARIES]) {
+                       fprintf(stderr, "Too many boundaries to handle\n");
+                       exit(1);
+               }
+               content_top->boundary_len = strlen(boundary);
+               content_top->boundary = xmalloc(content_top->boundary_len+1);
+               strcpy(content_top->boundary, boundary);
        }
-       slurp_attr(line, "charset=", charset);
-       if (*charset) {
+       if (slurp_attr(line, "charset=", charset)) {
                int i, c;
                for (i = 0; (c = charset[i]) != 0; i++)
                        charset[i] = tolower(c);
@@ -195,17 +211,6 @@ static int handle_subcontent_type(char *line)
        return 0;
 }
 
-static int handle_content_type(char *line)
-{
-       *multipart_boundary = 0;
-       if (slurp_attr(line, "boundary=", multipart_boundary + 2)) {
-               memcpy(multipart_boundary, "--", 2);
-               multipart_boundary_len = strlen(multipart_boundary);
-       }
-       slurp_attr(line, "charset=", charset);
-       return 0;
-}
-
 static int handle_content_transfer_encoding(char *line)
 {
        if (strcasestr(line, "base64"))
@@ -219,7 +224,7 @@ static int handle_content_transfer_encoding(char *line)
 
 static int is_multipart_boundary(const char *line)
 {
-       return (!memcmp(line, multipart_boundary, multipart_boundary_len));
+       return (!memcmp(line, content_top->boundary, content_top->boundary_len));
 }
 
 static int eatspace(char *line)
@@ -230,62 +235,6 @@ static int eatspace(char *line)
        return len;
 }
 
-#define SEEN_FROM 01
-#define SEEN_DATE 02
-#define SEEN_SUBJECT 04
-#define SEEN_BOGUS_UNIX_FROM 010
-#define SEEN_PREFIX  020
-
-/* First lines of body can have From:, Date:, and Subject: or empty */
-static void handle_inbody_header(int *seen, char *line)
-{
-       if (*seen & SEEN_PREFIX)
-               return;
-       if (isspace(*line)) {
-               char *cp;
-               for (cp = line + 1; *cp; cp++) {
-                       if (!isspace(*cp))
-                               break;
-               }
-               if (!*cp)
-                       return;
-       }
-       if (!memcmp(">From", line, 5) && isspace(line[5])) {
-               if (!(*seen & SEEN_BOGUS_UNIX_FROM)) {
-                       *seen |= SEEN_BOGUS_UNIX_FROM;
-                       return;
-               }
-       }
-       if (!memcmp("From:", line, 5) && isspace(line[5])) {
-               if (!(*seen & SEEN_FROM) && handle_from(line+6)) {
-                       *seen |= SEEN_FROM;
-                       return;
-               }
-       }
-       if (!memcmp("Date:", line, 5) && isspace(line[5])) {
-               if (!(*seen & SEEN_DATE)) {
-                       handle_date(line+6);
-                       *seen |= SEEN_DATE;
-                       return;
-               }
-       }
-       if (!memcmp("Subject:", line, 8) && isspace(line[8])) {
-               if (!(*seen & SEEN_SUBJECT)) {
-                       handle_subject(line+9);
-                       *seen |= SEEN_SUBJECT;
-                       return;
-               }
-       }
-       if (!memcmp("[PATCH]", line, 7) && isspace(line[7])) {
-               if (!(*seen & SEEN_SUBJECT)) {
-                       handle_subject(line);
-                       *seen |= SEEN_SUBJECT;
-                       return;
-               }
-       }
-       *seen |= SEEN_PREFIX;
-}
-
 static char *cleanup_subject(char *subject)
 {
        if (keep_subject)
@@ -296,7 +245,7 @@ static char *cleanup_subject(char *subject)
                switch (*subject) {
                case 'r': case 'R':
                        if (!memcmp("e:", subject+1, 2)) {
-                               subject +=3;
+                               subject += 3;
                                continue;
                        }
                        break;
@@ -341,57 +290,62 @@ static void cleanup_space(char *buf)
 }
 
 static void decode_header(char *it);
-typedef int (*header_fn_t)(char *);
-struct header_def {
-       const char *name;
-       header_fn_t func;
-       int namelen;
+static char *header[MAX_HDR_PARSED] = {
+       "From","Subject","Date",
 };
 
-static void check_header(char *line, struct header_def *header)
+static int check_header(char *line, char **hdr_data, int overwrite)
 {
        int i;
 
-       if (header[0].namelen <= 0) {
-               for (i = 0; header[i].name; i++)
-                       header[i].namelen = strlen(header[i].name);
-       }
-       for (i = 0; header[i].name; i++) {
-               int len = header[i].namelen;
-               if (!strncasecmp(line, header[i].name, len) &&
+       /* search for the interesting parts */
+       for (i = 0; header[i]; i++) {
+               int len = strlen(header[i]);
+               if ((!hdr_data[i] || overwrite) &&
+                   !strncasecmp(line, header[i], len) &&
                    line[len] == ':' && isspace(line[len + 1])) {
                        /* Unwrap inline B and Q encoding, and optionally
                         * normalize the meta information to utf8.
                         */
                        decode_header(line + len + 2);
-                       header[i].func(line + len + 2);
-                       break;
+                       hdr_data[i] = xmalloc(1000 * sizeof(char));
+                       if (! handle_header(line, hdr_data[i], len + 2)) {
+                               return 1;
+                       }
                }
        }
-}
 
-static void check_subheader_line(char *line)
-{
-       static struct header_def header[] = {
-               { "Content-Type", handle_subcontent_type },
-               { "Content-Transfer-Encoding",
-                 handle_content_transfer_encoding },
-               { NULL },
-       };
-       check_header(line, header);
-}
-static void check_header_line(char *line)
-{
-       static struct header_def header[] = {
-               { "From", handle_from },
-               { "Date", handle_date },
-               { "Subject", handle_subject },
-               { "Content-Type", handle_content_type },
-               { "Content-Transfer-Encoding",
-                 handle_content_transfer_encoding },
-               { NULL },
-       };
-       check_header(line, header);
+       /* Content stuff */
+       if (!strncasecmp(line, "Content-Type", 12) &&
+               line[12] == ':' && isspace(line[12 + 1])) {
+               decode_header(line + 12 + 2);
+               if (! handle_content_type(line)) {
+                       return 1;
+               }
+       }
+       if (!strncasecmp(line, "Content-Transfer-Encoding", 25) &&
+               line[25] == ':' && isspace(line[25 + 1])) {
+               decode_header(line + 25 + 2);
+               if (! handle_content_transfer_encoding(line)) {
+                       return 1;
+               }
+       }
+
+       /* for inbody stuff */
+       if (!memcmp(">From", line, 5) && isspace(line[5]))
+               return 1;
+       if (!memcmp("[PATCH]", line, 7) && isspace(line[7])) {
+               for (i = 0; header[i]; i++) {
+                       if (!memcmp("Subject: ", header[i], 9)) {
+                               if (! handle_header(line, hdr_data[i], 0)) {
+                                       return 1;
+                               }
+                       }
+               }
+       }
+
+       /* no match */
+       return 0;
 }
 
 static int is_rfc2822_header(char *line)
@@ -647,147 +601,254 @@ static void decode_transfer_encoding(char *line)
        }
 }
 
-static void handle_info(void)
+static int handle_filter(char *line);
+
+static int find_boundary(void)
 {
-       char *sub;
+       while(fgets(line, sizeof(line), fin) != NULL) {
+               if (is_multipart_boundary(line))
+                       return 1;
+       }
+       return 0;
+}
 
-       sub = cleanup_subject(subject);
-       cleanup_space(name);
-       cleanup_space(date);
-       cleanup_space(email);
-       cleanup_space(sub);
+static int handle_boundary(void)
+{
+       char newline[]="\n";
+again:
+       if (!memcmp(line+content_top->boundary_len, "--", 2)) {
+               /* we hit an end boundary */
+               /* pop the current boundary off the stack */
+               free(content_top->boundary);
+
+               /* technically won't happen as is_multipart_boundary()
+                  will fail first.  But just in case..
+                */
+               if (content_top-- < content) {
+                       fprintf(stderr, "Detected mismatched boundaries, "
+                                       "can't recover\n");
+                       exit(1);
+               }
+               handle_filter(newline);
+
+               /* skip to the next boundary */
+               if (!find_boundary())
+                       return 0;
+               goto again;
+       }
+
+       /* set some defaults */
+       transfer_encoding = TE_DONTCARE;
+       charset[0] = 0;
+       message_type = TYPE_TEXT;
+
+       /* slurp in this section's info */
+       while (read_one_header_line(line, sizeof(line), fin))
+               check_header(line, p_hdr_data, 0);
 
-       fprintf(fout, "Author: %s\nEmail: %s\nSubject: %s\nDate: %s\n\n",
-              name, email, sub, date);
+       /* eat the blank line after section info */
+       return (fgets(line, sizeof(line), fin) != NULL);
 }
 
-/* We are inside message body and have read line[] already.
- * Spit out the commit log.
- */
-static int handle_commit_msg(int *seen)
+static inline int patchbreak(const char *line)
 {
+       /* Beginning of a "diff -" header? */
+       if (!memcmp("diff -", line, 6))
+               return 1;
+
+       /* CVS "Index: " line? */
+       if (!memcmp("Index: ", line, 7))
+               return 1;
+
+       /*
+        * "--- <filename>" starts patches without headers
+        * "---<sp>*" is a manual separator
+        */
+       if (!memcmp("---", line, 3)) {
+               line += 3;
+               /* space followed by a filename? */
+               if (line[0] == ' ' && !isspace(line[1]))
+                       return 1;
+               /* Just whitespace? */
+               for (;;) {
+                       unsigned char c = *line++;
+                       if (c == '\n')
+                               return 1;
+                       if (!isspace(c))
+                               break;
+               }
+               return 0;
+       }
+       return 0;
+}
+
+
+static int handle_commit_msg(char *line)
+{
+       static int still_looking = 1;
+
        if (!cmitmsg)
                return 0;
-       do {
-               if (!memcmp("diff -", line, 6) ||
-                   !memcmp("---", line, 3) ||
-                   !memcmp("Index: ", line, 7))
-                       break;
-               if ((multipart_boundary[0] && is_multipart_boundary(line))) {
-                       /* We come here when the first part had only
-                        * the commit message without any patch.  We
-                        * pretend we have not seen this line yet, and
-                        * go back to the loop.
-                        */
-                       return 1;
+
+       if (still_looking) {
+               char *cp = line;
+               if (isspace(*line)) {
+                       for (cp = line + 1; *cp; cp++) {
+                               if (!isspace(*cp))
+                                       break;
+                       }
+                       if (!*cp)
+                               return 0;
                }
+               if ((still_looking = check_header(cp, s_hdr_data, 0)) != 0)
+                       return 0;
+       }
 
-               /* Unwrap transfer encoding and optionally
-                * normalize the log message to UTF-8.
-                */
-               decode_transfer_encoding(line);
-               if (metainfo_charset)
-                       convert_to_utf8(line, charset);
+       /* normalize the log message to UTF-8. */
+       if (metainfo_charset)
+               convert_to_utf8(line, charset);
 
-               handle_inbody_header(seen, line);
-               if (!(*seen & SEEN_PREFIX))
-                       continue;
+       if (patchbreak(line)) {
+               fclose(cmitmsg);
+               cmitmsg = NULL;
+               return 1;
+       }
 
-               fputs(line, cmitmsg);
-       } while (fgets(line, sizeof(line), fin) != NULL);
-       fclose(cmitmsg);
-       cmitmsg = NULL;
+       fputs(line, cmitmsg);
        return 0;
 }
 
-/* We have done the commit message and have the first
- * line of the patch in line[].
- */
-static void handle_patch(void)
+static int handle_patch(char *line)
 {
-       do {
-               if (multipart_boundary[0] && is_multipart_boundary(line))
-                       break;
-               /* Only unwrap transfer encoding but otherwise do not
-                * do anything.  We do *NOT* want UTF-8 conversion
-                * here; we are dealing with the user payload.
-                */
-               decode_transfer_encoding(line);
-               fputs(line, patchfile);
-               patch_lines++;
-       } while (fgets(line, sizeof(line), fin) != NULL);
+       fputs(line, patchfile);
+       patch_lines++;
+       return 0;
 }
 
-/* multipart boundary and transfer encoding are set up for us, and we
- * are at the end of the sub header.  do equivalent of handle_body up
- * to the next boundary without closing patchfile --- we will expect
- * that the first part to contain commit message and a patch, and
- * handle other parts as pure patches.
- */
-static int handle_multipart_one_part(int *seen)
+static int handle_filter(char *line)
 {
-       int n = 0;
+       static int filter = 0;
 
-       while (fgets(line, sizeof(line), fin) != NULL) {
-       again:
-               n++;
-               if (is_multipart_boundary(line))
+       /* filter tells us which part we left off on
+        * a non-zero return indicates we hit a filter point
+        */
+       switch (filter) {
+       case 0:
+               if (!handle_commit_msg(line))
                        break;
-               if (handle_commit_msg(seen))
-                       goto again;
-               handle_patch();
-               break;
+               filter++;
+       case 1:
+               if (!handle_patch(line))
+                       break;
+               filter++;
+       default:
+               return 1;
        }
-       if (n == 0)
-               return -1;
+
        return 0;
 }
 
-static void handle_multipart_body(void)
+static void handle_body(void)
 {
-       int seen = 0;
-       int part_num = 0;
+       int rc = 0;
+       static char newline[2000];
+       static char *np = newline;
 
        /* Skip up to the first boundary */
-       while (fgets(line, sizeof(line), fin) != NULL)
-               if (is_multipart_boundary(line)) {
-                       part_num = 1;
+       if (content_top->boundary) {
+               if (!find_boundary())
+                       return;
+       }
+
+       do {
+               /* process any boundary lines */
+               if (content_top->boundary && is_multipart_boundary(line)) {
+                       /* flush any leftover */
+                       if ((transfer_encoding == TE_BASE64)  &&
+                           (np != newline)) {
+                               handle_filter(newline);
+                       }
+                       if (!handle_boundary())
+                               return;
+               }
+
+               /* Unwrap transfer encoding */
+               decode_transfer_encoding(line);
+
+               switch (transfer_encoding) {
+               case TE_BASE64:
+               {
+                       char *op = line;
+
+                       /* binary data most likely doesn't have newlines */
+                       if (message_type != TYPE_TEXT) {
+                               rc = handle_filter(line);
+                               break;
+                       }
+
+                       /* this is a decoded line that may contain
+                        * multiple new lines.  Pass only one chunk
+                        * at a time to handle_filter()
+                        */
+
+                       do {
+                               while (*op != '\n' && *op != 0)
+                                       *np++ = *op++;
+                               *np = *op;
+                               if (*np != 0) {
+                                       /* should be sitting on a new line */
+                                       *(++np) = 0;
+                                       op++;
+                                       rc = handle_filter(newline);
+                                       np = newline;
+                               }
+                       } while (*op != 0);
+                       /* the partial chunk is saved in newline and
+                        * will be appended by the next iteration of fgets
+                        */
                        break;
                }
-       if (!part_num)
-               return;
-       /* We are on boundary line.  Start slurping the subhead. */
-       while (1) {
-               int hdr = read_one_header_line(line, sizeof(line), fin);
-               if (!hdr) {
-                       if (handle_multipart_one_part(&seen) < 0)
-                               return;
-                       /* Reset per part headers */
-                       transfer_encoding = TE_DONTCARE;
-                       charset[0] = 0;
+               default:
+                       rc = handle_filter(line);
                }
-               else
-                       check_subheader_line(line);
-       }
-       fclose(patchfile);
-       if (!patch_lines) {
-               fprintf(stderr, "No patch found\n");
-               exit(1);
-       }
+               if (rc)
+                       /* nothing left to filter */
+                       break;
+       } while (fgets(line, sizeof(line), fin));
+
+       return;
 }
 
-/* Non multipart message */
-static void handle_body(void)
+static void handle_info(void)
 {
-       int seen = 0;
+       char *sub;
+       char *hdr;
+       int i;
+
+       for (i = 0; header[i]; i++) {
 
-       handle_commit_msg(&seen);
-       handle_patch();
-       fclose(patchfile);
-       if (!patch_lines) {
-               fprintf(stderr, "No patch found\n");
-               exit(1);
+               /* only print inbody headers if we output a patch file */
+               if (patch_lines && s_hdr_data[i])
+                       hdr = s_hdr_data[i];
+               else if (p_hdr_data[i])
+                       hdr = p_hdr_data[i];
+               else
+                       continue;
+
+               if (!memcmp(header[i], "Subject", 7)) {
+                       sub = cleanup_subject(hdr);
+                       cleanup_space(sub);
+                       fprintf(fout, "Subject: %s\n", sub);
+               } else if (!memcmp(header[i], "From", 4)) {
+                       handle_from(hdr);
+                       fprintf(fout, "Author: %s\n", name);
+                       fprintf(fout, "Email: %s\n", email);
+               } else {
+                       cleanup_space(hdr);
+                       fprintf(fout, "%s: %s\n", header[i], hdr);
+               }
        }
+       fprintf(fout, "\n");
 }
 
 int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
@@ -809,18 +870,16 @@ int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
                fclose(cmitmsg);
                return -1;
        }
-       while (1) {
-               int hdr = read_one_header_line(line, sizeof(line), fin);
-               if (!hdr) {
-                       if (multipart_boundary[0])
-                               handle_multipart_body();
-                       else
-                               handle_body();
-                       handle_info();
-                       break;
-               }
-               check_header_line(line);
-       }
+
+       p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));
+       s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));
+
+       /* process the email header */
+       while (read_one_header_line(line, sizeof(line), fin))
+               check_header(line, p_hdr_data, 1);
+
+       handle_body();
+       handle_info();
 
        return 0;
 }
index 737af350b873e90c787cb49960236fc19b62a3bf..3563216acaebba668f465895fe0563e5d7113fef 100644 (file)
@@ -77,7 +77,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
        git_config(git_default_config);
 
-       newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
+       newfd = hold_locked_index(&lock_file, 1);
        if (read_cache() < 0)
                die("index file corrupt");
 
@@ -273,7 +273,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
                for (i = 0; i < added.nr; i++) {
                        const char *path = added.items[i].path;
-                       add_file_to_index(path, verbose);
+                       add_file_to_cache(path, verbose);
                }
 
                for (i = 0; i < deleted.nr; i++) {
@@ -285,7 +285,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                if (active_cache_changed) {
                        if (write_cache(newfd, active_cache, active_nr) ||
                            close(newfd) ||
-                           commit_lock_file(&lock_file))
+                           commit_locked_index(&lock_file))
                                die("Unable to write new index file");
                }
        }
index f8ebad0b2f2006d619dc06814acb6024ee674eec..45ac3e482acc1c0f8f2bad043f1ba50019dec505 100644 (file)
@@ -166,11 +166,12 @@ static void prepare_pack_revindex(struct pack_revindex *rix)
        struct packed_git *p = rix->p;
        int num_ent = num_packed_objects(p);
        int i;
-       void *index = p->index_base + 256;
+       const char *index = p->index_data;
 
+       index += 4 * 256;
        rix->revindex = xmalloc(sizeof(*rix->revindex) * (num_ent + 1));
        for (i = 0; i < num_ent; i++) {
-               unsigned int hl = *((unsigned int *)((char *) index + 24*i));
+               uint32_t hl = *((uint32_t *)(index + 24 * i));
                rix->revindex[i].offset = ntohl(hl);
                rix->revindex[i].nr = i;
        }
@@ -217,11 +218,11 @@ static off_t find_packed_object_size(struct packed_git *p, off_t ofs)
        return entry[1].offset - ofs;
 }
 
-static unsigned char *find_packed_object_name(struct packed_git *p,
-                                             off_t ofs)
+static const unsigned char *find_packed_object_name(struct packed_git *p,
+                                                   off_t ofs)
 {
        struct revindex_entry *entry = find_packed_object(p, ofs);
-       return (unsigned char *)(p->index_base + 256) + 24 * entry->nr + 4;
+       return nth_packed_object_sha1(p, entry->nr);
 }
 
 static void *delta_against(void *buf, unsigned long size, struct object_entry *entry)
@@ -853,7 +854,7 @@ static void add_pbase_object(struct tree_desc *tree,
                unsigned long size;
                enum object_type type;
 
-               if (entry.pathlen != cmplen ||
+               if (tree_entry_len(entry.path, entry.sha1) != cmplen ||
                    memcmp(entry.path, name, cmplen) ||
                    !has_sha1_file(entry.sha1) ||
                    (type = sha1_object_info(entry.sha1, &size)) < 0)
@@ -872,8 +873,7 @@ static void add_pbase_object(struct tree_desc *tree,
                        tree = pbase_tree_get(entry.sha1);
                        if (!tree)
                                return;
-                       sub.buf = tree->tree_data;
-                       sub.size = tree->tree_size;
+                       init_tree_desc(&sub, tree->tree_data, tree->tree_size);
 
                        add_pbase_object(&sub, down, downlen, fullname);
                        pbase_tree_put(tree);
@@ -936,8 +936,7 @@ static void add_preferred_base_object(const char *name, unsigned hash)
                }
                else {
                        struct tree_desc tree;
-                       tree.buf = it->pcache.tree_data;
-                       tree.size = it->pcache.tree_size;
+                       init_tree_desc(&tree, it->pcache.tree_data, it->pcache.tree_size);
                        add_pbase_object(&tree, name, cmplen, name);
                }
        }
@@ -996,7 +995,8 @@ static void check_object(struct object_entry *entry)
                 * delta.
                 */
                if (!no_reuse_delta) {
-                       unsigned char c, *base_name;
+                       unsigned char c;
+                       const unsigned char *base_name;
                        off_t ofs;
                        unsigned long used_0;
                        /* there is at least 20 bytes left in the pack */
index 09864b7a6d52bfb0855735418486e046438ecee4..44df59e4a70f84cdebac94f2591765ada8d4b92d 100644 (file)
@@ -14,10 +14,8 @@ static int prune_object(char *path, const char *filename, const unsigned char *s
                enum object_type type = sha1_object_info(sha1, NULL);
                printf("%s %s\n", sha1_to_hex(sha1),
                       (type > 0) ? typename(type) : "unknown");
-               return 0;
-       }
-       unlink(mkpath("%s/%s", path, filename));
-       rmdir(path);
+       } else
+               unlink(mkpath("%s/%s", path, filename));
        return 0;
 }
 
@@ -60,6 +58,8 @@ static int prune_dir(int i, char *path)
                }
                fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
        }
+       if (!show_only)
+               rmdir(path);
        closedir(dir);
        return 0;
 }
index 979efcc45fca1a39b125e02d14b1f5d096f813ba..70b1168fa677fc889543e87b2a3f964b175375c6 100644 (file)
@@ -323,10 +323,10 @@ static int do_push(const char *repo)
                int dest_refspec_nr = refspec_nr;
                const char **dest_refspec = refspec;
                const char *dest = uri[i];
-               const char *sender = "git-send-pack";
+               const char *sender = "send-pack";
                if (!prefixcmp(dest, "http://") ||
                    !prefixcmp(dest, "https://"))
-                       sender = "git-http-push";
+                       sender = "http-push";
                else if (thin)
                        argv[dest_argc++] = "--thin";
                argv[0] = sender;
@@ -336,7 +336,7 @@ static int do_push(const char *repo)
                argv[dest_argc] = NULL;
                if (verbose)
                        fprintf(stderr, "Pushing to %s\n", dest);
-               err = run_command_v(argv);
+               err = run_command_v_opt(argv, RUN_GIT_CMD);
                if (!err)
                        continue;
                switch (err) {
index e47715538bd1ff81d1a91e0a43cd9bdbe1cb0d3f..316fb0f8dae022b35a89b71c94a22331a77a500a 100644 (file)
@@ -55,8 +55,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
        int cnt;
 
        hashcpy(it->sha1, tree->object.sha1);
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
        cnt = 0;
        while (tree_entry(&desc, &entry)) {
                if (!S_ISDIR(entry.mode))
@@ -85,7 +84,7 @@ static void prime_cache_tree(void)
 
 }
 
-static const char read_tree_usage[] = "git-read-tree (<sha> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] <sha1> [<sha2> [<sha3>]])";
+static const char read_tree_usage[] = "git-read-tree (<sha> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
 
 static struct lock_file lock_file;
 
@@ -101,7 +100,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
        setup_git_directory();
        git_config(git_default_config);
 
-       newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
+       newfd = hold_locked_index(&lock_file, 1);
 
        git_config(git_default_config);
 
@@ -129,6 +128,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                        continue;
                }
 
+               if (!prefixcmp(arg, "--index-output=")) {
+                       set_alternate_index_output(arg + 15);
+                       continue;
+               }
+
                /* "--prefix=<subdirectory>/" means keep the current index
                 *  entries and put the entries from the tree under the
                 * given subdirectory.
@@ -185,7 +189,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                        if (opts.dir)
                                die("more than one --exclude-per-directory are given.");
 
-                       dir = calloc(1, sizeof(*opts.dir));
+                       dir = xcalloc(1, sizeof(*opts.dir));
                        dir->show_ignored = 1;
                        dir->exclude_per_dir = arg + 24;
                        opts.dir = dir;
@@ -229,6 +233,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                if (0 <= pos)
                        die("file '%.*s' already exists.",
                                        pfxlen-1, opts.prefix);
+               opts.pos = -1 - pos;
        }
 
        if (opts.merge) {
@@ -268,7 +273,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
        }
 
        if (write_cache(newfd, active_cache, active_nr) ||
-           close(newfd) || commit_lock_file(&lock_file))
+           close(newfd) || commit_locked_index(&lock_file))
                die("unable to write new index file");
        return 0;
 }
index 186aabce042a1d6e5d83141495a854db09223bf8..4c39f1da98e5e690f28f5145a1ab5dba790da68d 100644 (file)
@@ -52,18 +52,18 @@ static int tree_is_complete(const unsigned char *sha1)
        if (tree->object.flags & INCOMPLETE)
                return 0;
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
-       if (!desc.buf) {
+       if (!tree->buffer) {
                enum object_type type;
-               void *data = read_sha1_file(sha1, &type, &desc.size);
+               unsigned long size;
+               void *data = read_sha1_file(sha1, &type, &size);
                if (!data) {
                        tree->object.flags |= INCOMPLETE;
                        return 0;
                }
-               desc.buf = data;
                tree->buffer = data;
+               tree->size = size;
        }
+       init_tree_desc(&desc, tree->buffer, tree->size);
        complete = 1;
        while (tree_entry(&desc, &entry)) {
                if (!has_sha1_file(entry.sha1) ||
index b8867ab4add83dee4ab99108e96949bcd65290a0..8c2c8bdc18a69e4dff7386548e5f7ea78a133f7b 100644 (file)
@@ -78,6 +78,13 @@ static void append_line(struct buffer *buffer, const char *line)
        buffer->nr += len;
 }
 
+static void clear_buffer(struct buffer *buffer)
+{
+       free(buffer->ptr);
+       buffer->ptr = NULL;
+       buffer->nr = buffer->alloc = 0;
+}
+
 static int handle_file(const char *path,
         unsigned char *sha1, const char *output)
 {
@@ -110,10 +117,13 @@ static int handle_file(const char *path,
                else if (!prefixcmp(buf, "======="))
                        hunk = 2;
                else if (!prefixcmp(buf, ">>>>>>> ")) {
+                       int one_is_longer = (one->nr > two->nr);
+                       int common_len = one_is_longer ? two->nr : one->nr;
+                       int cmp = memcmp(one->ptr, two->ptr, common_len);
+
                        hunk_no++;
                        hunk = 0;
-                       if (memcmp(one->ptr, two->ptr, one->nr < two->nr ?
-                                               one->nr : two->nr) > 0) {
+                       if ((cmp > 0) || ((cmp == 0) && one_is_longer)) {
                                struct buffer *swap = one;
                                one = two;
                                two = swap;
@@ -131,6 +141,8 @@ static int handle_file(const char *path,
                                SHA1_Update(&ctx, two->ptr, two->nr);
                                SHA1_Update(&ctx, "\0", 1);
                        }
+                       clear_buffer(one);
+                       clear_buffer(two);
                } else if (hunk == 1)
                        append_line(one, buf);
                else if (hunk == 2)
index c2db5a5b037babf9020353d9b11dc348915b6c1b..09774f9559b81050d89bd6663b8b672438da4342 100644 (file)
@@ -35,8 +35,10 @@ static const char rev_list_usage[] =
 "    --header | --pretty\n"
 "    --abbrev=nr | --no-abbrev\n"
 "    --abbrev-commit\n"
+"    --left-right\n"
 "  special purpose:\n"
-"    --bisect"
+"    --bisect\n"
+"    --bisect-vars"
 ;
 
 static struct rev_info revs;
@@ -168,38 +170,273 @@ static void clear_distance(struct commit_list *list)
        }
 }
 
-static struct commit_list *find_bisection(struct commit_list *list)
+#define DEBUG_BISECT 0
+
+static inline int weight(struct commit_list *elem)
 {
-       int nr, closest;
-       struct commit_list *p, *best;
+       return *((int*)(elem->item->util));
+}
 
-       nr = 0;
-       p = list;
-       while (p) {
-               if (!revs.prune_fn || (p->item->object.flags & TREECHANGE))
-                       nr++;
-               p = p->next;
+static inline void weight_set(struct commit_list *elem, int weight)
+{
+       *((int*)(elem->item->util)) = weight;
+}
+
+static int count_interesting_parents(struct commit *commit)
+{
+       struct commit_list *p;
+       int count;
+
+       for (count = 0, p = commit->parents; p; p = p->next) {
+               if (p->item->object.flags & UNINTERESTING)
+                       continue;
+               count++;
        }
-       closest = 0;
-       best = list;
+       return count;
+}
+
+static inline int halfway(struct commit_list *p, int distance, int nr)
+{
+       /*
+        * Don't short-cut something we are not going to return!
+        */
+       if (revs.prune_fn && !(p->item->object.flags & TREECHANGE))
+               return 0;
+       if (DEBUG_BISECT)
+               return 0;
+       /*
+        * 2 and 3 are halfway of 5.
+        * 3 is halfway of 6 but 2 and 4 are not.
+        */
+       distance *= 2;
+       switch (distance - nr) {
+       case -1: case 0: case 1:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+#if !DEBUG_BISECT
+#define show_list(a,b,c,d) do { ; } while (0)
+#else
+static void show_list(const char *debug, int counted, int nr,
+                     struct commit_list *list)
+{
+       struct commit_list *p;
+
+       fprintf(stderr, "%s (%d/%d)\n", debug, counted, nr);
 
        for (p = list; p; p = p->next) {
-               int distance;
+               struct commit_list *pp;
+               struct commit *commit = p->item;
+               unsigned flags = commit->object.flags;
+               enum object_type type;
+               unsigned long size;
+               char *buf = read_sha1_file(commit->object.sha1, &type, &size);
+               char *ep, *sp;
+
+               fprintf(stderr, "%c%c%c ",
+                       (flags & TREECHANGE) ? 'T' : ' ',
+                       (flags & UNINTERESTING) ? 'U' : ' ',
+                       (flags & COUNTED) ? 'C' : ' ');
+               if (commit->util)
+                       fprintf(stderr, "%3d", weight(p));
+               else
+                       fprintf(stderr, "---");
+               fprintf(stderr, " %.*s", 8, sha1_to_hex(commit->object.sha1));
+               for (pp = commit->parents; pp; pp = pp->next)
+                       fprintf(stderr, " %.*s", 8,
+                               sha1_to_hex(pp->item->object.sha1));
+
+               sp = strstr(buf, "\n\n");
+               if (sp) {
+                       sp += 2;
+                       for (ep = sp; *ep && *ep != '\n'; ep++)
+                               ;
+                       fprintf(stderr, " %.*s", (int)(ep - sp), sp);
+               }
+               fprintf(stderr, "\n");
+       }
+}
+#endif /* DEBUG_BISECT */
+
+/*
+ * zero or positive weight is the number of interesting commits it can
+ * reach, including itself.  Especially, weight = 0 means it does not
+ * reach any tree-changing commits (e.g. just above uninteresting one
+ * but traversal is with pathspec).
+ *
+ * weight = -1 means it has one parent and its distance is yet to
+ * be computed.
+ *
+ * weight = -2 means it has more than one parent and its distance is
+ * unknown.  After running count_distance() first, they will get zero
+ * or positive distance.
+ */
+
+static struct commit_list *find_bisection(struct commit_list *list,
+                                         int *reaches, int *all)
+{
+       int n, nr, on_list, counted, distance;
+       struct commit_list *p, *best, *next, *last;
+       int *weights;
+
+       show_list("bisection 2 entry", 0, 0, list);
 
-               if (revs.prune_fn && !(p->item->object.flags & TREECHANGE))
+       /*
+        * Count the number of total and tree-changing items on the
+        * list, while reversing the list.
+        */
+       for (nr = on_list = 0, last = NULL, p = list;
+            p;
+            p = next) {
+               unsigned flags = p->item->object.flags;
+
+               next = p->next;
+               if (flags & UNINTERESTING)
                        continue;
+               p->next = last;
+               last = p;
+               if (!revs.prune_fn || (flags & TREECHANGE))
+                       nr++;
+               on_list++;
+       }
+       list = last;
+       show_list("bisection 2 sorted", 0, nr, list);
+
+       *all = nr;
+       weights = xcalloc(on_list, sizeof(int*));
+       counted = 0;
+
+       for (n = 0, p = list; p; p = p->next) {
+               struct commit *commit = p->item;
+               unsigned flags = commit->object.flags;
+
+               p->item->util = &weights[n++];
+               switch (count_interesting_parents(commit)) {
+               case 0:
+                       if (!revs.prune_fn || (flags & TREECHANGE)) {
+                               weight_set(p, 1);
+                               counted++;
+                               show_list("bisection 2 count one",
+                                         counted, nr, list);
+                       }
+                       /*
+                        * otherwise, it is known not to reach any
+                        * tree-changing commit and gets weight 0.
+                        */
+                       break;
+               case 1:
+                       weight_set(p, -1);
+                       break;
+               default:
+                       weight_set(p, -2);
+                       break;
+               }
+       }
 
+       show_list("bisection 2 initialize", counted, nr, list);
+
+       /*
+        * If you have only one parent in the resulting set
+        * then you can reach one commit more than that parent
+        * can reach.  So we do not have to run the expensive
+        * count_distance() for single strand of pearls.
+        *
+        * However, if you have more than one parents, you cannot
+        * just add their distance and one for yourself, since
+        * they usually reach the same ancestor and you would
+        * end up counting them twice that way.
+        *
+        * So we will first count distance of merges the usual
+        * way, and then fill the blanks using cheaper algorithm.
+        */
+       for (p = list; p; p = p->next) {
+               if (p->item->object.flags & UNINTERESTING)
+                       continue;
+               n = weight(p);
+               if (n != -2)
+                       continue;
                distance = count_distance(p);
                clear_distance(list);
+               weight_set(p, distance);
+
+               /* Does it happen to be at exactly half-way? */
+               if (halfway(p, distance, nr)) {
+                       p->next = NULL;
+                       *reaches = distance;
+                       free(weights);
+                       return p;
+               }
+               counted++;
+       }
+
+       show_list("bisection 2 count_distance", counted, nr, list);
+
+       while (counted < nr) {
+               for (p = list; p; p = p->next) {
+                       struct commit_list *q;
+                       unsigned flags = p->item->object.flags;
+
+                       if (0 <= weight(p))
+                               continue;
+                       for (q = p->item->parents; q; q = q->next) {
+                               if (q->item->object.flags & UNINTERESTING)
+                                       continue;
+                               if (0 <= weight(q))
+                                       break;
+                       }
+                       if (!q)
+                               continue;
+
+                       /*
+                        * weight for p is unknown but q is known.
+                        * add one for p itself if p is to be counted,
+                        * otherwise inherit it from q directly.
+                        */
+                       if (!revs.prune_fn || (flags & TREECHANGE)) {
+                               weight_set(p, weight(q)+1);
+                               counted++;
+                               show_list("bisection 2 count one",
+                                         counted, nr, list);
+                       }
+                       else
+                               weight_set(p, weight(q));
+
+                       /* Does it happen to be at exactly half-way? */
+                       distance = weight(p);
+                       if (halfway(p, distance, nr)) {
+                               p->next = NULL;
+                               *reaches = distance;
+                               free(weights);
+                               return p;
+                       }
+               }
+       }
+
+       show_list("bisection 2 counted all", counted, nr, list);
+
+       /* Then find the best one */
+       counted = -1;
+       best = list;
+       for (p = list; p; p = p->next) {
+               unsigned flags = p->item->object.flags;
+
+               if (revs.prune_fn && !(flags & TREECHANGE))
+                       continue;
+               distance = weight(p);
                if (nr - distance < distance)
                        distance = nr - distance;
-               if (distance > closest) {
+               if (distance > counted) {
                        best = p;
-                       closest = distance;
+                       counted = distance;
+                       *reaches = weight(p);
                }
        }
        if (best)
                best->next = NULL;
+       free(weights);
        return best;
 }
 
@@ -225,6 +462,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
        struct commit_list *list;
        int i;
        int read_from_stdin = 0;
+       int bisect_show_vars = 0;
 
        git_config(git_default_config);
        init_revisions(&revs, prefix);
@@ -247,6 +485,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
                        bisect_list = 1;
                        continue;
                }
+               if (!strcmp(arg, "--bisect-vars")) {
+                       bisect_list = 1;
+                       bisect_show_vars = 1;
+                       continue;
+               }
                if (!strcmp(arg, "--stdin")) {
                        if (read_from_stdin++)
                                die("--stdin given twice?");
@@ -285,8 +528,39 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
        if (revs.tree_objects)
                mark_edges_uninteresting(revs.commits, &revs, show_edge);
 
-       if (bisect_list)
-               revs.commits = find_bisection(revs.commits);
+       if (bisect_list) {
+               int reaches = reaches, all = all;
+
+               revs.commits = find_bisection(revs.commits, &reaches, &all);
+               if (bisect_show_vars) {
+                       int cnt;
+                       if (!revs.commits)
+                               return 1;
+                       /*
+                        * revs.commits can reach "reaches" commits among
+                        * "all" commits.  If it is good, then there are
+                        * (all-reaches) commits left to be bisected.
+                        * On the other hand, if it is bad, then the set
+                        * to bisect is "reaches".
+                        * A bisect set of size N has (N-1) commits further
+                        * to test, as we already know one bad one.
+                        */
+                       cnt = all-reaches;
+                       if (cnt < reaches)
+                               cnt = reaches;
+                       printf("bisect_rev=%s\n"
+                              "bisect_nr=%d\n"
+                              "bisect_good=%d\n"
+                              "bisect_bad=%d\n"
+                              "bisect_all=%d\n",
+                              sha1_to_hex(revs.commits->item->object.sha1),
+                              cnt - 1,
+                              all - reaches - 1,
+                              reaches - 1,
+                              all);
+                       return 0;
+               }
+       }
 
        traverse_commit_list(&revs, show_commit, show_object);
 
diff --git a/builtin-revert.c b/builtin-revert.c
new file mode 100644 (file)
index 0000000..4ba0ee6
--- /dev/null
@@ -0,0 +1,404 @@
+#include "cache.h"
+#include "builtin.h"
+#include "object.h"
+#include "commit.h"
+#include "tag.h"
+#include "wt-status.h"
+#include "run-command.h"
+#include "exec_cmd.h"
+#include "utf8.h"
+
+/*
+ * This implements the builtins revert and cherry-pick.
+ *
+ * Copyright (c) 2007 Johannes E. Schindelin
+ *
+ * Based on git-revert.sh, which is
+ *
+ * Copyright (c) 2005 Linus Torvalds
+ * Copyright (c) 2005 Junio C Hamano
+ */
+
+static const char *revert_usage = "git-revert [--edit | --no-edit] [-n] <commit-ish>";
+
+static const char *cherry_pick_usage = "git-cherry-pick [--edit] [-n] [-r] [-x] <commit-ish>";
+
+static int edit;
+static int replay;
+enum { REVERT, CHERRY_PICK } action;
+static int no_commit;
+static struct commit *commit;
+static int needed_deref;
+
+static const char *me;
+
+#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
+
+static void parse_options(int argc, const char **argv)
+{
+       const char *usage_str = action == REVERT ?
+               revert_usage : cherry_pick_usage;
+       unsigned char sha1[20];
+       const char *arg;
+       int i;
+
+       if (argc < 2)
+               usage(usage_str);
+
+       for (i = 1; i < argc - 1; i++) {
+               arg = argv[i];
+               if (!strcmp(arg, "-n") || !strcmp(arg, "--no-commit"))
+                       no_commit = 1;
+               else if (!strcmp(arg, "-e") || !strcmp(arg, "--edit"))
+                       edit = 1;
+               else if (!strcmp(arg, "--no-edit"))
+                       edit = 0;
+               else if (!strcmp(arg, "-x") || !strcmp(arg, "--i-really-want-"
+                               "to-expose-my-private-commit-object-name"))
+                       replay = 0;
+               else if (strcmp(arg, "-r"))
+                       usage(usage_str);
+       }
+
+       arg = argv[argc - 1];
+       if (get_sha1(arg, sha1))
+               die ("Cannot find '%s'", arg);
+       commit = (struct commit *)parse_object(sha1);
+       if (!commit)
+               die ("Could not find %s", sha1_to_hex(sha1));
+       if (commit->object.type == OBJ_TAG) {
+               commit = (struct commit *)
+                       deref_tag((struct object *)commit, arg, strlen(arg));
+               needed_deref = 1;
+       }
+       if (commit->object.type != OBJ_COMMIT)
+               die ("'%s' does not point to a commit", arg);
+}
+
+static char *get_oneline(const char *message)
+{
+       char *result;
+       const char *p = message, *abbrev, *eol;
+       int abbrev_len, oneline_len;
+
+       if (!p)
+               die ("Could not read commit message of %s",
+                               sha1_to_hex(commit->object.sha1));
+       while (*p && (*p != '\n' || p[1] != '\n'))
+               p++;
+
+       if (*p) {
+               p += 2;
+               for (eol = p + 1; *eol && *eol != '\n'; eol++)
+                       ; /* do nothing */
+       } else
+               eol = p;
+       abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
+       abbrev_len = strlen(abbrev);
+       oneline_len = eol - p;
+       result = xmalloc(abbrev_len + 5 + oneline_len);
+       memcpy(result, abbrev, abbrev_len);
+       memcpy(result + abbrev_len, "... ", 4);
+       memcpy(result + abbrev_len + 4, p, oneline_len);
+       result[abbrev_len + 4 + oneline_len] = '\0';
+       return result;
+}
+
+char *get_encoding(const char *message)
+{
+       const char *p = message, *eol;
+
+       if (!p)
+               die ("Could not read commit message of %s",
+                               sha1_to_hex(commit->object.sha1));
+       while (*p && *p != '\n') {
+               for (eol = p + 1; *eol && *eol != '\n'; eol++)
+                       ; /* do nothing */
+               if (!prefixcmp(p, "encoding ")) {
+                       char *result = xmalloc(eol - 8 - p);
+                       strlcpy(result, p + 9, eol - 8 - p);
+                       return result;
+               }
+               p = eol;
+               if (*p == '\n')
+                       p++;
+       }
+       return NULL;
+}
+
+struct lock_file msg_file;
+static int msg_fd;
+
+static void add_to_msg(const char *string)
+{
+       int len = strlen(string);
+       if (write_in_full(msg_fd, string, len) < 0)
+               die ("Could not write to .msg");
+}
+
+static void add_message_to_msg(const char *message)
+{
+       const char *p = message;
+       while (*p && (*p != '\n' || p[1] != '\n'))
+               p++;
+
+       if (!*p)
+               add_to_msg(sha1_to_hex(commit->object.sha1));
+
+       p += 2;
+       add_to_msg(p);
+       return;
+}
+
+static void set_author_ident_env(const char *message)
+{
+       const char *p = message;
+       if (!p)
+               die ("Could not read commit message of %s",
+                               sha1_to_hex(commit->object.sha1));
+       while (*p && *p != '\n') {
+               const char *eol;
+
+               for (eol = p; *eol && *eol != '\n'; eol++)
+                       ; /* do nothing */
+               if (!prefixcmp(p, "author ")) {
+                       char *line, *pend, *email, *timestamp;
+
+                       p += 7;
+                       line = xmalloc(eol + 1 - p);
+                       memcpy(line, p, eol - p);
+                       line[eol - p] = '\0';
+                       email = strchr(line, '<');
+                       if (!email)
+                               die ("Could not extract author email from %s",
+                                       sha1_to_hex(commit->object.sha1));
+                       if (email == line)
+                               pend = line;
+                       else
+                               for (pend = email; pend != line + 1 &&
+                                               isspace(pend[-1]); pend--);
+                                       ; /* do nothing */
+                       *pend = '\0';
+                       email++;
+                       timestamp = strchr(email, '>');
+                       if (!timestamp)
+                               die ("Could not extract author email from %s",
+                                       sha1_to_hex(commit->object.sha1));
+                       *timestamp = '\0';
+                       for (timestamp++; *timestamp && isspace(*timestamp);
+                                       timestamp++)
+                               ; /* do nothing */
+                       setenv("GIT_AUTHOR_NAME", line, 1);
+                       setenv("GIT_AUTHOR_EMAIL", email, 1);
+                       setenv("GIT_AUTHOR_DATE", timestamp, 1);
+                       free(line);
+                       return;
+               }
+               p = eol;
+               if (*p == '\n')
+                       p++;
+       }
+       die ("No author information found in %s",
+                       sha1_to_hex(commit->object.sha1));
+}
+
+static int merge_recursive(const char *base_sha1,
+               const char *head_sha1, const char *head_name,
+               const char *next_sha1, const char *next_name)
+{
+       char buffer[256];
+       const char *argv[6];
+
+       sprintf(buffer, "GITHEAD_%s", head_sha1);
+       setenv(buffer, head_name, 1);
+       sprintf(buffer, "GITHEAD_%s", next_sha1);
+       setenv(buffer, next_name, 1);
+
+       /*
+        * This three way merge is an interesting one.  We are at
+        * $head, and would want to apply the change between $commit
+        * and $prev on top of us (when reverting), or the change between
+        * $prev and $commit on top of us (when cherry-picking or replaying).
+        */
+       argv[0] = "merge-recursive";
+       argv[1] = base_sha1;
+       argv[2] = "--";
+       argv[3] = head_sha1;
+       argv[4] = next_sha1;
+       argv[5] = NULL;
+
+       return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD);
+}
+
+static int revert_or_cherry_pick(int argc, const char **argv)
+{
+       unsigned char head[20];
+       struct commit *base, *next;
+       int i;
+       char *oneline, *reencoded_message = NULL;
+       const char *message, *encoding;
+
+       git_config(git_default_config);
+       me = action == REVERT ? "revert" : "cherry-pick";
+       setenv(GIT_REFLOG_ACTION, me, 0);
+       parse_options(argc, argv);
+
+       /* this is copied from the shell script, but it's never triggered... */
+       if (action == REVERT && replay)
+               die("revert is incompatible with replay");
+
+       if (no_commit) {
+               /*
+                * We do not intend to commit immediately.  We just want to
+                * merge the differences in.
+                */
+               if (write_tree(head, 0, NULL))
+                       die ("Your index file is unmerged.");
+       } else {
+               struct wt_status s;
+
+               if (get_sha1("HEAD", head))
+                       die ("You do not have a valid HEAD");
+               wt_status_prepare(&s);
+               if (s.commitable || s.workdir_dirty)
+                       die ("Dirty index: cannot %s", me);
+               discard_cache();
+       }
+
+       if (!commit->parents)
+               die ("Cannot %s a root commit", me);
+       if (commit->parents->next)
+               die ("Cannot %s a multi-parent commit.", me);
+       if (!(message = commit->buffer))
+               die ("Cannot get commit message for %s",
+                               sha1_to_hex(commit->object.sha1));
+
+       /*
+        * "commit" is an existing commit.  We would want to apply
+        * the difference it introduces since its first parent "prev"
+        * on top of the current HEAD if we are cherry-pick.  Or the
+        * reverse of it if we are revert.
+        */
+
+       msg_fd = hold_lock_file_for_update(&msg_file, ".msg", 1);
+
+       encoding = get_encoding(message);
+       if (!encoding)
+               encoding = "utf-8";
+       if (!git_commit_encoding)
+               git_commit_encoding = "utf-8";
+       if ((reencoded_message = reencode_string(message,
+                                       git_commit_encoding, encoding)))
+               message = reencoded_message;
+
+       oneline = get_oneline(message);
+
+       if (action == REVERT) {
+               char *oneline_body = strchr(oneline, ' ');
+
+               base = commit;
+               next = commit->parents->item;
+               add_to_msg("Revert \"");
+               add_to_msg(oneline_body + 1);
+               add_to_msg("\"\n\nThis reverts commit ");
+               add_to_msg(sha1_to_hex(commit->object.sha1));
+               add_to_msg(".\n");
+       } else {
+               base = commit->parents->item;
+               next = commit;
+               set_author_ident_env(message);
+               add_message_to_msg(message);
+               if (!replay) {
+                       add_to_msg("(cherry picked from commit ");
+                       add_to_msg(sha1_to_hex(commit->object.sha1));
+                       add_to_msg(")\n");
+               }
+       }
+       if (needed_deref) {
+               add_to_msg("(original 'git ");
+               add_to_msg(me);
+               add_to_msg("' arguments: ");
+               for (i = 0; i < argc; i++) {
+                       if (i)
+                               add_to_msg(" ");
+                       add_to_msg(argv[i]);
+               }
+               add_to_msg(")\n");
+       }
+
+       if (merge_recursive(sha1_to_hex(base->object.sha1),
+                               sha1_to_hex(head), "HEAD",
+                               sha1_to_hex(next->object.sha1), oneline) ||
+                       write_tree(head, 0, NULL)) {
+               const char *target = git_path("MERGE_MSG");
+               add_to_msg("\nConflicts:\n\n");
+               read_cache();
+               for (i = 0; i < active_nr;) {
+                       struct cache_entry *ce = active_cache[i++];
+                       if (ce_stage(ce)) {
+                               add_to_msg("\t");
+                               add_to_msg(ce->name);
+                               add_to_msg("\n");
+                               while (i < active_nr && !strcmp(ce->name,
+                                               active_cache[i]->name))
+                                       i++;
+                       }
+               }
+               if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
+                       die ("Error wrapping up .msg");
+               unlink(target);
+               if (rename(".msg", target))
+                       die ("Could not move .msg to %s", target);
+               fprintf(stderr, "Automatic %s failed.  "
+                       "After resolving the conflicts,\n"
+                       "mark the corrected paths with 'git-add <paths>'\n"
+                       "and commit the result.\n", me);
+               if (action == CHERRY_PICK) {
+                       fprintf(stderr, "When commiting, use the option "
+                               "'-c %s' to retain authorship and message.\n",
+                               find_unique_abbrev(commit->object.sha1,
+                                       DEFAULT_ABBREV));
+               }
+               exit(1);
+       }
+       if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
+               die ("Error wrapping up .msg");
+       fprintf(stderr, "Finished one %s.\n", me);
+
+       /*
+        *
+        * If we are cherry-pick, and if the merge did not result in
+        * hand-editing, we will hit this commit and inherit the original
+        * author date and name.
+        * If we are revert, or if our cherry-pick results in a hand merge,
+        * we had better say that the current user is responsible for that.
+        */
+
+       if (!no_commit) {
+               if (edit)
+                       return execl_git_cmd("commit", "-n", "-F", ".msg",
+                               "-e", NULL);
+               else
+                       return execl_git_cmd("commit", "-n", "-F", ".msg",
+                               NULL);
+       }
+       if (reencoded_message)
+               free(reencoded_message);
+
+       return 0;
+}
+
+int cmd_revert(int argc, const char **argv, const char *prefix)
+{
+       if (isatty(0))
+               edit = 1;
+       action = REVERT;
+       return revert_or_cherry_pick(argc, argv);
+}
+
+int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
+{
+       replay = 1;
+       action = CHERRY_PICK;
+       return revert_or_cherry_pick(argc, argv);
+}
index 00dbe399609051647f393e0c543a862a0ba432c8..8a0738f83dd31a847bf486ddb3aefef94af5e049 100644 (file)
@@ -89,20 +89,10 @@ static int check_local_mod(unsigned char *head)
                if (ce_match_stat(ce, &st, 0))
                        errs = error("'%s' has local modifications "
                                     "(hint: try -f)", ce->name);
-               if (no_head)
-                       continue;
-               /*
-                * It is Ok to remove a newly added path, as long as
-                * it is cache-clean.
-                */
-               if (get_tree_entry(head, name, sha1, &mode))
-                       continue;
-               /*
-                * Otherwise make sure the version from the HEAD
-                * matches the index.
-                */
-               if (ce->ce_mode != create_ce_mode(mode) ||
-                   hashcmp(ce->sha1, sha1))
+               if (no_head
+                    || get_tree_entry(head, name, sha1, &mode)
+                    || ce->ce_mode != create_ce_mode(mode)
+                    || hashcmp(ce->sha1, sha1))
                        errs = error("'%s' has changes staged in the index "
                                     "(hint: try -f)", name);
        }
@@ -120,7 +110,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 
        git_config(git_default_config);
 
-       newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
+       newfd = hold_locked_index(&lock_file, 1);
 
        if (read_cache() < 0)
                die("index file corrupt");
@@ -230,7 +220,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 
        if (active_cache_changed) {
                if (write_cache(newfd, active_cache, active_nr) ||
-                   close(newfd) || commit_lock_file(&lock_file))
+                   close(newfd) || commit_locked_index(&lock_file))
                        die("Unable to write new index file");
        }
 
index 2d7726e8b975d9977e14638cc127ed0b30d3058b..29343aefc843c4dd22095f559262bc6b5e381440 100644 (file)
@@ -304,8 +304,11 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
        if (!access(".mailmap", R_OK))
                read_mailmap(".mailmap");
 
-       if (rev.pending.nr == 0)
+       if (rev.pending.nr == 0) {
+               if (isatty(0))
+                       fprintf(stderr, "(reading log to summarize from standard input)\n");
                read_from_stdin(&list);
+       }
        else
                get_from_rev(&rev, &list);
 
index 71cef633c0e36b3a33fa29eccb8579a9304b0777..47d42ed6450695b0502b58e6aca9dabeb96e5bf5 100644 (file)
@@ -60,7 +60,7 @@ static int mark_valid(const char *path)
        return -1;
 }
 
-static int add_file_to_cache(const char *path)
+static int process_file(const char *path)
 {
        int size, namelen, option, status;
        struct cache_entry *ce;
@@ -210,7 +210,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
                report("remove '%s'", path);
                goto free_return;
        }
-       if (add_file_to_cache(p))
+       if (process_file(p))
                die("Unable to process file %s", path);
        report("add '%s'", path);
  free_return:
@@ -495,7 +495,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
        /* We can't free this memory, it becomes part of a linked list parsed atexit() */
        lock_file = xcalloc(1, sizeof(struct lock_file));
 
-       newfd = hold_lock_file_for_update(lock_file, get_index_file(), 0);
+       newfd = hold_locked_index(lock_file, 0);
        if (newfd < 0)
                lock_error = errno;
 
@@ -661,7 +661,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                            get_index_file(), strerror(lock_error));
                }
                if (write_cache(newfd, active_cache, active_nr) ||
-                   close(newfd) || commit_lock_file(lock_file))
+                   close(newfd) || commit_locked_index(lock_file))
                        die("Unable to write new index file");
        }
 
index 90fc1cfcf40d057cd654edd1454f56cd823efd66..c88bbd1b9be0fe2c033e2fe9daef0a8a2dae03a5 100644 (file)
@@ -18,7 +18,7 @@ int write_tree(unsigned char *sha1, int missing_ok, const char *prefix)
        /* We can't free this memory, it becomes part of a linked list parsed atexit() */
        struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
 
-       newfd = hold_lock_file_for_update(lock_file, get_index_file(), 0);
+       newfd = hold_locked_index(lock_file, 1);
 
        entries = read_cache();
        if (entries < 0)
index 528074b61508fbf25fe0fdc7fbfa7a5bb9930a25..af203e9e367b1dc1abb012234b5a8ae5e09f1629 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -24,6 +24,7 @@ extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
 extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
 extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
 extern int cmd_cherry(int argc, const char **argv, const char *prefix);
+extern int cmd_cherry_pick(int argc, const char **argv, const char *prefix);
 extern int cmd_commit_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_count_objects(int argc, const char **argv, const char *prefix);
 extern int cmd_describe(int argc, const char **argv, const char *prefix);
@@ -31,10 +32,12 @@ extern int cmd_diff_files(int argc, const char **argv, const char *prefix);
 extern int cmd_diff_index(int argc, const char **argv, const char *prefix);
 extern int cmd_diff(int argc, const char **argv, const char *prefix);
 extern int cmd_diff_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_fetch__tool(int argc, const char **argv, const char *prefix);
 extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);
 extern int cmd_for_each_ref(int argc, const char **argv, const char *prefix);
 extern int cmd_format_patch(int argc, const char **argv, const char *prefix);
 extern int cmd_fsck(int argc, const char **argv, const char *prefix);
+extern int cmd_gc(int argc, const char **argv, const char *prefix);
 extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
 extern int cmd_grep(int argc, const char **argv, const char *prefix);
 extern int cmd_help(int argc, const char **argv, const char *prefix);
@@ -60,6 +63,7 @@ extern int cmd_config(int argc, const char **argv, const char *prefix);
 extern int cmd_rerere(int argc, const char **argv, const char *prefix);
 extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
 extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
+extern int cmd_revert(int argc, const char **argv, const char *prefix);
 extern int cmd_rm(int argc, const char **argv, const char *prefix);
 extern int cmd_runstatus(int argc, const char **argv, const char *prefix);
 extern int cmd_shortlog(int argc, const char **argv, const char *prefix);
diff --git a/cache.h b/cache.h
index ae25759c433a29caeb8662ef3ccfe4c0f3422bd5..1b50c32b139256c5d8be96a85b02f1ce9855f15a 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -128,7 +128,6 @@ static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned in
 extern struct cache_entry **active_cache;
 extern unsigned int active_nr, active_alloc, active_cache_changed;
 extern struct cache_tree *active_cache_tree;
-extern int cache_errno;
 
 enum object_type {
        OBJ_BAD = -1,
@@ -188,7 +187,7 @@ extern int add_cache_entry(struct cache_entry *ce, int option);
 extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
 extern int remove_cache_entry_at(int pos);
 extern int remove_file_from_cache(const char *path);
-extern int add_file_to_index(const char *path, int verbose);
+extern int add_file_to_cache(const char *path, int verbose);
 extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
 extern int ce_match_stat(struct cache_entry *ce, struct stat *st, int);
 extern int ce_modified(struct cache_entry *ce, struct stat *st, int);
@@ -212,6 +211,11 @@ struct lock_file {
 };
 extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
 extern int commit_lock_file(struct lock_file *);
+
+extern int hold_locked_index(struct lock_file *, int);
+extern int commit_locked_index(struct lock_file *);
+extern void set_alternate_index_output(const char *);
+
 extern void rollback_lock_file(struct lock_file *);
 extern int delete_ref(const char *, unsigned char *sha1);
 
@@ -228,6 +232,7 @@ extern const char *apply_default_whitespace;
 extern int zlib_compression_level;
 extern size_t packed_git_window_size;
 extern size_t packed_git_limit;
+extern size_t delta_base_cache_limit;
 extern int auto_crlf;
 
 #define GIT_REPO_VERSION 0
@@ -281,9 +286,8 @@ char *enter_repo(char *path, int strict);
 
 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
 extern int sha1_object_info(const unsigned char *, unsigned long *);
-extern void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size);
 extern void * read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size);
-extern int hash_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *sha1);
+extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
 extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
 extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
 
@@ -372,9 +376,11 @@ struct pack_window {
 extern struct packed_git {
        struct packed_git *next;
        struct pack_window *windows;
-       uint32_t *index_base;
+       const void *index_data;
        off_t index_size;
        off_t pack_size;
+       time_t mtime;
+       int index_version;
        int pack_fd;
        int pack_local;
        unsigned char sha1[20];
@@ -412,7 +418,7 @@ extern int server_supports(const char *feature);
 
 extern struct packed_git *parse_pack_index(unsigned char *sha1);
 extern struct packed_git *parse_pack_index_file(const unsigned char *sha1,
-                                               char *idx_path);
+                                               const char *idx_path);
 
 extern void prepare_packed_git(void);
 extern void reprepare_packed_git(void);
@@ -424,9 +430,9 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
 extern void pack_report(void);
 extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *);
 extern void unuse_pack(struct pack_window **);
-extern struct packed_git *add_packed_git(char *, int, int);
+extern struct packed_git *add_packed_git(const char *, int, int);
 extern uint32_t num_packed_objects(const struct packed_git *p);
-extern int nth_packed_object_sha1(const struct packed_git *, uint32_t, unsigned char*);
+extern const unsigned char *nth_packed_object_sha1(const struct packed_git *, uint32_t);
 extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *);
 extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
 extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
@@ -450,7 +456,7 @@ extern int check_repository_format_version(const char *var, const char *value);
 extern char git_default_email[MAX_GITNAME];
 extern char git_default_name[MAX_GITNAME];
 
-extern char *git_commit_encoding;
+extern const char *git_commit_encoding;
 extern const char *git_log_output_encoding;
 
 extern int copy_fd(int ifd, int ofd);
@@ -481,6 +487,7 @@ extern struct tag *alloc_tag_node(void);
 extern void alloc_report(void);
 
 /* trace.c */
+extern int nfasprintf(char **str, const char *fmt, ...);
 extern int nfvasprintf(char **str, const char *fmt, va_list va);
 extern void trace_printf(const char *format, ...);
 extern void trace_argv_printf(const char **argv, int count, const char *format, ...);
index 5b9234e12e8d1ef46d0d53b15cea850dfbde14c2..754d1b8a0b8282fd3d1d6bd8f6ccb21b407504a5 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -654,6 +654,7 @@ static char *get_header(const struct commit *commit, const char *key)
 static char *replace_encoding_header(char *buf, const char *encoding)
 {
        char *encoding_header = strstr(buf, "\nencoding ");
+       char *header_end = strstr(buf, "\n\n");
        char *end_of_encoding_header;
        int encoding_header_pos;
        int encoding_header_len;
@@ -661,8 +662,10 @@ static char *replace_encoding_header(char *buf, const char *encoding)
        int need_len;
        int buflen = strlen(buf) + 1;
 
-       if (!encoding_header)
-               return buf; /* should not happen but be defensive */
+       if (!header_end)
+               header_end = buf + buflen;
+       if (!encoding_header || encoding_header >= header_end)
+               return buf;
        encoding_header++;
        end_of_encoding_header = strchr(encoding_header, '\n');
        if (!end_of_encoding_header)
@@ -706,7 +709,7 @@ static char *logmsg_reencode(const struct commit *commit,
        encoding = get_header(commit, "encoding");
        use_encoding = encoding ? encoding : utf8;
        if (!strcmp(use_encoding, output_encoding))
-               out = strdup(commit->buffer);
+               out = xstrdup(commit->buffer);
        else
                out = reencode_string(commit->buffer,
                                      output_encoding, use_encoding);
@@ -760,7 +763,7 @@ static void fill_person(struct interp *table, const char *msg, int len)
        if (msg + start == ep)
                return;
 
-       table[5].value = xstrndup(msg + start, ep - msg + start);
+       table[5].value = xstrndup(msg + start, ep - (msg + start));
 
        /* parse tz */
        for (start = ep - msg + 1; start < len && isspace(msg[start]); start++)
@@ -849,19 +852,23 @@ static long format_commit_message(const struct commit *commit,
        interp_set_entry(table, ITREE_ABBREV,
                        find_unique_abbrev(commit->tree->object.sha1,
                                DEFAULT_ABBREV));
+
+       parents[1] = 0;
        for (i = 0, p = commit->parents;
                        p && i < sizeof(parents) - 1;
                        p = p->next)
-               i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ",
+               i += snprintf(parents + i, sizeof(parents) - i - 1, " %s",
                        sha1_to_hex(p->item->object.sha1));
-       interp_set_entry(table, IPARENTS, parents);
+       interp_set_entry(table, IPARENTS, parents + 1);
+
+       parents[1] = 0;
        for (i = 0, p = commit->parents;
                        p && i < sizeof(parents) - 1;
                        p = p->next)
-               i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ",
+               i += snprintf(parents + i, sizeof(parents) - i - 1, " %s",
                        find_unique_abbrev(p->item->object.sha1,
                                DEFAULT_ABBREV));
-       interp_set_entry(table, IPARENTS_ABBREV, parents);
+       interp_set_entry(table, IPARENTS_ABBREV, parents + 1);
 
        for (i = 0, state = HEADER; msg[i] && state < BODY; i++) {
                int eol;
@@ -884,7 +891,8 @@ static long format_commit_message(const struct commit *commit,
                        fill_person(table + ICOMMITTER_NAME,
                                        msg + i + 10, eol - i - 10);
                else if (!prefixcmp(msg + i, "encoding "))
-                       table[IENCODING].value = xstrndup(msg + i, eol - i);
+                       table[IENCODING].value =
+                               xstrndup(msg + i + 9, eol - i - 9);
                i = eol;
        }
        if (msg[i])
index a3c7b772bce1d302e60bbf02212bb4ad4da0ee7b..70d105567921fe75518d8d5fe3d3df4aad0659cd 100644 (file)
--- a/config.c
+++ b/config.c
@@ -331,6 +331,11 @@ int git_default_config(const char *var, const char *value)
                return 0;
        }
 
+       if (!strcmp(var, "core.deltabasecachelimit")) {
+               delta_base_cache_limit = git_config_int(var, value);
+               return 0;
+       }
+
        if (!strcmp(var, "core.autocrlf")) {
                if (value && !strcasecmp(value, "input")) {
                        auto_crlf = -1;
@@ -351,12 +356,12 @@ int git_default_config(const char *var, const char *value)
        }
 
        if (!strcmp(var, "i18n.commitencoding")) {
-               git_commit_encoding = strdup(value);
+               git_commit_encoding = xstrdup(value);
                return 0;
        }
 
        if (!strcmp(var, "i18n.logoutputencoding")) {
-               git_log_output_encoding = strdup(value);
+               git_log_output_encoding = xstrdup(value);
                return 0;
        }
 
@@ -911,8 +916,8 @@ int git_config_rename_section(const char *old_name, const char *new_name)
        }
 
        if (!(config_file = fopen(config_filename, "rb"))) {
-               ret = error("Could not open config file!");
-               goto out;
+               /* no config file means nothing to rename, no error */
+               goto unlock_and_out;
        }
 
        while (fgets(buf, sizeof(buf), config_file)) {
@@ -946,6 +951,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
                }
        }
        fclose(config_file);
+ unlock_and_out:
        if (close(out_fd) || commit_lock_file(lock) < 0)
                        ret = error("Cannot commit config file!");
  out:
index 9a578405d856c3633e7137a24964b7b80fd96485..eb9d7a55496492fa021e8262f052c7f46b60ea20 100644 (file)
@@ -6,6 +6,7 @@ CFLAGS = @CFLAGS@
 AR = @AR@
 TAR = @TAR@
 #INSTALL = @INSTALL@           # needs install-sh or install.sh in sources
+TCLTK_PATH = @TCLTK_PATH@
 
 prefix = @prefix@
 exec_prefix = @exec_prefix@
index 3a8e778defcf1f0e1285664785c69d9213f99516..50d2b85ace7d79ba1b8c576b54c6ef1f22ddf91f 100644 (file)
@@ -75,6 +75,14 @@ GIT_ARG_SET_PATH(shell)
 # Define PERL_PATH to provide path to Perl.
 GIT_ARG_SET_PATH(perl)
 #
+# Declare the with-tcltk/without-tcltk options.
+AC_ARG_WITH(tcltk,
+AS_HELP_STRING([--with-tcltk],[use Tcl/Tk GUI (default is YES)])
+AS_HELP_STRING([],[ARG is the full path to the Tcl/Tk interpreter.])
+AS_HELP_STRING([],[Bare --with-tcltk will make the GUI part only if])
+AS_HELP_STRING([],[Tcl/Tk interpreter will be found in a system.]),\
+GIT_PARSE_WITH(tcltk))
+#
 
 
 ## Checks for programs.
@@ -84,6 +92,22 @@ AC_PROG_CC([cc gcc])
 #AC_PROG_INSTALL               # needs install-sh or install.sh in sources
 AC_CHECK_TOOL(AR, ar, :)
 AC_CHECK_PROGS(TAR, [gtar tar])
+# TCLTK_PATH will be set to some value if we want Tcl/Tk
+# or will be empty otherwise.
+if test -z "$NO_TCLTK"; then
+  if test "$with_tcltk" = ""; then
+  # No Tcl/Tk switches given. Do not check for Tcl/Tk, use bare 'wish'.
+    TCLTK_PATH=wish
+    AC_SUBST(TCLTK_PATH)
+  elif test "$with_tcltk" = "yes"; then
+  # Tcl/Tk check requested.
+    AC_CHECK_PROGS(TCLTK_PATH, [wish], )
+  else
+    AC_MSG_RESULT([Using Tcl/Tk interpreter $with_tcltk])
+    TCLTK_PATH="$with_tcltk"
+    AC_SUBST(TCLTK_PATH)
+  fi
+fi
 
 ## Checks for libraries.
 AC_MSG_NOTICE([CHECKS for libraries])
index 8a8a13bb72b33f335a5a10642f0461ef673ef168..da89c9cfcf3469dfab789f2644f953ea46666e90 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -3,6 +3,7 @@
 #include "pkt-line.h"
 #include "quote.h"
 #include "refs.h"
+#include "run-command.h"
 
 static char *server_capabilities;
 
@@ -416,6 +417,8 @@ static int git_tcp_connect_sock(char *host)
        if (colon) {
                *colon = 0;
                port = colon + 1;
+               if (!*port)
+                       port = "<none>";
        }
 
        memset(&hints, 0, sizeof(hints));
@@ -424,7 +427,7 @@ static int git_tcp_connect_sock(char *host)
 
        gai = getaddrinfo(host, port, &hints, &ai);
        if (gai)
-               die("Unable to look up %s (%s)", host, gai_strerror(gai));
+               die("Unable to look up %s (port %s) (%s)", host, port, gai_strerror(gai));
 
        for (ai0 = ai; ai; ai = ai->ai_next) {
                sockfd = socket(ai->ai_family,
@@ -598,8 +601,8 @@ static void git_proxy_connect(int fd[2], char *host)
 {
        const char *port = STR(DEFAULT_GIT_PORT);
        char *colon, *end;
-       int pipefd[2][2];
-       pid_t pid;
+       const char *argv[4];
+       struct child_process proxy;
 
        if (host[0] == '[') {
                end = strchr(host + 1, ']');
@@ -618,25 +621,18 @@ static void git_proxy_connect(int fd[2], char *host)
                port = colon + 1;
        }
 
-       if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
-               die("unable to create pipe pair for communication");
-       pid = fork();
-       if (!pid) {
-               dup2(pipefd[1][0], 0);
-               dup2(pipefd[0][1], 1);
-               close(pipefd[0][0]);
-               close(pipefd[0][1]);
-               close(pipefd[1][0]);
-               close(pipefd[1][1]);
-               execlp(git_proxy_command, git_proxy_command, host, port, NULL);
-               die("exec failed");
-       }
-       if (pid < 0)
-               die("fork failed");
-       fd[0] = pipefd[0][0];
-       fd[1] = pipefd[1][1];
-       close(pipefd[0][1]);
-       close(pipefd[1][0]);
+       argv[0] = git_proxy_command;
+       argv[1] = host;
+       argv[2] = port;
+       argv[3] = NULL;
+       memset(&proxy, 0, sizeof(proxy));
+       proxy.argv = argv;
+       proxy.in = -1;
+       proxy.out = -1;
+       if (start_command(&proxy))
+               die("cannot start proxy %s", argv[0]);
+       fd[0] = proxy.out; /* read from proxy stdout */
+       fd[1] = proxy.in;  /* write to proxy stdin */
 }
 
 #define MAX_CMD_LEN 1024
diff --git a/contrib/continuous/cidaemon b/contrib/continuous/cidaemon
new file mode 100644 (file)
index 0000000..4009a15
--- /dev/null
@@ -0,0 +1,503 @@
+#!/usr/bin/perl
+#
+# A daemon that waits for update events sent by its companion
+# post-receive-cinotify hook, checks out a new copy of source,
+# compiles it, and emails the guilty parties if the compile
+# (and optionally test suite) fails.
+#
+# To use this daemon, configure it and run it.  It will disconnect
+# from your terminal and fork into the background.  The daemon must
+# have local filesystem access to the source repositories, as it
+# uses objects/info/alternates to avoid copying objects.
+#
+# Add its companion post-receive-cinotify hook as the post-receive
+# hook to each repository that the daemon should monitor.  Yes, a
+# single daemon can monitor more than one repository.
+#
+# To use multiple daemons on the same system, give them each a
+# unique queue file and tmpdir.
+#
+# Global Config
+# -------------
+# Reads from a Git style configuration file.  This will be
+# ~/.gitconfig by default but can be overridden by setting
+# the GIT_CONFIG_FILE environment variable before starting.
+#
+# cidaemon.smtpHost
+#   Hostname of the SMTP server the daemon will send email
+#   through.  Defaults to 'localhost'.
+#
+# cidaemon.smtpUser
+#   Username to authenticate to the SMTP server as.  This
+#   variable is optional; if it is not supplied then no
+#   authentication will be performed.
+#
+# cidaemon.smtpPassword
+#   Password to authenticate to the SMTP server as.  This
+#   variable is optional.  If not supplied but smtpUser was,
+#   the daemon prompts for the password before forking into
+#   the background.
+#
+# cidaemon.smtpAuth
+#   Type of authentication to perform with the SMTP server.
+#   If set to 'login' and smtpUser was defined, this will
+#   use the AUTH LOGIN command, which is suitable for use
+#   with at least one version of Microsoft Exchange Server.
+#   If not set the daemon will use whatever auth methods
+#   are supported by your version of Net::SMTP.
+#
+# cidaemon.email
+#   Email address that daemon generated emails will be sent
+#   from.  This should be a useful email address within your
+#   organization.  Required.
+#
+# cidaemon.name
+#   Human friendly name that the daemon will send emails as.
+#   Defaults to 'cidaemon'.
+#
+# cidaemon.scanDelay
+#   Number of seconds to sleep between polls of the queue file.
+#   Defaults to 60.
+#
+# cidaemon.recentCache
+#   Number of recent commit SHA-1s per repository to cache and
+#   skip building if they appear again.  This is useful to avoid
+#   rebuilding the same commit multiple times just because it was
+#   pushed into more than one branch.  Defaults to 100.
+#
+# cidaemon.tmpdir
+#   Scratch directory to create the builds within.  The daemon
+#   makes a new subdirectory for each build, then deletes it when
+#   the build has finished.  The pid file is also placed here.
+#   Defaults to '/tmp'.
+#
+# cidaemon.queue
+#   Path to the queue file that the post-receive-cinotify hook
+#   appends events to.  This file is polled by the daemon.  It
+#   must not be on an NFS mount (uses flock).  Required.
+#
+# cidaemon.nocc
+#   Perl regex patterns to match against author and committer
+#   lines.  If a pattern matches, that author or committer will
+#   not be notified of a build failure.
+#
+# Per Repository Config
+# ----------------------
+# Read from the source repository's config file.
+#
+# builder.command
+#   Shell command to execute the build.  This command must
+#   return 0 on "success" and non-zero on failure.  If you
+#   also want to run a test suite, make sure your command
+#   does that too.  Required.
+#
+# builder.queue
+#   Queue file to notify the cidaemon through.  Should match
+#   cidaemon.queue.  If not set the hook will not notify the
+#   cidaemon.
+#
+# builder.skip
+#   Perl regex patterns of refs that should not be sent to
+#   cidaemon.  Updates of these refs will be ignored.
+#
+# builder.newBranchBase
+#   Glob patterns of refs that should be used to form the
+#   'old' revions of a newly created ref.  This should set
+#   to be globs that match your 'mainline' branches.  This
+#   way a build failure of a brand new topic branch does not
+#   attempt to email everyone since the beginning of time;
+#   instead it only emails those authors of commits not in
+#   these 'mainline' branches.
+
+local $ENV{PATH} = join ':', qw(
+       /opt/git/bin
+       /usr/bin
+       /bin
+       );
+
+use strict;
+use warnings;
+use FindBin qw($RealBin);
+use File::Spec;
+use lib File::Spec->catfile($RealBin, '..', 'perl5');
+use Storable qw(retrieve nstore);
+use Fcntl ':flock';
+use POSIX qw(strftime);
+use Getopt::Long qw(:config no_auto_abbrev auto_help);
+
+sub git_config ($;$)
+{
+       my $var = shift;
+       my $required = shift || 0;
+       local *GIT;
+       open GIT, '-|','git','config','--get',$var;
+       my $r = <GIT>;
+       chop $r if $r;
+       close GIT;
+       die "error: $var not set.\n" if ($required && !$r);
+       return $r;
+}
+
+package EXCHANGE_NET_SMTP;
+
+# Microsoft Exchange Server requires an 'AUTH LOGIN'
+# style of authentication.  This is different from
+# the default supported by Net::SMTP so we subclass
+# and override the auth method to support that.
+
+use Net::SMTP;
+use Net::Cmd;
+use MIME::Base64 qw(encode_base64);
+our @ISA = qw(Net::SMTP);
+our $auth_type = ::git_config 'cidaemon.smtpAuth';
+
+sub new
+{
+       my $self = shift;
+       my $type = ref($self) || $self;
+       $type->SUPER::new(@_);
+}
+
+sub auth
+{
+       my $self = shift;
+       return $self->SUPER::auth(@_) unless $auth_type eq 'login';
+
+       my $user = encode_base64 shift, '';
+       my $pass = encode_base64 shift, '';
+       return 0 unless CMD_MORE == $self->command("AUTH LOGIN")->response;
+       return 0 unless CMD_MORE == $self->command($user)->response;
+       CMD_OK == $self->command($pass)->response;
+}
+
+package main;
+
+my ($debug_flag, %recent);
+
+my $ex_host = git_config('cidaemon.smtpHost') || 'localhost';
+my $ex_user = git_config('cidaemon.smtpUser');
+my $ex_pass = git_config('cidaemon.smtpPassword');
+
+my $ex_from_addr = git_config('cidaemon.email', 1);
+my $ex_from_name = git_config('cidaemon.name') || 'cidaemon';
+
+my $scan_delay = git_config('cidaemon.scanDelay') || 60;
+my $recent_size = git_config('cidaemon.recentCache') || 100;
+my $tmpdir = git_config('cidaemon.tmpdir') || '/tmp';
+my $queue_name = git_config('cidaemon.queue', 1);
+my $queue_lock = "$queue_name.lock";
+
+my @nocc_list;
+open GIT,'git config --get-all cidaemon.nocc|';
+while (<GIT>) {
+       chop;
+       push @nocc_list, $_;
+}
+close GIT;
+
+sub nocc_author ($)
+{
+       local $_ = shift;
+       foreach my $pat (@nocc_list) {
+               return 1 if /$pat/;
+       }
+       0;
+}
+
+sub input_echo ($)
+{
+       my $prompt = shift;
+
+       local $| = 1;
+       print $prompt;
+       my $input = <STDIN>;
+       chop $input;
+       return $input;
+}
+
+sub input_noecho ($)
+{
+       my $prompt = shift;
+
+       my $end = sub {system('stty','echo');print "\n";exit};
+       local $SIG{TERM} = $end;
+       local $SIG{INT} = $end;
+       system('stty','-echo');
+
+       local $| = 1;
+       print $prompt;
+       my $input = <STDIN>;
+       system('stty','echo');
+       print "\n";
+       chop $input;
+       return $input;
+}
+
+sub rfc2822_date ()
+{
+        strftime("%a, %d %b %Y %H:%M:%S %Z", localtime);
+}
+
+sub send_email ($$$)
+{
+       my ($subj, $body, $to) = @_;
+       my $now = rfc2822_date;
+       my $to_str = '';
+       my @rcpt_to;
+       foreach (@$to) {
+               my $s = $_;
+               $s =~ s/^/"/;
+               $s =~ s/(\s+<)/"$1/;
+               $to_str .= ', ' if $to_str;
+               $to_str .= $s;
+               push @rcpt_to, $1 if $s =~ /<(.*)>/;
+       }
+       die "Nobody to send to.\n" unless @rcpt_to;
+       my $msg = <<EOF;
+From: "$ex_from_name" <$ex_from_addr>
+To: $to_str
+Date: $now
+Subject: $subj
+
+$body
+EOF
+
+       my $smtp = EXCHANGE_NET_SMTP->new(Host => $ex_host)
+               or die "Cannot connect to $ex_host: $!\n";
+       if ($ex_user && $ex_pass) {
+               $smtp->auth($ex_user,$ex_pass)
+                       or die "$ex_host rejected $ex_user\n";
+       }
+       $smtp->mail($ex_from_addr)
+               or die "$ex_host rejected $ex_from_addr\n";
+       scalar($smtp->recipient(@rcpt_to, { SkipBad => 1 }))
+               or die "$ex_host did not accept any addresses.\n";
+       $smtp->data($msg)
+               or die "$ex_host rejected message data\n";
+       $smtp->quit;
+}
+
+sub pop_queue ()
+{
+       open LOCK, ">$queue_lock" or die "Can't open $queue_lock: $!";
+       flock LOCK, LOCK_EX;
+
+       my $queue = -f $queue_name ? retrieve $queue_name : [];
+       my $ent = shift @$queue;
+       nstore $queue, $queue_name;
+
+       flock LOCK, LOCK_UN;
+       close LOCK;
+       $ent;
+}
+
+sub git_exec (@)
+{
+       system('git',@_) == 0 or die "Cannot git " . join(' ', @_) . "\n";
+}
+
+sub git_val (@)
+{
+       open(C, '-|','git',@_);
+       my $r = <C>;
+       chop $r if $r;
+       close C;
+       $r;
+}
+
+sub do_build ($$)
+{
+       my ($git_dir, $new) = @_;
+
+       my $tmp = File::Spec->catfile($tmpdir, "builder$$");
+       system('rm','-rf',$tmp) == 0 or die "Cannot clear $tmp\n";
+       die "Cannot clear $tmp.\n" if -e $tmp;
+
+       my $result = 1;
+       eval {
+               my $command;
+               {
+                       local $ENV{GIT_DIR} = $git_dir;
+                       $command = git_val 'config','builder.command';
+               }
+               die "No builder.command for $git_dir.\n" unless $command;
+
+               git_exec 'clone','-n','-l','-s',$git_dir,$tmp;
+               chmod 0700, $tmp or die "Cannot lock $tmp\n";
+               chdir $tmp or die "Cannot enter $tmp\n";
+
+               git_exec 'update-ref','HEAD',$new;
+               git_exec 'read-tree','-m','-u','HEAD','HEAD';
+               system $command;
+               if ($? == -1) {
+                       print STDERR "failed to execute '$command': $!\n";
+                       $result = 1;
+               } elsif ($? & 127) {
+                       my $sig = $? & 127;
+                       print STDERR "'$command' died from signal $sig\n";
+                       $result = 1;
+               } else {
+                       my $r = $? >> 8;
+                       print STDERR "'$command' exited with $r\n" if $r;
+                       $result = $r;
+               }
+       };
+       if ($@) {
+               $result = 2;
+               print STDERR "$@\n";
+       }
+
+       chdir '/';
+       system('rm','-rf',$tmp);
+       rmdir $tmp;
+       $result;
+}
+
+sub build_failed ($$$$$)
+{
+       my ($git_dir, $ref, $old, $new, $msg) = @_;
+
+       $git_dir =~ m,/([^/]+)$,;
+       my $repo_name = $1;
+       $ref =~ s,^refs/(heads|tags)/,,;
+
+       my %authors;
+       my $shortlog;
+       my $revstr;
+       {
+               local $ENV{GIT_DIR} = $git_dir;
+               my @revs = ($new);
+               push @revs, '--not', @$old if @$old;
+               open LOG,'-|','git','rev-list','--pretty=raw',@revs;
+               while (<LOG>) {
+                       if (s/^(author|committer) //) {
+                               chomp;
+                               s/>.*$/>/;
+                               $authors{$_} = 1 unless nocc_author $_;
+                       }
+               }
+               close LOG;
+               open LOG,'-|','git','shortlog',@revs;
+               $shortlog .= $_ while <LOG>;
+               close LOG;
+               $revstr = join(' ', @revs);
+       }
+
+       my @to = sort keys %authors;
+       unless (@to) {
+               print STDERR "error: No authors in $revstr\n";
+               return;
+       }
+
+       my $subject = "[$repo_name] $ref : Build Failed";
+       my $body = <<EOF;
+Project: $git_dir
+Branch:  $ref
+Commits: $revstr
+
+$shortlog
+Build Output:
+--------------------------------------------------------------
+$msg
+EOF
+       send_email($subject, $body, \@to);
+}
+
+sub run_build ($$$$)
+{
+       my ($git_dir, $ref, $old, $new) = @_;
+
+       if ($debug_flag) {
+               my @revs = ($new);
+               push @revs, '--not', @$old if @$old;
+               print "BUILDING $git_dir\n";
+               print "  BRANCH: $ref\n";
+               print "  COMMITS: ", join(' ', @revs), "\n";
+       }
+
+       local(*R, *W);
+       pipe R, W or die "cannot pipe builder: $!";
+
+       my $builder = fork();
+       if (!defined $builder) {
+               die "cannot fork builder: $!";
+       } elsif (0 == $builder) {
+               close R;
+               close STDIN;open(STDIN, '/dev/null');
+               open(STDOUT, '>&W');
+               open(STDERR, '>&W');
+               exit do_build $git_dir, $new;
+       } else {
+               close W;
+               my $out = '';
+               $out .= $_ while <R>;
+               close R;
+               waitpid $builder, 0;
+               build_failed $git_dir, $ref, $old, $new, $out if $?;
+       }
+
+       print "DONE\n\n" if $debug_flag;
+}
+
+sub daemon_loop ()
+{
+       my $run = 1;
+       my $stop_sub = sub {$run = 0};
+       $SIG{HUP} = $stop_sub;
+       $SIG{INT} = $stop_sub;
+       $SIG{TERM} = $stop_sub;
+
+       mkdir $tmpdir, 0755;
+       my $pidfile = File::Spec->catfile($tmpdir, "cidaemon.pid");
+       open(O, ">$pidfile"); print O "$$\n"; close O;
+
+       while ($run) {
+               my $ent = pop_queue;
+               if ($ent) {
+                       my ($git_dir, $ref, $old, $new) = @$ent;
+
+                       $ent = $recent{$git_dir};
+                       $recent{$git_dir} = $ent = [[], {}] unless $ent;
+                       my ($rec_arr, $rec_hash) = @$ent;
+                       next if $rec_hash->{$new}++;
+                       while (@$rec_arr >= $recent_size) {
+                               my $to_kill = shift @$rec_arr;
+                               delete $rec_hash->{$to_kill};
+                       }
+                       push @$rec_arr, $new;
+
+                       run_build $git_dir, $ref, $old, $new;
+               } else {
+                       sleep $scan_delay;
+               }
+       }
+
+       unlink $pidfile;
+}
+
+$debug_flag = 0;
+GetOptions(
+       'debug|d' => \$debug_flag,
+       'smtp-user=s' => \$ex_user,
+) or die "usage: $0 [--debug] [--smtp-user=user]\n";
+
+$ex_pass = input_noecho("$ex_user SMTP password: ")
+       if ($ex_user && !$ex_pass);
+
+if ($debug_flag) {
+       daemon_loop;
+       exit 0;
+}
+
+my $daemon = fork();
+if (!defined $daemon) {
+       die "cannot fork daemon: $!";
+} elsif (0 == $daemon) {
+       close STDIN;open(STDIN, '/dev/null');
+       close STDOUT;open(STDOUT, '>/dev/null');
+       close STDERR;open(STDERR, '>/dev/null');
+       daemon_loop;
+       exit 0;
+} else {
+       print "Daemon $daemon running in the background.\n";
+}
diff --git a/contrib/continuous/post-receive-cinotify b/contrib/continuous/post-receive-cinotify
new file mode 100644 (file)
index 0000000..b8f5a60
--- /dev/null
@@ -0,0 +1,104 @@
+#!/usr/bin/perl
+#
+# A hook that notifies its companion cidaemon through a simple
+# queue file that a ref has been updated via a push (actually
+# by a receive-pack running on the server).
+#
+# See cidaemon for per-repository configuration details.
+#
+# To use this hook, add it as the post-receive hook, make it
+# executable, and set its configuration options.
+#
+
+local $ENV{PATH} = '/opt/git/bin';
+
+use strict;
+use warnings;
+use File::Spec;
+use Storable qw(retrieve nstore);
+use Fcntl ':flock';
+
+my $git_dir = File::Spec->rel2abs($ENV{GIT_DIR});
+my $queue_name = `git config --get builder.queue`;chop $queue_name;
+$queue_name =~ m,^([^\s]+)$,; $queue_name = $1; # untaint
+unless ($queue_name) {
+       1 while <STDIN>;
+       print STDERR "\nerror: builder.queue not set.  Not enqueing.\n\n";
+       exit;
+}
+my $queue_lock = "$queue_name.lock";
+
+my @skip;
+open S, "git config --get-all builder.skip|";
+while (<S>) {
+       chop;
+       push @skip, $_;
+}
+close S;
+
+my @new_branch_base;
+open S, "git config --get-all builder.newBranchBase|";
+while (<S>) {
+       chop;
+       push @new_branch_base, $_;
+}
+close S;
+
+sub skip ($)
+{
+       local $_ = shift;
+       foreach my $p (@skip) {
+               return 1 if /^$p/;
+       }
+       0;
+}
+
+open LOCK, ">$queue_lock" or die "Can't open $queue_lock: $!";
+flock LOCK, LOCK_EX;
+
+my $queue = -f $queue_name ? retrieve $queue_name : [];
+my %existing;
+foreach my $r (@$queue) {
+       my ($gd, $ref) = @$r;
+       $existing{$gd}{$ref} = $r;
+}
+
+my @new_branch_commits;
+my $loaded_new_branch_commits = 0;
+
+while (<STDIN>) {
+       chop;
+       my ($old, $new, $ref) = split / /, $_, 3;
+
+       next if $old eq $new;
+       next if $new =~ /^0{40}$/;
+       next if skip $ref;
+
+       my $r = $existing{$git_dir}{$ref};
+       if ($r) {
+               $r->[3] = $new;
+       } else {
+               if ($old =~ /^0{40}$/) {
+                       if (!$loaded_new_branch_commits && @new_branch_base) {
+                               open M,'-|','git','show-ref',@new_branch_base;
+                               while (<M>) {
+                                       ($_) = split / /, $_;
+                                       push @new_branch_commits, $_;
+                               }
+                               close M;
+                               $loaded_new_branch_commits = 1;
+                       }
+                       $old = [@new_branch_commits];
+               } else {
+                       $old = [$old];
+               }
+
+               $r = [$git_dir, $ref, $old, $new];
+               $existing{$git_dir}{$ref} = $r;
+               push @$queue, $r;
+       }
+}
+nstore $queue, $queue_name;
+
+flock LOCK, LOCK_UN;
+close LOCK;
index 8554e3967cc692c6916e5aee35952074d07e8bf0..98aa0aae9b2e9e4a758fa58e7dd1e1adc3214883 100644 (file)
@@ -11,8 +11,8 @@ emacsdir = $(prefix)/share/emacs/site-lisp
 all: $(ELC)
 
 install: all
-       $(INSTALL) -d $(emacsdir)
-       $(INSTALL_ELC) $(ELC) $(emacsdir)
+       $(INSTALL) -d $(DESTDIR)$(emacsdir)
+       $(INSTALL_ELC) $(ELC) $(DESTDIR)$(emacsdir)
 
 %.elc: %.el
        $(EMACS) -batch -f batch-byte-compile $<
index 64ad50b3274d00199f5b3fc724eb5746b8eef480..bb671d561ebc9af51bb9a5d52017e71fd81881e9 100644 (file)
@@ -8,8 +8,8 @@
 ;; License:    GPL
 ;; Keywords:   git, version control, release management
 ;;
-;; Compatibility: Emacs21
-
+;; Compatibility: Emacs21, Emacs22 and EmacsCVS
+;;                Git 1.5 and up
 
 ;; This file is *NOT* part of GNU Emacs.
 ;; This file is distributed under the same terms as GNU Emacs.
@@ -61,8 +61,9 @@
 
 ;;; Compatibility:
 ;;
-;; It requires GNU Emacs 21.  If you'are using Emacs 20, try
-;; changing this:
+;; It requires GNU Emacs 21 or later and Git 1.5.0 and up
+;;
+;; If you'are using Emacs 20, try changing this:
 ;;
 ;;            (overlay-put ovl 'face (list :background
 ;;                                         (cdr (assq 'color (cddddr info)))))
 ;;
 ;;; Code:
 
-(require 'cl)                        ; to use `push', `pop'
-
-(defun color-scale (l)
-  (let* ((colors ())
-         r g b)
-    (setq r l)
-    (while r
-      (setq g l)
-      (while g
-        (setq b l)
-        (while b
-          (push (concat "#" (car r) (car g) (car b)) colors)
-          (pop b))
-        (pop g))
-      (pop r))
-    colors))
+(eval-when-compile (require 'cl))                            ; to use `push', `pop'
+
+
+(defun git-blame-color-scale (&rest elements)
+  "Given a list, returns a list of triples formed with each
+elements of the list.
+
+a b => bbb bba bab baa abb aba aaa aab"
+  (let (result)
+    (dolist (a elements)
+      (dolist (b elements)
+        (dolist (c elements)
+          (setq result (cons (format "#%s%s%s" a b c) result)))))
+    result))
+
+;; (git-blame-color-scale "0c" "04" "24" "1c" "2c" "34" "14" "3c") =>
+;; ("#3c3c3c" "#3c3c14" "#3c3c34" "#3c3c2c" "#3c3c1c" "#3c3c24"
+;; "#3c3c04" "#3c3c0c" "#3c143c" "#3c1414" "#3c1434" "#3c142c" ...)
+
+(defmacro git-blame-random-pop (l)
+  "Select a random element from L and returns it. Also remove
+selected element from l."
+  ;; only works on lists with unique elements
+  `(let ((e (elt ,l (random (length ,l)))))
+     (setq ,l (remove e ,l))
+     e))
 
 (defvar git-blame-dark-colors
-  (color-scale '("0c" "04" "24" "1c" "2c" "34" "14" "3c")))
+  (git-blame-color-scale "0c" "04" "24" "1c" "2c" "34" "14" "3c")
+  "*List of colors (format #RGB) to use in a dark environment.
+
+To check out the list, evaluate (list-colors-display git-blame-dark-colors).")
 
 (defvar git-blame-light-colors
-  (color-scale '("c4" "d4" "cc" "dc" "f4" "e4" "fc" "ec")))
+  (git-blame-color-scale "c4" "d4" "cc" "dc" "f4" "e4" "fc" "ec")
+  "*List of colors (format #RGB) to use in a light environment.
+
+To check out the list, evaluate (list-colors-display git-blame-light-colors).")
 
-(defvar git-blame-ancient-color "dark green")
+(defvar git-blame-colors '()
+  "Colors used by git-blame. The list is built once when activating git-blame
+minor mode.")
+
+(defvar git-blame-ancient-color "dark green"
+  "*Color to be used for ancient commit.")
 
 (defvar git-blame-autoupdate t
   "*Automatically update the blame display while editing")
   "A queue of update requests")
 (make-variable-buffer-local 'git-blame-update-queue)
 
+;; FIXME: docstrings
+(defvar git-blame-file nil)
+(defvar git-blame-current nil)
+
 (defvar git-blame-mode nil)
 (make-variable-buffer-local 'git-blame-mode)
-(unless (assq 'git-blame-mode minor-mode-alist)
-  (setq minor-mode-alist
-       (cons (list 'git-blame-mode " blame")
-             minor-mode-alist)))
+
+(defvar git-blame-mode-line-string " blame"
+  "String to display on the mode line when git-blame is active.")
+
+(or (assq 'git-blame-mode minor-mode-alist)
+    (setq minor-mode-alist
+         (cons '(git-blame-mode git-blame-mode-line-string) minor-mode-alist)))
 
 ;;;###autoload
 (defun git-blame-mode (&optional arg)
-  "Minor mode for displaying Git blame"
+  "Toggle minor mode for displaying Git blame
+
+With prefix ARG, turn the mode on if ARG is positive."
   (interactive "P")
-  (if arg
-      (setq git-blame-mode (eq arg 1))
-    (setq git-blame-mode (not git-blame-mode)))
+  (cond
+   ((null arg)
+    (if git-blame-mode (git-blame-mode-off) (git-blame-mode-on)))
+   ((> (prefix-numeric-value arg) 0) (git-blame-mode-on))
+   (t (git-blame-mode-off))))
+
+(defun git-blame-mode-on ()
+  "Turn on git-blame mode.
+
+See also function `git-blame-mode'."
   (make-local-variable 'git-blame-colors)
   (if git-blame-autoupdate
       (add-hook 'after-change-functions 'git-blame-after-change nil t)
     (remove-hook 'after-change-functions 'git-blame-after-change t))
   (git-blame-cleanup)
-  (if git-blame-mode
-      (progn
-        (let ((bgmode (cdr (assoc 'background-mode (frame-parameters)))))
-          (if (eq bgmode 'dark)
-              (setq git-blame-colors git-blame-dark-colors)
-            (setq git-blame-colors git-blame-light-colors)))
-        (setq git-blame-cache (make-hash-table :test 'equal))
-        (git-blame-run))
-    (cancel-timer git-blame-idle-timer)))
+  (let ((bgmode (cdr (assoc 'background-mode (frame-parameters)))))
+    (if (eq bgmode 'dark)
+       (setq git-blame-colors git-blame-dark-colors)
+      (setq git-blame-colors git-blame-light-colors)))
+  (setq git-blame-cache (make-hash-table :test 'equal))
+  (setq git-blame-mode t)
+  (git-blame-run))
+
+(defun git-blame-mode-off ()
+  "Turn off git-blame mode.
+
+See also function `git-blame-mode'."
+  (git-blame-cleanup)
+  (if git-blame-idle-timer (cancel-timer git-blame-idle-timer))
+  (setq git-blame-mode nil))
 
 ;;;###autoload
 (defun git-reblame ()
   "Recalculate all blame information in the current buffer"
-  (unless git-blame-mode
-    (error "git-blame is not active"))
   (interactive)
+  (unless git-blame-mode
+    (error "Git-blame is not active"))
+
   (git-blame-cleanup)
   (git-blame-run))
 
         (t
          nil)))
 
-
 (defun git-blame-new-commit (hash src-line res-line num-lines)
   (save-excursion
     (set-buffer git-blame-file)
           (inhibit-point-motion-hooks t)
           (inhibit-modification-hooks t))
       (when (not info)
-        (let ((color (pop git-blame-colors)))
-          (unless color
-            (setq color git-blame-ancient-color))
+       ;; Assign a random color to each new commit info
+       ;; Take care not to select the same color multiple times
+       (let ((color (if git-blame-colors
+                        (git-blame-random-pop git-blame-colors)
+                      git-blame-ancient-color)))
           (setq info (list hash src-line res-line num-lines
                            (git-describe-commit hash)
                            (cons 'color color))))
index 13d198229bbdf4c56f15bfbe0528c6714106e9e3..2f9995ea3979350c7cd3883dfc6364e90b8d9bb2 100644 (file)
@@ -1,6 +1,6 @@
 ;;; git.el --- A user interface for git
 
-;; Copyright (C) 2005, 2006 Alexandre Julliard <julliard@winehq.org>
+;; Copyright (C) 2005, 2006, 2007 Alexandre Julliard <julliard@winehq.org>
 
 ;; Version: 1.0
 
@@ -213,6 +213,23 @@ and returns the process output as a string."
     (error "Failed to run \"git %s\":\n%s" (mapconcat (lambda (x) x) args " ") (buffer-string)))
   (message "Running git %s...done" (car args)))
 
+(defun git-run-hook (hook env &rest args)
+  "Run a git hook and display its output if any."
+  (let ((dir default-directory)
+        (hook-name (expand-file-name (concat ".git/hooks/" hook))))
+    (or (not (file-executable-p hook-name))
+        (let (status (buffer (get-buffer-create "*Git Hook Output*")))
+          (with-current-buffer buffer
+            (erase-buffer)
+            (cd dir)
+            (setq status
+                  (if env
+                      (apply #'call-process "env" nil (list buffer t) nil
+                             (append (git-get-env-strings env) (list hook-name) args))
+                    (apply #'call-process hook-name nil (list buffer t) nil args))))
+          (display-message-or-buffer buffer)
+          (eq 0 status)))))
+
 (defun git-get-string-sha1 (string)
   "Read a SHA1 from the specified string."
   (and string
@@ -246,6 +263,16 @@ and returns the process output as a string."
              (locale-charset-to-coding-system repo-config))
       'utf-8)))
 
+(defun git-get-logoutput-coding-system ()
+  "Return the coding system used for git-log output."
+  (let ((repo-config (or (git-config "i18n.logoutputencoding")
+                         (git-config "i18n.commitencoding"))))
+    (or git-commits-coding-system
+        (and repo-config
+             (fboundp 'locale-charset-to-coding-system)
+             (locale-charset-to-coding-system repo-config))
+      'utf-8)))
+
 (defun git-escape-file-name (name)
   "Escape a file name if necessary."
   (if (string-match "[\n\t\"\\]" name)
@@ -389,6 +416,14 @@ and returns the process output as a string."
           (push (match-string 0) heads))))
     (nreverse heads)))
 
+(defun git-get-commit-description (commit)
+  "Get a one-line description of COMMIT."
+  (let ((coding-system-for-read (git-get-logoutput-coding-system)))
+    (let ((descr (git-call-process-env-string nil "log" "--max-count=1" "--pretty=oneline" commit)))
+      (if (and descr (string-match "\\`\\([0-9a-f]\\{40\\}\\) *\\(.*\\)$" descr))
+          (concat (substring (match-string 1 descr) 0 10) " - " (match-string 2 descr))
+        descr))))
+
 ;;;; File info structure
 ;;;; ------------------------------------------------------------
 
@@ -556,7 +591,7 @@ and returns the process output as a string."
   "Refresh the ewoc header and footer."
   (let ((branch (git-symbolic-ref "HEAD"))
         (head (if (git-empty-db-p) "Nothing committed yet"
-                (substring (git-rev-parse "HEAD") 0 10)))
+                (git-get-commit-description "HEAD")))
         (merge-heads (git-get-merge-heads)))
     (ewoc-set-hf status
                  (format "Directory:  %s\nBranch:     %s\nHead:       %s%s\n"
@@ -567,7 +602,7 @@ and returns the process output as a string."
                          head
                          (if merge-heads
                              (concat "\nMerging:    "
-                                     (mapconcat (lambda (str) (substring str 0 10)) merge-heads " "))
+                                     (mapconcat (lambda (str) (git-get-commit-description str)) merge-heads "\n            "))
                            ""))
                  (if (ewoc-nth status 0) "" "    No changes."))))
 
@@ -590,6 +625,20 @@ and returns the process output as a string."
     (when modified
       (apply #'git-run-command nil env "update-index" "--" (git-get-filenames modified)))))
 
+(defun git-run-pre-commit-hook ()
+  "Run the pre-commit hook if any."
+  (unless git-status (error "Not in git-status buffer."))
+  (let ((files (git-marked-files-state 'added 'deleted 'modified)))
+    (or (not files)
+        (not (file-executable-p ".git/hooks/pre-commit"))
+        (let ((index-file (make-temp-file "gitidx")))
+          (unwind-protect
+            (let ((head-tree (unless (git-empty-db-p) (git-rev-parse "HEAD^{tree}"))))
+              (git-read-tree head-tree index-file)
+              (git-update-index index-file files)
+              (git-run-hook "pre-commit" `(("GIT_INDEX_FILE" . ,index-file))))
+          (delete-file index-file))))))
+
 (defun git-do-commit ()
   "Perform the actual commit using the current buffer as log message."
   (interactive)
@@ -622,7 +671,8 @@ and returns the process output as a string."
                               (git-run-command nil nil "rerere"))
                             (git-refresh-files)
                             (git-refresh-ewoc-hf git-status)
-                            (message "Committed %s." commit))
+                            (message "Committed %s." commit)
+                            (git-run-hook "post-commit" nil))
                         (message "Commit aborted."))))
                 (message "No files to commit.")))
           (delete-file index-file))))))
@@ -891,40 +941,82 @@ and returns the process output as a string."
   (with-current-buffer log-edit-parent-buffer
     (git-get-filenames (git-marked-files-state 'added 'deleted 'modified))))
 
-(defun git-commit-file ()
-  "Commit the marked file(s), asking for a commit message."
-  (interactive)
+(defun git-append-sign-off (name email)
+  "Append a Signed-off-by entry to the current buffer, avoiding duplicates."
+  (let ((sign-off (format "Signed-off-by: %s <%s>" name email))
+        (case-fold-search t))
+    (goto-char (point-min))
+    (unless (re-search-forward (concat "^" (regexp-quote sign-off)) nil t)
+      (goto-char (point-min))
+      (unless (re-search-forward "^Signed-off-by: " nil t)
+        (setq sign-off (concat "\n" sign-off)))
+      (goto-char (point-max))
+      (insert sign-off "\n"))))
+
+(defun git-setup-log-buffer (buffer &optional author-name author-email subject date msg)
+  "Setup the log buffer for a commit."
   (unless git-status (error "Not in git-status buffer."))
-  (let ((buffer (get-buffer-create "*git-commit*"))
-        (merge-heads (git-get-merge-heads))
+  (let ((merge-heads (git-get-merge-heads))
         (dir default-directory)
-        (coding-system (git-get-commits-coding-system))
+        (committer-name (git-get-committer-name))
+        (committer-email (git-get-committer-email))
         (sign-off git-append-signed-off-by))
     (with-current-buffer buffer
-      (when (eq 0 (buffer-size))
-        (cd dir)
-        (erase-buffer)
-        (insert
-         (propertize
-          (format "Author: %s <%s>\n%s"
-                  (git-get-committer-name) (git-get-committer-email)
-                  (if merge-heads
-                      (format "Parent: %s\n%s\n"
-                              (git-rev-parse "HEAD")
-                              (mapconcat (lambda (str) (concat "Parent: " str)) merge-heads "\n"))
-                    ""))
-          'face 'git-header-face)
-         (propertize git-log-msg-separator 'face 'git-separator-face)
-         "\n")
-        (cond ((file-readable-p ".git/MERGE_MSG")
-               (insert-file-contents ".git/MERGE_MSG"))
-              (sign-off
-               (insert (format "\n\nSigned-off-by: %s <%s>\n"
-                               (git-get-committer-name) (git-get-committer-email)))))))
-    (log-edit #'git-do-commit nil #'git-log-edit-files buffer)
-    (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))
-    (setq buffer-file-coding-system coding-system)
-    (re-search-forward (regexp-quote (concat git-log-msg-separator "\n")) nil t)))
+      (cd dir)
+      (erase-buffer)
+      (insert
+       (propertize
+        (format "Author: %s <%s>\n%s%s"
+                (or author-name committer-name)
+                (or author-email committer-email)
+                (if date (format "Date: %s\n" date) "")
+                (if merge-heads
+                    (format "Parent: %s\n%s\n"
+                            (git-rev-parse "HEAD")
+                            (mapconcat (lambda (str) (concat "Parent: " str)) merge-heads "\n"))
+                  ""))
+        'face 'git-header-face)
+       (propertize git-log-msg-separator 'face 'git-separator-face)
+       "\n")
+      (when subject (insert subject "\n\n"))
+      (cond (msg (insert msg "\n"))
+            ((file-readable-p ".dotest/msg")
+             (insert-file-contents ".dotest/msg"))
+            ((file-readable-p ".git/MERGE_MSG")
+             (insert-file-contents ".git/MERGE_MSG")))
+      ; delete empty lines at end
+      (goto-char (point-min))
+      (when (re-search-forward "\n+\\'" nil t)
+        (replace-match "\n" t t))
+      (when sign-off (git-append-sign-off committer-name committer-email)))))
+
+(defun git-commit-file ()
+  "Commit the marked file(s), asking for a commit message."
+  (interactive)
+  (unless git-status (error "Not in git-status buffer."))
+  (when (git-run-pre-commit-hook)
+    (let ((buffer (get-buffer-create "*git-commit*"))
+          (coding-system (git-get-commits-coding-system))
+          author-name author-email subject date)
+      (when (eq 0 (buffer-size buffer))
+        (when (file-readable-p ".dotest/info")
+          (with-temp-buffer
+            (insert-file-contents ".dotest/info")
+            (goto-char (point-min))
+            (when (re-search-forward "^Author: \\(.*\\)\nEmail: \\(.*\\)$" nil t)
+              (setq author-name (match-string 1))
+              (setq author-email (match-string 2)))
+            (goto-char (point-min))
+            (when (re-search-forward "^Subject: \\(.*\\)$" nil t)
+              (setq subject (match-string 1)))
+            (goto-char (point-min))
+            (when (re-search-forward "^Date: \\(.*\\)$" nil t)
+              (setq date (match-string 1)))))
+        (git-setup-log-buffer buffer author-name author-email subject date))
+      (log-edit #'git-do-commit nil #'git-log-edit-files buffer)
+      (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))
+      (setq buffer-file-coding-system coding-system)
+      (re-search-forward (regexp-quote (concat git-log-msg-separator "\n")) nil t))))
 
 (defun git-find-file ()
   "Visit the current file in its own buffer."
diff --git a/contrib/examples/git-gc.sh b/contrib/examples/git-gc.sh
new file mode 100755 (executable)
index 0000000..436d7ca
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Copyright (c) 2006, Shawn O. Pearce
+#
+# Cleanup unreachable files and optimize the repository.
+
+USAGE='[--prune]'
+SUBDIRECTORY_OK=Yes
+. git-sh-setup
+
+no_prune=:
+while case $# in 0) break ;; esac
+do
+       case "$1" in
+       --prune)
+               no_prune=
+               ;;
+       --)
+               usage
+               ;;
+       esac
+       shift
+done
+
+case "$(git config --get gc.packrefs)" in
+notbare|"")
+       test $(is_bare_repository) = true || pack_refs=true;;
+*)
+       pack_refs=$(git config --bool --get gc.packrefs)
+esac
+
+test "true" != "$pack_refs" ||
+git-pack-refs --prune &&
+git-reflog expire --all &&
+git-repack -a -d -l &&
+$no_prune git-prune &&
+git-rerere gc || exit
diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
new file mode 100644 (file)
index 0000000..6516015
--- /dev/null
@@ -0,0 +1,588 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Andy Parkins
+#
+# An example hook script to mail out commit update information.  This hook sends emails
+# listing new revisions to the repository introduced by the change being reported.  The
+# rule is that (for branch updates) each commit will appear on one email and one email
+# only.
+#
+# This hook is stored in the contrib/hooks directory.  Your distribution will have put
+# this somewhere standard.  You should make this script executable then link to it in
+# the repository you would like to use it in.  For example, on debian the hook is stored
+# in /usr/share/doc/git-core/contrib/hooks/post-receive-email:
+#
+#  chmod a+x post-receive-email
+#  cd /path/to/your/repository.git
+#  ln -sf /usr/share/doc/git-core/contrib/hooks/post-receive-email hooks/post-receive
+#
+# This hook script assumes it is enabled on the central repository of a project, with
+# all users pushing only to it and not between each other.  It will still work if you
+# don't operate in that style, but it would become possible for the email to be from
+# someone other than the person doing the push.
+#
+# Config
+# ------
+# hooks.mailinglist
+#   This is the list that all pushes will go to; leave it blank to not send
+#   emails for every ref update.
+# hooks.announcelist
+#   This is the list that all pushes of annotated tags will go to.  Leave it
+#   blank to default to the mailinglist field.  The announce emails lists the
+#   short log summary of the changes since the last annotated tag.
+# hook.envelopesender
+#   If set then the -f option is passed to sendmail to allow the envelope sender
+#   address to be set
+#
+# Notes
+# -----
+# All emails have their subjects prefixed with "[SCM]" to aid filtering.
+# All emails include the headers "X-Git-Refname", "X-Git-Oldrev",
+# "X-Git-Newrev", and "X-Git-Reftype" to enable fine tuned filtering and
+# give information for debugging.
+#
+
+# ---------------------------- Functions
+
+#
+# Top level email generation function.  This decides what type of update
+# this is and calls the appropriate body-generation routine after outputting
+# the common header
+#
+# Note this function doesn't actually generate any email output, that is taken
+# care of by the functions it calls:
+#  - generate_email_header
+#  - generate_create_XXXX_email
+#  - generate_update_XXXX_email
+#  - generate_delete_XXXX_email
+#  - generate_email_footer
+#
+generate_email()
+{
+       # --- Arguments
+       oldrev=$(git rev-parse $1)
+       newrev=$(git rev-parse $2)
+       refname="$3"
+
+       # --- Interpret
+       # 0000->1234 (create)
+       # 1234->2345 (update)
+       # 2345->0000 (delete)
+       if expr "$oldrev" : '0*$' >/dev/null
+       then
+               change_type="create"
+       else
+               if expr "$newrev" : '0*$' >/dev/null
+               then
+                       change_type="delete"
+               else
+                       change_type="update"
+               fi
+       fi
+
+       # --- Get the revision types
+       newrev_type=$(git cat-file -t $newrev 2> /dev/null)
+       oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null)
+       case "$change_type" in
+       create|update)
+               rev="$newrev"
+               rev_type="$newrev_type"
+               ;;
+       delete)
+               rev="$oldrev"
+               rev_type="$oldrev_type"
+               ;;
+       esac
+
+       # The revision type tells us what type the commit is, combined with
+       # the location of the ref we can decide between
+       #  - working branch
+       #  - tracking branch
+       #  - unannoted tag
+       #  - annotated tag
+       case "$refname","$rev_type" in
+               refs/tags/*,commit)
+                       # un-annotated tag
+                       refname_type="tag"
+                       short_refname=${refname##refs/tags/}
+                       ;;
+               refs/tags/*,tag)
+                       # annotated tag
+                       refname_type="annotated tag"
+                       short_refname=${refname##refs/tags/}
+                       # change recipients
+                       if [ -n "$announcerecipients" ]; then
+                               recipients="$announcerecipients"
+                       fi
+                       ;;
+               refs/heads/*,commit)
+                       # branch
+                       refname_type="branch"
+                       short_refname=${refname##refs/heads/}
+                       ;;
+               refs/remotes/*,commit)
+                       # tracking branch
+                       refname_type="tracking branch"
+                       short_refname=${refname##refs/remotes/}
+                       echo >&2 "*** Push-update of tracking branch, $refname"
+                       echo >&2 "***  - no email generated."
+                       exit 0
+                       ;;
+               *)
+                       # Anything else (is there anything else?)
+                       echo >&2 "*** Unknown type of update to $refname ($rev_type)"
+                       echo >&2 "***  - no email generated"
+                       exit 1
+                       ;;
+       esac
+
+       # Check if we've got anyone to send to
+       if [ -z "$recipients" ]; then
+               echo >&2 "*** hooks.recipients is not set so no email will be sent"
+               echo >&2 "*** for $refname update $oldrev->$newrev"
+               exit 0
+       fi
+
+       # Email parameters
+       # The committer will be obtained from the latest existing rev; so
+       # for a deletion it will be the oldrev, for the others, then newrev
+       committer=$(git show --pretty=full -s $rev | sed -ne "s/^Commit: //p" |
+               sed -ne 's/\(.*\) </"\1" </p')
+       # The email subject will contain the best description of the ref
+       # that we can build from the parameters
+       describe=$(git describe $rev 2>/dev/null)
+       if [ -z "$describe" ]; then
+               describe=$rev
+       fi
+
+       generate_email_header
+
+       # Call the correct body generation function
+       fn_name=general
+       case "$refname_type" in
+       "tracking branch"|branch)
+               fn_name=branch
+               ;;
+       "annotated tag")
+               fn_name=atag
+               ;;
+       esac
+       generate_${change_type}_${fn_name}_email
+
+       generate_email_footer
+}
+
+generate_email_header()
+{
+       # --- Email (all stdout will be the email)
+       # Generate header
+       cat <<-EOF
+       From: $committer
+       To: $recipients
+       Subject: ${EMAILPREFIX}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe
+       X-Git-Refname: $refname
+       X-Git-Reftype: $refname_type
+       X-Git-Oldrev: $oldrev
+       X-Git-Newrev: $newrev
+
+       This is an automated email from the git hooks/post-receive script. It was
+       generated because a ref change was pushed to the repository containing
+       the project "$projectdesc".
+
+       The $refname_type, $short_refname has been ${change_type}d
+       EOF
+}
+
+generate_email_footer()
+{
+       cat <<-EOF
+
+
+       hooks/post-receive
+       -- 
+       $projectdesc
+       EOF
+}
+
+# --------------- Branches
+
+#
+# Called for the creation of a branch
+#
+generate_create_branch_email()
+{
+       # This is a new branch and so oldrev is not valid
+       echo "        at  $newrev ($newrev_type)"
+       echo ""
+
+       echo $LOGBEGIN
+       # This shows all log entries that are not already covered by
+       # another ref - i.e. commits that are now accessible from this
+       # ref that were previously not accessible (see generate_update_branch_email
+       # for the explanation of this command)
+       git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
+       git rev-list --pretty --stdin $newrev
+       echo $LOGEND
+}
+
+#
+# Called for the change of a pre-existing branch
+#
+generate_update_branch_email()
+{
+       # Consider this:
+       #   1 --- 2 --- O --- X --- 3 --- 4 --- N
+       #
+       # O is $oldrev for $refname
+       # N is $newrev for $refname
+       # X is a revision pointed to by some other ref, for which we may
+       #   assume that an email has already been generated.
+       # In this case we want to issue an email containing only revisions
+       # 3, 4, and N.  Given (almost) by
+       #
+       #  git-rev-list N ^O --not --all
+       #
+       # The reason for the "almost", is that the "--not --all" will take
+       # precedence over the "N", and effectively will translate to
+       #
+       #  git-rev-list N ^O ^X ^N
+       #
+       # So, we need to build up the list more carefully.  git-rev-parse will
+       # generate a list of revs that may be fed into git-rev-list.  We can get
+       # it to make the "--not --all" part and then filter out the "^N" with:
+       #
+       #  git-rev-parse --not --all | grep -v N
+       #
+       # Then, using the --stdin switch to git-rev-list we have effectively
+       # manufactured
+       #
+       #  git-rev-list N ^O ^X
+       #
+       # This leaves a problem when someone else updates the repository
+       # while this script is running.  Their new value of the ref we're working
+       # on would be included in the "--not --all" output; and as our $newrev
+       # would be an ancestor of that commit, it would exclude all of our
+       # commits.  What we really want is to exclude the current value of
+       # $refname from the --not list, rather than N itself.  So:
+       #
+       #  git-rev-parse --not --all | grep -v $(git-rev-parse $refname)
+       #
+       # Get's us to something pretty safe (apart from the small time between
+       # refname being read, and git-rev-parse running - for that, I give up)
+       #
+       #
+       # Next problem, consider this:
+       #   * --- B --- * --- O ($oldrev)
+       #          \
+       #           * --- X --- * --- N ($newrev)
+       #
+       # That is to say, there is no guarantee that oldrev is a strict subset of
+       # newrev (it would have required a --force, but that's allowed).  So, we
+       # can't simply say rev-list $oldrev..$newrev.  Instead we find the common
+       # base of the two revs and list from there.
+       #
+       # As above, we need to take into account the presence of X; if another
+       # branch is already in the repository and points at some of the revisions
+       # that we are about to output - we don't want them.  The solution is as
+       # before: git-rev-parse output filtered.
+       #
+       # Finally, tags:
+       #   1 --- 2 --- O --- T --- 3 --- 4 --- N
+       #
+       # Tags pushed into the repository generate nice shortlog emails that
+       # summarise the commits between them and the previous tag.  However,
+       # those emails don't include the full commit messages that we output
+       # for a branch update.  Therefore we still want to output revisions
+       # that have been output on a tag email.
+       #
+       # Luckily, git-rev-parse includes just the tool.  Instead of using "--all"
+       # we use "--branches"; this has the added benefit that "remotes/" will
+       # be ignored as well.
+
+       # List all of the revisions that were removed by this update, in a fast forward
+       # update, this list will be empty, because rev-list O ^N is empty.  For a non
+       # fast forward, O ^N is the list of removed revisions
+       fastforward=""
+       rev=""
+       for rev in $(git rev-list $newrev..$oldrev)
+       do
+               revtype=$(git cat-file -t "$rev")
+               echo "  discards  $rev ($revtype)"
+       done
+       if [ -z "$rev" ]; then
+               fast_forward=1
+       fi
+
+       # List all the revisions from baserev to newrev in a kind of
+       # "table-of-contents"; note this list can include revisions that have
+       # already had notification emails and is present to show the full detail
+       # of the change from rolling back the old revision to the base revision and
+       # then forward to the new revision
+       for rev in $(git rev-list $oldrev..$newrev)
+       do
+               revtype=$(git cat-file -t "$rev")
+               echo "       via  $rev ($revtype)"
+       done
+
+       if [ -z "$fastforward" ]; then
+               echo "      from  $oldrev ($oldrev_type)"
+       else
+               echo ""
+               echo "This update added new revisions after undoing old revisions.  That is to"
+               echo "say, the old revision is not a strict subset of the new revision.  This"
+               echo "situation occurs when you --force push a change and generate a"
+               echo "repository containing something like this:"
+               echo ""
+               echo " * -- * -- B -- O -- O -- O ($oldrev)"
+               echo "            \\"
+               echo "             N -- N -- N ($newrev)"
+               echo ""
+               echo "When this happens we assume that you've already had alert emails for all"
+               echo "of the O revisions, and so we here report only the revisions in the N"
+               echo "branch from the common base, B."
+       fi
+
+       echo ""
+       echo "Those revisions listed above that are new to this repository have"
+       echo "not appeared on any other notification email; so we list those"
+       echo "revisions in full, below."
+
+       echo ""
+       echo $LOGBEGIN
+       git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
+       git rev-list --pretty --stdin $oldrev..$newrev
+
+       # XXX: Need a way of detecting whether git rev-list actually outputted
+       # anything, so that we can issue a "no new revisions added by this
+       # update" message
+
+       echo $LOGEND
+
+       # The diffstat is shown from the old revision to the new revision.  This
+       # is to show the truth of what happened in this change.  There's no point
+       # showing the stat from the base to the new revision because the base
+       # is effectively a random revision at this point - the user will be
+       # interested in what this revision changed - including the undoing of
+       # previous revisions in the case of non-fast forward updates.
+       echo ""
+       echo "Summary of changes:"
+       git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev
+}
+
+#
+# Called for the deletion of a branch
+#
+generate_delete_branch_email()
+{
+       echo "       was  $oldrev"
+       echo ""
+       echo $LOGEND
+       git show -s --pretty=oneline $oldrev
+       echo $LOGEND
+}
+
+# --------------- Annotated tags
+
+#
+# Called for the creation of an annotated tag
+#
+generate_create_atag_email()
+{
+       echo "        at  $newrev ($newrev_type)"
+
+       generate_atag_email
+}
+
+#
+# Called for the update of an annotated tag (this is probably a rare event
+# and may not even be allowed)
+#
+generate_update_atag_email()
+{
+       echo "        to  $newrev ($newrev_type)"
+       echo "      from  $oldrev (which is now obsolete)"
+
+       generate_atag_email
+}
+
+#
+# Called when an annotated tag is created or changed
+#
+generate_atag_email()
+{
+       # Use git-for-each-ref to pull out the individual fields from the tag
+       eval $(git for-each-ref --shell --format='
+       tagobject=%(*objectname)
+       tagtype=%(*objecttype)
+       tagger=%(taggername)
+       tagged=%(taggerdate)' $refname
+       )
+
+       echo "   tagging  $tagobject ($tagtype)"
+       case "$tagtype" in
+       commit)
+               # If the tagged object is a commit, then we assume this is a
+               # release, and so we calculate which tag this tag is replacing
+               prevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null)
+
+               if [ -n "$prevtag" ]; then
+                       echo "  replaces  $prevtag"
+               fi
+               ;;
+       *)
+               echo "    length  $(git cat-file -s $tagobject) bytes"
+               ;;
+       esac
+       echo " tagged by  $tagger"
+       echo "        on  $tagged"
+
+       echo ""
+       echo $LOGBEGIN
+
+       # Show the content of the tag message; this might contain a change log
+       # or release notes so is worth displaying.
+       git cat-file tag $newrev | sed -e '1,/^$/d'
+
+       echo ""
+       case "$tagtype" in
+       commit)
+               # Only commit tags make sense to have rev-list operations performed
+               # on them
+               if [ -n "$prevtag" ]; then
+                       # Show changes since the previous release
+                       git rev-list --pretty=short "$prevtag..$newrev" | git shortlog
+               else
+                       # No previous tag, show all the changes since time began
+                       git rev-list --pretty=short $newrev | git shortlog
+               fi
+               ;;
+       *)
+               # XXX: Is there anything useful we can do for non-commit objects?
+               ;;
+       esac
+
+       echo $LOGEND
+}
+
+#
+# Called for the deletion of an annotated tag
+#
+generate_delete_atag_email()
+{
+       echo "       was  $oldrev"
+       echo ""
+       echo $LOGEND
+       git show -s --pretty=oneline $oldrev
+       echo $LOGEND
+}
+
+# --------------- General references
+
+#
+# Called when any other type of reference is created (most likely a
+# non-annotated tag)
+#
+generate_create_general_email()
+{
+       echo "        at  $newrev ($newrev_type)"
+
+       generate_general_email
+}
+
+#
+# Called when any other type of reference is updated (most likely a
+# non-annotated tag)
+#
+generate_update_general_email()
+{
+       echo "        to  $newrev ($newrev_type)"
+       echo "      from  $oldrev"
+
+       generate_general_email
+}
+
+#
+# Called for creation or update of any other type of reference
+#
+generate_general_email()
+{
+       # Unannotated tags are more about marking a point than releasing a version;
+       # therefore we don't do the shortlog summary that we do for annotated tags
+       # above - we simply show that the point has been marked, and print the log
+       # message for the marked point for reference purposes
+       #
+       # Note this section also catches any other reference type (although there
+       # aren't any) and deals with them in the same way.
+
+       echo ""
+       if [ "$newrev_type" = "commit" ]; then
+               echo $LOGBEGIN
+               git show --no-color --root -s $newrev
+               echo $LOGEND
+       else
+               # What can we do here?  The tag marks an object that is not a commit,
+               # so there is no log for us to display.  It's probably not wise to
+               # output git-cat-file as it could be a binary blob.  We'll just say how
+               # big it is
+               echo "$newrev is a $newrev_type, and is $(git cat-file -s $newrev) bytes long."
+       fi
+}
+
+#
+# Called for the deletion of any other type of reference
+#
+generate_delete_general_email()
+{
+       echo "       was  $oldrev"
+       echo ""
+       echo $LOGEND
+       git show -s --pretty=oneline $oldrev
+       echo $LOGEND
+}
+
+# ---------------------------- main()
+
+# --- Constants
+EMAILPREFIX="[SCM] "
+LOGBEGIN="- Log -----------------------------------------------------------------"
+LOGEND="-----------------------------------------------------------------------"
+
+# --- Config
+# Set GIT_DIR either from the working directory, or from the environment
+# variable.
+GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
+if [ -z "$GIT_DIR" ]; then
+       echo >&2 "fatal: post-receive: GIT_DIR not set"
+       exit 1
+fi
+
+projectdesc=$(sed -e '1p' "$GIT_DIR/description")
+# Check if the description is unchanged from it's default, and shorten it to a
+# more manageable length if it is
+if expr "$projectdesc" : "Unnamed repository.*$" >/dev/null
+then
+       projectdesc="UNNAMED PROJECT"
+fi
+
+recipients=$(git repo-config hooks.mailinglist)
+announcerecipients=$(git repo-config hooks.announcelist)
+envelopesender=$(git-repo-config hooks.envelopesender)
+
+# --- Main loop
+# Allow dual mode: run from the command line just like the update hook, or if
+# no arguments are given then run as a hook script
+if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
+       # Output to the terminal in command line mode - if someone wanted to
+       # resend an email; they could redirect the output to sendmail themselves
+       PAGER= generate_email $2 $3 $1
+else
+       if [ -n "$envelopesender" ]; then
+               envelopesender="-f '$envelopesender'"
+       fi
+
+       while read oldrev newrev refname
+       do
+               generate_email $oldrev $newrev $refname |
+               /usr/sbin/sendmail -t $envelopesender
+       done
+fi
diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir
new file mode 100755 (executable)
index 0000000..9877b98
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+usage () {
+       echo "usage:" $@
+       exit 127
+}
+
+die () {
+       echo $@
+       exit 128
+}
+
+if test $# -lt 2 || test $# -gt 3
+then
+       usage "$0 <repository> <new_workdir> [<branch>]"
+fi
+
+orig_git=$1
+new_workdir=$2
+branch=$3
+
+# want to make sure that what is pointed to has a .git directory ...
+test -d "$orig_git/.git" || die "\"$orig_git\" is not a git repository!"
+
+# don't link to a workdir
+if test -L "$orig_git/.git/config"
+then
+       die "\"$orig_git\" is a working directory only, please specify" \
+               "a complete repository."
+fi
+
+# make sure the the links use full paths
+orig_git=$(cd "$orig_git"; pwd)
+
+# create the workdir
+mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!"
+
+# create the links to the original repo.  explictly exclude index, HEAD and
+# logs/HEAD from the list since they are purely related to the current working
+# directory, and should not be shared.
+for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache
+do
+       case $x in
+       */*)
+               mkdir -p "$(dirname "$new_workdir/.git/$x")"
+               ;;
+       esac
+       ln -s "$orig_git/.git/$x" "$new_workdir/.git/$x"
+done
+
+# now setup the workdir
+cd "$new_workdir"
+# copy the HEAD from the original repository as a default branch
+cp "$orig_git/.git/HEAD" .git/HEAD
+# checkout the branch (either the same as HEAD from the original repository, or
+# the one that was asked for)
+git checkout -f $branch
index 778cf58244d64b1e1b14ead43c2fdf5735bd717f..5c5b05bfe32bc90484b5bd6a9c171e0f9b04fbd6 100644 (file)
@@ -30,22 +30,28 @@ static int read_directory(const char *path, struct path_list *list)
        return 0;
 }
 
+static int get_mode(const char *path, int *mode)
+{
+       struct stat st;
+
+       if (!path || !strcmp(path, "/dev/null"))
+               *mode = 0;
+       else if (!strcmp(path, "-"))
+               *mode = ntohl(create_ce_mode(0666));
+       else if (stat(path, &st))
+               return error("Could not access '%s'", path);
+       else
+               *mode = st.st_mode;
+       return 0;
+}
+
 static int queue_diff(struct diff_options *o,
                const char *name1, const char *name2)
 {
-       struct stat st;
        int mode1 = 0, mode2 = 0;
 
-       if (name1) {
-               if (stat(name1, &st))
-                       return error("Could not access '%s'", name1);
-               mode1 = st.st_mode;
-       }
-       if (name2) {
-               if (stat(name2, &st))
-                       return error("Could not access '%s'", name2);
-               mode2 = st.st_mode;
-       }
+       if (get_mode(name1, &mode1) || get_mode(name2, &mode2))
+               return -1;
 
        if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2))
                return error("file/directory conflict: %s, %s", name1, name2);
@@ -164,8 +170,10 @@ static int handle_diff_files_args(struct rev_info *revs,
                else if (!strcmp(argv[1], "--theirs"))
                        revs->max_count = 3;
                else if (!strcmp(argv[1], "-n") ||
-                               !strcmp(argv[1], "--no-index"))
+                               !strcmp(argv[1], "--no-index")) {
                        revs->max_count = -2;
+                       revs->diffopt.exit_with_status = 1;
+               }
                else if (!strcmp(argv[1], "-q"))
                        *silent = 1;
                else
@@ -224,13 +232,14 @@ int setup_diff_no_index(struct rev_info *revs,
 {
        int i;
        for (i = 1; i < argc; i++)
-               if (argv[i][0] != '-')
+               if (argv[i][0] != '-' || argv[i][1] == '\0')
                        break;
                else if (!strcmp(argv[i], "--")) {
                        i++;
                        break;
                } else if (i < argc - 3 && !strcmp(argv[i], "--no-index")) {
                        i = argc - 3;
+                       revs->diffopt.exit_with_status = 1;
                        break;
                }
        if (argc != i + 2 || (!is_outside_repo(argv[i + 1], nongit, prefix) &&
@@ -254,9 +263,15 @@ int setup_diff_no_index(struct rev_info *revs,
 
                revs->diffopt.paths = xcalloc(2, sizeof(char*));
                for (i = 0; i < 2; i++) {
-                       const char *p;
-                       p = prefix_filename(prefix, len, argv[argc - 2 + i]);
-                       revs->diffopt.paths[i] = xstrdup(p);
+                       const char *p = argv[argc - 2 + i];
+                       /*
+                        * stdin should be spelled as '-'; if you have
+                        * path that is '-', spell it as ./-.
+                        */
+                       p = (strcmp(p, "-")
+                            ? xstrdup(prefix_filename(prefix, len, p))
+                            : p);
+                       revs->diffopt.paths[i] = p;
                }
        }
        else
@@ -309,6 +324,9 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
                struct cache_entry *ce = active_cache[i];
                int changed;
 
+               if (revs->diffopt.quiet && revs->diffopt.has_changes)
+                       break;
+
                if (!ce_path_match(ce, revs->prune_data))
                        continue;
 
@@ -550,6 +568,9 @@ static int diff_cache(struct rev_info *revs,
                struct cache_entry *ce = *ac;
                int same = (entries > 1) && ce_same_name(ce, ac[1]);
 
+               if (revs->diffopt.quiet && revs->diffopt.has_changes)
+                       break;
+
                if (!ce_path_match(ce, pathspec))
                        goto skip_entry;
 
diff --git a/diff.c b/diff.c
index 8f7a7d110857f2dcfcdb577da08df8deaf720cf7..fbb79d70a93dd0c6c46a1d24505e55f737d44189 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -811,7 +811,12 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
 
                if (data->files[i]->is_binary) {
                        show_name(prefix, name, len, reset, set);
-                       printf("  Bin\n");
+                       printf("  Bin ");
+                       printf("%s%d%s", del_c, deleted, reset);
+                       printf(" -> ");
+                       printf("%s%d%s", add_c, added, reset);
+                       printf(" bytes");
+                       printf("\n");
                        goto free_diffstat_file;
                }
                else if (data->files[i]->is_unmerged) {
@@ -1185,9 +1190,11 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
        if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
                die("unable to read files to diff");
 
-       if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2))
+       if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2)) {
                data->is_binary = 1;
-       else {
+               data->added = mf2.size;
+               data->deleted = mf1.size;
+       } else {
                /* Crazy xdl interfaces.. */
                xpparam_t xpp;
                xdemitconf_t xecfg;
@@ -1364,6 +1371,32 @@ static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,
        return e;
 }
 
+static int populate_from_stdin(struct diff_filespec *s)
+{
+#define INCREMENT 1024
+       char *buf;
+       unsigned long size;
+       int got;
+
+       size = 0;
+       buf = NULL;
+       while (1) {
+               buf = xrealloc(buf, size + INCREMENT);
+               got = xread(0, buf + size, INCREMENT);
+               if (!got)
+                       break; /* EOF */
+               if (got < 0)
+                       return error("error while reading from stdin %s",
+                                    strerror(errno));
+               size += got;
+       }
+       s->should_munmap = 0;
+       s->data = buf;
+       s->size = size;
+       s->should_free = 1;
+       return 0;
+}
+
 /*
  * While doing rename detection and pickaxe operation, we may need to
  * grab the data for the blob (or file) for our own in-core comparison.
@@ -1389,6 +1422,9 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
                char *buf;
                unsigned long size;
 
+               if (!strcmp(s->path, "-"))
+                       return populate_from_stdin(s);
+
                if (lstat(s->path, &st) < 0) {
                        if (errno == ENOENT) {
                        err_empty:
@@ -1690,6 +1726,10 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
        if (DIFF_FILE_VALID(one)) {
                if (!one->sha1_valid) {
                        struct stat st;
+                       if (!strcmp(one->path, "-")) {
+                               hashcpy(one->sha1, null_sha1);
+                               return;
+                       }
                        if (lstat(one->path, &st) < 0)
                                die("stat %s", one->path);
                        if (index_path(one->sha1, one->path, &st, 0))
@@ -1925,6 +1965,23 @@ int diff_setup_done(struct diff_options *options)
        if (options->abbrev <= 0 || 40 < options->abbrev)
                options->abbrev = 40; /* full */
 
+       /*
+        * It does not make sense to show the first hit we happened
+        * to have found.  It does not make sense not to return with
+        * exit code in such a case either.
+        */
+       if (options->quiet) {
+               options->output_format = DIFF_FORMAT_NO_OUTPUT;
+               options->exit_with_status = 1;
+       }
+
+       /*
+        * If we postprocess in diffcore, we cannot simply return
+        * upon the first hit.  We need to run diff as usual.
+        */
+       if (options->pickaxe || options->filter)
+               options->quiet = 0;
+
        return 0;
 }
 
@@ -2101,6 +2158,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->color_diff = options->color_diff_words = 1;
        else if (!strcmp(arg, "--no-renames"))
                options->detect_rename = 0;
+       else if (!strcmp(arg, "--exit-code"))
+               options->exit_with_status = 1;
+       else if (!strcmp(arg, "--quiet"))
+               options->quiet = 1;
        else
                return 0;
        return 1;
@@ -2865,6 +2926,8 @@ static void diffcore_apply_filter(const char *filter)
 
 void diffcore_std(struct diff_options *options)
 {
+       if (options->quiet)
+               return;
        if (options->break_opt != -1)
                diffcore_break(options->break_opt);
        if (options->detect_rename)
@@ -2877,18 +2940,11 @@ void diffcore_std(struct diff_options *options)
                diffcore_order(options->orderfile);
        diff_resolve_rename_copy();
        diffcore_apply_filter(options->filter);
-}
-
 
-void diffcore_std_no_resolve(struct diff_options *options)
-{
-       if (options->pickaxe)
-               diffcore_pickaxe(options->pickaxe, options->pickaxe_opts);
-       if (options->orderfile)
-               diffcore_order(options->orderfile);
-       diffcore_apply_filter(options->filter);
+       options->has_changes = !!diff_queued_diff.nr;
 }
 
+
 void diff_addremove(struct diff_options *options,
                    int addremove, unsigned mode,
                    const unsigned char *sha1,
@@ -2924,6 +2980,7 @@ void diff_addremove(struct diff_options *options,
                fill_filespec(two, sha1, mode);
 
        diff_queue(&diff_queued_diff, one, two);
+       options->has_changes = 1;
 }
 
 void diff_change(struct diff_options *options,
@@ -2949,6 +3006,7 @@ void diff_change(struct diff_options *options,
        fill_filespec(two, new_sha1, new_mode);
 
        diff_queue(&diff_queued_diff, one, two);
+       options->has_changes = 1;
 }
 
 void diff_unmerge(struct diff_options *options,
diff --git a/diff.h b/diff.h
index 4b435e8b1933222da02f9e4cf2c28d2fef44d292..a0d2ce13994c1a8751bf7b207671e95c5bc5db97 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -56,7 +56,10 @@ struct diff_options {
                 silent_on_remove:1,
                 find_copies_harder:1,
                 color_diff:1,
-                color_diff_words:1;
+                color_diff_words:1,
+                has_changes:1,
+                quiet:1,
+                exit_with_status:1;
        int context;
        int break_opt;
        int detect_rename;
@@ -170,8 +173,6 @@ extern int diff_setup_done(struct diff_options *);
 
 extern void diffcore_std(struct diff_options *);
 
-extern void diffcore_std_no_resolve(struct diff_options *);
-
 #define COMMON_DIFF_OPTIONS_HELP \
 "\ncommon diff options:\n" \
 "  -z            output diff-raw with lines terminated with NUL.\n" \
diff --git a/dir.c b/dir.c
index b48e19dc09fff7d7fb1d5b48673fe4448b69a7c3..7426fde330a200e3137e722c4b9adbc5ce6bdd90 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -8,6 +8,11 @@
 #include "cache.h"
 #include "dir.h"
 
+struct path_simplify {
+       int len;
+       const char *path;
+};
+
 int common_prefix(const char **pathspec)
 {
        const char *path, *slash, *next;
@@ -292,6 +297,31 @@ static int dir_exists(const char *dirname, int len)
        return !strncmp(active_cache[pos]->name, dirname, len);
 }
 
+/*
+ * This is an inexact early pruning of any recursive directory
+ * reading - if the path cannot possibly be in the pathspec,
+ * return true, and we'll skip it early.
+ */
+static int simplify_away(const char *path, int pathlen, const struct path_simplify *simplify)
+{
+       if (simplify) {
+               for (;;) {
+                       const char *match = simplify->path;
+                       int len = simplify->len;
+
+                       if (!match)
+                               break;
+                       if (len > pathlen)
+                               len = pathlen;
+                       if (!memcmp(path, match, len))
+                               return 0;
+                       simplify++;
+               }
+               return 1;
+       }
+       return 0;
+}
+
 /*
  * Read a directory tree. We currently ignore anything but
  * directories, regular files and symlinks. That's because git
@@ -301,7 +331,7 @@ static int dir_exists(const char *dirname, int len)
  * Also, we ignore the name ".git" (even if it is not a directory).
  * That likely will not change.
  */
-static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen, int check_only)
+static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen, int check_only, const struct path_simplify *simplify)
 {
        DIR *fdir = opendir(path);
        int contents = 0;
@@ -324,6 +354,8 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
                                continue;
                        len = strlen(de->d_name);
                        memcpy(fullname + baselen, de->d_name, len+1);
+                       if (simplify_away(fullname, baselen + len, simplify))
+                               continue;
                        if (excluded(dir, fullname) != dir->show_ignored) {
                                if (!dir->show_ignored || DTYPE(de) != DT_DIR) {
                                        continue;
@@ -350,13 +382,13 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
                                        if (dir->hide_empty_directories &&
                                            !read_directory_recursive(dir,
                                                    fullname, fullname,
-                                                   baselen + len, 1))
+                                                   baselen + len, 1, simplify))
                                                continue;
                                        break;
                                }
 
                                contents += read_directory_recursive(dir,
-                                       fullname, fullname, baselen + len, 0);
+                                       fullname, fullname, baselen + len, 0, simplify);
                                continue;
                        case DT_REG:
                        case DT_LNK:
@@ -386,8 +418,61 @@ static int cmp_name(const void *p1, const void *p2)
                                  e2->name, e2->len);
 }
 
-int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen)
+/*
+ * Return the length of the "simple" part of a path match limiter.
+ */
+static int simple_length(const char *match)
 {
+       const char special[256] = {
+               [0] = 1, ['?'] = 1,
+               ['\\'] = 1, ['*'] = 1,
+               ['['] = 1
+       };
+       int len = -1;
+
+       for (;;) {
+               unsigned char c = *match++;
+               len++;
+               if (special[c])
+                       return len;
+       }
+}
+
+static struct path_simplify *create_simplify(const char **pathspec)
+{
+       int nr, alloc = 0;
+       struct path_simplify *simplify = NULL;
+
+       if (!pathspec)
+               return NULL;
+
+       for (nr = 0 ; ; nr++) {
+               const char *match;
+               if (nr >= alloc) {
+                       alloc = alloc_nr(alloc);
+                       simplify = xrealloc(simplify, alloc * sizeof(*simplify));
+               }
+               match = *pathspec++;
+               if (!match)
+                       break;
+               simplify[nr].path = match;
+               simplify[nr].len = simple_length(match);
+       }
+       simplify[nr].path = NULL;
+       simplify[nr].len = 0;
+       return simplify;
+}
+
+static void free_simplify(struct path_simplify *simplify)
+{
+       if (simplify)
+               free(simplify);
+}
+
+int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen, const char **pathspec)
+{
+       struct path_simplify *simplify = create_simplify(pathspec);
+
        /*
         * Make sure to do the per-directory exclude for all the
         * directories leading up to our base.
@@ -414,7 +499,8 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i
                }
        }
 
-       read_directory_recursive(dir, path, base, baselen, 0);
+       read_directory_recursive(dir, path, base, baselen, 0, simplify);
+       free_simplify(simplify);
        qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);
        return dir->nr;
 }
diff --git a/dir.h b/dir.h
index 7233d65bbd393f1d34d75538dd0e39e4a86383f2..33c31f25fbabc36db26e6fdf9f33381f166d2d7f 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -48,7 +48,7 @@ extern int common_prefix(const char **pathspec);
 #define MATCHED_EXACTLY 3
 extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen);
 
-extern int read_directory(struct dir_struct *, const char *path, const char *base, int baselen);
+extern int read_directory(struct dir_struct *, const char *path, const char *base, int baselen, const char **pathspec);
 extern int push_exclude_per_directory(struct dir_struct *, const char *, int);
 extern void pop_exclude_per_directory(struct dir_struct *, int);
 
index 0151ad07227d20a7f8d4a5c390d77b2aa85ef739..22316597df60648c850001e068938eaf39d57f6d 100644 (file)
@@ -20,13 +20,14 @@ int is_bare_repository_cfg = -1; /* unspecified */
 int log_all_ref_updates = -1; /* unspecified */
 int warn_ambiguous_refs = 1;
 int repository_format_version;
-char *git_commit_encoding;
+const char *git_commit_encoding;
 const char *git_log_output_encoding;
 int shared_repository = PERM_UMASK;
 const char *apply_default_whitespace;
 int zlib_compression_level = Z_DEFAULT_COMPRESSION;
 size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
+size_t delta_base_cache_limit = 16 * 1024 * 1024;
 int pager_in_use;
 int pager_use_color = 1;
 int auto_crlf = 0;     /* 1: both ways, -1: only when adding git objects */
index 726f5ba7d2a8b16e0fb62846f3ede631d99486d3..cdd629d6bc547609daabab6c1f3b73939fddb7b9 100644 (file)
@@ -630,7 +630,7 @@ static void start_packfile(void)
        int pack_fd;
 
        snprintf(tmpfile, sizeof(tmpfile),
-               "%s/pack_XXXXXX", get_object_directory());
+               "%s/tmp_pack_XXXXXX", get_object_directory());
        pack_fd = mkstemp(tmpfile);
        if (pack_fd < 0)
                die("Can't create %s: %s", tmpfile, strerror(errno));
@@ -730,7 +730,7 @@ static char *create_index(void)
        }
 
        snprintf(tmpfile, sizeof(tmpfile),
-               "%s/index_XXXXXX", get_object_directory());
+               "%s/tmp_idx_XXXXXX", get_object_directory());
        idx_fd = mkstemp(tmpfile);
        if (idx_fd < 0)
                die("Can't create %s: %s", tmpfile, strerror(errno));
@@ -1058,7 +1058,7 @@ static void load_tree(struct tree_entry *root)
                struct tree_entry *e = new_tree_entry();
 
                if (t->entry_count == t->entry_capacity)
-                       root->tree = t = grow_tree_content(t, 8);
+                       root->tree = t = grow_tree_content(t, t->entry_count);
                t->entries[t->entry_count++] = e;
 
                e->tree = NULL;
@@ -1066,7 +1066,7 @@ static void load_tree(struct tree_entry *root)
                if (!c)
                        die("Corrupt mode in %s", sha1_to_hex(sha1));
                e->versions[0].mode = e->versions[1].mode;
-               e->name = to_atom(c, (unsigned short)strlen(c));
+               e->name = to_atom(c, strlen(c));
                c += e->name->str_len + 1;
                hashcpy(e->versions[0].sha1, (unsigned char*)c);
                hashcpy(e->versions[1].sha1, (unsigned char*)c);
@@ -1225,9 +1225,9 @@ static int tree_content_set(
        }
 
        if (t->entry_count == t->entry_capacity)
-               root->tree = t = grow_tree_content(t, 8);
+               root->tree = t = grow_tree_content(t, t->entry_count);
        e = new_tree_entry();
-       e->name = to_atom(p, (unsigned short)n);
+       e->name = to_atom(p, n);
        e->versions[0].mode = 0;
        hashclr(e->versions[0].sha1);
        t->entries[t->entry_count++] = e;
@@ -1312,7 +1312,7 @@ static int update_branch(struct branch *b)
 
                if (!in_merge_bases(old_cmit, &new_cmit, 1)) {
                        unlock_ref(lock);
-                       warn("Not updating %s"
+                       warning("Not updating %s"
                                " (new tip %s does not contain %s)",
                                b->name, sha1_to_hex(b->sha1), sha1_to_hex(old_sha1));
                        return -1;
diff --git a/fetch.c b/fetch.c
index f69be82f10d287d71f6184c4b9203bdab3ce81fc..8e29d313f817981a29ebb65f2f579c9f1bd8e9b6 100644 (file)
--- a/fetch.c
+++ b/fetch.c
@@ -42,8 +42,7 @@ static int process_tree(struct tree *tree)
        if (parse_tree(tree))
                return -1;
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
        while (tree_entry(&desc, &entry)) {
                struct object *obj = NULL;
 
index 2c73d116b28d0d89d1fbdfc1d454506bff9e3f46..e69ecbfdb1a817b477aff8618f284a4c921e00e5 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -290,6 +290,10 @@ do
                git-mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \
                        <"$dotest/$msgnum" >"$dotest/info" ||
                        stop_here $this
+               test -s $dotest/patch || {
+                       echo "Patch is empty.  Was is split wrong?"
+                       stop_here $this
+               }
                git-stripspace < "$dotest/msg" > "$dotest/msg-clean"
                ;;
        esac
@@ -404,12 +408,10 @@ do
                # trust what the user has in the index file and the
                # working tree.
                resolved=
-               changed="$(git-diff-index --cached --name-only HEAD)"
-               if test '' = "$changed"
-               then
+               git-diff-index --quiet --cached HEAD && {
                        echo "No changes - did you forget to use 'git add'?"
                        stop_here_user_resolve $this
-               fi
+               }
                unmerged=$(git-ls-files -u)
                if test -n "$unmerged"
                then
@@ -431,13 +433,11 @@ do
                then
                    # Applying the patch to an earlier tree and merging the
                    # result may have produced the same tree as ours.
-                   changed="$(git-diff-index --cached --name-only HEAD)"
-                   if test '' = "$changed"
-                   then
-                           echo No changes -- Patch already applied.
-                           go_next
-                           continue
-                   fi
+                   git-diff-index --quiet --cached HEAD && {
+                       echo No changes -- Patch already applied.
+                       go_next
+                       continue
+                   }
                    # clear apply_status -- we have successfully merged.
                    apply_status=0
                fi
index 1f68599ae51a671f8c7a3a01c6aa9c6b205dd217..3efd6a746407bdc38ba9d251332427c508e5ee40 100755 (executable)
@@ -77,6 +77,10 @@ do
     *)
            git-mailinfo $keep_subject $utf8 \
                .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
+           test -s .dotest/patch || {
+               echo "Patch is empty.  Was is split wrong?"
+               exit 1
+           }
            git-stripspace < .dotest/msg > .dotest/msg-clean
            ;;
     esac
index b1c3a6b1c1af9815db473595f4eb3e9593425f10..85c374e21e7076cae8f186afe899437bda1ac770 100755 (executable)
@@ -1,14 +1,24 @@
 #!/bin/sh
 
-USAGE='[start|bad|good|next|reset|visualize|replay|log]'
-LONG_USAGE='git bisect start [<pathspec>]      reset bisect state and start bisection.
-git bisect bad [<rev>]         mark <rev> a known-bad revision.
-git bisect good [<rev>...]     mark <rev>... known-good revisions.
-git bisect next                        find next bisection to test and check it out.
-git bisect reset [<branch>]    finish bisection search and go back to branch.
-git bisect visualize            show bisect status in gitk.
-git bisect replay <logfile>    replay bisection log
-git bisect log                 show bisect log.'
+USAGE='[start|bad|good|next|reset|visualize|replay|log|run]'
+LONG_USAGE='git bisect start [<bad> [<good>...]] [--] [<pathspec>...]
+        reset bisect state and start bisection.
+git bisect bad [<rev>]
+        mark <rev> a known-bad revision.
+git bisect good [<rev>...]
+        mark <rev>... known-good revisions.
+git bisect next
+        find next bisection to test and check it out.
+git bisect reset [<branch>]
+        finish bisection search and go back to branch.
+git bisect visualize
+        show bisect status in gitk.
+git bisect replay <logfile>
+        replay bisection log.
+git bisect log
+        show bisect log.
+git bisect run <cmd>...
+        use <cmd>... to automatically bisect.'
 
 . git-sh-setup
 require_work_tree
@@ -49,7 +59,7 @@ bisect_start() {
        head=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD) ||
        die "Bad HEAD - I need a symbolic ref"
        case "$head" in
-       refs/heads/bisect*)
+       refs/heads/bisect)
                if [ -s "$GIT_DIR/head-name" ]; then
                    branch=`cat "$GIT_DIR/head-name"`
                else
@@ -69,14 +79,48 @@ bisect_start() {
        #
        # Get rid of any old bisect state
        #
-       rm -f "$GIT_DIR/refs/heads/bisect"
-       rm -rf "$GIT_DIR/refs/bisect/"
+       bisect_clean_state
        mkdir "$GIT_DIR/refs/bisect"
+
+       #
+       # Check for one bad and then some good revisions.
+       #
+       has_double_dash=0
+       for arg; do
+           case "$arg" in --) has_double_dash=1; break ;; esac
+       done
+       orig_args=$(sq "$@")
+       bad_seen=0
+       while [ $# -gt 0 ]; do
+           arg="$1"
+           case "$arg" in
+           --)
+               shift
+               break
+               ;;
+           *)
+               rev=$(git-rev-parse --verify "$arg^{commit}" 2>/dev/null) || {
+                   test $has_double_dash -eq 1 &&
+                       die "'$arg' does not appear to be a valid revision"
+                   break
+               }
+               if [ $bad_seen -eq 0 ]; then
+                   bad_seen=1
+                   bisect_write_bad "$rev"
+               else
+                   bisect_write_good "$rev"
+               fi
+               shift
+               ;;
+           esac
+        done
+
+       sq "$@" >"$GIT_DIR/BISECT_NAMES"
        {
            printf "git-bisect start"
-           sq "$@"
-       } >"$GIT_DIR/BISECT_LOG"
-       sq "$@" >"$GIT_DIR/BISECT_NAMES"
+           echo "$orig_args"
+       } >>"$GIT_DIR/BISECT_LOG"
+       bisect_auto_next
 }
 
 bisect_bad() {
@@ -85,16 +129,21 @@ bisect_bad() {
        0)
                rev=$(git-rev-parse --verify HEAD) ;;
        1)
-               rev=$(git-rev-parse --verify "$1") ;;
+               rev=$(git-rev-parse --verify "$1^{commit}") ;;
        *)
                usage ;;
        esac || exit
-       echo "$rev" >"$GIT_DIR/refs/bisect/bad"
-       echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
+       bisect_write_bad "$rev"
        echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
        bisect_auto_next
 }
 
+bisect_write_bad() {
+       rev="$1"
+       echo "$rev" >"$GIT_DIR/refs/bisect/bad"
+       echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
+}
+
 bisect_good() {
        bisect_autostart
         case "$#" in
@@ -104,28 +153,55 @@ bisect_good() {
        esac
        for rev in $revs
        do
-               rev=$(git-rev-parse --verify "$rev") || exit
-               echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
-               echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
+               rev=$(git-rev-parse --verify "$rev^{commit}") || exit
+               bisect_write_good "$rev"
                echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
+
        done
        bisect_auto_next
 }
 
+bisect_write_good() {
+       rev="$1"
+       echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
+       echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
+}
+
 bisect_next_check() {
-       next_ok=no
-        test -f "$GIT_DIR/refs/bisect/bad" &&
-       case "$(cd "$GIT_DIR" && echo refs/bisect/good-*)" in
-       refs/bisect/good-\*) ;;
-       *) next_ok=yes ;;
-       esac
-       case "$next_ok,$1" in
-       no,) false ;;
-       no,fail)
-           echo >&2 'You need to give me at least one good and one bad revisions.'
-           exit 1 ;;
+       missing_good= missing_bad=
+       git show-ref -q --verify refs/bisect/bad || missing_bad=t
+       test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t
+
+       case "$missing_good,$missing_bad,$1" in
+       ,,*)
+               : have both good and bad - ok
+               ;;
+       *,)
+               # do not have both but not asked to fail - just report.
+               false
+               ;;
+       t,,good)
+               # have bad but not good.  we could bisect although
+               # this is less optimum.
+               echo >&2 'Warning: bisecting only with a bad commit.'
+               if test -t 0
+               then
+                       printf >&2 'Are you sure [Y/n]? '
+                       case "$(read yesno)" in [Nn]*) exit 1 ;; esac
+               fi
+               : bisect without good...
+               ;;
        *)
-           true ;;
+               THEN=''
+               test -d "$GIT_DIR/refs/bisect" || {
+                       echo >&2 'You need to start by "git bisect start".'
+                       THEN='then '
+               }
+               echo >&2 'You '$THEN'need to give me at least one good' \
+                       'and one bad revisions.'
+               echo >&2 '(You can use "git bisect bad" and' \
+                       '"git bisect good" for that.)'
+               exit 1 ;;
        esac
 }
 
@@ -136,27 +212,32 @@ bisect_auto_next() {
 bisect_next() {
         case "$#" in 0) ;; *) usage ;; esac
        bisect_autostart
-       bisect_next_check fail
+       bisect_next_check good
+
        bad=$(git-rev-parse --verify refs/bisect/bad) &&
-       good=$(git-rev-parse --sq --revs-only --not \
-               $(cd "$GIT_DIR" && ls refs/bisect/good-*)) &&
-       rev=$(eval "git-rev-list --bisect $good $bad -- $(cat $GIT_DIR/BISECT_NAMES)") || exit
-       if [ -z "$rev" ]; then
-           echo "$bad was both good and bad"
-           exit 1
+       good=$(git for-each-ref --format='^%(objectname)' \
+               "refs/bisect/good-*" | tr '[\012]' ' ') &&
+       eval="git-rev-list --bisect-vars $good $bad --" &&
+       eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" &&
+       eval=$(eval "$eval") &&
+       eval "$eval" || exit
+
+       if [ -z "$bisect_rev" ]; then
+               echo "$bad was both good and bad"
+               exit 1
        fi
-       if [ "$rev" = "$bad" ]; then
-           echo "$rev is first bad commit"
-           git-diff-tree --pretty $rev
-           exit 0
+       if [ "$bisect_rev" = "$bad" ]; then
+               echo "$bisect_rev is first bad commit"
+               git-diff-tree --pretty $bisect_rev
+               exit 0
        fi
-       nr=$(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" | wc -l) || exit
-       echo "Bisecting: $nr revisions left to test after this"
-       echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
+
+       echo "Bisecting: $bisect_nr revisions left to test after this"
+       echo "$bisect_rev" >"$GIT_DIR/refs/heads/new-bisect"
        git checkout -q new-bisect || exit
        mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
        GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD refs/heads/bisect
-       git-show-branch "$rev"
+       git-show-branch "$bisect_rev"
 }
 
 bisect_visualize() {
@@ -172,7 +253,7 @@ bisect_reset() {
           else
               branch=master
           fi ;;
-       1) test -f "$GIT_DIR/refs/heads/$1" || {
+       1) git-show-ref --verify --quiet -- "refs/heads/$1" || {
               echo >&2 "$1 does not seem to be a valid branch"
               exit 1
           }
@@ -181,13 +262,19 @@ bisect_reset() {
            usage ;;
        esac
        if git checkout "$branch"; then
-               rm -fr "$GIT_DIR/refs/bisect"
-               rm -f "$GIT_DIR/refs/heads/bisect" "$GIT_DIR/head-name"
-               rm -f "$GIT_DIR/BISECT_LOG"
-               rm -f "$GIT_DIR/BISECT_NAMES"
+               rm -f "$GIT_DIR/head-name"
+               bisect_clean_state
        fi
 }
 
+bisect_clean_state() {
+       rm -fr "$GIT_DIR/refs/bisect"
+       rm -f "$GIT_DIR/refs/heads/bisect"
+       rm -f "$GIT_DIR/BISECT_LOG"
+       rm -f "$GIT_DIR/BISECT_NAMES"
+       rm -f "$GIT_DIR/BISECT_RUN"
+}
+
 bisect_replay () {
        test -r "$1" || {
                echo >&2 "cannot read $1 for replaying"
@@ -220,6 +307,52 @@ bisect_replay () {
        bisect_auto_next
 }
 
+bisect_run () {
+    bisect_next_check fail
+
+    while true
+    do
+      echo "running $@"
+      "$@"
+      res=$?
+
+      # Check for really bad run error.
+      if [ $res -lt 0 -o $res -ge 128 ]; then
+         echo >&2 "bisect run failed:"
+         echo >&2 "exit code $res from '$@' is < 0 or >= 128"
+         exit $res
+      fi
+
+      # Use "bisect_good" or "bisect_bad"
+      # depending on run success or failure.
+      if [ $res -gt 0 ]; then
+         next_bisect='bisect_bad'
+      else
+         next_bisect='bisect_good'
+      fi
+
+      # We have to use a subshell because bisect_good or
+      # bisect_bad functions can exit.
+      ( $next_bisect > "$GIT_DIR/BISECT_RUN" )
+      res=$?
+
+      cat "$GIT_DIR/BISECT_RUN"
+
+      if [ $res -ne 0 ]; then
+         echo >&2 "bisect run failed:"
+         echo >&2 "$next_bisect exited with error code $res"
+         exit $res
+      fi
+
+      if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then
+         echo "bisect run success"
+         exit 0;
+      fi
+
+    done
+}
+
+
 case "$#" in
 0)
     usage ;;
@@ -244,6 +377,8 @@ case "$#" in
        bisect_replay "$@" ;;
     log)
        cat "$GIT_DIR/BISECT_LOG" ;;
+    run)
+        bisect_run "$@" ;;
     *)
         usage ;;
     esac
index 14835a4aa982af88d758ea014afacf7b2fb1bb1e..deb0a9a3c733ed889158d05b7cae4d174917553d 100755 (executable)
@@ -12,6 +12,7 @@ new=
 new_name=
 force=
 branch=
+track=
 newbranch=
 newbranch_log=
 merge=
@@ -33,7 +34,10 @@ while [ "$#" != "0" ]; do
                        die "git checkout: we do not like '$newbranch' as a branch name."
                ;;
        "-l")
-               newbranch_log=1
+               newbranch_log=-l
+               ;;
+       "--track"|"--no-track")
+               track="$arg"
                ;;
        "-f")
                force=1
@@ -85,6 +89,11 @@ while [ "$#" != "0" ]; do
     esac
 done
 
+case "$newbranch,$track" in
+,--*)
+       die "git checkout: --track and --no-track require -b"
+esac
+
 case "$force$merge" in
 11)
        die "git checkout: -f and -m are incompatible"
@@ -154,7 +163,14 @@ cd_to_toplevel
 detached=
 detach_warn=
 
-if test -z "$branch$newbranch" && test "$new" != "$old"
+describe_detached_head () {
+       test -n "$quiet" || {
+               printf >&2 "$1 "
+               GIT_PAGER= git log >&2 -1 --pretty=oneline --abbrev-commit "$2"
+       }
+}
+
+if test -z "$branch$newbranch" && test "$new_name" != "$old_name"
 then
        detached="$new"
        if test -n "$oldbranch" && test -z "$quiet"
@@ -164,9 +180,9 @@ If you want to create a new branch from this checkout, you may do so
 (now or later) by using -b with the checkout command again. Example:
   git checkout -b <new_branch_name>"
        fi
-elif test -z "$oldbranch" && test -z "$quiet"
+elif test -z "$oldbranch" && test "$new" != "$old"
 then
-       echo >&2 "Previous HEAD position was $old"
+       describe_detached_head 'Previous HEAD position was' "$old"
 fi
 
 if [ "X$old" = X ]
@@ -196,7 +212,7 @@ else
        work=`git write-tree` &&
        git read-tree --reset -u $new || exit
 
-       eval GITHEAD_$new=${new_name:-${branch:-$new}} &&
+       eval GITHEAD_$new='${new_name:-${branch:-$new}}' &&
        eval GITHEAD_$work=local &&
        export GITHEAD_$new GITHEAD_$work &&
        git merge-recursive $old -- $new $work
@@ -235,18 +251,19 @@ fi
 #
 if [ "$?" -eq 0 ]; then
        if [ "$newbranch" ]; then
-               if [ "$newbranch_log" ]; then
-                       mkdir -p $(dirname "$GIT_DIR/logs/refs/heads/$newbranch")
-                       touch "$GIT_DIR/logs/refs/heads/$newbranch"
-               fi
-               git-update-ref -m "checkout: Created from $new_name" "refs/heads/$newbranch" $new || exit
+               git-branch $track $newbranch_log "$newbranch" "$new_name" || exit
                branch="$newbranch"
        fi
        if test -n "$branch"
        then
                GIT_DIR="$GIT_DIR" git-symbolic-ref -m "checkout: moving to $branch" HEAD "refs/heads/$branch"
-               if test -z "$quiet"
+               if test -n "$quiet"
+               then
+                       true    # nothing
+               elif test "refs/heads/$branch" = "$oldbranch"
                then
+                       echo >&2 "Already on branch \"$branch\""
+               else
                        echo >&2 "Switched to${newbranch:+ a new} branch \"$branch\""
                fi
        elif test -n "$detached"
@@ -265,6 +282,7 @@ if [ "$?" -eq 0 ]; then
                then
                        echo >&2 "$detach_warn"
                fi
+               describe_detached_head 'HEAD is now at' HEAD
        fi
        rm -f "$GIT_DIR/MERGE_HEAD"
 else
index de51983584bb0fd015ed75704b72bec8fdb55430..513b574d13858f1a81e6f66251890d81bf0e55ce 100755 (executable)
@@ -42,6 +42,7 @@ clone_dumb_http () {
        http_fetch "$1/info/refs" "$clone_tmp/refs" ||
                die "Cannot get remote repository information.
 Perhaps git-update-server-info needs to be run there?"
+       test "z$quiet" = z && v=-v || v=
        while read sha1 refname
        do
                name=`expr "z$refname" : 'zrefs/\(.*\)'` &&
@@ -59,7 +60,7 @@ Perhaps git-update-server-info needs to be run there?"
                else
                        tname=$name
                fi
-               git-http-fetch -v -a -w "$tname" "$name" "$1/" || exit 1
+               git-http-fetch $v -a -w "$tname" "$name" "$1" || exit 1
        done <"$clone_tmp/refs"
        rm -fr "$clone_tmp"
        http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" ||
index b8c00b823656f36f6a6f38493b9569831db713b1..9e0959aec06c4d4d7b4f14660c26bc9dd941f111 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Linus Torvalds
 # Copyright (c) 2006 Junio C Hamano
 
-USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]'
+USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]'
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
 require_work_tree
@@ -71,6 +71,7 @@ trap '
 
 all=
 also=
+interactive=
 only=
 logfile=
 use_commit=
@@ -131,6 +132,11 @@ do
                also=t
                shift
                ;;
+       --int|--inte|--inter|--intera|--interac|--interact|--interacti|\
+       --interactiv|--interactive)
+               interactive=t
+               shift
+               ;;
        -o|--o|--on|--onl|--only)
                only=t
                shift
@@ -304,12 +310,14 @@ case "$#,$also,$only,$amend" in
        ;;
 esac
 unset only
-case "$all,$also,$#" in
-t,t,*)
-       die "Cannot use -a and -i at the same time." ;;
+case "$all,$interactive,$also,$#" in
+*t,*t,*)
+       die "Cannot use -a, --interactive or -i at the same time." ;;
 t,,[1-9]*)
        die "Paths with -a does not make sense." ;;
-,t,0)
+,t,[1-9]*)
+       die "Paths with --interactive does not make sense." ;;
+,,t,0)
        die "No paths with -i does not make sense." ;;
 esac
 
@@ -344,6 +352,9 @@ t,)
        ) || exit
        ;;
 ,)
+       if test "$interactive" = t; then
+               git add --interactive || exit
+       fi
        case "$#" in
        0)
                ;; # commit as-is
@@ -359,8 +370,8 @@ t,)
                # the same way.
                if test -z "$initial_commit"
                then
-                       cp "$THIS_INDEX" "$TMP_INDEX"
-                       GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD
+                       GIT_INDEX_FILE="$THIS_INDEX" \
+                       git-read-tree --index-output="$TMP_INDEX" -i -m HEAD
                else
                        rm -f "$TMP_INDEX"
                fi || exit
index 7534db1267bfa64a4a0cba80680fefc42177f0e8..139fc19108cab51eb23659868ef8600ff6b25795 100644 (file)
@@ -87,7 +87,7 @@
 extern void usage(const char *err) NORETURN;
 extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
 extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
-extern void warn(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
 
 extern void set_usage_routine(void (*routine)(const char *err) NORETURN);
 extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
index 1a1ba7b1a6f779773702ae3c1efb56425c31beb4..ac74bc51b3197d06f13f588d6916400ac3e6fcf0 100755 (executable)
@@ -32,12 +32,15 @@ $ENV{'TZ'}="UTC";
 our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,$opt_M,$opt_A,$opt_S,$opt_L, $opt_a);
 my (%conv_author_name, %conv_author_email);
 
-sub usage() {
+sub usage(;$) {
+       my $msg = shift;
+       print(STDERR "Error: $msg\n") if $msg;
        print STDERR <<END;
 Usage: ${\basename $0}     # fetch/update GIT from CVS
        [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
-       [-p opts-for-cvsps] [-C GIT_repository] [-z fuzz] [-i] [-k] [-u]
-       [-s subst] [-a] [-m] [-M regex] [-S regex] [CVS_module]
+       [-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
+       [-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
+       [CVS_module]
 END
        exit(1);
 }
@@ -116,7 +119,7 @@ read_repo_config($opts);
 getopts($opts) or usage();
 usage if $opt_h;
 
-@ARGV <= 1 or usage();
+@ARGV <= 1 or usage("You can't specify more than one CVS module");
 
 if ($opt_d) {
        $ENV{"CVSROOT"} = $opt_d;
@@ -129,7 +132,7 @@ if ($opt_d) {
 } elsif ($ENV{"CVSROOT"}) {
        $opt_d = $ENV{"CVSROOT"};
 } else {
-       die "CVSROOT needs to be set";
+       usage("CVSROOT needs to be set");
 }
 $opt_o ||= "origin";
 $opt_s ||= "-";
@@ -148,7 +151,7 @@ if ($#ARGV == 0) {
        chomp $cvs_tree;
        close $f;
 } else {
-       usage();
+       usage("CVS module has to be specified");
 }
 
 our @mergerx = ();
index 1bf892e4c130b20d39e4962595fa9040001d9fad..68aa75255e21ff8231fe2f54e5772f8cbb026fce 100755 (executable)
@@ -947,6 +947,7 @@ sub req_update
 
             # we need to merge with the local changes ( M=successful merge, C=conflict merge )
             $log->info("Merging $file_local, $file_old, $file_new");
+            print "M Merging differences between 1.$oldmeta->{revision} and 1.$meta->{revision} into $filename\n";
 
             $log->debug("Temporary directory for merge is $dir");
 
@@ -957,12 +958,12 @@ sub req_update
             {
                 $log->info("Merged successfully");
                 print "M M $filename\n";
-                $log->debug("Update-existing $dirpart");
+                $log->debug("Merged $dirpart");
 
                 # Don't want to actually _DO_ the update if -n specified
                 unless ( $state->{globaloptions}{-n} )
                 {
-                    print "Update-existing $dirpart\n";
+                    print "Merged $dirpart\n";
                     $log->debug($state->{CVSROOT} . "/$state->{module}/$filename");
                     print $state->{CVSROOT} . "/$state->{module}/$filename\n";
                     my $kopts = kopts_from_path($filepart);
@@ -973,12 +974,13 @@ sub req_update
             elsif ( $return == 1 )
             {
                 $log->info("Merged with conflicts");
+                print "E cvs update: conflicts found in $filename\n";
                 print "M C $filename\n";
 
                 # Don't want to actually _DO_ the update if -n specified
                 unless ( $state->{globaloptions}{-n} )
                 {
-                    print "Update-existing $dirpart\n";
+                    print "Merged $dirpart\n";
                     print $state->{CVSROOT} . "/$state->{module}/$filename\n";
                     my $kopts = kopts_from_path($filepart);
                     print "/$filepart/1.$meta->{revision}/+/$kopts/\n";
@@ -1067,6 +1069,7 @@ sub req_ci
     $log->info("Created index '$file_index' with for head $state->{module} - exit status $?");
 
     my @committedfiles = ();
+    my %oldmeta;
 
     # foreach file specified on the command line ...
     foreach my $filename ( @{$state->{args}} )
@@ -1077,6 +1080,7 @@ sub req_ci
         next unless ( exists $state->{entries}{$filename}{modified_filename} or not $state->{entries}{$filename}{unchanged} );
 
         my $meta = $updater->getmeta($filename);
+       $oldmeta{$filename} = $meta;
 
         my $wrev = revparse($filename);
 
@@ -1205,11 +1209,18 @@ sub req_ci
 
         $log->debug("Checked-in $dirpart : $filename");
 
+       print "M $state->{CVSROOT}/$state->{module}/$filename,v  <--  $dirpart$filepart\n";
         if ( defined $meta->{filehash} && $meta->{filehash} eq "deleted" )
         {
+            print "M new revision: delete; previous revision: 1.$oldmeta{$filename}{revision}\n";
             print "Remove-entry $dirpart\n";
             print "$filename\n";
         } else {
+            if ($meta->{revision} == 1) {
+               print "M initial revision: 1.1\n";
+            } else {
+               print "M new revision: 1.$meta->{revision}; previous revision: 1.$oldmeta{$filename}{revision}\n";
+            }
             print "Checked-in $dirpart\n";
             print "$filename\n";
             my $kopts = kopts_from_path($filepart);
@@ -1295,7 +1306,7 @@ sub req_status
         }
         if ( defined($meta->{revision}) )
         {
-            print "M Repository revision:\t1." . $meta->{revision} . "\t$state->{repository}/$filename,v\n";
+            print "M Repository revision:\t1." . $meta->{revision} . "\t$state->{CVSROOT}/$state->{module}/$filename,v\n";
             print "M Sticky Tag:\t\t(none)\n";
             print "M Sticky Date:\t\t(none)\n";
             print "M Sticky Options:\t\t(none)\n";
index 3aa117e321a83c7bda912530cb847ee7a73ced02..b04bd553f86213478a36f8ec2f19476f02ccf09f 100755 (executable)
@@ -113,133 +113,11 @@ ls_remote_result=$(git ls-remote $exec "$remote") ||
        die "Cannot get the repository state from $remote"
 
 append_fetch_head () {
-    head_="$1"
-    remote_="$2"
-    remote_name_="$3"
-    remote_nick_="$4"
-    local_name_="$5"
-    case "$6" in
-    t) not_for_merge_='not-for-merge' ;;
-    '') not_for_merge_= ;;
-    esac
-
-    # remote-nick is the URL given on the command line (or a shorthand)
-    # remote-name is the $GIT_DIR relative refs/ path we computed
-    # for this refspec.
-
-    # the $note_ variable will be fed to git-fmt-merge-msg for further
-    # processing.
-    case "$remote_name_" in
-    HEAD)
-       note_= ;;
-    refs/heads/*)
-       note_="$(expr "$remote_name_" : 'refs/heads/\(.*\)')"
-       note_="branch '$note_' of " ;;
-    refs/tags/*)
-       note_="$(expr "$remote_name_" : 'refs/tags/\(.*\)')"
-       note_="tag '$note_' of " ;;
-    refs/remotes/*)
-       note_="$(expr "$remote_name_" : 'refs/remotes/\(.*\)')"
-       note_="remote branch '$note_' of " ;;
-    *)
-       note_="$remote_name of " ;;
-    esac
-    remote_1_=$(expr "z$remote_" : 'z\(.*\)\.git/*$') &&
-       remote_="$remote_1_"
-    note_="$note_$remote_"
-
-    # 2.6.11-tree tag would not be happy to be fed to resolve.
-    if git-cat-file commit "$head_" >/dev/null 2>&1
-    then
-       headc_=$(git-rev-parse --verify "$head_^0") || exit
-       echo "$headc_   $not_for_merge_ $note_" >>"$GIT_DIR/FETCH_HEAD"
-    else
-       echo "$head_    not-for-merge   $note_" >>"$GIT_DIR/FETCH_HEAD"
-    fi
-
-    update_local_ref "$local_name_" "$head_" "$note_"
-}
-
-update_local_ref () {
-    # If we are storing the head locally make sure that it is
-    # a fast forward (aka "reverse push").
-
-    label_=$(git-cat-file -t $2)
-    newshort_=$(git-rev-parse --short $2)
-    if test -z "$1" ; then
-       [ "$verbose" ] && echo >&2 "* fetched $3"
-       [ "$verbose" ] && echo >&2 "  $label_: $newshort_"
-       return 0
-    fi
-    oldshort_=$(git show-ref --hash --abbrev "$1" 2>/dev/null)
-
-    case "$1" in
-    refs/tags/*)
-       # Tags need not be pointing at commits so there
-       # is no way to guarantee "fast-forward" anyway.
-       if test -n "$oldshort_"
-       then
-               if now_=$(git show-ref --hash "$1") && test "$now_" = "$2"
-               then
-                       [ "$verbose" ] && echo >&2 "* $1: same as $3"
-                       [ "$verbose" ] && echo >&2 "  $label_: $newshort_" ||:
-               else
-                       echo >&2 "* $1: updating with $3"
-                       echo >&2 "  $label_: $newshort_"
-                       git-update-ref -m "$GIT_REFLOG_ACTION: updating tag" "$1" "$2"
-               fi
-       else
-               echo >&2 "* $1: storing $3"
-               echo >&2 "  $label_: $newshort_"
-               git-update-ref -m "$GIT_REFLOG_ACTION: storing tag" "$1" "$2"
-       fi
-       ;;
-
-    refs/heads/* | refs/remotes/*)
-       # $1 is the ref being updated.
-       # $2 is the new value for the ref.
-       local=$(git-rev-parse --verify "$1^0" 2>/dev/null)
-       if test "$local"
-       then
-           # Require fast-forward.
-           mb=$(git-merge-base "$local" "$2") &&
-           case "$2,$mb" in
-           $local,*)
-               if test -n "$verbose"
-               then
-                       echo >&2 "* $1: same as $3"
-                       echo >&2 "  $label_: $newshort_"
-               fi
-               ;;
-           *,$local)
-               echo >&2 "* $1: fast forward to $3"
-               echo >&2 "  old..new: $oldshort_..$newshort_"
-               git-update-ref -m "$GIT_REFLOG_ACTION: fast-forward" "$1" "$2" "$local"
-               ;;
-           *)
-               false
-               ;;
-           esac || {
-               case ",$force,$single_force," in
-               *,t,*)
-                       echo >&2 "* $1: forcing update to non-fast forward $3"
-                       echo >&2 "  old...new: $oldshort_...$newshort_"
-                       git-update-ref -m "$GIT_REFLOG_ACTION: forced-update" "$1" "$2" "$local"
-                       ;;
-               *)
-                       echo >&2 "* $1: not updating to non-fast forward $3"
-                       echo >&2 "  old...new: $oldshort_...$newshort_"
-                       exit 1
-                       ;;
-               esac
-           }
-       else
-           echo >&2 "* $1: storing $3"
-           echo >&2 "  $label_: $newshort_"
-           git-update-ref -m "$GIT_REFLOG_ACTION: storing head" "$1" "$2"
-       fi
-       ;;
-    esac
+       flags=
+       test -n "$verbose" && flags="$flags$LF-v"
+       test -n "$force$single_force" && flags="$flags$LF-f"
+       GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
+               git-fetch--tool $flags append-fetch-head "$@"
 }
 
 # updating the current HEAD with git-fetch in a bare
@@ -283,7 +161,40 @@ then
        fi
 fi
 
-fetch_main () {
+fetch_all_at_once () {
+
+  eval=$(echo "$1" | git-fetch--tool parse-reflist "-")
+  eval "$eval"
+
+    ( : subshell because we muck with IFS
+      IFS="    $LF"
+      (
+       if test "$remote" = . ; then
+           git-show-ref $rref || echo failed "$remote"
+       elif test -f "$remote" ; then
+           test -n "$shallow_depth" &&
+               die "shallow clone with bundle is not supported"
+           git-bundle unbundle "$remote" $rref ||
+           echo failed "$remote"
+       else
+         git-fetch-pack --thin $exec $keep $shallow_depth \
+             $quiet $no_progress "$remote" $rref ||
+         echo failed "$remote"
+       fi
+      ) |
+      (
+       flags=
+       test -n "$verbose" && flags="$flags -v"
+       test -n "$force" && flags="$flags -f"
+       GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION" \
+               git-fetch--tool $flags native-store \
+                       "$remote" "$remote_nick" "$refs"
+      )
+    ) || exit
+
+}
+
+fetch_per_ref () {
   reflist="$1"
   refs=
   rref=
@@ -342,7 +253,7 @@ fetch_main () {
                die "No such ref $remote_name at $remote"
          echo >&2 "Fetching $remote_name from $remote using $proto"
          case "$quiet" in '') v=-v ;; *) v= ;; esac
-         git-http-fetch $v -a "$head" "$remote/" || exit
+         git-http-fetch $v -a "$head" "$remote" || exit
          ;;
       rsync://*)
          test -n "$shallow_depth" &&
@@ -377,9 +288,6 @@ fetch_main () {
              rsync_slurped_objects=t
          }
          ;;
-      *)
-         # We will do git native transport with just one call later.
-         continue ;;
       esac
 
       append_fetch_head "$head" "$remote" \
@@ -387,80 +295,17 @@ fetch_main () {
 
   done
 
-  case "$remote" in
-  http://* | https://* | ftp://* | rsync://* )
-      ;; # we are already done.
-  *)
-    ( : subshell because we muck with IFS
-      IFS="    $LF"
-      (
-       if test -f "$remote" ; then
-           test -n "$shallow_depth" &&
-               die "shallow clone with bundle is not supported"
-           git-bundle unbundle "$remote" $rref ||
-           echo failed "$remote"
-       else
-         git-fetch-pack --thin $exec $keep $shallow_depth \
-             $quiet $no_progress "$remote" $rref ||
-         echo failed "$remote"
-       fi
-      ) |
-      (
-       trap '
-               if test -n "$keepfile" && test -f "$keepfile"
-               then
-                       rm -f "$keepfile"
-               fi
-       ' 0
-
-        keepfile=
-       while read sha1 remote_name
-       do
-         case "$sha1" in
-         failed)
-                 echo >&2 "Fetch failure: $remote"
-                 exit 1 ;;
-         # special line coming from index-pack with the pack name
-         pack)
-                 continue ;;
-         keep)
-                 keepfile="$GIT_OBJECT_DIRECTORY/pack/pack-$remote_name.keep"
-                 continue ;;
-         esac
-         found=
-         single_force=
-         for ref in $refs
-         do
-             case "$ref" in
-             +$remote_name:*)
-                 single_force=t
-                 not_for_merge=
-                 found="$ref"
-                 break ;;
-             .+$remote_name:*)
-                 single_force=t
-                 not_for_merge=t
-                 found="$ref"
-                 break ;;
-             .$remote_name:*)
-                 not_for_merge=t
-                 found="$ref"
-                 break ;;
-             $remote_name:*)
-                 not_for_merge=
-                 found="$ref"
-                 break ;;
-             esac
-         done
-         local_name=$(expr "z$found" : 'z[^:]*:\(.*\)')
-         append_fetch_head "$sha1" "$remote" \
-                 "$remote_name" "$remote_nick" "$local_name" \
-                 "$not_for_merge" || exit
-        done
-      )
-    ) || exit ;;
-  esac
+}
 
+fetch_main () {
+       case "$remote" in
+       http://* | https://* | ftp://* | rsync://* )
+               fetch_per_ref "$@"
+               ;;
+       *)
+               fetch_all_at_once "$@"
+               ;;
+       esac
 }
 
 fetch_main "$reflist" || exit
diff --git a/git-gc.sh b/git-gc.sh
deleted file mode 100755 (executable)
index 436d7ca..0000000
--- a/git-gc.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2006, Shawn O. Pearce
-#
-# Cleanup unreachable files and optimize the repository.
-
-USAGE='[--prune]'
-SUBDIRECTORY_OK=Yes
-. git-sh-setup
-
-no_prune=:
-while case $# in 0) break ;; esac
-do
-       case "$1" in
-       --prune)
-               no_prune=
-               ;;
-       --)
-               usage
-               ;;
-       esac
-       shift
-done
-
-case "$(git config --get gc.packrefs)" in
-notbare|"")
-       test $(is_bare_repository) = true || pack_refs=true;;
-*)
-       pack_refs=$(git config --bool --get gc.packrefs)
-esac
-
-test "true" != "$pack_refs" ||
-git-pack-refs --prune &&
-git-reflog expire --all &&
-git-repack -a -d -l &&
-$no_prune git-prune &&
-git-rerere gc || exit
index 805ca2e1c7875fcc9c588dbee5041929c0e451d3..c714d382e87b5c18609f5934890c8b135a720262 100644 (file)
@@ -1,4 +1,3 @@
-CREDITS-FILE
 GIT-VERSION-FILE
 git-citool
 git-gui
diff --git a/git-gui/CREDITS-GEN b/git-gui/CREDITS-GEN
deleted file mode 100755 (executable)
index d1b0f86..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/bin/sh
-
-CF=CREDITS-FILE
-tip=
-
-tree_search ()
-{
-       head=$1
-       tree=$2
-       for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null)
-       do
-               test $tree = $(git rev-parse $p^{tree} 2>/dev/null) &&
-               vn=$(git describe --abbrev=4 $p 2>/dev/null) &&
-               case "$vn" in
-               gitgui-[0-9]*) echo $p; break;;
-               esac
-       done
-}
-
-generate_credits ()
-{
-       tip=$1 &&
-       rm -f "$2" &&
-       git shortlog -n -s $tip | sed 's/: .*$//' >"$2" || exit
-}
-
-# Always use the tarball credits file if found, just
-# in case we are somehow contained in a larger git
-# repository that doesn't actually track our state.
-# (At least one package manager is doing this.)
-#
-# We may be a subproject, so try looking for the merge
-# commit that supplied this directory content if we are
-# not at the toplevel.  We probably will always be the
-# second parent in the commit, but we shouldn't rely on
-# that fact.
-#
-
-credits_tmp=/var/tmp/gitgui-credits-$$
-trap 'rm -f "$credits_tmp"' 0
-
-orig="$credits_tmp"
-
-if test -f credits
-then
-       orig=credits
-elif prefix="$(git rev-parse --show-prefix 2>/dev/null)" &&
-   test -n "$prefix" &&
-   head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
-   tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
-   tip=$(tree_search $head $tree) &&
-   test -n "$tip"
-then
-       generate_credits $tip "$orig" || exit
-elif tip="$(git rev-parse --verify HEAD 2>/dev/null)" &&
-   test -n "$tip"
-then
-       generate_credits $tip "$orig" || exit
-else
-       echo "error: Cannot locate authorship information." >&2
-       exit 1
-fi
-
-if test -f "$orig" && cmp -s "$orig" "$CF"
-then
-       : noop
-else
-       rm -f "$CF" &&
-       cat "$orig" >"$CF"
-fi
-
index e486e8f9843ed48f06e667cfa5659e51e5a0e4d1..b82789ead6255b33be0f1ed2029a91611cea3072 100644 (file)
@@ -7,8 +7,9 @@ GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
 -include GIT-VERSION-FILE
 
+SCRIPT_SH = git-gui.sh
 GITGUI_BUILT_INS = git-citool
-ALL_PROGRAMS = git-gui $(GITGUI_BUILT_INS)
+ALL_PROGRAMS = $(GITGUI_BUILT_INS) $(patsubst %.sh,%,$(SCRIPT_SH))
 
 ifndef SHELL_PATH
        SHELL_PATH = /bin/sh
@@ -27,28 +28,29 @@ ifndef V
        QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
 endif
 
+ifeq ($(findstring $(MAKEFLAGS),s),s)
+QUIET_GEN =
+QUIET_BUILT_IN =
+endif
+
 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
 gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 
-git-gui: git-gui.sh GIT-VERSION-FILE CREDITS-FILE
+$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
        $(QUIET_GEN)rm -f $@ $@+ && \
-       sed -n \
-               -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
+       sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
                -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
-               -e '1,/^set gitgui_credits /p' \
                $@.sh >$@+ && \
-       cat CREDITS-FILE >>$@+ && \
-       sed -e '1,/^set gitgui_credits /d' $@.sh >>$@+ && \
        chmod +x $@+ && \
        mv $@+ $@
 
-CREDITS-FILE: CREDITS-GEN .FORCE-CREDITS-FILE
-       $(QUIET_GEN)$(SHELL_PATH) ./CREDITS-GEN
-
 $(GITGUI_BUILT_INS): git-gui
        $(QUIET_BUILT_IN)rm -f $@ && ln git-gui $@
 
+# These can record GITGUI_VERSION
+$(patsubst %.sh,%,$(SCRIPT_SH)): GIT-VERSION-FILE
+
 all:: $(ALL_PROGRAMS)
 
 install: all
@@ -56,14 +58,12 @@ install: all
        $(INSTALL) git-gui '$(DESTDIR_SQ)$(gitexecdir_SQ)'
        $(foreach p,$(GITGUI_BUILT_INS), rm -f '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' && ln '$(DESTDIR_SQ)$(gitexecdir_SQ)/git-gui' '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' ;)
 
-dist-version: CREDITS-FILE
+dist-version:
        @mkdir -p $(TARDIR)
        @echo $(GITGUI_VERSION) > $(TARDIR)/version
-       @cat CREDITS-FILE > $(TARDIR)/credits
 
 clean::
-       rm -f $(ALL_PROGRAMS) GIT-VERSION-FILE CREDITS-FILE
+       rm -f $(ALL_PROGRAMS) GIT-VERSION-FILE
 
 .PHONY: all install dist-version clean
 .PHONY: .FORCE-GIT-VERSION-FILE
-.PHONY: .FORCE-CREDITS-FILE
index 1981827a8e8bcc2b2e43598bb06e3e6c87bd4d1d..60e79ca1b01bc8b057abe17ddab484699a7f5fdb 100755 (executable)
@@ -19,9 +19,6 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA}
-set gitgui_credits {
-Paul Mackerras
-}
 
 ######################################################################
 ##
@@ -302,6 +299,11 @@ proc ask_popup {msg} {
 ##
 ## version check
 
+if {{--version} eq $argv || {version} eq $argv} {
+       puts "git-gui version $appvers"
+       exit
+}
+
 set req_maj 1
 set req_min 5
 
@@ -1171,7 +1173,7 @@ File [short_path $path] cannot be committed by this program.
                }
                }
        }
-       if {!$files_ready} {
+       if {!$files_ready && ![string match *merge $curType]} {
                info_popup {No changes to commit.
 
 You must add at least 1 file before you can commit.
@@ -4492,61 +4494,6 @@ proc do_commit {} {
        commit_tree
 }
 
-proc do_credits {} {
-       global gitgui_credits
-
-       set w .credits_dialog
-
-       toplevel $w
-       wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
-
-       label $w.header -text {git-gui Contributors} -font font_uibold
-       pack $w.header -side top -fill x
-
-       frame $w.buttons
-       button $w.buttons.close -text {Close} \
-               -font font_ui \
-               -command [list destroy $w]
-       pack $w.buttons.close -side right
-       pack $w.buttons -side bottom -fill x -pady 10 -padx 10
-
-       frame $w.credits
-       text $w.credits.t \
-               -background [$w.header cget -background] \
-               -yscrollcommand [list $w.credits.sby set] \
-               -width 20 \
-               -height 10 \
-               -wrap none \
-               -borderwidth 1 \
-               -relief solid \
-               -padx 5 -pady 5 \
-               -font font_ui
-       scrollbar $w.credits.sby -command [list $w.credits.t yview]
-       pack $w.credits.sby -side right -fill y
-       pack $w.credits.t -fill both -expand 1
-       pack $w.credits -side top -fill both -expand 1 -padx 5 -pady 5
-
-       label $w.desc \
-               -text "All portions are copyrighted by their respective authors
-and are distributed under the GNU General Public License." \
-               -padx 5 -pady 5 \
-               -justify left \
-               -anchor w \
-               -borderwidth 1 \
-               -relief solid \
-               -font font_ui
-       pack $w.desc -side top -fill x -padx 5 -pady 5
-
-       $w.credits.t insert end "[string trim $gitgui_credits]\n"
-       $w.credits.t conf -state disabled
-       $w.credits.t see 1.0
-
-       bind $w <Visibility> "grab $w; focus $w"
-       bind $w <Key-Escape> [list destroy $w]
-       wm title $w [$w.header cget -text]
-       tkwait window $w
-}
-
 proc do_about {} {
        global appvers copyright
        global tcl_patchLevel tk_patchLevel
@@ -4563,10 +4510,6 @@ proc do_about {} {
        button $w.buttons.close -text {Close} \
                -font font_ui \
                -command [list destroy $w]
-       button $w.buttons.credits -text {Contributors} \
-               -font font_ui \
-               -command do_credits
-       pack $w.buttons.credits -side left
        pack $w.buttons.close -side right
        pack $w.buttons -side bottom -fill x -pady 10 -padx 10
 
@@ -5116,8 +5059,6 @@ enable_option branch
 enable_option transport
 
 switch -- $subcommand {
---version -
-version -
 browser -
 blame {
        disable_option multicommit
@@ -5488,11 +5429,6 @@ bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
 # -- Not a normal commit type invocation?  Do that instead!
 #
 switch -- $subcommand {
---version -
-version {
-       puts "git-gui version $appvers"
-       exit
-}
 browser {
        if {[llength $argv] != 1} {
                puts stderr "usage: $argv0 browser commit"
index 9360804711d6b81983e53df67c86ddc8082e2ab4..58570dff137adfdeb72ebf3f088af7379eded522 100755 (executable)
@@ -12,7 +12,7 @@ fi
 laf="$GIT_DIR/lost-found"
 rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit
 
-git fsck --full |
+git fsck --full --no-reflogs |
 while read dangling type sha1
 do
        case "$dangling" in
index 4f3d053889de4a5ba8e6e5d519c014a51220accd..2b6a5c0d104b09b2eb471be9ec86e215ac003b0a 100755 (executable)
@@ -9,6 +9,6 @@
 # because the current index is what we will be committing as the
 # merge result.
 
-test "$(git-diff-index --cached --name-status HEAD)" = "" || exit 2
+git-diff-index --quiet --cached HEAD || exit 2
 
 exit 0
index 4afcd95316c01e5d1811184c615c4da574ab0717..fa4589173f426d6172883c47479c52b8700cafa8 100755 (executable)
@@ -108,6 +108,10 @@ merge_name () {
                git-show-ref -q --verify "refs/heads/$truname" 2>/dev/null
        then
                echo "$rh               branch '$truname' (early part) of ."
+       elif test "$remote" = "FETCH_HEAD" -a -r "$GIT_DIR/FETCH_HEAD"
+       then
+               sed -e 's/      not-for-merge   /               /' -e 1q \
+                       "$GIT_DIR/FETCH_HEAD"
        else
                echo "$rh               commit '$remote'"
        fi
@@ -292,9 +296,14 @@ f,*)
        # Again the most common case of merging one remote.
        echo "Updating $(git-rev-parse --short $head)..$(git-rev-parse --short $1)"
        git-update-index --refresh 2>/dev/null
+       msg="Fast forward"
+       if test -n "$have_message"
+       then
+               msg="$msg (no commit created; -m option ignored)"
+       fi
        new_head=$(git-rev-parse --verify "$1^0") &&
        git-read-tree -v -m -u --exclude-per-directory=.gitignore $head "$new_head" &&
-       finish "$new_head" "Fast forward" || exit
+       finish "$new_head" "$msg" || exit
        dropsave
        exit 0
        ;;
diff --git a/git-mergetool.sh b/git-mergetool.sh
new file mode 100755 (executable)
index 0000000..e62351b
--- /dev/null
@@ -0,0 +1,365 @@
+#!/bin/sh
+#
+# This program resolves merge conflicts in git
+#
+# Copyright (c) 2006 Theodore Y. Ts'o
+#
+# This file is licensed under the GPL v2, or a later version
+# at the discretion of Junio C Hammano.
+#
+
+USAGE='[--tool=tool] [file to merge] ...'
+SUBDIRECTORY_OK=Yes
+. git-sh-setup
+require_work_tree
+
+# Returns true if the mode reflects a symlink
+is_symlink () {
+    test "$1" = 120000
+}
+
+local_present () {
+    test -n "$local_mode"
+}
+
+remote_present () {
+    test -n "$remote_mode"
+}
+
+base_present () {
+    test -n "$base_mode"
+}
+
+cleanup_temp_files () {
+    if test "$1" = --save-backup ; then
+       mv -- "$BACKUP" "$path.orig"
+       rm -f -- "$LOCAL" "$REMOTE" "$BASE"
+    else
+       rm -f -- "$LOCAL" "$REMOTE" "$BASE" "$BACKUP"
+    fi
+}
+
+describe_file () {
+    mode="$1"
+    branch="$2"
+    file="$3"
+
+    printf "  {%s}: " "$branch"
+    if test -z "$mode"; then
+       echo "deleted"
+    elif is_symlink "$mode" ; then
+       echo "a symbolic link -> '$(cat "$file")'"
+    else
+       if base_present; then
+           echo "modified"
+       else
+           echo "created"
+       fi
+    fi
+}
+
+
+resolve_symlink_merge () {
+    while true; do
+       printf "Use (l)ocal or (r)emote, or (a)bort? "
+       read ans
+       case "$ans" in
+           [lL]*)
+               git-checkout-index -f --stage=2 -- "$path"
+               git-add -- "$path"
+               cleanup_temp_files --save-backup
+               return
+               ;;
+           [rR]*)
+               git-checkout-index -f --stage=3 -- "$path"
+               git-add -- "$path"
+               cleanup_temp_files --save-backup
+               return
+               ;;
+           [aA]*)
+               exit 1
+               ;;
+           esac
+       done
+}
+
+resolve_deleted_merge () {
+    while true; do
+       if base_present; then
+           printf "Use (m)odified or (d)eleted file, or (a)bort? "
+       else
+           printf "Use (c)reated or (d)eleted file, or (a)bort? "
+       fi
+       read ans
+       case "$ans" in
+           [mMcC]*)
+               git-add -- "$path"
+               cleanup_temp_files --save-backup
+               return
+               ;;
+           [dD]*)
+               git-rm -- "$path" > /dev/null
+               cleanup_temp_files
+               return
+               ;;
+           [aA]*)
+               exit 1
+               ;;
+           esac
+       done
+}
+
+check_unchanged () {
+    if test "$path" -nt "$BACKUP" ; then
+       status=0;
+    else
+       while true; do
+           echo "$path seems unchanged."
+           printf "Was the merge successful? [y/n] "
+           read answer < /dev/tty
+           case "$answer" in
+               y*|Y*) status=0; break ;;
+               n*|N*) status=1; break ;;
+           esac
+       done
+    fi
+}
+
+save_backup () {
+    if test "$status" -eq 0; then
+       mv -- "$BACKUP" "$path.orig"
+    fi
+}
+
+remove_backup () {
+    if test "$status" -eq 0; then
+       rm "$BACKUP"
+    fi
+}
+
+merge_file () {
+    path="$1"
+
+    f=`git-ls-files -u -- "$path"`
+    if test -z "$f" ; then
+       if test ! -f "$path" ; then
+           echo "$path: file not found"
+       else
+           echo "$path: file does not need merging"
+       fi
+       exit 1
+    fi
+
+    BACKUP="$path.BACKUP.$$"
+    LOCAL="$path.LOCAL.$$"
+    REMOTE="$path.REMOTE.$$"
+    BASE="$path.BASE.$$"
+
+    mv -- "$path" "$BACKUP"
+    cp -- "$BACKUP" "$path"
+
+    base_mode=`git ls-files -u -- "$path" | awk '{if ($3==1) print $1;}'`
+    local_mode=`git ls-files -u -- "$path" | awk '{if ($3==2) print $1;}'`
+    remote_mode=`git ls-files -u -- "$path" | awk '{if ($3==3) print $1;}'`
+
+    base_present   && git cat-file blob ":1:$path" > "$BASE" 2>/dev/null
+    local_present  && git cat-file blob ":2:$path" > "$LOCAL" 2>/dev/null
+    remote_present && git cat-file blob ":3:$path" > "$REMOTE" 2>/dev/null
+
+    if test -z "$local_mode" -o -z "$remote_mode"; then
+       echo "Deleted merge conflict for '$path':"
+       describe_file "$local_mode" "local" "$LOCAL"
+       describe_file "$remote_mode" "remote" "$REMOTE"
+       resolve_deleted_merge
+       return
+    fi
+
+    if is_symlink "$local_mode" || is_symlink "$remote_mode"; then
+       echo "Symbolic link merge conflict for '$path':"
+       describe_file "$local_mode" "local" "$LOCAL"
+       describe_file "$remote_mode" "remote" "$REMOTE"
+       resolve_symlink_merge
+       return
+    fi
+
+    echo "Normal merge conflict for '$path':"
+    describe_file "$local_mode" "local" "$LOCAL"
+    describe_file "$remote_mode" "remote" "$REMOTE"
+    printf "Hit return to start merge resolution tool (%s): " "$merge_tool"
+    read ans
+
+    case "$merge_tool" in
+       kdiff3)
+           if base_present ; then
+               (kdiff3 --auto --L1 "$path (Base)" -L2 "$path (Local)" --L3 "$path (Remote)" \
+                   -o "$path" -- "$BASE" "$LOCAL" "$REMOTE" > /dev/null 2>&1)
+           else
+               (kdiff3 --auto -L1 "$path (Local)" --L2 "$path (Remote)" \
+                   -o "$path" -- "$LOCAL" "$REMOTE" > /dev/null 2>&1)
+           fi
+           status=$?
+           remove_backup
+           ;;
+       tkdiff)
+           if base_present ; then
+               tkdiff -a "$BASE" -o "$path" -- "$LOCAL" "$REMOTE"
+           else
+               tkdiff -o "$path" -- "$LOCAL" "$REMOTE"
+           fi
+           status=$?
+           save_backup
+           ;;
+       meld|vimdiff)
+           touch "$BACKUP"
+           $merge_tool -- "$LOCAL" "$path" "$REMOTE"
+           check_unchanged
+           save_backup
+           ;;
+       xxdiff)
+           touch "$BACKUP"
+           if base_present ; then
+               xxdiff -X --show-merged-pane \
+                   -R 'Accel.SaveAsMerged: "Ctrl-S"' \
+                   -R 'Accel.Search: "Ctrl+F"' \
+                   -R 'Accel.SearchForward: "Ctrl-G"' \
+                   --merged-file "$path" -- "$LOCAL" "$BASE" "$REMOTE"
+           else
+               xxdiff -X --show-merged-pane \
+                   -R 'Accel.SaveAsMerged: "Ctrl-S"' \
+                   -R 'Accel.Search: "Ctrl+F"' \
+                   -R 'Accel.SearchForward: "Ctrl-G"' \
+                   --merged-file "$path" -- "$LOCAL" "$REMOTE"
+           fi
+           check_unchanged
+           save_backup
+           ;;
+       opendiff)
+           touch "$BACKUP"
+           if base_present; then
+               opendiff "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$path" | cat
+           else
+               opendiff "$LOCAL" "$REMOTE" -merge "$path" | cat
+           fi
+           check_unchanged
+           save_backup
+           ;;
+       emerge)
+           if base_present ; then
+               emacs -f emerge-files-with-ancestor-command "$LOCAL" "$REMOTE" "$BASE" "$path"
+           else
+               emacs -f emerge-files-command "$LOCAL" "$REMOTE" "$path"
+           fi
+           status=$?
+           save_backup
+           ;;
+    esac
+    if test "$status" -ne 0; then
+       echo "merge of $path failed" 1>&2
+       mv -- "$BACKUP" "$path"
+       exit 1
+    fi
+    git add -- "$path"
+    cleanup_temp_files
+}
+
+while case $# in 0) break ;; esac
+do
+    case "$1" in
+       -t|--tool*)
+           case "$#,$1" in
+               *,*=*)
+                   merge_tool=`expr "z$1" : 'z-[^=]*=\(.*\)'`
+                   ;;
+               1,*)
+                   usage ;;
+               *)
+                   merge_tool="$2"
+                   shift ;;
+           esac
+           ;;
+       --)
+           break
+           ;;
+       -*)
+           usage
+           ;;
+       *)
+           break
+           ;;
+    esac
+    shift
+done
+
+if test -z "$merge_tool"; then
+    merge_tool=`git-config merge.tool`
+    case "$merge_tool" in
+       kdiff3 | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | "")
+           ;; # happy
+       *)
+           echo >&2 "git config option merge.tool set to unknown tool: $merge_tool"
+           echo >&2 "Resetting to default..."
+           unset merge_tool
+           ;;
+    esac
+fi
+
+if test -z "$merge_tool" ; then
+    if type kdiff3 >/dev/null 2>&1 && test -n "$DISPLAY"; then
+       merge_tool="kdiff3";
+    elif type tkdiff >/dev/null 2>&1 && test -n "$DISPLAY"; then
+       merge_tool=tkdiff
+    elif type xxdiff >/dev/null 2>&1 && test -n "$DISPLAY"; then
+       merge_tool=xxdiff
+    elif type meld >/dev/null 2>&1 && test -n "$DISPLAY"; then
+       merge_tool=meld
+    elif type opendiff >/dev/null 2>&1; then
+       merge_tool=opendiff
+    elif type emacs >/dev/null 2>&1; then
+       merge_tool=emerge
+    elif type vimdiff >/dev/null 2>&1; then
+       merge_tool=vimdiff
+    else
+       echo "No available merge resolution programs available."
+       exit 1
+    fi
+fi
+
+case "$merge_tool" in
+    kdiff3|tkdiff|meld|xxdiff|vimdiff|opendiff)
+       if ! type "$merge_tool" > /dev/null 2>&1; then
+           echo "The merge tool $merge_tool is not available"
+           exit 1
+       fi
+       ;;
+    emerge)
+       if ! type "emacs" > /dev/null 2>&1; then
+           echo "Emacs is not available"
+           exit 1
+       fi
+       ;;
+    *)
+       echo "Unknown merge tool: $merge_tool"
+       exit 1
+       ;;
+esac
+
+if test $# -eq 0 ; then
+       files=`git ls-files -u | sed -e 's/^[^  ]*      //' | sort -u`
+       if test -z "$files" ; then
+               echo "No files need merging"
+               exit 0
+       fi
+       echo Merging the files: $files
+       git ls-files -u | sed -e 's/^[^ ]*      //' | sort -u | while read i
+       do
+               printf "\n"
+               merge_file "$i" < /dev/tty > /dev/tty
+       done
+else
+       while test $# -gt 0; do
+               printf "\n"
+               merge_file "$1"
+               shift
+       done
+fi
+exit 0
index 5208ee6ce0bb07dd22ad5ca63ee469cb03011164..437b0c3b1bc522c4b5a4a3a656b97cb2009c43a0 100755 (executable)
@@ -9,6 +9,9 @@ get_data_source () {
        */*)
                echo ''
                ;;
+       .)
+               echo self
+               ;;
        *)
                if test "$(git-config --get "remote.$1.url")"
                then
@@ -31,6 +34,9 @@ get_remote_url () {
        '')
                echo "$1"
                ;;
+       self)
+               echo "$1"
+               ;;
        config)
                git-config --get "remote.$1.url"
                ;;
@@ -57,7 +63,7 @@ get_default_remote () {
 get_remote_default_refs_for_push () {
        data_source=$(get_data_source "$1")
        case "$data_source" in
-       '' | branches)
+       '' | branches | self)
                ;; # no default push mapping, just send matching refs.
        config)
                git-config --get-all "remote.$1.push" ;;
@@ -81,51 +87,8 @@ get_remote_default_refs_for_push () {
 # is to help prevent randomly "globbed" ref from being chosen as
 # a merge candidate
 expand_refs_wildcard () {
-       remote="$1"
-       shift
-       first_one=yes
-       if test "$#" = 0
-       then
-               echo empty
-               echo >&2 "Nothing specified for fetching with remote.$remote.fetch"
-       fi
-       for ref
-       do
-               lref=${ref#'+'}
-               # a non glob pattern is given back as-is.
-               expr "z$lref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev/null || {
-                       if test -n "$first_one"
-                       then
-                               echo "explicit"
-                               first_one=
-                       fi
-                       echo "$ref"
-                       continue
-               }
-
-               # glob
-               if test -n "$first_one"
-               then
-                       echo "glob"
-                       first_one=
-               fi
-               from=`expr "z$lref" : 'z\(refs/.*/\)\*:refs/.*/\*$'`
-               to=`expr "z$lref" : 'zrefs/.*/\*:\(refs/.*/\)\*$'`
-               local_force=
-               test "z$lref" = "z$ref" || local_force='+'
-               echo "$ls_remote_result" |
-               sed -e '/\^{}$/d' |
-               (
-                       IFS='   '
-                       while read sha1 name
-                       do
-                               # ignore the ones that do not start with $from
-                               mapped=${name#"$from"}
-                               test "z$name" = "z$mapped" && continue
-                               echo "${local_force}${name}:${to}${mapped}"
-                       done
-               )
-       done
+       echo "$ls_remote_result" |
+       git fetch--tool expand-refs-wildcard "-" "$@"
 }
 
 # Subroutine to canonicalize remote:local notation.
@@ -206,6 +169,10 @@ get_remote_default_refs_for_fetch () {
        case "$data_source" in
        '')
                echo "HEAD:" ;;
+       self)
+               canon_refs_list_for_fetch -d "$1" \
+                       $(git-for-each-ref --format='%(refname):')
+               ;;
        config)
                canon_refs_list_for_fetch -d "$1" \
                        $(git-config --get-all "remote.$1.fetch") ;;
@@ -220,7 +187,7 @@ get_remote_default_refs_for_fetch () {
                                        }' "$GIT_DIR/remotes/$1")
                ;;
        *)
-               die "internal error: get-remote-default-ref-for-push $1" ;;
+               die "internal error: get-remote-default-ref-for-fetch $1" ;;
        esac
 }
 
index 671a5ff865b6ab891da4251ee3dd90892b13cbad..edccd827553d04dde89f210bbb5128ccc09eff3d 100755 (executable)
@@ -73,6 +73,10 @@ mkdir $tmp_dir || exit 2
 for patch_name in $(cat "$QUILT_PATCHES/series" | grep -v '^#'); do
        echo $patch_name
        (cat $QUILT_PATCHES/$patch_name | git-mailinfo "$tmp_msg" "$tmp_patch" > "$tmp_info") || exit 3
+       test -s $dotest/patch || {
+               echo "Patch is empty.  Was is split wrong?"
+               stop_here $this
+       }
 
        # Parse the author information
        export GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info")
@@ -111,7 +115,7 @@ for patch_name in $(cat "$QUILT_PATCHES/series" | grep -v '^#'); do
        if [ -z "$dry_run" ] ; then
                git-apply --index -C1 "$tmp_patch" &&
                tree=$(git-write-tree) &&
-               commit=$((echo "$SUBJECT"; echo; cat "$tmp_msg") | git-commit-tree $tree -p $commit) &&
+               commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git-commit-tree $tree -p $commit) &&
                git-update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4
        fi
 done
index b51d19d12e6d5a108f13c4ec60c5f5a6e560ef47..1d96f32685cdc51c89c63516519e8b544ab818af 100755 (executable)
@@ -59,7 +59,7 @@ continue_merge () {
                die "$RESOLVEMSG"
        fi
 
-       if test -n "`git-diff-index HEAD`"
+       if ! git-diff-index --quiet HEAD
        then
                if ! git-commit -C "`cat $dotest/current`"
                then
@@ -124,13 +124,11 @@ while case "$#" in 0) break ;; esac
 do
        case "$1" in
        --continue)
-               diff=$(git-diff-files)
-               case "$diff" in
-               ?*)     echo "You must edit all merge conflicts and then"
+               git-diff-files --quiet || {
+                       echo "You must edit all merge conflicts and then"
                        echo "mark them as resolved using git update-index"
                        exit 1
-                       ;;
-               esac
+               }
                if test -d "$dotest"
                then
                        prev_head="`cat $dotest/prev_head`"
@@ -265,6 +263,10 @@ upstream_name="$1"
 upstream=`git rev-parse --verify "${upstream_name}^0"` ||
     die "invalid upstream $upstream_name"
 
+# Make sure the branch to rebase onto is valid.
+onto_name=${newbase-"$upstream_name"}
+onto=$(git-rev-parse --verify "${onto_name}^0") || exit
+
 # If a hook exists, give it a chance to interrupt
 if test -x "$GIT_DIR/hooks/pre-rebase"
 then
@@ -291,10 +293,6 @@ case "$#" in
 esac
 branch=$(git-rev-parse --verify "${branch_name}^0") || exit
 
-# Make sure the branch to rebase onto is valid.
-onto_name=${newbase-"$upstream_name"}
-onto=$(git-rev-parse --verify "${onto_name}^0") || exit
-
 # Now we are rebasing commits $upstream..$branch on top of $onto
 
 # Check if we are already based on $onto, but this should be
index bd70bf1ddd663db7d0af49b8513fdf234767e422..52013fe76dba73e19244fadf63f91677ce8e6a40 100755 (executable)
@@ -15,6 +15,10 @@ sub add_remote_config {
                $hash->{$name}{'FETCH'} ||= [];
                push @{$hash->{$name}{'FETCH'}}, $value;
        }
+       elsif ($what eq 'push') {
+               $hash->{$name}{'PUSH'} ||= [];
+               push @{$hash->{$name}{'PUSH'}}, $value;
+       }
        if (!exists $hash->{$name}{'SOURCE'}) {
                $hash->{$name}{'SOURCE'} = 'config';
        }
@@ -44,7 +48,8 @@ sub add_remote_remotes {
                        }
                }
                elsif (/^Push:\s*(.*)$/) {
-                       ; # later
+                       $it->{'PUSH'} ||= [];
+                       push @{$it->{'PUSH'}}, $1;
                }
                elsif (/^Pull:\s*(.*)$/) {
                        $it->{'FETCH'} ||= [];
@@ -250,6 +255,15 @@ sub show_remote {
        if ($info->{'LS_REMOTE'}) {
                show_mapping($name, $info);
        }
+       if ($info->{'PUSH'}) {
+               my @pushed = map {
+                       s|^refs/heads/||;
+                       s|:refs/heads/|:|;
+                       $_;
+               } @{$info->{'PUSH'}};
+               print "  Local branch(es) pushed with 'git push'\n";
+               print "    @pushed\n";
+       }
 }
 
 sub add_remote {
diff --git a/git-revert.sh b/git-revert.sh
deleted file mode 100755 (executable)
index 49f0032..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2005 Linus Torvalds
-# Copyright (c) 2005 Junio C Hamano
-#
-
-case "$0" in
-*-revert* )
-       test -t 0 && edit=-e
-       replay=
-       me=revert
-       USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
-*-cherry-pick* )
-       replay=t
-       edit=
-       me=cherry-pick
-       USAGE='[--edit] [-n] [-r] [-x] <commit-ish>'  ;;
-* )
-       echo >&2 "What are you talking about?"
-       exit 1 ;;
-esac
-
-SUBDIRECTORY_OK=Yes ;# we will cd up
-. git-sh-setup
-require_work_tree
-cd_to_toplevel
-
-no_commit=
-while case "$#" in 0) break ;; esac
-do
-       case "$1" in
-       -n|--n|--no|--no-|--no-c|--no-co|--no-com|--no-comm|\
-           --no-commi|--no-commit)
-               no_commit=t
-               ;;
-       -e|--e|--ed|--edi|--edit)
-               edit=-e
-               ;;
-       --n|--no|--no-|--no-e|--no-ed|--no-edi|--no-edit)
-               edit=
-               ;;
-       -r)
-               : no-op ;;
-       -x|--i-really-want-to-expose-my-private-commit-object-name)
-               replay=
-               ;;
-       -*)
-               usage
-               ;;
-       *)
-               break
-               ;;
-       esac
-       shift
-done
-
-set_reflog_action "$me"
-
-test "$me,$replay" = "revert,t" && usage
-
-case "$no_commit" in
-t)
-       # We do not intend to commit immediately.  We just want to
-       # merge the differences in.
-       head=$(git-write-tree) ||
-               die "Your index file is unmerged."
-       ;;
-*)
-       head=$(git-rev-parse --verify HEAD) ||
-               die "You do not have a valid HEAD"
-       files=$(git-diff-index --cached --name-only $head) || exit
-       if [ "$files" ]; then
-               die "Dirty index: cannot $me (dirty: $files)"
-       fi
-       ;;
-esac
-
-rev=$(git-rev-parse --verify "$@") &&
-commit=$(git-rev-parse --verify "$rev^0") ||
-       die "Not a single commit $@"
-prev=$(git-rev-parse --verify "$commit^1" 2>/dev/null) ||
-       die "Cannot run $me a root commit"
-git-rev-parse --verify "$commit^2" >/dev/null 2>&1 &&
-       die "Cannot run $me a multi-parent commit."
-
-encoding=$(git config i18n.commitencoding || echo UTF-8)
-
-# "commit" is an existing commit.  We would want to apply
-# the difference it introduces since its first parent "prev"
-# on top of the current HEAD if we are cherry-pick.  Or the
-# reverse of it if we are revert.
-
-case "$me" in
-revert)
-       git show -s --pretty=oneline --encoding="$encoding" $commit |
-       sed -e '
-               s/^[^ ]* /Revert "/
-               s/$/"/
-       '
-       echo
-       echo "This reverts commit $commit."
-       test "$rev" = "$commit" ||
-       echo "(original 'git revert' arguments: $@)"
-       base=$commit next=$prev
-       ;;
-
-cherry-pick)
-       pick_author_script='
-       /^author /{
-               s/'\''/'\''\\'\'\''/g
-               h
-               s/^author \([^<]*\) <[^>]*> .*$/\1/
-               s/'\''/'\''\'\'\''/g
-               s/.*/GIT_AUTHOR_NAME='\''&'\''/p
-
-               g
-               s/^author [^<]* <\([^>]*\)> .*$/\1/
-               s/'\''/'\''\'\'\''/g
-               s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
-
-               g
-               s/^author [^<]* <[^>]*> \(.*\)$/\1/
-               s/'\''/'\''\'\'\''/g
-               s/.*/GIT_AUTHOR_DATE='\''&'\''/p
-
-               q
-       }'
-
-       logmsg=`git show -s --pretty=raw --encoding="$encoding" "$commit"`
-       set_author_env=`echo "$logmsg" |
-       LANG=C LC_ALL=C sed -ne "$pick_author_script"`
-       eval "$set_author_env"
-       export GIT_AUTHOR_NAME
-       export GIT_AUTHOR_EMAIL
-       export GIT_AUTHOR_DATE
-
-       echo "$logmsg" |
-       sed -e '1,/^$/d' -e 's/^    //'
-       case "$replay" in
-       '')
-               echo "(cherry picked from commit $commit)"
-               test "$rev" = "$commit" ||
-               echo "(original 'git cherry-pick' arguments: $@)"
-               ;;
-       esac
-       base=$prev next=$commit
-       ;;
-
-esac >.msg
-
-eval GITHEAD_$head=HEAD
-eval GITHEAD_$next='`git show -s \
-       --pretty=oneline --encoding="$encoding" "$commit" |
-       sed -e "s/^[^ ]* //"`'
-export GITHEAD_$head GITHEAD_$next
-
-# This three way merge is an interesting one.  We are at
-# $head, and would want to apply the change between $commit
-# and $prev on top of us (when reverting), or the change between
-# $prev and $commit on top of us (when cherry-picking or replaying).
-
-git-merge-recursive $base -- $head $next &&
-result=$(git-write-tree 2>/dev/null) || {
-       mv -f .msg "$GIT_DIR/MERGE_MSG"
-       {
-           echo '
-Conflicts:
-'
-               git ls-files --unmerged |
-               sed -e 's/^[^   ]*      /       /' |
-               uniq
-       } >>"$GIT_DIR/MERGE_MSG"
-       echo >&2 "Automatic $me failed.  After resolving the conflicts,"
-       echo >&2 "mark the corrected paths with 'git-add <paths>'"
-       echo >&2 "and commit the result."
-       case "$me" in
-       cherry-pick)
-               echo >&2 "You may choose to use the following when making"
-               echo >&2 "the commit:"
-               echo >&2 "$set_author_env"
-       esac
-       exit 1
-}
-echo >&2 "Finished one $me."
-
-# If we are cherry-pick, and if the merge did not result in
-# hand-editing, we will hit this commit and inherit the original
-# author date and name.
-# If we are revert, or if our cherry-pick results in a hand merge,
-# we had better say that the current user is responsible for that.
-
-case "$no_commit" in
-'')
-       git-commit -n -F .msg $edit
-       rm -f .msg
-       ;;
-esac
index a71a192e4d752b7d79493321df5f82fbdd682dc7..1278fcba462f632a3687742f74cc15c0498874e2 100755 (executable)
@@ -65,8 +65,8 @@ Options:
                   Defaults to on.
 
    --no-signed-off-cc Suppress the automatic addition of email addresses
-                 that appear in a Signed-off-by: line, to the cc: list.
-                Note: Using this option is not recommended.
+                 that appear in Signed-off-by: or Cc: lines to the cc:
+                 list.  Note: Using this option is not recommended.
 
    --smtp-server  If set, specifies the outgoing SMTP server to use.
                   Defaults to localhost.
@@ -149,6 +149,16 @@ if ($@) {
        $term = new FakeTerm "$@: going non-interactive";
 }
 
+my $def_chain = $repo->config_boolean('sendemail.chainreplyto');
+if ($def_chain and $def_chain eq 'false') {
+    $chain_reply_to = 0;
+}
+
+@bcclist = $repo->config('sendemail.bcc');
+if (!@bcclist or !$bcclist[0]) {
+    @bcclist = ();
+}
+
 # Begin by accumulating all the variables (defined above), that we will end up
 # needing, first, from the command line:
 
@@ -562,8 +572,8 @@ foreach my $t (@files) {
                        }
                } else {
                        $message .=  $_;
-                       if (/^Signed-off-by: (.*)$/i && !$no_signed_off_cc) {
-                               my $c = $1;
+                       if (/^(Signed-off-by|Cc): (.*)$/i && !$no_signed_off_cc) {
+                               my $c = $2;
                                chomp $c;
                                push @cc, $c;
                                printf("(sob) Adding cc: %s from line '%s'\n",
@@ -585,7 +595,7 @@ foreach my $t (@files) {
        if ($chain_reply_to || !defined $reply_to || length($reply_to) == 0) {
                $reply_to = $message_id;
                if (length $references > 0) {
-                       $references .= " $message_id";
+                       $references .= "\n $message_id";
                } else {
                        $references = "$message_id";
                }
index 326e89fe037561c1ad72d91c7783bf2a0f603826..ac44f60b81412753248c78fbe73fe7f6a212b6df 100755 (executable)
@@ -33,7 +33,7 @@ use Carp qw/croak/;
 use IO::File qw//;
 use File::Basename qw/dirname basename/;
 use File::Path qw/mkpath/;
-use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev pass_through/;
+use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
 use IPC::Open3;
 use Git;
 
@@ -56,7 +56,7 @@ my ($_stdin, $_help, $_edit,
        $_message, $_file,
        $_template, $_shared,
        $_version, $_fetch_all,
-       $_merge, $_strategy, $_dry_run,
+       $_merge, $_strategy, $_dry_run, $_local,
        $_prefix, $_no_checkout, $_verbose);
 $Git::SVN::_follow_parent = 1;
 my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
@@ -145,6 +145,7 @@ my %cmd = (
                        { 'merge|m|M' => \$_merge,
                          'verbose|v' => \$_verbose,
                          'strategy|s=s' => \$_strategy,
+                         'local|l' => \$_local,
                          'fetch-all|all' => \$_fetch_all,
                          %fc_opts } ],
        'commit-diff' => [ \&cmd_commit_diff,
@@ -167,6 +168,7 @@ for (my $i = 0; $i < @ARGV; $i++) {
 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
 
 read_repo_config(\%opts);
+Getopt::Long::Configure('pass_through') if $cmd eq 'log';
 my $rv = GetOptions(%opts, 'help|H|h' => \$_help, 'version|V' => \$_version,
                     'minimize-connections' => \$Git::SVN::Migration::_minimize,
                     'id|i=s' => \$Git::SVN::default_ref_id,
@@ -228,6 +230,8 @@ Usage: $0 <command> [options] [arguments]\n
                next if /^multi-/; # don't show deprecated commands
                print $fd '  ',pack('A17',$_),$cmd{$_}->[1],"\n";
                foreach (keys %{$cmd{$_}->[2]}) {
+                       # mixed-case options are for .git/config only
+                       next if /[A-Z]/ && /^[a-z]+$/i;
                        # prints out arguments as they should be passed:
                        my $x = s#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
                        print $fd ' ' x 21, join(', ', map { length $_ > 1 ?
@@ -359,13 +363,12 @@ sub cmd_dcommit {
        my $head = shift;
        $head ||= 'HEAD';
        my @refs;
-       my ($url, $rev, $uuid) = working_head_info($head, \@refs);
-       my $c = $refs[-1];
-       unless (defined $url && defined $rev && defined $uuid) {
+       my ($url, $rev, $uuid, $gs) = working_head_info($head, \@refs);
+       unless ($gs) {
                die "Unable to determine upstream SVN information from ",
                    "$head history\n";
        }
-       my $gs = Git::SVN->find_by_url($url);
+       my $c = $refs[-1];
        my $last_rev;
        foreach my $d (@refs) {
                if (!verify_ref("$d~1")) {
@@ -427,25 +430,25 @@ sub cmd_dcommit {
 
 sub cmd_rebase {
        command_noisy(qw/update-index --refresh/);
-       my $url = (working_head_info('HEAD'))[0];
-       if (!defined $url) {
+       my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
+       unless ($gs) {
                die "Unable to determine upstream SVN information from ",
                    "working tree history\n";
        }
-
-       my $gs = Git::SVN->find_by_url($url);
        if (command(qw/diff-index HEAD --/)) {
                print STDERR "Cannot rebase with uncommited changes:\n";
                command_noisy('status');
                exit 1;
        }
-       $_fetch_all ? $gs->fetch_all : $gs->fetch;
+       unless ($_local) {
+               $_fetch_all ? $gs->fetch_all : $gs->fetch;
+       }
        command_noisy(rebase_cmd(), $gs->refname);
 }
 
 sub cmd_show_ignore {
-       my $url = (::working_head_info('HEAD'))[0];
-       my $gs = Git::SVN->find_by_url($url) || Git::SVN->new;
+       my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
+       $gs ||= Git::SVN->new;
        my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
        $gs->traverse_ignore(\*STDOUT, $gs->{path}, $r);
 }
@@ -767,16 +770,23 @@ sub cmt_metadata {
 
 sub working_head_info {
        my ($head, $refs) = @_;
-       my ($url, $rev, $uuid);
        my ($fh, $ctx) = command_output_pipe('rev-list', $head);
        while (<$fh>) {
                chomp;
-               ($url, $rev, $uuid) = cmt_metadata($_);
-               last if (defined $url && defined $rev && defined $uuid);
+               my ($url, $rev, $uuid) = cmt_metadata($_);
+               if (defined $url && defined $rev) {
+                       if (my $gs = Git::SVN->find_by_url($url)) {
+                               my $c = $gs->rev_db_get($rev);
+                               if ($c && $c eq $_) {
+                                       close $fh; # break the pipe
+                                       return ($url, $rev, $uuid, $gs);
+                               }
+                       }
+               }
                unshift @$refs, $_ if $refs;
        }
-       close $fh; # break the pipe
-       ($url, $rev, $uuid);
+       command_close_pipe($fh, $ctx);
+       (undef, undef, undef, undef);
 }
 
 package Git::SVN;
@@ -1324,8 +1334,10 @@ sub rel_path {
        my ($self) = @_;
        my $repos_root = $self->ra->{repos_root};
        return $self->{path} if ($self->{url} eq $repos_root);
-       die "BUG: rel_path failed! repos_root: $repos_root, Ra URL: ",
-           $self->ra->{url}, " path: $self->{path},  URL: $self->{url}\n";
+       my $url = $self->{url} .
+                 (length $self->{path} ? "/$self->{path}" : $self->{path});
+       $url =~ s!^\Q$repos_root\E(?:/+|$)!!g;
+       $url;
 }
 
 sub traverse_ignore {
@@ -2835,8 +2847,7 @@ package Git::SVN::Ra;
 use vars qw/@ISA $config_dir $_log_window_size/;
 use strict;
 use warnings;
-my ($can_do_switch);
-my $RA;
+my ($can_do_switch, %ignored_err, $RA);
 
 BEGIN {
        # enforce temporary pool usage for some simple functions
@@ -3208,9 +3219,16 @@ sub skip_unknown_revs {
        # 175007 - http(s):// (this repo required authorization, too...)
        #   More codes may be discovered later...
        if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
-               warn "W: Ignoring error from SVN, path probably ",
-                    "does not exist: ($errno): ",
-                    $err->expanded_message,"\n";
+               my $err_key = $err->expanded_message;
+               # revision numbers change every time, filter them out
+               $err_key =~ s/\d+/\0/g;
+               $err_key = "$errno\0$err_key";
+               unless ($ignored_err{$err_key}) {
+                       warn "W: Ignoring error from SVN, path probably ",
+                            "does not exist: ($errno): ",
+                            $err->expanded_message,"\n";
+                       $ignored_err{$err_key} = 1;
+               }
                return;
        }
        die "Error from SVN, ($errno): ", $err->expanded_message,"\n";
@@ -3245,12 +3263,19 @@ my $l_fmt;
 sub cmt_showable {
        my ($c) = @_;
        return 1 if defined $c->{r};
+
+       # big commit message got truncated by the 16k pretty buffer in rev-list
        if ($c->{l} && $c->{l}->[-1] eq "...\n" &&
                                $c->{a_raw} =~ /\@([a-f\d\-]+)>$/) {
+               @{$c->{l}} = ();
                my @log = command(qw/cat-file commit/, $c->{c});
-               shift @log while ($log[0] ne "\n");
+
+               # shift off the headers
+               shift @log while ($log[0] ne '');
                shift @log;
-               @{$c->{l}} = grep !/^git-svn-id: /, @log;
+
+               # TODO: make $c->{l} not have a trailing newline in the future
+               @{$c->{l}} = map { "$_\n" } grep !/^git-svn-id: /, @log;
 
                (undef, $c->{r}, undef) = ::extract_metadata(
                                (grep(/^git-svn-id: /, @log))[-1]);
@@ -3304,8 +3329,8 @@ sub git_svn_log_cmd {
                last;
        }
 
-       my $url = (::working_head_info($head))[0];
-       my $gs = Git::SVN->find_by_url($url) || Git::SVN->_new;
+       my ($url, $rev, $uuid, $gs) = ::working_head_info($head);
+       $gs ||= Git::SVN->_new;
        my @cmd = (qw/log --abbrev-commit --pretty=raw --default/,
                   $gs->refname);
        push @cmd, '-r' unless $non_recursive;
diff --git a/git.c b/git.c
index 04fc99a3dd9666bb4c22c99754334aeecc08bab5..33dd4d39d907a229679a41f9712ee99007a34f3b 100644 (file)
--- a/git.c
+++ b/git.c
@@ -99,7 +99,7 @@ static int split_cmdline(char *cmdline, const char ***argv)
        int src, dst, count = 0, size = 16;
        char quoted = 0;
 
-       *argv = malloc(sizeof(char*) * size);
+       *argv = xmalloc(sizeof(char*) * size);
 
        /* split alias_string */
        (*argv)[count++] = cmdline;
@@ -226,7 +226,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "add", cmd_add, RUN_SETUP | NOT_BARE },
                { "annotate", cmd_annotate, USE_PAGER },
                { "apply", cmd_apply },
-               { "archive", cmd_archive, RUN_SETUP },
+               { "archive", cmd_archive },
                { "blame", cmd_blame, RUN_SETUP },
                { "branch", cmd_branch, RUN_SETUP },
                { "bundle", cmd_bundle },
@@ -234,6 +234,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "checkout-index", cmd_checkout_index, RUN_SETUP },
                { "check-ref-format", cmd_check_ref_format },
                { "cherry", cmd_cherry, RUN_SETUP },
+               { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NOT_BARE },
                { "commit-tree", cmd_commit_tree, RUN_SETUP },
                { "config", cmd_config },
                { "count-objects", cmd_count_objects, RUN_SETUP },
@@ -242,11 +243,13 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "diff-files", cmd_diff_files },
                { "diff-index", cmd_diff_index, RUN_SETUP },
                { "diff-tree", cmd_diff_tree, RUN_SETUP },
+               { "fetch--tool", cmd_fetch__tool, RUN_SETUP },
                { "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP },
                { "for-each-ref", cmd_for_each_ref, RUN_SETUP },
                { "format-patch", cmd_format_patch, RUN_SETUP },
                { "fsck", cmd_fsck, RUN_SETUP },
                { "fsck-objects", cmd_fsck, RUN_SETUP },
+               { "gc", cmd_gc, RUN_SETUP },
                { "get-tar-commit-id", cmd_get_tar_commit_id },
                { "grep", cmd_grep, RUN_SETUP | USE_PAGER },
                { "help", cmd_help },
@@ -272,6 +275,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "rerere", cmd_rerere, RUN_SETUP },
                { "rev-list", cmd_rev_list, RUN_SETUP },
                { "rev-parse", cmd_rev_parse, RUN_SETUP },
+               { "revert", cmd_revert, RUN_SETUP | NOT_BARE },
                { "rm", cmd_rm, RUN_SETUP | NOT_BARE },
                { "runstatus", cmd_runstatus, RUN_SETUP | NOT_BARE },
                { "shortlog", cmd_shortlog, RUN_SETUP | USE_PAGER },
index 46aee88fd15d934dd84783981f2be3ed086c9cf3..f0746ed78c79739885ca9c32af27d3ee9ed4a974 100644 (file)
@@ -1,4 +1,7 @@
 # Pass --without docs to rpmbuild if you don't want the documentation
+
+%define python_path /usr/bin/python
+
 Name:          git
 Version:       @@VERSION@@
 Release:       1%{?dist}
@@ -9,7 +12,7 @@ URL:           http://kernel.org/pub/software/scm/git/
 Source:        http://kernel.org/pub/software/scm/git/%{name}-%{version}.tar.gz
 BuildRequires: zlib-devel >= 1.2, openssl-devel, curl-devel, expat-devel  %{!?_without_docs:, xmlto, asciidoc > 6.0.3}
 BuildRoot:     %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-Requires:      git-core, git-svn, git-cvs, git-arch, git-email, gitk, git-gui, perl-Git
+Requires:      git-core, git-svn, git-cvs, git-arch, git-email, gitk, git-gui, git-p4, perl-Git
 
 %description
 Git is a fast, scalable, distributed revision control system with an
@@ -50,6 +53,13 @@ Requires:       git-core = %{version}-%{release}, tla
 %description arch
 Git tools for importing Arch repositories.
 
+%package p4
+Summary:        Git tools for importing Perforce repositories
+Group:          Development/Tools
+Requires:       git-core = %{version}-%{release}, python
+%description p4
+Git tools for importing Perforce repositories.
+
 %package email
 Summary:        Git tools for sending email
 Group:          Development/Tools
@@ -85,23 +95,23 @@ Perl interface to Git
 %setup -q
 
 %build
-make %{_smp_mflags} CFLAGS="$RPM_OPT_FLAGS" WITH_OWN_SUBPROCESS_PY=YesPlease \
-     prefix=%{_prefix} all %{!?_without_docs: doc}
+make %{_smp_mflags} CFLAGS="$RPM_OPT_FLAGS" WITH_P4IMPORT=YesPlease \
+     prefix=%{_prefix} PYTHON_PATH=%{python_path} all %{!?_without_docs: doc}
 
 %install
 rm -rf $RPM_BUILD_ROOT
 make %{_smp_mflags} CFLAGS="$RPM_OPT_FLAGS" DESTDIR=$RPM_BUILD_ROOT \
-     WITH_OWN_SUBPROCESS_PY=YesPlease \
-     prefix=%{_prefix} mandir=%{_mandir} INSTALLDIRS=vendor \
-     install %{!?_without_docs: install-doc}
+     WITH_P4IMPORT=YesPlease prefix=%{_prefix} mandir=%{_mandir} \
+     PYTHON_PATH=%{python_path} \
+     INSTALLDIRS=vendor install %{!?_without_docs: install-doc}
 find $RPM_BUILD_ROOT -type f -name .packlist -exec rm -f {} ';'
 find $RPM_BUILD_ROOT -type f -name '*.bs' -empty -exec rm -f {} ';'
 find $RPM_BUILD_ROOT -type f -name perllocal.pod -exec rm -f {} ';'
 
-(find $RPM_BUILD_ROOT%{_bindir} -type f | grep -vE "archimport|svn|cvs|email|gitk|git-gui|git-citool" | sed -e s@^$RPM_BUILD_ROOT@@)               > bin-man-doc-files
+(find $RPM_BUILD_ROOT%{_bindir} -type f | grep -vE "p4import|archimport|svn|cvs|email|gitk|git-gui|git-citool" | sed -e s@^$RPM_BUILD_ROOT@@)               > bin-man-doc-files
 (find $RPM_BUILD_ROOT%{perl_vendorlib} -type f | sed -e s@^$RPM_BUILD_ROOT@@) >> perl-files
 %if %{!?_without_docs:1}0
-(find $RPM_BUILD_ROOT%{_mandir} $RPM_BUILD_ROOT/Documentation -type f | grep -vE "archimport|svn|git-cvs|email|gitk|git-gui|git-citool" | sed -e s@^$RPM_BUILD_ROOT@@ -e 's/$/*/' ) >> bin-man-doc-files
+(find $RPM_BUILD_ROOT%{_mandir} $RPM_BUILD_ROOT/Documentation -type f | grep -vE "p4import|archimport|svn|git-cvs|email|gitk|git-gui|git-citool" | sed -e s@^$RPM_BUILD_ROOT@@ -e 's/$/*/' ) >> bin-man-doc-files
 %else
 rm -rf $RPM_BUILD_ROOT%{_mandir}
 %endif
@@ -133,6 +143,13 @@ rm -rf $RPM_BUILD_ROOT
 %{!?_without_docs: %{_mandir}/man1/git-archimport.1*}
 %{!?_without_docs: %doc Documentation/git-archimport.html }
 
+%files p4
+%defattr(-,root,root)
+%doc Documentation/git-p4import.txt
+%{_bindir}/git-p4import
+%{!?_without_docs: %{_mandir}/man1/git-p4import.1*}
+%{!?_without_docs: %doc Documentation/git-p4import.html }
+
 %files email
 %defattr(-,root,root)
 %doc Documentation/*email*.txt
@@ -167,6 +184,9 @@ rm -rf $RPM_BUILD_ROOT
 %{!?_without_docs: %doc Documentation/*.html }
 
 %changelog
+* Tue Mar 27 2007 Eygene Ryabinkin <rea-git@codelabs.ru>
+- Added the git-p4 package: Perforce import stuff.
+
 * Mon Feb 13 2007 Nicolas Pitre <nico@cam.org>
 - Update core package description (Git isn't as stupid as it used to be)
 
diff --git a/gitk b/gitk
index 9ddff3e7f7b011564c56fb619f57bed66d875f7e..db28d745dc005722ff3d7c071aeb37f9fd4fdc21 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -720,6 +720,7 @@ proc makewindow {} {
     bindkey <Key-Return> {findnext 0}
     bindkey ? findprev
     bindkey f nextfile
+    bindkey <F5> updatecommits
     bind . <Control-q> doquit
     bind . <Control-f> dofind
     bind . <Control-g> {findnext 0}
@@ -985,6 +986,7 @@ f           Scroll diff view to next file
 <Ctrl-plus>    Increase font size
 <Ctrl-KP->     Decrease font size
 <Ctrl-minus>   Decrease font size
+<F5>           Update
 } \
            -justify left -bg white -border 2 -relief sunken
     pack $w.m -side top -fill both
@@ -1904,7 +1906,7 @@ proc do_file_hl {serial} {
     } else {
        set gdtargs [list "-S$highlight_files"]
     }
-    set cmd [concat | git-diff-tree -r -s --stdin $gdtargs]
+    set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
     set filehighlight [open $cmd r+]
     fconfigure $filehighlight -blocking 0
     fileevent $filehighlight readable readfhighlight
@@ -1956,7 +1958,7 @@ proc readfhighlight {} {
     }
     if {[eof $filehighlight]} {
        # strange...
-       puts "oops, git-diff-tree died"
+       puts "oops, git diff-tree died"
        catch {close $filehighlight}
        unset filehighlight
     }
diff --git a/gitweb/INSTALL b/gitweb/INSTALL
new file mode 100644 (file)
index 0000000..6328e26
--- /dev/null
@@ -0,0 +1,225 @@
+GIT web Interface (gitweb) Installation
+=======================================
+
+First you have to generate gitweb.cgi from gitweb.perl using
+"make gitweb/gitweb.cgi", then copy appropriate files (gitweb.cgi,
+gitweb.css, git-logo.png and git-favicon.png) to their destination.
+For example if git was (or is) installed with /usr prefix, you can do
+
+       $ make prefix=/usr gitweb/gitweb.cgi  ;# as yourself
+       # cp gitweb/git* /var/www/cgi-bin/    ;# as root
+
+Alternatively you can use autoconf generated ./configure script to
+set up path to git binaries (via config.mak.autogen), so you can write
+instead
+
+       $ make configure                     ;# as yourself
+       $ ./configure --prefix=/usr          ;# as yourself
+       $ make gitweb/gitweb.cgi             ;# as yourself
+       # cp gitweb/git* /var/www/cgi-bin/   ;# as root
+
+The above example assumes that your web server is configured to run
+[executable] files in /var/www/cgi-bin/ as server scripts (as CGI
+scripts).
+
+
+Build time configuration
+------------------------
+
+See also "How to configure gitweb for your local system" in README
+file for gitweb (in gitweb/README).
+
+- There are many configuration variables which affects building of
+  gitweb.cgi; see "default configuration for gitweb" section in main
+  (top dir) Makefile, and instructions for building gitweb/gitweb.cgi
+  target.
+
+  One of most important is where to find git wrapper binary. Gitweb
+  tries to find git wrapper at $(bindir)/git, so you have to set $bindir
+  when building gitweb.cgi, or $prefix from which $bindir is derived. If
+  you build and install gitweb together with the rest of git suite,
+  there should be no problems. Otherwise, if git was for example
+  installed from a binary package, you have to set $prefix (or $bindir)
+  accordingly.
+
+- Another important issue is where are git repositories you want to make
+  available to gitweb. By default gitweb search for repositories under
+  /pub/git; if you want to have projects somewhere else, like /home/git,
+  use GITWEB_PROJECTROOT build configuration variable.
+
+  By default all git repositories under projectroot are visible and
+  available to gitweb. List of projects is generated by default by
+  scanning the projectroot directory for git repositories. This can be
+  changed (configured) as described in "Gitweb repositories" section
+  below.
+
+  Note that gitweb deals directly with object database, and does not
+  need working directory; the name of the project is the name of its
+  repository object database, usually projectname.git for bare
+  repositories. If you want to provide gitweb access to non-bare (live)
+  repository, you can make projectname.git symbolic link under
+  projectroot linking to projectname/.git (but it is just
+  a suggestion).
+
+- You can control where gitweb tries to find its main CSS style file,
+  its favicon and logo with GITWEB_CSS, GITWEB_FAVICON and GITWEB_LOGO
+  build configuration variables. By default gitweb tries to find them
+  in the same directory as gitweb.cgi script.
+
+Build example
+~~~~~~~~~~~~~
+
+- To install gitweb to /var/www/cgi-bin/gitweb/ when git wrapper
+  is installed at /usr/local/bin/git and the repositories (projects)
+  we want to display are under /home/local/scm, you can do
+
+       make GITWEB_PROJECTROOT="/home/local/scm" \
+            GITWEB_CSS="/gitweb/gitweb.css" \
+            GITWEB_LOGO="/gitweb/git-logo.png" \
+            GITWEB_FAVICON="/gitweb/git-favicon.png" \
+            bindir=/usr/local/bin \
+            gitweb/gitweb.cgi
+
+       cp -fv ~/git/gitweb/gitweb.{cgi,css} \
+              ~/git/gitweb/git-{favicon,logo}.png \
+            /var/www/cgi-bin/gitweb/
+
+
+Gitweb config file
+------------------
+
+See also "Runtime gitweb configuration" section in README file
+for gitweb (in gitweb/README).
+
+- You can configure gitweb further using gitweb configuration file;
+  by default it is file named gitweb_config.perl in the same place as
+  gitweb.cgi script. You can control default place for config file
+  using GITWEB_CONFIG build configuration variable, and you can set it
+  using GITWEB_CONFIG environmental variable.
+
+- Gitweb config file is [fragment] of perl code. You can set variables
+  using "our $variable = value"; text from "#" character until the end
+  of a line is ignored. See perlsyn(1) for details.
+
+  See the top of gitweb.perl file for examples of customizable options.
+
+Config file example
+~~~~~~~~~~~~~~~~~~~
+
+To enable blame, pickaxe search, and snapshot support, while allowing
+individual projects to turn them off, put the following in your
+GITWEB_CONFIG file:
+
+       $feature{'blame'}{'default'} = [1];
+       $feature{'blame'}{'override'} = 1;
+
+       $feature{'pickaxe'}{'default'} = [1];
+       $feature{'pickaxe'}{'override'} = 1;
+
+       $feature{'snapshot'}{'default'} = ['x-gzip', 'gz', 'gzip'];
+       $feature{'snapshot'}{'override'} = 1;
+
+
+Gitweb repositories
+-------------------
+
+- By default all git repositories under projectroot are visible and
+  available to gitweb. List of projects is generated by default by
+  scanning the projectroot directory for git repositories (for object
+  databases to be more exact).
+
+  You can provide pre-generated list of [visible] repositories,
+  together with information about their owners (the project ownership
+  is taken from owner of repository directory otherwise), by setting
+  GITWEB_LIST build configuration variable (or $projects_list variable
+  in gitweb config file) to point to a plain file.
+
+  Each line of projects list file should consist of url-encoded path
+  to project repository database (relative to projectroot) separated
+  by space from url-encoded project owner; spaces in both project path
+  and project owner have to be encoded as either '%20' or '+'.
+
+  You can generate projects list index file using project_index action
+  (the 'TXT' link on projects list page) directly from gitweb.
+
+- By default even if project is not visible on projects list page, you
+  can view it nevertheless by hand-crafting gitweb URL. You can set
+  GITWEB_STRICT_EXPORT build configuration variable (or $strict_export
+  variable in gitweb config file) to only allow viewing of
+  repositories also shown on the overview page.
+
+- Alternatively, you can configure gitweb to only list and allow
+  viewing of the explicitly exported repositories, via
+  GITWEB_EXPORT_OK build configuration variable (or $export_ok
+  variable in gitweb config file). If it evaluates to true, gitweb
+  show repository only if this file exists in its object database
+  (if directory has the magic file $export_ok).
+
+Generating projects list using gitweb
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+We assume that GITWEB_CONFIG has its default Makefile value, namely
+gitweb_config.perl. Put the following in gitweb_make_index.perl file:
+
+       $GITWEB_CONFIG = "gitweb_config.perl";
+       do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
+
+       $projects_list = $projectroot;
+
+Then create the following script to get list of project in the format
+suitable for GITWEB_LIST build configuration variable (or
+$projects_list variable in gitweb config):
+
+       #!/bin/sh
+
+       export GITWEB_CONFIG="gitweb_make_index.perl"
+       export GATEWAY_INTERFACE="CGI/1.1"
+       export HTTP_ACCEPT="*/*"
+       export REQUEST_METHOD="GET"
+       export QUERY_STRING="a=project_index"
+
+       perl -- /var/www/cgi-bin/gitweb.cgi
+
+
+Requirements
+------------
+
+ - Core git tools
+ - Perl
+ - Perl modules: CGI, Encode, Fcntl, File::Find, File::Basename.
+ - web server
+
+
+Example web server configuration
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+See also "Webserver configuration" section in README file for gitweb
+(in gitweb/README).
+
+
+- Apache2, gitweb installed as CGI script,
+  under /var/www/cgi-bin/
+
+       ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
+
+       <Directory "/var/www/cgi-bin">
+           Options Indexes FollowSymlinks ExecCGI
+           AllowOverride None
+           Order allow,deny
+           Allow from all
+       </Directory>
+
+- Apache2, gitweb installed as mod_perl legacy script,
+  under /var/www/perl/
+
+       Alias /perl "/var/www/perl"
+
+       <Directory "/var/www/perl">
+           SetHandler perl-script
+           PerlResponseHandler ModPerl::Registry
+           PerlOptions +ParseHeaders
+           Options Indexes FollowSymlinks +ExecCGI
+           AllowOverride None
+           Order allow,deny
+           Allow from all
+       </Directory>
index 7177c6e86b8e8c3dc1e5d0db4bce4122cbe2430a..5e402924040d55aff5fb831a737d108d1e68a0bb 100644 (file)
@@ -107,7 +107,7 @@ span.age {
        font-style: italic;
 }
 
-div.page_body span.signoff {
+span.signoff {
        color: #888888;
 }
 
index 27b5970bcadf21f2f0e294c8c34d9595f6288503..e49eb91d69c2344163ab9477883777476c789bc7 100755 (executable)
@@ -19,7 +19,7 @@ use File::Basename qw(basename);
 binmode STDOUT, ':utf8';
 
 BEGIN {
-       CGI->compile() if $ENV{MOD_PERL};
+       CGI->compile() if $ENV{'MOD_PERL'};
 }
 
 our $cgi = new CGI;
@@ -1800,7 +1800,7 @@ EOF
                      $cgi->hidden(-name => "a") . "\n" .
                      $cgi->hidden(-name => "h") . "\n" .
                      $cgi->popup_menu(-name => 'st', -default => 'commit',
-                                      -values => ['commit', 'author', 'committer', 'pickaxe']) .
+                                      -values => ['commit', 'author', 'committer', 'pickaxe']) .
                      $cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
                      " search:\n",
                      $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
@@ -1870,16 +1870,16 @@ sub git_print_page_nav {
        my %arg = map { $_ => {action=>$_} } @navs;
        if (defined $head) {
                for (qw(commit commitdiff)) {
-                       $arg{$_}{hash} = $head;
+                       $arg{$_}{'hash'} = $head;
                }
                if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
                        for (qw(shortlog log)) {
-                               $arg{$_}{hash} = $head;
+                               $arg{$_}{'hash'} = $head;
                        }
                }
        }
-       $arg{tree}{hash} = $treehead if defined $treehead;
-       $arg{tree}{hash_base} = $treebase if defined $treebase;
+       $arg{'tree'}{'hash'} = $treehead if defined $treehead;
+       $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
 
        print "<div class=\"page_nav\">\n" .
                (join " | ",
@@ -1927,9 +1927,9 @@ sub git_print_header_div {
        my ($action, $title, $hash, $hash_base) = @_;
        my %args = ();
 
-       $args{action} = $action;
-       $args{hash} = $hash if $hash;
-       $args{hash_base} = $hash_base if $hash_base;
+       $args{'action'} = $action;
+       $args{'hash'} = $hash if $hash;
+       $args{'hash_base'} = $hash_base if $hash_base;
 
        print "<div class=\"header\">\n" .
              $cgi->a({-href => href(%args), -class => "title"},
@@ -3095,7 +3095,7 @@ sub git_summary {
                git_project_list_body(\@forklist, undef, 0, 15,
                                      $#forklist <= 15 ? undef :
                                      $cgi->a({-href => href(action=>"forks")}, "..."),
-                                     'noheader');
+                                     'noheader');
        }
 
        git_footer_html();
@@ -3154,7 +3154,7 @@ sub git_blame2 {
        }
        $ftype = git_get_type($hash);
        if ($ftype !~ "blob") {
-               die_error("400 Bad Request", "Object is not a blob");
+               die_error('400 Bad Request', "Object is not a blob");
        }
        open ($fd, "-|", git_cmd(), "blame", '-p', '--',
              $file_name, $hash_base)
@@ -3202,7 +3202,7 @@ HTML
                my $rev = substr($full_rev, 0, 8);
                my $author = $meta->{'author'};
                my %date = parse_date($meta->{'author-time'},
-                                     $meta->{'author-tz'});
+                                     $meta->{'author-tz'});
                my $date = $date{'iso-tz'};
                if ($group_size) {
                        $current_color = ++$current_color % $num_colors;
@@ -3214,24 +3214,24 @@ HTML
                        print " rowspan=\"$group_size\"" if ($group_size > 1);
                        print ">";
                        print $cgi->a({-href => href(action=>"commit",
-                                                    hash=>$full_rev,
-                                                    file_name=>$file_name)},
-                                     esc_html($rev));
+                                                    hash=>$full_rev,
+                                                    file_name=>$file_name)},
+                                     esc_html($rev));
                        print "</td>\n";
                }
                open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
-                       or die_error("could not open git-rev-parse");
+                       or die_error(undef, "Open git-rev-parse failed");
                my $parent_commit = <$dd>;
                close $dd;
                chomp($parent_commit);
                my $blamed = href(action => 'blame',
-                                 file_name => $meta->{'filename'},
-                                 hash_base => $parent_commit);
+                                 file_name => $meta->{'filename'},
+                                 hash_base => $parent_commit);
                print "<td class=\"linenr\">";
                print $cgi->a({ -href => "$blamed#l$orig_lineno",
-                               -id => "l$lineno",
-                               -class => "linenr" },
-                             esc_html($lineno));
+                               -id => "l$lineno",
+                               -class => "linenr" },
+                             esc_html($lineno));
                print "</td>";
                print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
                print "</tr>\n";
@@ -3621,8 +3621,8 @@ sub git_snapshot {
        my $name = $project;
        $name =~ s/\047/\047\\\047\047/g;
        open my $fd, "-|",
-       "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
-               or die_error(undef, "Execute git-tar-tree failed.");
+               "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
+               or die_error(undef, "Execute git-tar-tree failed");
        binmode STDOUT, ':raw';
        print <$fd>;
        binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
@@ -3719,7 +3719,7 @@ sub git_commit {
                $formats_nav .=
                        '(merge: ' .
                        join(' ', map {
-                               $cgi->a({-href => href(action=>"commitdiff",
+                               $cgi->a({-href => href(action=>"commit",
                                                       hash=>$_)},
                                        esc_html(substr($_, 0, 7)));
                        } @$parents ) .
@@ -3734,7 +3734,7 @@ sub git_commit {
                # difftree output is not printed for merges
                open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
                        @diff_opts, $parent, $hash, "--"
-                               or die_error(undef, "Open git-diff-tree failed");
+                       or die_error(undef, "Open git-diff-tree failed");
                @difftree = map { chomp; $_ } <$fd>;
                close $fd or die_error(undef, "Reading git-diff-tree failed");
        }
@@ -3885,7 +3885,7 @@ sub git_blobdiff {
                        # read raw output
                        open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
                                $hash_parent_base, $hash_base,
-                               "--", $file_name
+                               "--", (defined $file_parent ? $file_parent : ()), $file_name
                                or die_error(undef, "Open git-diff-tree failed");
                        @difftree = map { chomp; $_ } <$fd>;
                        close $fd
@@ -3934,8 +3934,9 @@ sub git_blobdiff {
 
                # open patch output
                open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
-                       '-p', $hash_parent_base, $hash_base,
-                       "--", $file_name
+                       '-p', ($format eq 'html' ? "--full-index" : ()),
+                       $hash_parent_base, $hash_base,
+                       "--", (defined $file_parent ? $file_parent : ()), $file_name
                        or die_error(undef, "Open git-diff-tree failed");
        }
 
@@ -3969,7 +3970,8 @@ sub git_blobdiff {
                }
 
                # open patch output
-               open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts,
+               open $fd, "-|", git_cmd(), "diff", @diff_opts,
+                       '-p', ($format eq 'html' ? "--full-index" : ()),
                        $hash_parent, $hash, "--"
                        or die_error(undef, "Open git-diff failed");
        } else  {
@@ -4304,13 +4306,13 @@ sub git_search {
                if ($page > 0) {
                        $paging_nav .=
                                $cgi->a({-href => href(action=>"search", hash=>$hash,
-                                                      searchtext=>$searchtext, searchtype=>$searchtype)},
-                                       "first");
+                                                      searchtext=>$searchtext, searchtype=>$searchtype)},
+                                       "first");
                        $paging_nav .= " &sdot; " .
                                $cgi->a({-href => href(action=>"search", hash=>$hash,
-                                                      searchtext=>$searchtext, searchtype=>$searchtype,
-                                                      page=>$page-1),
-                                        -accesskey => "p", -title => "Alt-p"}, "prev");
+                                                      searchtext=>$searchtext, searchtype=>$searchtype,
+                                                      page=>$page-1),
+                                        -accesskey => "p", -title => "Alt-p"}, "prev");
                } else {
                        $paging_nav .= "first";
                        $paging_nav .= " &sdot; prev";
@@ -4318,9 +4320,9 @@ sub git_search {
                if ($#commitlist >= 100) {
                        $paging_nav .= " &sdot; " .
                                $cgi->a({-href => href(action=>"search", hash=>$hash,
-                                                      searchtext=>$searchtext, searchtype=>$searchtype,
-                                                      page=>$page+1),
-                                        -accesskey => "n", -title => "Alt-n"}, "next");
+                                                      searchtext=>$searchtext, searchtype=>$searchtype,
+                                                      page=>$page+1),
+                                        -accesskey => "n", -title => "Alt-n"}, "next");
                } else {
                        $paging_nav .= " &sdot; next";
                }
@@ -4328,9 +4330,9 @@ sub git_search {
                if ($#commitlist >= 100) {
                        $next_link =
                                $cgi->a({-href => href(action=>"search", hash=>$hash,
-                                                      searchtext=>$searchtext, searchtype=>$searchtype,
-                                                      page=>$page+1),
-                                        -accesskey => "n", -title => "Alt-n"}, "next");
+                                                      searchtext=>$searchtext, searchtype=>$searchtype,
+                                                      page=>$page+1),
+                                        -accesskey => "n", -title => "Alt-n"}, "next");
                }
 
                git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
diff --git a/help.c b/help.c
index 0893fea0254f4ec8acbce82a0af41e4e61bd72a6..6a9af4d175f2fe9724a2844df63e4011ba91f1b3 100644 (file)
--- a/help.c
+++ b/help.c
@@ -31,12 +31,6 @@ static int term_columns(void)
        return 80;
 }
 
-static void oom(void)
-{
-       fprintf(stderr, "git: out of memory\n");
-       exit(1);
-}
-
 static inline void mput_char(char c, unsigned int num)
 {
        while(num--)
@@ -54,13 +48,9 @@ static void add_cmdname(const char *name, int len)
        struct cmdname *ent;
        if (cmdname_alloc <= cmdname_cnt) {
                cmdname_alloc = cmdname_alloc + 200;
-               cmdname = realloc(cmdname, cmdname_alloc * sizeof(*cmdname));
-               if (!cmdname)
-                       oom();
+               cmdname = xrealloc(cmdname, cmdname_alloc * sizeof(*cmdname));
        }
-       ent = malloc(sizeof(*ent) + len);
-       if (!ent)
-               oom();
+       ent = xmalloc(sizeof(*ent) + len);
        ent->len = len;
        memcpy(ent->name, name, len);
        ent->name[len] = 0;
index e6cd11db737e1ed79c3b60d33674c6e0ce38af55..09baedc18ae320a2f09fa61d9065bedb69c02a41 100644 (file)
@@ -16,8 +16,7 @@ static struct curl_slist *no_pragma_header;
 
 struct alt_base
 {
-       const char *base;
-       int path_len;
+       char *base;
        int got_indices;
        struct packed_git *packs;
        struct alt_base *next;
@@ -158,12 +157,12 @@ static void start_object_request(struct object_request *obj_req)
 
        SHA1_Init(&obj_req->c);
 
-       url = xmalloc(strlen(obj_req->repo->base) + 50);
-       obj_req->url = xmalloc(strlen(obj_req->repo->base) + 50);
+       url = xmalloc(strlen(obj_req->repo->base) + 51);
+       obj_req->url = xmalloc(strlen(obj_req->repo->base) + 51);
        strcpy(url, obj_req->repo->base);
        posn = url + strlen(obj_req->repo->base);
-       strcpy(posn, "objects/");
-       posn += 8;
+       strcpy(posn, "/objects/");
+       posn += 9;
        memcpy(posn, hex, 2);
        posn += 2;
        *(posn++) = '/';
@@ -199,7 +198,7 @@ static void start_object_request(struct object_request *obj_req)
                SHA1_Init(&obj_req->c);
                if (prev_posn>0) {
                        prev_posn = 0;
-                       lseek(obj_req->local, SEEK_SET, 0);
+                       lseek(obj_req->local, 0, SEEK_SET);
                        ftruncate(obj_req->local, 0);
                }
        }
@@ -515,7 +514,6 @@ static void process_alternates_response(void *callback_data)
                        int serverlen = 0;
                        struct alt_base *newalt;
                        char *target = NULL;
-                       char *path;
                        if (data[i] == '/') {
                                /* This counts
                                 * http://git.host/pub/scm/linux.git/
@@ -583,12 +581,6 @@ static void process_alternates_response(void *callback_data)
                                newalt->base = target;
                                newalt->got_indices = 0;
                                newalt->packs = NULL;
-                               path = strstr(target, "//");
-                               if (path) {
-                                       path = strchr(path+2, '/');
-                                       if (path)
-                                               newalt->path_len = strlen(path);
-                               }
 
                                while (tail->next != NULL)
                                        tail = tail->next;
@@ -938,14 +930,14 @@ static char *quote_ref_url(const char *base, const char *ref)
        int len, baselen, ch;
 
        baselen = strlen(base);
-       len = baselen + 6; /* "refs/" + NUL */
+       len = baselen + 7; /* "/refs/" + NUL */
        for (cp = ref; (ch = *cp) != 0; cp++, len++)
                if (needs_quote(ch))
                        len += 2; /* extra two hex plus replacement % */
        qref = xmalloc(len);
        memcpy(qref, base, baselen);
-       memcpy(qref + baselen, "refs/", 5);
-       for (cp = ref, dp = qref + baselen + 5; (ch = *cp) != 0; cp++) {
+       memcpy(qref + baselen, "/refs/", 6);
+       for (cp = ref, dp = qref + baselen + 6; (ch = *cp) != 0; cp++) {
                if (needs_quote(ch)) {
                        *dp++ = '%';
                        *dp++ = hex((ch >> 4) & 0xF);
@@ -999,7 +991,7 @@ int main(int argc, const char **argv)
        const char **write_ref = NULL;
        char **commit_id;
        const char *url;
-       char *path;
+       char *s;
        int arg = 1;
        int rc = 0;
 
@@ -1044,16 +1036,13 @@ int main(int argc, const char **argv)
        no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
 
        alt = xmalloc(sizeof(*alt));
-       alt->base = url;
+       alt->base = xmalloc(strlen(url) + 1);
+       strcpy(alt->base, url);
+       for (s = alt->base + strlen(alt->base) - 1; *s == '/'; --s)
+               *s = 0;
        alt->got_indices = 0;
        alt->packs = NULL;
        alt->next = NULL;
-       path = strstr(url, "//");
-       if (path) {
-               path = strchr(path+2, '/');
-               if (path)
-                       alt->path_len = strlen(path);
-       }
 
        if (pull(commits, commit_id, write_ref, url))
                rc = 1;
index cbb02d3bc1eef3d5a088be320a3a8bcb87a4a685..e3f767582bfc71fc3d1b90be8fa76ab3ad7e1664 100644 (file)
@@ -312,7 +312,7 @@ static void start_fetch_loose(struct transfer_request *request)
                SHA1_Init(&request->c);
                if (prev_posn>0) {
                        prev_posn = 0;
-                       lseek(request->local_fileno, SEEK_SET, 0);
+                       lseek(request->local_fileno, 0, SEEK_SET);
                        ftruncate(request->local_fileno, 0);
                }
        }
@@ -1750,8 +1750,7 @@ static struct object_list **process_tree(struct tree *tree,
        me.elem = name;
        me.elem_len = strlen(name);
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &entry)) {
                if (S_ISDIR(entry.mode))
index b405864be954941dedc4b0cc0c7f7aefcf65dd2d..3c768fbc631387b59bbbae3423b65b6a311a702b 100644 (file)
@@ -139,7 +139,7 @@ static const char *open_pack_file(const char *pack_name)
                if (!pack_name) {
                        static char tmpfile[PATH_MAX];
                        snprintf(tmpfile, sizeof(tmpfile),
-                                "%s/pack_XXXXXX", get_object_directory());
+                                "%s/tmp_pack_XXXXXX", get_object_directory());
                        output_fd = mkstemp(tmpfile);
                        pack_name = xstrdup(tmpfile);
                } else
@@ -347,26 +347,19 @@ static int find_delta_children(const union delta_base *base,
 static void sha1_object(const void *data, unsigned long size,
                        enum object_type type, unsigned char *sha1)
 {
-       SHA_CTX ctx;
-       char header[50];
-       int header_size;
-       const char *type_str;
-
-       switch (type) {
-       case OBJ_COMMIT: type_str = commit_type; break;
-       case OBJ_TREE:   type_str = tree_type; break;
-       case OBJ_BLOB:   type_str = blob_type; break;
-       case OBJ_TAG:    type_str = tag_type; break;
-       default:
-               die("bad type %d", type);
+       hash_sha1_file(data, size, typename(type), sha1);
+       if (has_sha1_file(sha1)) {
+               void *has_data;
+               enum object_type has_type;
+               unsigned long has_size;
+               has_data = read_sha1_file(sha1, &has_type, &has_size);
+               if (!has_data)
+                       die("cannot read existing object %s", sha1_to_hex(sha1));
+               if (size != has_size || type != has_type ||
+                   memcmp(data, has_data, size) != 0)
+                       die("SHA1 COLLISION FOUND WITH %s !", sha1_to_hex(sha1));
+               free(has_data);
        }
-
-       header_size = sprintf(header, "%s %lu", type_str, size) + 1;
-
-       SHA1_Init(&ctx);
-       SHA1_Update(&ctx, header, header_size);
-       SHA1_Update(&ctx, data, size);
-       SHA1_Final(sha1, &ctx);
 }
 
 static void resolve_delta(struct object_entry *delta_obj, void *base_data,
@@ -547,7 +540,7 @@ static int write_compressed(int fd, void *in, unsigned int size)
        return size;
 }
 
-static void append_obj_to_pack(void *buf,
+static void append_obj_to_pack(const unsigned char *sha1, void *buf,
                               unsigned long size, enum object_type type)
 {
        struct object_entry *obj = &objects[nr_objects++];
@@ -565,7 +558,7 @@ static void append_obj_to_pack(void *buf,
        write_or_die(output_fd, header, n);
        obj[1].offset = obj[0].offset + n;
        obj[1].offset += write_compressed(output_fd, buf, size);
-       sha1_object(buf, size, type, obj->sha1);
+       hashcpy(obj->sha1, sha1);
 }
 
 static int delta_pos_compare(const void *_a, const void *_b)
@@ -618,7 +611,9 @@ static void fix_unresolved_deltas(int nr_unresolved)
                                resolve_delta(child, data, size, type);
                }
 
-               append_obj_to_pack(data, size, type);
+               if (check_sha1_signature(d->base.sha1, data, size, typename(type)))
+                       die("local object %s is corrupt", sha1_to_hex(d->base.sha1));
+               append_obj_to_pack(d->base.sha1, data, size, type);
                free(data);
                if (verbose)
                        percent = display_progress(nr_resolved_deltas,
@@ -696,7 +691,7 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1)
        if (!index_name) {
                static char tmpfile[PATH_MAX];
                snprintf(tmpfile, sizeof(tmpfile),
-                        "%s/index_XXXXXX", get_object_directory());
+                        "%s/tmp_idx_XXXXXX", get_object_directory());
                fd = mkstemp(tmpfile);
                index_name = xstrdup(tmpfile);
        } else {
index f1fa21c3978f32882b6aac68c32d33ead6f8f1ff..2ba2c958e0aac63f0d5b092019e71f6905edb052 100644 (file)
@@ -49,8 +49,7 @@ static void process_tree(struct rev_info *revs,
        me.elem = name;
        me.elem_len = strlen(name);
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &entry)) {
                if (S_ISDIR(entry.mode))
index 7cfe8b3587c10bf0791c066a72482771e7daae77..4b650efa8b19424a61566b7ec87e7808874a6721 100644 (file)
@@ -64,9 +64,9 @@ static int copy_file(const char *source, char *dest, const char *hex,
                }
                /* If we got ENOENT there is no point continuing. */
                if (errno == ENOENT) {
-                       if (warn_if_not_exists)
-                               fprintf(stderr, "does not exist %s\n", source);
-                       return -1;
+                       if (!warn_if_not_exists)
+                               return -1;
+                       return error("does not exist %s", source);
                }
        }
        if (use_symlink) {
@@ -74,9 +74,8 @@ static int copy_file(const char *source, char *dest, const char *hex,
                if (stat(source, &st)) {
                        if (!warn_if_not_exists && errno == ENOENT)
                                return -1;
-                       fprintf(stderr, "cannot stat %s: %s\n", source,
-                               strerror(errno));
-                       return -1;
+                       return error("cannot stat %s: %s", source,
+                                    strerror(errno));
                }
                if (!symlink(source, dest)) {
                        pull_say("symlink %s\n", hex);
@@ -90,25 +89,21 @@ static int copy_file(const char *source, char *dest, const char *hex,
                if (ifd < 0) {
                        if (!warn_if_not_exists && errno == ENOENT)
                                return -1;
-                       fprintf(stderr, "cannot open %s\n", source);
-                       return -1;
+                       return error("cannot open %s", source);
                }
                ofd = open(dest, O_WRONLY | O_CREAT | O_EXCL, 0666);
                if (ofd < 0) {
-                       fprintf(stderr, "cannot open %s\n", dest);
                        close(ifd);
-                       return -1;
+                       return error("cannot open %s", dest);
                }
                status = copy_fd(ifd, ofd);
                close(ofd);
                if (status)
-                       fprintf(stderr, "cannot write %s\n", dest);
-               else
-                       pull_say("copy %s\n", hex);
-               return status;
+                       return error("cannot write %s", dest);
+               pull_say("copy %s\n", hex);
+               return 0;
        }
-       fprintf(stderr, "failed to copy %s with given copy methods.\n", hex);
-       return -1;
+       return error("failed to copy %s with given copy methods.", hex);
 }
 
 static int fetch_pack(const unsigned char *sha1)
@@ -181,13 +176,11 @@ int fetch_ref(char *ref, unsigned char *sha1)
        ifd = open(filename, O_RDONLY);
        if (ifd < 0) {
                close(ifd);
-               fprintf(stderr, "cannot open %s\n", filename);
-               return -1;
+               return error("cannot open %s", filename);
        }
        if (read_in_full(ifd, hex, 40) != 40 || get_sha1_hex(hex, sha1)) {
                close(ifd);
-               fprintf(stderr, "cannot read from %s\n", filename);
-               return -1;
+               return error("cannot read from %s", filename);
        }
        close(ifd);
        pull_say("ref %s\n", sha1_to_hex(sha1));
index 4824f4dc026e7b3f978fe4e9b2154335359e9d2e..bed6b21daf302c76cb87bb99b613f168df9899e1 100644 (file)
@@ -4,6 +4,7 @@
 #include "cache.h"
 
 static struct lock_file *lock_file_list;
+static const char *alternate_index_output;
 
 static void remove_lock_file(void)
 {
@@ -65,6 +66,27 @@ int commit_lock_file(struct lock_file *lk)
        return i;
 }
 
+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);
+}
+
+void set_alternate_index_output(const char *name)
+{
+       alternate_index_output = name;
+}
+
+int commit_locked_index(struct lock_file *lk)
+{
+       if (alternate_index_output) {
+               int result = rename(lk->filename, alternate_index_output);
+               lk->filename[0] = 0;
+               return result;
+       }
+       else
+               return commit_lock_file(lk);
+}
+
 void rollback_lock_file(struct lock_file *lk)
 {
        if (lk->filename[0])
index 6ce239d8f92837ccce7326dab1951f74360eef88..8797aa14c43e693c4cb64bc93dac4fe78716558d 100644 (file)
@@ -186,7 +186,7 @@ void show_log(struct rev_info *opt, const char *sep)
                        snprintf(subject_buffer, sizeof(subject_buffer) - 1,
                                 "%s"
                                 "MIME-Version: 1.0\n"
-                                "Content-Type: multipart/mixed;\n"
+                                "Content-Type: multipart/mixed;"
                                 " boundary=\"%s%s\"\n"
                                 "\n"
                                 "This is a multi-part message in MIME "
@@ -202,13 +202,15 @@ void show_log(struct rev_info *opt, const char *sep)
 
                        snprintf(buffer, sizeof(buffer) - 1,
                                 "--%s%s\n"
-                                "Content-Type: text/x-patch;\n"
+                                "Content-Type: text/x-patch;"
                                 " name=\"%s.diff\"\n"
                                 "Content-Transfer-Encoding: 8bit\n"
-                                "Content-Disposition: inline;\n"
+                                "Content-Disposition: %s;"
                                 " filename=\"%s.diff\"\n\n",
                                 mime_boundary_leader, opt->mime_boundary,
-                                sha1, sha1);
+                                sha1,
+                                opt->no_inline ? "attachment" : "inline",
+                                sha1);
                        opt->diffopt.stat_sep = buffer;
                }
        } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
index 7027d7865971646f178690a150246d9bc4d674c0..5599fd321bb4c09c1c0ce4fc62dfb9ecf5531c2b 100644 (file)
@@ -1,30 +1,17 @@
 #include "cache.h"
+#include "run-command.h"
 
 static const char *pgm;
-static const char *arguments[8];
+static const char *arguments[9];
 static int one_shot, quiet;
 static int err;
 
 static void run_program(void)
 {
-       pid_t pid = fork();
-       int status;
-
-       if (pid < 0)
-               die("unable to fork");
-       if (!pid) {
-               execlp(pgm, arguments[0],
-                           arguments[1],
-                           arguments[2],
-                           arguments[3],
-                           arguments[4],
-                           arguments[5],
-                           arguments[6],
-                           arguments[7],
-                           NULL);
-               die("unable to execute '%s'", pgm);
-       }
-       if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) || WEXITSTATUS(status)) {
+       struct child_process child;
+       memset(&child, 0, sizeof(child));
+       child.argv = arguments;
+       if (run_command(&child)) {
                if (one_shot) {
                        err++;
                } else {
@@ -49,6 +36,7 @@ static int merge_entry(int pos, const char *path)
        arguments[5] = "";
        arguments[6] = "";
        arguments[7] = "";
+       arguments[8] = NULL;
        found = 0;
        do {
                static char hexbuf[4][60];
index c96e1a734cb0c258cd4adb4f00e247abdf804640..2b614b64ba71f4006685ed1e08c300385ece5dec 100644 (file)
@@ -221,7 +221,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
        struct cache_entry *ce;
        ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage, refresh);
        if (!ce)
-               return error("cache_addinfo failed: %s", strerror(cache_errno));
+               return error("addinfo_cache failed for path '%s'", path);
        return add_cache_entry(ce, options);
 }
 
@@ -278,8 +278,16 @@ static struct tree *git_write_tree(void)
 {
        struct tree *result = NULL;
 
-       if (unmerged_index())
+       if (unmerged_index()) {
+               int i;
+               output(0, "There are unmerged index entries:");
+               for (i = 0; i < active_nr; i++) {
+                       struct cache_entry *ce = active_cache[i];
+                       if (ce_stage(ce))
+                               output(0, "%d %.*s", ce_stage(ce), ce_namelen(ce), ce->name);
+               }
                return NULL;
+       }
 
        if (!active_cache_tree)
                active_cache_tree = cache_tree();
@@ -735,8 +743,19 @@ static void conflict_rename_rename(struct rename *ren1,
                       ren2_dst, branch1, dst_name2);
                remove_file(0, ren2_dst, 0);
        }
-       update_stages(dst_name1, NULL, ren1->pair->two, NULL, 1);
-       update_stages(dst_name2, NULL, NULL, ren2->pair->two, 1);
+       if (index_only) {
+               remove_file_from_cache(dst_name1);
+               remove_file_from_cache(dst_name2);
+               /*
+                * Uncomment to leave the conflicting names in the resulting tree
+                *
+                * update_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, dst_name1);
+                * update_file(0, ren2->pair->two->sha1, ren2->pair->two->mode, dst_name2);
+                */
+       } else {
+               update_stages(dst_name1, NULL, ren1->pair->two, NULL, 1);
+               update_stages(dst_name2, NULL, NULL, ren2->pair->two, 1);
+       }
        while (delp--)
                free(del[delp]);
 }
@@ -852,10 +871,16 @@ static int process_renames(struct path_list *a_renames,
                        if (strcmp(ren1_dst, ren2_dst) != 0) {
                                clean_merge = 0;
                                output(1, "CONFLICT (rename/rename): "
-                                      "Rename %s->%s in branch %s "
-                                      "rename %s->%s in %s",
+                                      "Rename \"%s\"->\"%s\" in branch \"%s\" "
+                                      "rename \"%s\"->\"%s\" in \"%s\"%s",
                                       src, ren1_dst, branch1,
-                                      src, ren2_dst, branch2);
+                                      src, ren2_dst, branch2,
+                                      index_only ? " (left unresolved)": "");
+                               if (index_only) {
+                                       remove_file_from_cache(src);
+                                       update_file(0, ren1->pair->one->sha1,
+                                                   ren1->pair->one->mode, src);
+                               }
                                conflict_rename_rename(ren1, branch1, ren2, branch2);
                        } else {
                                struct merge_file_info mfi;
@@ -1353,7 +1378,7 @@ int main(int argc, char *argv[])
        if (show(3))
                printf("Merging %s with %s\n", branch1, branch2);
 
-       index_fd = hold_lock_file_for_update(lock, get_index_file(), 1);
+       index_fd = hold_locked_index(lock, 1);
 
        for (i = 0; i < bases_count; i++) {
                struct commit *ancestor = get_ref(bases[i]);
@@ -1363,7 +1388,7 @@ int main(int argc, char *argv[])
 
        if (active_cache_changed &&
            (write_cache(index_fd, active_cache, active_nr) ||
-            close(index_fd) || commit_lock_file(lock)))
+            close(index_fd) || commit_locked_index(lock)))
                        die ("unable to write %s", get_index_file());
 
        return clean ? 0: 1;
index b2867ba7226ea6ff69876f8f20da87d200fe5fca..3b8d9e6887ae051bf61cc0833f97d83bb47a0bae 100644 (file)
@@ -188,7 +188,7 @@ static void resolve(const char *base, struct name_entry *branch1, struct name_en
 
 static int unresolved_directory(const char *base, struct name_entry n[3])
 {
-       int baselen;
+       int baselen, pathlen;
        char *newbase;
        struct name_entry *p;
        struct tree_desc t[3];
@@ -205,10 +205,11 @@ static int unresolved_directory(const char *base, struct name_entry n[3])
        if (!S_ISDIR(p->mode))
                return 0;
        baselen = strlen(base);
-       newbase = xmalloc(baselen + p->pathlen + 2);
+       pathlen = tree_entry_len(p->path, p->sha1);
+       newbase = xmalloc(baselen + pathlen + 2);
        memcpy(newbase, base, baselen);
-       memcpy(newbase + baselen, p->path, p->pathlen);
-       memcpy(newbase + baselen + p->pathlen, "/", 2);
+       memcpy(newbase + baselen, p->path, pathlen);
+       memcpy(newbase + baselen + pathlen, "/", 2);
 
        buf0 = fill_tree_descriptor(t+0, n[0].sha1);
        buf1 = fill_tree_descriptor(t+1, n[1].sha1);
index 5b468893421794c50741ce9085c12bc41fb1985f..78a44a6ef4e4823487861c9173f3db4a3fb76e3a 100644 (file)
--- a/object.c
+++ b/object.c
@@ -184,8 +184,10 @@ struct object *parse_object(const unsigned char *sha1)
 
        if (buffer) {
                struct object *obj;
-               if (check_sha1_signature(sha1, buffer, size, typename(type)) < 0)
-                       printf("sha1 mismatch %s\n", sha1_to_hex(sha1));
+               if (check_sha1_signature(sha1, buffer, size, typename(type)) < 0) {
+                       error("sha1 mismatch %s\n", sha1_to_hex(sha1));
+                       return NULL;
+               }
 
                obj = parse_object_buffer(sha1, type, size, buffer, &eaten);
                if (!eaten)
index 299c514128b8b6330561a1a2b8ac30324a7ac479..f58083d11e0cfb974861d340bdea4ae18d2469e8 100644 (file)
@@ -5,7 +5,7 @@ static int verify_packfile(struct packed_git *p,
                struct pack_window **w_curs)
 {
        off_t index_size = p->index_size;
-       void *index_base = p->index_base;
+       const unsigned char *index_base = p->index_data;
        SHA_CTX ctx;
        unsigned char sha1[20];
        off_t offset = 0, pack_sig = p->pack_size - 20;
@@ -31,7 +31,7 @@ static int verify_packfile(struct packed_git *p,
        if (hashcmp(sha1, use_pack(p, w_curs, pack_sig, NULL)))
                return error("Packfile %s SHA1 mismatch with itself",
                             p->pack_name);
-       if (hashcmp(sha1, (unsigned char *)index_base + index_size - 40))
+       if (hashcmp(sha1, index_base + index_size - 40))
                return error("Packfile %s SHA1 mismatch with idx",
                             p->pack_name);
        unuse_pack(w_curs);
@@ -42,13 +42,14 @@ static int verify_packfile(struct packed_git *p,
         */
        nr_objects = num_packed_objects(p);
        for (i = 0, err = 0; i < nr_objects; i++) {
-               unsigned char sha1[20];
+               const unsigned char *sha1;
                void *data;
                enum object_type type;
                unsigned long size;
                off_t offset;
 
-               if (nth_packed_object_sha1(p, i, sha1))
+               sha1 = nth_packed_object_sha1(p, i);
+               if (!sha1)
                        die("internal error pack-check nth-packed-object");
                offset = find_pack_entry_one(sha1, p);
                if (!offset)
@@ -82,14 +83,16 @@ static void show_pack_info(struct packed_git *p)
        memset(chain_histogram, 0, sizeof(chain_histogram));
 
        for (i = 0; i < nr_objects; i++) {
-               unsigned char sha1[20], base_sha1[20];
+               const unsigned char *sha1;
+               unsigned char base_sha1[20];
                const char *type;
                unsigned long size;
                unsigned long store_size;
                off_t offset;
                unsigned int delta_chain_length;
 
-               if (nth_packed_object_sha1(p, i, sha1))
+               sha1 = nth_packed_object_sha1(p, i);
+               if (!sha1)
                        die("internal error pack-check nth-packed-object");
                offset = find_pack_entry_one(sha1, p);
                if (!offset)
@@ -127,7 +130,7 @@ static void show_pack_info(struct packed_git *p)
 int verify_pack(struct packed_git *p, int verbose)
 {
        off_t index_size = p->index_size;
-       void *index_base = p->index_base;
+       const unsigned char *index_base = p->index_data;
        SHA_CTX ctx;
        unsigned char sha1[20];
        int ret;
@@ -137,7 +140,7 @@ int verify_pack(struct packed_git *p, int verbose)
        SHA1_Init(&ctx);
        SHA1_Update(&ctx, index_base, (unsigned int)(index_size - 20));
        SHA1_Final(sha1, &ctx);
-       if (hashcmp(sha1, (unsigned char *)index_base + index_size - 20))
+       if (hashcmp(sha1, index_base + index_size - 20))
                ret = error("Packfile index for %s SHA1 mismatch",
                            p->pack_name);
 
index c8f7d9af7b502e12a3d36fc3b3e796e43b4f2bdb..40e579b2d9788bb0867b345c3596b1ad1539272a 100644 (file)
@@ -17,7 +17,7 @@ static int load_all_packs, verbose, alt_odb;
 
 struct llist_item {
        struct llist_item *next;
-       unsigned char *sha1;
+       const unsigned char *sha1;
 };
 static struct llist {
        struct llist_item *front;
@@ -104,9 +104,9 @@ static struct llist * llist_copy(struct llist *list)
        return ret;
 }
 
-static inline struct llist_item * llist_insert(struct llist *list,
-                                              struct llist_item *after,
-                                              unsigned char *sha1)
+static inline struct llist_item *llist_insert(struct llist *list,
+                                             struct llist_item *after,
+                                              const unsigned char *sha1)
 {
        struct llist_item *new = llist_item_get();
        new->sha1 = sha1;
@@ -128,12 +128,14 @@ static inline struct llist_item * llist_insert(struct llist *list,
        return new;
 }
 
-static inline struct llist_item *llist_insert_back(struct llist *list, unsigned char *sha1)
+static inline struct llist_item *llist_insert_back(struct llist *list,
+                                                  const unsigned char *sha1)
 {
        return llist_insert(list, list->back, sha1);
 }
 
-static inline struct llist_item *llist_insert_sorted_unique(struct llist *list, unsigned char *sha1, struct llist_item *hint)
+static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
+                       const unsigned char *sha1, struct llist_item *hint)
 {
        struct llist_item *prev = NULL, *l;
 
@@ -246,12 +248,12 @@ static struct pack_list * pack_list_difference(const struct pack_list *A,
 static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
 {
        int p1_off, p2_off;
-       unsigned char *p1_base, *p2_base;
+       const unsigned char *p1_base, *p2_base;
        struct llist_item *p1_hint = NULL, *p2_hint = NULL;
 
        p1_off = p2_off = 256 * 4 + 4;
-       p1_base = (unsigned char *) p1->pack->index_base;
-       p2_base = (unsigned char *) p2->pack->index_base;
+       p1_base = p1->pack->index_data;
+       p2_base = p2->pack->index_data;
 
        while (p1_off <= p1->pack->index_size - 3 * 20 &&
               p2_off <= p2->pack->index_size - 3 * 20)
@@ -351,11 +353,11 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
 {
        size_t ret = 0;
        int p1_off, p2_off;
-       unsigned char *p1_base, *p2_base;
+       const unsigned char *p1_base, *p2_base;
 
        p1_off = p2_off = 256 * 4 + 4;
-       p1_base = (unsigned char *)p1->index_base;
-       p2_base = (unsigned char *)p2->index_base;
+       p1_base = p1->index_data;
+       p2_base = p2->index_data;
 
        while (p1_off <= p1->index_size - 3 * 20 &&
               p2_off <= p2->index_size - 3 * 20)
@@ -534,7 +536,7 @@ static struct pack_list * add_pack(struct packed_git *p)
 {
        struct pack_list l;
        size_t off;
-       unsigned char *base;
+       const unsigned char *base;
 
        if (!p->pack_local && !(alt_odb || verbose))
                return NULL;
@@ -543,7 +545,7 @@ static struct pack_list * add_pack(struct packed_git *p)
        llist_init(&l.all_objects);
 
        off = 256 * 4 + 4;
-       base = (unsigned char *)p->index_base;
+       base = p->index_data;
        while (off <= p->index_size - 3 * 20) {
                llist_insert_back(l.all_objects, base + off);
                off += 24;
diff --git a/pack.h b/pack.h
index deb427edbe43710dd2b76a3af0dbd87750344103..d4d412ccbb403f1374d41a00791eec3c16ba64ef 100644 (file)
--- a/pack.h
+++ b/pack.h
@@ -16,24 +16,15 @@ struct pack_header {
 };
 
 /*
- * Packed object index header
- *
- * struct pack_idx_header {
- *     uint32_t idx_signature;
- *     uint32_t idx_version;
- * };
- *
- * Note: this header isn't active yet.  In future versions of git
- * we may change the index file format.  At that time we would start
- * the first four bytes of the new index format with this signature,
- * as all older git binaries would find this value illegal and abort
- * reading the file.
+ * The first four bytes of index formats later than version 1 should
+ * start with this signature, as all older git binaries would find this
+ * value illegal and abort reading the file.
  *
  * This is the case because the number of objects in a packfile
  * cannot exceed 1,431,660,000 as every object would need at least
- * 3 bytes of data and the overall packfile cannot exceed 4 GiB due
- * to the 32 bit offsets used by the index.  Clearly the signature
- * exceeds this maximum.
+ * 3 bytes of data and the overall packfile cannot exceed 4 GiB with
+ * version 1 of the index file due to the offsets limited to 32 bits.
+ * Clearly the signature exceeds this maximum.
  *
  * Very old git binaries will also compare the first 4 bytes to the
  * next 4 bytes in the index and abort with a "non-monotonic index"
@@ -43,6 +34,15 @@ struct pack_header {
  */
 #define PACK_IDX_SIGNATURE 0xff744f63  /* "\377tOc" */
 
+/*
+ * Packed object index header
+ */
+struct pack_idx_header {
+       uint32_t idx_signature;
+       uint32_t idx_version;
+};
+
+
 extern int verify_pack(struct packed_git *, int);
 
 #define PH_ERROR_EOF           (-1)
index 099beda873e91ebacf1068531fe194fa041ed9d6..17d004e5a0a19dc59b928a96a71d1470deb06e53 100644 (file)
@@ -6,11 +6,15 @@ makfile:=perl.mak
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 prefix_SQ = $(subst ','\'',$(prefix))
 
+ifndef V
+       QUIET = @
+endif
+
 all install instlibdir: $(makfile)
-       $(MAKE) -f $(makfile) $@
+       $(QUIET)$(MAKE) -f $(makfile) $@
 
 clean:
-       test -f $(makfile) && $(MAKE) -f $(makfile) $@ || exit 0
+       $(QUIET)test -f $(makfile) && $(MAKE) -f $(makfile) $@ || exit 0
        $(RM) ppport.h
        $(RM) $(makfile)
        $(RM) $(makfile).old
index 01760d70462927ad33c7976a50e31372863a45f9..ff3dd34962ec69320a67a4823b844755ebfe0e7d 100644 (file)
@@ -42,8 +42,7 @@ static void process_tree(struct tree *tree,
        me.elem = name;
        me.elem_len = strlen(name);
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &entry)) {
                if (S_ISDIR(entry.mode))
index 6339a278da1ae1b323b5abf7d2604c7afdfde4e4..54573ce2ee3b2c70d5419716b20ade61683bc289 100644 (file)
@@ -24,8 +24,6 @@ unsigned int active_nr, active_alloc, active_cache_changed;
 
 struct cache_tree *active_cache_tree;
 
-int cache_errno;
-
 static void *cache_mmap;
 static size_t cache_mmap_size;
 
@@ -327,7 +325,7 @@ int remove_file_from_cache(const char *path)
        return 0;
 }
 
-int add_file_to_index(const char *path, int verbose)
+int add_file_to_cache(const char *path, int verbose)
 {
        int size, namelen;
        struct stat st;
@@ -487,6 +485,8 @@ static int has_file_name(const struct cache_entry *ce, int pos, int ok_to_replac
                        continue;
                if (p->name[len] != '/')
                        continue;
+               if (!ce_stage(p) && !p->ce_mode)
+                       continue;
                retval = -1;
                if (!ok_to_replace)
                        break;
@@ -519,26 +519,37 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
 
                pos = cache_name_pos(name, ntohs(create_ce_flags(len, stage)));
                if (pos >= 0) {
-                       retval = -1;
-                       if (!ok_to_replace)
-                               break;
-                       remove_cache_entry_at(pos);
-                       continue;
+                       /*
+                        * Found one, but not so fast.  This could
+                        * be a marker that says "I was here, but
+                        * I am being removed".  Such an entry is
+                        * not a part of the resulting tree, and
+                        * it is Ok to have a directory at the same
+                        * path.
+                        */
+                       if (stage || active_cache[pos]->ce_mode) {
+                               retval = -1;
+                               if (!ok_to_replace)
+                                       break;
+                               remove_cache_entry_at(pos);
+                               continue;
+                       }
                }
+               else
+                       pos = -pos-1;
 
                /*
                 * Trivial optimization: if we find an entry that
                 * already matches the sub-directory, then we know
                 * we're ok, and we can exit.
                 */
-               pos = -pos-1;
                while (pos < active_nr) {
                        struct cache_entry *p = active_cache[pos];
                        if ((ce_namelen(p) <= len) ||
                            (p->name[len] != '/') ||
                            memcmp(p->name, name, len))
                                break; /* not our subdirectory */
-                       if (ce_stage(p) == stage)
+                       if (ce_stage(p) == stage && (stage || p->ce_mode))
                                /* p is at the same stage as our entry, and
                                 * is a subdirectory of what we are looking
                                 * at, so we cannot have conflicts at our
@@ -562,12 +573,21 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
  */
 static int check_file_directory_conflict(const struct cache_entry *ce, int pos, int ok_to_replace)
 {
+       int retval;
+
+       /*
+        * When ce is an "I am going away" entry, we allow it to be added
+        */
+       if (!ce_stage(ce) && !ce->ce_mode)
+               return 0;
+
        /*
         * We check if the path is a sub-path of a subsequent pathname
         * first, since removing those will not change the position
-        * in the array
+        * in the array.
         */
-       int retval = has_file_name(ce, pos, ok_to_replace);
+       retval = has_file_name(ce, pos, ok_to_replace);
+
        /*
         * Then check if the path might have a clashing sub-directory
         * before it.
@@ -643,14 +663,15 @@ int add_cache_entry(struct cache_entry *ce, int option)
  * For example, you'd want to do this after doing a "git-read-tree",
  * to link up the stat cache details with the proper files.
  */
-struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
+static struct cache_entry *refresh_cache_ent(struct cache_entry *ce, int really, int *err)
 {
        struct stat st;
        struct cache_entry *updated;
        int changed, size;
 
        if (lstat(ce->name, &st) < 0) {
-               cache_errno = errno;
+               if (err)
+                       *err = errno;
                return NULL;
        }
 
@@ -664,7 +685,8 @@ struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
        }
 
        if (ce_modified(ce, &st, really)) {
-               cache_errno = EINVAL;
+               if (err)
+                       *err = EINVAL;
                return NULL;
        }
 
@@ -696,6 +718,8 @@ int refresh_cache(unsigned int flags)
 
        for (i = 0; i < active_nr; i++) {
                struct cache_entry *ce, *new;
+               int cache_errno = 0;
+
                ce = active_cache[i];
                if (ce_stage(ce)) {
                        while ((i < active_nr) &&
@@ -709,7 +733,7 @@ int refresh_cache(unsigned int flags)
                        continue;
                }
 
-               new = refresh_cache_entry(ce, really);
+               new = refresh_cache_ent(ce, really, &cache_errno);
                if (new == ce)
                        continue;
                if (!new) {
@@ -737,6 +761,11 @@ int refresh_cache(unsigned int flags)
        return has_errors;
 }
 
+struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
+{
+       return refresh_cache_ent(ce, really, NULL);
+}
+
 static int verify_hdr(struct cache_header *hdr, unsigned long size)
 {
        SHA_CTX c;
index 675c88f4924086667deddc945011f6037ee8a8eb..26aa26bcb5089adcf400d12b673519e328b49a23 100644 (file)
@@ -67,47 +67,11 @@ struct command {
 
 static struct command *commands;
 
-static const char update_hook[] = "hooks/update";
 static const char pre_receive_hook[] = "hooks/pre-receive";
 static const char post_receive_hook[] = "hooks/post-receive";
 
-static int run_hook(const char *hook_name,
-       struct command *first_cmd,
-       int single)
+static int hook_status(int code, const char *hook_name)
 {
-       struct command *cmd;
-       int argc, code;
-       const char **argv;
-
-       for (argc = 0, cmd = first_cmd; cmd; cmd = cmd->next) {
-               if (!cmd->error_string)
-                       argc += 3;
-               if (single)
-                       break;
-       }
-
-       if (!argc || access(hook_name, X_OK) < 0)
-               return 0;
-
-       argv = xmalloc(sizeof(*argv) * (2 + argc));
-       argv[0] = hook_name;
-       for (argc = 1, cmd = first_cmd; cmd; cmd = cmd->next) {
-               if (!cmd->error_string) {
-                       argv[argc++] = xstrdup(cmd->ref_name);
-                       argv[argc++] = xstrdup(sha1_to_hex(cmd->old_sha1));
-                       argv[argc++] = xstrdup(sha1_to_hex(cmd->new_sha1));
-               }
-               if (single)
-                       break;
-       }
-       argv[argc] = NULL;
-
-       code = run_command_v_opt(argv,
-               RUN_COMMAND_NO_STDIN | RUN_COMMAND_STDOUT_TO_STDERR);
-       while (--argc > 0)
-               free((char*)argv[argc]);
-       free(argv);
-
        switch (code) {
        case 0:
                return 0;
@@ -115,6 +79,8 @@ static int run_hook(const char *hook_name,
                return error("hook fork failed");
        case -ERR_RUN_COMMAND_EXEC:
                return error("hook execute failed");
+       case -ERR_RUN_COMMAND_PIPE:
+               return error("hook pipe failed");
        case -ERR_RUN_COMMAND_WAITPID:
                return error("waitpid failed");
        case -ERR_RUN_COMMAND_WAITPID_WRONG_PID:
@@ -129,6 +95,69 @@ static int run_hook(const char *hook_name,
        }
 }
 
+static int run_hook(const char *hook_name)
+{
+       static char buf[sizeof(commands->old_sha1) * 2 + PATH_MAX + 4];
+       struct command *cmd;
+       struct child_process proc;
+       const char *argv[2];
+       int have_input = 0, code;
+
+       for (cmd = commands; !have_input && cmd; cmd = cmd->next) {
+               if (!cmd->error_string)
+                       have_input = 1;
+       }
+
+       if (!have_input || access(hook_name, X_OK) < 0)
+               return 0;
+
+       argv[0] = hook_name;
+       argv[1] = NULL;
+
+       memset(&proc, 0, sizeof(proc));
+       proc.argv = argv;
+       proc.in = -1;
+       proc.stdout_to_stderr = 1;
+
+       code = start_command(&proc);
+       if (code)
+               return hook_status(code, hook_name);
+       for (cmd = commands; cmd; cmd = cmd->next) {
+               if (!cmd->error_string) {
+                       size_t n = snprintf(buf, sizeof(buf), "%s %s %s\n",
+                               sha1_to_hex(cmd->old_sha1),
+                               sha1_to_hex(cmd->new_sha1),
+                               cmd->ref_name);
+                       if (write_in_full(proc.in, buf, n) != n)
+                               break;
+               }
+       }
+       return hook_status(finish_command(&proc), hook_name);
+}
+
+static int run_update_hook(struct command *cmd)
+{
+       static const char update_hook[] = "hooks/update";
+       struct child_process proc;
+       const char *argv[5];
+
+       if (access(update_hook, X_OK) < 0)
+               return 0;
+
+       argv[0] = update_hook;
+       argv[1] = cmd->ref_name;
+       argv[2] = sha1_to_hex(cmd->old_sha1);
+       argv[3] = sha1_to_hex(cmd->new_sha1);
+       argv[4] = NULL;
+
+       memset(&proc, 0, sizeof(proc));
+       proc.argv = argv;
+       proc.no_stdin = 1;
+       proc.stdout_to_stderr = 1;
+
+       return hook_status(run_command(&proc), update_hook);
+}
+
 static const char *update(struct command *cmd)
 {
        const char *name = cmd->ref_name;
@@ -165,7 +194,7 @@ static const char *update(struct command *cmd)
                        return "non-fast forward";
                }
        }
-       if (run_hook(update_hook, cmd, 1)) {
+       if (run_update_hook(cmd)) {
                error("hook declined to update %s", name);
                return "hook declined";
        }
@@ -238,7 +267,7 @@ static void execute_commands(const char *unpacker_error)
                return;
        }
 
-       if (run_hook(pre_receive_hook, commands, 0)) {
+       if (run_hook(pre_receive_hook)) {
                while (cmd) {
                        cmd->error_string = "pre-receive hook declined";
                        cmd = cmd->next;
@@ -353,10 +382,10 @@ static const char *unpack(void)
                }
        } else {
                const char *keeper[6];
-               int fd[2], s, len, status;
-               pid_t pid;
+               int s, len, status;
                char keep_arg[256];
                char packname[46];
+               struct child_process ip;
 
                s = sprintf(keep_arg, "--keep=receive-pack %i on ", getpid());
                if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
@@ -368,20 +397,12 @@ static const char *unpack(void)
                keeper[3] = hdr_arg;
                keeper[4] = keep_arg;
                keeper[5] = NULL;
-
-               if (pipe(fd) < 0)
-                       return "index-pack pipe failed";
-               pid = fork();
-               if (pid < 0)
+               memset(&ip, 0, sizeof(ip));
+               ip.argv = keeper;
+               ip.out = -1;
+               ip.git_cmd = 1;
+               if (start_command(&ip))
                        return "index-pack fork failed";
-               if (!pid) {
-                       dup2(fd[1], 1);
-                       close(fd[1]);
-                       close(fd[0]);
-                       execv_git_cmd(keeper);
-                       die("execv of index-pack failed");
-               }
-               close(fd[1]);
 
                /*
                 * The first thing we expects from index-pack's output
@@ -391,9 +412,8 @@ static const char *unpack(void)
                 * later on.  If we don't get that then tough luck with it.
                 */
                for (len = 0;
-                    len < 46 && (s = xread(fd[0], packname+len, 46-len)) > 0;
+                    len < 46 && (s = xread(ip.out, packname+len, 46-len)) > 0;
                     len += s);
-               close(fd[0]);
                if (len == 46 && packname[45] == '\n' &&
                    memcmp(packname, "keep\t", 5) == 0) {
                        char path[PATH_MAX];
@@ -403,14 +423,8 @@ static const char *unpack(void)
                        pack_lockfile = xstrdup(path);
                }
 
-               /* Then wrap our index-pack process. */
-               while (waitpid(pid, &status, 0) < 0)
-                       if (errno != EINTR)
-                               return "waitpid failed";
-               if (WIFEXITED(status)) {
-                       int code = WEXITSTATUS(status);
-                       if (code)
-                               return "index-pack exited with error code";
+               status = finish_command(&ip);
+               if (!status) {
                        reprepare_packed_git();
                        return NULL;
                }
@@ -493,7 +507,7 @@ int main(int argc, char **argv)
                        unlink(pack_lockfile);
                if (report_status)
                        report(unpack_status);
-               run_hook(post_receive_hook, commands, 0);
+               run_hook(post_receive_hook);
                run_update_post_hook(commands);
        }
        return 0;
diff --git a/refs.c b/refs.c
index 76c08d03602554a77fcf48a488b0d7fceb41073c..d2b7b7fb56f76294bb48526496429968d86e49b2 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -828,16 +828,6 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
                goto rollback;
        }
 
-       if (!prefixcmp(oldref, "refs/heads/") &&
-                       !prefixcmp(newref, "refs/heads/")) {
-               char oldsection[1024], newsection[1024];
-
-               snprintf(oldsection, 1024, "branch.%s", oldref + 11);
-               snprintf(newsection, 1024, "branch.%s", newref + 11);
-               if (git_config_rename_section(oldsection, newsection) < 0)
-                       return 1;
-       }
-
        return 0;
 
  rollback:
@@ -921,6 +911,8 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
                                     log_file, strerror(errno));
        }
 
+       adjust_shared_perm(log_file);
+
        msglen = 0;
        if (msg) {
                /* clean up the message and make sure it is a single line */
@@ -978,6 +970,27 @@ int write_ref_sha1(struct ref_lock *lock,
                unlock_ref(lock);
                return -1;
        }
+       if (strcmp(lock->orig_ref_name, "HEAD") != 0) {
+               /*
+                * Special hack: If a branch is updated directly and HEAD
+                * points to it (may happen on the remote side of a push
+                * for example) then logically the HEAD reflog should be
+                * updated too.
+                * A generic solution implies reverse symref information,
+                * but finding all symrefs pointing to the given branch
+                * would be rather costly for this rare event (the direct
+                * update of a branch) to be worth it.  So let's cheat and
+                * check with HEAD only which should cover 99% of all usage
+                * scenarios (even 100% of the default ones).
+                */
+               unsigned char head_sha1[20];
+               int head_flag;
+               const char *head_ref;
+               head_ref = resolve_ref("HEAD", head_sha1, 1, &head_flag);
+               if (head_ref && (head_flag & REF_ISSYMREF) &&
+                   !strcmp(head_ref, lock->ref_name))
+                       log_ref_write("HEAD", lock->old_sha1, sha1, logmsg);
+       }
        if (commit_lock_file(lock->lk)) {
                error("Couldn't set %s", lock->ref_name);
                unlock_ref(lock);
index f5b8ae4f031a059cff08328cf661515b9e68ccec..486393cb0835ce70f685d665b916e1b67974f184 100644 (file)
@@ -62,8 +62,7 @@ void mark_tree_uninteresting(struct tree *tree)
        if (parse_tree(tree) < 0)
                die("bad tree %s", sha1_to_hex(obj->sha1));
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
        while (tree_entry(&desc, &entry)) {
                if (S_ISDIR(entry.mode))
                        mark_tree_uninteresting(lookup_tree(entry.sha1));
@@ -213,6 +212,13 @@ static int everybody_uninteresting(struct commit_list *orig)
        return 1;
 }
 
+/*
+ * The goal is to get REV_TREE_NEW as the result only if the
+ * diff consists of all '+' (and no other changes), and
+ * REV_TREE_DIFFERENT otherwise (of course if the trees are
+ * the same we want REV_TREE_SAME).  That means that once we
+ * get to REV_TREE_DIFFERENT, we do not have to look any further.
+ */
 static int tree_difference = REV_TREE_SAME;
 
 static void file_add_remove(struct diff_options *options,
@@ -236,6 +242,8 @@ static void file_add_remove(struct diff_options *options,
                diff = REV_TREE_NEW;
        }
        tree_difference = diff;
+       if (tree_difference == REV_TREE_DIFFERENT)
+               options->has_changes = 1;
 }
 
 static void file_change(struct diff_options *options,
@@ -245,6 +253,7 @@ static void file_change(struct diff_options *options,
                 const char *base, const char *path)
 {
        tree_difference = REV_TREE_DIFFERENT;
+       options->has_changes = 1;
 }
 
 int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree *t2)
@@ -254,6 +263,7 @@ int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree *t2)
        if (!t2)
                return REV_TREE_DIFFERENT;
        tree_difference = REV_TREE_SAME;
+       revs->pruning.has_changes = 0;
        if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "",
                           &revs->pruning) < 0)
                return REV_TREE_DIFFERENT;
@@ -264,24 +274,24 @@ int rev_same_tree_as_empty(struct rev_info *revs, struct tree *t1)
 {
        int retval;
        void *tree;
+       unsigned long size;
        struct tree_desc empty, real;
 
        if (!t1)
                return 0;
 
-       tree = read_object_with_reference(t1->object.sha1, tree_type, &real.size, NULL);
+       tree = read_object_with_reference(t1->object.sha1, tree_type, &size, NULL);
        if (!tree)
                return 0;
-       real.buf = tree;
-
-       empty.buf = "";
-       empty.size = 0;
+       init_tree_desc(&real, tree, size);
+       init_tree_desc(&empty, "", 0);
 
-       tree_difference = 0;
+       tree_difference = REV_TREE_SAME;
+       revs->pruning.has_changes = 0;
        retval = diff_tree(&empty, &real, "", &revs->pruning);
        free(tree);
 
-       return retval >= 0 && !tree_difference;
+       return retval >= 0 && (tree_difference == REV_TREE_SAME);
 }
 
 static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
@@ -350,6 +360,7 @@ static void add_parents_to_list(struct rev_info *revs, struct commit *commit, st
 {
        struct commit_list *parent = commit->parents;
        unsigned left_flag;
+       int add, rest;
 
        if (commit->object.flags & ADDED)
                return;
@@ -395,18 +406,19 @@ static void add_parents_to_list(struct rev_info *revs, struct commit *commit, st
                return;
 
        left_flag = (commit->object.flags & SYMMETRIC_LEFT);
-       parent = commit->parents;
-       while (parent) {
+
+       rest = !revs->first_parent_only;
+       for (parent = commit->parents, add = 1; parent; add = rest) {
                struct commit *p = parent->item;
 
                parent = parent->next;
-
                parse_commit(p);
                p->object.flags |= left_flag;
                if (p->object.flags & SEEN)
                        continue;
                p->object.flags |= SEEN;
-               insert_by_date(p, list);
+               if (add)
+                       insert_by_date(p, list);
        }
 }
 
@@ -437,36 +449,6 @@ static void limit_list(struct rev_info *revs)
                        continue;
                p = &commit_list_insert(commit, p)->next;
        }
-       if (revs->boundary) {
-               /* mark the ones that are on the result list first */
-               for (list = newlist; list; list = list->next) {
-                       struct commit *commit = list->item;
-                       commit->object.flags |= TMP_MARK;
-               }
-               for (list = newlist; list; list = list->next) {
-                       struct commit *commit = list->item;
-                       struct object *obj = &commit->object;
-                       struct commit_list *parent;
-                       if (obj->flags & UNINTERESTING)
-                               continue;
-                       for (parent = commit->parents;
-                            parent;
-                            parent = parent->next) {
-                               struct commit *pcommit = parent->item;
-                               if (!(pcommit->object.flags & UNINTERESTING))
-                                       continue;
-                               pcommit->object.flags |= BOUNDARY;
-                               if (pcommit->object.flags & TMP_MARK)
-                                       continue;
-                               pcommit->object.flags |= TMP_MARK;
-                               p = &commit_list_insert(pcommit, p)->next;
-                       }
-               }
-               for (list = newlist; list; list = list->next) {
-                       struct commit *commit = list->item;
-                       commit->object.flags &= ~TMP_MARK;
-               }
-       }
        revs->commits = newlist;
 }
 
@@ -504,7 +486,7 @@ static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
                        add_pending_object(cb->all_revs, o, "");
                }
                else if (!cb->warned_bad_reflog) {
-                       warn("reflog of '%s' references pruned commits",
+                       warning("reflog of '%s' references pruned commits",
                                cb->name_for_errormsg);
                        cb->warned_bad_reflog = 1;
                }
@@ -575,6 +557,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
        revs->ignore_merges = 1;
        revs->simplify_history = 1;
        revs->pruning.recursive = 1;
+       revs->pruning.quiet = 1;
        revs->pruning.add_remove = file_add_remove;
        revs->pruning.change = file_change;
        revs->lifo = 1;
@@ -866,6 +849,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                                handle_all(revs, flags);
                                continue;
                        }
+                       if (!strcmp(arg, "--first-parent")) {
+                               revs->first_parent_only = 1;
+                               continue;
+                       }
                        if (!strcmp(arg, "--reflog")) {
                                handle_reflog(revs, flags);
                                continue;
@@ -1055,7 +1042,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                        if (!prefixcmp(arg, "--encoding=")) {
                                arg += 11;
                                if (strcmp(arg, "none"))
-                                       git_log_output_encoding = strdup(arg);
+                                       git_log_output_encoding = xstrdup(arg);
                                else
                                        git_log_output_encoding = "";
                                continue;
@@ -1193,17 +1180,6 @@ static void rewrite_parents(struct rev_info *revs, struct commit *commit)
        }
 }
 
-static void mark_boundary_to_show(struct commit *commit)
-{
-       struct commit_list *p = commit->parents;
-       while (p) {
-               commit = p->item;
-               p = p->next;
-               if (commit->object.flags & BOUNDARY)
-                       commit->object.flags |= BOUNDARY_SHOW;
-       }
-}
-
 static int commit_match(struct commit *commit, struct rev_info *opt)
 {
        if (!opt->grep_filter)
@@ -1235,15 +1211,9 @@ static struct commit *get_revision_1(struct rev_info *revs)
                 */
                if (!revs->limited) {
                        if (revs->max_age != -1 &&
-                           (commit->date < revs->max_age)) {
-                               if (revs->boundary)
-                                       commit->object.flags |=
-                                               BOUNDARY_SHOW | BOUNDARY;
-                               else
-                                       continue;
-                       } else
-                               add_parents_to_list(revs, commit,
-                                               &revs->commits);
+                           (commit->date < revs->max_age))
+                               continue;
+                       add_parents_to_list(revs, commit, &revs->commits);
                }
                if (commit->object.flags & SHOWN)
                        continue;
@@ -1252,18 +1222,6 @@ static struct commit *get_revision_1(struct rev_info *revs)
                                                    revs->ignore_packed))
                    continue;
 
-               /* We want to show boundary commits only when their
-                * children are shown.  When path-limiter is in effect,
-                * rewrite_parents() drops some commits from getting shown,
-                * and there is no point showing boundary parents that
-                * are not shown.  After rewrite_parents() rewrites the
-                * parents of a commit that is shown, we mark the boundary
-                * parents with BOUNDARY_SHOW.
-                */
-               if (commit->object.flags & BOUNDARY_SHOW) {
-                       commit->object.flags |= SHOWN;
-                       return commit;
-               }
                if (commit->object.flags & UNINTERESTING)
                        continue;
                if (revs->min_age != -1 && (commit->date > revs->min_age))
@@ -1286,80 +1244,136 @@ static struct commit *get_revision_1(struct rev_info *revs)
                        if (revs->parents)
                                rewrite_parents(revs, commit);
                }
-               if (revs->boundary)
-                       mark_boundary_to_show(commit);
-               commit->object.flags |= SHOWN;
                return commit;
        } while (revs->commits);
        return NULL;
 }
 
+static void gc_boundary(struct object_array *array)
+{
+       unsigned nr = array->nr;
+       unsigned alloc = array->alloc;
+       struct object_array_entry *objects = array->objects;
+
+       if (alloc <= nr) {
+               unsigned i, j;
+               for (i = j = 0; i < nr; i++) {
+                       if (objects[i].item->flags & SHOWN)
+                               continue;
+                       if (i != j)
+                               objects[j] = objects[i];
+                       j++;
+               }
+               for (i = j; i < nr; i++)
+                       objects[i].item = NULL;
+               array->nr = j;
+       }
+}
+
 struct commit *get_revision(struct rev_info *revs)
 {
        struct commit *c = NULL;
+       struct commit_list *l;
+
+       if (revs->boundary == 2) {
+               unsigned i;
+               struct object_array *array = &revs->boundary_commits;
+               struct object_array_entry *objects = array->objects;
+               for (i = 0; i < array->nr; i++) {
+                       c = (struct commit *)(objects[i].item);
+                       if (!c)
+                               continue;
+                       if (!(c->object.flags & CHILD_SHOWN))
+                               continue;
+                       if (!(c->object.flags & SHOWN))
+                               break;
+               }
+               if (array->nr <= i)
+                       return NULL;
 
-       if (revs->reverse) {
-               struct commit_list *list;
+               c->object.flags |= SHOWN | BOUNDARY;
+               return c;
+       }
 
-               /*
-                * rev_info.reverse is used to note the fact that we
-                * want to output the list of revisions in reverse
-                * order.  To accomplish this goal, reverse can have
-                * different values:
-                *
-                *  0  do nothing
-                *  1  reverse the list
-                *  2  internal use:  we have already obtained and
-                *     reversed the list, now we only need to yield
-                *     its items.
-                */
+       if (revs->reverse) {
+               int limit = -1;
 
-               if (revs->reverse == 1) {
-                       revs->reverse = 0;
-                       list = NULL;
-                       while ((c = get_revision(revs)))
-                               commit_list_insert(c, &list);
-                       revs->commits = list;
-                       revs->reverse = 2;
+               if (0 <= revs->max_count) {
+                       limit = revs->max_count;
+                       if (0 < revs->skip_count)
+                               limit += revs->skip_count;
                }
-
-               if (!revs->commits)
-                       return NULL;
-               c = revs->commits->item;
-               list = revs->commits->next;
-               free(revs->commits);
-               revs->commits = list;
-               return c;
+               l = NULL;
+               while ((c = get_revision_1(revs))) {
+                       commit_list_insert(c, &l);
+                       if ((0 < limit) && !--limit)
+                               break;
+               }
+               revs->commits = l;
+               revs->reverse = 0;
+               revs->max_count = -1;
+               c = NULL;
        }
 
-       if (0 < revs->skip_count) {
-               while ((c = get_revision_1(revs)) != NULL) {
-                       if (revs->skip_count-- <= 0)
+       /*
+        * Now pick up what they want to give us
+        */
+       c = get_revision_1(revs);
+       if (c) {
+               while (0 < revs->skip_count) {
+                       revs->skip_count--;
+                       c = get_revision_1(revs);
+                       if (!c)
                                break;
                }
        }
 
-       /* Check the max_count ... */
+       /*
+        * Check the max_count.
+        */
        switch (revs->max_count) {
        case -1:
                break;
        case 0:
-               if (revs->boundary) {
-                       struct commit_list *list = revs->commits;
-                       while (list) {
-                               list->item->object.flags |=
-                                       BOUNDARY_SHOW | BOUNDARY;
-                               list = list->next;
-                       }
-                       /* all remaining commits are boundary commits */
-                       revs->max_count = -1;
-                       revs->limited = 1;
-               } else
-                       return NULL;
+               c = NULL;
+               break;
        default:
                revs->max_count--;
        }
+
        if (c)
+               c->object.flags |= SHOWN;
+
+       if (!revs->boundary) {
                return c;
-       return get_revision_1(revs);
+       }
+
+       if (!c) {
+               /*
+                * get_revision_1() runs out the commits, and
+                * we are done computing the boundaries.
+                * switch to boundary commits output mode.
+                */
+               revs->boundary = 2;
+               return get_revision(revs);
+       }
+
+       /*
+        * boundary commits are the commits that are parents of the
+        * ones we got from get_revision_1() but they themselves are
+        * not returned from get_revision_1().  Before returning
+        * 'c', we need to mark its parents that they could be boundaries.
+        */
+
+       for (l = c->parents; l; l = l->next) {
+               struct object *p;
+               p = &(l->item->object);
+               if (p->flags & (CHILD_SHOWN | SHOWN))
+                       continue;
+               p->flags |= CHILD_SHOWN;
+               gc_boundary(&revs->boundary_commits);
+               add_object_array(p, NULL, &revs->boundary_commits);
+       }
+
+       return c;
 }
index 5fec1846f366f1aadabc6f57edcfd17828afa8ee..55e6b531ce3e5838f988ca1896484333e795f192 100644 (file)
@@ -7,7 +7,7 @@
 #define SHOWN          (1u<<3)
 #define TMP_MARK       (1u<<4) /* for isolated cases; clean after use */
 #define BOUNDARY       (1u<<5)
-#define BOUNDARY_SHOW  (1u<<6)
+#define CHILD_SHOWN    (1u<<6)
 #define ADDED          (1u<<7) /* Parents already parsed and added? */
 #define SYMMETRIC_LEFT (1u<<8)
 
@@ -21,6 +21,9 @@ struct rev_info {
        struct commit_list *commits;
        struct object_array pending;
 
+       /* Parents of shown commits */
+       struct object_array boundary_commits;
+
        /* Basic information */
        const char *prefix;
        void *prune_data;
@@ -40,10 +43,11 @@ struct rev_info {
                        edge_hint:1,
                        limited:1,
                        unpacked:1, /* see also ignore_packed below */
-                       boundary:1,
+                       boundary:2,
                        left_right:1,
                        parents:1,
-                       reverse:2;
+                       reverse:1,
+                       first_parent_only:1;
 
        /* Diff flags */
        unsigned int    diff:1,
@@ -74,6 +78,7 @@ struct rev_info {
        const char      *add_signoff;
        const char      *extra_headers;
        const char      *log_reencode;
+       int             no_inline;
 
        /* Filter by commit log message */
        struct grep_opt *grep_filter;
index cfbad74d145145944352c568064cc2f8c0d4c5cb..eff523e191b35385895f6b077fc76c7c21819012 100644 (file)
 #include "run-command.h"
 #include "exec_cmd.h"
 
-int run_command_v_opt(const char **argv, int flags)
+static inline void close_pair(int fd[2])
 {
-       pid_t pid = fork();
+       close(fd[0]);
+       close(fd[1]);
+}
+
+static inline void dup_devnull(int to)
+{
+       int fd = open("/dev/null", O_RDWR);
+       dup2(fd, to);
+       close(fd);
+}
+
+int start_command(struct child_process *cmd)
+{
+       int need_in, need_out;
+       int fdin[2], fdout[2];
+
+       need_in = !cmd->no_stdin && cmd->in < 0;
+       if (need_in) {
+               if (pipe(fdin) < 0)
+                       return -ERR_RUN_COMMAND_PIPE;
+               cmd->in = fdin[1];
+               cmd->close_in = 1;
+       }
 
-       if (pid < 0)
+       need_out = !cmd->no_stdout
+               && !cmd->stdout_to_stderr
+               && cmd->out < 0;
+       if (need_out) {
+               if (pipe(fdout) < 0) {
+                       if (need_in)
+                               close_pair(fdin);
+                       return -ERR_RUN_COMMAND_PIPE;
+               }
+               cmd->out = fdout[0];
+               cmd->close_out = 1;
+       }
+
+       cmd->pid = fork();
+       if (cmd->pid < 0) {
+               if (need_in)
+                       close_pair(fdin);
+               if (need_out)
+                       close_pair(fdout);
                return -ERR_RUN_COMMAND_FORK;
-       if (!pid) {
-               if (flags & RUN_COMMAND_NO_STDIN) {
-                       int fd = open("/dev/null", O_RDWR);
-                       dup2(fd, 0);
-                       close(fd);
+       }
+
+       if (!cmd->pid) {
+               if (cmd->no_stdin)
+                       dup_devnull(0);
+               else if (need_in) {
+                       dup2(fdin[0], 0);
+                       close_pair(fdin);
+               } else if (cmd->in) {
+                       dup2(cmd->in, 0);
+                       close(cmd->in);
                }
-               if (flags & RUN_COMMAND_STDOUT_TO_STDERR)
+
+               if (cmd->no_stdout)
+                       dup_devnull(1);
+               else if (cmd->stdout_to_stderr)
                        dup2(2, 1);
-               if (flags & RUN_GIT_CMD) {
-                       execv_git_cmd(argv);
+               else if (need_out) {
+                       dup2(fdout[1], 1);
+                       close_pair(fdout);
+               } else if (cmd->out > 1) {
+                       dup2(cmd->out, 1);
+                       close(cmd->out);
+               }
+
+               if (cmd->git_cmd) {
+                       execv_git_cmd(cmd->argv);
                } else {
-                       execvp(argv[0], (char *const*) argv);
+                       execvp(cmd->argv[0], (char *const*) cmd->argv);
                }
-               die("exec %s failed.", argv[0]);
+               die("exec %s failed.", cmd->argv[0]);
        }
+
+       if (need_in)
+               close(fdin[0]);
+       else if (cmd->in)
+               close(cmd->in);
+
+       if (need_out)
+               close(fdout[1]);
+       else if (cmd->out > 1)
+               close(cmd->out);
+
+       return 0;
+}
+
+int finish_command(struct child_process *cmd)
+{
+       if (cmd->close_in)
+               close(cmd->in);
+       if (cmd->close_out)
+               close(cmd->out);
+
        for (;;) {
                int status, code;
-               pid_t waiting = waitpid(pid, &status, 0);
+               pid_t waiting = waitpid(cmd->pid, &status, 0);
 
                if (waiting < 0) {
                        if (errno == EINTR)
@@ -33,7 +111,7 @@ int run_command_v_opt(const char **argv, int flags)
                        error("waitpid failed (%s)", strerror(errno));
                        return -ERR_RUN_COMMAND_WAITPID;
                }
-               if (waiting != pid)
+               if (waiting != cmd->pid)
                        return -ERR_RUN_COMMAND_WAITPID_WRONG_PID;
                if (WIFSIGNALED(status))
                        return -ERR_RUN_COMMAND_WAITPID_SIGNAL;
@@ -47,47 +125,21 @@ int run_command_v_opt(const char **argv, int flags)
        }
 }
 
-int run_command_v(const char **argv)
-{
-       return run_command_v_opt(argv, 0);
-}
-
-static int run_command_va_opt(int opt, const char *cmd, va_list param)
-{
-       int argc;
-       const char *argv[MAX_RUN_COMMAND_ARGS];
-       const char *arg;
-
-       argv[0] = (char*) cmd;
-       argc = 1;
-       while (argc < MAX_RUN_COMMAND_ARGS) {
-               arg = argv[argc++] = va_arg(param, char *);
-               if (!arg)
-                       break;
-       }
-       if (MAX_RUN_COMMAND_ARGS <= argc)
-               return error("too many args to run %s", cmd);
-       return run_command_v_opt(argv, opt);
-}
-
-int run_command_opt(int opt, const char *cmd, ...)
+int run_command(struct child_process *cmd)
 {
-       va_list params;
-       int r;
-
-       va_start(params, cmd);
-       r = run_command_va_opt(opt, cmd, params);
-       va_end(params);
-       return r;
+       int code = start_command(cmd);
+       if (code)
+               return code;
+       return finish_command(cmd);
 }
 
-int run_command(const char *cmd, ...)
+int run_command_v_opt(const char **argv, int opt)
 {
-       va_list params;
-       int r;
-
-       va_start(params, cmd);
-       r = run_command_va_opt(0, cmd, params);
-       va_end(params);
-       return r;
+       struct child_process cmd;
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.argv = argv;
+       cmd.no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
+       cmd.git_cmd = opt & RUN_GIT_CMD ? 1 : 0;
+       cmd.stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
+       return run_command(&cmd);
 }
index 59c4476ced789441eea3f68bfc7377e7e15e9b14..3680ef9d452490c67788b0ab027839a8383ed855 100644 (file)
@@ -1,22 +1,36 @@
 #ifndef RUN_COMMAND_H
 #define RUN_COMMAND_H
 
-#define MAX_RUN_COMMAND_ARGS 256
 enum {
        ERR_RUN_COMMAND_FORK = 10000,
        ERR_RUN_COMMAND_EXEC,
+       ERR_RUN_COMMAND_PIPE,
        ERR_RUN_COMMAND_WAITPID,
        ERR_RUN_COMMAND_WAITPID_WRONG_PID,
        ERR_RUN_COMMAND_WAITPID_SIGNAL,
        ERR_RUN_COMMAND_WAITPID_NOEXIT,
 };
 
+struct child_process {
+       const char **argv;
+       pid_t pid;
+       int in;
+       int out;
+       unsigned close_in:1;
+       unsigned close_out:1;
+       unsigned no_stdin:1;
+       unsigned no_stdout:1;
+       unsigned git_cmd:1; /* if this is to be git sub-command */
+       unsigned stdout_to_stderr:1;
+};
+
+int start_command(struct child_process *);
+int finish_command(struct child_process *);
+int run_command(struct child_process *);
+
 #define RUN_COMMAND_NO_STDIN 1
 #define RUN_GIT_CMD         2  /*If this is to be git sub-command */
 #define RUN_COMMAND_STDOUT_TO_STDERR 4
 int run_command_v_opt(const char **argv, int opt);
-int run_command_v(const char **argv);
-int run_command_opt(int opt, const char *cmd, ...);
-int run_command(const char *cmd, ...);
 
 #endif
index 512b660e99f26e391df34d48e1aebc9c6c3250e7..d5b51628dfbcc44b22b5069df19eeac67dda1e57 100644 (file)
@@ -3,7 +3,7 @@
 #include "tag.h"
 #include "refs.h"
 #include "pkt-line.h"
-#include "exec_cmd.h"
+#include "run-command.h"
 
 static const char send_pack_usage[] =
 "git-send-pack [--all] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
@@ -19,46 +19,35 @@ static int use_thin_pack;
  */
 static int pack_objects(int fd, struct ref *refs)
 {
-       int pipe_fd[2];
-       pid_t pid;
-
-       if (pipe(pipe_fd) < 0)
-               return error("send-pack: pipe failed");
-       pid = fork();
-       if (pid < 0)
-               return error("send-pack: unable to fork git-pack-objects");
-       if (!pid) {
-               /*
-                * The child becomes pack-objects --revs; we feed
-                * the revision parameters to it via its stdin and
-                * let its stdout go back to the other end.
-                */
-               static const char *args[] = {
-                       "pack-objects",
-                       "--all-progress",
-                       "--revs",
-                       "--stdout",
-                       NULL,
-                       NULL,
-               };
-               if (use_thin_pack)
-                       args[4] = "--thin";
-               dup2(pipe_fd[0], 0);
-               dup2(fd, 1);
-               close(pipe_fd[0]);
-               close(pipe_fd[1]);
-               close(fd);
-               execv_git_cmd(args);
-               die("git-pack-objects exec failed (%s)", strerror(errno));
-       }
+       /*
+        * The child becomes pack-objects --revs; we feed
+        * the revision parameters to it via its stdin and
+        * let its stdout go back to the other end.
+        */
+       const char *args[] = {
+               "pack-objects",
+               "--all-progress",
+               "--revs",
+               "--stdout",
+               NULL,
+               NULL,
+       };
+       struct child_process po;
+
+       if (use_thin_pack)
+               args[4] = "--thin";
+       memset(&po, 0, sizeof(po));
+       po.argv = args;
+       po.in = -1;
+       po.out = fd;
+       po.git_cmd = 1;
+       if (start_command(&po))
+               die("git-pack-objects failed (%s)", strerror(errno));
 
        /*
         * We feed the pack-objects we just spawned with revision
         * parameters by writing to the pipe.
         */
-       close(pipe_fd[0]);
-       close(fd);
-
        while (refs) {
                char buf[42];
 
@@ -67,38 +56,23 @@ static int pack_objects(int fd, struct ref *refs)
                        memcpy(buf + 1, sha1_to_hex(refs->old_sha1), 40);
                        buf[0] = '^';
                        buf[41] = '\n';
-                       if (!write_or_whine(pipe_fd[1], buf, 42,
+                       if (!write_or_whine(po.in, buf, 42,
                                                "send-pack: send refs"))
                                break;
                }
                if (!is_null_sha1(refs->new_sha1)) {
                        memcpy(buf, sha1_to_hex(refs->new_sha1), 40);
                        buf[40] = '\n';
-                       if (!write_or_whine(pipe_fd[1], buf, 41,
+                       if (!write_or_whine(po.in, buf, 41,
                                                "send-pack: send refs"))
                                break;
                }
                refs = refs->next;
        }
-       close(pipe_fd[1]);
-
-       for (;;) {
-               int status, code;
-               pid_t waiting = waitpid(pid, &status, 0);
 
-               if (waiting < 0) {
-                       if (errno == EINTR)
-                               continue;
-                       return error("waitpid failed (%s)", strerror(errno));
-               }
-               if ((waiting != pid) || WIFSIGNALED(status) ||
-                   !WIFEXITED(status))
-                       return error("pack-objects died with strange error");
-               code = WEXITSTATUS(status);
-               if (code)
-                       return -code;
-               return 0;
-       }
+       if (finish_command(&po))
+               return error("pack-objects died with strange error");
+       return 0;
 }
 
 static void unmark_and_free(struct commit_list *list, unsigned int mark)
diff --git a/setup.c b/setup.c
index dda67d268dcacce2293d245395a38106860fb881..a45ea8309a9773160597f142f1208a6129885499 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -216,7 +216,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
                die("Not a git repository: '%s'", gitdirenv);
        }
 
-       if (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/')
+       if (!getcwd(cwd, sizeof(cwd)-1) || cwd[0] != '/')
                die("Unable to read current working directory");
 
        offset = len = strlen(cwd);
index 219a10f403e0c3aa2f8d60ecde5807cf51d1a659..4304fe9bbc2b8e796e944fa7ddb2ea2791000adf 100644 (file)
@@ -432,16 +432,15 @@ void pack_report()
                pack_mapped, peak_pack_mapped);
 }
 
-static int check_packed_git_idx(const char *path,
-       unsigned long *idx_size_,
-       void **idx_map_)
+static int check_packed_git_idx(const char *path,  struct packed_git *p)
 {
        void *idx_map;
-       uint32_t *index;
+       struct pack_idx_header *hdr;
        size_t idx_size;
-       uint32_t nr, i;
+       uint32_t nr, i, *index;
        int fd = open(path, O_RDONLY);
        struct stat st;
+
        if (fd < 0)
                return -1;
        if (fstat(fd, &st)) {
@@ -456,15 +455,12 @@ static int check_packed_git_idx(const char *path,
        idx_map = xmmap(NULL, idx_size, PROT_READ, MAP_PRIVATE, fd, 0);
        close(fd);
 
-       index = idx_map;
-       *idx_map_ = idx_map;
-       *idx_size_ = idx_size;
-
        /* a future index format would start with this, as older git
         * binaries would fail the non-monotonic index check below.
         * give a nicer warning to the user if we can.
         */
-       if (index[0] == htonl(PACK_IDX_SIGNATURE)) {
+       hdr = idx_map;
+       if (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) {
                munmap(idx_map, idx_size);
                return error("index file %s is a newer version"
                        " and is not supported by this binary"
@@ -473,6 +469,7 @@ static int check_packed_git_idx(const char *path,
        }
 
        nr = 0;
+       index = idx_map;
        for (i = 0; i < 256; i++) {
                uint32_t n = ntohl(index[i]);
                if (n < nr) {
@@ -494,6 +491,9 @@ static int check_packed_git_idx(const char *path,
                return error("wrong index file size in %s", path);
        }
 
+       p->index_version = 1;
+       p->index_data = idx_map;
+       p->index_size = idx_size;
        return 0;
 }
 
@@ -614,7 +614,7 @@ static int open_packed_git_1(struct packed_git *p)
                return error("end of packfile %s is unavailable", p->pack_name);
        if (read_in_full(p->pack_fd, sha1, sizeof(sha1)) != sizeof(sha1))
                return error("packfile %s signature is unavailable", p->pack_name);
-       idx_sha1 = ((unsigned char *)p->index_base) + p->index_size - 40;
+       idx_sha1 = ((unsigned char *)p->index_data) + p->index_size - 40;
        if (hashcmp(sha1, idx_sha1))
                return error("packfile %s does not match index", p->pack_name);
        return 0;
@@ -710,37 +710,37 @@ unsigned char* use_pack(struct packed_git *p,
        return win->base + offset;
 }
 
-struct packed_git *add_packed_git(char *path, int path_len, int local)
+struct packed_git *add_packed_git(const char *path, int path_len, int local)
 {
        struct stat st;
-       struct packed_git *p;
-       unsigned long idx_size;
-       void *idx_map;
-       unsigned char sha1[20];
+       struct packed_git *p = xmalloc(sizeof(*p) + path_len + 2);
 
-       if (check_packed_git_idx(path, &idx_size, &idx_map))
+       /*
+        * Make sure a corresponding .pack file exists and that
+        * the index looks sane.
+        */
+       path_len -= strlen(".idx");
+       if (path_len < 1)
                return NULL;
-
-       /* do we have a corresponding .pack file? */
-       strcpy(path + path_len - 4, ".pack");
-       if (stat(path, &st) || !S_ISREG(st.st_mode)) {
-               munmap(idx_map, idx_size);
+       memcpy(p->pack_name, path, path_len);
+       strcpy(p->pack_name + path_len, ".pack");
+       if (stat(p->pack_name, &st) || !S_ISREG(st.st_mode) ||
+           check_packed_git_idx(path, p)) {
+               free(p);
                return NULL;
        }
+
        /* ok, it looks sane as far as we can check without
         * actually mapping the pack file.
         */
-       p = xmalloc(sizeof(*p) + path_len + 2);
-       strcpy(p->pack_name, path);
-       p->index_size = idx_size;
        p->pack_size = st.st_size;
-       p->index_base = idx_map;
        p->next = NULL;
        p->windows = NULL;
        p->pack_fd = -1;
        p->pack_local = local;
-       if ((path_len > 44) && !get_sha1_hex(path + path_len - 44, sha1))
-               hashcpy(p->sha1, sha1);
+       p->mtime = st.st_mtime;
+       if (path_len < 40 || get_sha1_hex(path + path_len - 40, p->sha1))
+               hashclr(p->sha1);
        return p;
 }
 
@@ -750,23 +750,19 @@ struct packed_git *parse_pack_index(unsigned char *sha1)
        return parse_pack_index_file(sha1, path);
 }
 
-struct packed_git *parse_pack_index_file(const unsigned char *sha1, char *idx_path)
+struct packed_git *parse_pack_index_file(const unsigned char *sha1,
+                                        const char *idx_path)
 {
-       struct packed_git *p;
-       unsigned long idx_size;
-       void *idx_map;
-       char *path;
+       const char *path = sha1_pack_name(sha1);
+       struct packed_git *p = xmalloc(sizeof(*p) + strlen(path) + 2);
 
-       if (check_packed_git_idx(idx_path, &idx_size, &idx_map))
+       if (check_packed_git_idx(idx_path, p)) {
+               free(p);
                return NULL;
+       }
 
-       path = sha1_pack_name(sha1);
-
-       p = xmalloc(sizeof(*p) + strlen(path) + 2);
        strcpy(p->pack_name, path);
-       p->index_size = idx_size;
        p->pack_size = 0;
-       p->index_base = idx_map;
        p->next = NULL;
        p->windows = NULL;
        p->pack_fd = -1;
@@ -823,6 +819,60 @@ static void prepare_packed_git_one(char *objdir, int local)
        closedir(dir);
 }
 
+static int sort_pack(const void *a_, const void *b_)
+{
+       struct packed_git *a = *((struct packed_git **)a_);
+       struct packed_git *b = *((struct packed_git **)b_);
+       int st;
+
+       /*
+        * Local packs tend to contain objects specific to our
+        * variant of the project than remote ones.  In addition,
+        * remote ones could be on a network mounted filesystem.
+        * Favor local ones for these reasons.
+        */
+       st = a->pack_local - b->pack_local;
+       if (st)
+               return -st;
+
+       /*
+        * Younger packs tend to contain more recent objects,
+        * and more recent objects tend to get accessed more
+        * often.
+        */
+       if (a->mtime < b->mtime)
+               return 1;
+       else if (a->mtime == b->mtime)
+               return 0;
+       return -1;
+}
+
+static void rearrange_packed_git(void)
+{
+       struct packed_git **ary, *p;
+       int i, n;
+
+       for (n = 0, p = packed_git; p; p = p->next)
+               n++;
+       if (n < 2)
+               return;
+
+       /* prepare an array of packed_git for easier sorting */
+       ary = xcalloc(n, sizeof(struct packed_git *));
+       for (n = 0, p = packed_git; p; p = p->next)
+               ary[n++] = p;
+
+       qsort(ary, n, sizeof(struct packed_git *), sort_pack);
+
+       /* link them back again */
+       for (i = 0; i < n - 1; i++)
+               ary[i]->next = ary[i + 1];
+       ary[n - 1]->next = NULL;
+       packed_git = ary[0];
+
+       free(ary);
+}
+
 static int prepare_packed_git_run_once = 0;
 void prepare_packed_git(void)
 {
@@ -837,6 +887,7 @@ void prepare_packed_git(void)
                prepare_packed_git_one(alt->base, 0);
                alt->name[-1] = '/';
        }
+       rearrange_packed_git();
        prepare_packed_git_run_once = 1;
 }
 
@@ -967,26 +1018,50 @@ static int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned lon
        return 0;
 }
 
-static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size)
+static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size, const unsigned char *sha1)
 {
        int bytes = strlen(buffer) + 1;
        unsigned char *buf = xmalloc(1+size);
        unsigned long n;
+       int status = Z_OK;
 
        n = stream->total_out - bytes;
        if (n > size)
                n = size;
        memcpy(buf, (char *) buffer + bytes, n);
        bytes = n;
-       if (bytes < size) {
+       if (bytes <= size) {
+               /*
+                * The above condition must be (bytes <= size), not
+                * (bytes < size).  In other words, even though we
+                * expect no more output and set avail_out to zer0,
+                * the input zlib stream may have bytes that express
+                * "this concludes the stream", and we *do* want to
+                * eat that input.
+                *
+                * Otherwise we would not be able to test that we
+                * consumed all the input to reach the expected size;
+                * we also want to check that zlib tells us that all
+                * went well with status == Z_STREAM_END at the end.
+                */
                stream->next_out = buf + bytes;
                stream->avail_out = size - bytes;
-               while (inflate(stream, Z_FINISH) == Z_OK)
-                       /* nothing */;
+               while (status == Z_OK)
+                       status = inflate(stream, Z_FINISH);
        }
        buf[size] = 0;
-       inflateEnd(stream);
-       return buf;
+       if (status == Z_STREAM_END && !stream->avail_in) {
+               inflateEnd(stream);
+               return buf;
+       }
+
+       if (status < 0)
+               error("corrupt loose object '%s'", sha1_to_hex(sha1));
+       else if (stream->avail_in)
+               error("garbage at end of loose object '%s'",
+                     sha1_to_hex(sha1));
+       free(buf);
+       return NULL;
 }
 
 /*
@@ -1040,7 +1115,7 @@ static int parse_sha1_header(const char *hdr, unsigned long *sizep)
        return *hdr ? -1 : type_from_string(type);
 }
 
-void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size)
+static void *unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size, const unsigned char *sha1)
 {
        int ret;
        z_stream stream;
@@ -1050,7 +1125,7 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type
        if (ret < Z_OK || (*type = parse_sha1_header(hdr, size)) < 0)
                return NULL;
 
-       return unpack_sha1_rest(&stream, hdr, *size);
+       return unpack_sha1_rest(&stream, hdr, *size, sha1);
 }
 
 static off_t get_delta_base(struct packed_git *p,
@@ -1290,6 +1365,110 @@ static void *unpack_compressed_entry(struct packed_git *p,
        return buffer;
 }
 
+#define MAX_DELTA_CACHE (256)
+
+static size_t delta_base_cached;
+
+static struct delta_base_cache_lru_list {
+       struct delta_base_cache_lru_list *prev;
+       struct delta_base_cache_lru_list *next;
+} delta_base_cache_lru = { &delta_base_cache_lru, &delta_base_cache_lru };
+
+static struct delta_base_cache_entry {
+       struct delta_base_cache_lru_list lru;
+       void *data;
+       struct packed_git *p;
+       off_t base_offset;
+       unsigned long size;
+       enum object_type type;
+} delta_base_cache[MAX_DELTA_CACHE];
+
+static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset)
+{
+       unsigned long hash;
+
+       hash = (unsigned long)p + (unsigned long)base_offset;
+       hash += (hash >> 8) + (hash >> 16);
+       return hash % MAX_DELTA_CACHE;
+}
+
+static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,
+       unsigned long *base_size, enum object_type *type, int keep_cache)
+{
+       void *ret;
+       unsigned long hash = pack_entry_hash(p, base_offset);
+       struct delta_base_cache_entry *ent = delta_base_cache + hash;
+
+       ret = ent->data;
+       if (ret && ent->p == p && ent->base_offset == base_offset)
+               goto found_cache_entry;
+       return unpack_entry(p, base_offset, type, base_size);
+
+found_cache_entry:
+       if (!keep_cache) {
+               ent->data = NULL;
+               ent->lru.next->prev = ent->lru.prev;
+               ent->lru.prev->next = ent->lru.next;
+               delta_base_cached -= ent->size;
+       }
+       else {
+               ret = xmalloc(ent->size + 1);
+               memcpy(ret, ent->data, ent->size);
+               ((char *)ret)[ent->size] = 0;
+       }
+       *type = ent->type;
+       *base_size = ent->size;
+       return ret;
+}
+
+static inline void release_delta_base_cache(struct delta_base_cache_entry *ent)
+{
+       if (ent->data) {
+               free(ent->data);
+               ent->data = NULL;
+               ent->lru.next->prev = ent->lru.prev;
+               ent->lru.prev->next = ent->lru.next;
+               delta_base_cached -= ent->size;
+       }
+}
+
+static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
+       void *base, unsigned long base_size, enum object_type type)
+{
+       unsigned long hash = pack_entry_hash(p, base_offset);
+       struct delta_base_cache_entry *ent = delta_base_cache + hash;
+       struct delta_base_cache_lru_list *lru;
+
+       release_delta_base_cache(ent);
+       delta_base_cached += base_size;
+
+       for (lru = delta_base_cache_lru.next;
+            delta_base_cached > delta_base_cache_limit
+            && lru != &delta_base_cache_lru;
+            lru = lru->next) {
+               struct delta_base_cache_entry *f = (void *)lru;
+               if (f->type == OBJ_BLOB)
+                       release_delta_base_cache(f);
+       }
+       for (lru = delta_base_cache_lru.next;
+            delta_base_cached > delta_base_cache_limit
+            && lru != &delta_base_cache_lru;
+            lru = lru->next) {
+               struct delta_base_cache_entry *f = (void *)lru;
+               release_delta_base_cache(f);
+       }
+
+       ent->p = p;
+       ent->base_offset = base_offset;
+       ent->type = type;
+       ent->data = base;
+       ent->size = base_size;
+       ent->lru.next = &delta_base_cache_lru;
+       ent->lru.prev = delta_base_cache_lru.prev;
+       delta_base_cache_lru.prev->next = &ent->lru;
+       delta_base_cache_lru.prev = &ent->lru;
+}
+
 static void *unpack_delta_entry(struct packed_git *p,
                                struct pack_window **w_curs,
                                off_t curpos,
@@ -1303,7 +1482,7 @@ static void *unpack_delta_entry(struct packed_git *p,
        off_t base_offset;
 
        base_offset = get_delta_base(p, w_curs, &curpos, *type, obj_offset);
-       base = unpack_entry(p, base_offset, type, &base_size);
+       base = cache_or_unpack_entry(p, base_offset, &base_size, type, 0);
        if (!base)
                die("failed to read delta base object"
                    " at %"PRIuMAX" from %s",
@@ -1316,7 +1495,7 @@ static void *unpack_delta_entry(struct packed_git *p,
        if (!result)
                die("failed to apply delta");
        free(delta_data);
-       free(base);
+       add_delta_base_cache(p, base_offset, base, base_size, *type);
        return result;
 }
 
@@ -1353,27 +1532,29 @@ uint32_t num_packed_objects(const struct packed_git *p)
        return (uint32_t)((p->index_size - 20 - 20 - 4*256) / 24);
 }
 
-int nth_packed_object_sha1(const struct packed_git *p, uint32_t n,
-                          unsigned char* sha1)
+const unsigned char *nth_packed_object_sha1(const struct packed_git *p,
+                                           uint32_t n)
 {
-       void *index = p->index_base + 256;
+       const unsigned char *index = p->index_data;
+       index += 4 * 256;
        if (num_packed_objects(p) <= n)
-               return -1;
-       hashcpy(sha1, (unsigned char *) index + (24 * n) + 4);
-       return 0;
+               return NULL;
+       return index + 24 * n + 4;
 }
 
 off_t find_pack_entry_one(const unsigned char *sha1,
                                  struct packed_git *p)
 {
-       uint32_t *level1_ofs = p->index_base;
+       const uint32_t *level1_ofs = p->index_data;
        int hi = ntohl(level1_ofs[*sha1]);
        int lo = ((*sha1 == 0x0) ? 0 : ntohl(level1_ofs[*sha1 - 1]));
-       void *index = p->index_base + 256;
+       const unsigned char *index = p->index_data;
+
+       index += 4 * 256;
 
        do {
                int mi = (lo + hi) / 2;
-               int cmp = hashcmp((unsigned char *)index + (24 * mi) + 4, sha1);
+               int cmp = hashcmp(index + 24 * mi + 4, sha1);
                if (!cmp)
                        return ntohl(*((uint32_t *)((char *)index + (24 * mi))));
                if (cmp > 0)
@@ -1497,7 +1678,7 @@ static void *read_packed_sha1(const unsigned char *sha1,
        if (!find_pack_entry(sha1, &e, NULL))
                return NULL;
        else
-               return unpack_entry(e.p, e.offset, type, size);
+               return cache_or_unpack_entry(e.p, e.offset, size, type, 1);
 }
 
 /*
@@ -1571,7 +1752,7 @@ void *read_sha1_file(const unsigned char *sha1, enum object_type *type,
                return buf;
        map = map_sha1_file(sha1, &mapsize);
        if (map) {
-               buf = unpack_sha1_file(map, mapsize, type, size);
+               buf = unpack_sha1_file(map, mapsize, type, size, sha1);
                munmap(map, mapsize);
                return buf;
        }
@@ -1626,7 +1807,7 @@ void *read_object_with_reference(const unsigned char *sha1,
        }
 }
 
-static void write_sha1_file_prepare(void *buf, unsigned long len,
+static void write_sha1_file_prepare(const void *buf, unsigned long len,
                                     const char *type, unsigned char *sha1,
                                     char *hdr, int *hdrlen)
 {
@@ -1754,7 +1935,7 @@ static void setup_object_header(z_stream *stream, const char *type, unsigned lon
        stream->avail_out -= hdrlen;
 }
 
-int hash_sha1_file(void *buf, unsigned long len, const char *type,
+int hash_sha1_file(const void *buf, unsigned long len, const char *type,
                    unsigned char *sha1)
 {
        char hdr[32];
@@ -1765,7 +1946,7 @@ int hash_sha1_file(void *buf, unsigned long len, const char *type,
 
 int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *returnsha1)
 {
-       int size;
+       int size, ret;
        unsigned char *compressed;
        z_stream stream;
        unsigned char sha1[20];
@@ -1797,7 +1978,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
                return error("sha1 file %s: %s\n", filename, strerror(errno));
        }
 
-       snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
+       snprintf(tmpfile, sizeof(tmpfile), "%s/tmp_obj_XXXXXX", get_object_directory());
 
        fd = mkstemp(tmpfile);
        if (fd < 0) {
@@ -1825,15 +2006,21 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
        /* Then the data itself.. */
        stream.next_in = buf;
        stream.avail_in = len;
-       while (deflate(&stream, Z_FINISH) == Z_OK)
-               /* nothing */;
-       deflateEnd(&stream);
+       ret = deflate(&stream, Z_FINISH);
+       if (ret != Z_STREAM_END)
+               die("unable to deflate new object %s (%d)", sha1_to_hex(sha1), ret);
+
+       ret = deflateEnd(&stream);
+       if (ret != Z_OK)
+               die("deflateEnd on object %s failed (%d)", sha1_to_hex(sha1), ret);
+
        size = stream.total_out;
 
        if (write_buffer(fd, compressed, size) < 0)
                die("unable to write sha1 file");
        fchmod(fd, 0444);
-       close(fd);
+       if (close(fd))
+               die("unable to write sha1 file");
        free(compressed);
 
        return move_temp_to_file(tmpfile, filename);
@@ -1918,7 +2105,7 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
        int ret;
        SHA_CTX c;
 
-       snprintf(tmpfile, sizeof(tmpfile), "%s/obj_XXXXXX", get_object_directory());
+       snprintf(tmpfile, sizeof(tmpfile), "%s/tmp_obj_XXXXXX", get_object_directory());
 
        local = mkstemp(tmpfile);
        if (local < 0) {
@@ -1967,7 +2154,9 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
        } while (1);
        inflateEnd(&stream);
 
-       close(local);
+       fchmod(local, 0444);
+       if (close(local) != 0)
+               die("unable to write sha1 file");
        SHA1_Final(real_sha1, &c);
        if (ret != Z_STREAM_END) {
                unlink(tmpfile);
index 31812d3d26c7b33eaf3fe76f3145fd1fc193366d..267ea3f3edc63600bc1591d2115ee85222f3e8c5 100644 (file)
@@ -71,7 +71,7 @@ static int match_sha(unsigned len, const unsigned char *a, const unsigned char *
 static int find_short_packed_object(int len, const unsigned char *match, unsigned char *sha1)
 {
        struct packed_git *p;
-       unsigned char found_sha1[20];
+       const unsigned char *found_sha1 = NULL;
        int found = 0;
 
        prepare_packed_git();
@@ -80,10 +80,10 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
                uint32_t first = 0, last = num;
                while (first < last) {
                        uint32_t mid = (first + last) / 2;
-                       unsigned char now[20];
+                       const unsigned char *now;
                        int cmp;
 
-                       nth_packed_object_sha1(p, mid, now);
+                       now = nth_packed_object_sha1(p, mid);
                        cmp = hashcmp(match, now);
                        if (!cmp) {
                                first = mid;
@@ -96,14 +96,14 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
                        last = mid;
                }
                if (first < num) {
-                       unsigned char now[20], next[20];
-                       nth_packed_object_sha1(p, first, now);
+                       const unsigned char *now, *next;
+                      now = nth_packed_object_sha1(p, first);
                        if (match_sha(len, match, now)) {
-                               if (nth_packed_object_sha1(p, first+1, next) ||
-                                   !match_sha(len, match, next)) {
+                               next = nth_packed_object_sha1(p, first+1);
+                              if (!next|| !match_sha(len, match, next)) {
                                        /* unique within this pack */
                                        if (!found) {
-                                               hashcpy(found_sha1, now);
+                                               found_sha1 = now;
                                                found++;
                                        }
                                        else if (hashcmp(found_sha1, now)) {
@@ -602,10 +602,10 @@ static int handle_one_ref(const char *path,
  */
 
 #define ONELINE_SEEN (1u<<20)
-int get_sha1_oneline(const char *prefix, unsigned char *sha1)
+static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 {
        struct commit_list *list = NULL, *backup = NULL, *l;
-       struct commit *commit;
+       int retval = -1;
 
        if (prefix[0] == '!') {
                if (prefix[1] != '!')
@@ -617,20 +617,24 @@ int get_sha1_oneline(const char *prefix, unsigned char *sha1)
        for_each_ref(handle_one_ref, &list);
        for (l = list; l; l = l->next)
                commit_list_insert(l->item, &backup);
-       while ((commit = pop_most_recent_commit(&list, ONELINE_SEEN))) {
+       while (list) {
                char *p;
+               struct commit *commit;
+
+               commit = pop_most_recent_commit(&list, ONELINE_SEEN);
                parse_object(commit->object.sha1);
                if (!commit->buffer || !(p = strstr(commit->buffer, "\n\n")))
                        continue;
                if (!prefixcmp(p + 2, prefix)) {
                        hashcpy(sha1, commit->object.sha1);
+                       retval = 0;
                        break;
                }
        }
        free_commit_list(list);
        for (l = backup; l; l = l->next)
                clear_commit_marks(l->item, ONELINE_SEEN);
-       return commit == NULL;
+       return retval;
 }
 
 /*
index 745a1b03116a58f89cc9ac533f948fa91c795518..4624fe654c2515afe14e9e05402ac9ce78322772 100755 (executable)
@@ -11,7 +11,7 @@ compare_diff_raw () {
 
     sed -e "$sanitize_diff_raw" <"$1" >.tmp-1
     sed -e "$sanitize_diff_raw" <"$2" >.tmp-2
-    diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
+    git diff .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
 }
 
 sanitize_diff_raw_z='/^:/s/ '"$_x40"' '"$_x40"' \([A-Z]\)[0-9]*$/ X X \1#/'
@@ -23,7 +23,7 @@ compare_diff_raw_z () {
 
     tr '\0' '\012' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
     tr '\0' '\012' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
-    diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
+    git diff .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
 }
 
 compare_diff_patch () {
@@ -37,5 +37,5 @@ compare_diff_patch () {
        /^[dis]*imilarity index [0-9]*%$/d
        /^index [0-9a-f]*\.\.[0-9a-f]/d
     ' <"$2" >.tmp-2
-    diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
+    git diff .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
 }
index d0af8c3d52573fea203aab13612a9103cca78dd9..e26a36cf0f4c113d916c2d23daf036e4844be053 100755 (executable)
@@ -131,7 +131,7 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
 
 check_result () {
     git-ls-files --stage | sed -e 's/ '"$_x40"' / X /' >current &&
-    diff -u expected current
+    git diff expected current
 }
 
 # This is done on an empty work directory, which is the normal
index 75e4c9a88657e4ea28e0b4dfb7cbb2c3eaaa2f3f..030226bbfbd764a21aa59577b365868237d4f40b 100755 (executable)
@@ -33,7 +33,7 @@ compare_change () {
            -e '/^--- /d; /^+++ /d; /^@@ /d;' \
            -e 's/^\([-+][0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /p' \
            "$1"
-       diff -u expected current
+       git diff expected current
 }
 
 check_cache_at () {
@@ -86,7 +86,7 @@ test_expect_success \
     'rm -f .git/index &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >1-3.out &&
-     diff -u M.out 1-3.out &&
+     git diff M.out 1-3.out &&
      check_cache_at bozbar dirty &&
      check_cache_at frotz dirty &&
      check_cache_at nitfol dirty'
@@ -101,7 +101,7 @@ test_expect_success \
      git-update-index --add yomin &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >4.out || return 1
-     diff -u M.out 4.out >4diff.out
+     git diff M.out 4.out >4diff.out
      compare_change 4diff.out expected &&
      check_cache_at yomin clean'
 
@@ -115,7 +115,7 @@ test_expect_success \
      echo yomin yomin >yomin &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >5.out || return 1
-     diff -u M.out 5.out >5diff.out
+     git diff M.out 5.out >5diff.out
      compare_change 5diff.out expected &&
      check_cache_at yomin dirty'
 
@@ -127,7 +127,7 @@ test_expect_success \
      git-update-index --add frotz &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >6.out &&
-     diff -u M.out 6.out &&
+     git diff M.out 6.out &&
      check_cache_at frotz clean'
 
 test_expect_success \
@@ -140,7 +140,7 @@ test_expect_success \
      echo frotz frotz >frotz &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >7.out &&
-     diff -u M.out 7.out &&
+     git diff M.out 7.out &&
      check_cache_at frotz dirty'
 
 test_expect_success \
@@ -171,7 +171,7 @@ test_expect_success \
      git-update-index --add rezrov &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >10.out &&
-     diff -u M.out 10.out'
+     git diff M.out 10.out'
 
 test_expect_success \
     '11 - dirty path removed.' \
@@ -216,7 +216,7 @@ test_expect_success \
      git-update-index --add nitfol &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >14.out || return 1
-     diff -u M.out 14.out >14diff.out
+     git diff M.out 14.out >14diff.out
      compare_change 14diff.out expected &&
      check_cache_at nitfol clean'
 
@@ -230,7 +230,7 @@ test_expect_success \
      echo nitfol nitfol nitfol >nitfol &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >15.out || return 1
-     diff -u M.out 15.out >15diff.out
+     git diff M.out 15.out >15diff.out
      compare_change 15diff.out expected &&
      check_cache_at nitfol dirty'
 
@@ -262,7 +262,7 @@ test_expect_success \
      git-update-index --add bozbar &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >18.out &&
-     diff -u M.out 18.out &&
+     git diff M.out 18.out &&
      check_cache_at bozbar clean'
 
 test_expect_success \
@@ -275,7 +275,7 @@ test_expect_success \
      echo gnusto gnusto >bozbar &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >19.out &&
-     diff -u M.out 19.out &&
+     git diff M.out 19.out &&
      check_cache_at bozbar dirty'
 
 test_expect_success \
@@ -287,7 +287,7 @@ test_expect_success \
      git-update-index --add bozbar &&
      read_tree_twoway $treeH $treeM &&
      git-ls-files --stage >20.out &&
-     diff -u M.out 20.out &&
+     git diff M.out 20.out &&
      check_cache_at bozbar dirty'
 
 test_expect_success \
@@ -337,7 +337,7 @@ test_expect_success \
      git-update-index --add DF &&
      read_tree_twoway $treeDF $treeDFDF &&
      git-ls-files --stage >DFDFcheck.out &&
-     diff -u DFDF.out DFDFcheck.out &&
+     git diff DFDF.out DFDFcheck.out &&
      check_cache_at DF/DF dirty &&
      :'
 
index da3c81357b8ffee7d6fc3f2d4301e9c3c9d076fd..87fe993f59e2b3843ea2abcd92a2bab77a392997 100755 (executable)
@@ -16,7 +16,7 @@ compare_change () {
        sed >current \
            -e '/^--- /d; /^+++ /d; /^@@ /d;' \
            -e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1"
-       diff -u expected current
+       git diff expected current
 }
 
 check_cache_at () {
index ee386cfbf3be4d457644103b223e1fcafaa363ba..78c2e0864f56ecf39e8738e8fecec9ca8dd4e8a2 100755 (executable)
@@ -368,12 +368,12 @@ cat > expect << EOF
 weird
 EOF
 
-test_expect_success "rename succeeded" "diff -u expect .git/config"
+test_expect_success "rename succeeded" "git diff expect .git/config"
 
 test_expect_failure "rename non-existing section" \
        'git-config --rename-section branch."world domination" branch.drei'
 
-test_expect_success "rename succeeded" "diff -u expect .git/config"
+test_expect_success "rename succeeded" "git diff expect .git/config"
 
 test_expect_success "rename another section" \
        'git-config --rename-section branch."1 234 blabl/a" branch.drei'
@@ -389,7 +389,7 @@ cat > expect << EOF
 weird
 EOF
 
-test_expect_success "rename succeeded" "diff -u expect .git/config"
+test_expect_success "rename succeeded" "git diff expect .git/config"
 
 cat >> .git/config << EOF
   [branch "zwei"] a = 1 [branch "vier"]
@@ -405,7 +405,7 @@ weird
 EOF
 
 test_expect_success "section was removed properly" \
-       "diff -u expect .git/config"
+       "git diff -u expect .git/config"
 
 test_expect_success numbers '
 
index 6979b7c1c05001d08ce94f9034580f94745b4924..db7a847a5dd13ece7a4ec22d795b8407631d7d4c 100755 (executable)
@@ -65,7 +65,7 @@ test_expect_success \
        --exclude-per-directory=.gitignore \
        --exclude-from=.git/ignore \
        >output &&
-     diff -u expect output'
+     git diff expect output'
 
 # Test \r\n (MSDOS-like systems)
 printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
@@ -77,6 +77,6 @@ test_expect_success \
        --exclude-per-directory=.gitignore \
        --exclude-from=.git/ignore \
        >output &&
-     diff -u expect output'
+     git diff expect output'
 
 test_done
index b42f1382bc9c585d12febcd99594f6ba7d7d743c..cc8967d76b10e18eb6b7db69fbb31baf702f2efc 100755 (executable)
@@ -23,7 +23,7 @@ test_expect_success \
 test_expect_success \
     'git-ls-files without path restriction.' \
     'git-ls-files --others >output &&
-     diff -u output - <<EOF
+     git diff output - <<EOF
 --
 -foo
 output
@@ -34,7 +34,7 @@ EOF
 test_expect_success \
     'git-ls-files with path restriction.' \
     'git-ls-files --others path0 >output &&
-       diff -u output - <<EOF
+       git diff output - <<EOF
 path0
 EOF
 '
@@ -42,7 +42,7 @@ EOF
 test_expect_success \
     'git-ls-files with path restriction with --.' \
     'git-ls-files --others -- path0 >output &&
-       diff -u output - <<EOF
+       git diff output - <<EOF
 path0
 EOF
 '
@@ -50,7 +50,7 @@ EOF
 test_expect_success \
     'git-ls-files with path restriction with -- --.' \
     'git-ls-files --others -- -- >output &&
-       diff -u output - <<EOF
+       git diff output - <<EOF
 --
 EOF
 '
@@ -58,7 +58,7 @@ EOF
 test_expect_success \
     'git-ls-files with no path restriction.' \
     'git-ls-files --others -- >output &&
-       diff -u output - <<EOF
+       git diff output - <<EOF
 --
 -foo
 output
index 2ec06d3d3979aad18b4594329e93407d33f8cae5..e10749245b454f4c71486e536049cbf5b09259d5 100755 (executable)
@@ -35,7 +35,7 @@ _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
 test_output () {
     sed -e "s/ $_x40   / X     /" <current >check
-    diff -u expected check
+    git diff expected check
 }
 
 test_expect_success \
index d78deb1e710056e236ba61f4b8ceb55e11c44cbf..087929a4bfdf053124f81af3bfb73ab1e9e1709a 100755 (executable)
@@ -43,7 +43,7 @@ _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
 test_output () {
     sed -e "s/ $_x40   / X     /" <current >check
-    diff -u expected check
+    git diff expected check
 }
 
 test_expect_success \
index 5565c27033ab89959f2a39dfa9abaea99e40432b..828d553a4b53210e9bd15c522e2a798901b2ac35 100755 (executable)
@@ -11,7 +11,7 @@ handled.  Specifically, that a bogus branch is not created.
 . ./test-lib.sh
 
 test_expect_success \
-    'prepare an trivial repository' \
+    'prepare a trivial repository' \
     'echo Hello > A &&
      git-update-index --add A &&
      git-commit -m "Initial commit." &&
@@ -47,17 +47,6 @@ test_expect_success \
         test ! -f .git/refs/heads/d/e/f &&
         test ! -f .git/logs/refs/heads/d/e/f'
 
-cat >expect <<EOF
-0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000     checkout: Created from master
-EOF
-test_expect_success \
-    'git checkout -b g/h/i -l should create a branch and a log' \
-       'GIT_COMMITTER_DATE="2005-05-26 23:30" \
-     git-checkout -b g/h/i -l master &&
-        test -f .git/refs/heads/g/h/i &&
-        test -f .git/logs/refs/heads/g/h/i &&
-        diff expect .git/logs/refs/heads/g/h/i'
-
 test_expect_success \
     'git branch j/k should work after branch j has been deleted' \
        'git-branch j &&
@@ -94,6 +83,15 @@ test_expect_failure \
          git-branch r &&
          git-branch -m q r/q'
 
+mv .git/config .git/config-saved
+
+test_expect_success 'git branch -m q q2 without config should succeed' '
+       git-branch -m q q2 &&
+       git-branch -m q2 q
+'
+
+mv .git/config-saved .git/config
+
 git-config branch.s/s.dummy Hello
 
 test_expect_success \
@@ -117,4 +115,64 @@ test_expect_failure \
      ln -s real-u .git/logs/refs/heads/u &&
      git-branch -m u v'
 
+test_expect_success 'test tracking setup via --track' \
+    'git-config remote.local.url . &&
+     git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+     (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
+     git-branch --track my1 local/master &&
+     test $(git-config branch.my1.remote) = local &&
+     test $(git-config branch.my1.merge) = refs/heads/master'
+
+test_expect_success 'test tracking setup (non-wildcard, matching)' \
+    'git-config remote.local.url . &&
+     git-config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
+     (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
+     git-branch --track my4 local/master &&
+     test $(git-config branch.my4.remote) = local &&
+     test $(git-config branch.my4.merge) = refs/heads/master'
+
+test_expect_success 'test tracking setup (non-wildcard, not matching)' \
+    'git-config remote.local.url . &&
+     git-config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
+     (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
+     git-branch --track my5 local/master &&
+     ! test $(git-config branch.my5.remote) = local &&
+     ! test $(git-config branch.my5.merge) = refs/heads/master'
+
+test_expect_success 'test tracking setup via config' \
+    'git-config branch.autosetupmerge true &&
+     git-config remote.local.url . &&
+     git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+     (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
+     git-branch my3 local/master &&
+     test $(git-config branch.my3.remote) = local &&
+     test $(git-config branch.my3.merge) = refs/heads/master'
+
+test_expect_success 'test overriding tracking setup via --no-track' \
+    'git-config branch.autosetupmerge true &&
+     git-config remote.local.url . &&
+     git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+     (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
+     git-branch --no-track my2 local/master &&
+     git-config branch.autosetupmerge false &&
+     ! test $(git-config branch.my2.remote) = local &&
+     ! test $(git-config branch.my2.merge) = refs/heads/master'
+
+test_expect_success 'test local tracking setup' \
+    'git branch --track my6 s &&
+     test $(git-config branch.my6.remote) = . &&
+     test $(git-config branch.my6.merge) = refs/heads/s'
+
+# Keep this test last, as it changes the current branch
+cat >expect <<EOF
+0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000     branch: Created from master
+EOF
+test_expect_success \
+    'git checkout -b g/h/i -l should create a branch and a log' \
+       'GIT_COMMITTER_DATE="2005-05-26 23:30" \
+     git-checkout -b g/h/i -l master &&
+        test -f .git/refs/heads/g/h/i &&
+        test -f .git/logs/refs/heads/g/h/i &&
+        diff expect .git/logs/refs/heads/g/h/i'
+
 test_done
index c12270efab80e715e50440a0ae6d05555b055481..b5a1400e18b0fa5190fde4d0b60d1563581b2a19 100755 (executable)
@@ -35,7 +35,7 @@ no-funny' >expected
 test_expect_success 'git-ls-files no-funny' \
        'git-update-index --add "$p0" "$p2" &&
        git-ls-files >current &&
-       diff -u expected current'
+       git diff expected current'
 
 t0=`git-write-tree`
 echo "$t0" >t0
@@ -48,14 +48,14 @@ EOF
 test_expect_success 'git-ls-files with-funny' \
        'git-update-index --add "$p1" &&
        git-ls-files >current &&
-       diff -u expected current'
+       git diff expected current'
 
 echo 'just space
 no-funny
 tabs   ," (dq) and spaces' >expected
 test_expect_success 'git-ls-files -z with-funny' \
        'git-ls-files -z | tr \\0 \\012 >current &&
-       diff -u expected current'
+       git diff expected current'
 
 t1=`git-write-tree`
 echo "$t1" >t1
@@ -67,28 +67,28 @@ no-funny
 EOF
 test_expect_success 'git-ls-tree with funny' \
        'git-ls-tree -r $t1 | sed -e "s/^[^     ]*      //" >current &&
-        diff -u expected current'
+        git diff expected current'
 
 cat > expected <<\EOF
 A      "tabs\t,\" (dq) and spaces"
 EOF
 test_expect_success 'git-diff-index with-funny' \
        'git-diff-index --name-status $t0 >current &&
-       diff -u expected current'
+       git diff expected current'
 
 test_expect_success 'git-diff-tree with-funny' \
        'git-diff-tree --name-status $t0 $t1 >current &&
-       diff -u expected current'
+       git diff expected current'
 
 echo 'A
 tabs   ," (dq) and spaces' >expected
 test_expect_success 'git-diff-index -z with-funny' \
        'git-diff-index -z --name-status $t0 | tr \\0 \\012 >current &&
-       diff -u expected current'
+       git diff expected current'
 
 test_expect_success 'git-diff-tree -z with-funny' \
        'git-diff-tree -z --name-status $t0 $t1 | tr \\0 \\012 >current &&
-       diff -u expected current'
+       git diff expected current'
 
 cat > expected <<\EOF
 CNUM   no-funny        "tabs\t,\" (dq) and spaces"
@@ -96,7 +96,7 @@ EOF
 test_expect_success 'git-diff-tree -C with-funny' \
        'git-diff-tree -C --find-copies-harder --name-status \
                $t0 $t1 | sed -e 's/^C[0-9]*/CNUM/' >current &&
-       diff -u expected current'
+       git diff expected current'
 
 cat > expected <<\EOF
 RNUM   no-funny        "tabs\t,\" (dq) and spaces"
@@ -105,7 +105,7 @@ test_expect_success 'git-diff-tree delete with-funny' \
        'git-update-index --force-remove "$p0" &&
        git-diff-index -M --name-status \
                $t0 | sed -e 's/^R[0-9]*/RNUM/' >current &&
-       diff -u expected current'
+       git diff expected current'
 
 cat > expected <<\EOF
 diff --git a/no-funny "b/tabs\t,\" (dq) and spaces"
@@ -116,7 +116,7 @@ EOF
 test_expect_success 'git-diff-tree delete with-funny' \
        'git-diff-index -M -p $t0 |
         sed -e "s/index [0-9]*%/index NUM%/" >current &&
-        diff -u expected current'
+        git diff expected current'
 
 chmod +x "$p1"
 cat > expected <<\EOF
@@ -130,7 +130,7 @@ EOF
 test_expect_success 'git-diff-tree delete with-funny' \
        'git-diff-index -M -p $t0 |
         sed -e "s/index [0-9]*%/index NUM%/" >current &&
-        diff -u expected current'
+        git diff expected current'
 
 cat >expected <<\EOF
  "tabs\t,\" (dq) and spaces"
@@ -139,7 +139,7 @@ EOF
 test_expect_success 'git-diff-tree rename with-funny applied' \
        'git-diff-index -M -p $t0 |
         git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
-        diff -u expected current'
+        git diff expected current'
 
 cat > expected <<\EOF
  no-funny
@@ -149,12 +149,12 @@ EOF
 test_expect_success 'git-diff-tree delete with-funny applied' \
        'git-diff-index -p $t0 |
         git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
-        diff -u expected current'
+        git diff expected current'
 
 test_expect_success 'git-apply non-git diff' \
        'git-diff-index -p $t0 |
         sed -ne "/^[-+@]/p" |
         git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
-        diff -u expected current'
+        git diff expected current'
 
 test_done
index e54fe0f4014d435f7d2da325bef3d7602a584d42..ffddb68db3abbf1ab14bf99f3c9514a7ee0c276b 100755 (executable)
@@ -9,7 +9,7 @@ test_description='commit and log output encodings'
 
 compare_with () {
        git-show -s $1 | sed -e '1,/^$/d' -e 's/^    //' -e '$d' >current &&
-       diff -u current "$2"
+       git diff current "$2"
 }
 
 test_expect_success setup '
index ca342f48a198c2e98e4459273e8350bb7aed6328..e72c6fd1b4fa294e3e52fe55ab68c672bfc57e15 100755 (executable)
@@ -38,7 +38,7 @@ echo ":100644 100755 X X M    rezrov" >expected
 
 test_expect_success \
     'verify' \
-    'diff -u expected check'
+    'git diff expected check'
 
 test_done
 
index 3d85ceaae9e695d7b03d09cb082f1eef4f8406f2..488e075c16611e5e6132744939574cdd878c3959 100755 (executable)
@@ -106,12 +106,12 @@ do
                        echo "\$ git $cmd"
                        git $cmd |
                        sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
-                           -e "s/^\\( *boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
+                           -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
                        echo "\$"
                } >"$actual" &&
                if test -f "$expect"
                then
-                       diff -u "$expect" "$actual" &&
+                       git diff "$expect" "$actual" &&
                        rm -f "$actual"
                else
                        # this is to help developing new tests.
@@ -238,6 +238,9 @@ format-patch --stdout initial..master
 format-patch --attach --stdout initial..side
 format-patch --attach --stdout initial..master^
 format-patch --attach --stdout initial..master
+format-patch --inline --stdout initial..side
+format-patch --inline --stdout initial..master^
+format-patch --inline --stdout initial..master
 
 diff --abbrev initial..side
 diff -r initial..side
index e5ddd6fcbb7611e86f19b36cf04dec9d23d74fdc..cf6891f748009ad1dc381da16beb63f28c0025b4 100644 (file)
@@ -4,8 +4,7 @@ From: A U Thor <author@example.com>
 Date: Mon, 26 Jun 2006 00:01:00 +0000
 Subject: [PATCH] Second
 MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="------------g-i-t--v-e-r-s-i-o-n"
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
 
 This is a multi-part message in MIME format.
 --------------g-i-t--v-e-r-s-i-o-n
@@ -21,11 +20,9 @@ This is the second commit.
  3 files changed, 5 insertions(+), 3 deletions(-)
  delete mode 100644 file2
 --------------g-i-t--v-e-r-s-i-o-n
-Content-Type: text/x-patch;
- name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
+Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
 Content-Transfer-Encoding: 8bit
-Content-Disposition: inline;
- filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
+Content-Disposition: attachment; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
 
 diff --git a/dir/sub b/dir/sub
 index 35d242b..8422d40 100644
@@ -66,8 +63,7 @@ From: A U Thor <author@example.com>
 Date: Mon, 26 Jun 2006 00:02:00 +0000
 Subject: [PATCH] Third
 MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="------------g-i-t--v-e-r-s-i-o-n"
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
 
 This is a multi-part message in MIME format.
 --------------g-i-t--v-e-r-s-i-o-n
@@ -80,11 +76,9 @@ Content-Transfer-Encoding: 8bit
  2 files changed, 5 insertions(+), 0 deletions(-)
  create mode 100644 file1
 --------------g-i-t--v-e-r-s-i-o-n
-Content-Type: text/x-patch;
- name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
+Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
 Content-Transfer-Encoding: 8bit
-Content-Disposition: inline;
- filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
+Content-Disposition: attachment; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
 
 diff --git a/dir/sub b/dir/sub
 index 8422d40..cead32e 100644
@@ -115,8 +109,7 @@ From: A U Thor <author@example.com>
 Date: Mon, 26 Jun 2006 00:03:00 +0000
 Subject: [PATCH] Side
 MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="------------g-i-t--v-e-r-s-i-o-n"
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
 
 This is a multi-part message in MIME format.
 --------------g-i-t--v-e-r-s-i-o-n
@@ -130,11 +123,9 @@ Content-Transfer-Encoding: 8bit
  3 files changed, 9 insertions(+), 0 deletions(-)
  create mode 100644 file3
 --------------g-i-t--v-e-r-s-i-o-n
-Content-Type: text/x-patch;
- name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
+Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
 Content-Transfer-Encoding: 8bit
-Content-Disposition: inline;
- filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
+Content-Disposition: attachment; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
 
 diff --git a/dir/sub b/dir/sub
 index 35d242b..7289e35 100644
index d0dd19b6239f7bae2087535566a7a7c626b70cce..fe0258720ca5f2058a7f71f8417b5eece23b867a 100644 (file)
@@ -4,8 +4,7 @@ From: A U Thor <author@example.com>
 Date: Mon, 26 Jun 2006 00:01:00 +0000
 Subject: [PATCH] Second
 MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="------------g-i-t--v-e-r-s-i-o-n"
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
 
 This is a multi-part message in MIME format.
 --------------g-i-t--v-e-r-s-i-o-n
@@ -21,11 +20,9 @@ This is the second commit.
  3 files changed, 5 insertions(+), 3 deletions(-)
  delete mode 100644 file2
 --------------g-i-t--v-e-r-s-i-o-n
-Content-Type: text/x-patch;
- name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
+Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
 Content-Transfer-Encoding: 8bit
-Content-Disposition: inline;
- filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
+Content-Disposition: attachment; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
 
 diff --git a/dir/sub b/dir/sub
 index 35d242b..8422d40 100644
@@ -66,8 +63,7 @@ From: A U Thor <author@example.com>
 Date: Mon, 26 Jun 2006 00:02:00 +0000
 Subject: [PATCH] Third
 MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="------------g-i-t--v-e-r-s-i-o-n"
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
 
 This is a multi-part message in MIME format.
 --------------g-i-t--v-e-r-s-i-o-n
@@ -80,11 +76,9 @@ Content-Transfer-Encoding: 8bit
  2 files changed, 5 insertions(+), 0 deletions(-)
  create mode 100644 file1
 --------------g-i-t--v-e-r-s-i-o-n
-Content-Type: text/x-patch;
- name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
+Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
 Content-Transfer-Encoding: 8bit
-Content-Disposition: inline;
- filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
+Content-Disposition: attachment; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
 
 diff --git a/dir/sub b/dir/sub
 index 8422d40..cead32e 100644
index 67a95c5cba8fd256d9e57d7d254b2e9bd58a227e..9ff828ee9d1cbf59d637645b5946c82fe8af00e4 100644 (file)
@@ -4,8 +4,7 @@ From: A U Thor <author@example.com>
 Date: Mon, 26 Jun 2006 00:03:00 +0000
 Subject: [PATCH] Side
 MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="------------g-i-t--v-e-r-s-i-o-n"
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
 
 This is a multi-part message in MIME format.
 --------------g-i-t--v-e-r-s-i-o-n
@@ -19,11 +18,9 @@ Content-Transfer-Encoding: 8bit
  3 files changed, 9 insertions(+), 0 deletions(-)
  create mode 100644 file3
 --------------g-i-t--v-e-r-s-i-o-n
-Content-Type: text/x-patch;
- name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
+Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
 Content-Transfer-Encoding: 8bit
-Content-Disposition: inline;
- filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
+Content-Disposition: attachment; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
 
 diff --git a/dir/sub b/dir/sub
 index 35d242b..7289e35 100644
diff --git a/t/t4013/diff.format-patch_--inline_--stdout_initial..master b/t/t4013/diff.format-patch_--inline_--stdout_initial..master
new file mode 100644 (file)
index 0000000..aa110c0
--- /dev/null
@@ -0,0 +1,164 @@
+$ git format-patch --inline --stdout initial..master
+From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Mon, 26 Jun 2006 00:01:00 +0000
+Subject: [PATCH] Second
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
+
+This is a multi-part message in MIME format.
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/plain; charset=UTF-8; format=fixed
+Content-Transfer-Encoding: 8bit
+
+
+This is the second commit.
+---
+ dir/sub |    2 ++
+ file0   |    3 +++
+ file2   |    3 ---
+ 3 files changed, 5 insertions(+), 3 deletions(-)
+ delete mode 100644 file2
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: inline; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
+
+diff --git a/dir/sub b/dir/sub
+index 35d242b..8422d40 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -1,2 +1,4 @@
+ A
+ B
++C
++D
+diff --git a/file0 b/file0
+index 01e79c3..b414108 100644
+--- a/file0
++++ b/file0
+@@ -1,3 +1,6 @@
+ 1
+ 2
+ 3
++4
++5
++6
+diff --git a/file2 b/file2
+deleted file mode 100644
+index 01e79c3..0000000
+--- a/file2
++++ /dev/null
+@@ -1,3 +0,0 @@
+-1
+-2
+-3
+
+--------------g-i-t--v-e-r-s-i-o-n--
+
+
+
+From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Mon, 26 Jun 2006 00:02:00 +0000
+Subject: [PATCH] Third
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
+
+This is a multi-part message in MIME format.
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/plain; charset=UTF-8; format=fixed
+Content-Transfer-Encoding: 8bit
+
+---
+ dir/sub |    2 ++
+ file1   |    3 +++
+ 2 files changed, 5 insertions(+), 0 deletions(-)
+ create mode 100644 file1
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: inline; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
+
+diff --git a/dir/sub b/dir/sub
+index 8422d40..cead32e 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -2,3 +2,5 @@ A
+ B
+ C
+ D
++E
++F
+diff --git a/file1 b/file1
+new file mode 100644
+index 0000000..b1e6722
+--- /dev/null
++++ b/file1
+@@ -0,0 +1,3 @@
++A
++B
++C
+
+--------------g-i-t--v-e-r-s-i-o-n--
+
+
+
+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Mon, 26 Jun 2006 00:03:00 +0000
+Subject: [PATCH] Side
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
+
+This is a multi-part message in MIME format.
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/plain; charset=UTF-8; format=fixed
+Content-Transfer-Encoding: 8bit
+
+---
+ dir/sub |    2 ++
+ file0   |    3 +++
+ file3   |    4 ++++
+ 3 files changed, 9 insertions(+), 0 deletions(-)
+ create mode 100644 file3
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: inline; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
+
+diff --git a/dir/sub b/dir/sub
+index 35d242b..7289e35 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -1,2 +1,4 @@
+ A
+ B
++1
++2
+diff --git a/file0 b/file0
+index 01e79c3..f4615da 100644
+--- a/file0
++++ b/file0
+@@ -1,3 +1,6 @@
+ 1
+ 2
+ 3
++A
++B
++C
+diff --git a/file3 b/file3
+new file mode 100644
+index 0000000..7289e35
+--- /dev/null
++++ b/file3
+@@ -0,0 +1,4 @@
++A
++B
++1
++2
+
+--------------g-i-t--v-e-r-s-i-o-n--
+
+
+$
diff --git a/t/t4013/diff.format-patch_--inline_--stdout_initial..master^ b/t/t4013/diff.format-patch_--inline_--stdout_initial..master^
new file mode 100644 (file)
index 0000000..95e9ea4
--- /dev/null
@@ -0,0 +1,106 @@
+$ git format-patch --inline --stdout initial..master^
+From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Mon, 26 Jun 2006 00:01:00 +0000
+Subject: [PATCH] Second
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
+
+This is a multi-part message in MIME format.
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/plain; charset=UTF-8; format=fixed
+Content-Transfer-Encoding: 8bit
+
+
+This is the second commit.
+---
+ dir/sub |    2 ++
+ file0   |    3 +++
+ file2   |    3 ---
+ 3 files changed, 5 insertions(+), 3 deletions(-)
+ delete mode 100644 file2
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/x-patch; name="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: inline; filename="1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44.diff"
+
+diff --git a/dir/sub b/dir/sub
+index 35d242b..8422d40 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -1,2 +1,4 @@
+ A
+ B
++C
++D
+diff --git a/file0 b/file0
+index 01e79c3..b414108 100644
+--- a/file0
++++ b/file0
+@@ -1,3 +1,6 @@
+ 1
+ 2
+ 3
++4
++5
++6
+diff --git a/file2 b/file2
+deleted file mode 100644
+index 01e79c3..0000000
+--- a/file2
++++ /dev/null
+@@ -1,3 +0,0 @@
+-1
+-2
+-3
+
+--------------g-i-t--v-e-r-s-i-o-n--
+
+
+
+From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Mon, 26 Jun 2006 00:02:00 +0000
+Subject: [PATCH] Third
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
+
+This is a multi-part message in MIME format.
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/plain; charset=UTF-8; format=fixed
+Content-Transfer-Encoding: 8bit
+
+---
+ dir/sub |    2 ++
+ file1   |    3 +++
+ 2 files changed, 5 insertions(+), 0 deletions(-)
+ create mode 100644 file1
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/x-patch; name="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: inline; filename="9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0.diff"
+
+diff --git a/dir/sub b/dir/sub
+index 8422d40..cead32e 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -2,3 +2,5 @@ A
+ B
+ C
+ D
++E
++F
+diff --git a/file1 b/file1
+new file mode 100644
+index 0000000..b1e6722
+--- /dev/null
++++ b/file1
+@@ -0,0 +1,3 @@
++A
++B
++C
+
+--------------g-i-t--v-e-r-s-i-o-n--
+
+
+$
diff --git a/t/t4013/diff.format-patch_--inline_--stdout_initial..side b/t/t4013/diff.format-patch_--inline_--stdout_initial..side
new file mode 100644 (file)
index 0000000..86ae923
--- /dev/null
@@ -0,0 +1,59 @@
+$ git format-patch --inline --stdout initial..side
+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Mon, 26 Jun 2006 00:03:00 +0000
+Subject: [PATCH] Side
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
+
+This is a multi-part message in MIME format.
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/plain; charset=UTF-8; format=fixed
+Content-Transfer-Encoding: 8bit
+
+---
+ dir/sub |    2 ++
+ file0   |    3 +++
+ file3   |    4 ++++
+ 3 files changed, 9 insertions(+), 0 deletions(-)
+ create mode 100644 file3
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/x-patch; name="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: inline; filename="c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a.diff"
+
+diff --git a/dir/sub b/dir/sub
+index 35d242b..7289e35 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -1,2 +1,4 @@
+ A
+ B
++1
++2
+diff --git a/file0 b/file0
+index 01e79c3..f4615da 100644
+--- a/file0
++++ b/file0
+@@ -1,3 +1,6 @@
+ 1
+ 2
+ 3
++A
++B
++C
+diff --git a/file3 b/file3
+new file mode 100644
+index 0000000..7289e35
+--- /dev/null
++++ b/file3
+@@ -0,0 +1,4 @@
++A
++B
++1
++2
+
+--------------g-i-t--v-e-r-s-i-o-n--
+
+
+$
index adf4993bacf05b4ccb0b447910dda6a2c453bc83..930e209d3136c855c3257e81d889e4dcf765595a 100755 (executable)
@@ -43,13 +43,13 @@ index adf3937..6edc172 100644
 EOF
 
 git-diff > out
-test_expect_success "Ray's example without options" 'diff -u expect out'
+test_expect_success "Ray's example without options" 'git diff expect out'
 
 git-diff -w > out
-test_expect_success "Ray's example with -w" 'diff -u expect out'
+test_expect_success "Ray's example with -w" 'git diff expect out'
 
 git-diff -b > out
-test_expect_success "Ray's example with -b" 'diff -u expect out'
+test_expect_success "Ray's example with -b" 'git diff expect out'
 
 tr 'Q' '\015' << EOF > x
 whitespace at beginning
@@ -90,14 +90,14 @@ index d99af23..8b32fb5 100644
 +CR at end
 EOF
 git-diff > out
-test_expect_success 'another test, without options' 'diff -u expect out'
+test_expect_success 'another test, without options' 'git diff expect out'
 
 cat << EOF > expect
 diff --git a/x b/x
 index d99af23..8b32fb5 100644
 EOF
 git-diff -w > out
-test_expect_success 'another test, with -w' 'diff -u expect out'
+test_expect_success 'another test, with -w' 'git diff expect out'
 
 tr 'Q' '\015' << EOF > expect
 diff --git a/x b/x
@@ -115,6 +115,6 @@ index d99af23..8b32fb5 100644
  CR at endQ
 EOF
 git-diff -b > out
-test_expect_success 'another test, with -b' 'diff -u expect out'
+test_expect_success 'another test, with -b' 'git diff expect out'
 
 test_done
index 2e7cd5f255ce01e0143963aa69e24a4f33ea8325..5dbdc0c9faf81ea95939fec0c285b2020e07a8d9 100755 (executable)
@@ -49,7 +49,7 @@ cat >expect <<\EOF
 EOF
 test_expect_success 'git diff --summary -M HEAD' '
        git diff --summary -M HEAD >actual &&
-       diff -u expect actual
+       git diff expect actual
 '
 
 cat >expect <<\EOF
@@ -64,7 +64,7 @@ cat >expect <<\EOF
 EOF
 test_expect_success 'git diff --stat -M HEAD' '
        git diff --stat -M HEAD >actual &&
-       diff -u expect actual
+       git diff expect actual
 '
 
 test_done
diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh
new file mode 100755 (executable)
index 0000000..6873190
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+test_description='Return value of diffs'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       echo 1 >a &&
+       git add . &&
+       git commit -m first &&
+       echo 2 >b &&
+       git add . &&
+       git commit -a -m second
+'
+
+test_expect_success 'git diff-tree HEAD^ HEAD' '
+       git diff-tree --exit-code HEAD^ HEAD
+       test $? = 1
+'
+test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
+       git diff-tree --exit-code HEAD^ HEAD -- a
+       test $? = 0
+'
+test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
+       git diff-tree --exit-code HEAD^ HEAD -- b
+       test $? = 1
+'
+test_expect_success 'echo HEAD | git diff-tree --stdin' '
+       echo $(git rev-parse HEAD) | git diff-tree --exit-code --stdin
+       test $? = 1
+'
+test_expect_success 'git diff-tree HEAD HEAD' '
+       git diff-tree --exit-code HEAD HEAD
+       test $? = 0
+'
+test_expect_success 'git diff-files' '
+       git diff-files --exit-code
+       test $? = 0
+'
+test_expect_success 'git diff-index --cached HEAD' '
+       git diff-index --exit-code --cached HEAD
+       test $? = 0
+'
+test_expect_success 'git diff-index --cached HEAD^' '
+       git diff-index --exit-code --cached HEAD^
+       test $? = 1
+'
+test_expect_success 'git diff-index --cached HEAD^' '
+       echo text >>b &&
+       echo 3 >c &&
+       git add . && {
+               git diff-index --exit-code --cached HEAD^
+               test $? = 1
+       }
+'
+test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
+       git commit -m "text in b" && {
+               git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b
+               test $? = 1
+       }
+'
+test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
+       git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b
+       test $? = 0
+'
+test_expect_success 'git diff-files' '
+       echo 3 >>c && {
+               git diff-files --exit-code
+               test $? = 1
+       }
+'
+test_expect_success 'git diff-index --cached HEAD' '
+       git update-index c && {
+               git diff-index --exit-code --cached HEAD
+               test $? = 1
+       }
+'
+
+test_done
diff --git a/t/t4017-quiet.sh b/t/t4017-quiet.sh
new file mode 100755 (executable)
index 0000000..e747e84
--- /dev/null
@@ -0,0 +1,80 @@
+#!/bin/sh
+
+test_description='Return value of diffs'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       echo 1 >a &&
+       git add . &&
+       git commit -m first &&
+       echo 2 >b &&
+       git add . &&
+       git commit -a -m second
+'
+
+test_expect_success 'git diff-tree HEAD^ HEAD' '
+       git diff-tree --quiet HEAD^ HEAD >cnt
+       test $? = 1 && test $(wc -l <cnt) = 0
+'
+test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
+       git diff-tree --quiet HEAD^ HEAD -- a >cnt
+       test $? = 0 && test $(wc -l <cnt) = 0
+'
+test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
+       git diff-tree --quiet HEAD^ HEAD -- b >cnt
+       test $? = 1 && test $(wc -l <cnt) = 0
+'
+# this diff outputs one line: sha1 of the given head
+test_expect_success 'echo HEAD | git diff-tree --stdin' '
+       echo $(git rev-parse HEAD) | git diff-tree --quiet --stdin >cnt
+       test $? = 1 && test $(wc -l <cnt) = 1
+'
+test_expect_success 'git diff-tree HEAD HEAD' '
+       git diff-tree --quiet HEAD HEAD >cnt
+       test $? = 0 && test $(wc -l <cnt) = 0
+'
+test_expect_success 'git diff-files' '
+       git diff-files --quiet >cnt
+       test $? = 0 && test $(wc -l <cnt) = 0
+'
+test_expect_success 'git diff-index --cached HEAD' '
+       git diff-index --quiet --cached HEAD >cnt
+       test $? = 0 && test $(wc -l <cnt) = 0
+'
+test_expect_success 'git diff-index --cached HEAD^' '
+       git diff-index --quiet --cached HEAD^ >cnt
+       test $? = 1 && test $(wc -l <cnt) = 0
+'
+test_expect_success 'git diff-index --cached HEAD^' '
+       echo text >>b &&
+       echo 3 >c &&
+       git add . && {
+               git diff-index --quiet --cached HEAD^ >cnt
+               test $? = 1 && test $(wc -l <cnt) = 0
+       }
+'
+test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
+       git commit -m "text in b" && {
+               git diff-tree --quiet -Stext HEAD^ HEAD -- b >cnt
+               test $? = 1 && test $(wc -l <cnt) = 0
+       }
+'
+test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
+       git diff-tree --quiet -Snot-found HEAD^ HEAD -- b >cnt
+       test $? = 0 && test $(wc -l <cnt) = 0
+'
+test_expect_success 'git diff-files' '
+       echo 3 >>c && {
+               git diff-files --quiet >cnt
+               test $? = 1 && test $(wc -l <cnt) = 0
+       }
+'
+test_expect_success 'git diff-index --cached HEAD' '
+       git update-index c && {
+               git diff-index --quiet --cached HEAD >cnt
+               test $? = 1 && test $(wc -l <cnt) = 0
+       }
+'
+
+test_done
index 6579f06b05c91f00f4f45015894f2bfab1076bf6..7b81c32e57f502f2c6d952bd9b7e6b432e092372 100755 (executable)
@@ -11,37 +11,37 @@ test_description='git-apply --stat --summary test.
 test_expect_success \
     'rename' \
     'git-apply --stat --summary <../t4100/t-apply-1.patch >current &&
-    diff -u ../t4100/t-apply-1.expect current'
+    git diff ../t4100/t-apply-1.expect current'
 
 test_expect_success \
     'copy' \
     'git-apply --stat --summary <../t4100/t-apply-2.patch >current &&
-    diff -u ../t4100/t-apply-2.expect current'
+    git diff ../t4100/t-apply-2.expect current'
 
 test_expect_success \
     'rewrite' \
     'git-apply --stat --summary <../t4100/t-apply-3.patch >current &&
-    diff -u ../t4100/t-apply-3.expect current'
+    git diff ../t4100/t-apply-3.expect current'
 
 test_expect_success \
     'mode' \
     'git-apply --stat --summary <../t4100/t-apply-4.patch >current &&
-    diff -u ../t4100/t-apply-4.expect current'
+    git diff ../t4100/t-apply-4.expect current'
 
 test_expect_success \
     'non git' \
     'git-apply --stat --summary <../t4100/t-apply-5.patch >current &&
-    diff -u ../t4100/t-apply-5.expect current'
+    git diff ../t4100/t-apply-5.expect current'
 
 test_expect_success \
     'non git' \
     'git-apply --stat --summary <../t4100/t-apply-6.patch >current &&
-    diff -u ../t4100/t-apply-6.expect current'
+    git diff ../t4100/t-apply-6.expect current'
 
 test_expect_success \
     'non git' \
     'git-apply --stat --summary <../t4100/t-apply-7.patch >current &&
-    diff -u ../t4100/t-apply-7.expect current'
+    git diff ../t4100/t-apply-7.expect current'
 
 test_done
 
index 2ff800c23f8f833393c9eb7f50c89bd1a790094f..a5fb3ea40e4fde9126e66ed46fd3fc337b40ff66 100755 (executable)
@@ -90,7 +90,7 @@ do
                                cat '"$kind-patch.$with"'
                                (exit 1)
                        } &&
-                       diff -u '"$kind"'-expect victim
+                       git diff '"$kind"'-expect victim
                '
        done
 done
@@ -108,7 +108,7 @@ do
                        cat '"$kind-ng.without"'
                        (exit 1)
                } &&
-               diff -u '"$kind"'-expect victim
+               git diff '"$kind"'-expect victim
        '
 done
 
index d5f2cfb186110160df47a450e2f76206b85ee51b..b947ed83bb1b1d61690df1140ede337b15cb04ed 100755 (executable)
@@ -33,7 +33,7 @@ test_expect_success 'apply symlink patch' '
        git checkout side &&
        git apply patch &&
        git diff-files -p >patched &&
-       diff -u patch patched
+       git diff patch patched
 
 '
 
@@ -42,7 +42,7 @@ test_expect_success 'apply --index symlink patch' '
        git checkout -f side &&
        git apply --index patch &&
        git diff-index --cached -p HEAD >patched &&
-       diff -u patch patched
+       git diff patch patched
 
 '
 
index aa2c869e0e7ffcfba2e4349cf5af0e2badcb5516..2685b2263017df96159542853b373ea261880ba4 100755 (executable)
@@ -42,7 +42,7 @@ test_expect_success 'apply in reverse' '
        git reset --hard second &&
        git apply --reverse --binary --index patch &&
        git diff >diff &&
-       diff -u /dev/null diff
+       git diff /dev/null diff
 
 '
 
index b4de075a3e5df86fe399f9133f7437c4a8d8e26d..91931f0e3fde4874c865aa8dd44615b415d324ee 100755 (executable)
@@ -54,7 +54,7 @@ test_expect_success 'apply without --reject should fail' '
                exit 1
        fi
 
-       diff -u file1 saved.file1
+       git diff file1 saved.file1
 '
 
 test_expect_success 'apply without --reject should fail' '
@@ -65,7 +65,7 @@ test_expect_success 'apply without --reject should fail' '
                exit 1
        fi
 
-       diff -u file1 saved.file1
+       git diff file1 saved.file1
 '
 
 test_expect_success 'apply with --reject should fail but update the file' '
@@ -79,7 +79,7 @@ test_expect_success 'apply with --reject should fail but update the file' '
                exit 1
        fi
 
-       diff -u file1 expected &&
+       git diff file1 expected &&
 
        cat file1.rej &&
 
@@ -105,7 +105,7 @@ test_expect_success 'apply with --reject should fail but update the file' '
                echo "file1 still exists?"
                exit 1
        }
-       diff -u file2 expected &&
+       git diff file2 expected &&
 
        cat file2.rej &&
 
@@ -132,7 +132,7 @@ test_expect_success 'the same test with --verbose' '
                echo "file1 still exists?"
                exit 1
        }
-       diff -u file2 expected &&
+       git diff file2 expected &&
 
        cat file2.rej &&
 
@@ -151,7 +151,7 @@ test_expect_success 'apply cleanly with --verbose' '
 
        git apply --verbose patch.1 &&
 
-       diff -u file1 clean
+       git diff file1 clean
 '
 
 test_done
index 7309422fe520ee5f459713da85b255233c0de9a5..27cc6f2b88974051cd521755800342e375d84af7 100755 (executable)
@@ -23,7 +23,8 @@ test_expect_success setup '
        cat file2 >file2.orig
        git add file1 file2 &&
        sed -e "/^B/d" <file1.orig >file1 &&
-       sed -e "/^B/d" <file2.orig >file2 &&
+       sed -e "/^[BQ]/d" <file2.orig >file2 &&
+       echo Q | tr -d "\\012" >>file2 &&
        cat file1 >file1.mods &&
        cat file2 >file2.mods &&
        git diff |
@@ -37,7 +38,7 @@ test_expect_success 'apply --numstat' '
                echo "0 1       file1" &&
                echo "0 1       file2"
        } >expect &&
-       diff -u expect actual
+       git diff expect actual
 
 '
 
@@ -47,8 +48,8 @@ test_expect_success 'apply --apply' '
        cat file2.orig >file2 &&
        git update-index file1 file2 &&
        git apply --index diff.output &&
-       diff -u file1.mods file1 &&
-       diff -u file2.mods file2
+       git diff file1.mods file1 &&
+       git diff file2.mods file2
 '
 
 test_done
diff --git a/t/t4120-apply-popt.sh b/t/t4120-apply-popt.sh
new file mode 100755 (executable)
index 0000000..2f672f3
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Shawn O. Pearce
+#
+
+test_description='git-apply -p handling.'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+       mkdir sub &&
+       echo A >sub/file1 &&
+       cp sub/file1 file1 &&
+       git add sub/file1 &&
+       echo B >sub/file1 &&
+       git diff >patch.file &&
+       rm sub/file1 &&
+       rmdir sub
+'
+
+test_expect_success 'apply git diff with -p2' '
+       git apply -p2 patch.file
+'
+
+test_done
index 639d45fcec2ce80a225da4d73696cea5af3a9de3..6ba63d7173ba5d333d80c017c4ef5a8c77b90a11 100755 (executable)
@@ -34,7 +34,9 @@ EOF
 git commit -q -a -m first
 
 git checkout -b second master
-git show first:a1 | sed 's/To die, t/To die! T/' > a1
+git show first:a1 |
+sed -e 's/To die, t/To die! T/' > a1
+echo "* END *" >>a1
 git commit -q -a -m second
 
 # activate rerere
@@ -42,19 +44,26 @@ mkdir .git/rr-cache
 
 test_expect_failure 'conflicting merge' 'git pull . first'
 
-sha1=4f58849a60b4f969a2848966b6d02893b783e8fb
+sha1=$(sed -e 's/\t.*//' .git/rr-cache/MERGE_RR)
 rr=.git/rr-cache/$sha1
 test_expect_success 'recorded preimage' "grep ======= $rr/preimage"
 
 test_expect_success 'no postimage or thisimage yet' \
        "test ! -f $rr/postimage -a ! -f $rr/thisimage"
 
+test_expect_success 'preimage has right number of lines' '
+
+       cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
+       test $cnt = 9
+
+'
+
 git show first:a1 > a1
 
 cat > expect << EOF
 --- a/a1
 +++ b/a1
-@@ -6,11 +6,7 @@
+@@ -6,17 +6,9 @@
  The heart-ache and the thousand natural shocks
  That flesh is heir to, 'tis a consummation
  Devoutly to be wish'd.
@@ -66,11 +75,16 @@ cat > expect << EOF
  To sleep: perchance to dream: ay, there's the rub;
  For in that sleep of death what dreams may come
  When we have shuffled off this mortal coil,
+ Must give us pause: there's the respect
+ That makes calamity of so long life;
+-<<<<<<<
+-=======
+-* END *
+->>>>>>>
 EOF
-
 git rerere diff > out
 
-test_expect_success 'rerere diff' 'diff -u expect out'
+test_expect_success 'rerere diff' 'git diff expect out'
 
 cat > expect << EOF
 a1
@@ -78,7 +92,7 @@ EOF
 
 git rerere status > out
 
-test_expect_success 'rerere status' 'diff -u expect out'
+test_expect_success 'rerere status' 'git diff expect out'
 
 test_expect_success 'commit succeeds' \
        "git commit -q -a -m 'prefer first over second'"
@@ -94,7 +108,7 @@ test_expect_failure 'another conflicting merge' 'git pull . first'
 git show first:a1 | sed 's/To die: t/To die! T/' > expect
 test_expect_success 'rerere kicked in' "! grep ======= a1"
 
-test_expect_success 'rerere prefers first change' 'diff -u a1 expect'
+test_expect_success 'rerere prefers first change' 'git diff a1 expect'
 
 rm $rr/postimage
 echo "$sha1    a1" | tr '\012' '\0' > .git/rr-cache/MERGE_RR
index ac835fe4317b7a37d77205487066d8f10bd71422..b4359df795483691e61452366add69a212347723 100755 (executable)
@@ -130,4 +130,8 @@ test_expect_success \
     'validate file contents with prefix' \
     'diff -r a e/prefix/a'
 
+test_expect_success \
+    'git-archive --list outside of a git repo' \
+    'GIT_DIR=some/non-existing/directory git-archive --list'
+
 test_done
index 4d2b781a1877b2718b961a057b0dddea8f87c51b..ca96918da2008e9036624fac67c6337961e3c2b0 100755 (executable)
@@ -11,7 +11,7 @@ test_expect_success 'split sample box' \
        'git-mailsplit -o. ../t5100/sample.mbox >last &&
        last=`cat last` &&
        echo total is $last &&
-       test `cat last` = 6'
+       test `cat last` = 8'
 
 for mail in `echo 00*`
 do
diff --git a/t/t5100/info0007 b/t/t5100/info0007
new file mode 100644 (file)
index 0000000..49bb0fe
--- /dev/null
@@ -0,0 +1,5 @@
+Author: A U Thor
+Email: a.u.thor@example.com
+Subject: another patch
+Date: Fri, 9 Jun 2006 00:44:16 -0700
+
diff --git a/t/t5100/info0008 b/t/t5100/info0008
new file mode 100644 (file)
index 0000000..e8a2951
--- /dev/null
@@ -0,0 +1,5 @@
+Author: Junio C Hamano
+Email: junio@kernel.org
+Subject: another patch
+Date: Fri, 9 Jun 2006 00:44:16 -0700
+
diff --git a/t/t5100/msg0007 b/t/t5100/msg0007
new file mode 100644 (file)
index 0000000..71b23c0
--- /dev/null
@@ -0,0 +1,2 @@
+Here is an empty patch from A U Thor.
+
diff --git a/t/t5100/msg0008 b/t/t5100/msg0008
new file mode 100644 (file)
index 0000000..a80ecb9
--- /dev/null
@@ -0,0 +1,4 @@
+>Here is an empty patch from A U Thor.
+
+Hey you forgot the patch!
+
diff --git a/t/t5100/patch0007 b/t/t5100/patch0007
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/t/t5100/patch0008 b/t/t5100/patch0008
new file mode 100644 (file)
index 0000000..e69de29
index 86bfc27147f7df8458f32fee5a9aa199a0c76b3a..b80c981c165e9c82f56f826a0542f3bef3f13eb3 100644 (file)
@@ -386,3 +386,21 @@ index 9123cdc..918dcf8 100644
 -- 
 1.4.0.g6f2b
 
+From nobody Mon Sep 17 00:00:00 2001
+From: A U Thor <a.u.thor@example.com>
+Date: Fri, 9 Jun 2006 00:44:16 -0700
+Subject: [PATCH] another patch
+
+Here is an empty patch from A U Thor.
+
+From nobody Mon Sep 17 00:00:00 2001
+From: Junio C Hamano <junio@kernel.org>
+Date: Fri, 9 Jun 2006 00:44:16 -0700
+Subject: re: [PATCH] another patch
+
+From: A U Thor <a.u.thor@example.com>
+Subject: [PATCH] another patch
+>Here is an empty patch from A U Thor.
+
+Hey you forgot the patch!
+
index f51154745586b246ecb30caee3f2150441911e1d..083095f7f3a6720836f135835091e6d27d18617a 100755 (executable)
@@ -64,7 +64,7 @@ test_expect_success \
 cd "$TRASH"
 
 test_expect_success \
-    'pack with delta' \
+    'pack with REF_DELTA' \
     'pwd &&
      packname_2=$(git-pack-objects test-2 <obj-list)'
 
@@ -72,7 +72,7 @@ rm -fr .git2
 mkdir .git2
 
 test_expect_success \
-    'unpack with delta' \
+    'unpack with REF_DELTA' \
     'GIT_OBJECT_DIRECTORY=.git2/objects &&
      export GIT_OBJECT_DIRECTORY &&
      git-init &&
@@ -82,7 +82,7 @@ test_expect_success \
 unset GIT_OBJECT_DIRECTORY
 cd "$TRASH/.git2"
 test_expect_success \
-    'check unpack with delta' \
+    'check unpack with REF_DELTA' \
     '(cd ../.git && find objects -type f -print) |
      while read path
      do
@@ -93,6 +93,43 @@ test_expect_success \
      done'
 cd "$TRASH"
 
+test_expect_success \
+    'pack with OFS_DELTA' \
+    'pwd &&
+     packname_3=$(git-pack-objects --delta-base-offset test-3 <obj-list)'
+
+rm -fr .git2
+mkdir .git2
+
+test_expect_success \
+    'unpack with OFS_DELTA' \
+    'GIT_OBJECT_DIRECTORY=.git2/objects &&
+     export GIT_OBJECT_DIRECTORY &&
+     git-init &&
+     git-unpack-objects -n <test-3-${packname_3}.pack &&
+     git-unpack-objects <test-3-${packname_3}.pack'
+
+unset GIT_OBJECT_DIRECTORY
+cd "$TRASH/.git2"
+test_expect_success \
+    'check unpack with OFS_DELTA' \
+    '(cd ../.git && find objects -type f -print) |
+     while read path
+     do
+         cmp $path ../.git/$path || {
+            echo $path differs.
+            return 1
+        }
+     done'
+cd "$TRASH"
+
+test_expect_success 'compare delta flavors' '
+       perl -e '\''
+               defined($_ = -s $_) or die for @ARGV;
+               exit 1 if $ARGV[0] <= $ARGV[1];
+       '\'' test-2-$packname_2.pack test-3-$packname_3.pack
+'
+
 rm -fr .git2
 mkdir .git2
 
@@ -111,12 +148,11 @@ test_expect_success \
     } >current &&
     diff expect current'
 
-
 test_expect_success \
-    'use packed deltified objects' \
+    'use packed deltified (REF_DELTA) objects' \
     'GIT_OBJECT_DIRECTORY=.git2/objects &&
      export GIT_OBJECT_DIRECTORY &&
-     rm -f .git2/objects/pack/test-?.idx &&
+     rm .git2/objects/pack/test-* &&
      cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
         git-diff-tree --root -p $commit &&
         while read object
@@ -127,11 +163,28 @@ test_expect_success \
     } >current &&
     diff expect current'
 
+test_expect_success \
+    'use packed deltified (OFS_DELTA) objects' \
+    'GIT_OBJECT_DIRECTORY=.git2/objects &&
+     export GIT_OBJECT_DIRECTORY &&
+     rm .git2/objects/pack/test-* &&
+     cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
+        git-diff-tree --root -p $commit &&
+        while read object
+        do
+           t=`git-cat-file -t $object` &&
+           git-cat-file $t $object || return 1
+        done <obj-list
+    } >current &&
+    diff expect current'
+
 unset GIT_OBJECT_DIRECTORY
 
 test_expect_success \
     'verify pack' \
-    'git-verify-pack test-1-${packname_1}.idx test-2-${packname_2}.idx'
+    'git-verify-pack   test-1-${packname_1}.idx \
+                       test-2-${packname_2}.idx \
+                       test-3-${packname_3}.idx'
 
 test_expect_success \
     'corrupt a pack and see if verify catches' \
@@ -194,6 +247,23 @@ test_expect_success \
      git-index-pack test-3.pack &&
      cmp test-3.idx test-2-${packname_2}.idx &&
 
+     cp test-3-${packname_3}.pack test-3.pack &&
+     git-index-pack -o tmp.idx test-3-${packname_3}.pack &&
+     cmp tmp.idx test-3-${packname_3}.idx &&
+
+     git-index-pack test-3.pack &&
+     cmp test-3.idx test-3-${packname_3}.idx &&
+
      :'
 
+test_expect_success \
+    'fake a SHA1 hash collision' \
+    'test -f   .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 &&
+     cp -f     .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \
+               .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67'
+
+test_expect_failure \
+    'make sure index-pack detects the SHA1 collision' \
+    'git-index-pack -o bad.idx test-3.pack'
+
 test_done
index b1c97b0dfb1748a7ba80c18d2d4b84bdee192c95..477b267599512fee5a5a3cf86687c3708ff967b8 100755 (executable)
@@ -110,7 +110,7 @@ test_expect_success \
        cd .. &&
        git-update-ref refs/heads/master master^ || return 1
        git-send-pack --force ./victim/.git/ master && return 1
-       ! diff .git/refs/heads/master victim/.git/refs/heads/master
+       ! git diff .git/refs/heads/master victim/.git/refs/heads/master
 '
 
 test_done
index 0c0034e34c616fc8a385956a21e282a98b480b37..f1c7ff0c0a8082d260b136fa641a3f109172b7e6 100755 (executable)
@@ -25,8 +25,8 @@ test_expect_success setup '
 
 cat >victim/.git/hooks/pre-receive <<'EOF'
 #!/bin/sh
-echo "$@" >>$GIT_DIR/pre-receive.args
-read x; printf "$x" >$GIT_DIR/pre-receive.stdin
+printf "$@" >>$GIT_DIR/pre-receive.args
+cat - >$GIT_DIR/pre-receive.stdin
 echo STDOUT pre-receive
 echo STDERR pre-receive >&2
 EOF
@@ -44,8 +44,8 @@ chmod u+x victim/.git/hooks/update
 
 cat >victim/.git/hooks/post-receive <<'EOF'
 #!/bin/sh
-echo "$@" >>$GIT_DIR/post-receive.args
-read x; printf "$x" >$GIT_DIR/post-receive.stdin
+printf "$@" >>$GIT_DIR/post-receive.args
+cat - >$GIT_DIR/post-receive.stdin
 echo STDOUT post-receive
 echo STDERR post-receive >&2
 EOF
@@ -80,36 +80,38 @@ test_expect_success 'hooks ran' '
        test -f victim/.git/post-update.stdin
 '
 
-test_expect_success 'pre-receive hook arguments' '
-       echo \
-        refs/heads/master $commit0 $commit1 \
-        refs/heads/tofail $commit1 $commit0 \
-       | diff - victim/.git/pre-receive.args
+test_expect_success 'pre-receive hook input' '
+       (echo $commit0 $commit1 refs/heads/master;
+        echo $commit1 $commit0 refs/heads/tofail
+       ) | git diff - victim/.git/pre-receive.stdin
 '
 
 test_expect_success 'update hook arguments' '
        (echo refs/heads/master $commit0 $commit1;
         echo refs/heads/tofail $commit1 $commit0
-       ) | diff - victim/.git/update.args
+       ) | git diff - victim/.git/update.args
 '
 
-test_expect_success 'post-receive hook arguments' '
-       echo refs/heads/master $commit0 $commit1 |
-       diff - victim/.git/post-receive.args
+test_expect_success 'post-receive hook input' '
+       echo $commit0 $commit1 refs/heads/master |
+       git diff - victim/.git/post-receive.stdin
 '
 
 test_expect_success 'post-update hook arguments' '
        echo refs/heads/master |
-       diff -u - victim/.git/post-update.args
+       git diff - victim/.git/post-update.args
 '
 
 test_expect_success 'all hook stdin is /dev/null' '
-       ! test -s victim/.git/pre-receive.stdin &&
        ! test -s victim/.git/update.stdin &&
-       ! test -s victim/.git/post-receive.stdin &&
        ! test -s victim/.git/post-update.stdin
 '
 
+test_expect_success 'all *-receive hook args are empty' '
+       ! test -s victim/.git/pre-receive.args &&
+       ! test -s victim/.git/post-receive.args
+'
+
 test_expect_failure 'send-pack produced no output' '
        test -s send.out
 '
@@ -128,7 +130,7 @@ STDERR post-update
 EOF
 test_expect_success 'send-pack stderr contains hook messages' '
        egrep ^STD send.err >actual &&
-       diff - actual <expect
+       git diff - actual <expect
 '
 
 test_done
index fa76662dce3dd45cf9d59f57a151c7ab209d4014..426017e1d08aad5aa3a92f9473e02defc4b10aaf 100755 (executable)
@@ -90,6 +90,13 @@ test_expect_success 'create bundle 1' '
        git bundle create bundle1 master^..master
 '
 
+test_expect_success 'header of bundle looks right' '
+       head -n 1 "$D"/bundle1 | grep "^#" &&
+       head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
+       head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
+       head -n 4 "$D"/bundle1 | grep "^$"
+'
+
 test_expect_success 'create bundle 2' '
        cd "$D" &&
        git bundle create bundle2 master~2..master
@@ -101,10 +108,41 @@ test_expect_failure 'unbundle 1' '
        git fetch "$D/bundle1" master:master
 '
 
+test_expect_success 'bundle 1 has only 3 files ' '
+       cd "$D" &&
+       (
+               while read x && test -n "$x"
+               do
+                       :;
+               done
+               cat
+       ) <bundle1 >bundle.pack &&
+       git index-pack bundle.pack &&
+       verify=$(git verify-pack -v bundle.pack) &&
+       test 4 = $(echo "$verify" | wc -l)
+'
+
 test_expect_success 'unbundle 2' '
        cd "$D/bundle" &&
        git fetch ../bundle2 master:master &&
        test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
 '
 
+test_expect_success 'bundle does not prerequisite objects' '
+       cd "$D" &&
+       touch file2 &&
+       git add file2 &&
+       git commit -m add.file2 file2 &&
+       git bundle create bundle3 -1 HEAD &&
+       (
+               while read x && test -n "$x"
+               do
+                       :;
+               done
+               cat
+       ) <bundle3 >bundle.pack &&
+       git index-pack bundle.pack &&
+       test 4 = $(git verify-pack -v bundle.pack | wc -l)
+'
+
 test_done
index 0b600bb429b69df02d971913e4b658bf7e313277..6c9cc67508f4351f5627b613215e6b88b0adc49a 100755 (executable)
@@ -149,7 +149,7 @@ do
                } >"$actual" &&
                if test -f "$expect"
                then
-                       diff -u "$expect" "$actual" &&
+                       git diff -u "$expect" "$actual" &&
                        rm -f "$actual"
                else
                        # this is to help developing new tests.
index 7eb37838bb788dfb68361bca95860fd532276deb..243212d3dac03c19db18e9c8fcfc3b9049137cdd 100755 (executable)
@@ -29,5 +29,29 @@ test_expect_success 'checking the results' '
        diff file cloned/file
 '
 
+test_expect_success 'test . as a remote' '
+
+       git branch copy master &&
+       git config branch.copy.remote . &&
+       git config branch.copy.merge refs/heads/master &&
+       echo updated >file &&
+       git commit -a -m updated &&
+       git checkout copy &&
+       test `cat file` = file &&
+       git pull &&
+       test `cat file` = updated
+'
+
+test_expect_success 'the default remote . should not break explicit pull' '
+       git checkout -b second master^ &&
+       echo modified >file &&
+       git commit -a -m modified &&
+       git checkout copy &&
+       git reset --hard HEAD^ &&
+       test `cat file` = file &&
+       git pull . second &&
+       test `cat file` = modified
+'
+
 test_done
 
index 7831e3461c3dd7d332db56e9f5828a27009c9460..fcb33027648b8449cba5869cbe808a4e26ff7f2d 100755 (executable)
@@ -163,7 +163,7 @@ test_sequence()
 # the bisection point is the head - this is the bad point.
 #
 
-test_output_expect_success "--bisect l5 ^root" 'git-rev-list $_bisect_option l5 ^root' <<EOF
+test_output_expect_success "$_bisect_option l5 ^root" 'git-rev-list $_bisect_option l5 ^root' <<EOF
 c3
 EOF
 
index 5182dbb15811ae518c1686c0a8f037a84d3cbd06..761f09b1e537ebf9c24171c646e8578d99ce95fa 100755 (executable)
@@ -7,7 +7,8 @@ test_description='git-rev-list trivial path optimization test'
 test_expect_success setup '
 echo Hello > a &&
 git add a &&
-git commit -m "Initial commit" a
+git commit -m "Initial commit" a &&
+initial=$(git rev-parse --verify HEAD)
 '
 
 test_expect_success path-optimization '
@@ -16,4 +17,35 @@ test_expect_success path-optimization '
     test $(git-rev-list $commit -- . | wc -l) = 1
 '
 
+test_expect_success 'further setup' '
+       git checkout -b side &&
+       echo Irrelevant >c &&
+       git add c &&
+       git commit -m "Side makes an irrelevant commit" &&
+       echo "More Irrelevancy" >c &&
+       git add c &&
+       git commit -m "Side makes another irrelevant commit" &&
+       echo Bye >a &&
+       git add a &&
+       git commit -m "Side touches a" &&
+       side=$(git rev-parse --verify HEAD) &&
+       echo "Yet more Irrelevancy" >c &&
+       git add c &&
+       git commit -m "Side makes yet another irrelevant commit" &&
+       git checkout master &&
+       echo Another >b &&
+       git add b &&
+       git commit -m "Master touches b" &&
+       git merge side &&
+       echo Touched >b &&
+       git add b &&
+       git commit -m "Master touches b again"
+'
+
+test_expect_success 'path optimization 2' '
+       ( echo "$side"; echo "$initial" ) >expected &&
+       git rev-list HEAD -- a >actual &&
+       diff -u expected actual
+'
+
 test_done
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
new file mode 100755 (executable)
index 0000000..aab17fa
--- /dev/null
@@ -0,0 +1,150 @@
+#!/bin/sh
+
+test_description='git-rev-list --pretty=format test'
+
+. ./test-lib.sh
+
+test_tick
+test_expect_success 'setup' '
+touch foo && git-add foo && git-commit -m "added foo" &&
+  echo changed >foo && git-commit -a -m "changed foo"
+'
+
+# usage: test_format name format_string <expected_output
+test_format() {
+       cat >expect.$1
+       test_expect_success "format $1" "
+git-rev-list --pretty=format:$2 master >output.$1 &&
+git-diff expect.$1 output.$1
+"
+}
+
+test_format hash %H%n%h <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+131a310eb913d107dd3c09a65d1651175898735d
+131a310
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+86c75cf
+EOF
+
+test_format tree %T%n%t <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+fe722612f26da5064c32ca3843aa154bdb0b08a0
+fe72261
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+4d5fcadc293a348e88f777dc0920f11e7d71441c
+4d5fcad
+EOF
+
+test_format parents %P%n%p <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+86c75cf
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+
+
+EOF
+
+# we don't test relative here
+test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+A U Thor
+author@example.com
+Thu Apr 7 15:13:13 2005 -0700
+Thu, 7 Apr 2005 15:13:13 -0700
+1112911993
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+A U Thor
+author@example.com
+Thu Apr 7 15:13:13 2005 -0700
+Thu, 7 Apr 2005 15:13:13 -0700
+1112911993
+EOF
+
+test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+C O Mitter
+committer@example.com
+Thu Apr 7 15:13:13 2005 -0700
+Thu, 7 Apr 2005 15:13:13 -0700
+1112911993
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+C O Mitter
+committer@example.com
+Thu Apr 7 15:13:13 2005 -0700
+Thu, 7 Apr 2005 15:13:13 -0700
+1112911993
+EOF
+
+test_format encoding %e <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+<unknown>
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+<unknown>
+EOF
+
+test_format subject %s <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+changed foo
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+added foo
+EOF
+
+test_format body %b <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+<unknown>
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+<unknown>
+EOF
+
+test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+\e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+\e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
+EOF
+
+cat >commit-msg <<'EOF'
+Test printing of complex bodies
+
+This commit message is much longer than the others,
+and it will be encoded in iso8859-1. We should therefore
+include an iso8859 character: Â¡bueno!
+EOF
+test_expect_success 'setup complex body' '
+git-config i18n.commitencoding iso8859-1 &&
+  echo change2 >foo && git-commit -a -F commit-msg
+'
+
+test_format complex-encoding %e <<'EOF'
+commit f58db70b055c5718631e5c61528b28b12090cdea
+iso8859-1
+commit 131a310eb913d107dd3c09a65d1651175898735d
+<unknown>
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+<unknown>
+EOF
+
+test_format complex-subject %s <<'EOF'
+commit f58db70b055c5718631e5c61528b28b12090cdea
+Test printing of complex bodies
+commit 131a310eb913d107dd3c09a65d1651175898735d
+changed foo
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+added foo
+EOF
+
+test_format complex-body %b <<'EOF'
+commit f58db70b055c5718631e5c61528b28b12090cdea
+This commit message is much longer than the others,
+and it will be encoded in iso8859-1. We should therefore
+include an iso8859 character: Â¡bueno!
+
+commit 131a310eb913d107dd3c09a65d1651175898735d
+<unknown>
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+<unknown>
+EOF
+
+test_done
index f3cd3dba4df6ac1582956a1f9d17a9818aeb694d..c76fccfb5a0811aca3bb5af67f8558745935148f 100644 (file)
@@ -63,7 +63,7 @@ test_expect_success "merge without conflict (missing LF at EOF)" \
        "git-merge-file test2.txt orig.txt new2.txt"
 
 test_expect_success "merge result added missing LF" \
-       "diff -u test.txt test2.txt"
+       "git diff test.txt test2.txt"
 
 cp test.txt backup.txt
 test_expect_failure "merge with conflicts" \
@@ -86,7 +86,7 @@ non timebo mala, quoniam tu mecum es:
 virga tua et baculus tuus ipsa me consolata sunt.
 EOF
 
-test_expect_success "expected conflict markers" "diff -u test.txt expect.txt"
+test_expect_success "expected conflict markers" "git diff test.txt expect.txt"
 
 cp backup.txt test.txt
 test_expect_failure "merge with conflicts, using -L" \
@@ -110,7 +110,7 @@ virga tua et baculus tuus ipsa me consolata sunt.
 EOF
 
 test_expect_success "expected conflict markers, with -L" \
-       "diff -u test.txt expect.txt"
+       "git diff test.txt expect.txt"
 
 sed "s/ tu / TU /" < new1.txt > new5.txt
 test_expect_failure "conflict in removed tail" \
@@ -132,7 +132,7 @@ virga tua et baculus tuus ipsa me consolata sunt.
 >>>>>>> new5.txt
 EOF
 
-test_expect_success "expected conflict markers" "diff -u expect out"
+test_expect_success "expected conflict markers" "git diff expect out"
 
 test_done
 
index 31b96257b454c62ce84c3d883e961c41740ddddd..a398556137205d9fb561746335a13330a5aeda54 100644 (file)
@@ -70,7 +70,7 @@ G
 >>>>>>> G:a1
 EOF
 
-test_expect_success "result contains a conflict" "diff -u expect a1"
+test_expect_success "result contains a conflict" "git diff expect a1"
 
 git ls-files --stage > out
 cat > expect << EOF
@@ -79,6 +79,6 @@ cat > expect << EOF
 100644 fd7923529855d0b274795ae3349c5e0438333979 3      a1
 EOF
 
-test_expect_success "virtual trees were processed" "diff -u expect out"
+test_expect_success "virtual trees were processed" "git diff expect out"
 
 test_done
diff --git a/t/t6030-bisect-run.sh b/t/t6030-bisect-run.sh
new file mode 100755 (executable)
index 0000000..de31235
--- /dev/null
@@ -0,0 +1,102 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Christian Couder
+#
+test_description='Tests git-bisect functionality'
+
+exec </dev/null
+
+. ./test-lib.sh
+
+add_line_into_file()
+{
+    _line=$1
+    _file=$2
+
+    if [ -f "$_file" ]; then
+        echo "$_line" >> $_file || return $?
+        MSG="Add <$_line> into <$_file>."
+    else
+        echo "$_line" > $_file || return $?
+        git add $_file || return $?
+        MSG="Create file <$_file> with <$_line> inside."
+    fi
+
+    git-commit -m "$MSG" $_file
+}
+
+HASH1=
+HASH3=
+HASH4=
+
+test_expect_success \
+    'set up basic repo with 1 file (hello) and 4 commits' \
+    'add_line_into_file "1: Hello World" hello &&
+     add_line_into_file "2: A new day for git" hello &&
+     add_line_into_file "3: Another new day for git" hello &&
+     add_line_into_file "4: Ciao for now" hello &&
+     HASH1=$(git rev-list HEAD | tail -1) &&
+     HASH3=$(git rev-list HEAD | head -2 | tail -1) &&
+     HASH4=$(git rev-list HEAD | head -1)'
+
+test_expect_success 'bisect starts with only one bad' '
+       git bisect reset &&
+       git bisect start &&
+       git bisect bad $HASH4 &&
+       git bisect next
+'
+
+test_expect_success 'bisect starts with only one good' '
+       git bisect reset &&
+       git bisect start &&
+       git bisect good $HASH1 || return 1
+
+       if git bisect next
+       then
+               echo Oops, should have failed.
+               false
+       else
+               :
+       fi
+'
+
+test_expect_success 'bisect start with one bad and good' '
+       git bisect reset &&
+       git bisect start &&
+       git bisect good $HASH1 &&
+       git bisect bad $HASH4 &&
+       git bisect next
+'
+
+# We want to automatically find the commit that
+# introduced "Another" into hello.
+test_expect_success \
+    '"git bisect run" simple case' \
+    'echo "#"\!"/bin/sh" > test_script.sh &&
+     echo "grep Another hello > /dev/null" >> test_script.sh &&
+     echo "test \$? -ne 0" >> test_script.sh &&
+     chmod +x test_script.sh &&
+     git bisect start &&
+     git bisect good $HASH1 &&
+     git bisect bad $HASH4 &&
+     git bisect run ./test_script.sh > my_bisect_log.txt &&
+     grep "$HASH3 is first bad commit" my_bisect_log.txt &&
+     git bisect reset'
+
+# We want to automatically find the commit that
+# introduced "Ciao" into hello.
+test_expect_success \
+    '"git bisect run" with more complex "git bisect start"' \
+    'echo "#"\!"/bin/sh" > test_script.sh &&
+     echo "grep Ciao hello > /dev/null" >> test_script.sh &&
+     echo "test \$? -ne 0" >> test_script.sh &&
+     chmod +x test_script.sh &&
+     git bisect start $HASH4 $HASH1 &&
+     git bisect run ./test_script.sh > my_bisect_log.txt &&
+     grep "$HASH4 is first bad commit" my_bisect_log.txt &&
+     git bisect reset'
+
+#
+#
+test_done
+
index ea140236162894ed2e5691b57ba8c5cf98e5627d..526d7d1c4422e342c7257e260626dac3dda36a3a 100755 (executable)
@@ -79,7 +79,7 @@ test_expect_success 'merge-msg test #1' '
        git fetch . left &&
 
        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
-       diff -u actual expected
+       git diff actual expected
 '
 
 cat >expected <<\EOF
@@ -92,7 +92,7 @@ test_expect_success 'merge-msg test #2' '
        git fetch ../trash left &&
 
        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
-       diff -u actual expected
+       git diff actual expected
 '
 
 cat >expected <<\EOF
@@ -115,7 +115,7 @@ test_expect_success 'merge-msg test #3' '
        git fetch . left &&
 
        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
-       diff -u actual expected
+       git diff actual expected
 '
 
 cat >expected <<\EOF
@@ -145,7 +145,7 @@ test_expect_success 'merge-msg test #4' '
        git fetch . left right &&
 
        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
-       diff -u actual expected
+       git diff actual expected
 '
 
 test_expect_success 'merge-msg test #5' '
@@ -157,7 +157,7 @@ test_expect_success 'merge-msg test #5' '
        git fetch . left right &&
 
        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
-       diff -u actual expected
+       git diff actual expected
 '
 
 test_done
index 867bbd26cbbacbe03ef76cadb6ff34976c324da5..5fa6a45577894e05446351fc5076a27accb1fa9f 100755 (executable)
@@ -3,7 +3,20 @@
 # Copyright (c) 2006 Junio C Hamano
 #
 
-test_description='git-checkout tests.'
+test_description='git-checkout tests.
+
+Creates master, forks renamer and side branches from it.
+Test switching across them.
+
+  ! [master] Initial A one, A two
+   * [renamer] Renamer R one->uno, M two
+    ! [side] Side M one, D two, A three
+  ---
+    + [side] Side M one, D two, A three
+   *  [renamer] Renamer R one->uno, M two
+  +*+ [master] Initial A one, A two
+
+'
 
 . ./test-lib.sh
 
@@ -129,4 +142,52 @@ test_expect_success 'checkout -m with merge conflict' '
        ! test -s current
 '
 
+test_expect_success 'checkout to detach HEAD' '
+
+       git checkout -f renamer && git clean &&
+       git checkout renamer^ &&
+       H=$(git rev-parse --verify HEAD) &&
+       M=$(git show-ref -s --verify refs/heads/master) &&
+       test "z$H" = "z$M" &&
+       if git symbolic-ref HEAD >/dev/null 2>&1
+       then
+               echo "OOPS, HEAD is still symbolic???"
+               false
+       else
+               : happy
+       fi
+'
+
+test_expect_success 'checkout to detach HEAD with branchname^' '
+
+       git checkout -f master && git clean &&
+       git checkout renamer^ &&
+       H=$(git rev-parse --verify HEAD) &&
+       M=$(git show-ref -s --verify refs/heads/master) &&
+       test "z$H" = "z$M" &&
+       if git symbolic-ref HEAD >/dev/null 2>&1
+       then
+               echo "OOPS, HEAD is still symbolic???"
+               false
+       else
+               : happy
+       fi
+'
+
+test_expect_success 'checkout to detach HEAD with HEAD^0' '
+
+       git checkout -f master && git clean &&
+       git checkout HEAD^0 &&
+       H=$(git rev-parse --verify HEAD) &&
+       M=$(git show-ref -s --verify refs/heads/master) &&
+       test "z$H" = "z$M" &&
+       if git symbolic-ref HEAD >/dev/null 2>&1
+       then
+               echo "OOPS, HEAD is still symbolic???"
+               false
+       else
+               : happy
+       fi
+'
+
 test_done
index 7dcfc7e7db47a815606577b366f309f590896082..eb628fe07543d07812525942cba11b8133f2e000 100755 (executable)
@@ -169,7 +169,7 @@ test_expect_success "$name" "
        svn up '$SVN_TREE' &&
        test -f '$SVN_TREE'/exec-2.sh &&
        test ! -L '$SVN_TREE'/exec-2.sh &&
-       diff -u help $SVN_TREE/exec-2.sh"
+       git diff help $SVN_TREE/exec-2.sh"
 
 if test "$have_utf8" = t
 then
@@ -193,7 +193,7 @@ test_expect_success "$name" \
     "git-svn init $svnrepo && git-svn fetch &&
      git-rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
      git-rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
-     diff -u a b"
+     git diff a b"
 
 name='check imported tree checksums expected tree checksums'
 rm -f expected
@@ -211,7 +211,7 @@ tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
 EOF
 
-test_expect_success "$name" "diff -u a expected"
+test_expect_success "$name" "git diff a expected"
 
 test_expect_failure 'exit if remote refs are ambigious' "
         git-config --add svn-remote.svn.fetch \
index 2e1a09ff2db29421629b038a3374449c49bdc79d..8e958da5361f69e47a27833948eed0bd7dc8b32e 100755 (executable)
@@ -74,7 +74,7 @@ EOF
 test_expect_success \
        'A: verify commit' \
        'git-cat-file commit master | sed 1d >actual &&
-       diff -u expect actual'
+       git diff expect actual'
 
 cat >expect <<EOF
 100644 blob file2
@@ -84,22 +84,22 @@ EOF
 test_expect_success \
        'A: verify tree' \
        'git-cat-file -p master^{tree} | sed "s/ [0-9a-f]*      / /" >actual &&
-        diff -u expect actual'
+        git diff expect actual'
 
 echo "$file2_data" >expect
 test_expect_success \
        'A: verify file2' \
-       'git-cat-file blob master:file2 >actual && diff -u expect actual'
+       'git-cat-file blob master:file2 >actual && git diff expect actual'
 
 echo "$file3_data" >expect
 test_expect_success \
        'A: verify file3' \
-       'git-cat-file blob master:file3 >actual && diff -u expect actual'
+       'git-cat-file blob master:file3 >actual && git diff expect actual'
 
 printf "$file4_data" >expect
 test_expect_success \
        'A: verify file4' \
-       'git-cat-file blob master:file4 >actual && diff -u expect actual'
+       'git-cat-file blob master:file4 >actual && git diff expect actual'
 
 cat >expect <<EOF
 :2 `git-rev-parse --verify master:file2`
@@ -109,7 +109,7 @@ cat >expect <<EOF
 EOF
 test_expect_success \
        'A: verify marks output' \
-       'diff -u expect marks.out'
+       'git diff expect marks.out'
 
 test_expect_success \
        'A: verify marks import' \
@@ -117,7 +117,7 @@ test_expect_success \
                --import-marks=marks.out \
                --export-marks=marks.new \
                </dev/null &&
-       diff -u expect marks.new'
+       git diff -u expect marks.new'
 
 ###
 ### series B
@@ -183,7 +183,7 @@ EOF
 test_expect_success \
        'C: verify commit' \
        'git-cat-file commit branch | sed 1d >actual &&
-        diff -u expect actual'
+        git diff expect actual'
 
 cat >expect <<EOF
 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A     file2/newf
@@ -240,13 +240,13 @@ echo "$file5_data" >expect
 test_expect_success \
        'D: verify file5' \
        'git-cat-file blob branch:newdir/interesting >actual &&
-        diff -u expect actual'
+        git diff expect actual'
 
 echo "$file6_data" >expect
 test_expect_success \
        'D: verify file6' \
        'git-cat-file blob branch:newdir/exec.sh >actual &&
-        diff -u expect actual'
+        git diff expect actual'
 
 ###
 ### series E
@@ -282,7 +282,7 @@ EOF
 test_expect_success \
        'E: verify commit' \
        'git-cat-file commit branch | sed 1,2d >actual &&
-       diff -u expect actual'
+       git diff expect actual'
 
 ###
 ### series F
@@ -335,7 +335,7 @@ EOF
 test_expect_success \
        'F: verify other commit' \
        'git-cat-file commit other >actual &&
-       diff -u expect actual'
+       git diff expect actual'
 
 ###
 ### series G
@@ -413,7 +413,7 @@ echo "$file5_data" >expect
 test_expect_success \
        'H: verify file' \
        'git-cat-file blob H:h/e/l/lo >actual &&
-        diff -u expect actual'
+        git diff expect actual'
 
 ###
 ### series I
@@ -439,7 +439,7 @@ EOF
 test_expect_success \
        'I: verify edge list' \
        'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
-        diff -u expect actual'
+        git diff expect actual'
 
 ###
 ### series J
@@ -501,4 +501,54 @@ test_expect_success \
     'test `git-rev-parse --verify branch^1` \
                = `git-rev-parse --verify K^1`'
 
+###
+### series L
+###
+
+cat >input <<INPUT_END
+blob
+mark :1
+data <<EOF
+some data
+EOF
+
+blob
+mark :2
+data <<EOF
+other data
+EOF
+
+commit refs/heads/L
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+create L
+COMMIT
+
+M 644 :1 b.
+M 644 :1 b/other
+M 644 :1 ba
+
+commit refs/heads/L
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+update L
+COMMIT
+
+M 644 :2 b.
+M 644 :2 b/other
+M 644 :2 ba
+INPUT_END
+
+cat >expect <<EXPECT_END
+:100644 100644 4268632... 55d3a52... M b.
+:040000 040000 0ae5cac... 443c768... M b
+:100644 100644 4268632... 55d3a52... M ba
+EXPECT_END
+
+test_expect_success \
+    'L: verify internal tree sorting' \
+       'git-fast-import <input &&
+        git-diff --raw L^ L >output &&
+        git diff expect output'
+
 test_done
index 0eeee43feb97ac79406d196c735e4027c4e9cdfd..b8352e731bf4baffbda780a1420f52ca4670b828 100644 (file)
@@ -1,5 +1,9 @@
 # make and install sample templates
 
+ifndef V
+       QUIET = @
+endif
+
 INSTALL ?= install
 TAR ?= tar
 prefix ?= $(HOME)
@@ -18,7 +22,7 @@ all: boilerplates.made custom
 
 bpsrc = $(filter-out %~,$(wildcard *--*))
 boilerplates.made : $(bpsrc)
-       ls *--* 2>/dev/null | \
+       $(QUIET)ls *--* 2>/dev/null | \
        while read boilerplate; \
        do \
                case "$$boilerplate" in *~) continue ;; esac && \
@@ -29,13 +33,13 @@ boilerplates.made : $(bpsrc)
                *--) ;; \
                *) cp $$boilerplate blt/$$dst ;; \
                esac || exit; \
-       done || exit
+       done && \
        date >$@
 
 # If you need build-tailored templates, build them into blt/
 # directory yourself here.
 custom:
-       : no custom templates yet
+       $(QUIET): no custom templates yet
 
 clean:
        rm -rf blt boilerplates.made
diff --git a/templates/hooks--post-receive b/templates/hooks--post-receive
new file mode 100644 (file)
index 0000000..190de26
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# An example hook script for the post-receive event
+#
+# This script is run after receive-pack has accepted a pack and the
+# repository has been updated.  It is passed arguments in through stdin
+# in the form
+#  <oldrev> <newrev> <refname>
+# For example:
+#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
+#
+# see contrib/hooks/ for an sample, or uncomment the next line (on debian)
+#
+
+
+#. /usr/share/doc/git-core/contrib/hooks/post-receive-email
+
index 5b82b68e93980924befa9ecc99e099e77da27b5f..0ff03309e69aed6b506e333e087f23099ad80290 100644 (file)
@@ -1,36 +1,16 @@
 #!/bin/sh
 #
-# An example hook script to mail out commit update information.
-# It can also blocks tags that aren't annotated.
+# An example hook script to blocks unannotated tags from entering.
 # Called by git-receive-pack with arguments: refname sha1-old sha1-new
 #
 # To enable this hook, make this file executable by "chmod +x update".
 #
 # Config
 # ------
-# hooks.mailinglist
-#   This is the list that all pushes will go to; leave it blank to not send
-#   emails frequently.  The log email will list every log entry in full between
-#   the old ref value and the new ref value.
-# hooks.announcelist
-#   This is the list that all pushes of annotated tags will go to.  Leave it
-#   blank to just use the mailinglist field.  The announce emails list the
-#   short log summary of the changes since the last annotated tag
 # hooks.allowunannotated
 #   This boolean sets whether unannotated tags will be allowed into the
 #   repository.  By default they won't be.
 #
-# Notes
-# -----
-# All emails have their subjects prefixed with "[SCM]" to aid filtering.
-# All emails include the headers "X-Git-Refname", "X-Git-Oldrev",
-# "X-Git-Newrev", and "X-Git-Reftype" to enable fine tuned filtering and info.
-
-# --- Constants
-EMAILPREFIX="[SCM] "
-LOGBEGIN="- Log -----------------------------------------------------------------"
-LOGEND="-----------------------------------------------------------------------"
-DATEFORMAT="%F %R %z"
 
 # --- Command line
 refname="$1"
@@ -51,235 +31,42 @@ if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
 fi
 
 # --- Config
-projectdesc=$(cat $GIT_DIR/description)
-recipients=$(git-repo-config hooks.mailinglist)
-announcerecipients=$(git-repo-config hooks.announcelist)
 allowunannotated=$(git-repo-config --bool hooks.allowunannotated)
 
+# check for no description
+if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb" ]; then
+       echo "*** Project description file hasn't been set" >&2
+       exit 1
+fi
+
 # --- Check types
 newrev_type=$(git-cat-file -t $newrev)
 
 case "$refname","$newrev_type" in
        refs/tags/*,commit)
                # un-annotated tag
-               refname_type="tag"
                short_refname=${refname##refs/tags/}
                if [ "$allowunannotated" != "true" ]; then
-                       echo "*** The un-annotated tag, $short_refname is not allowed in this repository" >&2
+                       echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
                        echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
                        exit 1
                fi
                ;;
        refs/tags/*,tag)
                # annotated tag
-               refname_type="annotated tag"
-               short_refname=${refname##refs/tags/}
-               # change recipients
-               if [ -n "$announcerecipients" ]; then
-                       recipients="$announcerecipients"
-               fi
                ;;
        refs/heads/*,commit)
                # branch
-               refname_type="branch"
-               short_refname=${refname##refs/heads/}
                ;;
        refs/remotes/*,commit)
                # tracking branch
-               refname_type="tracking branch"
-               short_refname=${refname##refs/remotes/}
-               # Should this even be allowed?
-               echo "*** Push-update of tracking branch, $refname.  No email generated." >&2
-               exit 0
                ;;
        *)
                # Anything else (is there anything else?)
-               echo "*** Update hook: unknown type of update, \"$newrev_type\", to ref $refname" >&2
+               echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
                exit 1
                ;;
 esac
 
-# Check if we've got anyone to send to
-if [ -z "$recipients" ]; then
-       # If the email isn't sent, then at least give the user some idea of what command
-       # would generate the email at a later date
-       echo "*** No recipients found - no email will be sent, but the push will continue" >&2
-       echo "*** for $0 $1 $2 $3" >&2
-       exit 0
-fi
-
-# --- Email parameters
-committer=$(git show --pretty=full -s $newrev | grep "^Commit: " | sed -e "s/^Commit: //")
-describe=$(git describe $newrev 2>/dev/null)
-if [ -z "$describe" ]; then
-       describe=$newrev
-fi
-
-# --- Email (all stdout will be the email)
-(
-# Generate header
-cat <<-EOF
-From: $committer
-To: $recipients
-Subject: ${EMAILPREFIX}$projectdesc $refname_type, $short_refname now at $describe
-X-Git-Refname: $refname
-X-Git-Reftype: $refname_type
-X-Git-Oldrev: $oldrev
-X-Git-Newrev: $newrev
-
-Hello,
-
-This is an automated email from the git hooks/update script, it was
-generated because a ref change was pushed to the repository.
-
-Updating $refname_type, $short_refname,
-EOF
-
-case "$refname_type" in
-       "tracking branch"|branch)
-               if expr "$oldrev" : '0*$' >/dev/null
-               then
-                       # If the old reference is "0000..0000" then this is a new branch
-                       # and so oldrev is not valid
-                       echo "  as a new  $refname_type"
-                   echo "        to  $newrev ($newrev_type)"
-                       echo ""
-                       echo $LOGBEGIN
-                       # This shows all log entries that are not already covered by
-                       # another ref - i.e. commits that are now accessible from this
-                       # ref that were previously not accessible
-                       git log $newrev --not --all
-                       echo $LOGEND
-               else
-                       # oldrev is valid
-                       oldrev_type=$(git-cat-file -t "$oldrev")
-
-                       # Now the problem is for cases like this:
-                       #   * --- * --- * --- * (oldrev)
-                       #          \
-                       #           * --- * --- * (newrev)
-                       # i.e. there is no guarantee that newrev is a strict subset
-                       # of oldrev - (would have required a force, but that's allowed).
-                       # So, we can't simply say rev-list $oldrev..$newrev.  Instead
-                       # we find the common base of the two revs and list from there
-                       baserev=$(git-merge-base $oldrev $newrev)
-
-                       # Commit with a parent
-                       for rev in $(git-rev-list $newrev --not $baserev --all)
-                       do
-                               revtype=$(git-cat-file -t "$rev")
-                               echo "       via  $rev ($revtype)"
-                       done
-                       if [ "$baserev" = "$oldrev" ]; then
-                               echo "      from  $oldrev ($oldrev_type)"
-                       else
-                               echo "  based on  $baserev"
-                               echo "      from  $oldrev ($oldrev_type)"
-                               echo ""
-                               echo "This ref update crossed a branch point; i.e. the old rev is not a strict subset"
-                               echo "of the new rev.  This occurs, when you --force push a change in a situation"
-                               echo "like this:"
-                               echo ""
-                               echo " * -- * -- B -- O -- O -- O ($oldrev)"
-                               echo "            \\"
-                               echo "             N -- N -- N ($newrev)"
-                               echo ""
-                               echo "Therefore, we assume that you've already had alert emails for all of the O"
-                               echo "revisions, and now give you all the revisions in the N branch from the common"
-                               echo "base, B ($baserev), up to the new revision."
-                       fi
-                       echo ""
-                       echo $LOGBEGIN
-                       git log $newrev --not $baserev --all
-                       echo $LOGEND
-                       echo ""
-                       echo "Diffstat:"
-                       git-diff-tree --no-color --stat -M -C --find-copies-harder $baserev..$newrev
-               fi
-               ;;
-       "annotated tag")
-               # Should we allow changes to annotated tags?
-               if expr "$oldrev" : '0*$' >/dev/null
-               then
-                       # If the old reference is "0000..0000" then this is a new atag
-                       # and so oldrev is not valid
-                       echo "        to  $newrev ($newrev_type)"
-               else
-                       echo "        to  $newrev ($newrev_type)"
-                       echo "      from  $oldrev"
-               fi
-
-               # If this tag succeeds another, then show which tag it replaces
-               prevtag=$(git describe $newrev^ 2>/dev/null | sed 's/-g.*//')
-               if [ -n "$prevtag" ]; then
-                       echo "  replaces  $prevtag"
-               fi
-
-               # Read the tag details
-               eval $(git cat-file tag $newrev | \
-                       sed -n '4s/tagger \([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p')
-               tagged=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds" +"$DATEFORMAT")
-
-               echo " tagged by  $tagger"
-               echo "        on  $tagged"
-
-               echo ""
-               echo $LOGBEGIN
-               echo ""
-
-               if [ -n "$prevtag" ]; then
-                       git rev-list --pretty=short "$prevtag..$newrev" | git shortlog
-               else
-                       git rev-list --pretty=short $newrev | git shortlog
-               fi
-
-               echo $LOGEND
-               echo ""
-               ;;
-       *)
-               # By default, unannotated tags aren't allowed in; if
-               # they are though, it's debatable whether we would even want an
-               # email to be generated; however, I don't want to add another config
-               # option just for that.
-               #
-               # Unannotated tags are more about marking a point than releasing
-               # a version; therefore we don't do the shortlog summary that we
-               # do for annotated tags above - we simply show that the point has
-               # been marked, and print the log message for the marked point for
-               # reference purposes
-               #
-               # Note this section also catches any other reference type (although
-               # there aren't any) and deals with them in the same way.
-               if expr "$oldrev" : '0*$' >/dev/null
-               then
-                       # If the old reference is "0000..0000" then this is a new tag
-                       # and so oldrev is not valid
-                       echo "  as a new  $refname_type"
-                       echo "        to  $newrev ($newrev_type)"
-               else
-                       echo "        to  $newrev ($newrev_type)"
-                       echo "      from  $oldrev"
-               fi
-               echo ""
-               echo $LOGBEGIN
-               git-show --no-color --root -s $newrev
-               echo $LOGEND
-               echo ""
-               ;;
-esac
-
-# Footer
-cat <<-EOF
-
-hooks/update
----
-Git Source Code Management System
-$0 $1 \\
-  $2 \\
-  $3
-EOF
-#) | cat >&2
-) | /usr/sbin/sendmail -t
-
 # --- Finished
 exit 0
diff --git a/trace.c b/trace.c
index 27fef868c4e2276638873cbda7d353cf4b8f67ed..7961a27a2ed4f32c766dabdf12c4115c3d3b36ba 100644 (file)
--- a/trace.c
+++ b/trace.c
 #include "quote.h"
 
 /* Stolen from "imap-send.c". */
-static int git_vasprintf(char **strp, const char *fmt, va_list ap)
+int nfvasprintf(char **strp, const char *fmt, va_list ap)
 {
        int len;
        char tmp[1024];
 
        if ((len = vsnprintf(tmp, sizeof(tmp), fmt, ap)) < 0 ||
            !(*strp = xmalloc(len + 1)))
-               return -1;
+               die("Fatal: Out of memory\n");
        if (len >= (int)sizeof(tmp))
                vsprintf(*strp, fmt, ap);
        else
@@ -41,13 +41,15 @@ static int git_vasprintf(char **strp, const char *fmt, va_list ap)
        return len;
 }
 
-/* Stolen from "imap-send.c". */
-int nfvasprintf(char **str, const char *fmt, va_list va)
+int nfasprintf(char **str, const char *fmt, ...)
 {
-       int ret = git_vasprintf(str, fmt, va);
-       if (ret < 0)
-               die("Fatal: Out of memory\n");
-       return ret;
+       int rc;
+       va_list args;
+
+       va_start(args, fmt);
+       rc = nfvasprintf(str, fmt, args);
+       va_end(args);
+       return rc;
 }
 
 /* Get a trace file descriptor from GIT_TRACE env variable. */
index c8275823d0eb976e95b256f2bce5497f45d5da77..852498eb49fe0cba5e1cd21661288e8321a4b20e 100644 (file)
@@ -5,9 +5,8 @@
 #include "diff.h"
 #include "tree.h"
 
-static char *malloc_base(const char *base, const char *path, int pathlen)
+static char *malloc_base(const char *base, int baselen, const char *path, int pathlen)
 {
-       int baselen = strlen(base);
        char *newbase = xmalloc(baselen + pathlen + 2);
        memcpy(newbase, base, baselen);
        memcpy(newbase + baselen, path, pathlen);
@@ -16,9 +15,9 @@ static char *malloc_base(const char *base, const char *path, int pathlen)
 }
 
 static void show_entry(struct diff_options *opt, const char *prefix, struct tree_desc *desc,
-                      const char *base);
+                      const char *base, int baselen);
 
-static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
+static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const char *base, int baselen, struct diff_options *opt)
 {
        unsigned mode1, mode2;
        const char *path1, *path2;
@@ -28,15 +27,15 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
        sha1 = tree_entry_extract(t1, &path1, &mode1);
        sha2 = tree_entry_extract(t2, &path2, &mode2);
 
-       pathlen1 = strlen(path1);
-       pathlen2 = strlen(path2);
+       pathlen1 = tree_entry_len(path1, sha1);
+       pathlen2 = tree_entry_len(path2, sha2);
        cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2);
        if (cmp < 0) {
-               show_entry(opt, "-", t1, base);
+               show_entry(opt, "-", t1, base, baselen);
                return -1;
        }
        if (cmp > 0) {
-               show_entry(opt, "+", t2, base);
+               show_entry(opt, "+", t2, base, baselen);
                return 1;
        }
        if (!opt->find_copies_harder && !hashcmp(sha1, sha2) && mode1 == mode2)
@@ -47,14 +46,14 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
         * file, we need to consider it a remove and an add.
         */
        if (S_ISDIR(mode1) != S_ISDIR(mode2)) {
-               show_entry(opt, "-", t1, base);
-               show_entry(opt, "+", t2, base);
+               show_entry(opt, "-", t1, base, baselen);
+               show_entry(opt, "+", t2, base, baselen);
                return 0;
        }
 
        if (opt->recursive && S_ISDIR(mode1)) {
                int retval;
-               char *newbase = malloc_base(base, path1, pathlen1);
+               char *newbase = malloc_base(base, baselen, path1, pathlen1);
                if (opt->tree_in_recursive)
                        opt->change(opt, mode1, mode2,
                                    sha1, sha2, base, path1);
@@ -67,32 +66,46 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
        return 0;
 }
 
-static int interesting(struct tree_desc *desc, const char *base, struct diff_options *opt)
+/*
+ * Is a tree entry interesting given the pathspec we have?
+ *
+ * Return:
+ *  - 2 for "yes, and all subsequent entries will be"
+ *  - 1 for yes
+ *  - zero for no
+ *  - negative for "no, and no subsequent entries will be either"
+ */
+static int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)
 {
        const char *path;
+       const unsigned char *sha1;
        unsigned mode;
        int i;
-       int baselen, pathlen;
+       int pathlen;
+       int never_interesting = -1;
 
        if (!opt->nr_paths)
                return 1;
 
-       (void)tree_entry_extract(desc, &path, &mode);
+       sha1 = tree_entry_extract(desc, &path, &mode);
 
-       pathlen = strlen(path);
-       baselen = strlen(base);
+       pathlen = tree_entry_len(path, sha1);
 
-       for (i=0; i < opt->nr_paths; i++) {
+       for (i = 0; i < opt->nr_paths; i++) {
                const char *match = opt->paths[i];
                int matchlen = opt->pathlens[i];
+               int m = -1; /* signals that we haven't called strncmp() */
 
                if (baselen >= matchlen) {
                        /* If it doesn't match, move along... */
                        if (strncmp(base, match, matchlen))
                                continue;
 
-                       /* The base is a subdirectory of a path which was specified. */
-                       return 1;
+                       /*
+                        * The base is a subdirectory of a path which
+                        * was specified, so all of them are interesting.
+                        */
+                       return 2;
                }
 
                /* Does the base match? */
@@ -102,6 +115,37 @@ static int interesting(struct tree_desc *desc, const char *base, struct diff_opt
                match += baselen;
                matchlen -= baselen;
 
+               if (never_interesting) {
+                       /*
+                        * We have not seen any match that sorts later
+                        * than the current path.
+                        */
+
+                       /*
+                        * Does match sort strictly earlier than path
+                        * with their common parts?
+                        */
+                       m = strncmp(match, path,
+                                   (matchlen < pathlen) ? matchlen : pathlen);
+                       if (m < 0)
+                               continue;
+
+                       /*
+                        * If we come here even once, that means there is at
+                        * least one pathspec that would sort equal to or
+                        * later than the path we are currently looking at.
+                        * In other words, if we have never reached this point
+                        * after iterating all pathspecs, it means all
+                        * pathspecs are either outside of base, or inside the
+                        * base but sorts strictly earlier than the current
+                        * one.  In either case, they will never match the
+                        * subsequent entries.  In such a case, we initialized
+                        * the variable to -1 and that is what will be
+                        * returned, allowing the caller to terminate early.
+                        */
+                       never_interesting = 0;
+               }
+
                if (pathlen > matchlen)
                        continue;
 
@@ -112,27 +156,50 @@ static int interesting(struct tree_desc *desc, const char *base, struct diff_opt
                                continue;
                }
 
-               if (strncmp(path, match, pathlen))
-                       continue;
-
-               return 1;
+               if (m == -1)
+                       /*
+                        * we cheated and did not do strncmp(), so we do
+                        * that here.
+                        */
+                       m = strncmp(match, path, pathlen);
+
+               /*
+                * If common part matched earlier then it is a hit,
+                * because we rejected the case where path is not a
+                * leading directory and is shorter than match.
+                */
+               if (!m)
+                       return 1;
        }
-       return 0; /* No matches */
+       return never_interesting; /* No matches */
 }
 
 /* A whole sub-tree went away or appeared */
-static void show_tree(struct diff_options *opt, const char *prefix, struct tree_desc *desc, const char *base)
+static void show_tree(struct diff_options *opt, const char *prefix, struct tree_desc *desc, const char *base, int baselen)
 {
+       int all_interesting = 0;
        while (desc->size) {
-               if (interesting(desc, base, opt))
-                       show_entry(opt, prefix, desc, base);
+               int show;
+
+               if (all_interesting)
+                       show = 1;
+               else {
+                       show = tree_entry_interesting(desc, base, baselen,
+                                                     opt);
+                       if (show == 2)
+                               all_interesting = 1;
+               }
+               if (show < 0)
+                       break;
+               if (show)
+                       show_entry(opt, prefix, desc, base, baselen);
                update_tree_entry(desc);
        }
 }
 
 /* A file entry went away or appeared */
 static void show_entry(struct diff_options *opt, const char *prefix, struct tree_desc *desc,
-                      const char *base)
+                      const char *base, int baselen)
 {
        unsigned mode;
        const char *path;
@@ -140,16 +207,18 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
 
        if (opt->recursive && S_ISDIR(mode)) {
                enum object_type type;
-               char *newbase = malloc_base(base, path, strlen(path));
+               int pathlen = tree_entry_len(path, sha1);
+               char *newbase = malloc_base(base, baselen, path, pathlen);
                struct tree_desc inner;
                void *tree;
+               unsigned long size;
 
-               tree = read_sha1_file(sha1, &type, &inner.size);
+               tree = read_sha1_file(sha1, &type, &size);
                if (!tree || type != OBJ_TREE)
                        die("corrupt tree sha %s", sha1_to_hex(sha1));
 
-               inner.buf = tree;
-               show_tree(opt, prefix, &inner, newbase);
+               init_tree_desc(&inner, tree, size);
+               show_tree(opt, prefix, &inner, newbase, baselen + 1 + pathlen);
 
                free(tree);
                free(newbase);
@@ -158,28 +227,54 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
        }
 }
 
-int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
+static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt)
 {
-       while (t1->size | t2->size) {
-               if (opt->nr_paths && t1->size && !interesting(t1, base, opt)) {
-                       update_tree_entry(t1);
-                       continue;
+       int all_interesting = 0;
+       while (t->size) {
+               int show;
+
+               if (all_interesting)
+                       show = 1;
+               else {
+                       show = tree_entry_interesting(t, base, baselen, opt);
+                       if (show == 2)
+                               all_interesting = 1;
                }
-               if (opt->nr_paths && t2->size && !interesting(t2, base, opt)) {
-                       update_tree_entry(t2);
+               if (!show) {
+                       update_tree_entry(t);
                        continue;
                }
+               /* Skip it all? */
+               if (show < 0)
+                       t->size = 0;
+               return;
+       }
+}
+
+int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
+{
+       int baselen = strlen(base);
+
+       for (;;) {
+               if (opt->quiet && opt->has_changes)
+                       break;
+               if (opt->nr_paths) {
+                       skip_uninteresting(t1, base, baselen, opt);
+                       skip_uninteresting(t2, base, baselen, opt);
+               }
                if (!t1->size) {
-                       show_entry(opt, "+", t2, base);
+                       if (!t2->size)
+                               break;
+                       show_entry(opt, "+", t2, base, baselen);
                        update_tree_entry(t2);
                        continue;
                }
                if (!t2->size) {
-                       show_entry(opt, "-", t1, base);
+                       show_entry(opt, "-", t1, base, baselen);
                        update_tree_entry(t1);
                        continue;
                }
-               switch (compare_tree_entry(t1, t2, base, opt)) {
+               switch (compare_tree_entry(t1, t2, base, baselen, opt)) {
                case -1:
                        update_tree_entry(t1);
                        continue;
@@ -199,16 +294,17 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha
 {
        void *tree1, *tree2;
        struct tree_desc t1, t2;
+       unsigned long size1, size2;
        int retval;
 
-       tree1 = read_object_with_reference(old, tree_type, &t1.size, NULL);
+       tree1 = read_object_with_reference(old, tree_type, &size1, NULL);
        if (!tree1)
                die("unable to read source tree (%s)", sha1_to_hex(old));
-       tree2 = read_object_with_reference(new, tree_type, &t2.size, NULL);
+       tree2 = read_object_with_reference(new, tree_type, &size2, NULL);
        if (!tree2)
                die("unable to read destination tree (%s)", sha1_to_hex(new));
-       t1.buf = tree1;
-       t2.buf = tree2;
+       init_tree_desc(&t1, tree1, size1);
+       init_tree_desc(&t2, tree2, size2);
        retval = diff_tree(&t1, &t2, base, opt);
        free(tree1);
        free(tree2);
@@ -219,15 +315,15 @@ int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_
 {
        int retval;
        void *tree;
+       unsigned long size;
        struct tree_desc empty, real;
 
-       tree = read_object_with_reference(new, tree_type, &real.size, NULL);
+       tree = read_object_with_reference(new, tree_type, &size, NULL);
        if (!tree)
                die("unable to read root tree (%s)", sha1_to_hex(new));
-       real.buf = tree;
+       init_tree_desc(&real, tree, size);
 
-       empty.size = 0;
-       empty.buf = "";
+       init_tree_desc(&empty, "", 0);
        retval = diff_tree(&empty, &real, base, opt);
        free(tree);
        return retval;
index 70f899957e8ce511f0f5a470e8b6927d58d1b63e..cbb24eb3f663cd0370f528d983a2266a55b91c4f 100644 (file)
@@ -2,6 +2,44 @@
 #include "tree-walk.h"
 #include "tree.h"
 
+static const char *get_mode(const char *str, unsigned int *modep)
+{
+       unsigned char c;
+       unsigned int mode = 0;
+
+       while ((c = *str++) != ' ') {
+               if (c < '0' || c > '7')
+                       return NULL;
+               mode = (mode << 3) + (c - '0');
+       }
+       *modep = mode;
+       return str;
+}
+
+static void decode_tree_entry(struct tree_desc *desc, const void *buf, unsigned long size)
+{
+       const char *path;
+       unsigned int mode, len;
+
+       path = get_mode(buf, &mode);
+       if (!path)
+               die("corrupt tree file");
+       len = strlen(path) + 1;
+
+       /* Initialize the descriptor entry */
+       desc->entry.path = path;
+       desc->entry.mode = mode;
+       desc->entry.sha1 = (const unsigned char *)(path + len);
+}
+
+void init_tree_desc(struct tree_desc *desc, const void *buffer, unsigned long size)
+{
+       desc->buffer = buffer;
+       desc->size = size;
+       if (size)
+               decode_tree_entry(desc, buffer, size);
+}
+
 void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
 {
        unsigned long size = 0;
@@ -12,16 +50,15 @@ void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
                if (!buf)
                        die("unable to read tree %s", sha1_to_hex(sha1));
        }
-       desc->size = size;
-       desc->buf = buf;
+       init_tree_desc(desc, buf, size);
        return buf;
 }
 
 static int entry_compare(struct name_entry *a, struct name_entry *b)
 {
        return base_name_compare(
-                       a->path, a->pathlen, a->mode,
-                       b->path, b->pathlen, b->mode);
+                       a->path, tree_entry_len(a->path, a->sha1), a->mode,
+                       b->path, tree_entry_len(b->path, b->sha1), b->mode);
 }
 
 static void entry_clear(struct name_entry *a)
@@ -31,80 +68,33 @@ static void entry_clear(struct name_entry *a)
 
 static void entry_extract(struct tree_desc *t, struct name_entry *a)
 {
-       a->sha1 = tree_entry_extract(t, &a->path, &a->mode);
-       a->pathlen = strlen(a->path);
+       *a = t->entry;
 }
 
 void update_tree_entry(struct tree_desc *desc)
 {
-       const void *buf = desc->buf;
+       const void *buf = desc->buffer;
+       const unsigned char *end = desc->entry.sha1 + 20;
        unsigned long size = desc->size;
-       int len = strlen(buf) + 1 + 20;
+       unsigned long len = end - (const unsigned char *)buf;
 
        if (size < len)
                die("corrupt tree file");
-       desc->buf = (char *) buf + len;
-       desc->size = size - len;
-}
-
-static const char *get_mode(const char *str, unsigned int *modep)
-{
-       unsigned char c;
-       unsigned int mode = 0;
-
-       while ((c = *str++) != ' ') {
-               if (c < '0' || c > '7')
-                       return NULL;
-               mode = (mode << 3) + (c - '0');
-       }
-       *modep = mode;
-       return str;
-}
-
-const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
-{
-       const void *tree = desc->buf;
-       unsigned long size = desc->size;
-       int len = strlen(tree)+1;
-       const unsigned char *sha1 = (unsigned char *) tree + len;
-       const char *path;
-       unsigned int mode;
-
-       path = get_mode(tree, &mode);
-       if (!path || size < len + 20)
-               die("corrupt tree file");
-       *pathp = path;
-       *modep = canon_mode(mode);
-       return sha1;
+       buf = end;
+       size -= len;
+       desc->buffer = buf;
+       desc->size = size;
+       if (size)
+               decode_tree_entry(desc, buf, size);
 }
 
 int tree_entry(struct tree_desc *desc, struct name_entry *entry)
 {
-       const void *tree = desc->buf;
-       const char *path;
-       unsigned long len, size = desc->size;
-
-       if (!size)
+       if (!desc->size)
                return 0;
 
-       path = get_mode(tree, &entry->mode);
-       if (!path)
-               die("corrupt tree file");
-
-       entry->path = path;
-       len = strlen(path);
-       entry->pathlen = len;
-
-       path += len + 1;
-       entry->sha1 = (const unsigned char *) path;
-
-       path += 20;
-       len = path - (char *) tree;
-       if (len > size)
-               die("corrupt tree file");
-
-       desc->buf = path;
-       desc->size = size - len;
+       *entry = desc->entry;
+       update_tree_entry(desc);
        return 1;
 }
 
@@ -169,7 +159,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
 
                sha1 = tree_entry_extract(t, &entry, mode);
                update_tree_entry(t);
-               entrylen = strlen(entry);
+               entrylen = tree_entry_len(entry, sha1);
                if (entrylen > namelen)
                        continue;
                cmp = memcmp(name, entry, entrylen);
@@ -198,10 +188,11 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
 {
        int retval;
        void *tree;
+       unsigned long size;
        struct tree_desc t;
        unsigned char root[20];
 
-       tree = read_object_with_reference(tree_sha1, tree_type, &t.size, root);
+       tree = read_object_with_reference(tree_sha1, tree_type, &size, root);
        if (!tree)
                return -1;
 
@@ -210,7 +201,7 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
                return 0;
        }
 
-       t.buf = tree;
+       init_tree_desc(&t, tree, size);
        retval = find_tree_entry(&t, name, sha1, mode);
        free(tree);
        return retval;
index e57befa4dac0854906d5b792ce546dab0e6dcdc3..43458cf8ce3a115ee22bb3512749d456c93f783c 100644 (file)
@@ -1,19 +1,32 @@
 #ifndef TREE_WALK_H
 #define TREE_WALK_H
 
-struct tree_desc {
-       const void *buf;
-       unsigned long size;
-};
-
 struct name_entry {
        const unsigned char *sha1;
        const char *path;
        unsigned int mode;
-       int pathlen;
 };
 
+struct tree_desc {
+       const void *buffer;
+       struct name_entry entry;
+       unsigned int size;
+};
+
+static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
+{
+       *pathp = desc->entry.path;
+       *modep = canon_mode(desc->entry.mode);
+       return desc->entry.sha1;
+}
+
+static inline int tree_entry_len(const char *name, const unsigned char *sha1)
+{
+       return (char *)sha1 - (char *)name - 1;
+}
+
 void update_tree_entry(struct tree_desc *);
+void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
 const unsigned char *tree_entry_extract(struct tree_desc *, const char **, unsigned int *);
 
 /* Helper function that does both of the above and returns true for success */
diff --git a/tree.c b/tree.c
index 46923ee61bcce99e677abcc37e233359d39cc9fc..d188c0fbaee110a17ca7a0d16dcc979091f44ded 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -83,8 +83,7 @@ int read_tree_recursive(struct tree *tree,
        if (parse_tree(tree))
                return -1;
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &entry)) {
                if (!match_tree_entry(base, baselen, entry.path, entry.mode, match))
@@ -101,14 +100,15 @@ int read_tree_recursive(struct tree *tree,
                if (S_ISDIR(entry.mode)) {
                        int retval;
                        char *newbase;
+                       unsigned int pathlen = tree_entry_len(entry.path, entry.sha1);
 
-                       newbase = xmalloc(baselen + 1 + entry.pathlen);
+                       newbase = xmalloc(baselen + 1 + pathlen);
                        memcpy(newbase, base, baselen);
-                       memcpy(newbase + baselen, entry.path, entry.pathlen);
-                       newbase[baselen + entry.pathlen] = '/';
+                       memcpy(newbase + baselen, entry.path, pathlen);
+                       newbase[baselen + pathlen] = '/';
                        retval = read_tree_recursive(lookup_tree(entry.sha1),
                                                     newbase,
-                                                    baselen + entry.pathlen + 1,
+                                                    baselen + pathlen + 1,
                                                     stage, match, fn);
                        free(newbase);
                        if (retval)
@@ -151,18 +151,14 @@ static void track_tree_refs(struct tree *item)
        struct name_entry entry;
 
        /* Count how many entries there are.. */
-       desc.buf = item->buffer;
-       desc.size = item->size;
-       while (desc.size) {
+       init_tree_desc(&desc, item->buffer, item->size);
+       while (tree_entry(&desc, &entry))
                n_refs++;
-               update_tree_entry(&desc);
-       }
 
        /* Allocate object refs and walk it again.. */
        i = 0;
        refs = alloc_object_refs(n_refs);
-       desc.buf = item->buffer;
-       desc.size = item->size;
+       init_tree_desc(&desc, item->buffer, item->size);
        while (tree_entry(&desc, &entry)) {
                struct object *obj;
 
index 2e2232cbb07e61de3be74302fba67142a58a857b..a0b676903ad042bfc1bb199a33f1658cdfd511c9 100644 (file)
@@ -27,8 +27,7 @@ static struct tree_entry_list *create_tree_entry_list(struct tree *tree)
        if (!tree->object.parsed)
                parse_tree(tree);
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &one)) {
                struct tree_entry_list *entry;
@@ -71,7 +70,6 @@ static int entcmp(const char *name1, int dir1, const char *name2, int dir2)
 
 static int unpack_trees_rec(struct tree_entry_list **posns, int len,
                            const char *base, struct unpack_trees_options *o,
-                           int *indpos,
                            struct tree_entry_list *df_conflict_list)
 {
        int baselen = strlen(base);
@@ -101,7 +99,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
                cache_name = NULL;
 
                /* Check the cache */
-               if (o->merge && *indpos < active_nr) {
+               if (o->merge && o->pos < active_nr) {
                        /* This is a bit tricky: */
                        /* If the index has a subdirectory (with
                         * contents) as the first name, it'll get a
@@ -119,7 +117,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
                         * file case.
                         */
 
-                       cache_name = active_cache[*indpos]->name;
+                       cache_name = active_cache[o->pos]->name;
                        if (strlen(cache_name) > baselen &&
                            !memcmp(cache_name, base, baselen)) {
                                cache_name += baselen;
@@ -159,8 +157,8 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
 
                if (cache_name && !strcmp(cache_name, first)) {
                        any_files = 1;
-                       src[0] = active_cache[*indpos];
-                       remove_cache_entry_at(*indpos);
+                       src[0] = active_cache[o->pos];
+                       remove_cache_entry_at(o->pos);
                }
 
                for (i = 0; i < len; i++) {
@@ -229,7 +227,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
 #if DBRT_DEBUG > 1
                                printf("Added %d entries\n", ret);
 #endif
-                               *indpos += ret;
+                               o->pos += ret;
                        } else {
                                for (i = 0; i < src_size; i++) {
                                        if (src[i]) {
@@ -245,7 +243,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
                        newbase[baselen + pathlen] = '/';
                        newbase[baselen + pathlen + 1] = '\0';
                        if (unpack_trees_rec(subposns, len, newbase, o,
-                                            indpos, df_conflict_list)) {
+                                            df_conflict_list)) {
                                retval = -1;
                                goto leave_directory;
                        }
@@ -376,7 +374,6 @@ static void check_updates(struct cache_entry **src, int nr,
 
 int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
 {
-       int indpos = 0;
        unsigned len = object_list_length(trees);
        struct tree_entry_list **posns;
        int i;
@@ -405,7 +402,7 @@ int unpack_trees(struct object_list *trees, struct unpack_trees_options *o)
                        posn = posn->next;
                }
                if (unpack_trees_rec(posns, len, o->prefix ? o->prefix : "",
-                                    o, &indpos, &df_conflict_list))
+                                    o, &df_conflict_list))
                        return -1;
        }
 
@@ -468,6 +465,64 @@ static void invalidate_ce_path(struct cache_entry *ce)
                cache_tree_invalidate_path(active_cache_tree, ce->name);
 }
 
+static int verify_clean_subdirectory(const char *path, const char *action,
+                                     struct unpack_trees_options *o)
+{
+       /*
+        * we are about to extract "path"; we would not want to lose
+        * anything in the existing directory there.
+        */
+       int namelen;
+       int pos, i;
+       struct dir_struct d;
+       char *pathbuf;
+       int cnt = 0;
+
+       /*
+        * First let's make sure we do not have a local modification
+        * in that directory.
+        */
+       namelen = strlen(path);
+       pos = cache_name_pos(path, namelen);
+       if (0 <= pos)
+               return cnt; /* we have it as nondirectory */
+       pos = -pos - 1;
+       for (i = pos; i < active_nr; i++) {
+               struct cache_entry *ce = active_cache[i];
+               int len = ce_namelen(ce);
+               if (len < namelen ||
+                   strncmp(path, ce->name, namelen) ||
+                   ce->name[namelen] != '/')
+                       break;
+               /*
+                * ce->name is an entry in the subdirectory.
+                */
+               if (!ce_stage(ce)) {
+                       verify_uptodate(ce, o);
+                       ce->ce_mode = 0;
+               }
+               cnt++;
+       }
+
+       /*
+        * Then we need to make sure that we do not lose a locally
+        * present file that is not ignored.
+        */
+       pathbuf = xmalloc(namelen + 2);
+       memcpy(pathbuf, path, namelen);
+       strcpy(pathbuf+namelen, "/");
+
+       memset(&d, 0, sizeof(d));
+       if (o->dir)
+               d.exclude_per_dir = o->dir->exclude_per_dir;
+       i = read_directory(&d, path, pathbuf, namelen+1, NULL);
+       if (i)
+               die("Updating '%s' would lose untracked files in it",
+                   path);
+       free(pathbuf);
+       return cnt;
+}
+
 /*
  * We do not want to remove or overwrite a working tree file that
  * is not tracked, unless it is ignored.
@@ -479,9 +534,62 @@ static void verify_absent(const char *path, const char *action,
 
        if (o->index_only || o->reset || !o->update)
                return;
-       if (!lstat(path, &st) && !(o->dir && excluded(o->dir, path)))
+
+       if (!lstat(path, &st)) {
+               int cnt;
+
+               if (o->dir && excluded(o->dir, path))
+                       /*
+                        * path is explicitly excluded, so it is Ok to
+                        * overwrite it.
+                        */
+                       return;
+               if (S_ISDIR(st.st_mode)) {
+                       /*
+                        * We are checking out path "foo" and
+                        * found "foo/." in the working tree.
+                        * This is tricky -- if we have modified
+                        * files that are in "foo/" we would lose
+                        * it.
+                        */
+                       cnt = verify_clean_subdirectory(path, action, o);
+
+                       /*
+                        * If this removed entries from the index,
+                        * what that means is:
+                        *
+                        * (1) the caller unpack_trees_rec() saw path/foo
+                        * in the index, and it has not removed it because
+                        * it thinks it is handling 'path' as blob with
+                        * D/F conflict;
+                        * (2) we will return "ok, we placed a merged entry
+                        * in the index" which would cause o->pos to be
+                        * incremented by one;
+                        * (3) however, original o->pos now has 'path/foo'
+                        * marked with "to be removed".
+                        *
+                        * We need to increment it by the number of
+                        * deleted entries here.
+                        */
+                       o->pos += cnt;
+                       return;
+               }
+
+               /*
+                * The previous round may already have decided to
+                * delete this path, which is in a subdirectory that
+                * is being replaced with a blob.
+                */
+               cnt = cache_name_pos(path, strlen(path));
+               if (0 <= cnt) {
+                       struct cache_entry *ce = active_cache[cnt];
+                       if (!ce_stage(ce) && !ce->ce_mode)
+                               return;
+               }
+
                die("Untracked working tree file '%s' "
                    "would be %s by merge.", path, action);
+       }
 }
 
 static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
@@ -526,7 +634,7 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old,
        return 1;
 }
 
-static int keep_entry(struct cache_entry *ce)
+static int keep_entry(struct cache_entry *ce, struct unpack_trees_options *o)
 {
        add_cache_entry(ce, ADD_CACHE_OK_TO_ADD);
        return 1;
@@ -683,7 +791,7 @@ int threeway_merge(struct cache_entry **stages,
        if (!head_match || !remote_match) {
                for (i = 1; i < o->head_idx; i++) {
                        if (stages[i]) {
-                               keep_entry(stages[i]);
+                               keep_entry(stages[i], o);
                                count++;
                                break;
                        }
@@ -696,8 +804,8 @@ int threeway_merge(struct cache_entry **stages,
                show_stage_entry(stderr, "remote ", stages[remote_match]);
        }
 #endif
-       if (head) { count += keep_entry(head); }
-       if (remote) { count += keep_entry(remote); }
+       if (head) { count += keep_entry(head, o); }
+       if (remote) { count += keep_entry(remote, o); }
        return count;
 }
 
@@ -714,12 +822,18 @@ int twoway_merge(struct cache_entry **src,
                struct unpack_trees_options *o)
 {
        struct cache_entry *current = src[0];
-       struct cache_entry *oldtree = src[1], *newtree = src[2];
+       struct cache_entry *oldtree = src[1];
+       struct cache_entry *newtree = src[2];
 
        if (o->merge_size != 2)
                return error("Cannot do a twoway merge of %d trees",
                             o->merge_size);
 
+       if (oldtree == o->df_conflict_entry)
+               oldtree = NULL;
+       if (newtree == o->df_conflict_entry)
+               newtree = NULL;
+
        if (current) {
                if ((!oldtree && !newtree) || /* 4 and 5 */
                    (!oldtree && newtree &&
@@ -727,9 +841,9 @@ int twoway_merge(struct cache_entry **src,
                    (oldtree && newtree &&
                     same(oldtree, newtree)) || /* 14 and 15 */
                    (oldtree && newtree &&
-                    !same(oldtree, newtree) && /* 18 and 19*/
+                    !same(oldtree, newtree) && /* 18 and 19 */
                     same(current, newtree))) {
-                       return keep_entry(current);
+                       return keep_entry(current, o);
                }
                else if (oldtree && !newtree && same(current, oldtree)) {
                        /* 10 or 11 */
@@ -775,7 +889,7 @@ int bind_merge(struct cache_entry **src,
        if (a && old)
                die("Entry '%s' overlaps.  Cannot bind.", a->name);
        if (!a)
-               return keep_entry(old);
+               return keep_entry(old, o);
        else
                return merged_entry(a, NULL, o);
 }
@@ -805,7 +919,7 @@ int oneway_merge(struct cache_entry **src,
                            ce_match_stat(old, &st, 1))
                                old->ce_flags |= htons(CE_UPDATE);
                }
-               return keep_entry(old);
+               return keep_entry(old, o);
        }
        return merged_entry(a, old, o);
 }
index 191f7442f10683c8043288eece36f39166fedc95..fee7da43822b63e5b1f24444e5c51c43d3ff5760 100644 (file)
@@ -16,6 +16,7 @@ struct unpack_trees_options {
        int verbose_update;
        int aggressive;
        const char *prefix;
+       int pos;
        struct dir_struct *dir;
        merge_fn_t fn;
 
index 498bf50eb86f9e437dae89fc631499b73a8ec116..d3a09e78d56642db9b1fb1b1ead34ff60dd8c923 100644 (file)
@@ -119,6 +119,7 @@ static void create_pack_file(void)
                int i;
                struct rev_info revs;
 
+               close(lp_pipe[0]);
                pack_pipe = fdopen(lp_pipe[1], "w");
 
                if (create_full_pack)
diff --git a/usage.c b/usage.c
index 4dc5c77633747e0c2b3a4d04fddbd043f8f49e1e..f5e652cc76d7587fd7b682eb865d3436c99b16fb 100644 (file)
--- a/usage.c
+++ b/usage.c
@@ -86,7 +86,7 @@ int error(const char *err, ...)
        return -1;
 }
 
-void warn(const char *warn, ...)
+void warning(const char *warn, ...)
 {
        va_list params;
 
index a25632bc87867748016e32a4ba4652918c8705a3..a0559905a0b7072f4a4b44ea321c1316cfc84414 100644 (file)
@@ -260,7 +260,7 @@ static void wt_status_print_untracked(struct wt_status *s)
        if (file_exists(x))
                add_excludes_from_file(&dir, x);
 
-       read_directory(&dir, ".", "", 0);
+       read_directory(&dir, ".", "", 0, NULL);
        for(i = 0; i < dir.nr; i++) {
                /* check for matching entry, which is unmerged; lifted from
                 * builtin-ls-files:show_other_files */
index 3653864e4bf704c024453df8d9abf26d89b4778d..bf91c0f73c658637d078ac93226148faa3bb0dc4 100644 (file)
@@ -236,12 +236,13 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
        return 0;
 }
 
-unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
+static unsigned long xdl_hash_record_with_whitespace(char const **data,
+               char const *top, long flags) {
        unsigned long ha = 5381;
        char const *ptr = *data;
 
        for (; ptr < top && *ptr != '\n'; ptr++) {
-               if (isspace(*ptr) && (flags & XDF_WHITESPACE_FLAGS)) {
+               if (isspace(*ptr)) {
                        const char *ptr2 = ptr;
                        while (ptr + 1 < top && isspace(ptr[1])
                                        && ptr[1] != '\n')
@@ -270,6 +271,23 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
 }
 
 
+unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
+       unsigned long ha = 5381;
+       char const *ptr = *data;
+
+       if (flags & XDF_WHITESPACE_FLAGS)
+               return xdl_hash_record_with_whitespace(data, top, flags);
+
+       for (; ptr < top && *ptr != '\n'; ptr++) {
+               ha += (ha << 5);
+               ha ^= (unsigned long) *ptr;
+       }
+       *data = ptr < top ? ptr + 1: ptr;
+
+       return ha;
+}
+
+
 unsigned int xdl_hashbits(unsigned int size) {
        unsigned int val = 1, bits = 0;