Merge branch 'jk/pull-rebase-using-fork-point'
authorJunio C Hamano <gitster@pobox.com>
Fri, 27 Dec 2013 22:58:08 +0000 (14:58 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Dec 2013 22:58:08 +0000 (14:58 -0800)
* jk/pull-rebase-using-fork-point:
rebase: use reflog to find common base with upstream
pull: use merge-base --fork-point when appropriate

256 files changed:
.gitignore
Documentation/RelNotes/1.8.5.2.txt [new file with mode: 0644]
Documentation/RelNotes/1.9.txt [new file with mode: 0644]
Documentation/SubmittingPatches
Documentation/config.txt
Documentation/fetch-options.txt
Documentation/git-cherry.txt
Documentation/git-fetch.txt
Documentation/git-for-each-ref.txt
Documentation/git-lost-found.txt [deleted file]
Documentation/git-peek-remote.txt [deleted file]
Documentation/git-push.txt
Documentation/git-repo-config.txt [deleted file]
Documentation/git-rev-parse.txt
Documentation/git-tar-tree.txt [deleted file]
Documentation/git.txt
Documentation/gitcli.txt
Documentation/gitignore.txt
Documentation/gitweb.conf.txt
Documentation/merge-strategies.txt
Documentation/rev-list-options.txt
Documentation/technical/api-parse-options.txt
Documentation/technical/api-remote.txt
Documentation/technical/protocol-capabilities.txt
GIT-VERSION-GEN
Makefile
RelNotes
abspath.c
alias.c
attr.c
bisect.c
branch.c
builtin.h
builtin/apply.c
builtin/archive.c
builtin/branch.c
builtin/checkout.c
builtin/clean.c
builtin/clone.c
builtin/column.c
builtin/commit.c
builtin/config.c
builtin/describe.c
builtin/diff.c
builtin/fast-export.c
builtin/fetch-pack.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/for-each-ref.c
builtin/fsck.c
builtin/get-tar-commit-id.c [new file with mode: 0644]
builtin/help.c
builtin/index-pack.c
builtin/init-db.c
builtin/log.c
builtin/ls-remote.c
builtin/mailinfo.c
builtin/merge-recursive.c
builtin/merge.c
builtin/mv.c
builtin/name-rev.c
builtin/notes.c
builtin/pack-objects.c
builtin/prune.c
builtin/push.c
builtin/receive-pack.c
builtin/reflog.c
builtin/remote.c
builtin/repack.c
builtin/rev-parse.c
builtin/send-pack.c
builtin/shortlog.c
builtin/show-branch.c
builtin/show-ref.c
builtin/symbolic-ref.c
builtin/tag.c
builtin/tar-tree.c [deleted file]
builtin/unpack-objects.c
builtin/update-ref.c
builtin/upload-archive.c
bundle.c
command-list.txt
commit-slab.h
commit.c
compat/vcbuild/scripts/clink.pl [changed mode: 0644->0755]
compat/vcbuild/scripts/lib.pl [changed mode: 0644->0755]
config.c
connect.c
connect.h
connected.c
contrib/buildsystems/engine.pl [changed mode: 0644->0755]
contrib/buildsystems/generate [changed mode: 0644->0755]
contrib/buildsystems/parse.pl [changed mode: 0644->0755]
contrib/completion/git-completion.bash
contrib/completion/git-completion.tcsh
contrib/examples/git-whatchanged.sh
contrib/hooks/post-receive-email
contrib/hooks/pre-auto-gc-battery [changed mode: 0644->0755]
contrib/hooks/setgitperms.perl [changed mode: 0644->0755]
contrib/hooks/update-paranoid [changed mode: 0644->0755]
contrib/mw-to-git/Makefile
contrib/p4import/README [deleted file]
contrib/p4import/git-p4import.py [deleted file]
contrib/p4import/git-p4import.txt [deleted file]
contrib/remote-helpers/git-remote-bzr
contrib/remote-helpers/git-remote-hg
contrib/remote-helpers/test-bzr.sh
contrib/remote-helpers/test-hg.sh
convert.c
daemon.c
diff.c
diff.h
environment.c
fast-import.c
fetch-pack.c
fetch-pack.h
gettext.c
git-compat-util.h
git-gui/Makefile
git-gui/git-gui.sh
git-gui/lib/blame.tcl
git-gui/lib/choose_repository.tcl
git-gui/lib/index.tcl
git-gui/lib/option.tcl
git-gui/lib/spellcheck.tcl
git-gui/macosx/Info.plist
git-lost-found.sh [deleted file]
git-mergetool--lib.sh
git-p4.py
git-parse-remote.sh
git-pull.sh
git-rebase--am.sh
git-rebase--interactive.sh
git-rebase--merge.sh
git-send-email.perl
git-sh-i18n.sh
git-sh-setup.sh
git-submodule.sh
git.c
gitk-git/gitk
gitweb/gitweb.perl
help.c
http-backend.c
http-push.c
http.c
http.h
imap-send.c
log-tree.c
merge-recursive.c
notes-utils.c
notes.c
pager.c
parse-options.c
parse-options.h
pathspec.c
pkt-line.c
pretty.c
refs.c
remote-curl.c
remote-testsvn.c
remote.c
remote.h
revision.c
revision.h
send-pack.c
sequencer.c
setup.c
sha1_file.c
sha1_name.c
shell.c
strbuf.c
submodule.c
t/Git-SVN/00compile.t [changed mode: 0644->0755]
t/Git-SVN/Utils/add_path_to_url.t [changed mode: 0644->0755]
t/Git-SVN/Utils/can_compress.t [changed mode: 0644->0755]
t/Git-SVN/Utils/canonicalize_url.t [changed mode: 0644->0755]
t/Git-SVN/Utils/collapse_dotdot.t [changed mode: 0644->0755]
t/Git-SVN/Utils/fatal.t [changed mode: 0644->0755]
t/Git-SVN/Utils/join_paths.t [changed mode: 0644->0755]
t/gitweb-lib.sh
t/lib-bash.sh
t/lib-cvs.sh
t/lib-diff-alternative.sh
t/lib-gettext.sh
t/lib-git-daemon.sh
t/lib-httpd.sh
t/lib-pack.sh
t/lib-pager.sh
t/lib-prereq-FILEMODE.sh [deleted file]
t/lib-read-tree.sh
t/lib-rebase.sh
t/lib-terminal.sh
t/perf/perf-lib.sh
t/t0002-gitfile.sh
t/t0003-attributes.sh
t/t0202/test.pl [changed mode: 0644->0755]
t/t1005-read-tree-reset.sh
t/t1006-cat-file.sh
t/t1013-loose-object-format.sh [deleted file]
t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 [deleted file]
t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 [deleted file]
t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd [deleted file]
t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 [deleted file]
t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e [deleted file]
t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 [deleted file]
t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd [deleted file]
t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb [deleted file]
t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 [deleted file]
t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 [deleted file]
t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 [deleted file]
t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa [deleted file]
t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f [deleted file]
t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 [deleted file]
t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 [deleted file]
t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 [deleted file]
t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a [deleted file]
t/t1303-wacky-config.sh
t/t1502-rev-parse-parseopt.sh
t/t1506-rev-parse-diagnosis.sh
t/t3701-add-interactive.sh
t/t4102-apply-rename.sh
t/t4116-apply-reverse.sh
t/t4120-apply-popt.sh
t/t4129-apply-samemode.sh
t/t5000-tar-tree.sh
t/t5001-archive-attr.sh
t/t5500-fetch-pack.sh
t/t5510-fetch.sh
t/t5515/fetch.br-unconfig_--tags_.._.git
t/t5515/fetch.master_--tags_.._.git
t/t5516-fetch-push.sh
t/t5525-fetch-tagopt.sh
t/t5536-fetch-conflicts.sh [new file with mode: 0755]
t/t5601-clone.sh
t/t6018-rev-list-glob.sh
t/t6031-merge-recursive.sh
t/t6131-pathspec-icase.sh
t/t6300-for-each-ref.sh
t/t7001-mv.sh
t/t7406-submodule-update.sh
t/t7507-commit-verbose.sh
t/t9150/make-svk-dump [changed mode: 0644->0755]
t/t9151/make-svnmerge-dump [changed mode: 0644->0755]
t/t9200-git-cvsexportcommit.sh
t/test-lib-functions.sh
t/test-lib.sh
tag.c
test-line-buffer.c
test-string-list.c
transport-helper.c
transport.c
unpack-trees.c
upload-pack.c
vcs-svn/fast_export.c
wt-status.c
wt-status.h
index 66199edd4af6ddcd1398bff13fe9065ba4309a22..b5f9defed37c43b2c6075d7065c8cbae2b1797e1 100644 (file)
@@ -2,6 +2,7 @@
 /GIT-CFLAGS
 /GIT-LDFLAGS
 /GIT-PREFIX
+/GIT-PERL-DEFINES
 /GIT-PYTHON-VARS
 /GIT-SCRIPT-DEFINES
 /GIT-USER-AGENT
@@ -75,7 +76,6 @@
 /git-init-db
 /git-instaweb
 /git-log
-/git-lost-found
 /git-ls-files
 /git-ls-remote
 /git-ls-tree
 /git-pack-refs
 /git-parse-remote
 /git-patch-id
-/git-peek-remote
 /git-prune
 /git-prune-packed
 /git-pull
 /git-remote-testsvn
 /git-repack
 /git-replace
-/git-repo-config
 /git-request-pull
 /git-rerere
 /git-reset
 /git-svn
 /git-symbolic-ref
 /git-tag
-/git-tar-tree
 /git-unpack-file
 /git-unpack-objects
 /git-update-index
diff --git a/Documentation/RelNotes/1.8.5.2.txt b/Documentation/RelNotes/1.8.5.2.txt
new file mode 100644 (file)
index 0000000..3ac4984
--- /dev/null
@@ -0,0 +1,20 @@
+Git v1.8.5.2 Release Notes
+==========================
+
+Fixes since v1.8.5.1
+--------------------
+
+ * "git diff -- ':(icase)makefile'" was unnecessarily rejected at the
+   command line parser.
+
+ * "git cat-file --batch-check=ok" did not check the existence of
+   the named object.
+
+ * "git am --abort" sometimes complained about not being able to write
+   a tree with an 0{40} object in it.
+
+ * Two processes creating loose objects at the same time could have
+   failed unnecessarily when the name of their new objects started
+   with the same byte value, due to a race condition.
+
+Also contains typofixes, documentation updates and trivial code clean-ups.
diff --git a/Documentation/RelNotes/1.9.txt b/Documentation/RelNotes/1.9.txt
new file mode 100644 (file)
index 0000000..a966ab4
--- /dev/null
@@ -0,0 +1,186 @@
+Git v1.9 Release Notes
+======================
+
+Backward compatibility notes
+----------------------------
+
+"git submodule foreach $cmd $args" used to treat "$cmd $args" the same
+way "ssh" did, concatenating them into a single string and letting the
+shell unquote. Careless users who forget to sufficiently quote $args
+gets their argument split at $IFS whitespaces by the shell, and got
+unexpected results due to this. Starting from this release, the
+command line is passed directly to the shell, if it has an argument.
+
+Read-only support for experimental loose-object format, in which users
+could optionally choose to write in their loose objects for a short
+while between v1.4.3 to v1.5.3 era, has been dropped.
+
+The meanings of "--tags" option to "git fetch" has changed; the
+command fetches tags _in addition to_ what are fetched by the same
+command line without the option.
+
+A handful of ancient commands that have long been deprecated are
+finally gone (repo-config, tar-tree, lost-found, and peek-remote).
+
+
+Backward compatibility notes (for Git 2.0)
+------------------------------------------
+
+When "git push [$there]" does not say what to push, we have used the
+traditional "matching" semantics so far (all your branches were sent
+to the remote as long as there already are branches of the same name
+over there).  In Git 2.0, the default will change to the "simple"
+semantics, which pushes:
+
+ - only the current branch to the branch with the same name, and only
+   when the current branch is set to integrate with that remote
+   branch, if you are pushing to the same remote as you fetch from; or
+
+ - only the current branch to the branch with the same name, if you
+   are pushing to a remote that is not where you usually fetch from.
+
+Use the user preference configuration variable "push.default" to
+change this.  If you are an old-timer who is used to the "matching"
+semantics, you can set the variable to "matching" to keep the
+traditional behaviour.  If you want to live in the future early, you
+can set it to "simple" today without waiting for Git 2.0.
+
+When "git add -u" (and "git add -A") is run inside a subdirectory and
+does not specify which paths to add on the command line, it
+will operate on the entire tree in Git 2.0 for consistency
+with "git commit -a" and other commands.  There will be no
+mechanism to make plain "git add -u" behave like "git add -u .".
+Current users of "git add -u" (without a pathspec) should start
+training their fingers to explicitly say "git add -u ."
+before Git 2.0 comes.  A warning is issued when these commands are
+run without a pathspec and when you have local changes outside the
+current directory, because the behaviour in Git 2.0 will be different
+from today's version in such a situation.
+
+In Git 2.0, "git add <path>" will behave as "git add -A <path>", so
+that "git add dir/" will notice paths you removed from the directory
+and record the removal.  Versions before Git 2.0, including this
+release, will keep ignoring removals, but the users who rely on this
+behaviour are encouraged to start using "git add --ignore-removal <path>"
+now before 2.0 is released.
+
+The default prefix for "git svn" will change in Git 2.0.  For a long
+time, "git svn" created its remote-tracking branches directly under
+refs/remotes, but it will place them under refs/remotes/origin/ unless
+it is told otherwise with its --prefix option.
+
+
+Updates since v1.8.5
+--------------------
+
+Foreign interfaces, subsystems and ports.
+
+ * The HTTP transport, when talking GSS-Negotiate, uses "100
+   Continue" response to avoid having to rewind and resend a large
+   payload, which may not be always doable.
+
+ * Various bugfixes to remote-bzr and remote-hg (in contrib/).
+
+
+UI, Workflows & Features
+
+ * "gitweb" learned to treat ref hierarchies other than refs/heads as
+   if they are additional branch namespaces (e.g. refs/changes/ in
+   Gerrit).
+
+ * "git for-each-ref --format=..." learned a few formatting directives;
+   e.g. "%(color:red)%(HEAD)%(color:reset) %(refname:short) %(subject)".
+
+ * The command string given to "git submodule foreach" is passed
+   directly to the shell, without being eval'ed.  This is a backward
+   incompatible change that may break existing users.
+
+ * "git log" and friends learned the "--exclude=<glob>" option, to
+   allow people to say "list history of all branches except those that
+   match this pattern" with "git log --exclude='*/*' --branches".
+
+ * "git rev-parse --parseopt" learned a new "--stuck-long" option to
+   help scripts parse options with an optional parameter.
+
+ * The "--tags" option to "git fetch" no longer tells the command to
+   fetch _only_ the tags. It instead fetches tags _in addition to_
+   what are fetched by the same command line without the option.
+
+
+Performance, Internal Implementation, etc.
+
+ * The deprecated parse-options macro OPT_BOOLEAN has been removed;
+   use OPT_BOOL or OPT_COUNTUP in new code.
+
+ * A few duplicate implementations of prefix/suffix string comparison
+   functions have been unified to starts_with() and ends_with().
+
+ * The new PERLLIB_EXTRA makefile variable can be used to specify
+   additional directories Perl modules (e.g. the ones necessary to run
+   git-svn) are installed on the platform when building.
+
+ * "git merge-base" learned the "--fork-point" mode, that implements
+   the same logic used in "git pull --rebase" to find a suitable fork
+   point out of the reflog entries for the remote-tracking branch the
+   work has been based on.
+
+ * A third-party "receive-pack" (the responder to "git push") can
+   advertise the "no-thin" capability to tell "git push" not to use
+   the thin-pack optimization. Our receive-pack has always been
+   capable of accepting and fattening a thin-pack, and will continue
+   not to ask "git push" to use a non-thin pack.
+
+
+Also contains various documentation updates and code clean-ups.
+
+
+Fixes since v1.8.5
+------------------
+
+Unless otherwise noted, all the fixes since v1.8.5 in the maintenance
+track are contained in this release (see the maintenance releases' notes
+for details).
+
+ * "git mv A B/", when B does not exist as a directory, should error
+   out, but it didn't.
+   (merge c57f628 mm/mv-file-to-no-such-dir-with-slash later to maint).
+
+ * A workaround to an old bug in glibc prior to glibc 2.17 has been
+   retired; this would remove a side effect of the workaround that
+   corrupts system error messages in non-C locales.
+
+ * SSL-related options were not passed correctly to underlying socket
+   layer in "git send-email".
+   (merge 5508f3e tr/send-email-ssl later to maint).
+
+ * "git commit -v" appends the patch to the log message before
+   editing, and then removes the patch when the editor returned
+   control. However, the patch was not stripped correctly when the
+   first modified path was a submodule.
+   (merge 1a72cfd jl/commit-v-strip-marker later to maint).
+
+ * "git fetch --depth=0" was a no-op, and was silently ignored.
+   Diagnose it as an error.
+   (merge 5594bca nd/transport-positive-depth-only later to maint).
+
+ * Remote repository URL expressed in scp-style host:path notation are
+   parsed more carefully (e.g. "foo/bar:baz" is local, "[::1]:/~user" asks
+   to connect to user's home directory on host at address ::1.
+   (merge a2036d7 tb/clone-ssh-with-colon-for-port later to maint).
+
+ * "git diff -- ':(icase)makefile'" was unnecessarily rejected at the
+   command line parser.
+   (merge 887c6c1 nd/magic-pathspec later to maint).
+
+ * "git cat-file --batch-check=ok" did not check the existence of
+   the named object.
+   (merge 4ef8d1d sb/sha1-loose-object-info-check-existence later to maint).
+
+ * "git am --abort" sometimes complained about not being able to write
+   a tree with an 0{40} object in it.
+   (merge 77b43ca jk/two-way-merge-corner-case-fix later to maint).
+
+ * Two processes creating loose objects at the same time could have
+   failed unnecessarily when the name of their new objects started
+   with the same byte value, due to a race condition.
+   (merge b2476a6 jh/loose-object-dirs-creation-race later to maint).
index 705557689d7fa46f88f936bb8c42471ffbfb052b..e6d46edbe7376a9f15d4f337a341a344b5197ca4 100644 (file)
@@ -139,8 +139,15 @@ People on the Git mailing list need to be able to read and
 comment on the changes you are submitting.  It is important for
 a developer to be able to "quote" your changes, using standard
 e-mail tools, so that they may comment on specific portions of
-your code.  For this reason, all patches should be submitted
-"inline".  If your log message (including your name on the
+your code.  For this reason, each patch should be submitted
+"inline" in a separate message.
+
+Multiple related patches should be grouped into their own e-mail
+thread to help readers find all parts of the series.  To that end,
+send them as replies to either an additional "cover letter" message
+(see below), the first patch, or the respective preceding patch.
+
+If your log message (including your name on the
 Signed-off-by line) is not writable in ASCII, make sure that
 you send off a message in the correct encoding.
 
index ab26963d61877a2f8e03a3532ace5b31bc68738e..a4058063cedd61d88990faf739bda955834b1ea7 100644 (file)
@@ -2087,8 +2087,8 @@ remote.<name>.vcs::
 
 remote.<name>.prune::
        When set to true, fetching from this remote by default will also
-       remove any remote-tracking branches which no longer exist on the
-       remote (as if the `--prune` option was give on the command line).
+       remove any remote-tracking references that no longer exist on the
+       remote (as if the `--prune` option was given on the command line).
        Overrides `fetch.prune` settings, if any.
 
 remotes.<group>::
index ba1fe4958227dce5ab146a39374cf02c127c0c65..f0ef7d02a5dc6c40eb9aab706e0c43f467b3f8a6 100644 (file)
@@ -41,17 +41,20 @@ ifndef::git-pull[]
 
 -p::
 --prune::
-       After fetching, remove any remote-tracking branches which
-       no longer exist on the remote.
+       After fetching, remove any remote-tracking references that no
+       longer exist on the remote.  Tags are not subject to pruning
+       if they are fetched only because of the default tag
+       auto-following or due to a --tags option.  However, if tags
+       are fetched due to an explicit refspec (either on the command
+       line or in the remote configuration, for example if the remote
+       was cloned with the --mirror option), then they are also
+       subject to pruning.
 endif::git-pull[]
 
-ifdef::git-pull[]
---no-tags::
-endif::git-pull[]
 ifndef::git-pull[]
 -n::
---no-tags::
 endif::git-pull[]
+--no-tags::
        By default, tags that point at objects that are downloaded
        from the remote repository are fetched and stored locally.
        This option disables this automatic tag following. The default
@@ -61,11 +64,12 @@ endif::git-pull[]
 ifndef::git-pull[]
 -t::
 --tags::
-       This is a short-hand for giving `refs/tags/*:refs/tags/*`
-       refspec from the command line, to ask all tags to be fetched
-       and stored locally.  Because this acts as an explicit
-       refspec, the default refspecs (configured with the
-       remote.$name.fetch variable) are overridden and not used.
+       Fetch all tags from the remote (i.e., fetch remote tags
+       `refs/tags/*` into local tags with the same name), in addition
+       to whatever else would otherwise be fetched.  Using this
+       option alone does not subject tags to pruning, even if --prune
+       is used (though tags may be pruned anyway if they are also the
+       destination of an explicit refspec; see '--prune').
 
 --recurse-submodules[=yes|on-demand|no]::
        This option controls if and under what conditions new commits of
index 2d0daae626dd8e58c5a5c72ef999e36f56bcdce7..0ea921a5931647f21f74a44a80622c3d3c16827c 100644 (file)
@@ -3,7 +3,7 @@ git-cherry(1)
 
 NAME
 ----
-git-cherry - Find commits not merged upstream
+git-cherry - Find commits yet to be applied to upstream
 
 SYNOPSIS
 --------
@@ -12,46 +12,26 @@ SYNOPSIS
 
 DESCRIPTION
 -----------
-The changeset (or "diff") of each commit between the fork-point and <head>
-is compared against each commit between the fork-point and <upstream>.
-The diffs are compared after removing any whitespace and line numbers.
+Determine whether there are commits in `<head>..<upstream>` that are
+equivalent to those in the range `<limit>..<head>`.
 
-Every commit that doesn't exist in the <upstream> branch
-has its id (sha1) reported, prefixed by a symbol.  The ones that have
-equivalent change already
-in the <upstream> branch are prefixed with a minus (-) sign, and those
-that only exist in the <head> branch are prefixed with a plus (+) symbol:
-
-               __*__*__*__*__> <upstream>
-              /
-    fork-point
-              \__+__+__-__+__+__-__+__> <head>
-
-
-If a <limit> has been given then the commits along the <head> branch up
-to and including <limit> are not reported:
-
-               __*__*__*__*__> <upstream>
-              /
-    fork-point
-              \__*__*__<limit>__-__+__> <head>
-
-
-Because 'git cherry' compares the changeset rather than the commit id
-(sha1), you can use 'git cherry' to find out if a commit you made locally
-has been applied <upstream> under a different commit id.  For example,
-this will happen if you're feeding patches <upstream> via email rather
-than pushing or pulling commits directly.
+The equivalence test is based on the diff, after removing whitespace
+and line numbers.  git-cherry therefore detects when commits have been
+"copied" by means of linkgit:git-cherry-pick[1], linkgit:git-am[1] or
+linkgit:git-rebase[1].
 
+Outputs the SHA1 of every commit in `<limit>..<head>`, prefixed with
+`-` for commits that have an equivalent in <upstream>, and `+` for
+commits that do not.
 
 OPTIONS
 -------
 -v::
-       Verbose.
+       Show the commit subjects next to the SHA1s.
 
 <upstream>::
-       Upstream branch to compare against.
-       Defaults to the first tracked remote branch, if available.
+       Upstream branch to search for equivalent commits.
+       Defaults to the upstream branch of HEAD.
 
 <head>::
        Working branch; defaults to HEAD.
@@ -59,6 +39,103 @@ OPTIONS
 <limit>::
        Do not report commits up to (and including) limit.
 
+EXAMPLES
+--------
+
+Patch workflows
+~~~~~~~~~~~~~~~
+
+git-cherry is frequently used in patch-based workflows (see
+linkgit:gitworkflows[7]) to determine if a series of patches has been
+applied by the upstream maintainer.  In such a workflow you might
+create and send a topic branch like this:
+
+------------
+$ git checkout -b topic origin/master
+# work and create some commits
+$ git format-patch origin/master
+$ git send-email ... 00*
+------------
+
+Later, you can see whether your changes have been applied by saying
+(still on `topic`):
+
+------------
+$ git fetch  # update your notion of origin/master
+$ git cherry -v
+------------
+
+Concrete example
+~~~~~~~~~~~~~~~~
+
+In a situation where topic consisted of three commits, and the
+maintainer applied two of them, the situation might look like:
+
+------------
+$ git log --graph --oneline --decorate --boundary origin/master...topic
+* 7654321 (origin/master) upstream tip commit
+[... snip some other commits ...]
+* cccc111 cherry-pick of C
+* aaaa111 cherry-pick of A
+[... snip a lot more that has happened ...]
+| * cccc000 (topic) commit C
+| * bbbb000 commit B
+| * aaaa000 commit A
+|/
+o 1234567 branch point
+------------
+
+In such cases, git-cherry shows a concise summary of what has yet to
+be applied:
+
+------------
+$ git cherry origin/master topic
+- cccc000... commit C
++ bbbb000... commit B
+- aaaa000... commit A
+------------
+
+Here, we see that the commits A and C (marked with `-`) can be
+dropped from your `topic` branch when you rebase it on top of
+`origin/master`, while the commit B (marked with `+`) still needs to
+be kept so that it will be sent to be applied to `origin/master`.
+
+
+Using a limit
+~~~~~~~~~~~~~
+
+The optional <limit> is useful in cases where your topic is based on
+other work that is not in upstream.  Expanding on the previous
+example, this might look like:
+
+------------
+$ git log --graph --oneline --decorate --boundary origin/master...topic
+* 7654321 (origin/master) upstream tip commit
+[... snip some other commits ...]
+* cccc111 cherry-pick of C
+* aaaa111 cherry-pick of A
+[... snip a lot more that has happened ...]
+| * cccc000 (topic) commit C
+| * bbbb000 commit B
+| * aaaa000 commit A
+| * 0000fff (base) unpublished stuff F
+[... snip ...]
+| * 0000aaa unpublished stuff A
+|/
+o 1234567 merge-base between upstream and topic
+------------
+
+By specifying `base` as the limit, you can avoid listing commits
+between `base` and `topic`:
+
+------------
+$ git cherry origin/master topic base
+- cccc000... commit C
++ bbbb000... commit B
+- aaaa000... commit A
+------------
+
+
 SEE ALSO
 --------
 linkgit:git-patch-id[1]
index e08a028946978882cc1a70d3ab205490fd62b2c6..5809aa4eb94e969bf700806b1ef3df504ebcfd2b 100644 (file)
@@ -24,19 +24,22 @@ The ref names and their object names of fetched refs are stored
 in `.git/FETCH_HEAD`.  This information is left for a later merge
 operation done by 'git merge'.
 
-When <refspec> stores the fetched result in remote-tracking branches,
-the tags that point at these branches are automatically
-followed.  This is done by first fetching from the remote using
-the given <refspec>s, and if the repository has objects that are
-pointed by remote tags that it does not yet have, then fetch
-those missing tags.  If the other end has tags that point at
-branches you are not interested in, you will not get them.
+By default, tags are auto-followed.  This means that when fetching
+from a remote, any tags on the remote that point to objects that exist
+in the local repository are fetched.  The effect is to fetch tags that
+point at branches that you are interested in.  This default behavior
+can be changed by using the --tags or --no-tags options, by
+configuring remote.<name>.tagopt, or by using a refspec that fetches
+tags explicitly.
 
 'git fetch' can fetch from either a single named repository,
 or from several repositories at once if <group> is given and
 there is a remotes.<group> entry in the configuration file.
 (See linkgit:git-config[1]).
 
+When no remote is specified, by default the `origin` remote will be used,
+unless there's an upstream branch configured for the current branch.
+
 OPTIONS
 -------
 include::fetch-options.txt[]
index f2e08d11c19cf127c5f7d484b0c3d66fc475d547..94f5c465da008cc8ed009c5b1e1c2b262612b380 100644 (file)
@@ -91,7 +91,19 @@ objectname::
 upstream::
        The name of a local ref which can be considered ``upstream''
        from the displayed ref. Respects `:short` in the same way as
-       `refname` above.
+       `refname` above.  Additionally respects `:track` to show
+       "[ahead N, behind M]" and `:trackshort` to show the terse
+       version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
+       or "=" (in sync).  Has no effect if the ref does not have
+       tracking information associated with it.
+
+HEAD::
+       '*' if HEAD matches current ref (the checked out branch), ' '
+       otherwise.
+
+color::
+       Change output color.  Followed by `:<colorname>`, where names
+       are described in `color.branch.*`.
 
 In addition to the above, for commit and tag objects, the header
 field names (`tree`, `parent`, `object`, `type`, and `tag`) can
diff --git a/Documentation/git-lost-found.txt b/Documentation/git-lost-found.txt
deleted file mode 100644 (file)
index d549328..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-git-lost-found(1)
-=================
-
-NAME
-----
-git-lost-found - Recover lost refs that luckily have not yet been pruned
-
-SYNOPSIS
---------
-[verse]
-'git lost-found'
-
-DESCRIPTION
------------
-
-*NOTE*: this command is deprecated.  Use linkgit:git-fsck[1] with
-the option '--lost-found' instead.
-
-Finds dangling commits and tags from the object database, and
-creates refs to them in the .git/lost-found/ directory.  Commits and
-tags that dereference to commits are stored in .git/lost-found/commit,
-and other objects are stored in .git/lost-found/other.
-
-
-OUTPUT
-------
-Prints to standard output the object names and one-line descriptions
-of any commits or tags found.
-
-EXAMPLE
--------
-
-Suppose you run 'git tag -f' and mistype the tag to overwrite.
-The ref to your tag is overwritten, but until you run 'git
-prune', the tag itself is still there.
-
-------------
-$ git lost-found
-[1ef2b196d909eed523d4f3c9bf54b78cdd6843c6] GIT 0.99.9c
-...
-------------
-
-Also you can use gitk to browse how any tags found relate to each
-other.
-
-------------
-$ gitk $(cd .git/lost-found/commit && echo ??*)
-------------
-
-After making sure you know which the object is the tag you are looking
-for, you can reconnect it to your regular `refs` hierarchy by using
-the `update-ref` command.
-
-------------
-$ git cat-file -t 1ef2b196
-tag
-$ git cat-file tag 1ef2b196
-object fa41bbce8e38c67a218415de6cfa510c7e50032a
-type commit
-tag v0.99.9c
-tagger Junio C Hamano <junkio@cox.net> 1131059594 -0800
-
-GIT 0.99.9c
-
-This contains the following changes from the "master" branch, since
-...
-$ git update-ref refs/tags/not-lost-anymore 1ef2b196
-$ git rev-parse not-lost-anymore
-1ef2b196d909eed523d4f3c9bf54b78cdd6843c6
-------------
-
-GIT
----
-Part of the linkgit:git[1] suite
diff --git a/Documentation/git-peek-remote.txt b/Documentation/git-peek-remote.txt
deleted file mode 100644 (file)
index 87ea3fb..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-git-peek-remote(1)
-==================
-
-NAME
-----
-git-peek-remote - List the references in a remote repository
-
-
-SYNOPSIS
---------
-[verse]
-'git peek-remote' [--upload-pack=<git-upload-pack>] [<host>:]<directory>
-
-DESCRIPTION
------------
-This command is deprecated; use 'git ls-remote' instead.
-
-OPTIONS
--------
---upload-pack=<git-upload-pack>::
-       Use this to specify the path to 'git-upload-pack' on the
-       remote side, if it is not found on your $PATH. Some
-       installations of sshd ignores the user's environment
-       setup scripts for login shells (e.g. .bash_profile) and
-       your privately installed git may not be found on the system
-       default $PATH.  Another workaround suggested is to set
-       up your $PATH in ".bashrc", but this flag is for people
-       who do not want to pay the overhead for non-interactive
-       shells, but prefer having a lean .bashrc file (they set most of
-       the things up in .bash_profile).
-
-<host>::
-       A remote host that houses the repository.  When this
-       part is specified, 'git-upload-pack' is invoked via
-       ssh.
-
-<directory>::
-       The repository to sync from.
-
-
-GIT
----
-Part of the linkgit:git[1] suite
index 9eec74091097c0ea5c9fea69a09eb63e3cebd8d9..2b7f4f939f38626dbd796b808cc21285ad5c8c3d 100644 (file)
@@ -56,8 +56,13 @@ it can be any arbitrary "SHA-1 expression", such as `master~4` or
 +
 The <dst> tells which ref on the remote side is updated with this
 push. Arbitrary expressions cannot be used here, an actual ref must
-be named. If `:`<dst> is omitted, the same ref as <src> will be
-updated.
+be named.
+If `git push [<repository>]` without any `<refspec>` argument is set to
+update some ref at the destination with `<src>` with
+`remote.<repository>.push` configuration variable, `:<dst>` part can
+be omitted---such a push will update a ref that `<src>` normally updates
+without any `<refspec>` on the command line.  Otherwise, missing
+`:<dst>` means to update the same ref as the `<src>`.
 +
 The object referenced by <src> is used to update the <dst> reference
 on the remote side.  By default this is only allowed if <dst> is not
diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt
deleted file mode 100644 (file)
index 9ec115b..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-git-repo-config(1)
-==================
-
-NAME
-----
-git-repo-config - Get and set repository or global options
-
-
-SYNOPSIS
---------
-[verse]
-'git repo-config' ...
-
-
-DESCRIPTION
------------
-
-This is a synonym for linkgit:git-config[1].  Please refer to the
-documentation of that command.
-
-GIT
----
-Part of the linkgit:git[1] suite
index d068a653778d6713d6ab370379dadf0d6f754856..0d2cdcde556662d9d858dc282a9fced469814337 100644 (file)
@@ -50,6 +50,10 @@ Options for --parseopt
        the first non-option argument.  This can be used to parse sub-commands
        that take options themselves.
 
+--stuck-long::
+       Only meaningful in `--parseopt` mode. Output the options in their
+       long form if available, and with their arguments stuck.
+
 Options for Filtering
 ~~~~~~~~~~~~~~~~~~~~~
 
@@ -173,6 +177,20 @@ shown.  If the pattern does not contain a globbing character (`?`,
        character (`?`, `*`, or `[`), it is turned into a prefix
        match by appending `/*`.
 
+--exclude=<glob-pattern>::
+       Do not include refs matching '<glob-pattern>' that the next `--all`,
+       `--branches`, `--tags`, `--remotes`, or `--glob` would otherwise
+       consider. Repetitions of this option accumulate exclusion patterns
+       up to the next `--all`, `--branches`, `--tags`, `--remotes`, or
+       `--glob` option (other options or arguments do not clear
+       accumlated patterns).
++
+The patterns given should not begin with `refs/heads`, `refs/tags`, or
+`refs/remotes` when applied to `--branches`, `--tags`, or `--remotes`,
+respectively, and they must begin with `refs/` when applied to `--glob`
+or `--all`. If a trailing '/{asterisk}' is intended, it must be given
+explicitly.
+
 --disambiguate=<prefix>::
        Show every object whose name begins with the given prefix.
        The <prefix> must be at least 4 hexadecimal digits long to
@@ -285,7 +303,9 @@ Each line of options has this format:
        `<flags>` are of `*`, `=`, `?` or `!`.
        * Use `=` if the option takes an argument.
 
-       * Use `?` to mean that the option is optional (though its use is discouraged).
+       * Use `?` to mean that the option takes an optional argument. You
+         probably want to use the `--stuck-long` mode to be able to
+         unambiguously parse the optional argument.
 
        * Use `*` to mean that this option should not be listed in the usage
          generated for the `-h` argument. It's shown for `--help-all` as
diff --git a/Documentation/git-tar-tree.txt b/Documentation/git-tar-tree.txt
deleted file mode 100644 (file)
index f7362dc..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-git-tar-tree(1)
-===============
-
-NAME
-----
-git-tar-tree - Create a tar archive of the files in the named tree object
-
-
-SYNOPSIS
---------
-[verse]
-'git tar-tree' [--remote=<repo>] <tree-ish> [ <base> ]
-
-DESCRIPTION
------------
-THIS COMMAND IS DEPRECATED.  Use 'git archive' with `--format=tar`
-option instead (and move the <base> argument to `--prefix=base/`).
-
-Creates a tar archive containing the tree structure for the named tree.
-When <base> is specified it is added as a leading path to the files in the
-generated tar archive.
-
-'git tar-tree' behaves differently when given a tree ID versus when given
-a commit ID or tag ID.  In the first case the current time is used as
-modification time of each file in the archive.  In the latter case the
-commit time as recorded in the referenced commit object is used instead.
-Additionally the commit ID is stored in a global extended pax header.
-It can be extracted using 'git get-tar-commit-id'.
-
-OPTIONS
--------
-
-<tree-ish>::
-       The tree or commit to produce tar archive for.  If it is
-       the object name of a commit object.
-
-<base>::
-       Leading path to the files in the resulting tar archive.
-
---remote=<repo>::
-       Instead of making a tar archive from local repository,
-       retrieve a tar archive from a remote repository.
-
-CONFIGURATION
--------------
-
-tar.umask::
-       This variable can be used to restrict the permission bits of
-       tar archive entries.  The default is 0002, which turns off the
-       world write bit.  The special value "user" indicates that the
-       archiving user's umask will be used instead.  See umask(2) for
-       details.
-
-EXAMPLES
---------
-`git tar-tree HEAD junk | (cd /var/tmp/ && tar xf -)`::
-
-       Create a tar archive that contains the contents of the
-       latest commit on the current branch, and extracts it in
-       `/var/tmp/junk` directory.
-
-`git tar-tree v1.4.0 git-1.4.0 | gzip >git-1.4.0.tar.gz`::
-
-       Create a tarball for v1.4.0 release.
-
-`git tar-tree v1.4.0^{tree} git-1.4.0 | gzip >git-1.4.0.tar.gz`::
-
-       Create a tarball for v1.4.0 release, but without a
-       global extended pax header.
-
-`git tar-tree --remote=example.com:git.git v1.4.0 >git-1.4.0.tar`::
-
-       Get a tarball v1.4.0 from example.com.
-
-`git tar-tree HEAD:Documentation/ git-docs > git-1.4.0-docs.tar`::
-
-       Put everything in the current head's Documentation/ directory
-       into 'git-1.4.0-docs.tar', with the prefix 'git-docs/'.
-
-GIT
----
-Part of the linkgit:git[1] suite
index 4448ce2704284bde15a8a3222545993035e56467..cc0e5e2bfe66a0962283fd570c5e440e72b57813 100644 (file)
@@ -43,9 +43,10 @@ unreleased) version of Git, that is available from 'master'
 branch of the `git.git` repository.
 Documentation for older releases are available here:
 
-* link:v1.8.5.1/git.html[documentation for release 1.8.5.1]
+* link:v1.8.5.2/git.html[documentation for release 1.8.5.2]
 
 * release notes for
+  link:RelNotes/1.8.5.2.txt[1.8.5.2],
   link:RelNotes/1.8.5.1.txt[1.8.5.1],
   link:RelNotes/1.8.5.txt[1.8.5].
 
index 41bed2983f936bc936cb7e655ceb3ce04146aeeb..3f33ca5507a7a4b61030b1ad04b37387d7abdb37 100644 (file)
@@ -72,11 +72,11 @@ scripting Git:
  * splitting short options to separate words (prefer `git foo -a -b`
    to `git foo -ab`, the latter may not even work).
 
- * when a command line option takes an argument, use the 'sticked' form.  In
+ * when a command line option takes an argument, use the 'stuck' form.  In
    other words, write `git foo -oArg` instead of `git foo -o Arg` for short
    options, and `git foo --long-opt=Arg` instead of `git foo --long-opt Arg`
    for long options.  An option that takes optional option-argument must be
-   written in the 'sticked' form.
+   written in the 'stuck' form.
 
  * when you give a revision parameter to a command, make sure the parameter is
    not ambiguous with a name of a file in the work tree.  E.g. do not write
@@ -165,7 +165,7 @@ $ git foo -o Arg
 ----------------------------
 
 However, this is *NOT* allowed for switches with an optional value, where the
-'sticked' form must be used:
+'stuck' form must be used:
 ----------------------------
 $ git describe --abbrev HEAD     # correct
 $ git describe --abbrev=10 HEAD  # correct
index f9719605123003c97bdf2999f912712536fa927a..205e80ef884a8c8852d7e83ca1ee660a5e1e8414 100644 (file)
@@ -79,8 +79,10 @@ PATTERN FORMAT
 
  - An optional prefix "`!`" which negates the pattern; any
    matching file excluded by a previous pattern will become
-   included again.  If a negated pattern matches, this will
-   override lower precedence patterns sources.
+   included again. It is not possible to re-include a file if a parent
+   directory of that file is excluded. Git doesn't list excluded
+   directories for performance reasons, so any patterns on contained
+   files have no effect, no matter where they are defined.
    Put a backslash ("`\`") in front of the first "`!`" for patterns
    that begin with a literal "`!`", for example, "`\!important!.txt`".
 
@@ -182,6 +184,19 @@ Another example:
 The second .gitignore prevents Git from ignoring
 `arch/foo/kernel/vmlinux.lds.S`.
 
+Example to exclude everything except a specific directory `foo/bar`
+(note the `/*` - without the slash, the wildcard would also exclude
+everything within `foo/bar`):
+
+--------------------------------------------------------------
+    $ cat .gitignore
+    # exclude everything except directory foo/bar
+    /*
+    !/foo
+    /foo/*
+    !/foo/bar
+--------------------------------------------------------------
+
 SEE ALSO
 --------
 linkgit:git-rm[1],
index e2113d93c9d34aa0af3fd421d5f6ed9bf01ad896..db4154f9d5c84bfb1dc4453f3c3d5be1a525fc02 100644 (file)
@@ -849,6 +849,43 @@ time zones in the form of "+/-HHMM", such as "+0200".
 +
 Project specific override is not supported.
 
+extra-branch-refs::
+       List of additional directories under "refs" which are going to
+       be used as branch refs. For example if you have a gerrit setup
+       where all branches under refs/heads/ are official,
+       push-after-review ones and branches under refs/sandbox/,
+       refs/wip and refs/other are user ones where permissions are
+       much wider, then you might want to set this variable as
+       follows:
++
+--------------------------------------------------------------------------------
+$feature{'extra-branch-refs'}{'default'} =
+       ['sandbox', 'wip', 'other'];
+--------------------------------------------------------------------------------
++
+This feature can be configured on per-repository basis after setting
+$feature{'extra-branch-refs'}{'override'} to true, via repository's
+`gitweb.extraBranchRefs` configuration variable, which contains a
+space separated list of refs. An example:
++
+--------------------------------------------------------------------------------
+[gitweb]
+       extraBranchRefs = sandbox wip other
+--------------------------------------------------------------------------------
++
+The gitweb.extraBranchRefs is actually a multi-valued configuration
+variable, so following example is also correct and the result is the
+same as of the snippet above:
++
+--------------------------------------------------------------------------------
+[gitweb]
+       extraBranchRefs = sandbox
+       extraBranchRefs = wip other
+--------------------------------------------------------------------------------
++
+It is an error to specify a ref that does not pass "git check-ref-format"
+scrutiny. Duplicated values are filtered.
+
 
 EXAMPLES
 --------
index 49a9a7d53f5836ecf2c5bcadb30f0d314414afe0..fb6e593e7c6f287612f30be6206c0492d77e38d3 100644 (file)
@@ -113,3 +113,11 @@ subtree::
        match the tree structure of A, instead of reading the trees at
        the same level. This adjustment is also done to the common
        ancestor tree.
+
+With the strategies that use 3-way merge (including the default, 'recursive'),
+if a change is made on both branches, but later reverted on one of the
+branches, that change will be present in the merged result; some people find
+this behavior confusing.  It occurs because only the heads and the merge base
+are considered when performing a merge, not the individual commits.  The merge
+algorithm therefore considers the reverted change as no change at all, and
+substitutes the changed version instead.
index 2991d70a4a24d10c7f121b766d5f52545414b591..03533af7152e8b137cd3d885de3ec273b91d4791 100644 (file)
@@ -153,6 +153,21 @@ parents) and `--max-parents=-1` (negative numbers denote no upper limit).
        is automatically prepended if missing. If pattern lacks '?', '{asterisk}',
        or '[', '/{asterisk}' at the end is implied.
 
+--exclude=<glob-pattern>::
+
+       Do not include refs matching '<glob-pattern>' that the next `--all`,
+       `--branches`, `--tags`, `--remotes`, or `--glob` would otherwise
+       consider. Repetitions of this option accumulate exclusion patterns
+       up to the next `--all`, `--branches`, `--tags`, `--remotes`, or
+       `--glob` option (other options or arguments do not clear
+       accumlated patterns).
++
+The patterns given should not begin with `refs/heads`, `refs/tags`, or
+`refs/remotes` when applied to `--branches`, `--tags`, or `--remotes`,
+respectively, and they must begin with `refs/` when applied to `--glob`
+or `--all`. If a trailing '/{asterisk}' is intended, it must be given
+explicitly.
+
 --ignore-missing::
        Upon seeing an invalid object name in the input, pretend as if
        the bad input was not given.
index 0be2b5159f1b349f0c263eb9e8ba696e2a57ebc0..be50cf4de35c856da051f985eb42c22dbaac88e4 100644 (file)
@@ -29,9 +29,9 @@ that allow to change the behavior of a command.
 
 The parse-options API allows:
 
-* 'sticked' and 'separate form' of options with arguments.
-  `-oArg` is sticked, `-o Arg` is separate form.
-  `--option=Arg` is sticked, `--option Arg` is separate form.
+* 'stuck' and 'separate form' of options with arguments.
+  `-oArg` is stuck, `-o Arg` is separate form.
+  `--option=Arg` is stuck, `--option Arg` is separate form.
 
 * Long options may be 'abbreviated', as long as the abbreviation
   is unambiguous.
index 4be87768f62c004d22e2e28603e9e17625aa93b9..5d245aa9d1b1654749ee51495e9eebda261c3681 100644 (file)
@@ -58,16 +58,16 @@ default remote, given the current branch and configuration.
 struct refspec
 --------------
 
-A struct refspec holds the parsed interpretation of a refspec. If it
-will force updates (starts with a '+'), force is true. If it is a
-pattern (sides end with '*') pattern is true. src and dest are the two
-sides (if a pattern, only the part outside of the wildcards); if there
-is only one side, it is src, and dst is NULL; if sides exist but are
-empty (i.e., the refspec either starts or ends with ':'), the
-corresponding side is "".
-
-This parsing can be done to an array of strings to give an array of
-struct refpsecs with parse_ref_spec().
+A struct refspec holds the parsed interpretation of a refspec.  If it
+will force updates (starts with a '+'), force is true.  If it is a
+pattern (sides end with '*') pattern is true.  src and dest are the
+two sides (including '*' characters if present); if there is only one
+side, it is src, and dst is NULL; if sides exist but are empty (i.e.,
+the refspec either starts or ends with ':'), the corresponding side is
+"".
+
+An array of strings can be parsed into an array of struct refspecs
+using parse_fetch_refspec() or parse_push_refspec().
 
 remote_find_tracking(), given a remote and a struct refspec with
 either src or dst filled out, will fill out the other such that the
index fd8ffa5df38c8dd1a682ab77327654a4c2b80cd4..e3e792476e7a6b7554582469b2c5ac172b2f17dd 100644 (file)
@@ -72,14 +72,29 @@ interleaved with S-R-Q.
 thin-pack
 ---------
 
-This capability means that the server can send a 'thin' pack, a pack
-which does not contain base objects; if those base objects are available
-on client side. Client requests 'thin-pack' capability when it
-understands how to "thicken" it by adding required delta bases making
-it self-contained.
-
-Client MUST NOT request 'thin-pack' capability if it cannot turn a thin
-pack into a self-contained pack.
+A thin pack is one with deltas which reference base objects not
+contained within the pack (but are known to exist at the receiving
+end). This can reduce the network traffic significantly, but it
+requires the receiving end to know how to "thicken" these packs by
+adding the missing bases to the pack.
+
+The upload-pack server advertises 'thin-pack' when it can generate
+and send a thin pack. A client requests the 'thin-pack' capability
+when it understands how to "thicken" it, notifying the server that
+it can receive such a pack. A client MUST NOT request the
+'thin-pack' capability if it cannot turn a thin pack into a
+self-contained pack.
+
+Receive-pack, on the other hand, is assumed by default to be able to
+handle thin packs, but can ask the client not to use the feature by
+advertising the 'no-thin' capability. A client MUST NOT send a thin
+pack if the server advertises the 'no-thin' capability.
+
+The reasons for this asymmetry are historical. The receive-pack
+program did not exist until after the invention of thin packs, so
+historically the reference implementation of receive-pack always
+understood thin packs. Adding 'no-thin' later allowed receive-pack
+to disable the feature in a backwards-compatible manner.
 
 
 side-band, side-band-64k
index 99a62f3bafdf4e5f8392bc72d9619fd9d3a6a671..b9532f0ce4e308ccbe92ebc929a596c8f8589084 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v1.8.5
+DEF_VER=v1.8.5.GIT
 
 LF='
 '
index af847f84685af41a7da02c3c12fbdc1daa780f1c..b4af1e20586fb44af46139b17814e53afc4c41a4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -452,7 +452,6 @@ SCRIPT_SH += git-am.sh
 SCRIPT_SH += git-bisect.sh
 SCRIPT_SH += git-difftool--helper.sh
 SCRIPT_SH += git-filter-branch.sh
-SCRIPT_SH += git-lost-found.sh
 SCRIPT_SH += git-merge-octopus.sh
 SCRIPT_SH += git-merge-one-file.sh
 SCRIPT_SH += git-merge-resolve.sh
@@ -587,11 +586,8 @@ BUILT_INS += git-cherry$X
 BUILT_INS += git-cherry-pick$X
 BUILT_INS += git-format-patch$X
 BUILT_INS += git-fsck-objects$X
-BUILT_INS += git-get-tar-commit-id$X
 BUILT_INS += git-init$X
 BUILT_INS += git-merge-subtree$X
-BUILT_INS += git-peek-remote$X
-BUILT_INS += git-repo-config$X
 BUILT_INS += git-show$X
 BUILT_INS += git-stage$X
 BUILT_INS += git-status$X
@@ -932,6 +928,7 @@ BUILTIN_OBJS += builtin/fmt-merge-msg.o
 BUILTIN_OBJS += builtin/for-each-ref.o
 BUILTIN_OBJS += builtin/fsck.o
 BUILTIN_OBJS += builtin/gc.o
+BUILTIN_OBJS += builtin/get-tar-commit-id.o
 BUILTIN_OBJS += builtin/grep.o
 BUILTIN_OBJS += builtin/hash-object.o
 BUILTIN_OBJS += builtin/help.o
@@ -983,7 +980,6 @@ BUILTIN_OBJS += builtin/show-ref.o
 BUILTIN_OBJS += builtin/stripspace.o
 BUILTIN_OBJS += builtin/symbolic-ref.o
 BUILTIN_OBJS += builtin/tag.o
-BUILTIN_OBJS += builtin/tar-tree.o
 BUILTIN_OBJS += builtin/unpack-file.o
 BUILTIN_OBJS += builtin/unpack-objects.o
 BUILTIN_OBJS += builtin/update-index.o
@@ -1588,6 +1584,7 @@ PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
 TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
 DIFF_SQ = $(subst ','\'',$(DIFF))
+PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA))
 
 LIBS = $(GITLIBS) $(EXTLIBS)
 
@@ -1792,9 +1789,12 @@ perl/PM.stamp: FORCE
 perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL
        $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F)
 
-$(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl GIT-VERSION-FILE
+PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ)
+$(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-VERSION-FILE
        $(QUIET_GEN)$(RM) $@ $@+ && \
        INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C perl -s --no-print-directory instlibdir` && \
+       INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
+       INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
        sed -e '1{' \
            -e '        s|#!.*perl|#!$(PERL_PATH_SQ)|' \
            -e '        h' \
@@ -1807,6 +1807,13 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl GIT-VERSION-FILE
        chmod +x $@+ && \
        mv $@+ $@
 
+GIT-PERL-DEFINES: FORCE
+       @FLAGS='$(PERL_DEFINES)'; \
+           if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \
+               echo >&2 "    * new perl-specific parameters"; \
+               echo "$$FLAGS" >$@; \
+           fi
+
 
 .PHONY: gitweb
 gitweb:
@@ -2494,7 +2501,8 @@ ifndef NO_TCLTK
        $(MAKE) -C git-gui clean
 endif
        $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
-       $(RM) GIT-USER-AGENT GIT-PREFIX GIT-SCRIPT-DEFINES GIT-PYTHON-VARS
+       $(RM) GIT-USER-AGENT GIT-PREFIX
+       $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS
 
 .PHONY: all install profile-clean clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
index 61c3b54134d985cef6071014604d5b0499712df5..c300119d9690d6f399569c5e873fafe62cc05237 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/1.8.5.txt
\ No newline at end of file
+Documentation/RelNotes/1.9.txt
\ No newline at end of file
index e390994abff32054452e878484e79c249474389f..8b3385a77749108b29d0a25042a13a174ddbc2e4 100644 (file)
--- a/abspath.c
+++ b/abspath.c
@@ -143,7 +143,7 @@ static const char *real_path_internal(const char *path, int die_on_error)
 error_out:
        free(last_elem);
        if (*cwd && chdir(cwd))
-               die_errno ("Could not change back to '%s'", cwd);
+               die_errno("Could not change back to '%s'", cwd);
 
        return retval;
 }
diff --git a/alias.c b/alias.c
index 9938f03c255029ee8f5b10623e5e7bb65f2d7921..5efc3d69866731d0f56464c522b00f253f84c187 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -5,7 +5,7 @@ static char *alias_val;
 
 static int alias_lookup_cb(const char *k, const char *v, void *cb)
 {
-       if (!prefixcmp(k, "alias.") && !strcmp(k + 6, alias_key)) {
+       if (starts_with(k, "alias.") && !strcmp(k + 6, alias_key)) {
                if (!v)
                        return config_error_nonbool(k);
                alias_val = xstrdup(v);
diff --git a/attr.c b/attr.c
index 0e774c6f22f9fd6c7e27490e5bed5be1f9f10de5..8d13d70e80d6d52794d53ed071b8800f9c905a05 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -211,7 +211,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
        name = cp;
        namelen = strcspn(name, blank);
        if (strlen(ATTRIBUTE_MACRO_PREFIX) < namelen &&
-           !prefixcmp(name, ATTRIBUTE_MACRO_PREFIX)) {
+           starts_with(name, ATTRIBUTE_MACRO_PREFIX)) {
                if (!macro_ok) {
                        fprintf(stderr, "%s not allowed: %s:%d\n",
                                name, src, lineno);
index 1e46a4f50e16f059fa768cecc4c8331a88997021..37200b41f1dce3359c491039aeebea0108597833 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -406,9 +406,9 @@ static int register_ref(const char *refname, const unsigned char *sha1,
        if (!strcmp(refname, "bad")) {
                current_bad_sha1 = xmalloc(20);
                hashcpy(current_bad_sha1, sha1);
-       } else if (!prefixcmp(refname, "good-")) {
+       } else if (starts_with(refname, "good-")) {
                sha1_array_append(&good_revs, sha1);
-       } else if (!prefixcmp(refname, "skip-")) {
+       } else if (starts_with(refname, "skip-")) {
                sha1_array_append(&skipped_revs, sha1);
        }
 
index 9e6c68edaf90f27cf447ad1522da6d7de7827141..723a36bc540e41fe30b7b4fc2c8e893c4744ef3a 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -50,7 +50,7 @@ static int should_setup_rebase(const char *origin)
 void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
 {
        const char *shortname = remote + 11;
-       int remote_is_branch = !prefixcmp(remote, "refs/heads/");
+       int remote_is_branch = starts_with(remote, "refs/heads/");
        struct strbuf key = STRBUF_INIT;
        int rebasing = should_setup_rebase(origin);
 
@@ -272,7 +272,7 @@ void create_branch(const char *head,
                break;
        case 1:
                /* Unique completion -- good, only if it is a real branch */
-               if (prefixcmp(real_ref, "refs/heads/") &&
+               if (!starts_with(real_ref, "refs/heads/") &&
                    validate_remote_tracking_branch(real_ref)) {
                        if (explicit_tracking)
                                die(_(upstream_not_branch), start_name);
index b56cf07abc488909a2a38c0b0a7db988902aba96..d4afbfe4187ad45ac9586c9e6f05541cbe67196b 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -103,7 +103,6 @@ extern int cmd_remote(int argc, const char **argv, const char *prefix);
 extern int cmd_remote_ext(int argc, const char **argv, const char *prefix);
 extern int cmd_remote_fd(int argc, const char **argv, const char *prefix);
 extern int cmd_repack(int argc, const char **argv, const char *prefix);
-extern int cmd_repo_config(int argc, const char **argv, const char *prefix);
 extern int cmd_rerere(int argc, const char **argv, const char *prefix);
 extern int cmd_reset(int argc, const char **argv, const char *prefix);
 extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
index ef32e4f62415956aa8e2366589d4cd6200d3bf37..b0d0986226ccb7fa06b08bacba6269b8834e8dd6 100644 (file)
@@ -1409,10 +1409,10 @@ static void recount_diff(const char *line, int size, struct fragment *fragment)
                case '\\':
                        continue;
                case '@':
-                       ret = size < 3 || prefixcmp(line, "@@ ");
+                       ret = size < 3 || !starts_with(line, "@@ ");
                        break;
                case 'd':
-                       ret = size < 5 || prefixcmp(line, "diff ");
+                       ret = size < 5 || !starts_with(line, "diff ");
                        break;
                default:
                        ret = -1;
@@ -1798,11 +1798,11 @@ static struct fragment *parse_binary_hunk(char **buf_p,
 
        *status_p = 0;
 
-       if (!prefixcmp(buffer, "delta ")) {
+       if (starts_with(buffer, "delta ")) {
                patch_method = BINARY_DELTA_DEFLATED;
                origlen = strtoul(buffer + 6, NULL, 10);
        }
-       else if (!prefixcmp(buffer, "literal ")) {
+       else if (starts_with(buffer, "literal ")) {
                patch_method = BINARY_LITERAL_DEFLATED;
                origlen = strtoul(buffer + 8, NULL, 10);
        }
@@ -3627,12 +3627,12 @@ static int preimage_sha1_in_gitlink_patch(struct patch *p, unsigned char sha1[20
            hunk->oldpos == 1 && hunk->oldlines == 1 &&
            /* does preimage begin with the heading? */
            (preimage = memchr(hunk->patch, '\n', hunk->size)) != NULL &&
-           !prefixcmp(++preimage, heading) &&
+           starts_with(++preimage, heading) &&
            /* does it record full SHA-1? */
            !get_sha1_hex(preimage + sizeof(heading) - 1, sha1) &&
            preimage[sizeof(heading) + 40 - 1] == '\n' &&
            /* does the abbreviated name on the index line agree with it? */
-           !prefixcmp(preimage + sizeof(heading) - 1, p->old_sha1_prefix))
+           starts_with(preimage + sizeof(heading) - 1, p->old_sha1_prefix))
                return 0; /* it all looks fine */
 
        /* we may have full object name on the index line */
index 49178f159e246c9a99805d806fa5f096337e8d2f..a1e3b940c25ac20927d4daefa417d5b626e38a24 100644 (file)
@@ -57,9 +57,9 @@ static int run_remote_archiver(int argc, const char **argv,
        if (!buf)
                die(_("git archive: expected ACK/NAK, got EOF"));
        if (strcmp(buf, "ACK")) {
-               if (!prefixcmp(buf, "NACK "))
+               if (starts_with(buf, "NACK "))
                        die(_("git archive: NACK %s"), buf + 5);
-               if (!prefixcmp(buf, "ERR "))
+               if (starts_with(buf, "ERR "))
                        die(_("remote error: %s"), buf + 4);
                die(_("git archive: protocol error"));
        }
index 636a16ea4e3af71aef80ba42639f0933c286f485..b4d771673e7e9dccacbae8b29f4f1cd6a835151f 100644 (file)
@@ -81,13 +81,13 @@ static int parse_branch_color_slot(const char *var, int ofs)
 
 static int git_branch_config(const char *var, const char *value, void *cb)
 {
-       if (!prefixcmp(var, "column."))
+       if (starts_with(var, "column."))
                return git_column_config(var, value, "branch", &colopts);
        if (!strcmp(var, "color.branch")) {
                branch_use_color = git_config_colorbool(var, value);
                return 0;
        }
-       if (!prefixcmp(var, "color.branch.")) {
+       if (starts_with(var, "color.branch.")) {
                int slot = parse_branch_color_slot(var, 13);
                if (slot < 0)
                        return 0;
@@ -868,7 +868,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        if (!strcmp(head, "HEAD")) {
                detached = 1;
        } else {
-               if (prefixcmp(head, "refs/heads/"))
+               if (!starts_with(head, "refs/heads/"))
                        die(_("HEAD not found below refs/heads!"));
                head += 11;
        }
index 904fd715f0f27af0ac3694209ba3ffe61f174fa8..5df3837e3102e2f7d432ec11bb4685535bfaa0ac 100644 (file)
@@ -781,7 +781,7 @@ static int switch_branches(const struct checkout_opts *opts,
        if (!(flag & REF_ISSYMREF))
                old.path = NULL;
 
-       if (old.path && !prefixcmp(old.path, "refs/heads/"))
+       if (old.path && starts_with(old.path, "refs/heads/"))
                old.name = old.path + strlen("refs/heads/");
 
        if (!new->name) {
@@ -816,7 +816,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
-       if (!prefixcmp(var, "submodule."))
+       if (starts_with(var, "submodule."))
                return parse_submodule_config_option(var, value);
 
        return git_xmerge_config(var, value, NULL);
@@ -1151,9 +1151,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                const char *argv0 = argv[0];
                if (!argc || !strcmp(argv0, "--"))
                        die (_("--track needs a branch name"));
-               if (!prefixcmp(argv0, "refs/"))
+               if (starts_with(argv0, "refs/"))
                        argv0 += 5;
-               if (!prefixcmp(argv0, "remotes/"))
+               if (starts_with(argv0, "remotes/"))
                        argv0 += 8;
                argv0 = strchr(argv0, '/');
                if (!argv0 || !argv0[1])
index 615cd57caf1d4cbeafc73e7037bae81a6915df59..2f26297142fde89ec842d4e01665b3ebb24a9b59 100644 (file)
@@ -100,7 +100,7 @@ static int parse_clean_color_slot(const char *var)
 
 static int git_clean_config(const char *var, const char *value, void *cb)
 {
-       if (!prefixcmp(var, "column."))
+       if (starts_with(var, "column."))
                return git_column_config(var, value, "clean", &colopts);
 
        /* honors the color.interactive* config variables which also
@@ -109,7 +109,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
                clean_use_color = git_config_colorbool(var, value);
                return 0;
        }
-       if (!prefixcmp(var, "color.interactive.")) {
+       if (starts_with(var, "color.interactive.")) {
                int slot = parse_clean_color_slot(var +
                                                  strlen("color.interactive."));
                if (slot < 0)
index 874e0fd0b6e3ea4882783c0b2377016d93bd989d..f98f52980d3b8f7a4700d37c486c4379a4dd15ed 100644 (file)
@@ -508,9 +508,9 @@ static void write_followtags(const struct ref *refs, const char *msg)
 {
        const struct ref *ref;
        for (ref = refs; ref; ref = ref->next) {
-               if (prefixcmp(ref->name, "refs/tags/"))
+               if (!starts_with(ref->name, "refs/tags/"))
                        continue;
-               if (!suffixcmp(ref->name, "^{}"))
+               if (ends_with(ref->name, "^{}"))
                        continue;
                if (!has_sha1_file(ref->old_sha1))
                        continue;
@@ -578,7 +578,7 @@ static void update_remote_refs(const struct ref *refs,
 static void update_head(const struct ref *our, const struct ref *remote,
                        const char *msg)
 {
-       if (our && !prefixcmp(our->name, "refs/heads/")) {
+       if (our && starts_with(our->name, "refs/heads/")) {
                /* Local default branch link */
                create_symref("HEAD", our->name, NULL);
                if (!option_bare) {
@@ -625,7 +625,7 @@ static int checkout(void)
                if (advice_detached_head)
                        detach_advice(sha1_to_hex(sha1));
        } else {
-               if (prefixcmp(head, "refs/heads/"))
+               if (!starts_with(head, "refs/heads/"))
                        die(_("HEAD not found below refs/heads!"));
        }
        free(head);
@@ -796,6 +796,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (option_local > 0 && !is_local)
                warning(_("--local is ignored"));
 
+       /* no need to be strict, transport_set_option() will validate it again */
+       if (option_depth && atoi(option_depth) < 1)
+               die(_("depth %s is not a positive number"), option_depth);
+
        if (argc == 2)
                dir = xstrdup(argv[1]);
        else
index e125a55fc9de2b8f6d82fd5574f109b3d245934c..75818520e1b74de607620e48d2d3afb131c6e896 100644 (file)
@@ -34,7 +34,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
        };
 
        /* This one is special and must be the first one */
-       if (argc > 1 && !prefixcmp(argv[1], "--command=")) {
+       if (argc > 1 && starts_with(argv[1], "--command=")) {
                command = argv[1] + 10;
                git_config(column_config, (void *)command);
        } else
index e89c519192121d5386ba42b88a0157b31d57c690..3767478c6ddb02cf8a4a418f8911102aeaacfbe8 100644 (file)
@@ -733,7 +733,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                                eol = nl - sb.buf;
                        else
                                eol = sb.len;
-                       if (!prefixcmp(sb.buf + previous, "\nConflicts:\n")) {
+                       if (starts_with(sb.buf + previous, "\nConflicts:\n")) {
                                ignore_footer = sb.len - previous;
                                break;
                        }
@@ -904,7 +904,7 @@ static int rest_is_empty(struct strbuf *sb, int start)
                        eol = sb->len;
 
                if (strlen(sign_off_header) <= eol - i &&
-                   !prefixcmp(sb->buf + i, sign_off_header)) {
+                   starts_with(sb->buf + i, sign_off_header)) {
                        i = eol;
                        continue;
                }
@@ -1183,7 +1183,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
 {
        struct wt_status *s = cb;
 
-       if (!prefixcmp(k, "column."))
+       if (starts_with(k, "column."))
                return git_column_config(k, v, "status", &s->colopts);
        if (!strcmp(k, "status.submodulesummary")) {
                int is_bool;
@@ -1211,7 +1211,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
                s->display_comment_prefix = git_config_bool(k, v);
                return 0;
        }
-       if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
+       if (starts_with(k, "status.color.") || starts_with(k, "color.status.")) {
                int slot = parse_status_slot(k, 13);
                if (slot < 0)
                        return 0;
@@ -1377,7 +1377,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
 
        head = resolve_ref_unsafe("HEAD", junk_sha1, 0, NULL);
        printf("[%s%s ",
-               !prefixcmp(head, "refs/heads/") ?
+               starts_with(head, "refs/heads/") ?
                        head + 11 :
                        !strcmp(head, "HEAD") ?
                                _("detached HEAD") :
@@ -1505,7 +1505,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        struct strbuf sb = STRBUF_INIT;
        struct strbuf author_ident = STRBUF_INIT;
        const char *index_file, *reflog_msg;
-       char *nl, *p;
+       char *nl;
        unsigned char sha1[20];
        struct ref_lock *ref_lock;
        struct commit_list *parents = NULL, **pptr = &parents;
@@ -1601,11 +1601,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        }
 
        /* Truncate the message just before the diff, if any. */
-       if (verbose) {
-               p = strstr(sb.buf, "\ndiff --git ");
-               if (p != NULL)
-                       strbuf_setlen(&sb, p - sb.buf + 1);
-       }
+       if (verbose)
+               wt_status_truncate_message_at_cut_line(&sb);
 
        if (cleanup_mode != CLEANUP_NONE)
                stripspace(&sb, cleanup_mode == CLEANUP_ALL);
index 20e89fe4e0c7db50267e8e9358c38faea2259fab..92ebf23f0a9aa0e052ad68d60e17d0783f633a1c 100644 (file)
@@ -671,9 +671,3 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 
        return 0;
 }
-
-int cmd_repo_config(int argc, const char **argv, const char *prefix)
-{
-       fprintf(stderr, "WARNING: git repo-config is deprecated in favor of git config.\n");
-       return cmd_config(argc, argv, prefix);
-}
index 6f6210988709dc866bf79a5bb5523356773b93a0..7db43dae1be95e86c21249d9150fc8553c367527 100644 (file)
@@ -141,7 +141,7 @@ static void add_to_known_names(const char *path,
 
 static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
 {
-       int is_tag = !prefixcmp(path, "refs/tags/");
+       int is_tag = starts_with(path, "refs/tags/");
        unsigned char peeled[20];
        int is_annotated, prio;
 
index adb93a9efa5ed9b97a08224e46f6fbaf680343e6..fe0cc7f1b5b1451f267b1d9e24a6e40cd6e55325 100644 (file)
@@ -64,15 +64,18 @@ static void stuff_change(struct diff_options *opt,
 
 static int builtin_diff_b_f(struct rev_info *revs,
                            int argc, const char **argv,
-                           struct blobinfo *blob,
-                           const char *path)
+                           struct blobinfo *blob)
 {
        /* Blob vs file in the working tree*/
        struct stat st;
+       const char *path;
 
        if (argc > 1)
                usage(builtin_diff_usage);
 
+       GUARD_PATHSPEC(&revs->prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
+       path = revs->prune_data.items[0].match;
+
        if (lstat(path, &st))
                die_errno(_("failed to stat '%s'"), path);
        if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
@@ -255,7 +258,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
        struct rev_info rev;
        struct object_array ent = OBJECT_ARRAY_INIT;
        int blobs = 0, paths = 0;
-       const char *path = NULL;
        struct blobinfo blob[2];
        int nongit;
        int result = 0;
@@ -366,13 +368,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                        die(_("unhandled object '%s' given."), name);
                }
        }
-       if (rev.prune_data.nr) {
-               /* builtin_diff_b_f() */
-               GUARD_PATHSPEC(&rev.prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
-               if (!path)
-                       path = rev.prune_data.items[0].match;
+       if (rev.prune_data.nr)
                paths += rev.prune_data.nr;
-       }
 
        /*
         * Now, do the arguments look reasonable?
@@ -385,7 +382,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                case 1:
                        if (paths != 1)
                                usage(builtin_diff_usage);
-                       result = builtin_diff_b_f(&rev, argc, argv, blob, path);
+                       result = builtin_diff_b_f(&rev, argc, argv, blob);
                        break;
                case 2:
                        if (paths)
index ea6305258d4d63e58f2453736cfc5aa38ec37282..b8d8a3aaf9ee8294be9a78956a70b476d327ee05 100644 (file)
@@ -476,7 +476,7 @@ static void handle_tag(const char *name, struct tag *tag)
                }
        }
 
-       if (!prefixcmp(name, "refs/tags/"))
+       if (starts_with(name, "refs/tags/"))
                name += 10;
        printf("tag %s\nfrom :%d\n%.*s%sdata %d\n%.*s\n",
               name, tagged_mark,
index c8e858232a8e7a3536ef4d296efdc618e034c36e..8b8978a25287bce6c4f937ff52df6cb7ae8e429e 100644 (file)
@@ -7,7 +7,7 @@
 static const char fetch_pack_usage[] =
 "git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] "
 "[--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] "
-"[--no-progress] [-v] [<host>:]<directory> [<refs>...]";
+"[--no-progress] [--diag-url] [-v] [<host>:]<directory> [<refs>...]";
 
 static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
                                 const char *name, int namelen)
@@ -48,11 +48,11 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
        for (i = 1; i < argc && *argv[i] == '-'; i++) {
                const char *arg = argv[i];
 
-               if (!prefixcmp(arg, "--upload-pack=")) {
+               if (starts_with(arg, "--upload-pack=")) {
                        args.uploadpack = arg + 14;
                        continue;
                }
-               if (!prefixcmp(arg, "--exec=")) {
+               if (starts_with(arg, "--exec=")) {
                        args.uploadpack = arg + 7;
                        continue;
                }
@@ -81,11 +81,15 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
                        args.stdin_refs = 1;
                        continue;
                }
+               if (!strcmp("--diag-url", arg)) {
+                       args.diag_url = 1;
+                       continue;
+               }
                if (!strcmp("-v", arg)) {
                        args.verbose = 1;
                        continue;
                }
-               if (!prefixcmp(arg, "--depth=")) {
+               if (starts_with(arg, "--depth=")) {
                        args.depth = strtol(arg + 8, NULL, 0);
                        continue;
                }
@@ -146,10 +150,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
                fd[0] = 0;
                fd[1] = 1;
        } else {
+               int flags = args.verbose ? CONNECT_VERBOSE : 0;
+               if (args.diag_url)
+                       flags |= CONNECT_DIAG_URL;
                conn = git_connect(fd, dest, args.uploadpack,
-                                  args.verbose ? CONNECT_VERBOSE : 0);
+                                  flags);
+               if (!conn)
+                       return args.diag_url ? 0 : 1;
        }
-
        get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL);
 
        ref = fetch_pack(&args, fd, conn, ref, dest,
index bd7a10164f4fed8aeb6e8148e2ae8c0a793e7ee0..1e7d617f4671c43f704afe912edac5f5dc6dc316 100644 (file)
@@ -160,48 +160,156 @@ static void add_merge_config(struct ref **head,
        }
 }
 
+static int add_existing(const char *refname, const unsigned char *sha1,
+                       int flag, void *cbdata)
+{
+       struct string_list *list = (struct string_list *)cbdata;
+       struct string_list_item *item = string_list_insert(list, refname);
+       item->util = xmalloc(20);
+       hashcpy(item->util, sha1);
+       return 0;
+}
+
+static int will_fetch(struct ref **head, const unsigned char *sha1)
+{
+       struct ref *rm = *head;
+       while (rm) {
+               if (!hashcmp(rm->old_sha1, sha1))
+                       return 1;
+               rm = rm->next;
+       }
+       return 0;
+}
+
 static void find_non_local_tags(struct transport *transport,
                        struct ref **head,
-                       struct ref ***tail);
+                       struct ref ***tail)
+{
+       struct string_list existing_refs = STRING_LIST_INIT_DUP;
+       struct string_list remote_refs = STRING_LIST_INIT_NODUP;
+       const struct ref *ref;
+       struct string_list_item *item = NULL;
+
+       for_each_ref(add_existing, &existing_refs);
+       for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
+               if (!starts_with(ref->name, "refs/tags/"))
+                       continue;
+
+               /*
+                * The peeled ref always follows the matching base
+                * ref, so if we see a peeled ref that we don't want
+                * to fetch then we can mark the ref entry in the list
+                * as one to ignore by setting util to NULL.
+                */
+               if (ends_with(ref->name, "^{}")) {
+                       if (item && !has_sha1_file(ref->old_sha1) &&
+                           !will_fetch(head, ref->old_sha1) &&
+                           !has_sha1_file(item->util) &&
+                           !will_fetch(head, item->util))
+                               item->util = NULL;
+                       item = NULL;
+                       continue;
+               }
+
+               /*
+                * If item is non-NULL here, then we previously saw a
+                * ref not followed by a peeled reference, so we need
+                * to check if it is a lightweight tag that we want to
+                * fetch.
+                */
+               if (item && !has_sha1_file(item->util) &&
+                   !will_fetch(head, item->util))
+                       item->util = NULL;
+
+               item = NULL;
+
+               /* skip duplicates and refs that we already have */
+               if (string_list_has_string(&remote_refs, ref->name) ||
+                   string_list_has_string(&existing_refs, ref->name))
+                       continue;
+
+               item = string_list_insert(&remote_refs, ref->name);
+               item->util = (void *)ref->old_sha1;
+       }
+       string_list_clear(&existing_refs, 1);
+
+       /*
+        * We may have a final lightweight tag that needs to be
+        * checked to see if it needs fetching.
+        */
+       if (item && !has_sha1_file(item->util) &&
+           !will_fetch(head, item->util))
+               item->util = NULL;
+
+       /*
+        * For all the tags in the remote_refs string list,
+        * add them to the list of refs to be fetched
+        */
+       for_each_string_list_item(item, &remote_refs) {
+               /* Unless we have already decided to ignore this item... */
+               if (item->util)
+               {
+                       struct ref *rm = alloc_ref(item->string);
+                       rm->peer_ref = alloc_ref(item->string);
+                       hashcpy(rm->old_sha1, item->util);
+                       **tail = rm;
+                       *tail = &rm->next;
+               }
+       }
+
+       string_list_clear(&remote_refs, 0);
+}
 
 static struct ref *get_ref_map(struct transport *transport,
-                              struct refspec *refs, int ref_count, int tags,
-                              int *autotags)
+                              struct refspec *refspecs, int refspec_count,
+                              int tags, int *autotags)
 {
        int i;
        struct ref *rm;
        struct ref *ref_map = NULL;
        struct ref **tail = &ref_map;
 
-       const struct ref *remote_refs = transport_get_remote_refs(transport);
+       /* opportunistically-updated references: */
+       struct ref *orefs = NULL, **oref_tail = &orefs;
 
-       if (ref_count || tags == TAGS_SET) {
-               struct ref **old_tail;
+       const struct ref *remote_refs = transport_get_remote_refs(transport);
 
-               for (i = 0; i < ref_count; i++) {
-                       get_fetch_map(remote_refs, &refs[i], &tail, 0);
-                       if (refs[i].dst && refs[i].dst[0])
+       if (refspec_count) {
+               for (i = 0; i < refspec_count; i++) {
+                       get_fetch_map(remote_refs, &refspecs[i], &tail, 0);
+                       if (refspecs[i].dst && refspecs[i].dst[0])
                                *autotags = 1;
                }
-               /* Merge everything on the command line, but not --tags */
+               /* Merge everything on the command line (but not --tags) */
                for (rm = ref_map; rm; rm = rm->next)
                        rm->fetch_head_status = FETCH_HEAD_MERGE;
-               if (tags == TAGS_SET)
-                       get_fetch_map(remote_refs, tag_refspec, &tail, 0);
 
                /*
-                * For any refs that we happen to be fetching via command-line
-                * arguments, take the opportunity to update their configured
-                * counterparts. However, we do not want to mention these
-                * entries in FETCH_HEAD at all, as they would simply be
-                * duplicates of existing entries.
+                * For any refs that we happen to be fetching via
+                * command-line arguments, the destination ref might
+                * have been missing or have been different than the
+                * remote-tracking ref that would be derived from the
+                * configured refspec.  In these cases, we want to
+                * take the opportunity to update their configured
+                * remote-tracking reference.  However, we do not want
+                * to mention these entries in FETCH_HEAD at all, as
+                * they would simply be duplicates of existing
+                * entries, so we set them FETCH_HEAD_IGNORE below.
+                *
+                * We compute these entries now, based only on the
+                * refspecs specified on the command line.  But we add
+                * them to the list following the refspecs resulting
+                * from the tags option so that one of the latter,
+                * which has FETCH_HEAD_NOT_FOR_MERGE, is not removed
+                * by ref_remove_duplicates() in favor of one of these
+                * opportunistic entries with FETCH_HEAD_IGNORE.
                 */
-               old_tail = tail;
                for (i = 0; i < transport->remote->fetch_refspec_nr; i++)
                        get_fetch_map(ref_map, &transport->remote->fetch[i],
-                                     &tail, 1);
-               for (rm = *old_tail; rm; rm = rm->next)
-                       rm->fetch_head_status = FETCH_HEAD_IGNORE;
+                                     &oref_tail, 1);
+
+               if (tags == TAGS_SET)
+                       get_fetch_map(remote_refs, tag_refspec, &tail, 0);
        } else {
                /* Use the defaults */
                struct remote *remote = transport->remote;
@@ -238,11 +346,21 @@ static struct ref *get_ref_map(struct transport *transport,
                        tail = &ref_map->next;
                }
        }
-       if (tags == TAGS_DEFAULT && *autotags)
+
+       if (tags == TAGS_SET)
+               /* also fetch all tags */
+               get_fetch_map(remote_refs, tag_refspec, &tail, 0);
+       else if (tags == TAGS_DEFAULT && *autotags)
                find_non_local_tags(transport, &ref_map, &tail);
-       ref_remove_duplicates(ref_map);
 
-       return ref_map;
+       /* Now append any refs to be updated opportunistically: */
+       *tail = orefs;
+       for (rm = orefs; rm; rm = rm->next) {
+               rm->fetch_head_status = FETCH_HEAD_IGNORE;
+               tail = &rm->next;
+       }
+
+       return ref_remove_duplicates(ref_map);
 }
 
 #define STORE_REF_ERROR_OTHER 1
@@ -313,7 +431,7 @@ static int update_local_ref(struct ref *ref,
        }
 
        if (!is_null_sha1(ref->old_sha1) &&
-           !prefixcmp(ref->name, "refs/tags/")) {
+           starts_with(ref->name, "refs/tags/")) {
                int r;
                r = s_update_ref("updating tag", ref, 0);
                strbuf_addf(display, "%c %-*s %-*s -> %s%s",
@@ -336,10 +454,10 @@ static int update_local_ref(struct ref *ref,
                 * more likely to follow a standard layout.
                 */
                const char *name = remote_ref ? remote_ref->name : "";
-               if (!prefixcmp(name, "refs/tags/")) {
+               if (starts_with(name, "refs/tags/")) {
                        msg = "storing tag";
                        what = _("[new tag]");
-               } else if (!prefixcmp(name, "refs/heads/")) {
+               } else if (starts_with(name, "refs/heads/")) {
                        msg = "storing head";
                        what = _("[new branch]");
                } else {
@@ -471,15 +589,15 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
                                kind = "";
                                what = "";
                        }
-                       else if (!prefixcmp(rm->name, "refs/heads/")) {
+                       else if (starts_with(rm->name, "refs/heads/")) {
                                kind = "branch";
                                what = rm->name + 11;
                        }
-                       else if (!prefixcmp(rm->name, "refs/tags/")) {
+                       else if (starts_with(rm->name, "refs/tags/")) {
                                kind = "tag";
                                what = rm->name + 10;
                        }
-                       else if (!prefixcmp(rm->name, "refs/remotes/")) {
+                       else if (starts_with(rm->name, "refs/remotes/")) {
                                kind = "remote-tracking branch";
                                what = rm->name + 13;
                        }
@@ -612,106 +730,6 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map)
        return result;
 }
 
-static int add_existing(const char *refname, const unsigned char *sha1,
-                       int flag, void *cbdata)
-{
-       struct string_list *list = (struct string_list *)cbdata;
-       struct string_list_item *item = string_list_insert(list, refname);
-       item->util = xmalloc(20);
-       hashcpy(item->util, sha1);
-       return 0;
-}
-
-static int will_fetch(struct ref **head, const unsigned char *sha1)
-{
-       struct ref *rm = *head;
-       while (rm) {
-               if (!hashcmp(rm->old_sha1, sha1))
-                       return 1;
-               rm = rm->next;
-       }
-       return 0;
-}
-
-static void find_non_local_tags(struct transport *transport,
-                       struct ref **head,
-                       struct ref ***tail)
-{
-       struct string_list existing_refs = STRING_LIST_INIT_DUP;
-       struct string_list remote_refs = STRING_LIST_INIT_NODUP;
-       const struct ref *ref;
-       struct string_list_item *item = NULL;
-
-       for_each_ref(add_existing, &existing_refs);
-       for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
-               if (prefixcmp(ref->name, "refs/tags/"))
-                       continue;
-
-               /*
-                * The peeled ref always follows the matching base
-                * ref, so if we see a peeled ref that we don't want
-                * to fetch then we can mark the ref entry in the list
-                * as one to ignore by setting util to NULL.
-                */
-               if (!suffixcmp(ref->name, "^{}")) {
-                       if (item && !has_sha1_file(ref->old_sha1) &&
-                           !will_fetch(head, ref->old_sha1) &&
-                           !has_sha1_file(item->util) &&
-                           !will_fetch(head, item->util))
-                               item->util = NULL;
-                       item = NULL;
-                       continue;
-               }
-
-               /*
-                * If item is non-NULL here, then we previously saw a
-                * ref not followed by a peeled reference, so we need
-                * to check if it is a lightweight tag that we want to
-                * fetch.
-                */
-               if (item && !has_sha1_file(item->util) &&
-                   !will_fetch(head, item->util))
-                       item->util = NULL;
-
-               item = NULL;
-
-               /* skip duplicates and refs that we already have */
-               if (string_list_has_string(&remote_refs, ref->name) ||
-                   string_list_has_string(&existing_refs, ref->name))
-                       continue;
-
-               item = string_list_insert(&remote_refs, ref->name);
-               item->util = (void *)ref->old_sha1;
-       }
-       string_list_clear(&existing_refs, 1);
-
-       /*
-        * We may have a final lightweight tag that needs to be
-        * checked to see if it needs fetching.
-        */
-       if (item && !has_sha1_file(item->util) &&
-           !will_fetch(head, item->util))
-               item->util = NULL;
-
-       /*
-        * For all the tags in the remote_refs string list,
-        * add them to the list of refs to be fetched
-        */
-       for_each_string_list_item(item, &remote_refs) {
-               /* Unless we have already decided to ignore this item... */
-               if (item->util)
-               {
-                       struct ref *rm = alloc_ref(item->string);
-                       rm->peer_ref = alloc_ref(item->string);
-                       hashcpy(rm->old_sha1, item->util);
-                       **tail = rm;
-                       *tail = &rm->next;
-               }
-       }
-
-       string_list_clear(&remote_refs, 0);
-}
-
 static void check_not_current_branch(struct ref *ref_map)
 {
        struct branch *current_branch = branch_get(NULL);
@@ -831,30 +849,16 @@ static int do_fetch(struct transport *transport,
        }
        if (prune) {
                /*
-                * If --tags was specified, pretend that the user gave us
-                * the canonical tags refspec
+                * We only prune based on refspecs specified
+                * explicitly (via command line or configuration); we
+                * don't care whether --tags was specified.
                 */
-               if (tags == TAGS_SET) {
-                       const char *tags_str = "refs/tags/*:refs/tags/*";
-                       struct refspec *tags_refspec, *refspec;
-
-                       /* Copy the refspec and add the tags to it */
-                       refspec = xcalloc(ref_count + 1, sizeof(struct refspec));
-                       tags_refspec = parse_fetch_refspec(1, &tags_str);
-                       memcpy(refspec, refs, ref_count * sizeof(struct refspec));
-                       memcpy(&refspec[ref_count], tags_refspec, sizeof(struct refspec));
-                       ref_count++;
-
-                       prune_refs(refspec, ref_count, ref_map);
-
-                       ref_count--;
-                       /* The rest of the strings belong to fetch_one */
-                       free_refspec(1, tags_refspec);
-                       free(refspec);
-               } else if (ref_count) {
+               if (ref_count) {
                        prune_refs(refs, ref_count, ref_map);
                } else {
-                       prune_refs(transport->remote->fetch, transport->remote->fetch_refspec_nr, ref_map);
+                       prune_refs(transport->remote->fetch,
+                                  transport->remote->fetch_refspec_nr,
+                                  ref_map);
                }
        }
        free_refs(ref_map);
@@ -892,7 +896,7 @@ static int get_remote_group(const char *key, const char *value, void *priv)
 {
        struct remote_group_data *g = priv;
 
-       if (!prefixcmp(key, "remotes.") &&
+       if (starts_with(key, "remotes.") &&
                        !strcmp(key + 8, g->name)) {
                /* split list by white space */
                int space = strcspn(value, " \t\n");
@@ -930,8 +934,8 @@ static void add_options_to_argv(struct argv_array *argv)
 {
        if (dry_run)
                argv_array_push(argv, "--dry-run");
-       if (prune > 0)
-               argv_array_push(argv, "--prune");
+       if (prune != -1)
+               argv_array_push(argv, prune ? "--prune" : "--no-prune");
        if (update_head_ok)
                argv_array_push(argv, "--update-head-ok");
        if (force)
@@ -1075,6 +1079,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
                }
        }
 
+       /* no need to be strict, transport_set_option() will validate it again */
+       if (depth && atoi(depth) < 1)
+               die(_("depth %s is not a positive number"), depth);
+
        if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
                if (recurse_submodules_default) {
                        int arg = parse_fetch_recurse_submodules_arg("--recurse-submodules-default", recurse_submodules_default);
index 1c040708696c8d6e81023b3261966fa751f14ad4..3906eda87712ea099e0e5876fff1fe28fc5716be 100644 (file)
@@ -109,7 +109,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
        if (len < 43 || line[40] != '\t')
                return 1;
 
-       if (!prefixcmp(line + 41, "not-for-merge"))
+       if (starts_with(line + 41, "not-for-merge"))
                return 0;
 
        if (line[41] != '\t')
@@ -155,16 +155,16 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
        if (pulling_head) {
                origin = src;
                src_data->head_status |= 1;
-       } else if (!prefixcmp(line, "branch ")) {
+       } else if (starts_with(line, "branch ")) {
                origin_data->is_local_branch = 1;
                origin = line + 7;
                string_list_append(&src_data->branch, origin);
                src_data->head_status |= 2;
-       } else if (!prefixcmp(line, "tag ")) {
+       } else if (starts_with(line, "tag ")) {
                origin = line;
                string_list_append(&src_data->tag, origin + 4);
                src_data->head_status |= 2;
-       } else if (!prefixcmp(line, "remote-tracking branch ")) {
+       } else if (starts_with(line, "remote-tracking branch ")) {
                origin = line + strlen("remote-tracking branch ");
                string_list_append(&src_data->r_branch, origin);
                src_data->head_status |= 2;
@@ -605,7 +605,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
                resolve_refdup("HEAD", head_sha1, 1, NULL);
        if (!current_branch)
                die("No current branch");
-       if (!prefixcmp(current_branch, "refs/heads/"))
+       if (starts_with(current_branch, "refs/heads/"))
                current_branch += 11;
 
        find_merge_parents(&merge_parents, in, head_sha1);
index d096051b15c14a4f109bc9a9cfcf9749c14258b9..6551e7b39b6039032852d6ec0d0dd8da0d7031dc 100644 (file)
@@ -9,6 +9,7 @@
 #include "quote.h"
 #include "parse-options.h"
 #include "remote.h"
+#include "color.h"
 
 /* Quoting styles */
 #define QUOTE_NONE 0
@@ -75,6 +76,8 @@ static struct {
        { "upstream" },
        { "symref" },
        { "flag" },
+       { "HEAD" },
+       { "color" },
 };
 
 /*
@@ -90,6 +93,7 @@ static struct {
 static const char **used_atom;
 static cmp_type *used_atom_type;
 static int used_atom_cnt, sort_atom_limit, need_tagged, need_symref;
+static int need_color_reset_at_eol;
 
 /*
  * Used to parse format string and sort specifiers
@@ -176,13 +180,21 @@ static const char *find_next(const char *cp)
 static int verify_format(const char *format)
 {
        const char *cp, *sp;
+       static const char color_reset[] = "color:reset";
+
+       need_color_reset_at_eol = 0;
        for (cp = format; *cp && (sp = find_next(cp)); ) {
                const char *ep = strchr(sp, ')');
+               int at;
+
                if (!ep)
                        return error("malformed format string %s", sp);
                /* sp points at "%(" and ep points at the closing ")" */
-               parse_atom(sp + 2, ep);
+               at = parse_atom(sp + 2, ep);
                cp = ep + 1;
+
+               if (!memcmp(used_atom[at], "color:", 6))
+                       need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
        }
        return 0;
 }
@@ -441,7 +453,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
                if (name[wholen] != 0 &&
                    strcmp(name + wholen, "name") &&
                    strcmp(name + wholen, "email") &&
-                   prefixcmp(name + wholen, "date"))
+                   !starts_with(name + wholen, "date"))
                        continue;
                if (!wholine)
                        wholine = find_wholine(who, wholen, buf, sz);
@@ -453,7 +465,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
                        v->s = copy_name(wholine);
                else if (!strcmp(name + wholen, "email"))
                        v->s = copy_email(wholine);
-               else if (!prefixcmp(name + wholen, "date"))
+               else if (starts_with(name + wholen, "date"))
                        grab_date(wholine, v, name);
        }
 
@@ -475,7 +487,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
                if (deref)
                        name++;
 
-               if (!prefixcmp(name, "creatordate"))
+               if (starts_with(name, "creatordate"))
                        grab_date(wholine, v, name);
                else if (!strcmp(name, "creator"))
                        v->s = copy_line(wholine);
@@ -649,20 +661,20 @@ static void populate_value(struct refinfo *ref)
                int deref = 0;
                const char *refname;
                const char *formatp;
+               struct branch *branch = NULL;
 
                if (*name == '*') {
                        deref = 1;
                        name++;
                }
 
-               if (!prefixcmp(name, "refname"))
+               if (starts_with(name, "refname"))
                        refname = ref->refname;
-               else if (!prefixcmp(name, "symref"))
+               else if (starts_with(name, "symref"))
                        refname = ref->symref ? ref->symref : "";
-               else if (!prefixcmp(name, "upstream")) {
-                       struct branch *branch;
+               else if (starts_with(name, "upstream")) {
                        /* only local branches may have an upstream */
-                       if (prefixcmp(ref->refname, "refs/heads/"))
+                       if (!starts_with(ref->refname, "refs/heads/"))
                                continue;
                        branch = branch_get(ref->refname + 11);
 
@@ -670,8 +682,13 @@ static void populate_value(struct refinfo *ref)
                            !branch->merge[0]->dst)
                                continue;
                        refname = branch->merge[0]->dst;
-               }
-               else if (!strcmp(name, "flag")) {
+               } else if (starts_with(name, "color:")) {
+                       char color[COLOR_MAXLEN] = "";
+
+                       color_parse(name + 6, "--format", color);
+                       v->s = xstrdup(color);
+                       continue;
+               } else if (!strcmp(name, "flag")) {
                        char buf[256], *cp = buf;
                        if (ref->flag & REF_ISSYMREF)
                                cp = copy_advance(cp, ",symref");
@@ -684,20 +701,62 @@ static void populate_value(struct refinfo *ref)
                                v->s = xstrdup(buf + 1);
                        }
                        continue;
-               }
-               else if (!deref && grab_objectname(name, ref->objectname, v))
+               } else if (!deref && grab_objectname(name, ref->objectname, v)) {
                        continue;
-               else
+               } else if (!strcmp(name, "HEAD")) {
+                       const char *head;
+                       unsigned char sha1[20];
+
+                       head = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
+                       if (!strcmp(ref->refname, head))
+                               v->s = "*";
+                       else
+                               v->s = " ";
+                       continue;
+               } else
                        continue;
 
                formatp = strchr(name, ':');
-               /* look for "short" refname format */
                if (formatp) {
+                       int num_ours, num_theirs;
+
                        formatp++;
                        if (!strcmp(formatp, "short"))
                                refname = shorten_unambiguous_ref(refname,
                                                      warn_ambiguous_refs);
-                       else
+                       else if (!strcmp(formatp, "track") &&
+                                starts_with(name, "upstream")) {
+                               char buf[40];
+
+                               stat_tracking_info(branch, &num_ours, &num_theirs);
+                               if (!num_ours && !num_theirs)
+                                       v->s = "";
+                               else if (!num_ours) {
+                                       sprintf(buf, "[behind %d]", num_theirs);
+                                       v->s = xstrdup(buf);
+                               } else if (!num_theirs) {
+                                       sprintf(buf, "[ahead %d]", num_ours);
+                                       v->s = xstrdup(buf);
+                               } else {
+                                       sprintf(buf, "[ahead %d, behind %d]",
+                                               num_ours, num_theirs);
+                                       v->s = xstrdup(buf);
+                               }
+                               continue;
+                       } else if (!strcmp(formatp, "trackshort") &&
+                                  starts_with(name, "upstream")) {
+                               assert(branch);
+                               stat_tracking_info(branch, &num_ours, &num_theirs);
+                               if (!num_ours && !num_theirs)
+                                       v->s = "=";
+                               else if (!num_ours)
+                                       v->s = "<";
+                               else if (!num_theirs)
+                                       v->s = ">";
+                               else
+                                       v->s = "<>";
+                               continue;
+                       } else
                                die("unknown %.*s format %s",
                                    (int)(formatp - name), name, formatp);
                }
@@ -875,11 +934,9 @@ static void sort_refs(struct ref_sort *sort, struct refinfo **refs, int num_refs
        qsort(refs, num_refs, sizeof(struct refinfo *), compare_refs);
 }
 
-static void print_value(struct refinfo *ref, int atom, int quote_style)
+static void print_value(struct atom_value *v, int quote_style)
 {
-       struct atom_value *v;
        struct strbuf sb = STRBUF_INIT;
-       get_value(ref, atom, &v);
        switch (quote_style) {
        case QUOTE_NONE:
                fputs(v->s, stdout);
@@ -946,15 +1003,26 @@ static void show_ref(struct refinfo *info, const char *format, int quote_style)
        const char *cp, *sp, *ep;
 
        for (cp = format; *cp && (sp = find_next(cp)); cp = ep + 1) {
+               struct atom_value *atomv;
+
                ep = strchr(sp, ')');
                if (cp < sp)
                        emit(cp, sp);
-               print_value(info, parse_atom(sp + 2, ep), quote_style);
+               get_value(info, parse_atom(sp + 2, ep), &atomv);
+               print_value(atomv, quote_style);
        }
        if (*cp) {
                sp = cp + strlen(cp);
                emit(cp, sp);
        }
+       if (need_color_reset_at_eol) {
+               struct atom_value resetv;
+               char color[COLOR_MAXLEN] = "";
+
+               color_parse("reset", "--format", color);
+               resetv.s = color;
+               print_value(&resetv, quote_style);
+       }
        putchar('\n');
 }
 
index 97ce678c6ba63afeb3deedfd469c4a53a475a1be..1affdd5e924c9e71605be603f253e34f6a995f36 100644 (file)
@@ -442,7 +442,7 @@ static void fsck_dir(int i, char *path)
                        add_sha1_list(sha1, DIRENT_SORT_HINT(de));
                        continue;
                }
-               if (!prefixcmp(de->d_name, "tmp_obj_"))
+               if (starts_with(de->d_name, "tmp_obj_"))
                        continue;
                fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
        }
@@ -484,7 +484,7 @@ static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, in
 
 static int is_branch(const char *refname)
 {
-       return !strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/");
+       return !strcmp(refname, "HEAD") || starts_with(refname, "refs/heads/");
 }
 
 static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
@@ -566,7 +566,7 @@ static int fsck_head_link(void)
        if (!strcmp(head_points_at, "HEAD"))
                /* detached HEAD */
                null_is_error = 1;
-       else if (prefixcmp(head_points_at, "refs/heads/"))
+       else if (!starts_with(head_points_at, "refs/heads/"))
                return error("HEAD points to something strange (%s)",
                             head_points_at);
        if (is_null_sha1(head_sha1)) {
diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c
new file mode 100644 (file)
index 0000000..aa72596
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2005, 2006 Rene Scharfe
+ */
+#include "cache.h"
+#include "commit.h"
+#include "tar.h"
+#include "builtin.h"
+#include "quote.h"
+
+static const char builtin_get_tar_commit_id_usage[] =
+"git get-tar-commit-id < <tarfile>";
+
+/* ustar header + extended global header content */
+#define RECORDSIZE     (512)
+#define HEADERSIZE (2 * RECORDSIZE)
+
+int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
+{
+       char buffer[HEADERSIZE];
+       struct ustar_header *header = (struct ustar_header *)buffer;
+       char *content = buffer + RECORDSIZE;
+       ssize_t n;
+
+       if (argc != 1)
+               usage(builtin_get_tar_commit_id_usage);
+
+       n = read_in_full(0, buffer, HEADERSIZE);
+       if (n < HEADERSIZE)
+               die("git get-tar-commit-id: read error");
+       if (header->typeflag[0] != 'g')
+               return 1;
+       if (memcmp(content, "52 comment=", 11))
+               return 1;
+
+       n = write_in_full(1, content + 11, 41);
+       if (n < 41)
+               die_errno("git get-tar-commit-id: write error");
+
+       return 0;
+}
index f1e236b9124f8b7bfd9aa5e926d525c6f4568268..cc17e670ceb458491cc47e463b970b6d4c6143f8 100644 (file)
@@ -100,7 +100,7 @@ static int check_emacsclient_version(void)
         */
        finish_command(&ec_process);
 
-       if (prefixcmp(buffer.buf, "emacsclient")) {
+       if (!starts_with(buffer.buf, "emacsclient")) {
                strbuf_release(&buffer);
                return error(_("Failed to parse emacsclient version."));
        }
@@ -258,7 +258,7 @@ static int add_man_viewer_info(const char *var, const char *value)
 
 static int git_help_config(const char *var, const char *value, void *cb)
 {
-       if (!prefixcmp(var, "column."))
+       if (starts_with(var, "column."))
                return git_column_config(var, value, "help", &colopts);
        if (!strcmp(var, "help.format")) {
                if (!value)
@@ -278,7 +278,7 @@ static int git_help_config(const char *var, const char *value, void *cb)
                add_man_viewer(value);
                return 0;
        }
-       if (!prefixcmp(var, "man."))
+       if (starts_with(var, "man."))
                return add_man_viewer_info(var, value);
 
        return git_default_config(var, value, cb);
@@ -306,7 +306,7 @@ static const char *cmd_to_page(const char *git_cmd)
 {
        if (!git_cmd)
                return "git";
-       else if (!prefixcmp(git_cmd, "git"))
+       else if (starts_with(git_cmd, "git"))
                return git_cmd;
        else if (is_git_command(git_cmd))
                return prepend("git-", git_cmd);
index 9e9eb4b74e8335f097c7cc9e261b051feda0bf0d..2f37a38fbcdf131ab5897e47728c5773ba36b861 100644 (file)
@@ -1534,9 +1534,9 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
                                stat_only = 1;
                        } else if (!strcmp(arg, "--keep")) {
                                keep_msg = "";
-                       } else if (!prefixcmp(arg, "--keep=")) {
+                       } else if (starts_with(arg, "--keep=")) {
                                keep_msg = arg + 7;
-                       } else if (!prefixcmp(arg, "--threads=")) {
+                       } else if (starts_with(arg, "--threads=")) {
                                char *end;
                                nr_threads = strtoul(arg+10, &end, 0);
                                if (!arg[10] || *end || nr_threads < 0)
@@ -1547,7 +1547,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
                                                  "ignoring %s"), arg);
                                nr_threads = 1;
 #endif
-                       } else if (!prefixcmp(arg, "--pack_header=")) {
+                       } else if (starts_with(arg, "--pack_header=")) {
                                struct pack_header *hdr;
                                char *c;
 
@@ -1566,7 +1566,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
                                if (index_name || (i+1) >= argc)
                                        usage(index_pack_usage);
                                index_name = argv[++i];
-                       } else if (!prefixcmp(arg, "--index-version=")) {
+                       } else if (starts_with(arg, "--index-version=")) {
                                char *c;
                                opts.version = strtoul(arg + 16, &c, 10);
                                if (opts.version > 2)
index 78aa3872dddbba8988b61c49996f9e63719bac75..b3f03cf0d6c0f776b2eaba8ff4e1d340216a4463 100644 (file)
@@ -266,7 +266,7 @@ static int create_default_files(const char *template_path)
                /* allow template config file to override the default */
                if (log_all_ref_updates == -1)
                    git_config_set("core.logallrefupdates", "true");
-               if (prefixcmp(git_dir, work_tree) ||
+               if (!starts_with(git_dir, work_tree) ||
                    strcmp(git_dir + strlen(work_tree), "/.git")) {
                        git_config_set("core.worktree", work_tree);
                }
index b708517a3506517a25d4c05f3c9c92a660688f8d..b97373da3b2687e18b5eba96382049382d1536fd 100644 (file)
@@ -391,7 +391,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
                default_show_root = git_config_bool(var, value);
                return 0;
        }
-       if (!prefixcmp(var, "color.decorate."))
+       if (starts_with(var, "color.decorate."))
                return parse_decorate_color_config(var, 15, value);
        if (!strcmp(var, "log.mailmap")) {
                use_mailmap_config = git_config_bool(var, value);
@@ -477,7 +477,7 @@ static int show_tag_object(const unsigned char *sha1, struct rev_info *rev)
                int new_offset = offset + 1;
                while (new_offset < size && buf[new_offset++] != '\n')
                        ; /* do nothing */
-               if (!prefixcmp(buf + offset, "tagger "))
+               if (starts_with(buf + offset, "tagger "))
                        show_tagger(buf + offset + 7,
                                    new_offset - offset - 7, rev);
                offset = new_offset;
@@ -882,7 +882,7 @@ static char *find_branch_name(struct rev_info *rev)
        ref = rev->cmdline.rev[positive].name;
        tip_sha1 = rev->cmdline.rev[positive].item->sha1;
        if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) &&
-           !prefixcmp(full_ref, "refs/heads/") &&
+           starts_with(full_ref, "refs/heads/") &&
            !hashcmp(tip_sha1, branch_sha1))
                branch = xstrdup(full_ref + strlen("refs/heads/"));
        free(full_ref);
@@ -1388,7 +1388,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                        unsigned char sha1[20];
                        const char *ref;
                        ref = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
-                       if (ref && !prefixcmp(ref, "refs/heads/"))
+                       if (ref && starts_with(ref, "refs/heads/"))
                                branch_name = xstrdup(ref + strlen("refs/heads/"));
                        else
                                branch_name = xstrdup(""); /* no branch */
index 25e83cfe9de3dc3cee19f03f82b56396eb6b65de..39e5144b9e38f1319f8fb881af6b1d34ad0c4089 100644 (file)
@@ -50,11 +50,11 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                const char *arg = argv[i];
 
                if (*arg == '-') {
-                       if (!prefixcmp(arg, "--upload-pack=")) {
+                       if (starts_with(arg, "--upload-pack=")) {
                                uploadpack = arg + 14;
                                continue;
                        }
-                       if (!prefixcmp(arg, "--exec=")) {
+                       if (starts_with(arg, "--exec=")) {
                                uploadpack = arg + 7;
                                continue;
                        }
index 24a772d8e1b7355a58088d784fdc18cd54302b7d..2c3cd8eab7073669001ad605020577279ba7a07d 100644 (file)
@@ -328,11 +328,11 @@ static int check_header(const struct strbuf *line,
        }
 
        /* for inbody stuff */
-       if (!prefixcmp(line->buf, ">From") && isspace(line->buf[5])) {
+       if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
                ret = 1; /* Should this return 0? */
                goto check_header_out;
        }
-       if (!prefixcmp(line->buf, "[PATCH]") && isspace(line->buf[7])) {
+       if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
                for (i = 0; header[i]; i++) {
                        if (!memcmp("Subject", header[i], 7)) {
                                handle_header(&hdr_data[i], line);
@@ -361,7 +361,7 @@ static int is_rfc2822_header(const struct strbuf *line)
        char *cp = line->buf;
 
        /* Count mbox From headers as headers */
-       if (!prefixcmp(cp, "From ") || !prefixcmp(cp, ">From "))
+       if (starts_with(cp, "From ") || starts_with(cp, ">From "))
                return 1;
 
        while ((ch = *cp++)) {
@@ -671,11 +671,11 @@ static inline int patchbreak(const struct strbuf *line)
        size_t i;
 
        /* Beginning of a "diff -" header? */
-       if (!prefixcmp(line->buf, "diff -"))
+       if (starts_with(line->buf, "diff -"))
                return 1;
 
        /* CVS "Index: " line? */
-       if (!prefixcmp(line->buf, "Index: "))
+       if (starts_with(line->buf, "Index: "))
                return 1;
 
        /*
@@ -685,7 +685,7 @@ static inline int patchbreak(const struct strbuf *line)
        if (line->len < 4)
                return 0;
 
-       if (!prefixcmp(line->buf, "---")) {
+       if (starts_with(line->buf, "---")) {
                /* space followed by a filename? */
                if (line->buf[3] == ' ' && !isspace(line->buf[4]))
                        return 1;
@@ -986,7 +986,7 @@ static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch)
 
 static int git_mailinfo_config(const char *var, const char *value, void *unused)
 {
-       if (prefixcmp(var, "mailinfo."))
+       if (!starts_with(var, "mailinfo."))
                return git_default_config(var, value, unused);
        if (!strcmp(var, "mailinfo.scissors")) {
                use_scissors = git_config_bool(var, value);
@@ -1020,7 +1020,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
                        metainfo_charset = def_charset;
                else if (!strcmp(argv[1], "-n"))
                        metainfo_charset = NULL;
-               else if (!prefixcmp(argv[1], "--encoding="))
+               else if (starts_with(argv[1], "--encoding="))
                        metainfo_charset = argv[1] + 11;
                else if (!strcmp(argv[1], "--scissors"))
                        use_scissors = 1;
index 3a64f5d0bdbcc8d7d21edb01f285cc8b41755228..a90f28f34d2072b7d40964a7fa3cf46d3bb98cdd 100644 (file)
@@ -29,7 +29,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
        struct commit *result;
 
        init_merge_options(&o);
-       if (argv[0] && !suffixcmp(argv[0], "-subtree"))
+       if (argv[0] && ends_with(argv[0], "-subtree"))
                o.subtree_shift = "";
 
        if (argc < 4)
@@ -38,7 +38,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
        for (i = 1; i < argc; ++i) {
                const char *arg = argv[i];
 
-               if (!prefixcmp(arg, "--")) {
+               if (starts_with(arg, "--")) {
                        if (!arg[2])
                                break;
                        if (parse_merge_opt(&o, arg + 2))
index 41fb66dec2c2fd9645a72c28c362067fb3bcc16c..4941a6c36ab215fdb709ac58a3aea69218025dbb 100644 (file)
@@ -446,17 +446,17 @@ static void merge_name(const char *remote, struct strbuf *msg)
                die(_("'%s' does not point to a commit"), remote);
 
        if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) {
-               if (!prefixcmp(found_ref, "refs/heads/")) {
+               if (starts_with(found_ref, "refs/heads/")) {
                        strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
                                    sha1_to_hex(branch_head), remote);
                        goto cleanup;
                }
-               if (!prefixcmp(found_ref, "refs/tags/")) {
+               if (starts_with(found_ref, "refs/tags/")) {
                        strbuf_addf(msg, "%s\t\ttag '%s' of .\n",
                                    sha1_to_hex(branch_head), remote);
                        goto cleanup;
                }
-               if (!prefixcmp(found_ref, "refs/remotes/")) {
+               if (starts_with(found_ref, "refs/remotes/")) {
                        strbuf_addf(msg, "%s\t\tremote-tracking branch '%s' of .\n",
                                    sha1_to_hex(branch_head), remote);
                        goto cleanup;
@@ -570,8 +570,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
 {
        int status;
 
-       if (branch && !prefixcmp(k, "branch.") &&
-               !prefixcmp(k + 7, branch) &&
+       if (branch && starts_with(k, "branch.") &&
+               starts_with(k + 7, branch) &&
                !strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
                free(branch_mergeoptions);
                branch_mergeoptions = xstrdup(v);
@@ -1106,7 +1106,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * current branch.
         */
        branch = branch_to_free = resolve_refdup("HEAD", head_sha1, 0, &flag);
-       if (branch && !prefixcmp(branch, "refs/heads/"))
+       if (branch && starts_with(branch, "refs/heads/"))
                branch += 11;
        if (!branch || is_null_sha1(head_sha1))
                head_commit = NULL;
index 2e0e61b6517d74edc8b7ef2e56c75927385e7c85..08fbc033e45bba4880c8de797ef5ac0dc0b6259d 100644 (file)
@@ -16,9 +16,12 @@ static const char * const builtin_mv_usage[] = {
        NULL
 };
 
+#define DUP_BASENAME 1
+#define KEEP_TRAILING_SLASH 2
+
 static const char **internal_copy_pathspec(const char *prefix,
                                           const char **pathspec,
-                                          int count, int base_name)
+                                          int count, unsigned flags)
 {
        int i;
        const char **result = xmalloc((count + 1) * sizeof(const char *));
@@ -27,11 +30,12 @@ static const char **internal_copy_pathspec(const char *prefix,
        for (i = 0; i < count; i++) {
                int length = strlen(result[i]);
                int to_copy = length;
-               while (to_copy > 0 && is_dir_sep(result[i][to_copy - 1]))
+               while (!(flags & KEEP_TRAILING_SLASH) &&
+                      to_copy > 0 && is_dir_sep(result[i][to_copy - 1]))
                        to_copy--;
-               if (to_copy != length || base_name) {
+               if (to_copy != length || flags & DUP_BASENAME) {
                        char *it = xmemdupz(result[i], to_copy);
-                       if (base_name) {
+                       if (flags & DUP_BASENAME) {
                                result[i] = xstrdup(basename(it));
                                free(it);
                        } else
@@ -87,16 +91,21 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
        source = internal_copy_pathspec(prefix, argv, argc, 0);
        modes = xcalloc(argc, sizeof(enum update_mode));
-       dest_path = internal_copy_pathspec(prefix, argv + argc, 1, 0);
+       /*
+        * Keep trailing slash, needed to let
+        * "git mv file no-such-dir/" error out.
+        */
+       dest_path = internal_copy_pathspec(prefix, argv + argc, 1,
+                                          KEEP_TRAILING_SLASH);
        submodule_gitfile = xcalloc(argc, sizeof(char *));
 
        if (dest_path[0][0] == '\0')
                /* special case: "." was normalized to "" */
-               destination = internal_copy_pathspec(dest_path[0], argv, argc, 1);
+               destination = internal_copy_pathspec(dest_path[0], argv, argc, DUP_BASENAME);
        else if (!lstat(dest_path[0], &st) &&
                        S_ISDIR(st.st_mode)) {
                dest_path[0] = add_slash(dest_path[0]);
-               destination = internal_copy_pathspec(dest_path[0], argv, argc, 1);
+               destination = internal_copy_pathspec(dest_path[0], argv, argc, DUP_BASENAME);
        } else {
                if (argc != 1)
                        die("destination '%s' is not a directory", dest_path[0]);
index 23daaa7d99b40e1bbd38a2743bc0d9ed0c38eda9..0b21d7e5b297ff3d2d1a73d8a74c8bc37e672ccb 100644 (file)
@@ -100,9 +100,9 @@ static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
 {
        if (shorten_unambiguous)
                refname = shorten_unambiguous_ref(refname, 0);
-       else if (!prefixcmp(refname, "refs/heads/"))
+       else if (starts_with(refname, "refs/heads/"))
                refname = refname + 11;
-       else if (!prefixcmp(refname, "refs/"))
+       else if (starts_with(refname, "refs/"))
                refname = refname + 5;
        return refname;
 }
@@ -148,7 +148,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
        int can_abbreviate_output = data->tags_only && data->name_only;
        int deref = 0;
 
-       if (data->tags_only && prefixcmp(path, "refs/tags/"))
+       if (data->tags_only && !starts_with(path, "refs/tags/"))
                return 0;
 
        if (data->ref_filter) {
index d459e23c4225ae0f8084cfd756563c2b7ab85a60..2b24d059b509d28d587066440ed131ce2f85464f 100644 (file)
@@ -347,7 +347,7 @@ static struct notes_tree *init_notes_check(const char *subcommand)
        init_notes(NULL, NULL, NULL, 0);
        t = &default_notes_tree;
 
-       if (prefixcmp(t->ref, "refs/notes/"))
+       if (!starts_with(t->ref, "refs/notes/"))
                die("Refusing to %s notes in %s (outside of refs/notes/)",
                    subcommand, t->ref);
        return t;
index 36273dd6f0ebf3eab1062a0e24b9aa0c1834ce02..dfb4d84caa506cee874fd972bc0e9df1a4121362 100644 (file)
@@ -2032,7 +2032,7 @@ static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, vo
 {
        unsigned char peeled[20];
 
-       if (!prefixcmp(path, "refs/tags/") && /* is a tag? */
+       if (starts_with(path, "refs/tags/") && /* is a tag? */
            !peel_ref(path, peeled)        && /* peelable? */
            locate_object_entry(peeled))      /* object packed? */
                add_object_entry(sha1, OBJ_TAG, NULL, 0);
index 6366917c6de55e171a7f697b22f1de10293addf5..a85ef54d5aeb679067c7f3ad428439886a162362 100644 (file)
@@ -80,7 +80,7 @@ static int prune_dir(int i, char *path)
                        prune_object(path, de->d_name, sha1);
                        continue;
                }
-               if (!prefixcmp(de->d_name, "tmp_obj_")) {
+               if (starts_with(de->d_name, "tmp_obj_")) {
                        prune_tmp_object(path, de->d_name);
                        continue;
                }
@@ -119,7 +119,7 @@ static void remove_temporary_files(const char *path)
                return;
        }
        while ((de = readdir(dir)) != NULL)
-               if (!prefixcmp(de->d_name, "tmp_"))
+               if (starts_with(de->d_name, "tmp_"))
                        prune_tmp_object(path, de->d_name);
        closedir(dir);
 }
index 7b1b66c36ac14cb29db9dbbbd5b6f4d27b67d91c..0e50ddbb01342128d9118217118726000bdeaff6 100644 (file)
@@ -35,35 +35,75 @@ static void add_refspec(const char *ref)
        refspec[refspec_nr-1] = ref;
 }
 
-static void set_refspecs(const char **refs, int nr)
+static const char *map_refspec(const char *ref,
+                              struct remote *remote, struct ref *local_refs)
 {
+       struct ref *matched = NULL;
+
+       /* Does "ref" uniquely name our ref? */
+       if (count_refspec_match(ref, local_refs, &matched) != 1)
+               return ref;
+
+       if (remote->push) {
+               struct refspec query;
+               memset(&query, 0, sizeof(struct refspec));
+               query.src = matched->name;
+               if (!query_refspecs(remote->push, remote->push_refspec_nr, &query) &&
+                   query.dst) {
+                       struct strbuf buf = STRBUF_INIT;
+                       strbuf_addf(&buf, "%s%s:%s",
+                                   query.force ? "+" : "",
+                                   query.src, query.dst);
+                       return strbuf_detach(&buf, NULL);
+               }
+       }
+
+       if (push_default == PUSH_DEFAULT_UPSTREAM &&
+           !prefixcmp(matched->name, "refs/heads/")) {
+               struct branch *branch = branch_get(matched->name + 11);
+               if (branch->merge_nr == 1 && branch->merge[0]->src) {
+                       struct strbuf buf = STRBUF_INIT;
+                       strbuf_addf(&buf, "%s:%s",
+                                   ref, branch->merge[0]->src);
+                       return strbuf_detach(&buf, NULL);
+               }
+       }
+
+       return ref;
+}
+
+static void set_refspecs(const char **refs, int nr, const char *repo)
+{
+       struct remote *remote = NULL;
+       struct ref *local_refs = NULL;
        int i;
+
        for (i = 0; i < nr; i++) {
                const char *ref = refs[i];
                if (!strcmp("tag", ref)) {
-                       char *tag;
-                       int len;
+                       struct strbuf tagref = STRBUF_INIT;
                        if (nr <= ++i)
                                die(_("tag shorthand without <tag>"));
-                       len = strlen(refs[i]) + 11;
-                       if (deleterefs) {
-                               tag = xmalloc(len+1);
-                               strcpy(tag, ":refs/tags/");
-                       } else {
-                               tag = xmalloc(len);
-                               strcpy(tag, "refs/tags/");
+                       ref = refs[i];
+                       if (deleterefs)
+                               strbuf_addf(&tagref, ":refs/tags/%s", ref);
+                       else
+                               strbuf_addf(&tagref, "refs/tags/%s", ref);
+                       ref = strbuf_detach(&tagref, NULL);
+               } else if (deleterefs) {
+                       struct strbuf delref = STRBUF_INIT;
+                       if (strchr(ref, ':'))
+                               die(_("--delete only accepts plain target ref names"));
+                       strbuf_addf(&delref, ":%s", ref);
+                       ref = strbuf_detach(&delref, NULL);
+               } else if (!strchr(ref, ':')) {
+                       if (!remote) {
+                               /* lazily grab remote and local_refs */
+                               remote = remote_get(repo);
+                               local_refs = get_local_heads();
                        }
-                       strcat(tag, refs[i]);
-                       ref = tag;
-               } else if (deleterefs && !strchr(ref, ':')) {
-                       char *delref;
-                       int len = strlen(ref)+1;
-                       delref = xmalloc(len+1);
-                       strcpy(delref, ":");
-                       strcat(delref, ref);
-                       ref = delref;
-               } else if (deleterefs)
-                       die(_("--delete only accepts plain target ref names"));
+                       ref = map_refspec(ref, remote, local_refs);
+               }
                add_refspec(ref);
        }
 }
@@ -174,6 +214,13 @@ N_("push.default is unset; its implicit value is changing in\n"
    "\n"
    "  git config --global push.default simple\n"
    "\n"
+   "When push.default is set to 'matching', git will push local branches\n"
+   "to the remote branches that already exist with the same name.\n"
+   "\n"
+   "In Git 2.0, Git will default to the more conservative 'simple'\n"
+   "behavior, which only pushes the current branch to the corresponding\n"
+   "remote branch that 'git pull' uses to update the current branch.\n"
+   "\n"
    "See 'git help config' and search for 'push.default' for further information.\n"
    "(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode\n"
    "'current' instead of 'simple' if you sometimes use older versions of Git)");
@@ -494,7 +541,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 
        if (argc > 0) {
                repo = argv[0];
-               set_refspecs(argv + 1, argc - 1);
+               set_refspecs(argv + 1, argc - 1, repo);
        }
 
        rc = do_push(repo, flags);
index 67ce1ef105d1494e7905e66750b14676e082e11c..e09994f4dfa3a50ea285ad20d61dd845f4bea357 100644 (file)
@@ -428,7 +428,7 @@ static const char *update(struct command *cmd)
        struct ref_lock *lock;
 
        /* only refs/... are allowed */
-       if (prefixcmp(name, "refs/") || check_refname_format(name + 5, 0)) {
+       if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) {
                rp_error("refusing to create funny ref '%s' remotely", name);
                return "funny refname";
        }
@@ -459,7 +459,7 @@ static const char *update(struct command *cmd)
        }
 
        if (!is_null_sha1(old_sha1) && is_null_sha1(new_sha1)) {
-               if (deny_deletes && !prefixcmp(name, "refs/heads/")) {
+               if (deny_deletes && starts_with(name, "refs/heads/")) {
                        rp_error("denying ref deletion for %s", name);
                        return "deletion prohibited";
                }
@@ -483,7 +483,7 @@ static const char *update(struct command *cmd)
 
        if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
            !is_null_sha1(old_sha1) &&
-           !prefixcmp(name, "refs/heads/")) {
+           starts_with(name, "refs/heads/")) {
                struct object *old_object, *new_object;
                struct commit *old_commit, *new_commit;
 
index 6eb24c8da27d265cad38628aeaa3e040dd298aab..852cff60b784d316cddb59234b6276dfe18fd75d 100644 (file)
@@ -610,12 +610,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
                const char *arg = argv[i];
                if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
                        cb.dry_run = 1;
-               else if (!prefixcmp(arg, "--expire=")) {
+               else if (starts_with(arg, "--expire=")) {
                        if (parse_expiry_date(arg + 9, &cb.expire_total))
                                die(_("'%s' is not a valid timestamp"), arg);
                        explicit_expiry |= EXPIRE_TOTAL;
                }
-               else if (!prefixcmp(arg, "--expire-unreachable=")) {
+               else if (starts_with(arg, "--expire-unreachable=")) {
                        if (parse_expiry_date(arg + 21, &cb.expire_unreachable))
                                die(_("'%s' is not a valid timestamp"), arg);
                        explicit_expiry |= EXPIRE_UNREACH;
index 4e14891095e6ea016b9f44262ae300c42a75e1b2..b3ab4cf8f6517c715845db7e17c67cad5f50d730 100644 (file)
@@ -6,6 +6,7 @@
 #include "strbuf.h"
 #include "run-command.h"
 #include "refs.h"
+#include "argv-array.h"
 
 static const char * const builtin_remote_usage[] = {
        N_("git remote [-v | --verbose]"),
@@ -77,17 +78,6 @@ static const char * const builtin_remote_seturl_usage[] = {
 
 static int verbose;
 
-static int show_all(void);
-static int prune_remote(const char *remote, int dry_run);
-
-static inline int postfixcmp(const char *string, const char *postfix)
-{
-       int len1 = strlen(string), len2 = strlen(postfix);
-       if (len1 < len2)
-               return 1;
-       return strcmp(string + len1 - len2, postfix);
-}
-
 static int fetch_remote(const char *name)
 {
        const char *argv[] = { "fetch", name, NULL, NULL };
@@ -269,7 +259,7 @@ static const char *abbrev_ref(const char *name, const char *prefix)
 
 static int config_read_branches(const char *key, const char *value, void *cb)
 {
-       if (!prefixcmp(key, "branch.")) {
+       if (starts_with(key, "branch.")) {
                const char *orig_key = key;
                char *name;
                struct string_list_item *item;
@@ -277,13 +267,13 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                enum { REMOTE, MERGE, REBASE } type;
 
                key += 7;
-               if (!postfixcmp(key, ".remote")) {
+               if (ends_with(key, ".remote")) {
                        name = xstrndup(key, strlen(key) - 7);
                        type = REMOTE;
-               } else if (!postfixcmp(key, ".merge")) {
+               } else if (ends_with(key, ".merge")) {
                        name = xstrndup(key, strlen(key) - 6);
                        type = MERGE;
-               } else if (!postfixcmp(key, ".rebase")) {
+               } else if (ends_with(key, ".rebase")) {
                        name = xstrndup(key, strlen(key) - 7);
                        type = REBASE;
                } else
@@ -309,8 +299,13 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                                space = strchr(value, ' ');
                        }
                        string_list_append(&info->merge, xstrdup(value));
-               } else
-                       info->rebase = git_config_bool(orig_key, value);
+               } else {
+                       int v = git_config_maybe_bool(orig_key, value);
+                       if (v >= 0)
+                               info->rebase = v;
+                       else if (!strcmp(value, "preserve"))
+                               info->rebase = 1;
+               }
        }
        return 0;
 }
@@ -534,9 +529,9 @@ static int add_branch_for_removal(const char *refname,
        }
 
        /* don't delete non-remote-tracking refs */
-       if (prefixcmp(refname, "refs/remotes/")) {
+       if (!starts_with(refname, "refs/remotes/")) {
                /* advise user how to delete local branches */
-               if (!prefixcmp(refname, "refs/heads/"))
+               if (starts_with(refname, "refs/heads/"))
                        string_list_append(branches->skipped,
                                           abbrev_branch(refname));
                /* silently skip over other non-remote refs */
@@ -571,7 +566,7 @@ static int read_remote_branches(const char *refname,
        const char *symref;
 
        strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
-       if (!prefixcmp(refname, buf.buf)) {
+       if (starts_with(refname, buf.buf)) {
                item = string_list_append(rename->remote_branches, xstrdup(refname));
                symref = resolve_ref_unsafe(refname, orig_sha1, 1, &flag);
                if (flag & REF_ISSYMREF)
@@ -1084,6 +1079,64 @@ static int show_push_info_item(struct string_list_item *item, void *cb_data)
        return 0;
 }
 
+static int get_one_entry(struct remote *remote, void *priv)
+{
+       struct string_list *list = priv;
+       struct strbuf url_buf = STRBUF_INIT;
+       const char **url;
+       int i, url_nr;
+
+       if (remote->url_nr > 0) {
+               strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]);
+               string_list_append(list, remote->name)->util =
+                               strbuf_detach(&url_buf, NULL);
+       } else
+               string_list_append(list, remote->name)->util = NULL;
+       if (remote->pushurl_nr) {
+               url = remote->pushurl;
+               url_nr = remote->pushurl_nr;
+       } else {
+               url = remote->url;
+               url_nr = remote->url_nr;
+       }
+       for (i = 0; i < url_nr; i++)
+       {
+               strbuf_addf(&url_buf, "%s (push)", url[i]);
+               string_list_append(list, remote->name)->util =
+                               strbuf_detach(&url_buf, NULL);
+       }
+
+       return 0;
+}
+
+static int show_all(void)
+{
+       struct string_list list = STRING_LIST_INIT_NODUP;
+       int result;
+
+       list.strdup_strings = 1;
+       result = for_each_remote(get_one_entry, &list);
+
+       if (!result) {
+               int i;
+
+               sort_string_list(&list);
+               for (i = 0; i < list.nr; i++) {
+                       struct string_list_item *item = list.items + i;
+                       if (verbose)
+                               printf("%s\t%s\n", item->string,
+                                       item->util ? (const char *)item->util : "");
+                       else {
+                               if (i && !strcmp((item - 1)->string, item->string))
+                                       continue;
+                               printf("%s\n", item->string);
+                       }
+               }
+       }
+       string_list_clear(&list, 1);
+       return result;
+}
+
 static int show(int argc, const char **argv)
 {
        int no_query = 0, result = 0, query_flag = 0;
@@ -1246,26 +1299,6 @@ static int set_head(int argc, const char **argv)
        return result;
 }
 
-static int prune(int argc, const char **argv)
-{
-       int dry_run = 0, result = 0;
-       struct option options[] = {
-               OPT__DRY_RUN(&dry_run, N_("dry run")),
-               OPT_END()
-       };
-
-       argc = parse_options(argc, argv, NULL, options, builtin_remote_prune_usage,
-                            0);
-
-       if (argc < 1)
-               usage_with_options(builtin_remote_prune_usage, options);
-
-       for (; argc; argc--, argv++)
-               result |= prune_remote(*argv, dry_run);
-
-       return result;
-}
-
 static int prune_remote(const char *remote, int dry_run)
 {
        int result = 0, i;
@@ -1304,6 +1337,26 @@ static int prune_remote(const char *remote, int dry_run)
        return result;
 }
 
+static int prune(int argc, const char **argv)
+{
+       int dry_run = 0, result = 0;
+       struct option options[] = {
+               OPT__DRY_RUN(&dry_run, N_("dry run")),
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, NULL, options, builtin_remote_prune_usage,
+                            0);
+
+       if (argc < 1)
+               usage_with_options(builtin_remote_prune_usage, options);
+
+       for (; argc; argc--, argv++)
+               result |= prune_remote(*argv, dry_run);
+
+       return result;
+}
+
 static int get_remote_default(const char *key, const char *value, void *priv)
 {
        if (strcmp(key, "remotes.default") == 0) {
@@ -1315,42 +1368,42 @@ static int get_remote_default(const char *key, const char *value, void *priv)
 
 static int update(int argc, const char **argv)
 {
-       int i, prune = 0;
+       int i, prune = -1;
        struct option options[] = {
                OPT_BOOL('p', "prune", &prune,
                         N_("prune remotes after fetching")),
                OPT_END()
        };
-       const char **fetch_argv;
-       int fetch_argc = 0;
+       struct argv_array fetch_argv = ARGV_ARRAY_INIT;
        int default_defined = 0;
-
-       fetch_argv = xmalloc(sizeof(char *) * (argc+5));
+       int retval;
 
        argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage,
                             PARSE_OPT_KEEP_ARGV0);
 
-       fetch_argv[fetch_argc++] = "fetch";
+       argv_array_push(&fetch_argv, "fetch");
 
-       if (prune)
-               fetch_argv[fetch_argc++] = "--prune";
+       if (prune != -1)
+               argv_array_push(&fetch_argv, prune ? "--prune" : "--no-prune");
        if (verbose)
-               fetch_argv[fetch_argc++] = "-v";
-       fetch_argv[fetch_argc++] = "--multiple";
+               argv_array_push(&fetch_argv, "-v");
+       argv_array_push(&fetch_argv, "--multiple");
        if (argc < 2)
-               fetch_argv[fetch_argc++] = "default";
+               argv_array_push(&fetch_argv, "default");
        for (i = 1; i < argc; i++)
-               fetch_argv[fetch_argc++] = argv[i];
+               argv_array_push(&fetch_argv, argv[i]);
 
-       if (strcmp(fetch_argv[fetch_argc-1], "default") == 0) {
+       if (strcmp(fetch_argv.argv[fetch_argv.argc-1], "default") == 0) {
                git_config(get_remote_default, &default_defined);
-               if (!default_defined)
-                       fetch_argv[fetch_argc-1] = "--all";
+               if (!default_defined) {
+                       argv_array_pop(&fetch_argv);
+                       argv_array_push(&fetch_argv, "--all");
+               }
        }
 
-       fetch_argv[fetch_argc] = NULL;
-
-       return run_command_v_opt(fetch_argv, RUN_GIT_CMD);
+       retval = run_command_v_opt(fetch_argv.argv, RUN_GIT_CMD);
+       argv_array_clear(&fetch_argv);
+       return retval;
 }
 
 static int remove_all_fetch_refspecs(const char *remote, const char *key)
@@ -1505,64 +1558,6 @@ static int set_url(int argc, const char **argv)
        return 0;
 }
 
-static int get_one_entry(struct remote *remote, void *priv)
-{
-       struct string_list *list = priv;
-       struct strbuf url_buf = STRBUF_INIT;
-       const char **url;
-       int i, url_nr;
-
-       if (remote->url_nr > 0) {
-               strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]);
-               string_list_append(list, remote->name)->util =
-                               strbuf_detach(&url_buf, NULL);
-       } else
-               string_list_append(list, remote->name)->util = NULL;
-       if (remote->pushurl_nr) {
-               url = remote->pushurl;
-               url_nr = remote->pushurl_nr;
-       } else {
-               url = remote->url;
-               url_nr = remote->url_nr;
-       }
-       for (i = 0; i < url_nr; i++)
-       {
-               strbuf_addf(&url_buf, "%s (push)", url[i]);
-               string_list_append(list, remote->name)->util =
-                               strbuf_detach(&url_buf, NULL);
-       }
-
-       return 0;
-}
-
-static int show_all(void)
-{
-       struct string_list list = STRING_LIST_INIT_NODUP;
-       int result;
-
-       list.strdup_strings = 1;
-       result = for_each_remote(get_one_entry, &list);
-
-       if (!result) {
-               int i;
-
-               sort_string_list(&list);
-               for (i = 0; i < list.nr; i++) {
-                       struct string_list_item *item = list.items + i;
-                       if (verbose)
-                               printf("%s\t%s\n", item->string,
-                                       item->util ? (const char *)item->util : "");
-                       else {
-                               if (i && !strcmp((item - 1)->string, item->string))
-                                       continue;
-                               printf("%s\n", item->string);
-                       }
-               }
-       }
-       string_list_clear(&list, 1);
-       return result;
-}
-
 int cmd_remote(int argc, const char **argv, const char *prefix)
 {
        struct option options[] = {
index a0ff5c704f4e21c5021091aa7335e00959993470..ba66c6e37782fcf1bad53b7986e69ec113c4521c 100644 (file)
@@ -78,7 +78,7 @@ static void get_non_kept_pack_filenames(struct string_list *fname_list)
                return;
 
        while ((e = readdir(dir)) != NULL) {
-               if (suffixcmp(e->d_name, ".pack"))
+               if (!ends_with(e->d_name, ".pack"))
                        continue;
 
                len = strlen(e->d_name) - strlen(".pack");
@@ -123,7 +123,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        struct string_list rollback = STRING_LIST_INIT_NODUP;
        struct string_list existing_packs = STRING_LIST_INIT_DUP;
        struct strbuf line = STRBUF_INIT;
-       int nr_packs, ext, ret, failed;
+       int ext, ret, failed;
        FILE *out;
 
        /* variables to be filled by option parsing */
@@ -233,13 +233,11 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        if (ret)
                return ret;
 
-       nr_packs = 0;
        out = xfdopen(cmd.out, "r");
        while (strbuf_getline(&line, out, '\n') != EOF) {
                if (line.len != 40)
                        die("repack: Expecting 40 character sha1 lines only from pack-objects.");
                string_list_append(&names, line.buf);
-               nr_packs++;
        }
        fclose(out);
        ret = finish_command(&cmd);
@@ -247,7 +245,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                return ret;
        argv_array_clear(&cmd_args);
 
-       if (!nr_packs && !quiet)
+       if (!names.nr && !quiet)
                printf("Nothing new to pack.\n");
 
        /*
index c76b89dc5bcccb42f7c2613072b1093a58c7d21c..aaeb611a9729938251b1c679e35c446bb737ff4f 100644 (file)
@@ -9,6 +9,8 @@
 #include "quote.h"
 #include "builtin.h"
 #include "parse-options.h"
+#include "diff.h"
+#include "revision.h"
 
 #define DO_REVS                1
 #define DO_NOREV       2
@@ -30,6 +32,9 @@ static int abbrev_ref;
 static int abbrev_ref_strict;
 static int output_sq;
 
+static int stuck_long;
+static struct string_list *ref_excludes;
+
 /*
  * Some arguments are relevant "revision" arguments,
  * others are about output format or other details.
@@ -185,6 +190,8 @@ static int show_default(void)
 
 static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
 {
+       if (ref_excluded(ref_excludes, refname))
+               return 0;
        show_rev(NORMAL, sha1, refname);
        return 0;
 }
@@ -279,6 +286,7 @@ static int try_difference(const char *arg)
                                exclude = n;
                        }
                }
+               *dotdot = '.';
                return 1;
        }
        *dotdot = '.';
@@ -302,8 +310,10 @@ static int try_parent_shorthands(const char *arg)
                return 0;
 
        *dotdot = 0;
-       if (get_sha1_committish(arg, sha1))
+       if (get_sha1_committish(arg, sha1)) {
+               *dotdot = '^';
                return 0;
+       }
 
        if (!parents_only)
                show_rev(NORMAL, sha1, arg);
@@ -312,6 +322,7 @@ static int try_parent_shorthands(const char *arg)
                show_rev(parents_only ? NORMAL : REVERSED,
                                parents->item->object.sha1, arg);
 
+       *dotdot = '^';
        return 1;
 }
 
@@ -320,12 +331,15 @@ static int parseopt_dump(const struct option *o, const char *arg, int unset)
        struct strbuf *parsed = o->value;
        if (unset)
                strbuf_addf(parsed, " --no-%s", o->long_name);
-       else if (o->short_name)
+       else if (o->short_name && (o->long_name == NULL || !stuck_long))
                strbuf_addf(parsed, " -%c", o->short_name);
        else
                strbuf_addf(parsed, " --%s", o->long_name);
        if (arg) {
-               strbuf_addch(parsed, ' ');
+               if (!stuck_long)
+                       strbuf_addch(parsed, ' ');
+               else if (o->long_name)
+                       strbuf_addch(parsed, '=');
                sq_quote_buf(parsed, arg);
        }
        return 0;
@@ -351,6 +365,8 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "stop-at-non-option", &stop_at_non_option,
                                        N_("stop parsing after the "
                                           "first non-option argument")),
+               OPT_BOOL(0, "stuck-long", &stuck_long,
+                                       N_("output in stuck long form")),
                OPT_END(),
        };
 
@@ -476,6 +492,7 @@ N_("git rev-parse --parseopt [options] -- [<args>...]\n"
 int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 {
        int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
+       int has_dashdash = 0;
        int output_prefix = 0;
        unsigned char sha1[20];
        const char *name = NULL;
@@ -489,6 +506,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
        if (argc > 1 && !strcmp("-h", argv[1]))
                usage(builtin_rev_parse_usage);
 
+       for (i = 1; i < argc; i++) {
+               if (!strcmp(argv[i], "--")) {
+                       has_dashdash = 1;
+                       break;
+               }
+       }
+
        prefix = setup_git_directory();
        git_config(git_default_config, NULL);
        for (i = 1; i < argc; i++) {
@@ -508,7 +532,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                        }
                        continue;
                }
-               if (!prefixcmp(arg, "-n")) {
+               if (starts_with(arg, "-n")) {
                        if ((filter & DO_FLAGS) && (filter & DO_REVS))
                                show(arg);
                        continue;
@@ -560,7 +584,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                continue;
                        }
                        if (!strcmp(arg, "--short") ||
-                           !prefixcmp(arg, "--short=")) {
+                           starts_with(arg, "--short=")) {
                                filter &= ~(DO_FLAGS|DO_NOREV);
                                verify = 1;
                                abbrev = DEFAULT_ABBREV;
@@ -588,7 +612,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                symbolic = SHOW_SYMBOLIC_FULL;
                                continue;
                        }
-                       if (!prefixcmp(arg, "--abbrev-ref") &&
+                       if (starts_with(arg, "--abbrev-ref") &&
                            (!arg[12] || arg[12] == '=')) {
                                abbrev_ref = 1;
                                abbrev_ref_strict = warn_ambiguous_refs;
@@ -606,7 +630,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                for_each_ref(show_reference, NULL);
                                continue;
                        }
-                       if (!prefixcmp(arg, "--disambiguate=")) {
+                       if (starts_with(arg, "--disambiguate=")) {
                                for_each_abbrev(arg + 15, show_abbrev, NULL);
                                continue;
                        }
@@ -615,35 +639,46 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                for_each_ref_in("refs/bisect/good", anti_reference, NULL);
                                continue;
                        }
-                       if (!prefixcmp(arg, "--branches=")) {
+                       if (starts_with(arg, "--branches=")) {
                                for_each_glob_ref_in(show_reference, arg + 11,
                                        "refs/heads/", NULL);
+                               clear_ref_exclusion(&ref_excludes);
                                continue;
                        }
                        if (!strcmp(arg, "--branches")) {
                                for_each_branch_ref(show_reference, NULL);
+                               clear_ref_exclusion(&ref_excludes);
                                continue;
                        }
-                       if (!prefixcmp(arg, "--tags=")) {
+                       if (starts_with(arg, "--tags=")) {
                                for_each_glob_ref_in(show_reference, arg + 7,
                                        "refs/tags/", NULL);
+                               clear_ref_exclusion(&ref_excludes);
                                continue;
                        }
                        if (!strcmp(arg, "--tags")) {
                                for_each_tag_ref(show_reference, NULL);
+                               clear_ref_exclusion(&ref_excludes);
                                continue;
                        }
-                       if (!prefixcmp(arg, "--glob=")) {
+                       if (starts_with(arg, "--glob=")) {
                                for_each_glob_ref(show_reference, arg + 7, NULL);
+                               clear_ref_exclusion(&ref_excludes);
                                continue;
                        }
-                       if (!prefixcmp(arg, "--remotes=")) {
+                       if (starts_with(arg, "--remotes=")) {
                                for_each_glob_ref_in(show_reference, arg + 10,
                                        "refs/remotes/", NULL);
+                               clear_ref_exclusion(&ref_excludes);
                                continue;
                        }
                        if (!strcmp(arg, "--remotes")) {
                                for_each_remote_ref(show_reference, NULL);
+                               clear_ref_exclusion(&ref_excludes);
+                               continue;
+                       }
+                       if (starts_with(arg, "--exclude=")) {
+                               add_ref_exclusion(&ref_excludes, arg + 10);
                                continue;
                        }
                        if (!strcmp(arg, "--local-env-vars")) {
@@ -724,19 +759,19 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                                : "false");
                                continue;
                        }
-                       if (!prefixcmp(arg, "--since=")) {
+                       if (starts_with(arg, "--since=")) {
                                show_datestring("--max-age=", arg+8);
                                continue;
                        }
-                       if (!prefixcmp(arg, "--after=")) {
+                       if (starts_with(arg, "--after=")) {
                                show_datestring("--max-age=", arg+8);
                                continue;
                        }
-                       if (!prefixcmp(arg, "--before=")) {
+                       if (starts_with(arg, "--before=")) {
                                show_datestring("--min-age=", arg+9);
                                continue;
                        }
-                       if (!prefixcmp(arg, "--until=")) {
+                       if (starts_with(arg, "--until=")) {
                                show_datestring("--min-age=", arg+8);
                                continue;
                        }
@@ -765,6 +800,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                }
                if (verify)
                        die_no_single_rev(quiet);
+               if (has_dashdash)
+                       die("bad revision '%s'", arg);
                as_is = 1;
                if (!show_file(arg, output_prefix))
                        continue;
index 4482f16efb66c7fc06c7446a2e992840cc83f798..e7f0b97d315e0866a2bb3a95a0d1feebceddd545 100644 (file)
@@ -115,15 +115,15 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
                const char *arg = *argv;
 
                if (*arg == '-') {
-                       if (!prefixcmp(arg, "--receive-pack=")) {
+                       if (starts_with(arg, "--receive-pack=")) {
                                receivepack = arg + 15;
                                continue;
                        }
-                       if (!prefixcmp(arg, "--exec=")) {
+                       if (starts_with(arg, "--exec=")) {
                                receivepack = arg + 7;
                                continue;
                        }
-                       if (!prefixcmp(arg, "--remote=")) {
+                       if (starts_with(arg, "--remote=")) {
                                remote_name = arg + 9;
                                continue;
                        }
@@ -181,7 +181,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
                                        exit(1);
                                continue;
                        }
-                       if (!prefixcmp(arg, "--" CAS_OPT_NAME "=")) {
+                       if (starts_with(arg, "--" CAS_OPT_NAME "=")) {
                                if (parse_push_cas_option(&cas,
                                                          strchr(arg, '=') + 1, 0) < 0)
                                        exit(1);
index c226f767aa9b0e5633a3d5dde7b0b969fec39c7f..4b7e53623fc9cf0c86ed0e7e87d4b3357d765d86 100644 (file)
@@ -65,7 +65,7 @@ static void insert_one_record(struct shortlog *log,
        eol = strchr(oneline, '\n');
        if (!eol)
                eol = oneline + strlen(oneline);
-       if (!prefixcmp(oneline, "[PATCH")) {
+       if (starts_with(oneline, "[PATCH")) {
                char *eob = strchr(oneline, ']');
                if (eob && (!eol || eob < eol))
                        oneline = eob + 1;
@@ -95,7 +95,7 @@ static void read_from_stdin(struct shortlog *log)
 
        while (fgets(author, sizeof(author), stdin) != NULL) {
                if (!(author[0] == 'A' || author[0] == 'a') ||
-                   prefixcmp(author + 1, "uthor: "))
+                   !starts_with(author + 1, "uthor: "))
                        continue;
                while (fgets(oneline, sizeof(oneline), stdin) &&
                       oneline[0] != '\n')
@@ -123,7 +123,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
                else
                        eol++;
 
-               if (!prefixcmp(buffer, "author "))
+               if (starts_with(buffer, "author "))
                        author = buffer + 7;
                buffer = eol;
        }
index 46902c3de40b05b19ff1b5b0127b9f1cd11f6cde..d9217ce1e1a957462284224c08786db77f5a8f15 100644 (file)
@@ -284,7 +284,7 @@ static void show_one_commit(struct commit *commit, int no_name)
                pp_commit_easy(CMIT_FMT_ONELINE, commit, &pretty);
                pretty_str = pretty.buf;
        }
-       if (!prefixcmp(pretty_str, "[PATCH] "))
+       if (starts_with(pretty_str, "[PATCH] "))
                pretty_str += 8;
 
        if (!no_name) {
@@ -395,7 +395,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1, int f
 {
        unsigned char tmp[20];
        int ofs = 11;
-       if (prefixcmp(refname, "refs/heads/"))
+       if (!starts_with(refname, "refs/heads/"))
                return 0;
        /* If both heads/foo and tags/foo exists, get_sha1 would
         * get confused.
@@ -409,7 +409,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int
 {
        unsigned char tmp[20];
        int ofs = 13;
-       if (prefixcmp(refname, "refs/remotes/"))
+       if (!starts_with(refname, "refs/remotes/"))
                return 0;
        /* If both heads/foo and tags/foo exists, get_sha1 would
         * get confused.
@@ -421,7 +421,7 @@ static int append_remote_ref(const char *refname, const unsigned char *sha1, int
 
 static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
 {
-       if (prefixcmp(refname, "refs/tags/"))
+       if (!starts_with(refname, "refs/tags/"))
                return 0;
        return append_ref(refname + 5, sha1, 0);
 }
@@ -452,9 +452,9 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i
                return 0;
        if (fnmatch(match_ref_pattern, tail, 0))
                return 0;
-       if (!prefixcmp(refname, "refs/heads/"))
+       if (starts_with(refname, "refs/heads/"))
                return append_head_ref(refname, sha1, flag, cb_data);
-       if (!prefixcmp(refname, "refs/tags/"))
+       if (starts_with(refname, "refs/tags/"))
                return append_tag_ref(refname, sha1, flag, cb_data);
        return append_ref(refname, sha1, 0);
 }
@@ -479,11 +479,11 @@ static int rev_is_head(char *head, int headlen, char *name,
        if ((!head[0]) ||
            (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
                return 0;
-       if (!prefixcmp(head, "refs/heads/"))
+       if (starts_with(head, "refs/heads/"))
                head += 11;
-       if (!prefixcmp(name, "refs/heads/"))
+       if (starts_with(name, "refs/heads/"))
                name += 11;
-       else if (!prefixcmp(name, "heads/"))
+       else if (starts_with(name, "heads/"))
                name += 6;
        return !strcmp(head, name);
 }
@@ -812,7 +812,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                                has_head++;
                }
                if (!has_head) {
-                       int offset = !prefixcmp(head, "refs/heads/") ? 11 : 0;
+                       int offset = starts_with(head, "refs/heads/") ? 11 : 0;
                        append_one_rev(head + offset);
                }
        }
index 9f3f5e370bfb123df5c662bead122b29622fc1dd..5ba1f3083890c693f8ce82166fe1cb1f6440b106 100644 (file)
@@ -37,8 +37,8 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo
        if (tags_only || heads_only) {
                int match;
 
-               match = heads_only && !prefixcmp(refname, "refs/heads/");
-               match |= tags_only && !prefixcmp(refname, "refs/tags/");
+               match = heads_only && starts_with(refname, "refs/heads/");
+               match |= tags_only && starts_with(refname, "refs/tags/");
                if (!match)
                        return 0;
        }
@@ -210,7 +210,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
                while (*pattern) {
                        unsigned char sha1[20];
 
-                       if (!prefixcmp(*pattern, "refs/") &&
+                       if (starts_with(*pattern, "refs/") &&
                            !read_ref(*pattern, sha1)) {
                                if (!quiet)
                                        show_one(*pattern, sha1);
index 71286b4fae4792dce73ab1533204e803e2a61334..b6a711d3191a729e5f07aae20e3fc5343148c9b2 100644 (file)
@@ -65,7 +65,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
                break;
        case 2:
                if (!strcmp(argv[0], "HEAD") &&
-                   prefixcmp(argv[1], "refs/"))
+                   !starts_with(argv[1], "refs/"))
                        die("Refusing to point HEAD outside of refs/");
                create_symref(argv[0], argv[1], msg);
                break;
index ea55f1d1bdd524abd46e6baa7a02ef85d56d5eb2..74d3780b77548fc8a7bb2f51b47a51cbfb51969a 100644 (file)
@@ -259,7 +259,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
        int status = git_gpg_config(var, value, cb);
        if (status)
                return status;
-       if (!prefixcmp(var, "column."))
+       if (starts_with(var, "column."))
                return git_column_config(var, value, "tag", &colopts);
        return git_default_config(var, value, cb);
 }
diff --git a/builtin/tar-tree.c b/builtin/tar-tree.c
deleted file mode 100644 (file)
index ba3ffe6..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (c) 2005, 2006 Rene Scharfe
- */
-#include "cache.h"
-#include "commit.h"
-#include "tar.h"
-#include "builtin.h"
-#include "quote.h"
-
-static const char tar_tree_usage[] =
-"git tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
-"*** Note that this command is now deprecated; use \"git archive\" instead.";
-
-static const char builtin_get_tar_commit_id_usage[] =
-"git get-tar-commit-id < <tarfile>";
-
-int cmd_tar_tree(int argc, const char **argv, const char *prefix)
-{
-       /*
-        * "git tar-tree" is now a wrapper around "git archive --format=tar"
-        *
-        * $0 --remote=<repo> arg... ==>
-        *      git archive --format=tar --remote=<repo> arg...
-        * $0 tree-ish ==>
-        *      git archive --format=tar tree-ish
-        * $0 tree-ish basedir ==>
-        *      git archive --format-tar --prefix=basedir tree-ish
-        */
-       const char **nargv = xcalloc(sizeof(*nargv), argc + 3);
-       struct strbuf sb = STRBUF_INIT;
-       char *basedir_arg;
-       int nargc = 0;
-
-       nargv[nargc++] = "archive";
-       nargv[nargc++] = "--format=tar";
-
-       if (2 <= argc && !prefixcmp(argv[1], "--remote=")) {
-               nargv[nargc++] = argv[1];
-               argv++;
-               argc--;
-       }
-
-       /*
-        * Because it's just a compatibility wrapper, tar-tree supports only
-        * the old behaviour of reading attributes from the work tree.
-        */
-       nargv[nargc++] = "--worktree-attributes";
-
-       switch (argc) {
-       default:
-               usage(tar_tree_usage);
-               break;
-       case 3:
-               /* base-path */
-               basedir_arg = xmalloc(strlen(argv[2]) + 11);
-               sprintf(basedir_arg, "--prefix=%s/", argv[2]);
-               nargv[nargc++] = basedir_arg;
-               /* fallthru */
-       case 2:
-               /* tree-ish */
-               nargv[nargc++] = argv[1];
-       }
-       nargv[nargc] = NULL;
-
-       fprintf(stderr,
-               "*** \"git tar-tree\" is now deprecated.\n"
-               "*** Running \"git archive\" instead.\n***");
-       sq_quote_argv(&sb, nargv, 0);
-       strbuf_addch(&sb, '\n');
-       fputs(sb.buf, stderr);
-       strbuf_release(&sb);
-       return cmd_archive(nargc, nargv, prefix);
-}
-
-/* ustar header + extended global header content */
-#define RECORDSIZE     (512)
-#define HEADERSIZE (2 * RECORDSIZE)
-
-int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
-{
-       char buffer[HEADERSIZE];
-       struct ustar_header *header = (struct ustar_header *)buffer;
-       char *content = buffer + RECORDSIZE;
-       ssize_t n;
-
-       if (argc != 1)
-               usage(builtin_get_tar_commit_id_usage);
-
-       n = read_in_full(0, buffer, HEADERSIZE);
-       if (n < HEADERSIZE)
-               die("git get-tar-commit-id: read error");
-       if (header->typeflag[0] != 'g')
-               return 1;
-       if (memcmp(content, "52 comment=", 11))
-               return 1;
-
-       n = write_in_full(1, content + 11, 41);
-       if (n < 41)
-               die_errno("git get-tar-commit-id: write error");
-
-       return 0;
-}
index 2217d7b3ae57235fc25ac3f5bf8429588aa034c4..62ff673f68b48cc2147fc7f7b17dc5269da022bf 100644 (file)
@@ -523,7 +523,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
                                strict = 1;
                                continue;
                        }
-                       if (!prefixcmp(arg, "--pack_header=")) {
+                       if (starts_with(arg, "--pack_header=")) {
                                struct pack_header *hdr;
                                char *c;
 
index 702e90db2a82a0eba2ff233b9ec46690da5afc3e..1292cfea11d87e8c98ba64ffae9d6a1aeffaca9f 100644 (file)
@@ -229,15 +229,15 @@ static void update_refs_stdin(void)
                        die("empty command in input");
                else if (isspace(*cmd.buf))
                        die("whitespace before command: %s", cmd.buf);
-               else if (!prefixcmp(cmd.buf, "update "))
+               else if (starts_with(cmd.buf, "update "))
                        parse_cmd_update(cmd.buf + 7);
-               else if (!prefixcmp(cmd.buf, "create "))
+               else if (starts_with(cmd.buf, "create "))
                        parse_cmd_create(cmd.buf + 7);
-               else if (!prefixcmp(cmd.buf, "delete "))
+               else if (starts_with(cmd.buf, "delete "))
                        parse_cmd_delete(cmd.buf + 7);
-               else if (!prefixcmp(cmd.buf, "verify "))
+               else if (starts_with(cmd.buf, "verify "))
                        parse_cmd_verify(cmd.buf + 7);
-               else if (!prefixcmp(cmd.buf, "option "))
+               else if (starts_with(cmd.buf, "option "))
                        parse_cmd_option(cmd.buf + 7);
                else
                        die("unknown command: %s", cmd.buf);
index af2da35e7d05f4de2d7a77a708ee3cf6f490266e..32ab94cd06b43cd05316f9a16981adc883c0d066 100644 (file)
@@ -37,7 +37,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
                if (sent_argv.argc > MAX_ARGS)
                        die("Too many options (>%d)", MAX_ARGS - 1);
 
-               if (prefixcmp(buf, arg_cmd))
+               if (!starts_with(buf, arg_cmd))
                        die("'argument' token or flush expected");
                argv_array_push(&sent_argv, buf + strlen(arg_cmd));
        }
index 3d6431137336f9748247dfad625555d0a546b26b..e99065ce425ad6e816d946626ef83075ab70bf85 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -7,6 +7,7 @@
 #include "list-objects.h"
 #include "run-command.h"
 #include "refs.h"
+#include "argv-array.h"
 
 static const char bundle_signature[] = "# v2 git bundle\n";
 
@@ -234,13 +235,13 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
 }
 
 int create_bundle(struct bundle_header *header, const char *path,
-               int argc, const char **argv)
+                 int argc, const char **argv)
 {
        static struct lock_file lock;
        int bundle_fd = -1;
        int bundle_to_stdout;
-       const char **argv_boundary = xmalloc((argc + 4) * sizeof(const char *));
-       const char **argv_pack = xmalloc(6 * sizeof(const char *));
+       struct argv_array argv_boundary = ARGV_ARRAY_INIT;
+       struct argv_array argv_pack = ARGV_ARRAY_INIT;
        int i, ref_count = 0;
        struct strbuf buf = STRBUF_INIT;
        struct rev_info revs;
@@ -262,13 +263,14 @@ int create_bundle(struct bundle_header *header, const char *path,
        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;
+       argv_array_pushl(&argv_boundary,
+                        "rev-list", "--boundary", "--pretty=oneline",
+                        NULL);
+       for (i = 1; i < argc; i++)
+               argv_array_push(&argv_boundary, argv[i]);
+
        memset(&rls, 0, sizeof(rls));
-       rls.argv = argv_boundary;
+       rls.argv = argv_boundary.argv;
        rls.out = -1;
        rls.git_cmd = 1;
        if (start_command(&rls))
@@ -383,14 +385,12 @@ int create_bundle(struct bundle_header *header, const char *path,
        write_or_die(bundle_fd, "\n", 1);
 
        /* write pack */
-       argv_pack[0] = "pack-objects";
-       argv_pack[1] = "--all-progress-implied";
-       argv_pack[2] = "--stdout";
-       argv_pack[3] = "--thin";
-       argv_pack[4] = "--delta-base-offset";
-       argv_pack[5] = NULL;
+       argv_array_pushl(&argv_pack,
+                        "pack-objects", "--all-progress-implied",
+                        "--stdout", "--thin", "--delta-base-offset",
+                        NULL);
        memset(&rls, 0, sizeof(rls));
-       rls.argv = argv_pack;
+       rls.argv = argv_pack.argv;
        rls.in = -1;
        rls.out = bundle_fd;
        rls.git_cmd = 1;
index 08b04e2c66429a05f6fc5ac1f5b2aa94160a5c37..cf36c3d71e3b8fc3382162ef939f3ed1f7d20775 100644 (file)
@@ -64,7 +64,6 @@ git-init                                mainporcelain common
 git-instaweb                            ancillaryinterrogators
 gitk                                    mainporcelain
 git-log                                 mainporcelain common
-git-lost-found                          ancillarymanipulators  deprecated
 git-ls-files                            plumbinginterrogators
 git-ls-remote                           plumbinginterrogators
 git-ls-tree                             plumbinginterrogators
@@ -88,7 +87,6 @@ git-pack-redundant                      plumbinginterrogators
 git-pack-refs                           ancillarymanipulators
 git-parse-remote                        synchelpers
 git-patch-id                            purehelpers
-git-peek-remote                         purehelpers    deprecated
 git-prune                               ancillarymanipulators
 git-prune-packed                        plumbingmanipulators
 git-pull                                mainporcelain common
@@ -102,7 +100,6 @@ git-relink                              ancillarymanipulators
 git-remote                              ancillarymanipulators
 git-repack                              ancillarymanipulators
 git-replace                             ancillarymanipulators
-git-repo-config                         ancillarymanipulators  deprecated
 git-request-pull                        foreignscminterface
 git-rerere                              ancillaryinterrogators
 git-reset                               mainporcelain common
@@ -127,7 +124,6 @@ git-submodule                           mainporcelain
 git-svn                                 foreignscminterface
 git-symbolic-ref                        plumbingmanipulators
 git-tag                                 mainporcelain common
-git-tar-tree                            plumbinginterrogators  deprecated
 git-unpack-file                         plumbinginterrogators
 git-unpack-objects                      plumbingmanipulators
 git-update-index                        plumbingmanipulators
index d4c8286470c1adef499ca30e9f57c7fe4b2be2da..cc114b53b096c6fc8574629b86659a639fdfed61 100644 (file)
  *
  *   Initializes the indegree slab that associates an array of integers
  *   to each commit. 'stride' specifies how big each array is.  The slab
- *   that id initialied by the variant without "_with_stride" associates
+ *   that is initialized by the variant without "_with_stride" associates
  *   each commit with an array of one integer.
+ *
+ * - void clear_indegree(struct indegree *);
+ *
+ *   Empties the slab.  The slab can be reused with the same stride
+ *   without calling init_indegree() again or can be reconfigured to a
+ *   different stride by calling init_indegree_with_stride().
+ *
+ *   Call this function before the slab falls out of scope to avoid
+ *   leaking memory.
  */
 
 /* allocate ~512kB at once, allowing for malloc overhead */
@@ -31,6 +40,8 @@
 #define COMMIT_SLAB_SIZE (512*1024-32)
 #endif
 
+#define MAYBE_UNUSED __attribute__((__unused__))
+
 #define define_commit_slab(slabname, elemtype)                                 \
                                                                        \
 struct slabname {                                                      \
@@ -41,8 +52,8 @@ struct slabname {                                                     \
 };                                                                     \
 static int stat_ ##slabname## realloc;                                 \
                                                                        \
-static void init_ ##slabname## _with_stride(struct slabname *s,                \
-                                           unsigned stride)            \
+static MAYBE_UNUSED void init_ ##slabname## _with_stride(struct slabname *s, \
+                                                  unsigned stride)     \
 {                                                                      \
        unsigned int elem_size;                                         \
        if (!stride)                                                    \
@@ -54,12 +65,12 @@ static void init_ ##slabname## _with_stride(struct slabname *s,             \
        s->slab = NULL;                                                 \
 }                                                                      \
                                                                        \
-static void init_ ##slabname(struct slabname *s)                       \
+static MAYBE_UNUSED void init_ ##slabname(struct slabname *s)          \
 {                                                                      \
        init_ ##slabname## _with_stride(s, 1);                          \
 }                                                                      \
                                                                        \
-static void clear_ ##slabname(struct slabname *s)                      \
+static MAYBE_UNUSED void clear_ ##slabname(struct slabname *s)         \
 {                                                                      \
        int i;                                                          \
        for (i = 0; i < s->slab_count; i++)                             \
@@ -69,8 +80,8 @@ static void clear_ ##slabname(struct slabname *s)                     \
        s->slab = NULL;                                                 \
 }                                                                      \
                                                                        \
-static elemtype *slabname## _at(struct slabname *s,                    \
-                               const struct commit *c)                 \
+static MAYBE_UNUSED elemtype *slabname## _at(struct slabname *s,       \
+                                      const struct commit *c)          \
 {                                                                      \
        int nth_slab, nth_slot;                                         \
                                                                        \
@@ -80,7 +91,7 @@ static elemtype *slabname## _at(struct slabname *s,                   \
        if (s->slab_count <= nth_slab) {                                \
                int i;                                                  \
                s->slab = xrealloc(s->slab,                             \
-                                  (nth_slab + 1) * sizeof(s->slab));   \
+                                  (nth_slab + 1) * sizeof(*s->slab));  \
                stat_ ##slabname## realloc++;                           \
                for (i = s->slab_count; i <= nth_slab; i++)             \
                        s->slab[i] = NULL;                              \
@@ -94,4 +105,16 @@ static elemtype *slabname## _at(struct slabname *s,                 \
                                                                        \
 static int stat_ ##slabname## realloc
 
+/*
+ * Note that this seemingly redundant second declaration is required
+ * to allow a terminating semicolon, which makes instantiations look
+ * like function declarations.  I.e., the expansion of
+ *
+ *    define_commit_slab(indegree, int);
+ *
+ * ends in 'static int stat_indegreerealloc;'.  This would otherwise
+ * be a syntax error according (at least) to ISO C.  It's hard to
+ * catch because GCC silently parses it by default.
+ */
+
 #endif /* COMMIT_SLAB_H */
index 11509ffc471c548a1367068b3d7c2f15d19361f4..5df1df73512ebb90f558ce6f2f7e899e75f03ff8 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -566,7 +566,7 @@ static void record_author_date(struct author_date_slab *author_date,
             buf;
             buf = line_end + 1) {
                line_end = strchrnul(buf, '\n');
-               if (prefixcmp(buf, "author ")) {
+               if (!starts_with(buf, "author ")) {
                        if (!line_end[0] || line_end[1] == '\n')
                                return; /* end of header */
                        continue;
@@ -1113,7 +1113,7 @@ int parse_signed_commit(const unsigned char *sha1,
                next = next ? next + 1 : tail;
                if (in_signature && line[0] == ' ')
                        sig = line + 1;
-               else if (!prefixcmp(line, gpg_sig_header) &&
+               else if (starts_with(line, gpg_sig_header) &&
                         line[gpg_sig_header_len] == ' ')
                        sig = line + gpg_sig_header_len + 1;
                if (sig) {
@@ -1193,7 +1193,7 @@ static void parse_gpg_output(struct signature_check *sigc)
        for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
                const char *found, *next;
 
-               if (!prefixcmp(buf, sigcheck_gpg_status[i].check + 1)) {
+               if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
                        /* At the very beginning of the buffer */
                        found = buf + strlen(sigcheck_gpg_status[i].check + 1);
                } else {
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index e1d66a145b756c49c4e4902200c354499532a428..d969a5aefc2bca92938d3fd7f6a507e884ce2b7f 100644 (file)
--- a/config.c
+++ b/config.c
@@ -969,25 +969,25 @@ static int git_default_mailmap_config(const char *var, const char *value)
 
 int git_default_config(const char *var, const char *value, void *dummy)
 {
-       if (!prefixcmp(var, "core."))
+       if (starts_with(var, "core."))
                return git_default_core_config(var, value);
 
-       if (!prefixcmp(var, "user."))
+       if (starts_with(var, "user."))
                return git_ident_config(var, value, dummy);
 
-       if (!prefixcmp(var, "i18n."))
+       if (starts_with(var, "i18n."))
                return git_default_i18n_config(var, value);
 
-       if (!prefixcmp(var, "branch."))
+       if (starts_with(var, "branch."))
                return git_default_branch_config(var, value);
 
-       if (!prefixcmp(var, "push."))
+       if (starts_with(var, "push."))
                return git_default_push_config(var, value);
 
-       if (!prefixcmp(var, "mailmap."))
+       if (starts_with(var, "mailmap."))
                return git_default_mailmap_config(var, value);
 
-       if (!prefixcmp(var, "advice."))
+       if (starts_with(var, "advice."))
                return git_default_advice_config(var, value);
 
        if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
@@ -1210,15 +1210,14 @@ int git_config(config_fn_t fn, void *data)
  * Find all the stuff for git_config_set() below.
  */
 
-#define MAX_MATCHES 512
-
 static struct {
        int baselen;
        char *key;
        int do_not_match;
        regex_t *value_regex;
        int multi_replace;
-       size_t offset[MAX_MATCHES];
+       size_t *offset;
+       unsigned int offset_alloc;
        enum { START, SECTION_SEEN, SECTION_END_SEEN, KEY_SEEN } state;
        int seen;
 } store;
@@ -1241,11 +1240,11 @@ static int store_aux(const char *key, const char *value, void *cb)
                if (matches(key, value)) {
                        if (store.seen == 1 && store.multi_replace == 0) {
                                warning("%s has multiple values", key);
-                       } else if (store.seen >= MAX_MATCHES) {
-                               error("too many matches for %s", key);
-                               return 1;
                        }
 
+                       ALLOC_GROW(store.offset, store.seen + 1,
+                                  store.offset_alloc);
+
                        store.offset[store.seen] = cf->do_ftell(cf);
                        store.seen++;
                }
@@ -1273,11 +1272,15 @@ static int store_aux(const char *key, const char *value, void *cb)
                 * Do not increment matches: this is no match, but we
                 * just made sure we are in the desired section.
                 */
+               ALLOC_GROW(store.offset, store.seen + 1,
+                          store.offset_alloc);
                store.offset[store.seen] = cf->do_ftell(cf);
                /* fallthru */
        case SECTION_END_SEEN:
        case START:
                if (matches(key, value)) {
+                       ALLOC_GROW(store.offset, store.seen + 1,
+                                  store.offset_alloc);
                        store.offset[store.seen] = cf->do_ftell(cf);
                        store.state = KEY_SEEN;
                        store.seen++;
@@ -1285,6 +1288,9 @@ static int store_aux(const char *key, const char *value, void *cb)
                        if (strrchr(key, '.') - key == store.baselen &&
                              !strncmp(key, store.key, store.baselen)) {
                                        store.state = SECTION_SEEN;
+                                       ALLOC_GROW(store.offset,
+                                                  store.seen + 1,
+                                                  store.offset_alloc);
                                        store.offset[store.seen] = cf->do_ftell(cf);
                        }
                }
@@ -1583,6 +1589,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
                        }
                }
 
+               ALLOC_GROW(store.offset, 1, store.offset_alloc);
                store.offset[0] = 0;
                store.state = START;
                store.seen = 0;
@@ -1872,7 +1879,7 @@ int parse_config_key(const char *var,
        const char *dot;
 
        /* Does it start with "section." ? */
-       if (prefixcmp(var, section) || var[section_len] != '.')
+       if (!starts_with(var, section) || var[section_len] != '.')
                return -1;
 
        /*
index 06e88b0705f7fbd138e504920c20c70218121696..c763eeda863d62093a9f37d281e8b1afc1a1e254 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -145,7 +145,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
                if (!len)
                        break;
 
-               if (len > 4 && !prefixcmp(buffer, "ERR "))
+               if (len > 4 && starts_with(buffer, "ERR "))
                        die("remote error: %s", buffer + 4);
 
                if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
@@ -232,10 +232,34 @@ int server_supports(const char *feature)
 
 enum protocol {
        PROTO_LOCAL = 1,
+       PROTO_FILE,
        PROTO_SSH,
        PROTO_GIT
 };
 
+int url_is_local_not_ssh(const char *url)
+{
+       const char *colon = strchr(url, ':');
+       const char *slash = strchr(url, '/');
+       return !colon || (slash && slash < colon) ||
+               has_dos_drive_prefix(url);
+}
+
+static const char *prot_name(enum protocol protocol)
+{
+       switch (protocol) {
+               case PROTO_LOCAL:
+               case PROTO_FILE:
+                       return "file";
+               case PROTO_SSH:
+                       return "ssh";
+               case PROTO_GIT:
+                       return "git";
+               default:
+                       return "unkown protocol";
+       }
+}
+
 static enum protocol get_protocol(const char *name)
 {
        if (!strcmp(name, "ssh"))
@@ -247,7 +271,7 @@ static enum protocol get_protocol(const char *name)
        if (!strcmp(name, "ssh+git"))
                return PROTO_SSH;
        if (!strcmp(name, "file"))
-               return PROTO_LOCAL;
+               return PROTO_FILE;
        die("I don't handle protocol '%s'", name);
 }
 
@@ -527,55 +551,31 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
        return proxy;
 }
 
-#define MAX_CMD_LEN 1024
-
-static char *get_port(char *host)
+static const char *get_port_numeric(const char *p)
 {
        char *end;
-       char *p = strchr(host, ':');
-
        if (p) {
                long port = strtol(p + 1, &end, 10);
                if (end != p + 1 && *end == '\0' && 0 <= port && port < 65536) {
-                       *p = '\0';
-                       return p+1;
+                       return p;
                }
        }
 
        return NULL;
 }
 
-static struct child_process no_fork;
-
 /*
- * This returns a dummy child_process if the transport protocol does not
- * need fork(2), or a struct child_process object if it does.  Once done,
- * finish the connection with finish_connect() with the value returned from
- * this function (it is safe to call finish_connect() with NULL to support
- * the former case).
- *
- * If it returns, the connect is successful; it just dies on errors (this
- * will hopefully be changed in a libification effort, to return NULL when
- * the connection failed).
+ * Extract protocol and relevant parts from the specified connection URL.
+ * The caller must free() the returned strings.
  */
-struct child_process *git_connect(int fd[2], const char *url_orig,
-                                 const char *prog, int flags)
+static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
+                                      char **ret_path)
 {
        char *url;
        char *host, *path;
        char *end;
-       int c;
-       struct child_process *conn = &no_fork;
+       int separator = '/';
        enum protocol protocol = PROTO_LOCAL;
-       int free_path = 0;
-       char *port = NULL;
-       const char **arg;
-       struct strbuf cmd;
-
-       /* Without this we cannot rely on waitpid() to tell
-        * what happened to our children.
-        */
-       signal(SIGCHLD, SIG_DFL);
 
        if (is_url(url_orig))
                url = url_decode(url_orig);
@@ -587,40 +587,33 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
                *host = '\0';
                protocol = get_protocol(url);
                host += 3;
-               c = '/';
        } else {
                host = url;
-               c = ':';
+               if (!url_is_local_not_ssh(url)) {
+                       protocol = PROTO_SSH;
+                       separator = ':';
+               }
        }
 
        /*
-        * Don't do destructive transforms with git:// as that
-        * protocol code does '[]' unwrapping of its own.
+        * Don't do destructive transforms as protocol code does
+        * '[]' unwrapping in get_host_and_port()
         */
        if (host[0] == '[') {
                end = strchr(host + 1, ']');
                if (end) {
-                       if (protocol != PROTO_GIT) {
-                               *end = 0;
-                               host++;
-                       }
                        end++;
                } else
                        end = host;
        } else
                end = host;
 
-       path = strchr(end, c);
-       if (path && !has_dos_drive_prefix(end)) {
-               if (c == ':') {
-                       if (host != url || path < strchrnul(host, '/')) {
-                               protocol = PROTO_SSH;
-                               *path++ = '\0';
-                       } else /* '/' in the host part, assume local path */
-                               path = end;
-               }
-       } else
+       if (protocol == PROTO_LOCAL)
                path = end;
+       else if (protocol == PROTO_FILE && has_dos_drive_prefix(end))
+               path = end; /* "file://$(pwd)" may be "file://C:/projects/repo" */
+       else
+               path = strchr(end, separator);
 
        if (!path || !*path)
                die("No path specified. See 'man git-pull' for valid url syntax");
@@ -629,33 +622,67 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
         * null-terminate hostname and point path to ~ for URL's like this:
         *    ssh://host.xz/~user/repo
         */
-       if (protocol != PROTO_LOCAL && host != url) {
-               char *ptr = path;
+
+       end = path; /* Need to \0 terminate host here */
+       if (separator == ':')
+               path++; /* path starts after ':' */
+       if (protocol == PROTO_GIT || protocol == PROTO_SSH) {
                if (path[1] == '~')
                        path++;
-               else {
-                       path = xstrdup(ptr);
-                       free_path = 1;
-               }
-
-               *ptr = '\0';
        }
 
-       /*
-        * Add support for ssh port: ssh://host.xy:<port>/...
+       path = xstrdup(path);
+       *end = '\0';
+
+       *ret_host = xstrdup(host);
+       *ret_path = path;
+       free(url);
+       return protocol;
+}
+
+static struct child_process no_fork;
+
+/*
+ * This returns a dummy child_process if the transport protocol does not
+ * need fork(2), or a struct child_process object if it does.  Once done,
+ * finish the connection with finish_connect() with the value returned from
+ * this function (it is safe to call finish_connect() with NULL to support
+ * the former case).
+ *
+ * If it returns, the connect is successful; it just dies on errors (this
+ * will hopefully be changed in a libification effort, to return NULL when
+ * the connection failed).
+ */
+struct child_process *git_connect(int fd[2], const char *url,
+                                 const char *prog, int flags)
+{
+       char *hostandport, *path;
+       struct child_process *conn = &no_fork;
+       enum protocol protocol;
+       const char **arg;
+       struct strbuf cmd = STRBUF_INIT;
+
+       /* Without this we cannot rely on waitpid() to tell
+        * what happened to our children.
         */
-       if (protocol == PROTO_SSH && host != url)
-               port = get_port(end);
+       signal(SIGCHLD, SIG_DFL);
 
-       if (protocol == PROTO_GIT) {
+       protocol = parse_connect_url(url, &hostandport, &path);
+       if (flags & CONNECT_DIAG_URL) {
+               printf("Diag: url=%s\n", url ? url : "NULL");
+               printf("Diag: protocol=%s\n", prot_name(protocol));
+               printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
+               printf("Diag: path=%s\n", path ? path : "NULL");
+               conn = NULL;
+       } else if (protocol == PROTO_GIT) {
                /* These underlying connection commands die() if they
                 * cannot connect.
                 */
-               char *target_host = xstrdup(host);
-               if (git_use_proxy(host))
-                       conn = git_proxy_connect(fd, host);
+               char *target_host = xstrdup(hostandport);
+               if (git_use_proxy(hostandport))
+                       conn = git_proxy_connect(fd, hostandport);
                else
-                       git_tcp_connect(fd, host, flags);
+                       git_tcp_connect(fd, hostandport, flags);
                /*
                 * Separate original protocol components prog and path
                 * from extended host header with a NUL byte.
@@ -668,55 +695,51 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
                             prog, path, 0,
                             target_host, 0);
                free(target_host);
-               free(url);
-               if (free_path)
-                       free(path);
-               return conn;
-       }
-
-       conn = xcalloc(1, sizeof(*conn));
-
-       strbuf_init(&cmd, MAX_CMD_LEN);
-       strbuf_addstr(&cmd, prog);
-       strbuf_addch(&cmd, ' ');
-       sq_quote_buf(&cmd, path);
-       if (cmd.len >= MAX_CMD_LEN)
-               die("command line too long");
-
-       conn->in = conn->out = -1;
-       conn->argv = arg = xcalloc(7, sizeof(*arg));
-       if (protocol == PROTO_SSH) {
-               const char *ssh = getenv("GIT_SSH");
-               int putty = ssh && strcasestr(ssh, "plink");
-               if (!ssh) ssh = "ssh";
-
-               *arg++ = ssh;
-               if (putty && !strcasestr(ssh, "tortoiseplink"))
-                       *arg++ = "-batch";
-               if (port) {
-                       /* P is for PuTTY, p is for OpenSSH */
-                       *arg++ = putty ? "-P" : "-p";
-                       *arg++ = port;
+       } else {
+               conn = xcalloc(1, sizeof(*conn));
+
+               strbuf_addstr(&cmd, prog);
+               strbuf_addch(&cmd, ' ');
+               sq_quote_buf(&cmd, path);
+
+               conn->in = conn->out = -1;
+               conn->argv = arg = xcalloc(7, sizeof(*arg));
+               if (protocol == PROTO_SSH) {
+                       const char *ssh = getenv("GIT_SSH");
+                       int putty = ssh && strcasestr(ssh, "plink");
+                       char *ssh_host = hostandport;
+                       const char *port = NULL;
+                       get_host_and_port(&ssh_host, &port);
+                       port = get_port_numeric(port);
+
+                       if (!ssh) ssh = "ssh";
+
+                       *arg++ = ssh;
+                       if (putty && !strcasestr(ssh, "tortoiseplink"))
+                               *arg++ = "-batch";
+                       if (port) {
+                               /* P is for PuTTY, p is for OpenSSH */
+                               *arg++ = putty ? "-P" : "-p";
+                               *arg++ = port;
+                       }
+                       *arg++ = ssh_host;
+               }       else {
+                       /* remove repo-local variables from the environment */
+                       conn->env = local_repo_env;
+                       conn->use_shell = 1;
                }
-               *arg++ = host;
-       }
-       else {
-               /* remove repo-local variables from the environment */
-               conn->env = local_repo_env;
-               conn->use_shell = 1;
-       }
-       *arg++ = cmd.buf;
-       *arg = NULL;
+               *arg++ = cmd.buf;
+               *arg = NULL;
 
-       if (start_command(conn))
-               die("unable to fork");
+               if (start_command(conn))
+                       die("unable to fork");
 
-       fd[0] = conn->out; /* read from child's stdout */
-       fd[1] = conn->in;  /* write to child's stdin */
-       strbuf_release(&cmd);
-       free(url);
-       if (free_path)
-               free(path);
+               fd[0] = conn->out; /* read from child's stdout */
+               fd[1] = conn->in;  /* write to child's stdin */
+               strbuf_release(&cmd);
+       }
+       free(hostandport);
+       free(path);
        return conn;
 }
 
index 64fb7dbbee8714c034c5e018b3b1b4f8c29f0ea7..c41a6850f1302e4d27af1066b53b20dd303f0d13 100644 (file)
--- a/connect.h
+++ b/connect.h
@@ -2,11 +2,13 @@
 #define CONNECT_H
 
 #define CONNECT_VERBOSE       (1u << 0)
+#define CONNECT_DIAG_URL      (1u << 1)
 extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
 extern int finish_connect(struct child_process *conn);
 extern int git_connection_is_socket(struct child_process *conn);
 extern int server_supports(const char *feature);
 extern int parse_feature_request(const char *features, const char *feature);
 extern const char *server_feature_value(const char *feature, int *len_ret);
+extern int url_is_local_not_ssh(const char *url);
 
 #endif
index fae8d64c12e44cf6bcf4bab210abc4bc4b9c8ed9..51d8ba4bb7a5d04b7922a283e0ad0d904657c6b5 100644 (file)
@@ -38,7 +38,7 @@ int check_everything_connected_with_transport(sha1_iterate_fn fn,
        if (transport && transport->smart_options &&
            transport->smart_options->self_contained_and_connected &&
            transport->pack_lockfile &&
-           !suffixcmp(transport->pack_lockfile, ".keep")) {
+           ends_with(transport->pack_lockfile, ".keep")) {
                struct strbuf idx_file = STRBUF_INIT;
                strbuf_addstr(&idx_file, transport->pack_lockfile);
                strbuf_setlen(&idx_file, idx_file.len - 5); /* ".keep" */
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index dba3c15700fae1ae8a7a43fd7a6ad7a5b9cbd5dd..51c2dd4dec3b65dc6ab8f051580fc03ce3027d5b 100644 (file)
@@ -1,5 +1,3 @@
-#!bash
-#
 # bash/zsh completion support for core Git.
 #
 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
@@ -673,7 +671,6 @@ __git_list_porcelain_commands ()
                index-pack)       : plumbing;;
                init-db)          : deprecated;;
                local-fetch)      : plumbing;;
-               lost-found)       : infrequent;;
                ls-files)         : plumbing;;
                ls-remote)        : plumbing;;
                ls-tree)          : plumbing;;
@@ -687,14 +684,12 @@ __git_list_porcelain_commands ()
                pack-refs)        : plumbing;;
                parse-remote)     : plumbing;;
                patch-id)         : plumbing;;
-               peek-remote)      : plumbing;;
                prune)            : plumbing;;
                prune-packed)     : plumbing;;
                quiltimport)      : import;;
                read-tree)        : plumbing;;
                receive-pack)     : plumbing;;
                remote-*)         : transport;;
-               repo-config)      : deprecated;;
                rerere)           : plumbing;;
                rev-list)         : plumbing;;
                rev-parse)        : plumbing;;
@@ -707,7 +702,6 @@ __git_list_porcelain_commands ()
                ssh-*)            : transport;;
                stripspace)       : plumbing;;
                symbolic-ref)     : plumbing;;
-               tar-tree)         : deprecated;;
                unpack-file)      : plumbing;;
                unpack-objects)   : plumbing;;
                update-index)     : plumbing;;
index eaacaf0c3e5c63967163f863ec8cd37c01f3e996..6104a42a23c4f38848a34c5c212bd7b74de81ab4 100644 (file)
@@ -1,5 +1,3 @@
-#!tcsh
-#
 # tcsh completion support for core Git.
 #
 # Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>
index 1fb9feb34849f5030d0b9dc7f91ae65e22322786..2edbdc6d998806cbffb880e6d29d5f48b5905145 100755 (executable)
@@ -9,12 +9,12 @@ case "$0" in
 *whatchanged)
        count=
        test -z "$diff_tree_flags" &&
-               diff_tree_flags=$(git-repo-config --get whatchanged.difftree)
+               diff_tree_flags=$(git config --get whatchanged.difftree)
        diff_tree_default_flags='-c -M --abbrev' ;;
 *show)
        count=-n1
        test -z "$diff_tree_flags" &&
-               diff_tree_flags=$(git-repo-config --get show.difftree)
+               diff_tree_flags=$(git config --get show.difftree)
        diff_tree_default_flags='--cc --always' ;;
 esac
 test -z "$diff_tree_flags" &&
index 8ee410f8435c8794ca7f4fabd8ebdead439891c1..8747b84334f35fd378f51e6a9a433cfacc630960 100755 (executable)
@@ -22,7 +22,6 @@
 # For example, on debian the hook is stored in
 # /usr/share/git-core/contrib/hooks/post-receive-email:
 #
-#  chmod a+x post-receive-email
 #  cd /path/to/your/repository.git
 #  ln -sf /usr/share/git-core/contrib/hooks/post-receive-email hooks/post-receive
 #
old mode 100644 (file)
new mode 100755 (executable)
index 1f914c9..9d0c2d1
@@ -13,7 +13,6 @@
 # For example, if the hook is stored in
 # /usr/share/git-core/contrib/hooks/pre-auto-gc-battery:
 #
-# chmod a+x pre-auto-gc-battery
 # cd /path/to/your/repository.git
 # ln -sf /usr/share/git-core/contrib/hooks/pre-auto-gc-battery \
 #      hooks/pre-auto-gc
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index f206f9655b4c078c66cb885fd079c4a7b95f7949..a4b6f7a2cd4122adbb74a565b34270578b7b6aed 100644 (file)
@@ -18,9 +18,13 @@ SCRIPT_PERL+=git-mw.perl
 GIT_ROOT_DIR=../..
 HERE=contrib/mw-to-git/
 
+INSTALL = install
+
 SCRIPT_PERL_FULL=$(patsubst %,$(HERE)/%,$(SCRIPT_PERL))
 INSTLIBDIR=$(shell $(MAKE) -C $(GIT_ROOT_DIR)/perl \
                 -s --no-print-directory instlibdir)
+DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
+INSTLIBDIR_SQ = $(subst ','\'',$(INSTLIBDIR))
 
 all: build
 
@@ -30,7 +34,9 @@ test: all
 check: perlcritic test
 
 install_pm:
-       install $(GIT_MEDIAWIKI_PM) $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM)
+       $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(INSTLIBDIR_SQ)/Git'
+       $(INSTALL) -m 644 $(GIT_MEDIAWIKI_PM) \
+               '$(DESTDIR_SQ)$(INSTLIBDIR_SQ)/$(GIT_MEDIAWIKI_PM)'
 
 build:
        $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
@@ -43,7 +49,6 @@ install: install_pm
 clean:
        $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
                 clean-perl-script
-       rm $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM)
 
 perlcritic:
        perlcritic -5 $(SCRIPT_PERL)
diff --git a/contrib/p4import/README b/contrib/p4import/README
deleted file mode 100644 (file)
index b9892b6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Please see contrib/fast-import/git-p4 for a better Perforce importer.
diff --git a/contrib/p4import/git-p4import.py b/contrib/p4import/git-p4import.py
deleted file mode 100644 (file)
index 593d6a0..0000000
+++ /dev/null
@@ -1,365 +0,0 @@
-#!/usr/bin/env python
-#
-# This tool is copyright (c) 2006, Sean Estabrooks.
-# It is released under the Gnu Public License, version 2.
-#
-# Import Perforce branches into Git repositories.
-# Checking out the files is done by calling the standard p4
-# client which you must have properly configured yourself
-#
-
-import marshal
-import os
-import sys
-import time
-import getopt
-
-if sys.hexversion < 0x02020000:
-   # The behavior of the marshal module changed significantly in 2.2
-   sys.stderr.write("git-p4import.py: requires Python 2.2 or later.\n")
-   sys.exit(1)
-
-from signal import signal, \
-   SIGPIPE, SIGINT, SIG_DFL, \
-   default_int_handler
-
-signal(SIGPIPE, SIG_DFL)
-s = signal(SIGINT, SIG_DFL)
-if s != default_int_handler:
-   signal(SIGINT, s)
-
-def die(msg, *args):
-    for a in args:
-        msg = "%s %s" % (msg, a)
-    print "git-p4import fatal error:", msg
-    sys.exit(1)
-
-def usage():
-    print "USAGE: git-p4import [-q|-v]  [--authors=<file>]  [-t <timezone>]  [//p4repo/path <branch>]"
-    sys.exit(1)
-
-verbosity = 1
-logfile = "/dev/null"
-ignore_warnings = False
-stitch = 0
-tagall = True
-
-def report(level, msg, *args):
-    global verbosity
-    global logfile
-    for a in args:
-        msg = "%s %s" % (msg, a)
-    fd = open(logfile, "a")
-    fd.writelines(msg)
-    fd.close()
-    if level <= verbosity:
-        print msg
-
-class p4_command:
-    def __init__(self, _repopath):
-        try:
-            global logfile
-            self.userlist = {}
-            if _repopath[-1] == '/':
-                self.repopath = _repopath[:-1]
-            else:
-                self.repopath = _repopath
-            if self.repopath[-4:] != "/...":
-                self.repopath= "%s/..." % self.repopath
-            f=os.popen('p4 -V 2>>%s'%logfile, 'rb')
-            a = f.readlines()
-            if f.close():
-                raise
-        except:
-                die("Could not find the \"p4\" command")
-
-    def p4(self, cmd, *args):
-        global logfile
-        cmd = "%s %s" % (cmd, ' '.join(args))
-        report(2, "P4:", cmd)
-        f=os.popen('p4 -G %s 2>>%s' % (cmd,logfile), 'rb')
-        list = []
-        while 1:
-           try:
-                list.append(marshal.load(f))
-           except EOFError:
-                break
-        self.ret = f.close()
-        return list
-
-    def sync(self, id, force=False, trick=False, test=False):
-        if force:
-            ret = self.p4("sync -f %s@%s"%(self.repopath, id))[0]
-        elif trick:
-            ret = self.p4("sync -k %s@%s"%(self.repopath, id))[0]
-        elif test:
-            ret = self.p4("sync -n %s@%s"%(self.repopath, id))[0]
-        else:
-            ret = self.p4("sync    %s@%s"%(self.repopath, id))[0]
-        if ret['code'] == "error":
-             data = ret['data'].upper()
-             if data.find('VIEW') > 0:
-                 die("Perforce reports %s is not in client view"% self.repopath)
-             elif data.find('UP-TO-DATE') < 0:
-                 die("Could not sync files from perforce", self.repopath)
-
-    def changes(self, since=0):
-        try:
-            list = []
-            for rec in self.p4("changes %s@%s,#head" % (self.repopath, since+1)):
-                list.append(rec['change'])
-            list.reverse()
-            return list
-        except:
-            return []
-
-    def authors(self, filename):
-        f=open(filename)
-        for l in f.readlines():
-            self.userlist[l[:l.find('=')].rstrip()] = \
-                    (l[l.find('=')+1:l.find('<')].rstrip(),l[l.find('<')+1:l.find('>')])
-        f.close()
-        for f,e in self.userlist.items():
-                report(2, f, ":", e[0], "  <", e[1], ">")
-
-    def _get_user(self, id):
-        if not self.userlist.has_key(id):
-            try:
-                user = self.p4("users", id)[0]
-                self.userlist[id] = (user['FullName'], user['Email'])
-            except:
-                self.userlist[id] = (id, "")
-        return self.userlist[id]
-
-    def _format_date(self, ticks):
-        symbol='+'
-        name = time.tzname[0]
-        offset = time.timezone
-        if ticks[8]:
-            name = time.tzname[1]
-            offset = time.altzone
-        if offset < 0:
-            offset *= -1
-            symbol = '-'
-        localo = "%s%02d%02d %s" % (symbol, offset / 3600, offset % 3600, name)
-        tickso = time.strftime("%a %b %d %H:%M:%S %Y", ticks)
-        return "%s %s" % (tickso, localo)
-
-    def where(self):
-        try:
-            return self.p4("where %s" % self.repopath)[-1]['path']
-        except:
-            return ""
-
-    def describe(self, num):
-        desc = self.p4("describe -s", num)[0]
-        self.msg = desc['desc']
-        self.author, self.email = self._get_user(desc['user'])
-        self.date = self._format_date(time.localtime(long(desc['time'])))
-        return self
-
-class git_command:
-    def __init__(self):
-        try:
-            self.version = self.git("--version")[0][12:].rstrip()
-        except:
-            die("Could not find the \"git\" command")
-        try:
-            self.gitdir = self.get_single("rev-parse --git-dir")
-            report(2, "gdir:", self.gitdir)
-        except:
-            die("Not a git repository... did you forget to \"git init\" ?")
-        try:
-            self.cdup = self.get_single("rev-parse --show-cdup")
-            if self.cdup != "":
-                os.chdir(self.cdup)
-            self.topdir = os.getcwd()
-            report(2, "topdir:", self.topdir)
-        except:
-            die("Could not find top git directory")
-
-    def git(self, cmd):
-        global logfile
-        report(2, "GIT:", cmd)
-        f=os.popen('git %s 2>>%s' % (cmd,logfile), 'rb')
-        r=f.readlines()
-        self.ret = f.close()
-        return r
-
-    def get_single(self, cmd):
-        return self.git(cmd)[0].rstrip()
-
-    def current_branch(self):
-        try:
-            testit = self.git("rev-parse --verify HEAD")[0]
-            return self.git("symbolic-ref HEAD")[0][11:].rstrip()
-        except:
-            return None
-
-    def get_config(self, variable):
-        try:
-            return self.git("config --get %s" % variable)[0].rstrip()
-        except:
-            return None
-
-    def set_config(self, variable, value):
-        try:
-            self.git("config %s %s"%(variable, value) )
-        except:
-            die("Could not set %s to " % variable, value)
-
-    def make_tag(self, name, head):
-        self.git("tag -f %s %s"%(name,head))
-
-    def top_change(self, branch):
-        try:
-            a=self.get_single("name-rev --tags refs/heads/%s" % branch)
-            loc = a.find(' tags/') + 6
-            if a[loc:loc+3] != "p4/":
-                raise
-            return int(a[loc+3:][:-2])
-        except:
-            return 0
-
-    def update_index(self):
-        self.git("ls-files -m -d -o -z | git update-index --add --remove -z --stdin")
-
-    def checkout(self, branch):
-        self.git("checkout %s" % branch)
-
-    def repoint_head(self, branch):
-        self.git("symbolic-ref HEAD refs/heads/%s" % branch)
-
-    def remove_files(self):
-        self.git("ls-files | xargs rm")
-
-    def clean_directories(self):
-        self.git("clean -d")
-
-    def fresh_branch(self, branch):
-        report(1, "Creating new branch", branch)
-        self.git("ls-files | xargs rm")
-        os.remove(".git/index")
-        self.repoint_head(branch)
-        self.git("clean -d")
-
-    def basedir(self):
-        return self.topdir
-
-    def commit(self, author, email, date, msg, id):
-        self.update_index()
-        fd=open(".msg", "w")
-        fd.writelines(msg)
-        fd.close()
-        try:
-                current = self.get_single("rev-parse --verify HEAD")
-                head = "-p HEAD"
-        except:
-                current = ""
-                head = ""
-        tree = self.get_single("write-tree")
-        for r,l in [('DATE',date),('NAME',author),('EMAIL',email)]:
-            os.environ['GIT_AUTHOR_%s'%r] = l
-            os.environ['GIT_COMMITTER_%s'%r] = l
-        commit = self.get_single("commit-tree %s %s < .msg" % (tree,head))
-        os.remove(".msg")
-        self.make_tag("p4/%s"%id, commit)
-        self.git("update-ref HEAD %s %s" % (commit, current) )
-
-try:
-    opts, args = getopt.getopt(sys.argv[1:], "qhvt:",
-            ["authors=","help","stitch=","timezone=","log=","ignore","notags"])
-except getopt.GetoptError:
-    usage()
-
-for o, a in opts:
-    if o == "-q":
-        verbosity = 0
-    if o == "-v":
-        verbosity += 1
-    if o in ("--log"):
-        logfile = a
-    if o in ("--notags"):
-        tagall = False
-    if o in ("-h", "--help"):
-        usage()
-    if o in ("--ignore"):
-        ignore_warnings = True
-
-git = git_command()
-branch=git.current_branch()
-
-for o, a in opts:
-    if o in ("-t", "--timezone"):
-        git.set_config("perforce.timezone", a)
-    if o in ("--stitch"):
-        git.set_config("perforce.%s.path" % branch, a)
-        stitch = 1
-
-if len(args) == 2:
-    branch = args[1]
-    git.checkout(branch)
-    if branch == git.current_branch():
-        die("Branch %s already exists!" % branch)
-    report(1, "Setting perforce to ", args[0])
-    git.set_config("perforce.%s.path" % branch, args[0])
-elif len(args) != 0:
-    die("You must specify the perforce //depot/path and git branch")
-
-p4path = git.get_config("perforce.%s.path" % branch)
-if p4path == None:
-    die("Do not know Perforce //depot/path for git branch", branch)
-
-p4 = p4_command(p4path)
-
-for o, a in opts:
-    if o in ("-a", "--authors"):
-        p4.authors(a)
-
-localdir = git.basedir()
-if p4.where()[:len(localdir)] != localdir:
-    report(1, "**WARNING** Appears p4 client is misconfigured")
-    report(1, "   for sync from %s to %s" % (p4.repopath, localdir))
-    if ignore_warnings != True:
-        die("Reconfigure or use \"--ignore\" on command line")
-
-if stitch == 0:
-    top = git.top_change(branch)
-else:
-    top = 0
-changes = p4.changes(top)
-count = len(changes)
-if count == 0:
-    report(1, "Already up to date...")
-    sys.exit(0)
-
-ptz = git.get_config("perforce.timezone")
-if ptz:
-    report(1, "Setting timezone to", ptz)
-    os.environ['TZ'] = ptz
-    time.tzset()
-
-if stitch == 1:
-    git.remove_files()
-    git.clean_directories()
-    p4.sync(changes[0], force=True)
-elif top == 0 and branch != git.current_branch():
-    p4.sync(changes[0], test=True)
-    report(1, "Creating new initial commit");
-    git.fresh_branch(branch)
-    p4.sync(changes[0], force=True)
-else:
-    p4.sync(changes[0], trick=True)
-
-report(1, "processing %s changes from p4 (%s) to git (%s)" % (count, p4.repopath, branch))
-for id in changes:
-    report(1, "Importing changeset", id)
-    change = p4.describe(id)
-    p4.sync(id)
-    if tagall :
-            git.commit(change.author, change.email, change.date, change.msg, id)
-    else:
-            git.commit(change.author, change.email, change.date, change.msg, "import")
-    if stitch == 1:
-        git.clean_directories()
-        stitch = 0
diff --git a/contrib/p4import/git-p4import.txt b/contrib/p4import/git-p4import.txt
deleted file mode 100644 (file)
index 9967587..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-git-p4import(1)
-===============
-
-NAME
-----
-git-p4import - Import a Perforce repository into git
-
-
-SYNOPSIS
---------
-[verse]
-`git-p4import` [-q|-v] [--notags] [--authors <file>] [-t <timezone>]
-               <//p4repo/path> <branch>
-`git-p4import` --stitch <//p4repo/path>
-`git-p4import`
-
-
-DESCRIPTION
------------
-Import a Perforce repository into an existing git repository.  When
-a <//p4repo/path> and <branch> are specified a new branch with the
-given name will be created and the initial import will begin.
-
-Once the initial import is complete you can do an incremental import
-of new commits from the Perforce repository.  You do this by checking
-out the appropriate git branch and then running `git-p4import` without
-any options.
-
-The standard p4 client is used to communicate with the Perforce
-repository; it must be configured correctly in order for `git-p4import`
-to operate (see below).
-
-
-OPTIONS
--------
--q::
-       Do not display any progress information.
-
--v::
-        Give extra progress information.
-
-\--authors::
-       Specify an authors file containing a mapping of Perforce user
-       ids to full names and email addresses (see Notes below).
-
-\--notags::
-       Do not create a tag for each imported commit.
-
-\--stitch::
-       Import the contents of the given perforce branch into the
-       currently checked out git branch.
-
-\--log::
-       Store debugging information in the specified file.
-
--t::
-       Specify that the remote repository is in the specified timezone.
-       Timezone must be in the format "US/Pacific" or "Europe/London"
-       etc.  You only need to specify this once, it will be saved in
-       the git config file for the repository.
-
-<//p4repo/path>::
-       The Perforce path that will be imported into the specified branch.
-
-<branch>::
-       The new branch that will be created to hold the Perforce imports.
-
-
-P4 Client
----------
-You must make the `p4` client command available in your $PATH and
-configure it to communicate with the target Perforce repository.
-Typically this means you must set the "$P4PORT" and "$P4CLIENT"
-environment variables.
-
-You must also configure a `p4` client "view" which maps the Perforce
-branch into the top level of your git repository, for example:
-
-------------
-Client: myhost
-
-Root:   /home/sean/import
-
-Options:   noallwrite clobber nocompress unlocked modtime rmdir
-
-View:
-        //public/jam/... //myhost/jam/...
-------------
-
-With the above `p4` client setup, you could import the "jam"
-perforce branch into a branch named "jammy", like so:
-
-------------
-$ mkdir -p /home/sean/import/jam
-$ cd /home/sean/import/jam
-$ git init
-$ git p4import //public/jam jammy
-------------
-
-
-Multiple Branches
------------------
-Note that by creating multiple "views" you can use `git-p4import`
-to import additional branches into the same git repository.
-However, the `p4` client has a limitation in that it silently
-ignores all but the last "view" that maps into the same local
-directory.  So the following will *not* work:
-
-------------
-View:
-        //public/jam/... //myhost/jam/...
-        //public/other/... //myhost/jam/...
-        //public/guest/... //myhost/jam/...
-------------
-
-If you want more than one Perforce branch to be imported into the
-same directory you must employ a workaround.  A simple option is
-to adjust your `p4` client before each import to only include a
-single view.
-
-Another option is to create multiple symlinks locally which all
-point to the same directory in your git repository and then use
-one per "view" instead of listing the actual directory.
-
-
-Tags
-----
-A git tag of the form p4/xx is created for every change imported from
-the Perforce repository where xx is the Perforce changeset number.
-Therefore after the import you can use git to access any commit by its
-Perforce number, e.g. git show p4/327.
-
-The tag associated with the HEAD commit is also how `git-p4import`
-determines if there are new changes to incrementally import from the
-Perforce repository.
-
-If you import from a repository with many thousands of changes
-you will have an equal number of p4/xxxx git tags.  Git tags can
-be expensive in terms of disk space and repository operations.
-If you don't need to perform further incremental imports, you
-may delete the tags.
-
-
-Notes
------
-You can interrupt the import (e.g. ctrl-c) at any time and restart it
-without worry.
-
-Author information is automatically determined by querying the
-Perforce "users" table using the id associated with each change.
-However, if you want to manually supply these mappings you can do
-so with the "--authors" option.  It accepts a file containing a list
-of mappings with each line containing one mapping in the format:
-
-------------
-    perforce_id = Full Name <email@address.com>
-------------
-
-
-Author
-------
-Written by Sean Estabrooks <seanlkml@sympatico.ca>
-
-
-GIT
----
-Part of the gitlink:git[7] suite
index 054161ae21b0c884d314c984992a6c7aa8276a96..7e345320ada69f1cbb909130d406cf08ce9ae130 100755 (executable)
@@ -44,8 +44,8 @@ import StringIO
 import atexit, shutil, hashlib, urlparse, subprocess
 
 NAME_RE = re.compile('^([^<>]+)')
-AUTHOR_RE = re.compile('^([^<>]+?)? ?<([^<>]*)>$')
-EMAIL_RE = re.compile('^([^<>]+[^ \\\t<>])?\\b(?:[ \\t<>]*?)\\b([^ \\t<>]+@[^ \\t<>]+)')
+AUTHOR_RE = re.compile('^([^<>]+?)? ?[<>]([^<>]*)(?:$|>)')
+EMAIL_RE = re.compile(r'([^ \t<>]+@[^ \t<>]+)')
 RAW_AUTHOR_RE = re.compile('^(\w+) (.+)? <(.*)> (\d+) ([+-]\d+)')
 
 def die(msg, *args):
@@ -193,8 +193,7 @@ def fixup_user(user):
     else:
         m = EMAIL_RE.match(user)
         if m:
-            name = m.group(1)
-            mail = m.group(2)
+            mail = m.group(1)
         else:
             m = NAME_RE.match(user)
             if m:
index c6026b9bed37a91e30a278a02013072d21507061..30402d55323488f7c2bc6599bbc4a471f2120b33 100755 (executable)
@@ -51,8 +51,8 @@ import time as ptime
 #
 
 NAME_RE = re.compile('^([^<>]+)')
-AUTHOR_RE = re.compile('^([^<>]+?)? ?<([^<>]*)>$')
-EMAIL_RE = re.compile('^([^<>]+[^ \\\t<>])?\\b(?:[ \\t<>]*?)\\b([^ \\t<>]+@[^ \\t<>]+)')
+AUTHOR_RE = re.compile('^([^<>]+?)? ?[<>]([^<>]*)(?:$|>)')
+EMAIL_RE = re.compile(r'([^ \t<>]+@[^ \t<>]+)')
 AUTHOR_HG_RE = re.compile('^(.*?) ?<(.*?)(?:>(.+)?)?$')
 RAW_AUTHOR_RE = re.compile('^(\w+) (?:(.+)? )?<(.*)> (\d+) ([+-]\d+)')
 
@@ -316,8 +316,7 @@ def fixup_user_git(user):
     else:
         m = EMAIL_RE.match(user)
         if m:
-            name = m.group(1)
-            mail = m.group(2)
+            mail = m.group(1)
         else:
             m = NAME_RE.match(user)
             if m:
index 5c5025178370813aabec64c8bfbd7ac59c6186a5..1e53ff9a584a302366dcbd647a2e27db3fd1b9fe 100755 (executable)
@@ -5,7 +5,8 @@
 
 test_description='Test remote-bzr'
 
-. ./test-lib.sh
+test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
+. "$TEST_DIRECTORY"/test-lib.sh
 
 if ! test_have_prereq PYTHON
 then
@@ -378,7 +379,7 @@ test_expect_success 'export utf-8 authors' '
        git add content &&
        git commit -m one &&
        git remote add bzr "bzr::../bzrrepo" &&
-       git push bzr
+       git push bzr master
        ) &&
 
        (
index 72f745d63f2f225b4976b27875d726b4652198ed..347e812923a20652b964db6b820f8f08d6c0795f 100755 (executable)
@@ -8,7 +8,8 @@
 
 test_description='Test remote-hg'
 
-. ./test-lib.sh
+test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
+. "$TEST_DIRECTORY"/test-lib.sh
 
 if ! test_have_prereq PYTHON
 then
@@ -53,14 +54,14 @@ check_bookmark () {
 }
 
 check_push () {
-       local expected_ret=$1 ret=0 ref_ret=0 IFS=':'
+       expected_ret=$1 ret=0 ref_ret=0
 
        shift
        git push origin "$@" 2>error
        ret=$?
        cat error
 
-       while read branch kind
+       while IFS=':' read branch kind
        do
                case "$kind" in
                'new')
@@ -82,7 +83,7 @@ check_push () {
                test $ref_ret -ne 0 && echo "match for '$branch' failed" && break
        done
 
-       if test $expected_ret -ne $ret -o $ref_ret -ne 0
+       if test $expected_ret -ne $ret || test $ref_ret -ne 0
        then
                return 1
        fi
@@ -205,16 +206,17 @@ test_expect_success 'authors' '
 
        >../expected &&
        author_test alpha "" "H G Wells <wells@example.com>" &&
-       author_test beta "test" "test <unknown>" &&
-       author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
-       author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
-       author_test delta "name<test@example.com>" "name <test@example.com>" &&
-       author_test epsilon "name <test@example.com" "name <test@example.com>" &&
-       author_test zeta " test " "test <unknown>" &&
-       author_test eta "test < test@example.com >" "test <test@example.com>" &&
-       author_test theta "test >test@example.com>" "test <test@example.com>" &&
-       author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
-       author_test kappa "test@example.com" "Unknown <test@example.com>"
+       author_test beta "beta" "beta <unknown>" &&
+       author_test gamma "gamma <test@example.com> (comment)" "gamma <test@example.com>" &&
+       author_test delta "<delta@example.com>" "Unknown <delta@example.com>" &&
+       author_test epsilon "epsilon<test@example.com>" "epsilon <test@example.com>" &&
+       author_test zeta "zeta <test@example.com" "zeta <test@example.com>" &&
+       author_test eta " eta " "eta <unknown>" &&
+       author_test theta "theta < test@example.com >" "theta <test@example.com>" &&
+       author_test iota "iota >test@example.com>" "iota <test@example.com>" &&
+       author_test kappa "kappa < test <at> example <dot> com>" "kappa <unknown>" &&
+       author_test lambda "lambda@example.com" "Unknown <lambda@example.com>" &&
+       author_test mu "mu.mu@example.com" "Unknown <mu.mu@example.com>"
        ) &&
 
        git clone "hg::hgrepo" gitrepo &&
index 11a95fc8b5b5eea6de2014b9209e16f9a3422186..ab80b723574ff88b6c9c4a7c98c8821600f3e6bc 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -1121,7 +1121,7 @@ static int is_foreign_ident(const char *str)
 {
        int i;
 
-       if (prefixcmp(str, "$Id: "))
+       if (!starts_with(str, "$Id: "))
                return 0;
        for (i = 5; str[i]; i++) {
                if (isspace(str[i]) && str[i+1] != '$')
index 34916c5e105812e36d659dfeeb8341e003e746bd..7bee953de8e67bcb02acf178f8f1451633976b90 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -235,7 +235,7 @@ static int service_enabled;
 
 static int git_daemon_config(const char *var, const char *value, void *cb)
 {
-       if (!prefixcmp(var, "daemon.") &&
+       if (starts_with(var, "daemon.") &&
            !strcmp(var + 7, service_looking_at->config_name)) {
                service_enabled = git_config_bool(var, value);
                return 0;
@@ -633,7 +633,7 @@ static int execute(void)
        for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
                struct daemon_service *s = &(daemon_service[i]);
                int namelen = strlen(s->name);
-               if (!prefixcmp(line, "git-") &&
+               if (starts_with(line, "git-") &&
                    !strncmp(s->name, line + 4, namelen) &&
                    line[namelen + 4] == ' ') {
                        /*
@@ -1165,11 +1165,11 @@ int main(int argc, char **argv)
        for (i = 1; i < argc; i++) {
                char *arg = argv[i];
 
-               if (!prefixcmp(arg, "--listen=")) {
+               if (starts_with(arg, "--listen=")) {
                        string_list_append(&listen_addr, xstrdup_tolower(arg + 9));
                        continue;
                }
-               if (!prefixcmp(arg, "--port=")) {
+               if (starts_with(arg, "--port=")) {
                        char *end;
                        unsigned long n;
                        n = strtoul(arg+7, &end, 0);
@@ -1199,19 +1199,19 @@ int main(int argc, char **argv)
                        export_all_trees = 1;
                        continue;
                }
-               if (!prefixcmp(arg, "--access-hook=")) {
+               if (starts_with(arg, "--access-hook=")) {
                        access_hook = arg + 14;
                        continue;
                }
-               if (!prefixcmp(arg, "--timeout=")) {
+               if (starts_with(arg, "--timeout=")) {
                        timeout = atoi(arg+10);
                        continue;
                }
-               if (!prefixcmp(arg, "--init-timeout=")) {
+               if (starts_with(arg, "--init-timeout=")) {
                        init_timeout = atoi(arg+15);
                        continue;
                }
-               if (!prefixcmp(arg, "--max-connections=")) {
+               if (starts_with(arg, "--max-connections=")) {
                        max_connections = atoi(arg+18);
                        if (max_connections < 0)
                                max_connections = 0;            /* unlimited */
@@ -1221,7 +1221,7 @@ int main(int argc, char **argv)
                        strict_paths = 1;
                        continue;
                }
-               if (!prefixcmp(arg, "--base-path=")) {
+               if (starts_with(arg, "--base-path=")) {
                        base_path = arg+12;
                        continue;
                }
@@ -1229,7 +1229,7 @@ int main(int argc, char **argv)
                        base_path_relaxed = 1;
                        continue;
                }
-               if (!prefixcmp(arg, "--interpolated-path=")) {
+               if (starts_with(arg, "--interpolated-path=")) {
                        interpolated_path = arg+20;
                        continue;
                }
@@ -1241,11 +1241,11 @@ int main(int argc, char **argv)
                        user_path = "";
                        continue;
                }
-               if (!prefixcmp(arg, "--user-path=")) {
+               if (starts_with(arg, "--user-path=")) {
                        user_path = arg + 12;
                        continue;
                }
-               if (!prefixcmp(arg, "--pid-file=")) {
+               if (starts_with(arg, "--pid-file=")) {
                        pid_file = arg + 11;
                        continue;
                }
@@ -1254,35 +1254,35 @@ int main(int argc, char **argv)
                        log_syslog = 1;
                        continue;
                }
-               if (!prefixcmp(arg, "--user=")) {
+               if (starts_with(arg, "--user=")) {
                        user_name = arg + 7;
                        continue;
                }
-               if (!prefixcmp(arg, "--group=")) {
+               if (starts_with(arg, "--group=")) {
                        group_name = arg + 8;
                        continue;
                }
-               if (!prefixcmp(arg, "--enable=")) {
+               if (starts_with(arg, "--enable=")) {
                        enable_service(arg + 9, 1);
                        continue;
                }
-               if (!prefixcmp(arg, "--disable=")) {
+               if (starts_with(arg, "--disable=")) {
                        enable_service(arg + 10, 0);
                        continue;
                }
-               if (!prefixcmp(arg, "--allow-override=")) {
+               if (starts_with(arg, "--allow-override=")) {
                        make_service_overridable(arg + 17, 1);
                        continue;
                }
-               if (!prefixcmp(arg, "--forbid-override=")) {
+               if (starts_with(arg, "--forbid-override=")) {
                        make_service_overridable(arg + 18, 0);
                        continue;
                }
-               if (!prefixcmp(arg, "--informative-errors")) {
+               if (starts_with(arg, "--informative-errors")) {
                        informative_errors = 1;
                        continue;
                }
-               if (!prefixcmp(arg, "--no-informative-errors")) {
+               if (starts_with(arg, "--no-informative-errors")) {
                        informative_errors = 0;
                        continue;
                }
diff --git a/diff.c b/diff.c
index e34bf971207f7737c3b1a10968acd8ffb3ecf93d..b79432b1ec97909e20eb76fceb5530b2f7be647f 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -235,7 +235,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
        if (userdiff_config(var, value) < 0)
                return -1;
 
-       if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) {
+       if (starts_with(var, "diff.color.") || starts_with(var, "color.diff.")) {
                int slot = parse_diff_color_slot(var, 11);
                if (slot < 0)
                        return 0;
@@ -264,7 +264,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
-       if (!prefixcmp(var, "submodule."))
+       if (starts_with(var, "submodule."))
                return parse_submodule_config_option(var, value);
 
        return git_default_config(var, value, cb);
@@ -1215,7 +1215,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
                        diff_words_append(line, len,
                                          &ecbdata->diff_words->plus);
                        return;
-               } else if (!prefixcmp(line, "\\ ")) {
+               } else if (starts_with(line, "\\ ")) {
                        /*
                         * Eat the "no newline at eof" marker as if we
                         * saw a "+" or "-" line with nothing on it,
@@ -2387,9 +2387,9 @@ static void builtin_diff(const char *name_a,
                        xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
                if (!diffopts)
                        ;
-               else if (!prefixcmp(diffopts, "--unified="))
+               else if (starts_with(diffopts, "--unified="))
                        xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
-               else if (!prefixcmp(diffopts, "-u"))
+               else if (starts_with(diffopts, "-u"))
                        xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
                if (o->word_diff)
                        init_diff_words_data(&ecbdata, o, one, two);
@@ -3391,10 +3391,10 @@ int parse_long_opt(const char *opt, const char **argv,
        if (arg[0] != '-' || arg[1] != '-')
                return 0;
        arg += strlen("--");
-       if (prefixcmp(arg, opt))
+       if (!starts_with(arg, opt))
                return 0;
        arg += strlen(opt);
-       if (*arg == '=') { /* sticked form: --option=value */
+       if (*arg == '=') { /* stuck form: --option=value */
                *optarg = arg + 1;
                return 1;
        }
@@ -3422,7 +3422,7 @@ static int stat_opt(struct diff_options *options, const char **av)
 
        switch (*arg) {
        case '-':
-               if (!prefixcmp(arg, "-width")) {
+               if (starts_with(arg, "-width")) {
                        arg += strlen("-width");
                        if (*arg == '=')
                                width = strtoul(arg + 1, &end, 10);
@@ -3432,7 +3432,7 @@ static int stat_opt(struct diff_options *options, const char **av)
                                width = strtoul(av[1], &end, 10);
                                argcount = 2;
                        }
-               } else if (!prefixcmp(arg, "-name-width")) {
+               } else if (starts_with(arg, "-name-width")) {
                        arg += strlen("-name-width");
                        if (*arg == '=')
                                name_width = strtoul(arg + 1, &end, 10);
@@ -3442,7 +3442,7 @@ static int stat_opt(struct diff_options *options, const char **av)
                                name_width = strtoul(av[1], &end, 10);
                                argcount = 2;
                        }
-               } else if (!prefixcmp(arg, "-graph-width")) {
+               } else if (starts_with(arg, "-graph-width")) {
                        arg += strlen("-graph-width");
                        if (*arg == '=')
                                graph_width = strtoul(arg + 1, &end, 10);
@@ -3452,7 +3452,7 @@ static int stat_opt(struct diff_options *options, const char **av)
                                graph_width = strtoul(av[1], &end, 10);
                                argcount = 2;
                        }
-               } else if (!prefixcmp(arg, "-count")) {
+               } else if (starts_with(arg, "-count")) {
                        arg += strlen("-count");
                        if (*arg == '=')
                                count = strtoul(arg + 1, &end, 10);
@@ -3614,15 +3614,15 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->output_format |= DIFF_FORMAT_SHORTSTAT;
        else if (!strcmp(arg, "-X") || !strcmp(arg, "--dirstat"))
                return parse_dirstat_opt(options, "");
-       else if (!prefixcmp(arg, "-X"))
+       else if (starts_with(arg, "-X"))
                return parse_dirstat_opt(options, arg + 2);
-       else if (!prefixcmp(arg, "--dirstat="))
+       else if (starts_with(arg, "--dirstat="))
                return parse_dirstat_opt(options, arg + 10);
        else if (!strcmp(arg, "--cumulative"))
                return parse_dirstat_opt(options, "cumulative");
        else if (!strcmp(arg, "--dirstat-by-file"))
                return parse_dirstat_opt(options, "files");
-       else if (!prefixcmp(arg, "--dirstat-by-file=")) {
+       else if (starts_with(arg, "--dirstat-by-file=")) {
                parse_dirstat_opt(options, "files");
                return parse_dirstat_opt(options, arg + 18);
        }
@@ -3639,17 +3639,17 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->output_format |= DIFF_FORMAT_NAME_STATUS;
        else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
                options->output_format |= DIFF_FORMAT_NO_OUTPUT;
-       else if (!prefixcmp(arg, "--stat"))
+       else if (starts_with(arg, "--stat"))
                /* --stat, --stat-width, --stat-name-width, or --stat-count */
                return stat_opt(options, av);
 
        /* renames options */
-       else if (!prefixcmp(arg, "-B") || !prefixcmp(arg, "--break-rewrites=") ||
+       else if (starts_with(arg, "-B") || starts_with(arg, "--break-rewrites=") ||
                 !strcmp(arg, "--break-rewrites")) {
                if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
                        return error("invalid argument to -B: %s", arg+2);
        }
-       else if (!prefixcmp(arg, "-M") || !prefixcmp(arg, "--find-renames=") ||
+       else if (starts_with(arg, "-M") || starts_with(arg, "--find-renames=") ||
                 !strcmp(arg, "--find-renames")) {
                if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
                        return error("invalid argument to -M: %s", arg+2);
@@ -3658,7 +3658,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
                options->irreversible_delete = 1;
        }
-       else if (!prefixcmp(arg, "-C") || !prefixcmp(arg, "--find-copies=") ||
+       else if (starts_with(arg, "-C") || starts_with(arg, "--find-copies=") ||
                 !strcmp(arg, "--find-copies")) {
                if (options->detect_rename == DIFF_DETECT_COPY)
                        DIFF_OPT_SET(options, FIND_COPIES_HARDER);
@@ -3674,7 +3674,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                DIFF_OPT_CLR(options, RENAME_EMPTY);
        else if (!strcmp(arg, "--relative"))
                DIFF_OPT_SET(options, RELATIVE_NAME);
-       else if (!prefixcmp(arg, "--relative=")) {
+       else if (starts_with(arg, "--relative=")) {
                DIFF_OPT_SET(options, RELATIVE_NAME);
                options->prefix = arg + 11;
        }
@@ -3727,7 +3727,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                DIFF_OPT_CLR(options, FOLLOW_RENAMES);
        else if (!strcmp(arg, "--color"))
                options->use_color = 1;
-       else if (!prefixcmp(arg, "--color=")) {
+       else if (starts_with(arg, "--color=")) {
                int value = git_config_colorbool(NULL, arg+8);
                if (value < 0)
                        return error("option `color' expects \"always\", \"auto\", or \"never\"");
@@ -3739,7 +3739,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
        }
-       else if (!prefixcmp(arg, "--color-words=")) {
+       else if (starts_with(arg, "--color-words=")) {
                options->use_color = 1;
                options->word_diff = DIFF_WORDS_COLOR;
                options->word_regex = arg + 14;
@@ -3748,7 +3748,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                if (options->word_diff == DIFF_WORDS_NONE)
                        options->word_diff = DIFF_WORDS_PLAIN;
        }
-       else if (!prefixcmp(arg, "--word-diff=")) {
+       else if (starts_with(arg, "--word-diff=")) {
                const char *type = arg + 12;
                if (!strcmp(type, "plain"))
                        options->word_diff = DIFF_WORDS_PLAIN;
@@ -3784,12 +3784,12 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        else if (!strcmp(arg, "--ignore-submodules")) {
                DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
                handle_ignore_submodules_arg(options, "all");
-       } else if (!prefixcmp(arg, "--ignore-submodules=")) {
+       } else if (starts_with(arg, "--ignore-submodules=")) {
                DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
                handle_ignore_submodules_arg(options, arg + 20);
        } else if (!strcmp(arg, "--submodule"))
                DIFF_OPT_SET(options, SUBMODULE_LOG);
-       else if (!prefixcmp(arg, "--submodule="))
+       else if (starts_with(arg, "--submodule="))
                return parse_submodule_opt(options, arg + 12);
 
        /* misc options */
@@ -3825,7 +3825,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
        }
        else if (!strcmp(arg, "--abbrev"))
                options->abbrev = DEFAULT_ABBREV;
-       else if (!prefixcmp(arg, "--abbrev=")) {
+       else if (starts_with(arg, "--abbrev=")) {
                options->abbrev = strtoul(arg + 9, NULL, 10);
                if (options->abbrev < MINIMUM_ABBREV)
                        options->abbrev = MINIMUM_ABBREV;
@@ -3907,15 +3907,15 @@ static int diff_scoreopt_parse(const char *opt)
        cmd = *opt++;
        if (cmd == '-') {
                /* convert the long-form arguments into short-form versions */
-               if (!prefixcmp(opt, "break-rewrites")) {
+               if (starts_with(opt, "break-rewrites")) {
                        opt += strlen("break-rewrites");
                        if (*opt == 0 || *opt++ == '=')
                                cmd = 'B';
-               } else if (!prefixcmp(opt, "find-copies")) {
+               } else if (starts_with(opt, "find-copies")) {
                        opt += strlen("find-copies");
                        if (*opt == 0 || *opt++ == '=')
                                cmd = 'C';
-               } else if (!prefixcmp(opt, "find-renames")) {
+               } else if (starts_with(opt, "find-renames")) {
                        opt += strlen("find-renames");
                        if (*opt == 0 || *opt++ == '=')
                                cmd = 'M';
@@ -4325,7 +4325,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
        int new_len;
 
        /* Ignore line numbers when computing the SHA1 of the patch */
-       if (!prefixcmp(line, "@@ -"))
+       if (starts_with(line, "@@ -"))
                return;
 
        new_len = remove_space(line, len);
diff --git a/diff.h b/diff.h
index e34232501ee8e56a1d245da1c4f95ed8b928a837..1c05b3a6bec6ce90a97efe366614d23133026b00 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -244,7 +244,7 @@ extern struct diff_filepair *diff_unmerge(struct diff_options *, const char *pat
 #define DIFF_SETUP_USE_SIZE_CACHE      4
 
 /*
- * Poor man's alternative to parse-option, to allow both sticked form
+ * Poor man's alternative to parse-option, to allow both stuck form
  * (--option=value) and separate form (--option value).
  */
 extern int parse_long_opt(const char *opt, const char **argv,
index 0a15349cfe38ab76b1d1cc94878cec2a8d754bbd..3c76905b9ff1eac8f627c1e7a5c034ab421ac2e4 100644 (file)
@@ -171,7 +171,7 @@ const char *get_git_namespace(void)
 
 const char *strip_namespace(const char *namespaced_ref)
 {
-       if (prefixcmp(namespaced_ref, get_git_namespace()) != 0)
+       if (!starts_with(namespaced_ref, get_git_namespace()))
                return NULL;
        return namespaced_ref + namespace_len;
 }
index f4d9969e5c81f9c1415f0908f090bf62b156e179..4fd18a3574a6e72bb7a299b26b3f97fa20b8052d 100644 (file)
@@ -1877,8 +1877,8 @@ static int read_next_command(void)
                                return EOF;
 
                        if (!seen_data_command
-                               && prefixcmp(command_buf.buf, "feature ")
-                               && prefixcmp(command_buf.buf, "option ")) {
+                               && !starts_with(command_buf.buf, "feature ")
+                               && !starts_with(command_buf.buf, "option ")) {
                                parse_argv();
                        }
 
@@ -1898,7 +1898,7 @@ static int read_next_command(void)
                        rc->prev->next = rc;
                        cmd_tail = rc;
                }
-               if (!prefixcmp(command_buf.buf, "cat-blob ")) {
+               if (starts_with(command_buf.buf, "cat-blob ")) {
                        parse_cat_blob();
                        continue;
                }
@@ -1917,7 +1917,7 @@ static void skip_optional_lf(void)
 
 static void parse_mark(void)
 {
-       if (!prefixcmp(command_buf.buf, "mark :")) {
+       if (starts_with(command_buf.buf, "mark :")) {
                next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
                read_next_command();
        }
@@ -1929,10 +1929,10 @@ static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
 {
        strbuf_reset(sb);
 
-       if (prefixcmp(command_buf.buf, "data "))
+       if (!starts_with(command_buf.buf, "data "))
                die("Expected 'data n' command, found: %s", command_buf.buf);
 
-       if (!prefixcmp(command_buf.buf + 5, "<<")) {
+       if (starts_with(command_buf.buf + 5, "<<")) {
                char *term = xstrdup(command_buf.buf + 5 + 2);
                size_t term_len = command_buf.len - 5 - 2;
 
@@ -2306,7 +2306,7 @@ static void file_change_m(struct branch *b)
        if (*p == ':') {
                oe = find_mark(parse_mark_ref_space(&p));
                hashcpy(sha1, oe->idx.sha1);
-       } else if (!prefixcmp(p, "inline ")) {
+       } else if (starts_with(p, "inline ")) {
                inline_data = 1;
                oe = NULL; /* not used with inline_data, but makes gcc happy */
                p += strlen("inline");  /* advance to space */
@@ -2479,7 +2479,7 @@ static void note_change_n(struct branch *b, unsigned char *old_fanout)
        if (*p == ':') {
                oe = find_mark(parse_mark_ref_space(&p));
                hashcpy(sha1, oe->idx.sha1);
-       } else if (!prefixcmp(p, "inline ")) {
+       } else if (starts_with(p, "inline ")) {
                inline_data = 1;
                oe = NULL; /* not used with inline_data, but makes gcc happy */
                p += strlen("inline");  /* advance to space */
@@ -2590,7 +2590,7 @@ static int parse_from(struct branch *b)
        const char *from;
        struct branch *s;
 
-       if (prefixcmp(command_buf.buf, "from "))
+       if (!starts_with(command_buf.buf, "from "))
                return 0;
 
        if (b->branch_tree.tree) {
@@ -2636,7 +2636,7 @@ static struct hash_list *parse_merge(unsigned int *count)
        struct branch *s;
 
        *count = 0;
-       while (!prefixcmp(command_buf.buf, "merge ")) {
+       while (starts_with(command_buf.buf, "merge ")) {
                from = strchr(command_buf.buf, ' ') + 1;
                n = xmalloc(sizeof(*n));
                s = lookup_branch(from);
@@ -2687,11 +2687,11 @@ static void parse_new_commit(void)
 
        read_next_command();
        parse_mark();
-       if (!prefixcmp(command_buf.buf, "author ")) {
+       if (starts_with(command_buf.buf, "author ")) {
                author = parse_ident(command_buf.buf + 7);
                read_next_command();
        }
-       if (!prefixcmp(command_buf.buf, "committer ")) {
+       if (starts_with(command_buf.buf, "committer ")) {
                committer = parse_ident(command_buf.buf + 10);
                read_next_command();
        }
@@ -2712,19 +2712,19 @@ static void parse_new_commit(void)
 
        /* file_change* */
        while (command_buf.len > 0) {
-               if (!prefixcmp(command_buf.buf, "M "))
+               if (starts_with(command_buf.buf, "M "))
                        file_change_m(b);
-               else if (!prefixcmp(command_buf.buf, "D "))
+               else if (starts_with(command_buf.buf, "D "))
                        file_change_d(b);
-               else if (!prefixcmp(command_buf.buf, "R "))
+               else if (starts_with(command_buf.buf, "R "))
                        file_change_cr(b, 1);
-               else if (!prefixcmp(command_buf.buf, "C "))
+               else if (starts_with(command_buf.buf, "C "))
                        file_change_cr(b, 0);
-               else if (!prefixcmp(command_buf.buf, "N "))
+               else if (starts_with(command_buf.buf, "N "))
                        note_change_n(b, &prev_fanout);
                else if (!strcmp("deleteall", command_buf.buf))
                        file_change_deleteall(b);
-               else if (!prefixcmp(command_buf.buf, "ls "))
+               else if (starts_with(command_buf.buf, "ls "))
                        parse_ls(b);
                else {
                        unread_command_buf = 1;
@@ -2793,7 +2793,7 @@ static void parse_new_tag(void)
        read_next_command();
 
        /* from ... */
-       if (prefixcmp(command_buf.buf, "from "))
+       if (!starts_with(command_buf.buf, "from "))
                die("Expected from command, got %s", command_buf.buf);
        from = strchr(command_buf.buf, ' ') + 1;
        s = lookup_branch(from);
@@ -2821,7 +2821,7 @@ static void parse_new_tag(void)
        read_next_command();
 
        /* tagger ... */
-       if (!prefixcmp(command_buf.buf, "tagger ")) {
+       if (starts_with(command_buf.buf, "tagger ")) {
                tagger = parse_ident(command_buf.buf + 7);
                read_next_command();
        } else
@@ -3209,7 +3209,7 @@ static void option_export_pack_edges(const char *edges)
 
 static int parse_one_option(const char *option)
 {
-       if (!prefixcmp(option, "max-pack-size=")) {
+       if (starts_with(option, "max-pack-size=")) {
                unsigned long v;
                if (!git_parse_ulong(option + 14, &v))
                        return 0;
@@ -3221,20 +3221,20 @@ static int parse_one_option(const char *option)
                        v = 1024 * 1024;
                }
                max_packsize = v;
-       } else if (!prefixcmp(option, "big-file-threshold=")) {
+       } else if (starts_with(option, "big-file-threshold=")) {
                unsigned long v;
                if (!git_parse_ulong(option + 19, &v))
                        return 0;
                big_file_threshold = v;
-       } else if (!prefixcmp(option, "depth=")) {
+       } else if (starts_with(option, "depth=")) {
                option_depth(option + 6);
-       } else if (!prefixcmp(option, "active-branches=")) {
+       } else if (starts_with(option, "active-branches=")) {
                option_active_branches(option + 16);
-       } else if (!prefixcmp(option, "export-pack-edges=")) {
+       } else if (starts_with(option, "export-pack-edges=")) {
                option_export_pack_edges(option + 18);
-       } else if (!prefixcmp(option, "quiet")) {
+       } else if (starts_with(option, "quiet")) {
                show_stats = 0;
-       } else if (!prefixcmp(option, "stats")) {
+       } else if (starts_with(option, "stats")) {
                show_stats = 1;
        } else {
                return 0;
@@ -3245,14 +3245,14 @@ static int parse_one_option(const char *option)
 
 static int parse_one_feature(const char *feature, int from_stream)
 {
-       if (!prefixcmp(feature, "date-format=")) {
+       if (starts_with(feature, "date-format=")) {
                option_date_format(feature + 12);
-       } else if (!prefixcmp(feature, "import-marks=")) {
+       } else if (starts_with(feature, "import-marks=")) {
                option_import_marks(feature + 13, from_stream, 0);
-       } else if (!prefixcmp(feature, "import-marks-if-exists=")) {
+       } else if (starts_with(feature, "import-marks-if-exists=")) {
                option_import_marks(feature + strlen("import-marks-if-exists="),
                                        from_stream, 1);
-       } else if (!prefixcmp(feature, "export-marks=")) {
+       } else if (starts_with(feature, "export-marks=")) {
                option_export_marks(feature + 13);
        } else if (!strcmp(feature, "cat-blob")) {
                ; /* Don't die - this feature is supported */
@@ -3350,7 +3350,7 @@ static void parse_argv(void)
                if (parse_one_feature(a + 2, 0))
                        continue;
 
-               if (!prefixcmp(a + 2, "cat-blob-fd=")) {
+               if (starts_with(a + 2, "cat-blob-fd=")) {
                        option_cat_blob_fd(a + 2 + strlen("cat-blob-fd="));
                        continue;
                }
@@ -3404,25 +3404,25 @@ int main(int argc, char **argv)
        while (read_next_command() != EOF) {
                if (!strcmp("blob", command_buf.buf))
                        parse_new_blob();
-               else if (!prefixcmp(command_buf.buf, "ls "))
+               else if (starts_with(command_buf.buf, "ls "))
                        parse_ls(NULL);
-               else if (!prefixcmp(command_buf.buf, "commit "))
+               else if (starts_with(command_buf.buf, "commit "))
                        parse_new_commit();
-               else if (!prefixcmp(command_buf.buf, "tag "))
+               else if (starts_with(command_buf.buf, "tag "))
                        parse_new_tag();
-               else if (!prefixcmp(command_buf.buf, "reset "))
+               else if (starts_with(command_buf.buf, "reset "))
                        parse_reset_branch();
                else if (!strcmp("checkpoint", command_buf.buf))
                        parse_checkpoint();
                else if (!strcmp("done", command_buf.buf))
                        break;
-               else if (!prefixcmp(command_buf.buf, "progress "))
+               else if (starts_with(command_buf.buf, "progress "))
                        parse_progress();
-               else if (!prefixcmp(command_buf.buf, "feature "))
+               else if (starts_with(command_buf.buf, "feature "))
                        parse_feature();
-               else if (!prefixcmp(command_buf.buf, "option git "))
+               else if (starts_with(command_buf.buf, "option git "))
                        parse_option();
-               else if (!prefixcmp(command_buf.buf, "option "))
+               else if (starts_with(command_buf.buf, "option "))
                        /* ignore non-git options*/;
                else
                        die("Unsupported command: %s", command_buf.buf);
index 5a1200f1a06f0ba3a9366eb9221d982d423d8da0..760ed16e79a7a46eecfb4c9efecaee7feba0f121 100644 (file)
@@ -174,9 +174,9 @@ static void consume_shallow_list(struct fetch_pack_args *args, int fd)
                 */
                char *line;
                while ((line = packet_read_line(fd, NULL))) {
-                       if (!prefixcmp(line, "shallow "))
+                       if (starts_with(line, "shallow "))
                                continue;
-                       if (!prefixcmp(line, "unshallow "))
+                       if (starts_with(line, "unshallow "))
                                continue;
                        die("git fetch-pack: expected shallow list");
                }
@@ -192,7 +192,7 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)
                die("git fetch-pack: expected ACK/NAK, got EOF");
        if (!strcmp(line, "NAK"))
                return NAK;
-       if (!prefixcmp(line, "ACK ")) {
+       if (starts_with(line, "ACK ")) {
                if (!get_sha1_hex(line+4, result_sha1)) {
                        if (len < 45)
                                return ACK;
@@ -321,13 +321,13 @@ static int find_common(struct fetch_pack_args *args,
 
                send_request(args, fd[1], &req_buf);
                while ((line = packet_read_line(fd[0], NULL))) {
-                       if (!prefixcmp(line, "shallow ")) {
+                       if (starts_with(line, "shallow ")) {
                                if (get_sha1_hex(line + 8, sha1))
                                        die("invalid shallow line: %s", line);
                                register_shallow(sha1);
                                continue;
                        }
-                       if (!prefixcmp(line, "unshallow ")) {
+                       if (starts_with(line, "unshallow ")) {
                                if (get_sha1_hex(line + 10, sha1))
                                        die("invalid unshallow line: %s", line);
                                if (!lookup_object(sha1))
@@ -521,7 +521,7 @@ static void filter_refs(struct fetch_pack_args *args,
                }
 
                if (!keep && args->fetch_all &&
-                   (!args->depth || prefixcmp(ref->name, "refs/tags/")))
+                   (!args->depth || !starts_with(ref->name, "refs/tags/")))
                        keep = 1;
 
                if (keep) {
index 461cbf39b2affa71e27dd1a95c24d6c65a938d62..20ccc12e57b9499b0716c8295b4adea38d8d2a86 100644 (file)
@@ -14,6 +14,7 @@ struct fetch_pack_args {
                use_thin_pack:1,
                fetch_all:1,
                stdin_refs:1,
+               diag_url:1,
                verbose:1,
                no_progress:1,
                include_tag:1,
index 71e954563d7068500bd41269dd57f01b097f7c3d..8b2da4641f8b20ff3cc70c63636de878eec72470 100644 (file)
--- a/gettext.c
+++ b/gettext.c
@@ -29,6 +29,17 @@ int use_gettext_poison(void)
 #endif
 
 #ifndef NO_GETTEXT
+static int test_vsnprintf(const char *fmt, ...)
+{
+       char buf[26];
+       int ret;
+       va_list ap;
+       va_start(ap, fmt);
+       ret = vsnprintf(buf, sizeof(buf), fmt, ap);
+       va_end(ap);
+       return ret;
+}
+
 static const char *charset;
 static void init_gettext_charset(const char *domain)
 {
@@ -99,9 +110,7 @@ static void init_gettext_charset(const char *domain)
           $ LANGUAGE= LANG=de_DE.utf8 ./test
           test: Kein passendes Ger?t gefunden
 
-          In the long term we should probably see about getting that
-          vsnprintf bug in glibc fixed, and audit our code so it won't
-          fall apart under a non-C locale.
+          The vsnprintf bug has been fixed since glibc 2.17.
 
           Then we could simply set LC_CTYPE from the environment, which would
           make things like the external perror(3) messages work.
@@ -115,7 +124,9 @@ static void init_gettext_charset(const char *domain)
        setlocale(LC_CTYPE, "");
        charset = locale_charset();
        bind_textdomain_codeset(domain, charset);
-       setlocale(LC_CTYPE, "C");
+       /* the string is taken from v0.99.6~1 */
+       if (test_vsnprintf("%.*s", 13, "David_K\345gedal") < 0)
+               setlocale(LC_CTYPE, "C");
 }
 
 void git_setup_gettext(void)
index 7776f126d3bd4facfe987bd844a339c8a17b102a..b73916bbc64b3d2b926c4f5aa50311c7a867c711 100644 (file)
@@ -350,7 +350,9 @@ extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_lis
 extern void set_error_routine(void (*routine)(const char *err, va_list params));
 extern void set_die_is_recursing_routine(int (*routine)(void));
 
+extern int starts_with(const char *str, const char *prefix);
 extern int prefixcmp(const char *str, const char *prefix);
+extern int ends_with(const char *str, const char *suffix);
 extern int suffixcmp(const char *str, const char *suffix);
 
 static inline const char *skip_prefix(const char *str, const char *prefix)
index e9c2bc347dc77fb08bc6515a604a744fc4ee5795..cde8b2ea31969192136d5c541458cc43c358d4dc 100644 (file)
@@ -4,7 +4,7 @@ all::
 #
 # Define NO_MSGFMT if you do not have msgfmt from the GNU gettext
 # package and want to use our rough pure Tcl po->msg translator.
-# TCL_PATH must be vaild for this to work.
+# TCL_PATH must be valid for this to work.
 #
 
 GIT-VERSION-FILE: FORCE
index 153f85da068294917f5e60afca4fb6715f3f32ab..db46ac50bfb74c8a3252e303869557581309b505 100755 (executable)
@@ -894,6 +894,7 @@ set default_config(gui.textconv) true
 set default_config(gui.pruneduringfetch) false
 set default_config(gui.trustmtime) false
 set default_config(gui.fastcopyblame) false
+set default_config(gui.maxrecentrepo) 10
 set default_config(gui.copyblamethreshold) 40
 set default_config(gui.blamehistoryctx) 7
 set default_config(gui.diffcontext) 5
@@ -912,6 +913,7 @@ set font_descs {
        {fontdiff font_diff {mc "Diff/Console Font"}}
 }
 set default_config(gui.stageuntracked) ask
+set default_config(gui.displayuntracked) true
 
 ######################################################################
 ##
@@ -1282,7 +1284,11 @@ apply_config
 
 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
 if {[package vsatisfies $_git_version 1.7.0]} {
-       set _gitworktree [git rev-parse --show-toplevel]
+       if { [is_Cygwin] } {
+               catch {set _gitworktree [exec cygpath --windows [git rev-parse --show-toplevel]]}
+       } else {
+               set _gitworktree [git rev-parse --show-toplevel]
+       }
 } else {
        # try to set work tree from environment, core.worktree or use
        # cdup to obtain a relative path to the top of the worktree. If
@@ -1550,18 +1556,23 @@ proc rescan_stage2 {fd after} {
        set buf_rdf {}
        set buf_rlo {}
 
-       set rescan_active 3
+       set rescan_active 2
        ui_status [mc "Scanning for modified files ..."]
        set fd_di [git_read diff-index --cached -z [PARENT]]
        set fd_df [git_read diff-files -z]
-       set fd_lo [eval git_read ls-files --others -z $ls_others]
 
        fconfigure $fd_di -blocking 0 -translation binary -encoding binary
        fconfigure $fd_df -blocking 0 -translation binary -encoding binary
-       fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
+
        fileevent $fd_di readable [list read_diff_index $fd_di $after]
        fileevent $fd_df readable [list read_diff_files $fd_df $after]
-       fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
+
+       if {[is_config_true gui.displayuntracked]} {
+               set fd_lo [eval git_read ls-files --others -z $ls_others]
+               fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
+               fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
+               incr rescan_active
+       }
 }
 
 proc load_message {file {encoding {}}} {
@@ -2654,6 +2665,16 @@ if {![is_bare]} {
        .mbar.repository add command \
                -label [mc "Explore Working Copy"] \
                -command {do_explore}
+}
+
+if {[is_Windows]} {
+       .mbar.repository add command \
+               -label [mc "Git Bash"] \
+               -command {eval exec [auto_execok start] \
+                                         [list "Git Bash" bash --login -l &]}
+}
+
+if {[is_Windows] || ![is_bare]} {
        .mbar.repository add separator
 }
 
@@ -3203,13 +3224,19 @@ unset i
 
 # -- Diff and Commit Area
 #
-${NS}::frame .vpane.lower -height 300 -width 400
+${NS}::panedwindow .vpane.lower -orient vertical
 ${NS}::frame .vpane.lower.commarea
-${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
-pack .vpane.lower.diff -fill both -expand 1
-pack .vpane.lower.commarea -side bottom -fill x
+${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1 -height 500
+.vpane.lower add .vpane.lower.diff
+.vpane.lower add .vpane.lower.commarea
 .vpane add .vpane.lower
-if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
+if {$use_ttk} {
+       .vpane.lower pane .vpane.lower.diff -weight 1
+       .vpane.lower pane .vpane.lower.commarea -weight 0
+} else {
+       .vpane.lower paneconfigure .vpane.lower.diff -stretch always
+       .vpane.lower paneconfigure .vpane.lower.commarea -stretch never
+}
 
 # -- Commit Area Buttons
 #
index 324f7744c495dc2eb9a1d4acde09352d7948efe8..b1d15f46218e793866bee9300684663e2c04fd29 100644 (file)
@@ -5,7 +5,7 @@ class blame {
 
 image create photo ::blame::img_back_arrow -data {R0lGODlhGAAYAIUAAPwCBEzKXFTSZIz+nGzmhGzqfGTidIT+nEzGXHTqhGzmfGzifFzadETCVES+VARWDFzWbHzyjAReDGTadFTOZDSyRDyyTCymPARaFGTedFzSbDy2TCyqRCyqPARaDAyCHES6VDy6VCyiPAR6HCSeNByWLARyFARiDARqFGTifARiFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAYABgAAAajQIBwSCwaj8ikcsk0BppJwRPqHEypQwHBis0WDAdEFyBIKBaMAKLBdjQeSkFBYTBAIvgEoS6JmhUTEwIUDQ4VFhcMGEhyCgoZExoUaxsWHB0THkgfAXUGAhoBDSAVFR0XBnCbDRmgog0hpSIiDJpJIyEQhBUcJCIlwA22SSYVogknEg8eD82qSigdDSknY0IqJQXPYxIl1dZCGNvWw+Dm510GQQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7}
 
-# Persistant data (survives loads)
+# Persistent data (survives loads)
 #
 field history {}; # viewer history: {commit path}
 field header    ; # array commit,key -> header field
index ee58981f539bfd27dbba99db47d6f85102b0e7a6..3c10bc656d207553c8c093abcca275dd253a57fb 100644 (file)
@@ -24,6 +24,10 @@ field sorted_recent       ; # recent repositories (sorted)
 constructor pick {} {
        global M1T M1B use_ttk NS
 
+       if {[set maxrecent [get_config gui.maxrecentrepo]] eq {}} {
+               set maxrecent 10
+       }
+
        make_dialog top w
        wm title $top [mc "Git Gui"]
 
@@ -148,7 +152,7 @@ constructor pick {} {
                        -background [get_bg_color $w_body.recentlabel] \
                        -wrap none \
                        -width 50 \
-                       -height 10
+                       -height $maxrecent
                $w_recentlist tag conf link \
                        -foreground blue \
                        -underline 1
@@ -264,7 +268,11 @@ proc _append_recentrepos {path} {
        git config --global --add gui.recentrepo $path
        load_config 1
 
-       while {[llength $recent] > 10} {
+       if {[set maxrecent [get_config gui.maxrecentrepo]] eq {}} {
+               set maxrecent 10
+       }
+
+       while {[llength $recent] > $maxrecent} {
                _unset_recentrepo [lindex $recent 0]
                set recent [lrange $recent 1 end]
        }
index 8efbbdde21123dd65412cd5fe6dbb506966b0af9..74a81a7b42779c006fb0c0060724359fca2b33d9 100644 (file)
@@ -414,7 +414,7 @@ proc revert_helper {txt paths} {
        # such distinction is needed in some languages. Previously, the
        # code used "Revert changes in" for both, but that can't work
        # in languages where 'in' must be combined with word from
-       # rest of string (in diffrent way for both cases of course).
+       # rest of string (in different way for both cases of course).
        #
        # FIXME: Unfortunately, even that isn't enough in some languages
        # as they have quite complex plural-form rules. Unfortunately,
index 0cf1da1d7ebe75fe91322d9b404dbf4bd8a3b00f..23c9ae72a43c3f2b6ac0409ded488869f3b2de0d 100644 (file)
@@ -150,6 +150,7 @@ proc do_options {} {
                {b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
                {b gui.textconv {mc "Use Textconv For Diffs and Blames"}}
                {b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
+               {i-0..100 gui.maxrecentrepo {mc "Maximum Length of Recent Repositories List"}}
                {i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
                {i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}
                {i-1..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
@@ -159,6 +160,7 @@ proc do_options {} {
                {c gui.encoding {mc "Default File Contents Encoding"}}
                {b gui.warndetachedcommit {mc "Warn before committing to a detached head"}}
                {s gui.stageuntracked {mc "Staging of untracked files"} {list "yes" "no" "ask"}}
+               {b gui.displayuntracked {mc "Show untracked files"}}
                } {
                set type [lindex $option 0]
                set name [lindex $option 1]
index e6120303e940ee6c849bf706415c1b450e68b57f..538d61c792defa7a8e19736039fa5a9af630125c 100644 (file)
@@ -14,7 +14,7 @@ field w_menu      ; # context menu for the widget
 field s_menuidx 0 ; # last index of insertion into $w_menu
 
 field s_i           {} ; # timer registration for _run callbacks
-field s_clear        0 ; # did we erase mispelled tags yet?
+field s_clear        0 ; # did we erase misspelled tags yet?
 field s_seen    [list] ; # lines last seen from $w_text in _run
 field s_checked [list] ; # lines already checked
 field s_pending [list] ; # [$line $data] sent to ispell/aspell
@@ -259,7 +259,7 @@ method _run {} {
                if {$n == $cur_line
                 && ![regexp {^\W$} [$w_text get $cur_pos insert]]} {
 
-                       # If the current word is mispelled remove the tag
+                       # If the current word is misspelled remove the tag
                        # but force a spellcheck later.
                        #
                        set tags [$w_text tag names $cur_pos]
index b3bf15fa1c1a41265460664417caf47265553a4f..1ade121c4cc532d565bdfc9f03a7e766963c34a8 100644 (file)
@@ -24,5 +24,7 @@
        <string>GITg</string>
        <key>CFBundleVersion</key>
        <string>@@GITGUI_VERSION@@</string>
+       <key>NSHighResolutionCapable</key>
+       <true/>
 </dict>
 </plist>
diff --git a/git-lost-found.sh b/git-lost-found.sh
deleted file mode 100755 (executable)
index 0b3e8c7..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-
-USAGE=''
-SUBDIRECTORY_OK='Yes'
-OPTIONS_SPEC=
-. git-sh-setup
-
-echo "WARNING: '$0' is deprecated in favor of 'git fsck --lost-found'" >&2
-
-if [ "$#" != "0" ]
-then
-    usage
-fi
-
-laf="$GIT_DIR/lost-found"
-rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit
-
-git fsck --full --no-reflogs |
-while read dangling type sha1
-do
-       case "$dangling" in
-       dangling)
-               if git rev-parse -q --verify "$sha1^0" >/dev/null
-               then
-                       dir="$laf/commit"
-                       git show-branch "$sha1"
-               else
-                       dir="$laf/other"
-               fi
-               echo "$sha1" >"$dir/$sha1"
-               ;;
-       esac
-done
index a280f498179eb2747b32ba5de4111ccb32024848..c45a020301c16614057912b9a26d1466a94654a9 100644 (file)
@@ -1,5 +1,4 @@
-#!/bin/sh
-# git-mergetool--lib is a library for common merge tool functions
+# git-mergetool--lib is a shell library for common merge tool functions
 
 : ${MERGE_TOOLS_DIR=$(git --exec-path)/mergetools}
 
index 06a3cc6122410efcccf0fd77f359ffc2e809aff9..5ea8bb8fc27520cb6874431e827c00821b848b33 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -1311,7 +1311,7 @@ def applyCommit(self, id):
             else:
                 die("unknown modifier %s for %s" % (modifier, path))
 
-        diffcmd = "git format-patch -k --stdout \"%s^\"..\"%s\"" % (id, id)
+        diffcmd = "git diff-tree -p \"%s\"" % (id)
         patchcmd = diffcmd + " | git apply "
         tryPatchCmd = patchcmd + "--check -"
         applyPatchCmd = patchcmd + "--check --apply -"
index 0e87e0915ee16e36385aa4182b3a4271d1308641..55fe8d56c9d5107df0843378ef137d64a48b2980 100644 (file)
@@ -1,4 +1,6 @@
-#!/bin/sh
+# This is a shell library to calculate the remote repository and
+# upstream branch that should be pulled by "git pull" from the current
+# branch.
 
 # git-ls-remote could be called from outside a git managed repository;
 # this would fail in that case and would issue an error message.
index 605e9575df6c4cc08ac5fbb6c4eac2c959954e49..f210d0a14707c57d66baa2d098d0d2efdaaaf72e 100755 (executable)
@@ -172,7 +172,7 @@ error_on_no_merge_candidates () {
        do
                case "$opt" in
                -t|--t|--ta|--tag|--tags)
-                       echo "Fetching tags only, you probably meant:"
+                       echo "It doesn't make sense to pull all tags; you probably meant:"
                        echo "  git fetch --tags"
                        exit 1
                esac
index 34e3102fcbfa64ec101c1fe009c9b14a5976e4c2..a4f683a5d70213151f3713cc0a2d76dfe8293fd3 100644 (file)
@@ -1,4 +1,5 @@
-#!/bin/sh
+# This shell script fragment is sourced by git-rebase to implement
+# its default, fast, patch-based, non-interactive mode.
 #
 # Copyright (c) 2010 Junio C Hamano.
 #
index 3c6bed9a28f7ff96fa619a9acbfc42e4a2c78828..43c19e0829ca727501ba7e4d29c952bc286ccb77 100644 (file)
@@ -1,11 +1,8 @@
-#!/bin/sh
+# This shell script fragment is sourced by git-rebase to implement
+# its interactive mode.  "git rebase --interactive" makes it easy
+# to fix up commits in the middle of a series and rearrange commits.
 #
 # Copyright (c) 2006 Johannes E. Schindelin
-
-# SHORT DESCRIPTION
-#
-# This script makes it easy to fix up commits in the middle of a series,
-# and rearrange commits.
 #
 # The original idea comes from Eric W. Biederman, in
 # http://article.gmane.org/gmane.comp.version-control.git/22407
index 16d18176ece5eecf4a3b0b0a9dea0a5b41ac43d4..e7d96de9adcb133982bbbc6d20cd3b52b3c89214 100644 (file)
@@ -1,4 +1,6 @@
-#!/bin/sh
+# This shell script fragment is sourced by git-rebase to implement
+# its merge-based non-interactive mode that copes well with renamed
+# files.
 #
 # Copyright (c) 2010 Junio C Hamano.
 #
index 3782c3b0cb4f9356790ae581c0d408dc4f4cae75..2016d9c6198957943a8bd2510e217fe72412062a 100755 (executable)
@@ -291,7 +291,7 @@ sub signal_handler {
                    "smtp-pass:s" => \$smtp_authpass,
                    "smtp-ssl" => sub { $smtp_encryption = 'ssl' },
                    "smtp-encryption=s" => \$smtp_encryption,
-                   "smtp-ssl-cert-path" => \$smtp_ssl_cert_path,
+                   "smtp-ssl-cert-path=s" => \$smtp_ssl_cert_path,
                    "smtp-debug:i" => \$debug_net_smtp,
                    "smtp-domain:s" => \$smtp_domain,
                    "identity=s" => \$identity,
@@ -1214,10 +1214,14 @@ sub send_message {
                        $smtp_server_port ||= 465; # ssmtp
                        require Net::SMTP::SSL;
                        $smtp_domain ||= maildomain();
+                       require IO::Socket::SSL;
+                       # Net::SMTP::SSL->new() does not forward any SSL options
+                       IO::Socket::SSL::set_client_defaults(
+                               ssl_verify_params());
                        $smtp ||= Net::SMTP::SSL->new($smtp_server,
                                                      Hello => $smtp_domain,
                                                      Port => $smtp_server_port,
-                                                     ssl_verify_params());
+                                                     Debug => $debug_net_smtp);
                }
                else {
                        require Net::SMTP;
index 6a27f6813624e10b479cae244ad3bb9d2127ff6d..e6c3116e181318fa4c1036b0a26a1d0f24a4ace7 100644 (file)
@@ -1,9 +1,8 @@
-#!/bin/sh
+# This shell library is Git's interface to gettext.sh. See po/README
+# for usage instructions.
 #
 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
 #
-# This is Git's interface to gettext.sh. See po/README for usage
-# instructions.
 
 # Export the TEXTDOMAIN* data that we need for Git
 TEXTDOMAIN=git
index ebfe8f7a4d0697422a826d7878855bf9e92d0060..190a5394b9265270faadf578685e9a12b4efebfd 100644 (file)
@@ -1,9 +1,6 @@
-#!/bin/sh
-#
-# This is included in commands that either have to be run from the toplevel
-# of the repository, or with GIT_DIR environment variable properly.
-# If the GIT_DIR does not look like the right correct git-repository,
-# it dies.
+# This shell scriplet is meant to be included by other shell scripts
+# to set up some variables pointing at the normal git directories and
+# a few helper shell functions.
 
 # Having this variable in your environment would break scripts because
 # you would cause "cd" to be taken to unexpected places.  If you
index ed02f032140e0e93fd920f591f41bc328a071833..2677f2e8b3c57dc5c1a632e5705b26f74cbd7137 100755 (executable)
@@ -721,7 +721,6 @@ cmd_deinit()
 cmd_update()
 {
        # parse $args after "submodule ... update".
-       orig_flags=
        while test $# -ne 0
        do
                case "$1" in
@@ -746,7 +745,6 @@ cmd_update()
                --reference)
                        case "$2" in '') usage ;; esac
                        reference="--reference=$2"
-                       orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
                        shift
                        ;;
                --reference=*)
@@ -780,7 +778,6 @@ cmd_update()
                        break
                        ;;
                esac
-               orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
                shift
        done
 
@@ -924,7 +921,7 @@ Maybe you want to use 'update --init'?")"
                                prefix="$prefix$sm_path/"
                                clear_local_git_env
                                cd "$sm_path" &&
-                               eval cmd_update "$orig_flags"
+                               eval cmd_update
                        )
                        res=$?
                        if test $res -gt 0
diff --git a/git.c b/git.c
index cb5208de6a5aab7c222a1d1655fe37089a119fe0..3799514ccba86834ee076c66ee1b6f8473d3ebef 100644 (file)
--- a/git.c
+++ b/git.c
@@ -54,7 +54,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                /*
                 * Check remaining flags.
                 */
-               if (!prefixcmp(cmd, "--exec-path")) {
+               if (starts_with(cmd, "--exec-path")) {
                        cmd += 11;
                        if (*cmd == '=')
                                git_set_argv_exec_path(cmd + 1);
@@ -92,7 +92,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                *envchanged = 1;
                        (*argv)++;
                        (*argc)--;
-               } else if (!prefixcmp(cmd, "--git-dir=")) {
+               } else if (starts_with(cmd, "--git-dir=")) {
                        setenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);
                        if (envchanged)
                                *envchanged = 1;
@@ -106,7 +106,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                *envchanged = 1;
                        (*argv)++;
                        (*argc)--;
-               } else if (!prefixcmp(cmd, "--namespace=")) {
+               } else if (starts_with(cmd, "--namespace=")) {
                        setenv(GIT_NAMESPACE_ENVIRONMENT, cmd + 12, 1);
                        if (envchanged)
                                *envchanged = 1;
@@ -120,7 +120,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                *envchanged = 1;
                        (*argv)++;
                        (*argc)--;
-               } else if (!prefixcmp(cmd, "--work-tree=")) {
+               } else if (starts_with(cmd, "--work-tree=")) {
                        setenv(GIT_WORK_TREE_ENVIRONMENT, cmd + 12, 1);
                        if (envchanged)
                                *envchanged = 1;
@@ -408,7 +408,6 @@ static void handle_internal_command(int argc, const char **argv)
                { "pack-redundant", cmd_pack_redundant, RUN_SETUP },
                { "pack-refs", cmd_pack_refs, RUN_SETUP },
                { "patch-id", cmd_patch_id },
-               { "peek-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
                { "pickaxe", cmd_blame, RUN_SETUP },
                { "prune", cmd_prune, RUN_SETUP },
                { "prune-packed", cmd_prune_packed, RUN_SETUP },
@@ -421,7 +420,6 @@ static void handle_internal_command(int argc, const char **argv)
                { "remote-fd", cmd_remote_fd },
                { "repack", cmd_repack, RUN_SETUP },
                { "replace", cmd_replace, RUN_SETUP },
-               { "repo-config", cmd_repo_config, RUN_SETUP_GENTLY },
                { "rerere", cmd_rerere, RUN_SETUP },
                { "reset", cmd_reset, RUN_SETUP },
                { "rev-list", cmd_rev_list, RUN_SETUP },
@@ -438,7 +436,6 @@ static void handle_internal_command(int argc, const char **argv)
                { "stripspace", cmd_stripspace },
                { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
                { "tag", cmd_tag, RUN_SETUP },
-               { "tar-tree", cmd_tar_tree },
                { "unpack-file", cmd_unpack_file, RUN_SETUP },
                { "unpack-objects", cmd_unpack_objects, RUN_SETUP },
                { "update-index", cmd_update_index, RUN_SETUP },
@@ -569,7 +566,7 @@ int main(int argc, char **av)
         * So we just directly call the internal command handler, and
         * die if that one cannot handle it.
         */
-       if (!prefixcmp(cmd, "git-")) {
+       if (starts_with(cmd, "git-")) {
                cmd += 4;
                argv[0] = cmd;
                handle_internal_command(argc, argv);
@@ -581,7 +578,7 @@ int main(int argc, char **av)
        argc--;
        handle_options(&argv, &argc, NULL);
        if (argc > 0) {
-               if (!prefixcmp(argv[0], "--"))
+               if (starts_with(argv[0], "--"))
                        argv[0] += 2;
        } else {
                /* The user didn't specify a command; give them help */
index 5cd00d80fe2fb80a07a59b7e5327f8ff6c29d8f6..33c3a6c6b3c1b125bbf7f3951e38149742787314 100755 (executable)
@@ -156,10 +156,12 @@ proc unmerged_files {files} {
 
 proc parseviewargs {n arglist} {
     global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
+    global vinlinediff
     global worddiff git_version
 
     set vdatemode($n) 0
     set vmergeonly($n) 0
+    set vinlinediff($n) 0
     set glflags {}
     set diffargs {}
     set nextisval 0
@@ -227,12 +229,20 @@ proc parseviewargs {n arglist} {
            "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
            "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
            "--remove-empty" - "--first-parent" - "--cherry-pick" -
-           "-S*" - "--pickaxe-all" - "--pickaxe-regex" -
+           "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" -
            "--simplify-by-decoration" {
                # These mean that we get a subset of the commits
                set filtered 1
                lappend glflags $arg
            }
+           "-L*" {
+               # Line-log with 'stuck' argument (unstuck form is
+               # not supported)
+               set filtered 1
+               set vinlinediff($n) 1
+               set allknown 0
+               lappend glflags $arg
+           }
            "-n" {
                # This appears to be the only one that has a value as a
                # separate word following it
@@ -1704,8 +1714,17 @@ proc parsecommit {id contents listed} {
        set comment $newcomment
     }
     set hasnote [string first "\nNotes:\n" $contents]
+    set diff ""
+    # If there is diff output shown in the git-log stream, split it
+    # out.  But get rid of the empty line that always precedes the
+    # diff.
+    set i [string first "\n\ndiff" $comment]
+    if {$i >= 0} {
+       set diff [string range $comment $i+1 end]
+       set comment [string range $comment 0 $i-1]
+    }
     set commitinfo($id) [list $headline $auname $audate \
-                            $comname $comdate $comment $hasnote]
+                            $comname $comdate $comment $hasnote $diff]
 }
 
 proc getcommit {id} {
@@ -2385,6 +2404,7 @@ proc makewindow {} {
     $ctext tag conf found -back $foundbgcolor
     $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
     $ctext tag conf wwrap -wrap word
+    $ctext tag conf bold -font textfontbold
 
     .pwbottom add .bleft
     if {!$use_ttk} {
@@ -6387,6 +6407,25 @@ proc bindline {t id} {
     $canv bind $t <Button-1> "lineclick %x %y $id 1"
 }
 
+proc graph_pane_width {} {
+    global use_ttk
+
+    if {$use_ttk} {
+       set g [.tf.histframe.pwclist sashpos 0]
+    } else {
+       set g [.tf.histframe.pwclist sash coord 0]
+    }
+    return [lindex $g 0]
+}
+
+proc totalwidth {l font extra} {
+    set tot 0
+    foreach str $l {
+       set tot [expr {$tot + [font measure $font $str] + $extra}]
+    }
+    return $tot
+}
+
 proc drawtags {id x xt y1} {
     global idtags idheads idotherrefs mainhead
     global linespc lthickness
@@ -6398,9 +6437,27 @@ proc drawtags {id x xt y1} {
     set marks {}
     set ntags 0
     set nheads 0
+    set singletag 0
+    set maxtags 3
+    set maxtagpct 25
+    set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
+    set delta [expr {int(0.5 * ($linespc - $lthickness))}]
+    set extra [expr {$delta + $lthickness + $linespc}]
+
     if {[info exists idtags($id)]} {
        set marks $idtags($id)
        set ntags [llength $marks]
+       if {$ntags > $maxtags ||
+           [totalwidth $marks mainfont $extra] > $maxwidth} {
+           # show just a single "n tags..." tag
+           set singletag 1
+           if {$ntags == 1} {
+               set marks [list "tag..."]
+           } else {
+               set marks [list [format "%d tags..." $ntags]]
+           }
+           set ntags 1
+       }
     }
     if {[info exists idheads($id)]} {
        set marks [concat $marks $idheads($id)]
@@ -6413,7 +6470,6 @@ proc drawtags {id x xt y1} {
        return $xt
     }
 
-    set delta [expr {int(0.5 * ($linespc - $lthickness))}]
     set yt [expr {$y1 - 0.5 * $linespc}]
     set yb [expr {$yt + $linespc - 1}]
     set xvals {}
@@ -6428,7 +6484,7 @@ proc drawtags {id x xt y1} {
        }
        lappend xvals $xt
        lappend wvals $wid
-       set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
+       set xt [expr {$xt + $wid + $extra}]
     }
     set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
               -width $lthickness -fill $reflinecolor -tags tag.$id]
@@ -6444,7 +6500,12 @@ proc drawtags {id x xt y1} {
                       $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
                       -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
                       -tags tag.$id]
-           $canv bind $t <1> [list showtag $tag_quoted 1]
+           if {$singletag} {
+               set tagclick [list showtags $id 1]
+           } else {
+               set tagclick [list showtag $tag_quoted 1]
+           }
+           $canv bind $t <1> $tagclick
            set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
        } else {
            # draw a head or other ref
@@ -6471,7 +6532,7 @@ proc drawtags {id x xt y1} {
        set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
                   -font $font -tags [list tag.$id text]]
        if {$ntags >= 0} {
-           $canv bind $t <1> [list showtag $tag_quoted 1]
+           $canv bind $t <1> $tagclick
        } elseif {$nheads >= 0} {
            $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
        }
@@ -7080,6 +7141,7 @@ proc selectline {l isnew {desired_loc {}}} {
     global cmitmode showneartags allcommits
     global targetrow targetid lastscrollrows
     global autoselect autosellen jump_to_here
+    global vinlinediff
 
     catch {unset pending_select}
     $canv delete hover
@@ -7221,6 +7283,8 @@ proc selectline {l isnew {desired_loc {}}} {
     init_flist [mc "Comments"]
     if {$cmitmode eq "tree"} {
        gettree $id
+    } elseif {$vinlinediff($curview) == 1} {
+       showinlinediff $id
     } elseif {[llength $olds] <= 1} {
        startdiff $id
     } else {
@@ -7557,6 +7621,39 @@ proc startdiff {ids} {
     }
 }
 
+proc showinlinediff {ids} {
+    global commitinfo commitdata ctext
+    global treediffs
+
+    set info $commitinfo($ids)
+    set diff [lindex $info 7]
+    set difflines [split $diff "\n"]
+
+    initblobdiffvars
+    set treediff {}
+
+    set inhdr 0
+    foreach line $difflines {
+       if {![string compare -length 5 "diff " $line]} {
+           set inhdr 1
+       } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
+           # offset also accounts for the b/ prefix
+           lappend treediff [string range $line 6 end]
+           set inhdr 0
+       }
+    }
+
+    set treediffs($ids) $treediff
+    add_flist $treediff
+
+    $ctext conf -state normal
+    foreach line $difflines {
+       parseblobdiffline $ids $line
+    }
+    maybe_scroll_ctext 1
+    $ctext conf -state disabled
+}
+
 # If the filename (name) is under any of the passed filter paths
 # then return true to include the file in the listing.
 proc path_filter {filter name} {
@@ -7710,15 +7807,25 @@ proc changeworddiff {name ix op} {
     reselectline
 }
 
+proc initblobdiffvars {} {
+    global diffencoding targetline diffnparents
+    global diffinhdr currdiffsubmod diffseehere
+    set targetline {}
+    set diffnparents 0
+    set diffinhdr 0
+    set diffencoding [get_path_encoding {}]
+    set currdiffsubmod ""
+    set diffseehere -1
+}
+
 proc getblobdiffs {ids} {
     global blobdifffd diffids env
-    global diffinhdr treediffs
+    global treediffs
     global diffcontext
     global ignorespace
     global worddiff
     global limitdiffs vfilelimit curview
-    global diffencoding targetline diffnparents
-    global git_version currdiffsubmod
+    global git_version
 
     set textconv {}
     if {[package vcompare $git_version "1.6.1"] >= 0} {
@@ -7742,13 +7849,9 @@ proc getblobdiffs {ids} {
        error_popup [mc "Error getting diffs: %s" $err]
        return
     }
-    set targetline {}
-    set diffnparents 0
-    set diffinhdr 0
-    set diffencoding [get_path_encoding {}]
     fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
     set blobdifffd($ids) $bdf
-    set currdiffsubmod ""
+    initblobdiffvars
     filerun $bdf [list getblobdiffline $bdf $diffids]
 }
 
@@ -7814,13 +7917,17 @@ proc makediffhdr {fname ids} {
     set diffline 0
 }
 
+proc blobdiffmaybeseehere {ateof} {
+    global diffseehere
+    if {$diffseehere >= 0} {
+       mark_ctext_line [lindex [split $diffseehere .] 0]
+    }
+    maybe_scroll_ctext ateof
+}
+
 proc getblobdiffline {bdf ids} {
-    global diffids blobdifffd ctext curdiffstart
-    global diffnexthead diffnextnote difffilestart
-    global ctext_file_names ctext_file_lines
-    global diffinhdr treediffs mergemax diffnparents
-    global diffencoding jump_to_here targetline diffline currdiffsubmod
-    global worddiff
+    global diffids blobdifffd
+    global ctext
 
     set nr 0
     $ctext conf -state normal
@@ -7829,212 +7936,220 @@ proc getblobdiffline {bdf ids} {
            catch {close $bdf}
            return 0
        }
-       if {![string compare -length 5 "diff " $line]} {
-           if {![regexp {^diff (--cc|--git) } $line m type]} {
-               set line [encoding convertfrom $line]
-               $ctext insert end "$line\n" hunksep
-               continue
+       parseblobdiffline $ids $line
+    }
+    $ctext conf -state disabled
+    blobdiffmaybeseehere [eof $bdf]
+    if {[eof $bdf]} {
+       catch {close $bdf}
+       return 0
+    }
+    return [expr {$nr >= 1000? 2: 1}]
+}
+
+proc parseblobdiffline {ids line} {
+    global ctext curdiffstart
+    global diffnexthead diffnextnote difffilestart
+    global ctext_file_names ctext_file_lines
+    global diffinhdr treediffs mergemax diffnparents
+    global diffencoding jump_to_here targetline diffline currdiffsubmod
+    global worddiff diffseehere
+
+    if {![string compare -length 5 "diff " $line]} {
+       if {![regexp {^diff (--cc|--git) } $line m type]} {
+           set line [encoding convertfrom $line]
+           $ctext insert end "$line\n" hunksep
+           continue
+       }
+       # start of a new file
+       set diffinhdr 1
+       $ctext insert end "\n"
+       set curdiffstart [$ctext index "end - 1c"]
+       lappend ctext_file_names ""
+       lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
+       $ctext insert end "\n" filesep
+
+       if {$type eq "--cc"} {
+           # start of a new file in a merge diff
+           set fname [string range $line 10 end]
+           if {[lsearch -exact $treediffs($ids) $fname] < 0} {
+               lappend treediffs($ids) $fname
+               add_flist [list $fname]
            }
-           # start of a new file
-           set diffinhdr 1
-           $ctext insert end "\n"
-           set curdiffstart [$ctext index "end - 1c"]
-           lappend ctext_file_names ""
-           lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
-           $ctext insert end "\n" filesep
-
-           if {$type eq "--cc"} {
-               # start of a new file in a merge diff
-               set fname [string range $line 10 end]
-               if {[lsearch -exact $treediffs($ids) $fname] < 0} {
-                   lappend treediffs($ids) $fname
-                   add_flist [list $fname]
-               }
 
+       } else {
+           set line [string range $line 11 end]
+           # If the name hasn't changed the length will be odd,
+           # the middle char will be a space, and the two bits either
+           # side will be a/name and b/name, or "a/name" and "b/name".
+           # If the name has changed we'll get "rename from" and
+           # "rename to" or "copy from" and "copy to" lines following
+           # this, and we'll use them to get the filenames.
+           # This complexity is necessary because spaces in the
+           # filename(s) don't get escaped.
+           set l [string length $line]
+           set i [expr {$l / 2}]
+           if {!(($l & 1) && [string index $line $i] eq " " &&
+                 [string range $line 2 [expr {$i - 1}]] eq \
+                     [string range $line [expr {$i + 3}] end])} {
+               return
+           }
+           # unescape if quoted and chop off the a/ from the front
+           if {[string index $line 0] eq "\""} {
+               set fname [string range [lindex $line 0] 2 end]
            } else {
-               set line [string range $line 11 end]
-               # If the name hasn't changed the length will be odd,
-               # the middle char will be a space, and the two bits either
-               # side will be a/name and b/name, or "a/name" and "b/name".
-               # If the name has changed we'll get "rename from" and
-               # "rename to" or "copy from" and "copy to" lines following
-               # this, and we'll use them to get the filenames.
-               # This complexity is necessary because spaces in the
-               # filename(s) don't get escaped.
-               set l [string length $line]
-               set i [expr {$l / 2}]
-               if {!(($l & 1) && [string index $line $i] eq " " &&
-                     [string range $line 2 [expr {$i - 1}]] eq \
-                         [string range $line [expr {$i + 3}] end])} {
-                   continue
-               }
-               # unescape if quoted and chop off the a/ from the front
-               if {[string index $line 0] eq "\""} {
-                   set fname [string range [lindex $line 0] 2 end]
-               } else {
-                   set fname [string range $line 2 [expr {$i - 1}]]
-               }
+               set fname [string range $line 2 [expr {$i - 1}]]
            }
-           makediffhdr $fname $ids
+       }
+       makediffhdr $fname $ids
+
+    } elseif {![string compare -length 16 "* Unmerged path " $line]} {
+       set fname [encoding convertfrom [string range $line 16 end]]
+       $ctext insert end "\n"
+       set curdiffstart [$ctext index "end - 1c"]
+       lappend ctext_file_names $fname
+       lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
+       $ctext insert end "$line\n" filesep
+       set i [lsearch -exact $treediffs($ids) $fname]
+       if {$i >= 0} {
+           setinlist difffilestart $i $curdiffstart
+       }
 
-       } elseif {![string compare -length 16 "* Unmerged path " $line]} {
-           set fname [encoding convertfrom [string range $line 16 end]]
-           $ctext insert end "\n"
-           set curdiffstart [$ctext index "end - 1c"]
-           lappend ctext_file_names $fname
-           lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
+    } elseif {![string compare -length 2 "@@" $line]} {
+       regexp {^@@+} $line ats
+       set line [encoding convertfrom $diffencoding $line]
+       $ctext insert end "$line\n" hunksep
+       if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
+           set diffline $nl
+       }
+       set diffnparents [expr {[string length $ats] - 1}]
+       set diffinhdr 0
+
+    } elseif {![string compare -length 10 "Submodule " $line]} {
+       # start of a new submodule
+       if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
+           set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
+       } else {
+           set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
+       }
+       if {$currdiffsubmod != $fname} {
+           $ctext insert end "\n";     # Add newline after commit message
+       }
+       set curdiffstart [$ctext index "end - 1c"]
+       lappend ctext_file_names ""
+       if {$currdiffsubmod != $fname} {
+           lappend ctext_file_lines $fname
+           makediffhdr $fname $ids
+           set currdiffsubmod $fname
+           $ctext insert end "\n$line\n" filesep
+       } else {
            $ctext insert end "$line\n" filesep
+       }
+    } elseif {![string compare -length 3 "  >" $line]} {
+       set $currdiffsubmod ""
+       set line [encoding convertfrom $diffencoding $line]
+       $ctext insert end "$line\n" dresult
+    } elseif {![string compare -length 3 "  <" $line]} {
+       set $currdiffsubmod ""
+       set line [encoding convertfrom $diffencoding $line]
+       $ctext insert end "$line\n" d0
+    } elseif {$diffinhdr} {
+       if {![string compare -length 12 "rename from " $line]} {
+           set fname [string range $line [expr 6 + [string first " from " $line] ] end]
+           if {[string index $fname 0] eq "\""} {
+               set fname [lindex $fname 0]
+           }
+           set fname [encoding convertfrom $fname]
            set i [lsearch -exact $treediffs($ids) $fname]
            if {$i >= 0} {
                setinlist difffilestart $i $curdiffstart
            }
-
-       } elseif {![string compare -length 2 "@@" $line]} {
-           regexp {^@@+} $line ats
-           set line [encoding convertfrom $diffencoding $line]
-           $ctext insert end "$line\n" hunksep
-           if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
-               set diffline $nl
+       } elseif {![string compare -length 10 $line "rename to "] ||
+                 ![string compare -length 8 $line "copy to "]} {
+           set fname [string range $line [expr 4 + [string first " to " $line] ] end]
+           if {[string index $fname 0] eq "\""} {
+               set fname [lindex $fname 0]
            }
-           set diffnparents [expr {[string length $ats] - 1}]
+           makediffhdr $fname $ids
+       } elseif {[string compare -length 3 $line "---"] == 0} {
+           # do nothing
+           return
+       } elseif {[string compare -length 3 $line "+++"] == 0} {
            set diffinhdr 0
+           return
+       }
+       $ctext insert end "$line\n" filesep
 
-       } elseif {![string compare -length 10 "Submodule " $line]} {
-           # start of a new submodule
-           if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
-               set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
-           } else {
-               set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
-           }
-           if {$currdiffsubmod != $fname} {
-               $ctext insert end "\n";     # Add newline after commit message
-           }
-           set curdiffstart [$ctext index "end - 1c"]
-           lappend ctext_file_names ""
-           if {$currdiffsubmod != $fname} {
-               lappend ctext_file_lines $fname
-               makediffhdr $fname $ids
-               set currdiffsubmod $fname
-               $ctext insert end "\n$line\n" filesep
-           } else {
-               $ctext insert end "$line\n" filesep
-           }
-       } elseif {![string compare -length 3 "  >" $line]} {
-           set $currdiffsubmod ""
-           set line [encoding convertfrom $diffencoding $line]
-           $ctext insert end "$line\n" dresult
-       } elseif {![string compare -length 3 "  <" $line]} {
-           set $currdiffsubmod ""
-           set line [encoding convertfrom $diffencoding $line]
-           $ctext insert end "$line\n" d0
-       } elseif {$diffinhdr} {
-           if {![string compare -length 12 "rename from " $line]} {
-               set fname [string range $line [expr 6 + [string first " from " $line] ] end]
-               if {[string index $fname 0] eq "\""} {
-                   set fname [lindex $fname 0]
-               }
-               set fname [encoding convertfrom $fname]
-               set i [lsearch -exact $treediffs($ids) $fname]
-               if {$i >= 0} {
-                   setinlist difffilestart $i $curdiffstart
+    } else {
+       set line [string map {\x1A ^Z} \
+                     [encoding convertfrom $diffencoding $line]]
+       # parse the prefix - one ' ', '-' or '+' for each parent
+       set prefix [string range $line 0 [expr {$diffnparents - 1}]]
+       set tag [expr {$diffnparents > 1? "m": "d"}]
+       set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
+       set words_pre_markup ""
+       set words_post_markup ""
+       if {[string trim $prefix " -+"] eq {}} {
+           # prefix only has " ", "-" and "+" in it: normal diff line
+           set num [string first "-" $prefix]
+           if {$dowords} {
+               set line [string range $line 1 end]
+           }
+           if {$num >= 0} {
+               # removed line, first parent with line is $num
+               if {$num >= $mergemax} {
+                   set num "max"
                }
-           } elseif {![string compare -length 10 $line "rename to "] ||
-                     ![string compare -length 8 $line "copy to "]} {
-               set fname [string range $line [expr 4 + [string first " to " $line] ] end]
-               if {[string index $fname 0] eq "\""} {
-                   set fname [lindex $fname 0]
+               if {$dowords && $worddiff eq [mc "Markup words"]} {
+                   $ctext insert end "\[-$line-\]" $tag$num
+               } else {
+                   $ctext insert end "$line" $tag$num
                }
-               makediffhdr $fname $ids
-           } elseif {[string compare -length 3 $line "---"] == 0} {
-               # do nothing
-               continue
-           } elseif {[string compare -length 3 $line "+++"] == 0} {
-               set diffinhdr 0
-               continue
-           }
-           $ctext insert end "$line\n" filesep
-
-       } else {
-           set line [string map {\x1A ^Z} \
-                          [encoding convertfrom $diffencoding $line]]
-           # parse the prefix - one ' ', '-' or '+' for each parent
-           set prefix [string range $line 0 [expr {$diffnparents - 1}]]
-           set tag [expr {$diffnparents > 1? "m": "d"}]
-           set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
-           set words_pre_markup ""
-           set words_post_markup ""
-           if {[string trim $prefix " -+"] eq {}} {
-               # prefix only has " ", "-" and "+" in it: normal diff line
-               set num [string first "-" $prefix]
-               if {$dowords} {
-                   set line [string range $line 1 end]
+               if {!$dowords} {
+                   $ctext insert end "\n" $tag$num
                }
-               if {$num >= 0} {
-                   # removed line, first parent with line is $num
-                   if {$num >= $mergemax} {
-                       set num "max"
-                   }
-                   if {$dowords && $worddiff eq [mc "Markup words"]} {
-                       $ctext insert end "\[-$line-\]" $tag$num
-                   } else {
-                       $ctext insert end "$line" $tag$num
-                   }
-                   if {!$dowords} {
-                       $ctext insert end "\n" $tag$num
-                   }
-               } else {
-                   set tags {}
-                   if {[string first "+" $prefix] >= 0} {
-                       # added line
-                       lappend tags ${tag}result
-                       if {$diffnparents > 1} {
-                           set num [string first " " $prefix]
-                           if {$num >= 0} {
-                               if {$num >= $mergemax} {
-                                   set num "max"
-                               }
-                               lappend tags m$num
+           } else {
+               set tags {}
+               if {[string first "+" $prefix] >= 0} {
+                   # added line
+                   lappend tags ${tag}result
+                   if {$diffnparents > 1} {
+                       set num [string first " " $prefix]
+                       if {$num >= 0} {
+                           if {$num >= $mergemax} {
+                               set num "max"
                            }
+                           lappend tags m$num
                        }
-                       set words_pre_markup "{+"
-                       set words_post_markup "+}"
                    }
-                   if {$targetline ne {}} {
-                       if {$diffline == $targetline} {
-                           set seehere [$ctext index "end - 1 chars"]
-                           set targetline {}
-                       } else {
-                           incr diffline
-                       }
-                   }
-                   if {$dowords && $worddiff eq [mc "Markup words"]} {
-                       $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
+                   set words_pre_markup "{+"
+                   set words_post_markup "+}"
+               }
+               if {$targetline ne {}} {
+                   if {$diffline == $targetline} {
+                       set diffseehere [$ctext index "end - 1 chars"]
+                       set targetline {}
                    } else {
-                       $ctext insert end "$line" $tags
-                   }
-                   if {!$dowords} {
-                       $ctext insert end "\n" $tags
+                       incr diffline
                    }
                }
-           } elseif {$dowords && $prefix eq "~"} {
-               $ctext insert end "\n" {}
-           } else {
-               # "\ No newline at end of file",
-               # or something else we don't recognize
-               $ctext insert end "$line\n" hunksep
+               if {$dowords && $worddiff eq [mc "Markup words"]} {
+                   $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
+               } else {
+                   $ctext insert end "$line" $tags
+               }
+               if {!$dowords} {
+                   $ctext insert end "\n" $tags
+               }
            }
+       } elseif {$dowords && $prefix eq "~"} {
+           $ctext insert end "\n" {}
+       } else {
+           # "\ No newline at end of file",
+           # or something else we don't recognize
+           $ctext insert end "$line\n" hunksep
        }
     }
-    if {[info exists seehere]} {
-       mark_ctext_line [lindex [split $seehere .] 0]
-    }
-    maybe_scroll_ctext [eof $bdf]
-    $ctext conf -state disabled
-    if {[eof $bdf]} {
-       catch {close $bdf}
-       return 0
-    }
-    return [expr {$nr >= 1000? 2: 1}]
 }
 
 proc changediffdisp {} {
@@ -10878,6 +10993,23 @@ proc listrefs {id} {
     return [list $x $y $z]
 }
 
+proc add_tag_ctext {tag} {
+    global ctext cached_tagcontent tagids
+
+    if {![info exists cached_tagcontent($tag)]} {
+       catch {
+           set cached_tagcontent($tag) [exec git cat-file -p $tag]
+       }
+    }
+    $ctext insert end "[mc "Tag"]: $tag\n" bold
+    if {[info exists cached_tagcontent($tag)]} {
+       set text $cached_tagcontent($tag)
+    } else {
+       set text "[mc "Id"]:  $tagids($tag)"
+    }
+    appendwithlinks $text {}
+}
+
 proc showtag {tag isnew} {
     global ctext cached_tagcontent tagids linknum tagobjid
 
@@ -10888,17 +11020,28 @@ proc showtag {tag isnew} {
     clear_ctext
     settabs 0
     set linknum 0
-    if {![info exists cached_tagcontent($tag)]} {
-       catch {
-           set cached_tagcontent($tag) [exec git cat-file -p $tag]
-       }
+    add_tag_ctext $tag
+    maybe_scroll_ctext 1
+    $ctext conf -state disabled
+    init_flist {}
+}
+
+proc showtags {id isnew} {
+    global idtags ctext linknum
+
+    if {$isnew} {
+       addtohistory [list showtags $id 0] savectextpos
     }
-    if {[info exists cached_tagcontent($tag)]} {
-       set text $cached_tagcontent($tag)
-    } else {
-       set text "[mc "Tag"]: $tag\n[mc "Id"]:  $tagids($tag)"
+    $ctext conf -state normal
+    clear_ctext
+    settabs 0
+    set linknum 0
+    set sep {}
+    foreach tag $idtags($id) {
+       $ctext insert end $sep
+       add_tag_ctext $tag
+       set sep "\n\n"
     }
-    appendwithlinks $text {}
     maybe_scroll_ctext 1
     $ctext conf -state disabled
     init_flist {}
index 68c77f6f8ffd120f0011eb07accdc2849afca834..3bc0f0b5ca0995910e0e517b545b5fb9af626a8b 100755 (executable)
@@ -548,6 +548,20 @@ sub evaluate_uri {
                'sub' => sub { feature_bool('remote_heads', @_) },
                'override' => 0,
                'default' => [0]},
+
+       # Enable showing branches under other refs in addition to heads
+
+       # To set system wide extra branch refs have in $GITWEB_CONFIG
+       # $feature{'extra-branch-refs'}{'default'} = ['dirs', 'of', 'choice'];
+       # To have project specific config enable override in $GITWEB_CONFIG
+       # $feature{'extra-branch-refs'}{'override'} = 1;
+       # and in project config gitweb.extrabranchrefs = dirs of choice
+       # Every directory is separated with whitespace.
+
+       'extra-branch-refs' => {
+               'sub' => \&feature_extra_branch_refs,
+               'override' => 0,
+               'default' => []},
 );
 
 sub gitweb_get_feature {
@@ -626,6 +640,21 @@ sub feature_avatar {
        return @val ? @val : @_;
 }
 
+sub feature_extra_branch_refs {
+       my (@branch_refs) = @_;
+       my $values = git_get_project_config('extrabranchrefs');
+
+       if ($values) {
+               $values = config_to_multi ($values);
+               @branch_refs = ();
+               foreach my $value (@{$values}) {
+                       push @branch_refs, split /\s+/, $value;
+               }
+       }
+
+       return @branch_refs;
+}
+
 # checking HEAD file with -e is fragile if the repository was
 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
 # and then pruned.
@@ -656,6 +685,18 @@ sub filter_snapshot_fmts {
                !$known_snapshot_formats{$_}{'disabled'}} @fmts;
 }
 
+sub filter_and_validate_refs {
+       my @refs = @_;
+       my %unique_refs = ();
+
+       foreach my $ref (@refs) {
+               die_error(500, "Invalid ref '$ref' in 'extra-branch-refs' feature") unless (is_valid_ref_format($ref));
+               # 'heads' are added implicitly in get_branch_refs().
+               $unique_refs{$ref} = 1 if ($ref ne 'heads');
+       }
+       return sort keys %unique_refs;
+}
+
 # If it is set to code reference, it is code that it is to be run once per
 # request, allowing updating configurations that change with each request,
 # while running other code in config file only once.
@@ -994,7 +1035,7 @@ sub evaluate_path_info {
 sub evaluate_and_validate_params {
        our $action = $input_params{'action'};
        if (defined $action) {
-               if (!validate_action($action)) {
+               if (!is_valid_action($action)) {
                        die_error(400, "Invalid action parameter");
                }
        }
@@ -1002,7 +1043,7 @@ sub evaluate_and_validate_params {
        # parameters which are pathnames
        our $project = $input_params{'project'};
        if (defined $project) {
-               if (!validate_project($project)) {
+               if (!is_valid_project($project)) {
                        undef $project;
                        die_error(404, "No such project");
                }
@@ -1010,21 +1051,21 @@ sub evaluate_and_validate_params {
 
        our $project_filter = $input_params{'project_filter'};
        if (defined $project_filter) {
-               if (!validate_pathname($project_filter)) {
+               if (!is_valid_pathname($project_filter)) {
                        die_error(404, "Invalid project_filter parameter");
                }
        }
 
        our $file_name = $input_params{'file_name'};
        if (defined $file_name) {
-               if (!validate_pathname($file_name)) {
+               if (!is_valid_pathname($file_name)) {
                        die_error(400, "Invalid file parameter");
                }
        }
 
        our $file_parent = $input_params{'file_parent'};
        if (defined $file_parent) {
-               if (!validate_pathname($file_parent)) {
+               if (!is_valid_pathname($file_parent)) {
                        die_error(400, "Invalid file parent parameter");
                }
        }
@@ -1032,21 +1073,21 @@ sub evaluate_and_validate_params {
        # parameters which are refnames
        our $hash = $input_params{'hash'};
        if (defined $hash) {
-               if (!validate_refname($hash)) {
+               if (!is_valid_refname($hash)) {
                        die_error(400, "Invalid hash parameter");
                }
        }
 
        our $hash_parent = $input_params{'hash_parent'};
        if (defined $hash_parent) {
-               if (!validate_refname($hash_parent)) {
+               if (!is_valid_refname($hash_parent)) {
                        die_error(400, "Invalid hash parent parameter");
                }
        }
 
        our $hash_base = $input_params{'hash_base'};
        if (defined $hash_base) {
-               if (!validate_refname($hash_base)) {
+               if (!is_valid_refname($hash_base)) {
                        die_error(400, "Invalid hash base parameter");
                }
        }
@@ -1066,7 +1107,7 @@ sub evaluate_and_validate_params {
 
        our $hash_parent_base = $input_params{'hash_parent_base'};
        if (defined $hash_parent_base) {
-               if (!validate_refname($hash_parent_base)) {
+               if (!is_valid_refname($hash_parent_base)) {
                        die_error(400, "Invalid hash parent base parameter");
                }
        }
@@ -1113,7 +1154,7 @@ sub evaluate_git_dir {
        our $git_dir = "$projectroot/$project" if $project;
 }
 
-our (@snapshot_fmts, $git_avatar);
+our (@snapshot_fmts, $git_avatar, @extra_branch_refs);
 sub configure_gitweb_features {
        # list of supported snapshot formats
        our @snapshot_fmts = gitweb_get_feature('snapshot');
@@ -1131,6 +1172,13 @@ sub configure_gitweb_features {
        } else {
                $git_avatar = '';
        }
+
+       our @extra_branch_refs = gitweb_get_feature('extra-branch-refs');
+       @extra_branch_refs = filter_and_validate_refs (@extra_branch_refs);
+}
+
+sub get_branch_refs {
+       return ('heads', @extra_branch_refs);
 }
 
 # custom error handler: 'die <message>' is Internal Server Error
@@ -1418,27 +1466,30 @@ sub href {
 ## ======================================================================
 ## validation, quoting/unquoting and escaping
 
-sub validate_action {
-       my $input = shift || return undef;
+sub is_valid_action {
+       my $input = shift;
        return undef unless exists $actions{$input};
-       return $input;
+       return 1;
 }
 
-sub validate_project {
-       my $input = shift || return undef;
-       if (!validate_pathname($input) ||
+sub is_valid_project {
+       my $input = shift;
+
+       return unless defined $input;
+       if (!is_valid_pathname($input) ||
                !(-d "$projectroot/$input") ||
                !check_export_ok("$projectroot/$input") ||
                ($strict_export && !project_in_list($input))) {
                return undef;
        } else {
-               return $input;
+               return 1;
        }
 }
 
-sub validate_pathname {
-       my $input = shift || return undef;
+sub is_valid_pathname {
+       my $input = shift;
 
+       return undef unless defined $input;
        # no '.' or '..' as elements of path, i.e. no '.' nor '..'
        # at the beginning, at the end, and between slashes.
        # also this catches doubled slashes
@@ -1449,24 +1500,33 @@ sub validate_pathname {
        if ($input =~ m!\0!) {
                return undef;
        }
-       return $input;
+       return 1;
 }
 
-sub validate_refname {
-       my $input = shift || return undef;
+sub is_valid_ref_format {
+       my $input = shift;
 
-       # textual hashes are O.K.
-       if ($input =~ m/^[0-9a-fA-F]{40}$/) {
-               return $input;
-       }
-       # it must be correct pathname
-       $input = validate_pathname($input)
-               or return undef;
+       return undef unless defined $input;
        # restrictions on ref name according to git-check-ref-format
        if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
                return undef;
        }
-       return $input;
+       return 1;
+}
+
+sub is_valid_refname {
+       my $input = shift;
+
+       return undef unless defined $input;
+       # textual hashes are O.K.
+       if ($input =~ m/^[0-9a-fA-F]{40}$/) {
+               return 1;
+       }
+       # it must be correct pathname
+       is_valid_pathname($input) or return undef;
+       # check git-check-ref-format restrictions
+       is_valid_ref_format($input) or return undef;
+       return 1;
 }
 
 # decode sequences of octets in utf8 into Perl's internal form,
@@ -2515,6 +2575,7 @@ sub format_snapshot_links {
 sub get_feed_info {
        my $format = shift || 'Atom';
        my %res = (action => lc($format));
+       my $matched_ref = 0;
 
        # feed links are possible only for project views
        return unless (defined $project);
@@ -2522,12 +2583,17 @@ sub get_feed_info {
        # or don't have specific feed yet (so they should use generic)
        return if (!$action || $action =~ /^(?:tags|heads|forks|tag|search)$/x);
 
-       my $branch;
-       # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
-       # from tag links; this also makes possible to detect branch links
-       if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
-           (defined $hash      && $hash      =~ m!^refs/heads/(.*)$!)) {
-               $branch = $1;
+       my $branch = undef;
+       # branches refs uses 'refs/' + $get_branch_refs()[x] + '/' prefix
+       # (fullname) to differentiate from tag links; this also makes
+       # possible to detect branch links
+       for my $ref (get_branch_refs()) {
+               if ((defined $hash_base && $hash_base =~ m!^refs/\Q$ref\E/(.*)$!) ||
+                   (defined $hash      && $hash      =~ m!^refs/\Q$ref\E/(.*)$!)) {
+                       $branch = $1;
+                       $matched_ref = $ref;
+                       last;
+               }
        }
        # find log type for feed description (title)
        my $type = 'log';
@@ -2540,7 +2606,7 @@ sub get_feed_info {
        }
 
        $res{-title} = $type;
-       $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
+       $res{'hash'} = (defined $branch ? "refs/$matched_ref/$branch" : undef);
        $res{'file_name'} = $file_name;
 
        return %res;
@@ -3193,7 +3259,7 @@ sub git_get_last_activity {
             '--format=%(committer)',
             '--sort=-committerdate',
             '--count=1',
-            'refs/heads') or return;
+            map { "refs/$_" } get_branch_refs ()) or return;
        my $most_recent = <$fd>;
        close $fd or return;
        if (defined $most_recent &&
@@ -3644,7 +3710,7 @@ sub parse_from_to_diffinfo {
 
 sub git_get_heads_list {
        my ($limit, @classes) = @_;
-       @classes = ('heads') unless @classes;
+       @classes = get_branch_refs() unless @classes;
        my @patterns = map { "refs/$_" } @classes;
        my @headslist;
 
@@ -3662,9 +3728,16 @@ sub git_get_heads_list {
                my ($committer, $epoch, $tz) =
                        ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
                $ref_item{'fullname'}  = $name;
-               $name =~ s!^refs/(?:head|remote)s/!!;
+               my $strip_refs = join '|', map { quotemeta } get_branch_refs();
+               $name =~ s!^refs/($strip_refs|remotes)/!!;
+               $ref_item{'name'} = $name;
+               # for refs neither in 'heads' nor 'remotes' we want to
+               # show their ref dir
+               my $ref_dir = (defined $1) ? $1 : '';
+               if ($ref_dir ne '' and $ref_dir ne 'heads' and $ref_dir ne 'remotes') {
+                   $ref_item{'name'} .= ' (' . $ref_dir . ')';
+               }
 
-               $ref_item{'name'}  = $name;
                $ref_item{'id'}    = $hash;
                $ref_item{'title'} = $title || '(no commit message)';
                $ref_item{'epoch'} = $epoch;
@@ -7156,6 +7229,15 @@ sub git_tree {
        git_footer_html();
 }
 
+sub sanitize_for_filename {
+    my $name = shift;
+
+    $name =~ s!/!-!g;
+    $name =~ s/[^[:alnum:]_.-]//g;
+
+    return $name;
+}
+
 sub snapshot_name {
        my ($project, $hash) = @_;
 
@@ -7163,9 +7245,7 @@ sub snapshot_name {
        # path/to/project/.git -> project
        my $name = to_utf8($project);
        $name =~ s,([^/])/*\.git$,$1,;
-       $name = basename($name);
-       # sanitize name
-       $name =~ s/[[:cntrl:]]/?/g;
+       $name = sanitize_for_filename(basename($name));
 
        my $ver = $hash;
        if ($hash =~ /^[0-9a-fA-F]+$/) {
@@ -7179,13 +7259,25 @@ sub snapshot_name {
                $ver = $1;
        } else {
                # branches and other need shortened SHA-1 hash
-               if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
-                       $ver = $1;
+               my $strip_refs = join '|', map { quotemeta } get_branch_refs();
+               if ($hash =~ m!^refs/($strip_refs|remotes)/(.*)$!) {
+                       my $ref_dir = (defined $1) ? $1 : '';
+                       $ver = $2;
+
+                       $ref_dir = sanitize_for_filename($ref_dir);
+                       # for refs neither in heads nor remotes we want to
+                       # add a ref dir to archive name
+                       if ($ref_dir ne '' and $ref_dir ne 'heads' and $ref_dir ne 'remotes') {
+                               $ver = $ref_dir . '-' . $ver;
+                       }
                }
                $ver .= '-' . git_get_short_hash($project, $hash);
        }
+       # special case of sanitization for filename - we change
+       # slashes to dots instead of dashes
        # in case of hierarchical branch names
        $ver =~ s!/!.!g;
+       $ver =~ s/[^[:alnum:]_.-]//g;
 
        # name = project-version_string
        $name = "$name-$ver";
diff --git a/help.c b/help.c
index f068925bb7f26055fb699cda7173a0c06ac46a22..df7d16d7ce52ce9b9f274db92b24aa64bac56ebf 100644 (file)
--- a/help.c
+++ b/help.c
@@ -148,7 +148,7 @@ static void list_commands_in_dir(struct cmdnames *cmds,
        while ((de = readdir(dir)) != NULL) {
                int entlen;
 
-               if (prefixcmp(de->d_name, prefix))
+               if (!starts_with(de->d_name, prefix))
                        continue;
 
                strbuf_setlen(&buf, len);
@@ -255,7 +255,7 @@ static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
        if (!strcmp(var, "help.autocorrect"))
                autocorrect = git_config_int(var,value);
        /* Also use aliases for command lookup */
-       if (!prefixcmp(var, "alias."))
+       if (starts_with(var, "alias."))
                add_cmdname(&aliases, var + 6, strlen(var + 6));
 
        return git_default_config(var, value, cb);
@@ -329,7 +329,7 @@ const char *help_unknown_cmd(const char *cmd)
                if ((n < ARRAY_SIZE(common_cmds)) && !cmp) {
                        /* Yes, this is one of the common commands */
                        n++; /* use the entry from common_cmds[] */
-                       if (!prefixcmp(candidate, cmd)) {
+                       if (starts_with(candidate, cmd)) {
                                /* Give prefix match a very good score */
                                main_cmds.names[i]->len = 0;
                                continue;
@@ -414,7 +414,7 @@ static int append_similar_ref(const char *refname, const unsigned char *sha1,
        struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
        char *branch = strrchr(refname, '/') + 1;
        /* A remote branch of the same name is deemed similar */
-       if (!prefixcmp(refname, "refs/remotes/") &&
+       if (starts_with(refname, "refs/remotes/") &&
            !strcmp(branch, cb->base_ref))
                string_list_append(cb->similar_refs,
                                   refname + strlen("refs/remotes/"));
index 8c464bd8051ed813175b01f832e5e78a91bba8ea..d2c0a625cef558df252af6927cd3a86424674862 100644 (file)
@@ -226,7 +226,7 @@ static int http_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
-       if (!prefixcmp(var, "http.")) {
+       if (starts_with(var, "http.")) {
                int i;
 
                for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
@@ -247,7 +247,7 @@ static struct rpc_service *select_service(const char *name)
        struct rpc_service *svc = NULL;
        int i;
 
-       if (prefixcmp(name, "git-"))
+       if (!starts_with(name, "git-"))
                forbidden("Unsupported service: '%s'", name);
 
        for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
index 34cb70f90ea14a18848bd270463f5a34dc2c8fd3..d4b40c9c60e8caa2b8f8e676ac18b678b6ca2ed6 100644 (file)
@@ -771,7 +771,7 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
                        lock->owner = xmalloc(strlen(ctx->cdata) + 1);
                        strcpy(lock->owner, ctx->cdata);
                } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TIMEOUT)) {
-                       if (!prefixcmp(ctx->cdata, "Second-"))
+                       if (starts_with(ctx->cdata, "Second-"))
                                lock->timeout =
                                        strtol(ctx->cdata + 7, NULL, 10);
                } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
@@ -1579,7 +1579,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
                return;
 
        /* If it's a symref, set the refname; otherwise try for a sha1 */
-       if (!prefixcmp((char *)buffer.buf, "ref: ")) {
+       if (starts_with((char *)buffer.buf, "ref: ")) {
                *symref = xmemdupz((char *)buffer.buf + 5, buffer.len - 6);
        } else {
                get_sha1_hex(buffer.buf, sha1);
diff --git a/http.c b/http.c
index bcf54aa35f96e8f0b87b6e2fd23408991a684b66..70eaa26e88cbcfa62e7d5e967b4e519432319210 100644 (file)
--- a/http.c
+++ b/http.c
@@ -460,7 +460,7 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
                credential_from_url(&http_auth, url);
                if (!ssl_cert_password_required &&
                    getenv("GIT_SSL_CERT_PASSWORD_PROTECTED") &&
-                   !prefixcmp(url, "https://"))
+                   starts_with(url, "https://"))
                        ssl_cert_password_required = 1;
        }
 
@@ -761,6 +761,12 @@ void finish_active_slot(struct active_request_slot *slot)
        if (slot->results != NULL) {
                slot->results->curl_result = slot->curl_result;
                slot->results->http_code = slot->http_code;
+#if LIBCURL_VERSION_NUM >= 0x070a08
+               curl_easy_getinfo(slot->curl, CURLINFO_HTTPAUTH_AVAIL,
+                                 &slot->results->auth_avail);
+#else
+               slot->results->auth_avail = 0;
+#endif
        }
 
        /* Run callback if appropriate */
@@ -994,7 +1000,7 @@ static int update_url_from_redirect(struct strbuf *base,
        if (!strcmp(asked, got->buf))
                return 0;
 
-       if (prefixcmp(asked, base->buf))
+       if (!starts_with(asked, base->buf))
                die("BUG: update_url_from_redirect: %s is not a superset of %s",
                    asked, base->buf);
 
@@ -1100,7 +1106,7 @@ int http_fetch_ref(const char *base, struct ref *ref)
                strbuf_rtrim(&buffer);
                if (buffer.len == 40)
                        ret = get_sha1_hex(buffer.buf, ref->old_sha1);
-               else if (!prefixcmp(buffer.buf, "ref: ")) {
+               else if (starts_with(buffer.buf, "ref: ")) {
                        ref->symref = xstrdup(buffer.buf + 5);
                        ret = 0;
                }
@@ -1201,8 +1207,8 @@ int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
                case 'P':
                        i++;
                        if (i + 52 <= buf.len &&
-                           !prefixcmp(data + i, " pack-") &&
-                           !prefixcmp(data + i + 46, ".pack\n")) {
+                           starts_with(data + i, " pack-") &&
+                           starts_with(data + i + 46, ".pack\n")) {
                                get_sha1_hex(data + i + 6, sha1);
                                fetch_and_setup_pack_index(packs_head, sha1,
                                                      base_url);
diff --git a/http.h b/http.h
index 12ca5c892d61a063c856bcdef9154a103c0aa4bc..cd37d5881cb0e63e52bd33d0b49bed49645340f5 100644 (file)
--- a/http.h
+++ b/http.h
@@ -54,6 +54,7 @@
 struct slot_results {
        CURLcode curl_result;
        long http_code;
+       long auth_avail;
 };
 
 struct active_request_slot {
index 6f5cc4f782ea82fc14ee596c7bac96e2b6f907e7..0bc6f7fae151ea364e9d141b30b8e68d544a4448 100644 (file)
@@ -1263,7 +1263,7 @@ static int count_messages(struct strbuf *all_msgs)
        char *p = all_msgs->buf;
 
        while (1) {
-               if (!prefixcmp(p, "From ")) {
+               if (starts_with(p, "From ")) {
                        p = strstr(p+5, "\nFrom: ");
                        if (!p) break;
                        p = strstr(p+7, "\nDate: ");
@@ -1297,7 +1297,7 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
        data = &all_msgs->buf[*ofs];
        len = all_msgs->len - *ofs;
 
-       if (len < 5 || prefixcmp(data, "From "))
+       if (len < 5 || !starts_with(data, "From "))
                return 0;
 
        p = strchr(data, '\n');
@@ -1339,13 +1339,13 @@ static int git_imap_config(const char *key, const char *val, void *cb)
        if (!strcmp("folder", key)) {
                imap_folder = xstrdup(val);
        } else if (!strcmp("host", key)) {
-               if (!prefixcmp(val, "imap:"))
+               if (starts_with(val, "imap:"))
                        val += 5;
-               else if (!prefixcmp(val, "imaps:")) {
+               else if (starts_with(val, "imaps:")) {
                        val += 6;
                        server.use_ssl = 1;
                }
-               if (!prefixcmp(val, "//"))
+               if (starts_with(val, "//"))
                        val += 2;
                server.host = xstrdup(val);
        } else if (!strcmp("user", key))
index e958d0748f11d82995f63d06b7e6ed05b2e7e4f1..642faffdb7d149f162c8716eb13dd878d16baa4b 100644 (file)
@@ -98,7 +98,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
        struct object *obj;
        enum decoration_type type = DECORATION_NONE;
 
-       if (!prefixcmp(refname, "refs/replace/")) {
+       if (starts_with(refname, "refs/replace/")) {
                unsigned char original_sha1[20];
                if (!read_replace_refs)
                        return 0;
@@ -116,11 +116,11 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
        if (!obj)
                return 0;
 
-       if (!prefixcmp(refname, "refs/heads/"))
+       if (starts_with(refname, "refs/heads/"))
                type = DECORATION_REF_LOCAL;
-       else if (!prefixcmp(refname, "refs/remotes/"))
+       else if (starts_with(refname, "refs/remotes/"))
                type = DECORATION_REF_REMOTE;
-       else if (!prefixcmp(refname, "refs/tags/"))
+       else if (starts_with(refname, "refs/tags/"))
                type = DECORATION_REF_TAG;
        else if (!strcmp(refname, "refs/stash"))
                type = DECORATION_REF_STASH;
index dbb7104c043b14f2a43d67e1ca87ce88f4a55408..a18bd15dd3dcf303909b4b541f35815705a3f50b 100644 (file)
@@ -2063,13 +2063,13 @@ int parse_merge_opt(struct merge_options *o, const char *s)
                o->recursive_variant = MERGE_RECURSIVE_THEIRS;
        else if (!strcmp(s, "subtree"))
                o->subtree_shift = "";
-       else if (!prefixcmp(s, "subtree="))
+       else if (starts_with(s, "subtree="))
                o->subtree_shift = s + strlen("subtree=");
        else if (!strcmp(s, "patience"))
                o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF);
        else if (!strcmp(s, "histogram"))
                o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF);
-       else if (!prefixcmp(s, "diff-algorithm=")) {
+       else if (starts_with(s, "diff-algorithm=")) {
                long value = parse_algorithm_value(s + strlen("diff-algorithm="));
                if (value < 0)
                        return -1;
@@ -2088,7 +2088,7 @@ int parse_merge_opt(struct merge_options *o, const char *s)
                o->renormalize = 1;
        else if (!strcmp(s, "no-renormalize"))
                o->renormalize = 0;
-       else if (!prefixcmp(s, "rename-threshold=")) {
+       else if (starts_with(s, "rename-threshold=")) {
                const char *score = s + strlen("rename-threshold=");
                if ((o->rename_score = parse_rename_score(&score)) == -1 || *score != 0)
                        return -1;
index 7bb3473dbe44c1f8325ee6891620eec67163dfcd..2975dcd581024cd483953b47636466b79c95bafe 100644 (file)
@@ -70,7 +70,7 @@ static combine_notes_fn parse_combine_notes_fn(const char *v)
 static int notes_rewrite_config(const char *k, const char *v, void *cb)
 {
        struct notes_rewrite_cfg *c = cb;
-       if (!prefixcmp(k, "notes.rewrite.") && !strcmp(k+14, c->cmd)) {
+       if (starts_with(k, "notes.rewrite.") && !strcmp(k+14, c->cmd)) {
                c->enabled = git_config_bool(k, v);
                return 0;
        } else if (!c->mode_from_env && !strcmp(k, "notes.rewritemode")) {
@@ -85,7 +85,7 @@ static int notes_rewrite_config(const char *k, const char *v, void *cb)
        } else if (!c->refs_from_env && !strcmp(k, "notes.rewriteref")) {
                /* note that a refs/ prefix is implied in the
                 * underlying for_each_glob_ref */
-               if (!prefixcmp(v, "refs/notes/"))
+               if (starts_with(v, "refs/notes/"))
                        string_list_add_refs_by_glob(c->refs, v);
                else
                        warning(_("Refusing to rewrite notes in %s"
diff --git a/notes.c b/notes.c
index b69c0b82577e0d4958ddf3efbb4aec5a9c5fa99e..5f07c0b7f28e09bd2f7969ea08b00b319a226920 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -1243,9 +1243,9 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
                if (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {
                        strbuf_addstr(sb, "\nNotes:\n");
                } else {
-                       if (!prefixcmp(ref, "refs/"))
+                       if (starts_with(ref, "refs/"))
                                ref += 5;
-                       if (!prefixcmp(ref, "notes/"))
+                       if (starts_with(ref, "notes/"))
                                ref += 6;
                        strbuf_addf(sb, "\nNotes (%s):\n", ref);
                }
@@ -1293,9 +1293,9 @@ int copy_note(struct notes_tree *t,
 
 void expand_notes_ref(struct strbuf *sb)
 {
-       if (!prefixcmp(sb->buf, "refs/notes/"))
+       if (starts_with(sb->buf, "refs/notes/"))
                return; /* we're happy */
-       else if (!prefixcmp(sb->buf, "notes/"))
+       else if (starts_with(sb->buf, "notes/"))
                strbuf_insert(sb, 0, "refs/", 5);
        else
                strbuf_insert(sb, 0, "refs/notes/", 11);
diff --git a/pager.c b/pager.c
index fa19765eb9e60d2dbc17887773fff4ad66a32c37..345b0bc4b58ef641a653d6244d2ef7558fc84347 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -151,7 +151,7 @@ int decimal_width(int number)
 static int pager_command_config(const char *var, const char *value, void *data)
 {
        struct pager_config *c = data;
-       if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd)) {
+       if (starts_with(var, "pager.") && !strcmp(var + 6, c->cmd)) {
                int b = git_config_maybe_bool(var, value);
                if (b >= 0)
                        c->want = b;
index 62e9b1cc6831768315dd74eac30348668de22da3..7b8d3faa171309e84bff23c70206a9c8bd99cc71 100644 (file)
@@ -273,13 +273,13 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
                        if (options->flags & PARSE_OPT_NONEG)
                                continue;
                        /* negated and abbreviated very much? */
-                       if (!prefixcmp("no-", arg)) {
+                       if (starts_with("no-", arg)) {
                                flags |= OPT_UNSET;
                                goto is_abbreviated;
                        }
                        /* negated? */
-                       if (prefixcmp(arg, "no-")) {
-                               if (!prefixcmp(long_name, "no-")) {
+                       if (!starts_with(arg, "no-")) {
+                               if (starts_with(long_name, "no-")) {
                                        long_name += 3;
                                        opt_flags |= OPT_UNSET;
                                        goto again;
@@ -289,7 +289,7 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
                        flags |= OPT_UNSET;
                        rest = skip_prefix(arg + 3, long_name);
                        /* abbreviated and negated? */
-                       if (!rest && !prefixcmp(long_name, arg + 3))
+                       if (!rest && starts_with(long_name, arg + 3))
                                goto is_abbreviated;
                        if (!rest)
                                continue;
@@ -334,7 +334,7 @@ static void check_typos(const char *arg, const struct option *options)
        if (strlen(arg) < 3)
                return;
 
-       if (!prefixcmp(arg, "no-")) {
+       if (starts_with(arg, "no-")) {
                error ("did you mean `--%s` (with two dashes ?)", arg);
                exit(129);
        }
@@ -342,7 +342,7 @@ static void check_typos(const char *arg, const struct option *options)
        for (; options->type != OPTION_END; options++) {
                if (!options->long_name)
                        continue;
-               if (!prefixcmp(options->long_name, arg)) {
+               if (starts_with(options->long_name, arg)) {
                        error ("did you mean `--%s` (with two dashes ?)", arg);
                        exit(129);
                }
index 8736006ed73560ebb05abac2debb04d5117dc114..d670cb9669f213951b9b2cac332c7869be6ca2ee 100644 (file)
@@ -161,9 +161,6 @@ struct option {
          N_("no-op (backward compatibility)"),         \
          PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb }
 
-/* Deprecated synonym */
-#define OPT_BOOLEAN OPT_COUNTUP
-
 /* parse_options() will filter out the processed options and leave the
  * non-option arguments in argv[]. usagestr strings should be marked
  * for translation with N_().
@@ -232,15 +229,15 @@ extern int parse_opt_tertiary(const struct option *, const char *, int);
 extern int parse_opt_string_list(const struct option *, const char *, int);
 extern int parse_opt_noop_cb(const struct option *, const char *, int);
 
-#define OPT__VERBOSE(var, h)  OPT_BOOLEAN('v', "verbose", (var), (h))
-#define OPT__QUIET(var, h)    OPT_BOOLEAN('q', "quiet",   (var), (h))
+#define OPT__VERBOSE(var, h)  OPT_COUNTUP('v', "verbose", (var), (h))
+#define OPT__QUIET(var, h)    OPT_COUNTUP('q', "quiet",   (var), (h))
 #define OPT__VERBOSITY(var) \
        { OPTION_CALLBACK, 'v', "verbose", (var), NULL, N_("be more verbose"), \
          PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }, \
        { OPTION_CALLBACK, 'q', "quiet", (var), NULL, N_("be more quiet"), \
          PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }
-#define OPT__DRY_RUN(var, h)  OPT_BOOLEAN('n', "dry-run", (var), (h))
-#define OPT__FORCE(var, h)    OPT_BOOLEAN('f', "force",   (var), (h))
+#define OPT__DRY_RUN(var, h)  OPT_BOOL('n', "dry-run", (var), (h))
+#define OPT__FORCE(var, h)    OPT_COUNTUP('f', "force",   (var), (h))
 #define OPT__ABBREV(var)  \
        { OPTION_CALLBACK, 0, "abbrev", (var), N_("n"), \
          N_("use <n> digits to display SHA-1s"),       \
index 87b3b82f1fd9baee7758159e5e3119b6da0655e3..52d38a4b4fb6cbb4928bf3084b773651f14d7e72 100644 (file)
@@ -154,7 +154,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
                                        magic |= pathspec_magic[i].bit;
                                        break;
                                }
-                               if (!prefixcmp(copyfrom, "prefix:")) {
+                               if (starts_with(copyfrom, "prefix:")) {
                                        char *endptr;
                                        pathspec_prefix = strtol(copyfrom + 7,
                                                                 &endptr, 10);
index 70f19501d0e0c0dd625976519fd039d5c7a8b314..bc63b3b80e5b2853f920ba66fe977c7cc0921c78 100644 (file)
@@ -24,8 +24,8 @@ static void packet_trace(const char *buf, unsigned int len, int write)
        strbuf_addf(&out, "packet: %12s%c ",
                    packet_trace_prefix, write ? '>' : '<');
 
-       if ((len >= 4 && !prefixcmp(buf, "PACK")) ||
-           (len >= 5 && !prefixcmp(buf+1, "PACK"))) {
+       if ((len >= 4 && starts_with(buf, "PACK")) ||
+           (len >= 5 && starts_with(buf+1, "PACK"))) {
                strbuf_addstr(&out, "PACK ...");
                unsetenv(trace_key);
        }
index 962e82be8633217b811a8c8c87b892721b35f662..87db08bd749e74fef0b2372ab71ea98baf57b322 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -40,7 +40,7 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
        const char *fmt;
        int i;
 
-       if (prefixcmp(var, "pretty."))
+       if (!starts_with(var, "pretty."))
                return 0;
 
        name = var + strlen("pretty.");
@@ -67,7 +67,7 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
        commit_format->name = xstrdup(name);
        commit_format->format = CMIT_FMT_USERFORMAT;
        git_config_string(&fmt, var, value);
-       if (!prefixcmp(fmt, "format:") || !prefixcmp(fmt, "tformat:")) {
+       if (starts_with(fmt, "format:") || starts_with(fmt, "tformat:")) {
                commit_format->is_tformat = fmt[0] == 't';
                fmt = strchr(fmt, ':') + 1;
        } else if (strchr(fmt, '%'))
@@ -115,7 +115,7 @@ static struct cmt_fmt_map *find_commit_format_recursive(const char *sought,
        for (i = 0; i < commit_formats_len; i++) {
                size_t match_len;
 
-               if (prefixcmp(commit_formats[i].name, sought))
+               if (!starts_with(commit_formats[i].name, sought))
                        continue;
 
                match_len = strlen(commit_formats[i].name);
@@ -151,7 +151,7 @@ void get_commit_format(const char *arg, struct rev_info *rev)
                rev->commit_format = CMIT_FMT_DEFAULT;
                return;
        }
-       if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) {
+       if (starts_with(arg, "format:") || starts_with(arg, "tformat:")) {
                save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
                return;
        }
@@ -840,10 +840,10 @@ static void parse_commit_header(struct format_commit_context *context)
 
                if (i == eol) {
                        break;
-               } else if (!prefixcmp(msg + i, "author ")) {
+               } else if (starts_with(msg + i, "author ")) {
                        context->author.off = i + 7;
                        context->author.len = eol - i - 7;
-               } else if (!prefixcmp(msg + i, "committer ")) {
+               } else if (starts_with(msg + i, "committer ")) {
                        context->committer.off = i + 10;
                        context->committer.len = eol - i - 10;
                }
@@ -983,7 +983,7 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
 
                if (!end)
                        return 0;
-               if (!prefixcmp(begin, "auto,")) {
+               if (starts_with(begin, "auto,")) {
                        if (!want_color(c->pretty_ctx->color))
                                return end - placeholder + 1;
                        begin += 5;
@@ -994,16 +994,16 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
                strbuf_addstr(sb, color);
                return end - placeholder + 1;
        }
-       if (!prefixcmp(placeholder + 1, "red")) {
+       if (starts_with(placeholder + 1, "red")) {
                strbuf_addstr(sb, GIT_COLOR_RED);
                return 4;
-       } else if (!prefixcmp(placeholder + 1, "green")) {
+       } else if (starts_with(placeholder + 1, "green")) {
                strbuf_addstr(sb, GIT_COLOR_GREEN);
                return 6;
-       } else if (!prefixcmp(placeholder + 1, "blue")) {
+       } else if (starts_with(placeholder + 1, "blue")) {
                strbuf_addstr(sb, GIT_COLOR_BLUE);
                return 5;
-       } else if (!prefixcmp(placeholder + 1, "reset")) {
+       } else if (starts_with(placeholder + 1, "reset")) {
                strbuf_addstr(sb, GIT_COLOR_RESET);
                return 6;
        } else
@@ -1060,11 +1060,11 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
                        end = strchr(start, ')');
                        if (!end || end == start)
                                return 0;
-                       if (!prefixcmp(start, "trunc)"))
+                       if (starts_with(start, "trunc)"))
                                c->truncate = trunc_right;
-                       else if (!prefixcmp(start, "ltrunc)"))
+                       else if (starts_with(start, "ltrunc)"))
                                c->truncate = trunc_left;
-                       else if (!prefixcmp(start, "mtrunc)"))
+                       else if (starts_with(start, "mtrunc)"))
                                c->truncate = trunc_middle;
                        else
                                return 0;
@@ -1089,7 +1089,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
        /* these are independent of the commit */
        switch (placeholder[0]) {
        case 'C':
-               if (!prefixcmp(placeholder + 1, "(auto)")) {
+               if (starts_with(placeholder + 1, "(auto)")) {
                        c->auto_color = 1;
                        return 7; /* consumed 7 bytes, "C(auto)" */
                } else {
@@ -1556,7 +1556,7 @@ static void pp_header(struct pretty_print_context *pp,
                        continue;
                }
 
-               if (!prefixcmp(line, "parent ")) {
+               if (starts_with(line, "parent ")) {
                        if (linelen != 48)
                                die("bad parent line in commit");
                        continue;
@@ -1580,11 +1580,11 @@ static void pp_header(struct pretty_print_context *pp,
                 * FULL shows both authors but not dates.
                 * FULLER shows both authors and dates.
                 */
-               if (!prefixcmp(line, "author ")) {
+               if (starts_with(line, "author ")) {
                        strbuf_grow(sb, linelen + 80);
                        pp_user_info(pp, "Author", sb, line + 7, encoding);
                }
-               if (!prefixcmp(line, "committer ") &&
+               if (starts_with(line, "committer ") &&
                    (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
                        strbuf_grow(sb, linelen + 80);
                        pp_user_info(pp, "Commit", sb, line + 10, encoding);
diff --git a/refs.c b/refs.c
index 5e5a3824b992132aaac8d86698feebcb773e13c6..39261368f5656273b0910c5b61a58d215afbcc5d 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -637,7 +637,7 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)
        struct ref_entry *old_current_ref;
        int retval;
 
-       if (prefixcmp(entry->name, data->base))
+       if (!starts_with(entry->name, data->base))
                return 0;
 
        if (!(data->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
@@ -1042,7 +1042,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
                if (refname) {
                        last = create_ref_entry(refname, sha1, REF_ISPACKED, 1);
                        if (peeled == PEELED_FULLY ||
-                           (peeled == PEELED_TAGS && !prefixcmp(refname, "refs/tags/")))
+                           (peeled == PEELED_TAGS && starts_with(refname, "refs/tags/")))
                                last->flag |= REF_KNOWS_PEELED;
                        add_ref(dir, last);
                        continue;
@@ -1376,7 +1376,7 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
                                        return NULL;
                        }
                        buffer[len] = 0;
-                       if (!prefixcmp(buffer, "refs/") &&
+                       if (starts_with(buffer, "refs/") &&
                                        !check_refname_format(buffer, 0)) {
                                strcpy(refname_buffer, buffer);
                                refname = refname_buffer;
@@ -1415,7 +1415,7 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
                /*
                 * Is it a symbolic ref?
                 */
-               if (prefixcmp(buffer, "ref:")) {
+               if (!starts_with(buffer, "ref:")) {
                        /*
                         * Please note that FETCH_HEAD has a second
                         * line containing other data.
@@ -1837,7 +1837,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
        struct ref_filter filter;
        int ret;
 
-       if (!prefix && prefixcmp(pattern, "refs/"))
+       if (!prefix && !starts_with(pattern, "refs/"))
                strbuf_addstr(&real_pattern, "refs/");
        else if (prefix)
                strbuf_addstr(&real_pattern, prefix);
@@ -1874,9 +1874,9 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
 const char *prettify_refname(const char *name)
 {
        return name + (
-               !prefixcmp(name, "refs/heads/") ? 11 :
-               !prefixcmp(name, "refs/tags/") ? 10 :
-               !prefixcmp(name, "refs/remotes/") ? 13 :
+               starts_with(name, "refs/heads/") ? 11 :
+               starts_with(name, "refs/tags/") ? 10 :
+               starts_with(name, "refs/remotes/") ? 13 :
                0);
 }
 
@@ -2244,7 +2244,7 @@ static int pack_if_possible_fn(struct ref_entry *entry, void *cb_data)
        struct pack_refs_cb_data *cb = cb_data;
        enum peel_status peel_status;
        struct ref_entry *packed_entry;
-       int is_tag_ref = !prefixcmp(entry->name, "refs/tags/");
+       int is_tag_ref = starts_with(entry->name, "refs/tags/");
 
        /* ALWAYS pack tags */
        if (!(cb->flags & PACK_REFS_ALL) && !is_tag_ref)
@@ -2679,9 +2679,9 @@ int log_ref_setup(const char *refname, char *logfile, int bufsize)
 
        git_snpath(logfile, bufsize, "logs/%s", refname);
        if (log_all_ref_updates &&
-           (!prefixcmp(refname, "refs/heads/") ||
-            !prefixcmp(refname, "refs/remotes/") ||
-            !prefixcmp(refname, "refs/notes/") ||
+           (starts_with(refname, "refs/heads/") ||
+            starts_with(refname, "refs/remotes/") ||
+            starts_with(refname, "refs/notes/") ||
             !strcmp(refname, "HEAD"))) {
                if (safe_create_leading_directories(logfile) < 0)
                        return error("unable to create directory for %s",
@@ -2751,7 +2751,7 @@ static int log_ref_write(const char *refname, const unsigned char *old_sha1,
 
 static int is_branch(const char *refname)
 {
-       return !strcmp(refname, "HEAD") || !prefixcmp(refname, "refs/heads/");
+       return !strcmp(refname, "HEAD") || starts_with(refname, "refs/heads/");
 }
 
 int write_ref_sha1(struct ref_lock *lock,
@@ -3450,7 +3450,7 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
 {
        if (!strcmp("transfer.hiderefs", var) ||
            /* NEEDSWORK: use parse_config_key() once both are merged */
-           (!prefixcmp(var, section) && var[strlen(section)] == '.' &&
+           (starts_with(var, section) && var[strlen(section)] == '.' &&
             !strcmp(var + strlen(section), ".hiderefs"))) {
                char *ref;
                int len;
@@ -3478,7 +3478,7 @@ int ref_is_hidden(const char *refname)
                return 0;
        for_each_string_list_item(item, hide_refs) {
                int len;
-               if (prefixcmp(refname, item->string))
+               if (!starts_with(refname, item->string))
                        continue;
                len = strlen(item->string);
                if (!refname[len] || refname[len] == '/')
index c9b891adbf134193f07681a631ae368671e04aa6..e38c4b026f2ad63181c765cd38ceb72ef30c4ee8 100644 (file)
@@ -217,7 +217,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
        free_discovery(last);
 
        strbuf_addf(&refs_url, "%sinfo/refs", url.buf);
-       if ((!prefixcmp(url.buf, "http://") || !prefixcmp(url.buf, "https://")) &&
+       if ((starts_with(url.buf, "http://") || starts_with(url.buf, "https://")) &&
             git_env_bool("GIT_SMART_HTTP", 1)) {
                maybe_smart = 1;
                if (!strchr(url.buf, '?'))
@@ -394,25 +394,29 @@ static size_t rpc_in(char *ptr, size_t eltsize,
        return size;
 }
 
-static int run_slot(struct active_request_slot *slot)
+static int run_slot(struct active_request_slot *slot,
+                   struct slot_results *results)
 {
        int err;
-       struct slot_results results;
+       struct slot_results results_buf;
 
-       slot->results = &results;
+       if (!results)
+               results = &results_buf;
+
+       slot->results = results;
        slot->curl_result = curl_easy_perform(slot->curl);
        finish_active_slot(slot);
 
-       err = handle_curl_result(&results);
+       err = handle_curl_result(results);
        if (err != HTTP_OK && err != HTTP_REAUTH) {
                error("RPC failed; result=%d, HTTP code = %ld",
-                     results.curl_result, results.http_code);
+                     results->curl_result, results->http_code);
        }
 
        return err;
 }
 
-static int probe_rpc(struct rpc_state *rpc)
+static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
 {
        struct active_request_slot *slot;
        struct curl_slist *headers = NULL;
@@ -434,7 +438,7 @@ static int probe_rpc(struct rpc_state *rpc)
        curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
        curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);
 
-       err = run_slot(slot);
+       err = run_slot(slot, results);
 
        curl_slist_free_all(headers);
        strbuf_release(&buf);
@@ -449,6 +453,7 @@ static int post_rpc(struct rpc_state *rpc)
        char *gzip_body = NULL;
        size_t gzip_size = 0;
        int err, large_request = 0;
+       int needs_100_continue = 0;
 
        /* Try to load the entire request, if we can fit it into the
         * allocated buffer space we can use HTTP/1.0 and avoid the
@@ -472,18 +477,24 @@ static int post_rpc(struct rpc_state *rpc)
        }
 
        if (large_request) {
+               struct slot_results results;
+
                do {
-                       err = probe_rpc(rpc);
+                       err = probe_rpc(rpc, &results);
                        if (err == HTTP_REAUTH)
                                credential_fill(&http_auth);
                } while (err == HTTP_REAUTH);
                if (err != HTTP_OK)
                        return -1;
+
+               if (results.auth_avail & CURLAUTH_GSSNEGOTIATE)
+                       needs_100_continue = 1;
        }
 
        headers = curl_slist_append(headers, rpc->hdr_content_type);
        headers = curl_slist_append(headers, rpc->hdr_accept);
-       headers = curl_slist_append(headers, "Expect:");
+       headers = curl_slist_append(headers, needs_100_continue ?
+               "Expect: 100-continue" : "Expect:");
 
 retry:
        slot = get_active_slot();
@@ -574,7 +585,7 @@ static int post_rpc(struct rpc_state *rpc)
        curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
        curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
 
-       err = run_slot(slot);
+       err = run_slot(slot, NULL);
        if (err == HTTP_REAUTH && !large_request) {
                credential_fill(&http_auth);
                goto retry;
@@ -755,7 +766,7 @@ static void parse_fetch(struct strbuf *buf)
        int alloc_heads = 0, nr_heads = 0;
 
        do {
-               if (!prefixcmp(buf->buf, "fetch ")) {
+               if (starts_with(buf->buf, "fetch ")) {
                        char *p = buf->buf + strlen("fetch ");
                        char *name;
                        struct ref *ref;
@@ -878,7 +889,7 @@ static void parse_push(struct strbuf *buf)
        int alloc_spec = 0, nr_spec = 0, i, ret;
 
        do {
-               if (!prefixcmp(buf->buf, "push ")) {
+               if (starts_with(buf->buf, "push ")) {
                        ALLOC_GROW(specs, nr_spec + 1, alloc_spec);
                        specs[nr_spec++] = xstrdup(buf->buf + 5);
                }
@@ -941,19 +952,19 @@ int main(int argc, const char **argv)
                }
                if (buf.len == 0)
                        break;
-               if (!prefixcmp(buf.buf, "fetch ")) {
+               if (starts_with(buf.buf, "fetch ")) {
                        if (nongit)
                                die("Fetch attempted without a local repo");
                        parse_fetch(&buf);
 
-               } else if (!strcmp(buf.buf, "list") || !prefixcmp(buf.buf, "list ")) {
+               } else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) {
                        int for_push = !!strstr(buf.buf + 4, "for-push");
                        output_refs(get_refs(for_push));
 
-               } else if (!prefixcmp(buf.buf, "push ")) {
+               } else if (starts_with(buf.buf, "push ")) {
                        parse_push(&buf);
 
-               } else if (!prefixcmp(buf.buf, "option ")) {
+               } else if (starts_with(buf.buf, "option ")) {
                        char *name = buf.buf + strlen("option ");
                        char *value = strchr(name, ' ');
                        int result;
index d7cd5d272fd23624223f37ec8bda7d4fa8c39bce..078f1ffa417092e1c783b16d782b2aa69417a591 100644 (file)
@@ -82,7 +82,7 @@ static int parse_rev_note(const char *msg, struct rev_note *res)
                len = end ? end - msg : strlen(msg);
 
                key = "Revision-number: ";
-               if (!prefixcmp(msg, key)) {
+               if (starts_with(msg, key)) {
                        long i;
                        char *end;
                        value = msg + strlen(key);
@@ -154,7 +154,7 @@ static void check_or_regenerate_marks(int latestrev)
        } else {
                strbuf_addf(&sb, ":%d ", latestrev);
                while (strbuf_getline(&line, marksfile, '\n') != EOF) {
-                       if (!prefixcmp(line.buf, sb.buf)) {
+                       if (starts_with(line.buf, sb.buf)) {
                                found++;
                                break;
                        }
@@ -264,7 +264,7 @@ static int do_command(struct strbuf *line)
                return 1;       /* end of command stream, quit */
        }
        if (batch_cmd) {
-               if (prefixcmp(batch_cmd->name, line->buf))
+               if (!starts_with(batch_cmd->name, line->buf))
                        die("Active %s batch interrupted by %s", batch_cmd->name, line->buf);
                /* buffer batch lines */
                string_list_append(&batchlines, line->buf);
@@ -272,7 +272,7 @@ static int do_command(struct strbuf *line)
        }
 
        for (p = input_command_list; p->name; p++) {
-               if (!prefixcmp(line->buf, p->name) && (strlen(p->name) == line->len ||
+               if (starts_with(line->buf, p->name) && (strlen(p->name) == line->len ||
                                line->buf[strlen(p->name)] == ' ')) {
                        if (p->batchable) {
                                batch_cmd = p;
@@ -304,7 +304,7 @@ int main(int argc, char **argv)
        remote = remote_get(argv[1]);
        url_in = (argc == 3) ? argv[2] : remote->url[0];
 
-       if (!prefixcmp(url_in, "file://")) {
+       if (starts_with(url_in, "file://")) {
                dump_from_file = 1;
                url = url_decode(url_in + sizeof("file://")-1);
        } else {
index 9f1a8aa2c499ae5d2eb8f76f8218eb62937eea51..a89efab5b766ba9374c3a09656b2d56593884c8e 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -76,7 +76,7 @@ static const char *alias_url(const char *url, struct rewrites *r)
                if (!r->rewrite[i])
                        continue;
                for (j = 0; j < r->rewrite[i]->instead_of_nr; j++) {
-                       if (!prefixcmp(url, r->rewrite[i]->instead_of[j].s) &&
+                       if (starts_with(url, r->rewrite[i]->instead_of[j].s) &&
                            (!longest ||
                             longest->len < r->rewrite[i]->instead_of[j].len)) {
                                longest = &(r->rewrite[i]->instead_of[j]);
@@ -239,13 +239,13 @@ static void read_remotes_file(struct remote *remote)
                int value_list;
                char *s, *p;
 
-               if (!prefixcmp(buffer, "URL:")) {
+               if (starts_with(buffer, "URL:")) {
                        value_list = 0;
                        s = buffer + 4;
-               } else if (!prefixcmp(buffer, "Push:")) {
+               } else if (starts_with(buffer, "Push:")) {
                        value_list = 1;
                        s = buffer + 5;
-               } else if (!prefixcmp(buffer, "Pull:")) {
+               } else if (starts_with(buffer, "Pull:")) {
                        value_list = 2;
                        s = buffer + 5;
                } else
@@ -337,7 +337,7 @@ static int handle_config(const char *key, const char *value, void *cb)
        const char *subkey;
        struct remote *remote;
        struct branch *branch;
-       if (!prefixcmp(key, "branch.")) {
+       if (starts_with(key, "branch.")) {
                name = key + 7;
                subkey = strrchr(name, '.');
                if (!subkey)
@@ -361,7 +361,7 @@ static int handle_config(const char *key, const char *value, void *cb)
                }
                return 0;
        }
-       if (!prefixcmp(key, "url.")) {
+       if (starts_with(key, "url.")) {
                struct rewrite *rewrite;
                name = key + 4;
                subkey = strrchr(name, '.');
@@ -380,7 +380,7 @@ static int handle_config(const char *key, const char *value, void *cb)
                }
        }
 
-       if (prefixcmp(key,  "remote."))
+       if (!starts_with(key,  "remote."))
                return 0;
        name = key + 7;
 
@@ -487,7 +487,7 @@ static void read_config(void)
        current_branch = NULL;
        head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
        if (head_ref && (flag & REF_ISSYMREF) &&
-           !prefixcmp(head_ref, "refs/heads/")) {
+           starts_with(head_ref, "refs/heads/")) {
                current_branch =
                        make_branch(head_ref + strlen("refs/heads/"), 0);
        }
@@ -745,35 +745,66 @@ int for_each_remote(each_remote_fn fn, void *priv)
        return result;
 }
 
-void ref_remove_duplicates(struct ref *ref_map)
+static void handle_duplicate(struct ref *ref1, struct ref *ref2)
+{
+       if (strcmp(ref1->name, ref2->name)) {
+               if (ref1->fetch_head_status != FETCH_HEAD_IGNORE &&
+                   ref2->fetch_head_status != FETCH_HEAD_IGNORE) {
+                       die(_("Cannot fetch both %s and %s to %s"),
+                           ref1->name, ref2->name, ref2->peer_ref->name);
+               } else if (ref1->fetch_head_status != FETCH_HEAD_IGNORE &&
+                          ref2->fetch_head_status == FETCH_HEAD_IGNORE) {
+                       warning(_("%s usually tracks %s, not %s"),
+                               ref2->peer_ref->name, ref2->name, ref1->name);
+               } else if (ref1->fetch_head_status == FETCH_HEAD_IGNORE &&
+                          ref2->fetch_head_status == FETCH_HEAD_IGNORE) {
+                       die(_("%s tracks both %s and %s"),
+                           ref2->peer_ref->name, ref1->name, ref2->name);
+               } else {
+                       /*
+                        * This last possibility doesn't occur because
+                        * FETCH_HEAD_IGNORE entries always appear at
+                        * the end of the list.
+                        */
+                       die(_("Internal error"));
+               }
+       }
+       free(ref2->peer_ref);
+       free(ref2);
+}
+
+struct ref *ref_remove_duplicates(struct ref *ref_map)
 {
        struct string_list refs = STRING_LIST_INIT_NODUP;
-       struct string_list_item *item = NULL;
-       struct ref *prev = NULL, *next = NULL;
-       for (; ref_map; prev = ref_map, ref_map = next) {
-               next = ref_map->next;
-               if (!ref_map->peer_ref)
-                       continue;
+       struct ref *retval = NULL;
+       struct ref **p = &retval;
 
-               item = string_list_lookup(&refs, ref_map->peer_ref->name);
-               if (item) {
-                       if (strcmp(((struct ref *)item->util)->name,
-                                  ref_map->name))
-                               die("%s tracks both %s and %s",
-                                   ref_map->peer_ref->name,
-                                   ((struct ref *)item->util)->name,
-                                   ref_map->name);
-                       prev->next = ref_map->next;
-                       free(ref_map->peer_ref);
-                       free(ref_map);
-                       ref_map = prev; /* skip this; we freed it */
-                       continue;
-               }
+       while (ref_map) {
+               struct ref *ref = ref_map;
+
+               ref_map = ref_map->next;
+               ref->next = NULL;
 
-               item = string_list_insert(&refs, ref_map->peer_ref->name);
-               item->util = ref_map;
+               if (!ref->peer_ref) {
+                       *p = ref;
+                       p = &ref->next;
+               } else {
+                       struct string_list_item *item =
+                               string_list_insert(&refs, ref->peer_ref->name);
+
+                       if (item->util) {
+                               /* Entry already existed */
+                               handle_duplicate((struct ref *)item->util, ref);
+                       } else {
+                               *p = ref;
+                               p = &ref->next;
+                               item->util = ref;
+                       }
+               }
        }
+
        string_list_clear(&refs, 0);
+       return retval;
 }
 
 int remote_has_url(struct remote *remote, const char *url)
@@ -821,10 +852,12 @@ static int match_name_with_pattern(const char *key, const char *name,
        return ret;
 }
 
-static int query_refspecs(struct refspec *refs, int ref_count, struct refspec *query)
+int query_refspecs(struct refspec *refs, int ref_count, struct refspec *query)
 {
        int i;
        int find_src = !query->src;
+       const char *needle = find_src ? query->dst : query->src;
+       char **result = find_src ? &query->src : &query->dst;
 
        if (find_src && !query->dst)
                return error("query_refspecs: need either src or dst");
@@ -833,8 +866,6 @@ static int query_refspecs(struct refspec *refs, int ref_count, struct refspec *q
                struct refspec *refspec = &refs[i];
                const char *key = find_src ? refspec->dst : refspec->src;
                const char *value = find_src ? refspec->src : refspec->dst;
-               const char *needle = find_src ? query->dst : query->src;
-               char **result = find_src ? &query->src : &query->dst;
 
                if (!refspec->dst)
                        continue;
@@ -955,9 +986,9 @@ void sort_ref_list(struct ref **l, int (*cmp)(const void *, const void *))
        *l = llist_mergesort(*l, ref_list_get_next, ref_list_set_next, cmp);
 }
 
-static int count_refspec_match(const char *pattern,
-                              struct ref *refs,
-                              struct ref **matched_ref)
+int count_refspec_match(const char *pattern,
+                       struct ref *refs,
+                       struct ref **matched_ref)
 {
        int patlen = strlen(pattern);
        struct ref *matched_weak = NULL;
@@ -982,8 +1013,8 @@ static int count_refspec_match(const char *pattern,
                 */
                if (namelen != patlen &&
                    patlen != namelen - 5 &&
-                   prefixcmp(name, "refs/heads/") &&
-                   prefixcmp(name, "refs/tags/")) {
+                   !starts_with(name, "refs/heads/") &&
+                   !starts_with(name, "refs/tags/")) {
                        /* We want to catch the case where only weak
                         * matches are found and there are multiple
                         * matches, and where more than one strong
@@ -1054,9 +1085,9 @@ static char *guess_ref(const char *name, struct ref *peer)
        if (!r)
                return NULL;
 
-       if (!prefixcmp(r, "refs/heads/"))
+       if (starts_with(r, "refs/heads/"))
                strbuf_addstr(&buf, "refs/heads/");
-       else if (!prefixcmp(r, "refs/tags/"))
+       else if (starts_with(r, "refs/tags/"))
                strbuf_addstr(&buf, "refs/tags/");
        else
                return NULL;
@@ -1104,7 +1135,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
                dst_value = resolve_ref_unsafe(matched_src->name, sha1, 1, &flag);
                if (!dst_value ||
                    ((flag & REF_ISSYMREF) &&
-                    prefixcmp(dst_value, "refs/heads/")))
+                    !starts_with(dst_value, "refs/heads/")))
                        die("%s cannot be resolved to branch.",
                            matched_src->name);
        }
@@ -1193,7 +1224,7 @@ static char *get_ref_match(const struct refspec *rs, int rs_nr, const struct ref
                 * including refs outside refs/heads/ hierarchy, but
                 * that does not make much sense these days.
                 */
-               if (!send_mirror && prefixcmp(ref->name, "refs/heads/"))
+               if (!send_mirror && !starts_with(ref->name, "refs/heads/"))
                        return NULL;
                name = xstrdup(ref->name);
        }
@@ -1248,7 +1279,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
                        add_to_tips(&sent_tips, ref->peer_ref->new_sha1);
                else
                        add_to_tips(&sent_tips, ref->old_sha1);
-               if (!prefixcmp(ref->name, "refs/tags/"))
+               if (starts_with(ref->name, "refs/tags/"))
                        string_list_append(&dst_tag, ref->name);
        }
        clear_commit_marks_many(sent_tips.nr, sent_tips.tip, TMP_MARK);
@@ -1257,7 +1288,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 
        /* Collect tags they do not have. */
        for (ref = src; ref; ref = ref->next) {
-               if (prefixcmp(ref->name, "refs/tags/"))
+               if (!starts_with(ref->name, "refs/tags/"))
                        continue; /* not a tag */
                if (string_list_has_string(&dst_tag, ref->name))
                        continue; /* they already have it */
@@ -1481,7 +1512,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
                 */
 
                else if (!ref->deletion && !is_null_sha1(ref->old_sha1)) {
-                       if (!prefixcmp(ref->name, "refs/tags/"))
+                       if (starts_with(ref->name, "refs/tags/"))
                                reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
                        else if (!has_sha1_file(ref->old_sha1))
                                reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
@@ -1553,6 +1584,13 @@ static int ignore_symref_update(const char *refname)
        return (flag & REF_ISSYMREF);
 }
 
+/*
+ * Create and return a list of (struct ref) consisting of copies of
+ * each remote_ref that matches refspec.  refspec must be a pattern.
+ * Fill in the copies' peer_ref to describe the local tracking refs to
+ * which they map.  Omit any references that would map to an existing
+ * local symbolic ref.
+ */
 static struct ref *get_expanded_map(const struct ref *remote_refs,
                                    const struct refspec *refspec)
 {
@@ -1560,9 +1598,9 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
        struct ref *ret = NULL;
        struct ref **tail = &ret;
 
-       char *expn_name;
-
        for (ref = remote_refs; ref; ref = ref->next) {
+               char *expn_name = NULL;
+
                if (strchr(ref->name, '^'))
                        continue; /* a dereference item */
                if (match_name_with_pattern(refspec->src, ref->name,
@@ -1571,12 +1609,12 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
                        struct ref *cpy = copy_ref(ref);
 
                        cpy->peer_ref = alloc_ref(expn_name);
-                       free(expn_name);
                        if (refspec->force)
                                cpy->peer_ref->force = 1;
                        *tail = cpy;
                        tail = &cpy->next;
                }
+               free(expn_name);
        }
 
        return ret;
@@ -1607,12 +1645,12 @@ static struct ref *get_local_ref(const char *name)
        if (!name || name[0] == '\0')
                return NULL;
 
-       if (!prefixcmp(name, "refs/"))
+       if (starts_with(name, "refs/"))
                return alloc_ref(name);
 
-       if (!prefixcmp(name, "heads/") ||
-           !prefixcmp(name, "tags/") ||
-           !prefixcmp(name, "remotes/"))
+       if (starts_with(name, "heads/") ||
+           starts_with(name, "tags/") ||
+           starts_with(name, "remotes/"))
                return alloc_ref_with_prefix("refs/", 5, name);
 
        return alloc_ref_with_prefix("refs/heads/", 11, name);
@@ -1647,7 +1685,7 @@ int get_fetch_map(const struct ref *remote_refs,
 
        for (rmp = &ref_map; *rmp; ) {
                if ((*rmp)->peer_ref) {
-                       if (prefixcmp((*rmp)->peer_ref->name, "refs/") ||
+                       if (!starts_with((*rmp)->peer_ref->name, "refs/") ||
                            check_refname_format((*rmp)->peer_ref->name, 0)) {
                                struct ref *ignore = *rmp;
                                error("* Ignoring funny ref '%s' locally",
@@ -1931,7 +1969,7 @@ struct ref *guess_remote_head(const struct ref *head,
        /* Look for another ref that points there */
        for (r = refs; r; r = r->next) {
                if (r != head &&
-                   !prefixcmp(r->name, "refs/heads/") &&
+                   starts_with(r->name, "refs/heads/") &&
                    !hashcmp(r->old_sha1, head->old_sha1)) {
                        *tail = copy_ref(r);
                        tail = &((*tail)->next);
index 131130a611b55c9f79649037e6dde916b621f578..00c6a76ef803005698e14d7f31eb4acd22b35649 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -128,6 +128,7 @@ struct ref *alloc_ref(const char *name);
 struct ref *copy_ref(const struct ref *ref);
 struct ref *copy_ref_list(const struct ref *ref);
 void sort_ref_list(struct ref **, int (*cmp)(const void *, const void *));
+extern int count_refspec_match(const char *, struct ref *refs, struct ref **matched_ref);
 int ref_compare_name(const void *, const void *);
 
 int check_ref_type(const struct ref *ref, int flags);
@@ -149,15 +150,20 @@ int resolve_remote_symref(struct ref *ref, struct ref *list);
 int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
 
 /*
- * Removes and frees any duplicate refs in the map.
+ * Remove and free all but the first of any entries in the input list
+ * that map the same remote reference to the same local reference.  If
+ * there are two entries that map different remote references to the
+ * same local reference, emit an error message and die.  Return a
+ * pointer to the head of the resulting list.
  */
-void ref_remove_duplicates(struct ref *ref_map);
+struct ref *ref_remove_duplicates(struct ref *ref_map);
 
 int valid_fetch_refspec(const char *refspec);
 struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec);
 
 void free_refspec(int nr_refspec, struct refspec *refspec);
 
+extern int query_refspecs(struct refspec *specs, int nr, struct refspec *query);
 char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
                     const char *name);
 
index a8adb3fc8891a73fb4017d18b00020bca790c766..a68fde6e959c3f305fa7dba285783bd4300b8c0f 100644 (file)
@@ -1180,11 +1180,28 @@ struct all_refs_cb {
        const char *name_for_errormsg;
 };
 
+int ref_excluded(struct string_list *ref_excludes, const char *path)
+{
+       struct string_list_item *item;
+
+       if (!ref_excludes)
+               return 0;
+       for_each_string_list_item(item, ref_excludes) {
+               if (!fnmatch(item->string, path, 0))
+                       return 1;
+       }
+       return 0;
+}
+
 static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
 {
        struct all_refs_cb *cb = cb_data;
-       struct object *object = get_reference(cb->all_revs, path, sha1,
-                                             cb->all_flags);
+       struct object *object;
+
+       if (ref_excluded(cb->all_revs->ref_excludes, path))
+           return 0;
+
+       object = get_reference(cb->all_revs, path, sha1, cb->all_flags);
        add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags);
        add_pending_sha1(cb->all_revs, path, sha1, cb->all_flags);
        return 0;
@@ -1197,6 +1214,24 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs,
        cb->all_flags = flags;
 }
 
+void clear_ref_exclusion(struct string_list **ref_excludes_p)
+{
+       if (*ref_excludes_p) {
+               string_list_clear(*ref_excludes_p, 0);
+               free(*ref_excludes_p);
+       }
+       *ref_excludes_p = NULL;
+}
+
+void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude)
+{
+       if (!*ref_excludes_p) {
+               *ref_excludes_p = xcalloc(1, sizeof(**ref_excludes_p));
+               (*ref_excludes_p)->strdup_strings = 1;
+       }
+       string_list_append(*ref_excludes_p, exclude);
+}
+
 static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags,
                int (*for_each)(const char *, each_ref_fn, void *))
 {
@@ -1592,9 +1627,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
            !strcmp(arg, "--tags") || !strcmp(arg, "--remotes") ||
            !strcmp(arg, "--reflog") || !strcmp(arg, "--not") ||
            !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
-           !strcmp(arg, "--bisect") || !prefixcmp(arg, "--glob=") ||
-           !prefixcmp(arg, "--branches=") || !prefixcmp(arg, "--tags=") ||
-           !prefixcmp(arg, "--remotes=") || !prefixcmp(arg, "--no-walk="))
+           !strcmp(arg, "--bisect") || starts_with(arg, "--glob=") ||
+           starts_with(arg, "--branches=") || starts_with(arg, "--tags=") ||
+           starts_with(arg, "--remotes=") || starts_with(arg, "--no-walk="))
        {
                unkv[(*unkc)++] = arg;
                return 1;
@@ -1617,7 +1652,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->max_count = atoi(argv[1]);
                revs->no_walk = 0;
                return 2;
-       } else if (!prefixcmp(arg, "-n")) {
+       } else if (starts_with(arg, "-n")) {
                revs->max_count = atoi(arg + 2);
                revs->no_walk = 0;
        } else if ((argcount = parse_long_opt("max-age", argv, &optarg))) {
@@ -1677,7 +1712,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
        } else if (!strcmp(arg, "--author-date-order")) {
                revs->sort_order = REV_SORT_BY_AUTHOR_DATE;
                revs->topo_order = 1;
-       } else if (!prefixcmp(arg, "--early-output")) {
+       } else if (starts_with(arg, "--early-output")) {
                int count = 100;
                switch (arg[14]) {
                case '=':
@@ -1702,13 +1737,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->min_parents = 2;
        } else if (!strcmp(arg, "--no-merges")) {
                revs->max_parents = 1;
-       } else if (!prefixcmp(arg, "--min-parents=")) {
+       } else if (starts_with(arg, "--min-parents=")) {
                revs->min_parents = atoi(arg+14);
-       } else if (!prefixcmp(arg, "--no-min-parents")) {
+       } else if (starts_with(arg, "--no-min-parents")) {
                revs->min_parents = 0;
-       } else if (!prefixcmp(arg, "--max-parents=")) {
+       } else if (starts_with(arg, "--max-parents=")) {
                revs->max_parents = atoi(arg+14);
-       } else if (!prefixcmp(arg, "--no-max-parents")) {
+       } else if (starts_with(arg, "--no-max-parents")) {
                revs->max_parents = -1;
        } else if (!strcmp(arg, "--boundary")) {
                revs->boundary = 1;
@@ -1758,7 +1793,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->verify_objects = 1;
        } else if (!strcmp(arg, "--unpacked")) {
                revs->unpacked = 1;
-       } else if (!prefixcmp(arg, "--unpacked=")) {
+       } else if (starts_with(arg, "--unpacked=")) {
                die("--unpacked=<packfile> no longer supported.");
        } else if (!strcmp(arg, "-r")) {
                revs->diff = 1;
@@ -1783,7 +1818,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->verbose_header = 1;
                revs->pretty_given = 1;
                get_commit_format(arg+8, revs);
-       } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) {
+       } else if (starts_with(arg, "--pretty=") || starts_with(arg, "--format=")) {
                /*
                 * Detached form ("--pretty X" as opposed to "--pretty=X")
                 * not allowed, since the argument is optional.
@@ -1797,12 +1832,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->notes_opt.use_default_notes = 1;
        } else if (!strcmp(arg, "--show-signature")) {
                revs->show_signature = 1;
-       } else if (!prefixcmp(arg, "--show-notes=") ||
-                  !prefixcmp(arg, "--notes=")) {
+       } else if (starts_with(arg, "--show-notes=") ||
+                  starts_with(arg, "--notes=")) {
                struct strbuf buf = STRBUF_INIT;
                revs->show_notes = 1;
                revs->show_notes_given = 1;
-               if (!prefixcmp(arg, "--show-notes")) {
+               if (starts_with(arg, "--show-notes")) {
                        if (revs->notes_opt.use_default_notes < 0)
                                revs->notes_opt.use_default_notes = 1;
                        strbuf_addstr(&buf, arg+13);
@@ -1845,7 +1880,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->abbrev = 0;
        } else if (!strcmp(arg, "--abbrev")) {
                revs->abbrev = DEFAULT_ABBREV;
-       } else if (!prefixcmp(arg, "--abbrev=")) {
+       } else if (starts_with(arg, "--abbrev=")) {
                revs->abbrev = strtoul(arg + 9, NULL, 10);
                if (revs->abbrev < MINIMUM_ABBREV)
                        revs->abbrev = MINIMUM_ABBREV;
@@ -1969,40 +2004,51 @@ static int handle_revision_pseudo_opt(const char *submodule,
        if (!strcmp(arg, "--all")) {
                handle_refs(submodule, revs, *flags, for_each_ref_submodule);
                handle_refs(submodule, revs, *flags, head_ref_submodule);
+               clear_ref_exclusion(&revs->ref_excludes);
        } else if (!strcmp(arg, "--branches")) {
                handle_refs(submodule, revs, *flags, for_each_branch_ref_submodule);
+               clear_ref_exclusion(&revs->ref_excludes);
        } else if (!strcmp(arg, "--bisect")) {
                handle_refs(submodule, revs, *flags, for_each_bad_bisect_ref);
                handle_refs(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref);
                revs->bisect = 1;
        } else if (!strcmp(arg, "--tags")) {
                handle_refs(submodule, revs, *flags, for_each_tag_ref_submodule);
+               clear_ref_exclusion(&revs->ref_excludes);
        } else if (!strcmp(arg, "--remotes")) {
                handle_refs(submodule, revs, *flags, for_each_remote_ref_submodule);
+               clear_ref_exclusion(&revs->ref_excludes);
        } else if ((argcount = parse_long_opt("glob", argv, &optarg))) {
                struct all_refs_cb cb;
                init_all_refs_cb(&cb, revs, *flags);
                for_each_glob_ref(handle_one_ref, optarg, &cb);
+               clear_ref_exclusion(&revs->ref_excludes);
+               return argcount;
+       } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) {
+               add_ref_exclusion(&revs->ref_excludes, optarg);
                return argcount;
-       } else if (!prefixcmp(arg, "--branches=")) {
+       } else if (starts_with(arg, "--branches=")) {
                struct all_refs_cb cb;
                init_all_refs_cb(&cb, revs, *flags);
                for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
-       } else if (!prefixcmp(arg, "--tags=")) {
+               clear_ref_exclusion(&revs->ref_excludes);
+       } else if (starts_with(arg, "--tags=")) {
                struct all_refs_cb cb;
                init_all_refs_cb(&cb, revs, *flags);
                for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
-       } else if (!prefixcmp(arg, "--remotes=")) {
+               clear_ref_exclusion(&revs->ref_excludes);
+       } else if (starts_with(arg, "--remotes=")) {
                struct all_refs_cb cb;
                init_all_refs_cb(&cb, revs, *flags);
                for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
+               clear_ref_exclusion(&revs->ref_excludes);
        } else if (!strcmp(arg, "--reflog")) {
                handle_reflog(revs, *flags);
        } else if (!strcmp(arg, "--not")) {
                *flags ^= UNINTERESTING | BOTTOM;
        } else if (!strcmp(arg, "--no-walk")) {
                revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
-       } else if (!prefixcmp(arg, "--no-walk=")) {
+       } else if (starts_with(arg, "--no-walk=")) {
                /*
                 * Detached form ("--no-walk X" as opposed to "--no-walk=X")
                 * not allowed, since the argument is optional.
index 89132df2fa481ce6cdd142fa31f5b2cfd2f43219..88967d6a24df852453f93cb7bc466386347b0c45 100644 (file)
@@ -61,6 +61,9 @@ struct rev_info {
        /* The end-points specified by the end user */
        struct rev_cmdline_info cmdline;
 
+       /* excluding from --branches, --refs, etc. expansion */
+       struct string_list *ref_excludes;
+
        /* Basic information */
        const char *prefix;
        const char *def;
@@ -194,6 +197,11 @@ struct rev_info {
        struct saved_parents *saved_parents_slab;
 };
 
+extern int ref_excluded(struct string_list *, const char *path);
+void clear_ref_exclusion(struct string_list **);
+void add_ref_exclusion(struct string_list **, const char *exclude);
+
+
 #define REV_TREE_SAME          0
 #define REV_TREE_NEW           1       /* Only new files */
 #define REV_TREE_OLD           2       /* Only files removed */
index fab62e3da05913b5a4f76db7ed1c17e5831384d2..ac14a4d090cce0fa282447641097085a8428c05c 100644 (file)
@@ -109,7 +109,7 @@ static int receive_status(int in, struct ref *refs)
        struct ref *hint;
        int ret = 0;
        char *line = packet_read_line(in, NULL);
-       if (prefixcmp(line, "unpack "))
+       if (!starts_with(line, "unpack "))
                return error("did not receive remote status");
        if (strcmp(line, "unpack ok")) {
                error("unpack failed: %s", line + 7);
@@ -122,7 +122,7 @@ static int receive_status(int in, struct ref *refs)
                line = packet_read_line(in, NULL);
                if (!line)
                        break;
-               if (prefixcmp(line, "ok ") && prefixcmp(line, "ng ")) {
+               if (!starts_with(line, "ok ") && !starts_with(line, "ng ")) {
                        error("invalid ref status from remote: %s", line);
                        ret = -1;
                        break;
@@ -206,6 +206,8 @@ int send_pack(struct send_pack_args *args,
                quiet_supported = 1;
        if (server_supports("agent"))
                agent_supported = 1;
+       if (server_supports("no-thin"))
+               args->use_thin_pack = 0;
 
        if (!remote_refs) {
                fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
index 06e52b4c83ffc0ce2b9414afe3fb1b4ee91d4335..90cac7b02eef1e9f681f5dc58bc26becaaf5ac12 100644 (file)
@@ -41,7 +41,7 @@ static int is_cherry_picked_from_line(const char *buf, int len)
         * We only care that it looks roughly like (cherry picked from ...)
         */
        return len > strlen(cherry_picked_prefix) + 1 &&
-               !prefixcmp(buf, cherry_picked_prefix) && buf[len - 1] == ')';
+               starts_with(buf, cherry_picked_prefix) && buf[len - 1] == ')';
 }
 
 /*
@@ -180,7 +180,7 @@ static char *get_encoding(const char *message)
        while (*p && *p != '\n') {
                for (eol = p + 1; *eol && *eol != '\n'; eol++)
                        ; /* do nothing */
-               if (!prefixcmp(p, "encoding ")) {
+               if (starts_with(p, "encoding ")) {
                        char *result = xmalloc(eol - 8 - p);
                        strlcpy(result, p + 9, eol - 8 - p);
                        return result;
@@ -705,10 +705,10 @@ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *
        char *end_of_object_name;
        int saved, status, padding;
 
-       if (!prefixcmp(bol, "pick")) {
+       if (starts_with(bol, "pick")) {
                action = REPLAY_PICK;
                bol += strlen("pick");
-       } else if (!prefixcmp(bol, "revert")) {
+       } else if (starts_with(bol, "revert")) {
                action = REPLAY_REVERT;
                bol += strlen("revert");
        } else
diff --git a/setup.c b/setup.c
index 5432a31b62800bfba4d5a19226946ea30c5446a4..6c3f85ff7a7935ed6f05ab5ab376a2d6c5ca2d46 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -82,7 +82,7 @@ int check_filename(const char *prefix, const char *arg)
        const char *name;
        struct stat st;
 
-       if (!prefixcmp(arg, ":/")) {
+       if (starts_with(arg, ":/")) {
                if (arg[2] == '\0') /* ":/" is root dir, always exists */
                        return 1;
                name = arg + 2;
@@ -304,7 +304,7 @@ const char *read_gitfile(const char *path)
        if (len != st.st_size)
                die("Error reading %s", path);
        buf[len] = '\0';
-       if (prefixcmp(buf, "gitdir: "))
+       if (!starts_with(buf, "gitdir: "))
                die("Invalid gitfile format: %s", path);
        while (buf[len - 1] == '\n' || buf[len - 1] == '\r')
                len--;
index 5f152235862bfed10a6b0de7dfb1002fa14cdf05..daacc0cfb0132e98a98ba9645991f3d3f228d1cd 100644 (file)
@@ -1442,51 +1442,6 @@ void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
        return map;
 }
 
-/*
- * There used to be a second loose object header format which
- * was meant to mimic the in-pack format, allowing for direct
- * copy of the object data.  This format turned up not to be
- * really worth it and we no longer write loose objects in that
- * format.
- */
-static int experimental_loose_object(unsigned char *map)
-{
-       unsigned int word;
-
-       /*
-        * We must determine if the buffer contains the standard
-        * zlib-deflated stream or the experimental format based
-        * on the in-pack object format. Compare the header byte
-        * for each format:
-        *
-        * RFC1950 zlib w/ deflate : 0www1000 : 0 <= www <= 7
-        * Experimental pack-based : Stttssss : ttt = 1,2,3,4
-        *
-        * If bit 7 is clear and bits 0-3 equal 8, the buffer MUST be
-        * in standard loose-object format, UNLESS it is a Git-pack
-        * format object *exactly* 8 bytes in size when inflated.
-        *
-        * However, RFC1950 also specifies that the 1st 16-bit word
-        * must be divisible by 31 - this checksum tells us our buffer
-        * is in the standard format, giving a false positive only if
-        * the 1st word of the Git-pack format object happens to be
-        * divisible by 31, ie:
-        *      ((byte0 * 256) + byte1) % 31 = 0
-        *   =>        0ttt10000www1000 % 31 = 0
-        *
-        * As it happens, this case can only arise for www=3 & ttt=1
-        * - ie, a Commit object, which would have to be 8 bytes in
-        * size. As no Commit can be that small, we find that the
-        * combination of these two criteria (bitmask & checksum)
-        * can always correctly determine the buffer format.
-        */
-       word = (map[0] << 8) + map[1];
-       if ((map[0] & 0x8F) == 0x08 && !(word % 31))
-               return 0;
-       else
-               return 1;
-}
-
 unsigned long unpack_object_header_buffer(const unsigned char *buf,
                unsigned long len, enum object_type *type, unsigned long *sizep)
 {
@@ -1514,14 +1469,6 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
 
 int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz)
 {
-       unsigned long size, used;
-       static const char valid_loose_object_type[8] = {
-               0, /* OBJ_EXT */
-               1, 1, 1, 1, /* "commit", "tree", "blob", "tag" */
-               0, /* "delta" and others are invalid in a loose object */
-       };
-       enum object_type type;
-
        /* Get the data stream */
        memset(stream, 0, sizeof(*stream));
        stream->next_in = map;
@@ -1529,27 +1476,6 @@ int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long ma
        stream->next_out = buffer;
        stream->avail_out = bufsiz;
 
-       if (experimental_loose_object(map)) {
-               /*
-                * The old experimental format we no longer produce;
-                * we can still read it.
-                */
-               used = unpack_object_header_buffer(map, mapsize, &type, &size);
-               if (!used || !valid_loose_object_type[type])
-                       return -1;
-               map += used;
-               mapsize -= used;
-
-               /* Set up the stream for the rest.. */
-               stream->next_in = map;
-               stream->avail_in = mapsize;
-               git_inflate_init(stream);
-
-               /* And generate the fake traditional header */
-               stream->total_out = 1 + snprintf(buffer, bufsiz, "%s %lu",
-                                                typename(type), size);
-               return 0;
-       }
        git_inflate_init(stream);
        return git_inflate(stream, 0);
 }
@@ -2483,15 +2409,18 @@ static int sha1_loose_object_info(const unsigned char *sha1,
 
        /*
         * If we don't care about type or size, then we don't
-        * need to look inside the object at all.
+        * need to look inside the object at all. Note that we
+        * do not optimize out the stat call, even if the
+        * caller doesn't care about the disk-size, since our
+        * return value implicitly indicates whether the
+        * object even exists.
         */
        if (!oi->typep && !oi->sizep) {
-               if (oi->disk_sizep) {
-                       struct stat st;
-                       if (stat_sha1_file(sha1, &st) < 0)
-                               return -1;
+               struct stat st;
+               if (stat_sha1_file(sha1, &st) < 0)
+                       return -1;
+               if (oi->disk_sizep)
                        *oi->disk_sizep = st.st_size;
-               }
                return 0;
        }
 
index 2f37488b96c0a8485e90d87befa997d75ba4b7b1..b1873d8113bdeb0ff8087319c99833036aaffe1b 100644 (file)
@@ -546,7 +546,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
                if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
                                &co_time, &co_tz, &co_cnt)) {
                        if (!len) {
-                               if (!prefixcmp(real_ref, "refs/heads/")) {
+                               if (starts_with(real_ref, "refs/heads/")) {
                                        str = real_ref + 11;
                                        len = strlen(real_ref + 11);
                                } else {
@@ -674,15 +674,15 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
                return -1;
 
        sp++; /* beginning of type name, or closing brace for empty */
-       if (!prefixcmp(sp, "commit}"))
+       if (starts_with(sp, "commit}"))
                expected_type = OBJ_COMMIT;
-       else if (!prefixcmp(sp, "tag}"))
+       else if (starts_with(sp, "tag}"))
                expected_type = OBJ_TAG;
-       else if (!prefixcmp(sp, "tree}"))
+       else if (starts_with(sp, "tree}"))
                expected_type = OBJ_TREE;
-       else if (!prefixcmp(sp, "blob}"))
+       else if (starts_with(sp, "blob}"))
                expected_type = OBJ_BLOB;
-       else if (!prefixcmp(sp, "object}"))
+       else if (starts_with(sp, "object}"))
                expected_type = OBJ_ANY;
        else if (sp[0] == '}')
                expected_type = OBJ_NONE;
@@ -909,7 +909,7 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
        const char *match = NULL, *target = NULL;
        size_t len;
 
-       if (!prefixcmp(message, "checkout: moving from ")) {
+       if (starts_with(message, "checkout: moving from ")) {
                match = message + strlen("checkout: moving from ");
                target = strstr(match, " to ");
        }
@@ -1302,7 +1302,7 @@ static void diagnose_invalid_index_path(int stage,
 
 static char *resolve_relative_path(const char *rel)
 {
-       if (prefixcmp(rel, "./") && prefixcmp(rel, "../"))
+       if (!starts_with(rel, "./") && !starts_with(rel, "../"))
                return NULL;
 
        if (!startup_info)
diff --git a/shell.c b/shell.c
index 66350b220cc74abd383e10770f8325ba4e658e87..5c0d47a5cc1ae85a03e40321e97ddfa859ff7e1a 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -15,7 +15,7 @@ static int do_generic_cmd(const char *me, char *arg)
        setup_path();
        if (!arg || !(arg = sq_dequote(arg)))
                die("bad argument");
-       if (prefixcmp(me, "git-"))
+       if (!starts_with(me, "git-"))
                die("bad command");
 
        my_argv[0] = me + 4;
index 1170d01c4322b494cd900853279766edd030de32..83caf4a9147e6788107fb5fd23e6d9e1d6f6267f 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,6 +1,15 @@
 #include "cache.h"
 #include "refs.h"
 
+int starts_with(const char *str, const char *prefix)
+{
+       for (; ; str++, prefix++)
+               if (!*prefix)
+                       return 1;
+               else if (*str != *prefix)
+                       return 0;
+}
+
 int prefixcmp(const char *str, const char *prefix)
 {
        for (; ; str++, prefix++)
@@ -10,6 +19,15 @@ int prefixcmp(const char *str, const char *prefix)
                        return (unsigned char)*prefix - (unsigned char)*str;
 }
 
+int ends_with(const char *str, const char *suffix)
+{
+       int len = strlen(str), suflen = strlen(suffix);
+       if (len < suflen)
+               return 0;
+       else
+               return !strcmp(str + len - suflen, suffix);
+}
+
 int suffixcmp(const char *str, const char *suffix)
 {
        int len = strlen(str), suflen = strlen(suffix);
index 1905d75b2b09ee7e1503b35bf072710a659ea1ef..613857e400f826f3d4ea28c87025b2c2df42408a 100644 (file)
@@ -201,7 +201,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 
 int submodule_config(const char *var, const char *value, void *cb)
 {
-       if (!prefixcmp(var, "submodule."))
+       if (starts_with(var, "submodule."))
                return parse_submodule_config_option(var, value);
        else if (!strcmp(var, "fetch.recursesubmodules")) {
                config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 8cf909a6c5521729b24064c8273209ec2338d29c..d5dab5a94f1d881b8b103f6290ba91e4ec596ec6 100644 (file)
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Initialization and helpers for Gitweb tests, which source this
+# shell library instead of test-lib.sh.
 #
 # Copyright (c) 2007 Jakub Narebski
 #
index 11397f747b9658146a133f5fa65923cc4edfb11f..2be955fafba60e9dbf30a3ab7f0bc1dfae270140 100644 (file)
@@ -1,7 +1,6 @@
-#!/bin/sh
-#
-# Ensures that tests are run under Bash; primarily intended for running tests
-# of the completion script.
+# Shell library sourced instead of ./test-lib.sh by tests that need
+# to run under Bash; primarily intended for tests of the completion
+# script.
 
 if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
        # we are in full-on bash mode
index 44263ade2533b848220c234441ab67813ca2b0b4..5076718916388d6abf483220cd35f9f61394abc4 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Shell library sourced instead of ./test-lib.sh by cvsimport tests.
 
 . ./test-lib.sh
 
index 75ffd9174fbfb7fc6b14d4777f6613d9f052d64f..8b4dbf22d2d140bef7ca0e106a389cb0ca1d4681 100644 (file)
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Helpers shared by the test scripts for diff algorithms (patience,
+# histogram, etc).
 
 test_diff_frobnitz() {
        cat >file1 <<\EOF
index ae8883a07514c47b0568c9323698e879b38703e5..eec757f104708df3a00935cef89dd7dad537afb9 100644 (file)
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Initialization and Icelandic locale for basic git i18n tests,
+# which source this scriptlet instead of ./test-lib.sh.
 #
 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
 #
index 87f0ad8f4182b13903b9649308e36e34a6122494..394b06b32f838463221e9c2f49380fd9eb08bb9d 100644 (file)
@@ -1,4 +1,20 @@
-#!/bin/sh
+# Shell library to run git-daemon in tests.  Ends the test early if
+# GIT_TEST_GIT_DAEMON is not set.
+#
+# Usage:
+#
+#      . ./test-lib.sh
+#      . "$TEST_DIRECTORY"/lib-git-daemon.sh
+#      start_git_daemon
+#
+#      test_expect_success '...' '
+#              ...
+#      '
+#
+#      test_expect_success ...
+#
+#      stop_git_daemon
+#      test_done
 
 if test -z "$GIT_TEST_GIT_DAEMON"
 then
index ad8f1ef71efcd7e449d2cad8edd3cf80c98ca188..c4707843c4ca5d91d34c86185b3b16bd37d27e36 100644 (file)
@@ -1,4 +1,31 @@
-#!/bin/sh
+# Shell library to run an HTTP server for use in tests.
+# Ends the test early if httpd tests should not be run,
+# for example because the user has not enabled them.
+#
+# Usage:
+#
+#      . ./test-lib.sh
+#      . "$TEST_DIRECTORY"/lib-httpd.sh
+#      start_httpd
+#
+#      test_expect_success '...' '
+#              ...
+#      '
+#
+#      test_expect_success ...
+#
+#      stop_httpd
+#      test_done
+#
+# Can be configured using the following variables.
+#
+#    GIT_TEST_HTTPD              enable HTTPD tests
+#    LIB_HTTPD_PATH              web server path
+#    LIB_HTTPD_MODULE_PATH       web server modules path
+#    LIB_HTTPD_PORT              listening port
+#    LIB_HTTPD_DAV               enable DAV
+#    LIB_HTTPD_SVN               enable SVN
+#    LIB_HTTPD_SSL               enable SSL
 #
 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
 #
index b96e1254dd36821b4a390726c7aefb5286c243f3..75098465716512a3373e64d51a5cdf848e9f1101 100644 (file)
@@ -1,5 +1,3 @@
-#!/bin/sh
-#
 # Support routines for hand-crafting weird or malicious packs.
 #
 # You can make a complete pack like:
index ba03eab14fc29934f095673fa82af658b06bf865..3aa7a3ffd8b0103752987872c84e75ea2b299b9e 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Helpers for tests of git's choice of pager.
 
 test_expect_success 'determine default pager' '
        test_might_fail git config --unset core.pager &&
diff --git a/t/lib-prereq-FILEMODE.sh b/t/lib-prereq-FILEMODE.sh
deleted file mode 100644 (file)
index bce5a4c..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
-#
-
-if test "$(git config --bool core.filemode)" = false
-then
-       say 'filemode disabled on the filesystem'
-else
-       test_set_prereq FILEMODE
-fi
index abc2c6f57fe29d124455227a16e241c49ae40c5c..b95f4856061da723cbe36bd6955c552bee7a29aa 100644 (file)
@@ -1,43 +1,41 @@
-#!/bin/sh
-#
 # Helper functions to check if read-tree would succeed/fail as expected with
 # and without the dry-run option. They also test that the dry-run does not
 # write the index and that together with -u it doesn't touch the work tree.
 #
 read_tree_must_succeed () {
-    git ls-files -s >pre-dry-run &&
-    git read-tree -n "$@" &&
-    git ls-files -s >post-dry-run &&
-    test_cmp pre-dry-run post-dry-run &&
-    git read-tree "$@"
+       git ls-files -s >pre-dry-run &&
+       git read-tree -n "$@" &&
+       git ls-files -s >post-dry-run &&
+       test_cmp pre-dry-run post-dry-run &&
+       git read-tree "$@"
 }
 
 read_tree_must_fail () {
-    git ls-files -s >pre-dry-run &&
-    test_must_fail git read-tree -n "$@" &&
-    git ls-files -s >post-dry-run &&
-    test_cmp pre-dry-run post-dry-run &&
-    test_must_fail git read-tree "$@"
+       git ls-files -s >pre-dry-run &&
+       test_must_fail git read-tree -n "$@" &&
+       git ls-files -s >post-dry-run &&
+       test_cmp pre-dry-run post-dry-run &&
+       test_must_fail git read-tree "$@"
 }
 
 read_tree_u_must_succeed () {
-    git ls-files -s >pre-dry-run &&
-    git diff-files -p >pre-dry-run-wt &&
-    git read-tree -n "$@" &&
-    git ls-files -s >post-dry-run &&
-    git diff-files -p >post-dry-run-wt &&
-    test_cmp pre-dry-run post-dry-run &&
-    test_cmp pre-dry-run-wt post-dry-run-wt &&
-    git read-tree "$@"
+       git ls-files -s >pre-dry-run &&
+       git diff-files -p >pre-dry-run-wt &&
+       git read-tree -n "$@" &&
+       git ls-files -s >post-dry-run &&
+       git diff-files -p >post-dry-run-wt &&
+       test_cmp pre-dry-run post-dry-run &&
+       test_cmp pre-dry-run-wt post-dry-run-wt &&
+       git read-tree "$@"
 }
 
 read_tree_u_must_fail () {
-    git ls-files -s >pre-dry-run &&
-    git diff-files -p >pre-dry-run-wt &&
-    test_must_fail git read-tree -n "$@" &&
-    git ls-files -s >post-dry-run &&
-    git diff-files -p >post-dry-run-wt &&
-    test_cmp pre-dry-run post-dry-run &&
-    test_cmp pre-dry-run-wt post-dry-run-wt &&
-    test_must_fail git read-tree "$@"
+       git ls-files -s >pre-dry-run &&
+       git diff-files -p >pre-dry-run-wt &&
+       test_must_fail git read-tree -n "$@" &&
+       git ls-files -s >post-dry-run &&
+       git diff-files -p >post-dry-run-wt &&
+       test_cmp pre-dry-run post-dry-run &&
+       test_cmp pre-dry-run-wt post-dry-run-wt &&
+       test_must_fail git read-tree "$@"
 }
index 8ff87fb3f9bee1c6955f84b66027037100ebbbd3..6bd252212a7eb901dded2a460eebe92aa3b6212b 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Helper functions used by interactive rebase tests.
 
 # After setting the fake editor with this function, you can
 #
index 737df289a1450b80aed58b52a59cf00eb2d77da3..9a2dca506a8d6c15f52e6ded3aa22a0f08f507a1 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Helpers for terminal output tests.
 
 test_expect_success PERL 'set up terminal for tests' '
        # Reading from the pty master seems to get stuck _sometimes_
index f4eecaa17110c2974cfdedab90db4604b6923443..a8c9574291b87d9bb1906a9d61faa9b157178b76 100644 (file)
@@ -1,4 +1,6 @@
-#!/bin/sh
+# Performance testing framework.  Each perf script starts much like
+# a normal test script, except it sources this library instead of
+# test-lib.sh.  See t/perf/README for documentation.
 #
 # Copyright (c) 2011 Thomas Rast
 #
index cb144258ccc3f32025c4b7beba6ac02c427612d8..37e9396e5dae8957ba73507018d5c334ee65e30d 100755 (executable)
@@ -7,7 +7,7 @@ Verify that plumbing commands work when .git is a file
 . ./test-lib.sh
 
 objpath() {
-    echo "$1" | sed -e 's|\(..\)|\1/|'
+       echo "$1" | sed -e 's|\(..\)|\1/|'
 }
 
 objck() {
@@ -19,7 +19,6 @@ objck() {
        fi
 }
 
-
 test_expect_success 'initial setup' '
        REAL="$(pwd)/.real" &&
        mv .git "$REAL"
index 0b98b6f8d090ecc3dfb48fe6fda5889dfbc5e018..b9d79476e20b4ddf0f9e85c672df2061fb910f9d 100755 (executable)
@@ -13,7 +13,6 @@ attr_check () {
        test_line_count = 0 err
 }
 
-
 test_expect_success 'setup' '
        mkdir -p a/b/d a/c b &&
        (
old mode 100644 (file)
new mode 100755 (executable)
index f53de79e565afcbe53a016a56a59b27831a3ce42..074568500a357d3bae69a953aa59155687483a10 100755 (executable)
@@ -8,84 +8,99 @@ test_description='read-tree -u --reset'
 # two-tree test
 
 test_expect_success 'setup' '
-  git init &&
-  mkdir df &&
-  echo content >df/file &&
-  git add df/file &&
-  git commit -m one &&
-  git ls-files >expect &&
-  rm -rf df &&
-  echo content >df &&
-  git add df &&
-  echo content >new &&
-  git add new &&
-  git commit -m two
+       git init &&
+       mkdir df &&
+       echo content >df/file &&
+       git add df/file &&
+       git commit -m one &&
+       git ls-files >expect &&
+       rm -rf df &&
+       echo content >df &&
+       git add df &&
+       echo content >new &&
+       git add new &&
+       git commit -m two
 '
 
 test_expect_success 'reset should work' '
-  read_tree_u_must_succeed -u --reset HEAD^ &&
-  git ls-files >actual &&
-  test_cmp expect actual
+       read_tree_u_must_succeed -u --reset HEAD^ &&
+       git ls-files >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success 'reset should remove remnants from a failed merge' '
-  read_tree_u_must_succeed --reset -u HEAD &&
-  git ls-files -s >expect &&
-  sha1=$(git rev-parse :new) &&
-  (
-       echo "100644 $sha1 1    old"
-       echo "100644 $sha1 3    old"
-  ) | git update-index --index-info &&
-  >old &&
-  git ls-files -s &&
-  read_tree_u_must_succeed --reset -u HEAD &&
-  git ls-files -s >actual &&
-  ! test -f old
+       read_tree_u_must_succeed --reset -u HEAD &&
+       git ls-files -s >expect &&
+       sha1=$(git rev-parse :new) &&
+       (
+               echo "100644 $sha1 1    old"
+               echo "100644 $sha1 3    old"
+       ) | git update-index --index-info &&
+       >old &&
+       git ls-files -s &&
+       read_tree_u_must_succeed --reset -u HEAD &&
+       git ls-files -s >actual &&
+       ! test -f old
+'
+
+test_expect_success 'two-way reset should remove remnants too' '
+       read_tree_u_must_succeed --reset -u HEAD &&
+       git ls-files -s >expect &&
+       sha1=$(git rev-parse :new) &&
+       (
+               echo "100644 $sha1 1    old"
+               echo "100644 $sha1 3    old"
+       ) | git update-index --index-info &&
+       >old &&
+       git ls-files -s &&
+       read_tree_u_must_succeed --reset -u HEAD HEAD &&
+       git ls-files -s >actual &&
+       ! test -f old
 '
 
 test_expect_success 'Porcelain reset should remove remnants too' '
-  read_tree_u_must_succeed --reset -u HEAD &&
-  git ls-files -s >expect &&
-  sha1=$(git rev-parse :new) &&
-  (
-       echo "100644 $sha1 1    old"
-       echo "100644 $sha1 3    old"
-  ) | git update-index --index-info &&
-  >old &&
-  git ls-files -s &&
-  git reset --hard &&
-  git ls-files -s >actual &&
-  ! test -f old
+       read_tree_u_must_succeed --reset -u HEAD &&
+       git ls-files -s >expect &&
+       sha1=$(git rev-parse :new) &&
+       (
+               echo "100644 $sha1 1    old"
+               echo "100644 $sha1 3    old"
+       ) | git update-index --index-info &&
+       >old &&
+       git ls-files -s &&
+       git reset --hard &&
+       git ls-files -s >actual &&
+       ! test -f old
 '
 
 test_expect_success 'Porcelain checkout -f should remove remnants too' '
-  read_tree_u_must_succeed --reset -u HEAD &&
-  git ls-files -s >expect &&
-  sha1=$(git rev-parse :new) &&
-  (
-       echo "100644 $sha1 1    old"
-       echo "100644 $sha1 3    old"
-  ) | git update-index --index-info &&
-  >old &&
-  git ls-files -s &&
-  git checkout -f &&
-  git ls-files -s >actual &&
-  ! test -f old
+       read_tree_u_must_succeed --reset -u HEAD &&
+       git ls-files -s >expect &&
+       sha1=$(git rev-parse :new) &&
+       (
+               echo "100644 $sha1 1    old"
+               echo "100644 $sha1 3    old"
+       ) | git update-index --index-info &&
+       >old &&
+       git ls-files -s &&
+       git checkout -f &&
+       git ls-files -s >actual &&
+       ! test -f old
 '
 
 test_expect_success 'Porcelain checkout -f HEAD should remove remnants too' '
-  read_tree_u_must_succeed --reset -u HEAD &&
-  git ls-files -s >expect &&
-  sha1=$(git rev-parse :new) &&
-  (
-       echo "100644 $sha1 1    old"
-       echo "100644 $sha1 3    old"
-  ) | git update-index --index-info &&
-  >old &&
-  git ls-files -s &&
-  git checkout -f HEAD &&
-  git ls-files -s >actual &&
-  ! test -f old
+       read_tree_u_must_succeed --reset -u HEAD &&
+       git ls-files -s >expect &&
+       sha1=$(git rev-parse :new) &&
+       (
+               echo "100644 $sha1 1    old"
+               echo "100644 $sha1 3    old"
+       ) | git update-index --index-info &&
+       >old &&
+       git ls-files -s &&
+       git checkout -f HEAD &&
+       git ls-files -s >actual &&
+       ! test -f old
 '
 
 test_done
index a420742494024e127d4e4233153c7054e077e471..8a1bc5c53281eb6f44c15d68dd0ae737bc0125f3 100755 (executable)
@@ -194,6 +194,12 @@ test_expect_success "--batch-check for an emtpy line" '
     test " missing" = "$(echo | git cat-file --batch-check)"
 '
 
+test_expect_success 'empty --batch-check notices missing object' '
+       echo "$_z40 missing" >expect &&
+       echo "$_z40" | git cat-file --batch-check="" >actual &&
+       test_cmp expect actual
+'
+
 batch_input="$hello_sha1
 $commit_sha1
 $tag_sha1
diff --git a/t/t1013-loose-object-format.sh b/t/t1013-loose-object-format.sh
deleted file mode 100755 (executable)
index fbf5f2f..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2011 Roberto Tyley
-#
-
-test_description='Correctly identify and parse loose object headers
-
-There are two file formats for loose objects - the original standard
-format, and the experimental format introduced with Git v1.4.3, later
-deprecated with v1.5.3. Although Git no longer writes the
-experimental format, objects in both formats must be read, with the
-format for a given file being determined by the header.
-
-Detecting file format based on header is not entirely trivial, not
-least because the first byte of a zlib-deflated stream will vary
-depending on how much memory was allocated for the deflation window
-buffer when the object was written out (for example 4KB on Android,
-rather that 32KB on a normal PC).
-
-The loose objects used as test vectors have been generated with the
-following Git versions:
-
-standard format: Git v1.7.4.1
-experimental format: Git v1.4.3 (legacyheaders=false)
-standard format, deflated with 4KB window size: Agit/JGit on Android
-'
-
-. ./test-lib.sh
-
-assert_blob_equals() {
-       printf "%s" "$2" >expected &&
-       git cat-file -p "$1" >actual &&
-       test_cmp expected actual
-}
-
-test_expect_success setup '
-       cp -R "$TEST_DIRECTORY/t1013/objects" .git/ &&
-       git --version
-'
-
-test_expect_success 'read standard-format loose objects' '
-       git cat-file tag 8d4e360d6c70fbd72411991c02a09c442cf7a9fa &&
-       git cat-file commit 6baee0540ea990d9761a3eb9ab183003a71c3696 &&
-       git ls-tree 7a37b887a73791d12d26c0d3e39568a8fb0fa6e8 &&
-       assert_blob_equals "257cc5642cb1a054f08cc83f2d943e56fd3ebe99" "foo$LF"
-'
-
-test_expect_success 'read experimental-format loose objects' '
-       git cat-file tag 76e7fa9941f4d5f97f64fea65a2cba436bc79cbb &&
-       git cat-file commit 7875c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 &&
-       git ls-tree 95b1625de3ba8b2214d1e0d0591138aea733f64f &&
-       assert_blob_equals "2e65efe2a145dda7ee51d1741299f848e5bf752e" "a" &&
-       assert_blob_equals "9ae9e86b7bd6cb1472d9373702d8249973da0832" "ab" &&
-       assert_blob_equals "85df50785d62d3b05ab03d9cbf7e4a0b49449730" "abcd" &&
-       assert_blob_equals "1656f9233d999f61ef23ef390b9c71d75399f435" "abcdefgh" &&
-       assert_blob_equals "1e72a6b2c4a577ab0338860fa9fe87f761fc9bbd" "abcdefghi" &&
-       assert_blob_equals "70e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd" "abcdefghijklmnop" &&
-       assert_blob_equals "bd15045f6ce8ff75747562173640456a394412c8" "abcdefghijklmnopqrstuvwx"
-'
-
-test_expect_success 'read standard-format objects deflated with smaller window buffer' '
-       git cat-file tag f816d5255855ac160652ee5253b06cd8ee14165a &&
-       git cat-file tag 149cedb5c46929d18e0f118e9fa31927487af3b6
-'
-
-test_done
diff --git a/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 b/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6
deleted file mode 100644 (file)
index 472fd14..0000000
Binary files a/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 and /dev/null differ
diff --git a/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 b/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435
deleted file mode 100644 (file)
index c379d74..0000000
Binary files a/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 and /dev/null differ
diff --git a/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd b/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd
deleted file mode 100644 (file)
index 9370630..0000000
Binary files a/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd and /dev/null differ
diff --git a/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 b/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99
deleted file mode 100644 (file)
index bdcf704..0000000
Binary files a/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 and /dev/null differ
diff --git a/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e b/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e
deleted file mode 100644 (file)
index ad62c43..0000000
Binary files a/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e and /dev/null differ
diff --git a/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 b/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696
deleted file mode 100644 (file)
index 3d2f033..0000000
Binary files a/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 and /dev/null differ
diff --git a/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd b/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd
deleted file mode 100644 (file)
index b3f71a6..0000000
Binary files a/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd and /dev/null differ
diff --git a/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb b/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb
deleted file mode 100644 (file)
index af4e9a7..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
\vx\9c%ÌA\ e\820\10@Ñ}O1{cSZ(\98\18ãνá\ 2Ãthª\94\92Z\8cÜÞ Ëÿ\16?\r\ f¦\ 2m×6dµi\9d\19É9\85¤Gå\98h\a´Ø¨ÁZR'Q¶\85\81R\8c¡\88\82\1eø³p\ e\91ç\82ÓqL9âÏ=g¸§\81sIÐo\13opÎÿ\94eÏ«_1»\80³¤$×ç\ 5*Si«ëNwpP\95RBôûÅÁú
\87[(ð®d-\8dø\ 2ÁL9á
\ No newline at end of file
diff --git a/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 b/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09
deleted file mode 100644 (file)
index 3dd28be..0000000
Binary files a/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 and /dev/null differ
diff --git a/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 b/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8
deleted file mode 100644 (file)
index 2b97b26..0000000
Binary files a/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 and /dev/null differ
diff --git a/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 b/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730
deleted file mode 100644 (file)
index 6dff746..0000000
Binary files a/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 and /dev/null differ
diff --git a/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa b/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa
deleted file mode 100644 (file)
index cb41e92..0000000
Binary files a/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa and /dev/null differ
diff --git a/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f b/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f
deleted file mode 100644 (file)
index 7ac46b4..0000000
Binary files a/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f and /dev/null differ
diff --git a/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 b/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832
deleted file mode 100644 (file)
index 9d8316d..0000000
Binary files a/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 and /dev/null differ
diff --git a/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 b/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8
deleted file mode 100644 (file)
index eebf239..0000000
Binary files a/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 and /dev/null differ
diff --git a/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
deleted file mode 100644 (file)
index 134cf19..0000000
Binary files a/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 and /dev/null differ
diff --git a/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a b/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a
deleted file mode 100644 (file)
index 26b75ae..0000000
+++ /dev/null
@@ -1 +0,0 @@
-H\89\15ÌÁ\ e\820\f\80aÏ{\8aÞ\rI»e\1d&Æø*¥\1d\88\ 1\17ß^¸ýù\ e¿Ë\ 4DåÒ\86wU\87Ò\97¬\1cS±4ª\19\8aÆ\11­ª\9e ,\19\afÅ[ðßVAÛºÎ\1eüxÈÇö6[wtG§Lu\a¸?\97¦²¼Ú×\1f@\89"gì{\86+\12b\b\7fy¾%M
\ No newline at end of file
index 46103a1591680c9803588d24a135abf79fe64ae9..3a2c81968cf7d539410358de1c8af6cf1d2500c9 100755 (executable)
@@ -3,17 +3,28 @@
 test_description='Test wacky input to git config'
 . ./test-lib.sh
 
+# Leaving off the newline is intentional!
 setup() {
        (printf "[section]\n" &&
        printf "  key = foo") >.git/config
 }
 
+# 'check section.key value' verifies that the entry for section.key is
+# 'value'
 check() {
        echo "$2" >expected
        git config --get "$1" >actual 2>&1
        test_cmp actual expected
 }
 
+# 'check section.key regex value' verifies that the entry for
+# section.key *that matches 'regex'* is 'value'
+check_regex() {
+       echo "$3" >expected
+       git config --get "$1" "$2" >actual 2>&1
+       test_cmp actual expected
+}
+
 test_expect_success 'modify same key' '
        setup &&
        git config section.key bar &&
@@ -47,4 +58,57 @@ test_expect_success 'do not crash on special long config line' '
        check section.key "$LONG_VALUE"
 '
 
+setup_many() {
+       setup &&
+       # This time we want the newline so that we can tack on more
+       # entries.
+       echo >>.git/config &&
+       # Semi-efficient way of concatenating 5^5 = 3125 lines. Note
+       # that because 'setup' already put one line, this means 3126
+       # entries for section.key in the config file.
+       cat >5to1 <<-\EOF &&
+         key = foo
+         key = foo
+         key = foo
+         key = foo
+         key = foo
+       EOF
+       cat 5to1 5to1 5to1 5to1 5to1 >5to2 &&      # 25
+       cat 5to2 5to2 5to2 5to2 5to2 >5to3 &&      # 125
+       cat 5to3 5to3 5to3 5to3 5to3 >5to4 &&      # 635
+       cat 5to4 5to4 5to4 5to4 5to4 >>.git/config # 3125
+}
+
+test_expect_success 'get many entries' '
+       setup_many &&
+       git config --get-all section.key >actual &&
+       test_line_count = 3126 actual
+'
+
+test_expect_success 'get many entries by regex' '
+       setup_many &&
+       git config --get-regexp "sec.*ke." >actual &&
+       test_line_count = 3126 actual
+'
+
+test_expect_success 'add and replace one of many entries' '
+       setup_many &&
+       git config --add section.key bar &&
+       check_regex section.key "b.*r" bar &&
+       git config section.key beer "b.*r" &&
+       check_regex section.key "b.*r" beer
+'
+
+test_expect_success 'replace many entries' '
+       setup_many &&
+       git config --replace-all section.key bar &&
+       check section.key bar
+'
+
+test_expect_success 'unset many entries' '
+       setup_many &&
+       git config --unset-all section.key &&
+       test_must_fail git config section.key
+'
+
 test_done
index 13c88c9aae7f7177cbff278cf5e587f86acb11e7..83b1300cef91c2a13ef58af4ab7a42618388bd01 100755 (executable)
@@ -12,9 +12,11 @@ usage: some-command [options] <args>...
     -h, --help            show the help
     --foo                 some nifty option --foo
     --bar ...             some cool option --bar with an argument
+    -b, --baz             a short and long option
 
 An option group Header
     -C[...]               option C with an optional argument
+    -d, --data[=...]      short and long option with an optional argument
 
 Extras
     --extra1              line above used to cause a segfault but no longer does
@@ -31,9 +33,11 @@ h,help    show the help
 
 foo       some nifty option --foo
 bar=      some cool option --bar with an argument
+b,baz     a short and long option
 
  An option group Header
 C?        option C with an optional argument
+d,data?   short and long option with an optional argument
 
 Extras
 extra1    line above used to cause a segfault but no longer does
@@ -45,16 +49,16 @@ test_expect_success 'test --parseopt help output' '
 '
 
 cat > expect <<EOF
-set -- --foo --bar 'ham' -- 'arg'
+set -- --foo --bar 'ham' -b -- 'arg'
 EOF
 
 test_expect_success 'test --parseopt' '
-       git rev-parse --parseopt -- --foo --bar=ham arg < optionspec > output &&
+       git rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output &&
        test_cmp expect output
 '
 
 test_expect_success 'test --parseopt with mixed options and arguments' '
-       git rev-parse --parseopt -- --foo arg --bar=ham < optionspec > output &&
+       git rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output &&
        test_cmp expect output
 '
 
@@ -99,4 +103,36 @@ test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option withou
        test_cmp expect output
 '
 
+cat > expect <<EOF
+set -- --foo --bar='z' --baz -C'Z' --data='A' -- 'arg'
+EOF
+
+test_expect_success 'test --parseopt --stuck-long' '
+       git rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA <optionspec >output &&
+       test_cmp expect output
+'
+
+cat > expect <<EOF
+set -- --data='' -C --baz -- 'arg'
+EOF
+
+test_expect_success 'test --parseopt --stuck-long and empty optional argument' '
+       git rev-parse --parseopt --stuck-long -- --data= arg -C -b <optionspec >output &&
+       test_cmp expect output
+'
+
+cat > expect <<EOF
+set -- --data --baz -- 'arg'
+EOF
+
+test_expect_success 'test --parseopt --stuck-long and long option with unset optional argument' '
+       git rev-parse --parseopt --stuck-long -- --data arg -b <optionspec >output &&
+       test_cmp expect output
+'
+
+test_expect_success 'test --parseopt --stuck-long and short option with unset optional argument' '
+       git rev-parse --parseopt --stuck-long -- -d arg -b <optionspec >output &&
+       test_cmp expect output
+'
+
 test_done
index f950c101287c2f05bbd70c1faffbcf2cda1edbee..613d9bfe1bbb153d1c2e647aee26a60e07a6af86 100755 (executable)
@@ -196,4 +196,28 @@ test_expect_success 'dotdot is not an empty set' '
        test_cmp expect actual
 '
 
+test_expect_success 'arg before dashdash must be a revision (missing)' '
+       test_must_fail git rev-parse foobar -- 2>stderr &&
+       test_i18ngrep "bad revision" stderr
+'
+
+test_expect_success 'arg before dashdash must be a revision (file)' '
+       >foobar &&
+       test_must_fail git rev-parse foobar -- 2>stderr &&
+       test_i18ngrep "bad revision" stderr
+'
+
+test_expect_success 'arg before dashdash must be a revision (ambiguous)' '
+       >foobar &&
+       git update-ref refs/heads/foobar HEAD &&
+       {
+               # we do not want to use rev-parse here, because
+               # we are testing it
+               cat .git/refs/heads/foobar &&
+               printf "%s\n" --
+       } >expect &&
+       git rev-parse foobar -- >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 9dc91d09d7ef3c66c39bcf930bb486312cf291af..24ddd8a704b22e32322b8ef52bbd0d2e6195e5e1 100755 (executable)
@@ -2,7 +2,6 @@
 
 test_description='add -i basic tests'
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 if ! test_have_prereq PERL
 then
index e3ea3d5114b8f6a09b79c9a1323c563da0c7b170..49e2d6c34983c7e4620739a52ecc03cf158efe3a 100755 (executable)
@@ -7,7 +7,6 @@ test_description='git apply handling copy/rename patch.
 
 '
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 # setup
 
index 2298ece8019d79ef718ef658bdac74493d265b92..1e4d4380bf01c081aeb1df44cef40319063f2faa 100755 (executable)
@@ -48,12 +48,12 @@ test_expect_success 'apply in reverse' '
 
 test_expect_success 'setup separate repository lacking postimage' '
 
-       git tar-tree initial initial | $TAR xf - &&
+       git archive --format=tar --prefix=initial/ initial | $TAR xf - &&
        (
                cd initial && git init && git add .
        ) &&
 
-       git tar-tree second second | $TAR xf - &&
+       git archive --format=tar --prefix=second/ second | $TAR xf - &&
        (
                cd second && git init && git add .
        )
index c5fecdfed43dc5682307dd0fdb66ddd78dece056..497b62868d4aa0f81c62178ee9b1a5a108b89c0d 100755 (executable)
@@ -6,7 +6,6 @@
 test_description='git apply -p handling.'
 
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 test_expect_success setup '
        mkdir sub &&
index 0d36ebdc8653d7d22ab5831c1f154db452e4558e..c268298eaf5672c649ca3e4815dc4f43d71efece 100755 (executable)
@@ -3,7 +3,6 @@
 test_description='applying patch with mode bits'
 
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 test_expect_success setup '
        echo original >file &&
index c2023b1a3d78a7f100207a76678957d2659f8a8d..05f011d38eeaf16e2be8caace5bca697b7a9daf3 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright (C) 2005 Rene Scharfe
 #
 
-test_description='git tar-tree and git get-tar-commit-id test
+test_description='git archive and git get-tar-commit-id test
 
 This test covers the topics of file contents, commit date handling and
 commit id embedding:
@@ -13,11 +13,11 @@ commit id embedding:
   binary file (/bin/sh).  Only paths shorter than 99 characters are
   used.
 
-  git tar-tree applies the commit date to every file in the archive it
+  git archive applies the commit date to every file in the archive it
   creates.  The test sets the commit date to a specific value and checks
   if the tar archive contains that value.
 
-  When giving git tar-tree a commit id (in contrast to a tree id) it
+  When giving git archive a commit id (in contrast to a tree id) it
   embeds this commit id into the tar archive as a comment.  The test
   checks the ability of git get-tar-commit-id to figure it out from the
   tar file.
@@ -25,8 +25,6 @@ commit id embedding:
 '
 
 . ./test-lib.sh
-GZIP=${GZIP:-gzip}
-GUNZIP=${GUNZIP:-gzip -d}
 
 SUBSTFORMAT=%H%n
 
@@ -39,6 +37,8 @@ test_lazy_prereq TAR_NEEDS_PAX_FALLBACK '
        )
 '
 
+test_lazy_prereq GZIP 'gzip --version'
+
 get_pax_header() {
        file=$1
        header=$2=
@@ -196,16 +196,6 @@ test_expect_success \
     'git get-tar-commit-id <b.tar >b.commitid &&
      test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
 
-test_expect_success 'git tar-tree' '
-       git tar-tree HEAD >tar-tree.tar &&
-       test_cmp b.tar tar-tree.tar
-'
-
-test_expect_success 'git tar-tree with prefix' '
-       git tar-tree HEAD prefix >tar-tree_with_prefix.tar &&
-       test_cmp with_prefix.tar tar-tree_with_prefix.tar
-'
-
 test_expect_success 'git archive with --output, override inferred format' '
        git archive --format=tar --output=d4.zip HEAD &&
        test_cmp b.tar d4.zip
@@ -275,12 +265,6 @@ test_expect_success 'only enabled filters are available remotely' '
        test_cmp remote.bar config.bar
 '
 
-if $GZIP --version >/dev/null 2>&1; then
-       test_set_prereq GZIP
-else
-       say "Skipping some tar.gz tests because gzip not found"
-fi
-
 test_expect_success GZIP 'git archive --format=tgz' '
        git archive --format=tgz HEAD >j.tgz
 '
@@ -300,14 +284,8 @@ test_expect_success GZIP 'infer tgz from .tar.gz filename' '
        test_cmp j.tgz j3.tar.gz
 '
 
-if $GUNZIP --version >/dev/null 2>&1; then
-       test_set_prereq GUNZIP
-else
-       say "Skipping some tar.gz tests because gunzip was not found"
-fi
-
-test_expect_success GZIP,GUNZIP 'extract tgz file' '
-       $GUNZIP -c <j.tgz >j.tar &&
+test_expect_success GZIP 'extract tgz file' '
+       gzip -d -c <j.tgz >j.tar &&
        test_cmp b.tar j.tar
 '
 
index f47d8717fdd93cf8ebf356c2675511567782335e..51dedab29b682749990fb29a3f11134a2629f941 100755 (executable)
@@ -87,14 +87,4 @@ test_expect_success 'export-subst' '
        test_cmp substfile2 archive/substfile2
 '
 
-test_expect_success 'git tar-tree vs. git archive with worktree attributes' '
-       git tar-tree HEAD >tar-tree.tar &&
-       test_cmp worktree.tar tar-tree.tar
-'
-
-test_expect_success 'git tar-tree vs. git archive with worktree attrs, bare' '
-       (cd bare && git tar-tree HEAD) >bare-tar-tree.tar &&
-       test_cmp bare-worktree.tar bare-tar-tree.tar
-'
-
 test_done
index d87ddf73b7127bc624ca739653db9389831b817e..5b2b1c2c130387332778f6e49043b739dd2d7d21 100755 (executable)
@@ -531,5 +531,92 @@ test_expect_success 'shallow fetch with tags does not break the repository' '
                git fsck
        )
 '
+check_prot_path () {
+       cat >expected <<-EOF &&
+       Diag: url=$1
+       Diag: protocol=$2
+       Diag: path=$3
+       EOF
+       git fetch-pack --diag-url "$1" | grep -v hostandport= >actual &&
+       test_cmp expected actual
+}
+
+check_prot_host_path () {
+       cat >expected <<-EOF &&
+       Diag: url=$1
+       Diag: protocol=$2
+       Diag: hostandport=$3
+       Diag: path=$4
+       EOF
+       git fetch-pack --diag-url "$1" >actual &&
+       test_cmp expected actual
+}
+
+for r in repo re:po re/po
+do
+       # git or ssh with scheme
+       for p in "ssh+git" "git+ssh" git ssh
+       do
+               for h in host host:12 [::1] [::1]:23
+               do
+                       case "$p" in
+                       *ssh*)
+                               pp=ssh
+                               ;;
+                       *)
+                               pp=$p
+                       ;;
+                       esac
+                       test_expect_success "fetch-pack --diag-url $p://$h/$r" '
+                               check_prot_host_path $p://$h/$r $pp "$h" "/$r"
+                       '
+                       # "/~" -> "~" conversion
+                       test_expect_success "fetch-pack --diag-url $p://$h/~$r" '
+                               check_prot_host_path $p://$h/~$r $pp "$h" "~$r"
+                       '
+               done
+       done
+       # file with scheme
+       for p in file
+       do
+               test_expect_success "fetch-pack --diag-url $p://$h/$r" '
+                       check_prot_path $p://$h/$r $p "/$r"
+               '
+               # No "/~" -> "~" conversion for file
+               test_expect_success "fetch-pack --diag-url $p://$h/~$r" '
+                       check_prot_path $p://$h/~$r $p "/~$r"
+               '
+       done
+       # file without scheme
+       for h in nohost nohost:12 [::1] [::1]:23 [ [:aa
+       do
+               test_expect_success "fetch-pack --diag-url ./$h:$r" '
+                       check_prot_path ./$h:$r $p "./$h:$r"
+               '
+               # No "/~" -> "~" conversion for file
+               test_expect_success "fetch-pack --diag-url ./$p:$h/~$r" '
+               check_prot_path ./$p:$h/~$r $p "./$p:$h/~$r"
+               '
+       done
+       #ssh without scheme
+       p=ssh
+       for h in host [::1]
+       do
+               test_expect_success "fetch-pack --diag-url $h:$r" '
+                       check_prot_path $h:$r $p "$r"
+               '
+               # Do "/~" -> "~" conversion
+               test_expect_success "fetch-pack --diag-url $h:/~$r" '
+                       check_prot_host_path $h:/~$r $p "$h" "~$r"
+               '
+       done
+done
+
+test_expect_success MINGW 'fetch-pack --diag-url file://c:/repo' '
+       check_prot_path file://c:/repo file c:/repo
+'
+test_expect_success MINGW 'fetch-pack --diag-url c:repo' '
+       check_prot_path c:repo file c:repo
+'
 
 test_done
index 1f0f8e6827773b1bb9a419a822de2d1ebde8e37a..5d4581dac84f0688389ca96ba139518336b78dba 100755 (executable)
@@ -88,7 +88,7 @@ test_expect_success 'fetch --prune on its own works as expected' '
        cd "$D" &&
        git clone . prune &&
        cd prune &&
-       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+       git update-ref refs/remotes/origin/extrabranch master &&
 
        git fetch --prune origin &&
        test_must_fail git rev-parse origin/extrabranch
@@ -98,7 +98,7 @@ test_expect_success 'fetch --prune with a branch name keeps branches' '
        cd "$D" &&
        git clone . prune-branch &&
        cd prune-branch &&
-       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+       git update-ref refs/remotes/origin/extrabranch master &&
 
        git fetch --prune origin master &&
        git rev-parse origin/extrabranch
@@ -113,25 +113,45 @@ test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
        git rev-parse origin/master
 '
 
-test_expect_success 'fetch --prune --tags does not delete the remote-tracking branches' '
+test_expect_success 'fetch --prune --tags prunes branches but not tags' '
        cd "$D" &&
        git clone . prune-tags &&
        cd prune-tags &&
-       git fetch origin refs/heads/master:refs/tags/sometag &&
+       git tag sometag master &&
+       # Create what looks like a remote-tracking branch from an earlier
+       # fetch that has since been deleted from the remote:
+       git update-ref refs/remotes/origin/fake-remote master &&
 
        git fetch --prune --tags origin &&
        git rev-parse origin/master &&
-       test_must_fail git rev-parse somebranch
+       test_must_fail git rev-parse origin/fake-remote &&
+       git rev-parse sometag
 '
 
-test_expect_success 'fetch --prune --tags with branch does not delete other remote-tracking branches' '
+test_expect_success 'fetch --prune --tags with branch does not prune other things' '
        cd "$D" &&
        git clone . prune-tags-branch &&
        cd prune-tags-branch &&
-       git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
+       git tag sometag master &&
+       git update-ref refs/remotes/origin/extrabranch master &&
 
        git fetch --prune --tags origin master &&
-       git rev-parse origin/extrabranch
+       git rev-parse origin/extrabranch &&
+       git rev-parse sometag
+'
+
+test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' '
+       cd "$D" &&
+       git clone . prune-tags-refspec &&
+       cd prune-tags-refspec &&
+       git tag sometag master &&
+       git update-ref refs/remotes/origin/foo/otherbranch master &&
+       git update-ref refs/remotes/origin/extrabranch master &&
+
+       git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
+       test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
+       git rev-parse origin/extrabranch &&
+       git rev-parse sometag
 '
 
 test_expect_success 'fetch tags when there is no tags' '
index 1669cc4af0e8b3d179bcff9dd850f2f363278005..0f70f66c705dd6af9f9861ae2e33223d1b944d3a 100644 (file)
@@ -1,4 +1,5 @@
 # br-unconfig --tags ../.git
+0567da4d5edd2ff4bb292a465ba9e64dcad9536b               ../
 6c9dec2b923228c9ff994c6cfe4ae16c12408dc5       not-for-merge   tag 'tag-master' of ../
 8e32a6d901327a23ef831511badce7bf3bf46689       not-for-merge   tag 'tag-one' of ../
 22feea448b023a2d864ef94b013735af34d238ba       not-for-merge   tag 'tag-one-tree' of ../
index 8a7493537b99ac9592fd548300d5332e4163ab77..ab473a6e1f76ddf0f10a78358097d5e3bf16bc02 100644 (file)
@@ -1,4 +1,5 @@
 # master --tags ../.git
+0567da4d5edd2ff4bb292a465ba9e64dcad9536b               ../
 6c9dec2b923228c9ff994c6cfe4ae16c12408dc5       not-for-merge   tag 'tag-master' of ../
 8e32a6d901327a23ef831511badce7bf3bf46689       not-for-merge   tag 'tag-one' of ../
 22feea448b023a2d864ef94b013735af34d238ba       not-for-merge   tag 'tag-one-tree' of ../
index 99c32d75391bb02fae779ad831879903abca5d25..926e7f6b979d4d1c69ecc9d280cd6de365627012 100755 (executable)
@@ -1126,6 +1126,81 @@ test_expect_success 'fetch follows tags by default' '
        test_cmp expect actual
 '
 
+test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' '
+       mk_test testrepo heads/master &&
+       rm -fr src dst &&
+       git init src &&
+       git init --bare dst &&
+       (
+               cd src &&
+               git pull ../testrepo master &&
+               git branch next &&
+               git config remote.dst.url ../dst &&
+               git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
+               git push dst master &&
+               git show-ref refs/heads/master |
+               sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
+       ) &&
+       (
+               cd dst &&
+               test_must_fail git show-ref refs/heads/next &&
+               test_must_fail git show-ref refs/heads/master &&
+               git show-ref refs/remotes/src/master >actual
+       ) &&
+       test_cmp dst/expect dst/actual
+'
+
+test_expect_success 'with no remote.$name.push, it is not used as refmap' '
+       mk_test testrepo heads/master &&
+       rm -fr src dst &&
+       git init src &&
+       git init --bare dst &&
+       (
+               cd src &&
+               git pull ../testrepo master &&
+               git branch next &&
+               git config remote.dst.url ../dst &&
+               git config push.default matching &&
+               git push dst master &&
+               git show-ref refs/heads/master >../dst/expect
+       ) &&
+       (
+               cd dst &&
+               test_must_fail git show-ref refs/heads/next &&
+               git show-ref refs/heads/master >actual
+       ) &&
+       test_cmp dst/expect dst/actual
+'
+
+test_expect_success 'with no remote.$name.push, upstream mapping is used' '
+       mk_test testrepo heads/master &&
+       rm -fr src dst &&
+       git init src &&
+       git init --bare dst &&
+       (
+               cd src &&
+               git pull ../testrepo master &&
+               git branch next &&
+               git config remote.dst.url ../dst &&
+               git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
+               git config push.default upstream &&
+
+               git config branch.master.merge refs/heads/trunk &&
+               git config branch.master.remote dst &&
+
+               git push dst master &&
+               git show-ref refs/heads/master |
+               sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect
+       ) &&
+       (
+               cd dst &&
+               test_must_fail git show-ref refs/heads/master &&
+               test_must_fail git show-ref refs/heads/next &&
+               git show-ref refs/heads/trunk >actual
+       ) &&
+       test_cmp dst/expect dst/actual
+'
+
 test_expect_success 'push does not follow tags by default' '
        mk_test testrepo heads/master &&
        rm -fr src dst &&
index 4fbf7a120f3fd4133e09cb7cbe5c8e4597bfa27c..45815f737850b61684f648af9d984ac16ea0944e 100755 (executable)
@@ -8,7 +8,8 @@ setup_clone () {
        git clone --mirror . $1 &&
        git remote add remote_$1 $1 &&
        (cd $1 &&
-       git tag tag_$1)
+       git tag tag_$1 &&
+       git branch branch_$1)
 }
 
 test_expect_success setup '
@@ -21,21 +22,33 @@ test_expect_success setup '
 
 test_expect_success "fetch with tagopt=--no-tags does not get tag" '
        git fetch remote_one &&
-       test_must_fail git show-ref tag_one
+       test_must_fail git show-ref tag_one &&
+       git show-ref remote_one/branch_one
        '
 
 test_expect_success "fetch --tags with tagopt=--no-tags gets tag" '
+       (
+               cd one &&
+               git branch second_branch_one
+       ) &&
        git fetch --tags remote_one &&
-       git show-ref tag_one
+       git show-ref tag_one &&
+       git show-ref remote_one/second_branch_one
        '
 
 test_expect_success "fetch --no-tags with tagopt=--tags does not get tag" '
        git fetch --no-tags remote_two &&
-       test_must_fail git show-ref tag_two
+       test_must_fail git show-ref tag_two &&
+       git show-ref remote_two/branch_two
        '
 
 test_expect_success "fetch with tagopt=--tags gets tag" '
+       (
+               cd two &&
+               git branch second_branch_two
+       ) &&
        git fetch remote_two &&
-       git show-ref tag_two
+       git show-ref tag_two &&
+       git show-ref remote_two/second_branch_two
        '
 test_done
diff --git a/t/t5536-fetch-conflicts.sh b/t/t5536-fetch-conflicts.sh
new file mode 100755 (executable)
index 0000000..6c5d3a4
--- /dev/null
@@ -0,0 +1,100 @@
+#!/bin/sh
+
+test_description='fetch handles conflicting refspecs correctly'
+
+. ./test-lib.sh
+
+D=$(pwd)
+
+setup_repository () {
+       git init "$1" && (
+               cd "$1" &&
+               git config remote.origin.url "$D" &&
+               shift &&
+               for refspec in "$@"
+               do
+                       git config --add remote.origin.fetch "$refspec"
+               done
+       )
+}
+
+verify_stderr () {
+       cat >expected &&
+       # We're not interested in the error
+       # "fatal: The remote end hung up unexpectedly":
+       grep -E '^(fatal|warning):' <error | grep -v 'hung up' >actual | sort &&
+       test_cmp expected actual
+}
+
+test_expect_success 'setup' '
+       git commit --allow-empty -m "Initial" &&
+       git branch branch1 &&
+       git tag tag1 &&
+       git commit --allow-empty -m "First" &&
+       git branch branch2 &&
+       git tag tag2
+'
+
+test_expect_success 'fetch with no conflict' '
+       setup_repository ok "+refs/heads/*:refs/remotes/origin/*" && (
+               cd ok &&
+               git fetch origin
+       )
+'
+
+test_expect_success 'fetch conflict: config vs. config' '
+       setup_repository ccc \
+               "+refs/heads/branch1:refs/remotes/origin/branch1" \
+               "+refs/heads/branch2:refs/remotes/origin/branch1" && (
+               cd ccc &&
+               test_must_fail git fetch origin 2>error &&
+               verify_stderr <<-\EOF
+               fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1
+               EOF
+       )
+'
+
+test_expect_success 'fetch duplicate: config vs. config' '
+       setup_repository dcc \
+               "+refs/heads/*:refs/remotes/origin/*" \
+               "+refs/heads/branch1:refs/remotes/origin/branch1" && (
+               cd dcc &&
+               git fetch origin
+       )
+'
+
+test_expect_success 'fetch conflict: arg overrides config' '
+       setup_repository aoc \
+               "+refs/heads/*:refs/remotes/origin/*" && (
+               cd aoc &&
+               git fetch origin refs/heads/branch2:refs/remotes/origin/branch1
+       )
+'
+
+test_expect_success 'fetch conflict: arg vs. arg' '
+       setup_repository caa && (
+               cd caa &&
+               test_must_fail git fetch origin \
+                       refs/heads/*:refs/remotes/origin/* \
+                       refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
+               verify_stderr <<-\EOF
+               fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1
+               EOF
+       )
+'
+
+test_expect_success 'fetch conflict: criss-cross args' '
+       setup_repository xaa \
+               "+refs/heads/*:refs/remotes/origin/*" && (
+               cd xaa &&
+               git fetch origin \
+                       refs/heads/branch1:refs/remotes/origin/branch2 \
+                       refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
+               verify_stderr <<-\EOF
+               warning: refs/remotes/origin/branch1 usually tracks refs/heads/branch1, not refs/heads/branch2
+               warning: refs/remotes/origin/branch2 usually tracks refs/heads/branch2, not refs/heads/branch1
+               EOF
+       )
+'
+
+test_done
index 1d1c8755ead4e432744a82f0d7b8ed7dfc8a6510..62fbd7e6649d9215528a83249f1b46735de2237d 100755 (executable)
@@ -280,25 +280,26 @@ test_expect_success 'clone checking out a tag' '
        test_cmp fetch.expected fetch.actual
 '
 
-test_expect_success 'setup ssh wrapper' '
-       write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
-       echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" &&
-       # throw away all but the last argument, which should be the
-       # command
-       while test $# -gt 1; do shift; done
-       eval "$1"
-       EOF
-
-       GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
-       export GIT_SSH &&
-       export TRASH_DIRECTORY
-'
-
-clear_ssh () {
-       >"$TRASH_DIRECTORY/ssh-output"
+setup_ssh_wrapper () {
+       test_expect_success 'setup ssh wrapper' '
+               write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
+               echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" &&
+               # throw away all but the last argument, which should be the
+               # command
+               while test $# -gt 1; do shift; done
+               eval "$1"
+               EOF
+               GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
+               export GIT_SSH &&
+               export TRASH_DIRECTORY &&
+               >"$TRASH_DIRECTORY"/ssh-output
+       '
 }
 
 expect_ssh () {
+       test_when_finished '
+               (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
+       ' &&
        {
                case "$1" in
                none)
@@ -310,25 +311,114 @@ expect_ssh () {
        (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
 }
 
-test_expect_success 'cloning myhost:src uses ssh' '
-       clear_ssh &&
+setup_ssh_wrapper
+
+test_expect_success 'clone myhost:src uses ssh' '
        git clone myhost:src ssh-clone &&
        expect_ssh myhost src
 '
 
 test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' '
-       clear_ssh &&
        cp -R src "foo:bar" &&
-       git clone "./foo:bar" foobar &&
+       git clone "foo:bar" foobar &&
        expect_ssh none
 '
 
 test_expect_success 'bracketed hostnames are still ssh' '
-       clear_ssh &&
        git clone "[myhost:123]:src" ssh-bracket-clone &&
        expect_ssh myhost:123 src
 '
 
+counter=0
+# $1 url
+# $2 none|host
+# $3 path
+test_clone_url () {
+       counter=$(($counter + 1))
+       test_might_fail git clone "$1" tmp$counter &&
+       expect_ssh "$2" "$3"
+}
+
+test_expect_success NOT_MINGW 'clone c:temp is ssl' '
+       test_clone_url c:temp c temp
+'
+
+test_expect_success MINGW 'clone c:temp is dos drive' '
+       test_clone_url c:temp none
+'
+
+#ip v4
+for repo in rep rep/home/project 123
+do
+       test_expect_success "clone host:$repo" '
+               test_clone_url host:$repo host $repo
+       '
+done
+
+#ipv6
+for repo in rep rep/home/project 123
+do
+       test_expect_success "clone [::1]:$repo" '
+               test_clone_url [::1]:$repo ::1 $repo
+       '
+done
+#home directory
+test_expect_success "clone host:/~repo" '
+       test_clone_url host:/~repo host "~repo"
+'
+
+test_expect_success "clone [::1]:/~repo" '
+       test_clone_url [::1]:/~repo ::1 "~repo"
+'
+
+# Corner cases
+for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz
+do
+       test_expect_success "clone $url is not ssh" '
+               test_clone_url $url none
+       '
+done
+
+#with ssh:// scheme
+test_expect_success 'clone ssh://host.xz/home/user/repo' '
+       test_clone_url "ssh://host.xz/home/user/repo" host.xz "/home/user/repo"
+'
+
+# from home directory
+test_expect_success 'clone ssh://host.xz/~repo' '
+       test_clone_url "ssh://host.xz/~repo" host.xz "~repo"
+'
+
+# with port number
+test_expect_success 'clone ssh://host.xz:22/home/user/repo' '
+       test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo"
+'
+
+# from home directory with port number
+test_expect_success 'clone ssh://host.xz:22/~repo' '
+       test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo"
+'
+
+#IPv6
+test_expect_success 'clone ssh://[::1]/home/user/repo' '
+       test_clone_url "ssh://[::1]/home/user/repo" "::1" "/home/user/repo"
+'
+
+#IPv6 from home directory
+test_expect_success 'clone ssh://[::1]/~repo' '
+       test_clone_url "ssh://[::1]/~repo" "::1" "~repo"
+'
+
+#IPv6 with port number
+test_expect_success 'clone ssh://[::1]:22/home/user/repo' '
+       test_clone_url "ssh://[::1]:22/home/user/repo" "-p 22 ::1" "/home/user/repo"
+'
+
+#IPv6 from home directory with port number
+test_expect_success 'clone ssh://[::1]:22/~repo' '
+       test_clone_url "ssh://[::1]:22/~repo" "-p 22 ::1" "~repo"
+'
+
 test_expect_success 'clone from a repository with two identical branches' '
 
        (
index f00cebff3e42cf0a38d06a03b6f14ef08dd16372..d00f7db8687b8bedcbc810735a16c65df2324c18 100755 (executable)
@@ -129,6 +129,18 @@ test_expect_success 'rev-parse --remotes=foo' '
 
 '
 
+test_expect_success 'rev-parse --exclude with --branches' '
+       compare rev-parse "--exclude=*/* --branches" "master someref subspace-x"
+'
+
+test_expect_success 'rev-parse --exclude with --all' '
+       compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags"
+'
+
+test_expect_success 'rev-parse accumulates multiple --exclude' '
+       compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
+'
+
 test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
 
        compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
@@ -231,6 +243,48 @@ test_expect_success 'rev-list --remotes=foo' '
 
 '
 
+test_expect_success 'rev-list --exclude with --branches' '
+       compare rev-list "--exclude=*/* --branches" "master someref subspace-x"
+'
+
+test_expect_success 'rev-list --exclude with --all' '
+       compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags"
+'
+
+test_expect_success 'rev-list accumulates multiple --exclude' '
+       compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
+'
+
+
+# "git rev-list<ENTER>" is likely to be a bug in the calling script and may
+# deserve an error message, but do cases where set of refs programatically
+# given using globbing and/or --stdin need to fail with the same error, or
+# are we better off reporting a success with no output?  The following few
+# tests document the current behaviour to remind us that we might want to
+# think about this issue.
+
+test_expect_failure 'rev-list may want to succeed with empty output on no input (1)' '
+       >expect &&
+       git rev-list --stdin <expect >actual &&
+       test_cmp expect actual
+'
+
+test_expect_failure 'rev-list may want to succeed with empty output on no input (2)' '
+       >expect &&
+       git rev-list --exclude=* --all >actual &&
+       test_cmp expect actual
+'
+
+test_expect_failure 'rev-list may want to succeed with empty output on no input (3)' '
+       (
+               test_create_repo empty &&
+               cd empty &&
+               >expect &&
+               git rev-list --all >actual &&
+               test_cmp expect actual
+       )
+'
+
 test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
 
        compare shortlog "subspace/one subspace/two" --branches=subspace &&
index 1cd649e245e49735afa539ab0e982036154c4797..a953f1b55cc26aae703d3c84f74df3265cc2ed57 100755 (executable)
@@ -2,7 +2,6 @@
 
 test_description='merge-recursive: handle file mode'
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 test_expect_success 'mode change in one branch: keep changed version' '
        : >file1 &&
index 8d4a7fcb916f9669a9c9ef5b3668f881aff29217..a7c7ff5f4938c1fa7439e7c5a45321572bfc55fe 100755 (executable)
@@ -100,4 +100,10 @@ test_expect_success 'match_pathspec_depth matches :(icase)bar with empty prefix'
        test_cmp expect actual
 '
 
+test_expect_success '"git diff" can take magic :(icase) pathspec' '
+       echo FOO/BAR >expect &&
+       git diff --name-only HEAD^ HEAD -- ":(icase)foo/bar" >actual &&
+       test_cmp expect actual
+'
+
 test_done
index da5fb6c9170b3e7fd818a59fc6e48ff3161d12da..bda354c1c48bce9fc6fdc442c3ec89fb034f20d3 100755 (executable)
@@ -18,16 +18,13 @@ setdate_and_increment () {
     export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
 }
 
-test_expect_success 'Create sample commit with known timestamp' '
+test_expect_success setup '
        setdate_and_increment &&
        echo "Using $datestamp" > one &&
        git add one &&
        git commit -m "Initial" &&
        setdate_and_increment &&
-       git tag -a -m "Tagging at $datestamp" testtag
-'
-
-test_expect_success 'Create upstream config' '
+       git tag -a -m "Tagging at $datestamp" testtag &&
        git update-ref refs/remotes/origin/master master &&
        git remote add origin nowhere &&
        git config branch.master.remote origin &&
@@ -52,8 +49,8 @@ test_atom head refname refs/heads/master
 test_atom head upstream refs/remotes/origin/master
 test_atom head objecttype commit
 test_atom head objectsize 171
-test_atom head objectname 67a36f10722846e891fbada1ba48ed035de75581
-test_atom head tree 0e51c00fcb93dffc755546f27593d511e1bdb46f
+test_atom head objectname $(git rev-parse refs/heads/master)
+test_atom head tree $(git rev-parse refs/heads/master^{tree})
 test_atom head parent ''
 test_atom head numparent 0
 test_atom head object ''
@@ -82,16 +79,17 @@ test_atom head contents:body ''
 test_atom head contents:signature ''
 test_atom head contents 'Initial
 '
+test_atom head HEAD '*'
 
 test_atom tag refname refs/tags/testtag
 test_atom tag upstream ''
 test_atom tag objecttype tag
 test_atom tag objectsize 154
-test_atom tag objectname 98b46b1d36e5b07909de1b3886224e3e81e87322
+test_atom tag objectname $(git rev-parse refs/tags/testtag)
 test_atom tag tree ''
 test_atom tag parent ''
 test_atom tag numparent ''
-test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581'
+test_atom tag object $(git rev-parse refs/tags/testtag^0)
 test_atom tag type 'commit'
 test_atom tag '*objectname' '67a36f10722846e891fbada1ba48ed035de75581'
 test_atom tag '*objecttype' 'commit'
@@ -117,6 +115,7 @@ test_atom tag contents:body ''
 test_atom tag contents:signature ''
 test_atom tag contents 'Tagging at 1151939927
 '
+test_atom tag HEAD ' '
 
 test_expect_success 'Check invalid atoms names are errors' '
        test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
@@ -308,8 +307,35 @@ test_expect_success 'Check short upstream format' '
        test_cmp expected actual
 '
 
+test_expect_success 'setup for upstream:track[short]' '
+       test_commit two
+'
+
+cat >expected <<EOF
+[ahead 1]
+EOF
+
+test_expect_success 'Check upstream:track format' '
+       git for-each-ref --format="%(upstream:track)" refs/heads >actual &&
+       test_cmp expected actual
+'
+
+cat >expected <<EOF
+>
+EOF
+
+test_expect_success 'Check upstream:trackshort format' '
+       git for-each-ref --format="%(upstream:trackshort)" refs/heads >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'Check that :track[short] cannot be used with other atoms' '
+       test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
+       test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
+'
+
 cat >expected <<EOF
-67a36f1
+$(git rev-parse --short HEAD)
 EOF
 
 test_expect_success 'Check short objectname format' '
@@ -321,6 +347,23 @@ test_expect_success 'Check for invalid refname format' '
        test_must_fail git for-each-ref --format="%(refname:INVALID)"
 '
 
+get_color ()
+{
+       git config --get-color no.such.slot "$1"
+}
+
+cat >expected <<EOF
+$(git rev-parse --short refs/heads/master) $(get_color green)master$(get_color reset)
+$(git rev-parse --short refs/remotes/origin/master) $(get_color green)origin/master$(get_color reset)
+$(git rev-parse --short refs/tags/testtag) $(get_color green)testtag$(get_color reset)
+$(git rev-parse --short refs/tags/two) $(get_color green)two$(get_color reset)
+EOF
+
+test_expect_success 'Check %(color:...) ' '
+       git for-each-ref --format="%(objectname:short) %(color:green)%(refname:short)" >actual &&
+       test_cmp expected actual
+'
+
 cat >expected <<\EOF
 heads/master
 tags/master
@@ -460,9 +503,9 @@ test_atom refs/tags/signed-long contents "subject line
 body contents
 $sig"
 
-cat >expected <<\EOF
-408fe76d02a785a006c2e9c669b7be5589ede96d <committer@example.com> refs/tags/master
-90b5ebede4899eda64893bc2a4c8f1d6fb6dfc40 <committer@example.com> refs/tags/bogo
+cat >expected <<EOF
+$(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
+$(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
 EOF
 
 test_expect_success 'Verify sort with multiple keys' '
index b90e985a48efbf8cdb16c6166356f6984ffbcea8..3bfdfed1f7774edb8a87864bdb6a021dc6a185ed 100755 (executable)
@@ -70,6 +70,35 @@ test_expect_success \
 rm -f idontexist untracked1 untracked2 \
      path0/idontexist path0/untracked1 path0/untracked2 \
      .git/index.lock
+rmdir path1
+
+test_expect_success \
+    'moving to absent target with trailing slash' \
+    'test_must_fail git mv path0/COPYING no-such-dir/ &&
+     test_must_fail git mv path0/COPYING no-such-dir// &&
+     git mv path0/ no-such-dir/ &&
+     test_path_is_dir no-such-dir'
+
+test_expect_success \
+    'clean up' \
+    'git reset --hard'
+
+test_expect_success \
+    'moving to existing untracked target with trailing slash' \
+    'mkdir path1 &&
+     git mv path0/ path1/ &&
+     test_path_is_dir path1/path0/'
+
+test_expect_success \
+    'moving to existing tracked target with trailing slash' \
+    'mkdir path2 &&
+     >path2/file && git add path2/file &&
+     git mv path1/path0/ path2/ &&
+     test_path_is_dir path2/path0/'
+
+test_expect_success \
+    'clean up' \
+    'git reset --hard'
 
 test_expect_success \
     'adding another file' \
index 0825a928dfa2a340f6fce6e2313324bd5d63ea7f..0246e80b1af98fe213b06beb8de0a9fec464b9f2 100755 (executable)
@@ -762,6 +762,17 @@ test_expect_success 'submodule update clone shallow submodule' '
         (cd submodule &&
          test 1 = $(git log --oneline | wc -l)
         )
+)
+'
+
+test_expect_success 'submodule update --recursive drops module name before recursing' '
+       (cd super2 &&
+        (cd deeper/submodule/subsubmodule &&
+         git checkout HEAD^
+        ) &&
+        git submodule update --recursive deeper/submodule >actual &&
+        test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
        )
 '
+
 test_done
index da5bd3b5a585667dad97481df27049f0aa7415eb..2ddf28c984de99cb17884f76d68a708076f57e12 100755 (executable)
@@ -65,9 +65,35 @@ test_expect_success 'diff in message is retained without -v' '
        check_message diff
 '
 
-test_expect_failure 'diff in message is retained with -v' '
+test_expect_success 'diff in message is retained with -v' '
        git commit --amend -F diff -v &&
        check_message diff
 '
 
+test_expect_success 'submodule log is stripped out too with -v' '
+       git config diff.submodule log &&
+       git submodule add ./. sub &&
+       git commit -m "sub added" &&
+       (
+               cd sub &&
+               echo "more" >>file &&
+               git commit -a -m "submodule commit"
+       ) &&
+       (
+               GIT_EDITOR=cat &&
+               export GIT_EDITOR &&
+               test_must_fail git commit -a -v 2>err
+       ) &&
+       test_i18ngrep "Aborting commit due to empty commit message." err
+'
+
+test_expect_success 'verbose diff is stripped out with set core.commentChar' '
+       (
+               GIT_EDITOR=cat &&
+               export GIT_EDITOR &&
+               test_must_fail git -c core.commentchar=";" commit -a -v 2>err
+       ) &&
+       test_i18ngrep "Aborting commit due to empty commit message." err
+'
+
 test_done
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 3fb3368903686c8588c51e881beaee1f29808575..812c9cd462f58f6fd76e3d339e95137aee598801 100755 (executable)
@@ -5,7 +5,6 @@
 test_description='Test export of commits to CVS'
 
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 if ! test_have_prereq PERL; then
        skip_all='skipping git cvsexportcommit tests, perl not available'
index 2f79146e6ce0c5df32845f7c9c0927cea133ad5f..aeae3ca7699b4c828f8ebe50624b5179fb5098b8 100644 (file)
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Library of functions shared by all tests scripts, included by
+# test-lib.sh.
 #
 # Copyright (c) 2005 Junio C Hamano
 #
index b25249ec4cc2844f5cd7491dd5fcc88c884ff450..1cf78d5b113e0ddac8cdda9b8bc9b49db7b43451 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Test framework for git.  See t/README for usage.
 #
 # Copyright (c) 2005 Junio C Hamano
 #
@@ -26,6 +26,10 @@ then
        # outside of t/, e.g. for running tests on the test library
        # itself.
        TEST_DIRECTORY=$(pwd)
+else
+       # ensure that TEST_DIRECTORY is an absolute path so that it
+       # is valid even if the current working directory is changed
+       TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1
 fi
 if test -z "$TEST_OUTPUT_DIRECTORY"
 then
@@ -573,11 +577,9 @@ then
 
        make_valgrind_symlink () {
                # handle only executables, unless they are shell libraries that
-               # need to be in the exec-path.  We will just use "#!" as a
-               # guess for a shell-script, since we have no idea what the user
-               # may have configured as the shell path.
+               # need to be in the exec-path.
                test -x "$1" ||
-               test "#!" = "$(head -c 2 <"$1")" ||
+               test "# " = "$(head -c 2 <"$1")" ||
                return;
 
                base=$(basename "$1")
@@ -830,6 +832,10 @@ test_lazy_prereq SYMLINKS '
        ln -s x y && test -h y
 '
 
+test_lazy_prereq FILEMODE '
+       test "$(git config --bool core.filemode)" = true
+'
+
 test_lazy_prereq CASE_INSENSITIVE_FS '
        echo good >CamelCase &&
        echo bad >camelcase &&
diff --git a/tag.c b/tag.c
index 78d272b863f22285048cf54b9dcb03f80cb36f00..7b07921b30641994ab3a877b6b377c5ce1f40149 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -86,7 +86,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
                return -1;
        bufptr += 48; /* "object " + sha1 + "\n" */
 
-       if (prefixcmp(bufptr, "type "))
+       if (!starts_with(bufptr, "type "))
                return -1;
        bufptr += 5;
        nl = memchr(bufptr, '\n', tail - bufptr);
@@ -109,7 +109,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
                item->tagged = NULL;
        }
 
-       if (bufptr + 4 < tail && !prefixcmp(bufptr, "tag "))
+       if (bufptr + 4 < tail && starts_with(bufptr, "tag "))
                ;               /* good */
        else
                return -1;
@@ -120,7 +120,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
        item->tag = xmemdupz(bufptr, nl - bufptr);
        bufptr = nl + 1;
 
-       if (bufptr + 7 < tail && !prefixcmp(bufptr, "tagger "))
+       if (bufptr + 7 < tail && starts_with(bufptr, "tagger "))
                item->date = parse_tag_date(bufptr, tail);
        else
                item->date = 0;
@@ -160,8 +160,8 @@ size_t parse_signature(const char *buf, unsigned long size)
 {
        char *eol;
        size_t len = 0;
-       while (len < size && prefixcmp(buf + len, PGP_SIGNATURE) &&
-                       prefixcmp(buf + len, PGP_MESSAGE)) {
+       while (len < size && !starts_with(buf + len, PGP_SIGNATURE) &&
+                       !starts_with(buf + len, PGP_MESSAGE)) {
                eol = memchr(buf + len, '\n', size - len);
                len += eol ? eol - (buf + len) + 1 : size - len;
        }
index ef1d7bae1441e07b6cb74e83a23d07b4720a8ebf..1e58f0476f3465f9b8b361cc4776abf5c051430b 100644 (file)
@@ -19,7 +19,7 @@ static void handle_command(const char *command, const char *arg, struct line_buf
 {
        switch (*command) {
        case 'b':
-               if (!prefixcmp(command, "binary ")) {
+               if (starts_with(command, "binary ")) {
                        struct strbuf sb = STRBUF_INIT;
                        strbuf_addch(&sb, '>');
                        buffer_read_binary(buf, &sb, strtouint32(arg));
@@ -28,12 +28,12 @@ static void handle_command(const char *command, const char *arg, struct line_buf
                        return;
                }
        case 'c':
-               if (!prefixcmp(command, "copy ")) {
+               if (starts_with(command, "copy ")) {
                        buffer_copy_bytes(buf, strtouint32(arg));
                        return;
                }
        case 's':
-               if (!prefixcmp(command, "skip ")) {
+               if (starts_with(command, "skip ")) {
                        buffer_skip_bytes(buf, strtouint32(arg));
                        return;
                }
index 00ce6c9a129674c1922e0c388366592c5ae7c8c7..14bdf9d2153a98d0b2a5d03395c1adcc166f8a07 100644 (file)
@@ -38,7 +38,7 @@ static void write_list_compact(const struct string_list *list)
 static int prefix_cb(struct string_list_item *item, void *cb_data)
 {
        const char *prefix = (const char *)cb_data;
-       return !prefixcmp(item->string, prefix);
+       return starts_with(item->string, prefix);
 }
 
 int main(int argc, char **argv)
index 673b7c214f981cf158a8790b7278e37611c700fa..2010674bb4add9c09d02d703b5337a69b14a58a6 100644 (file)
@@ -190,7 +190,7 @@ static struct child_process *get_helper(struct transport *transport)
                        data->export = 1;
                else if (!strcmp(capname, "check-connectivity"))
                        data->check_connectivity = 1;
-               else if (!data->refspecs && !prefixcmp(capname, "refspec ")) {
+               else if (!data->refspecs && starts_with(capname, "refspec ")) {
                        ALLOC_GROW(refspecs,
                                   refspec_nr + 1,
                                   refspec_alloc);
@@ -199,17 +199,17 @@ static struct child_process *get_helper(struct transport *transport)
                        data->connect = 1;
                } else if (!strcmp(capname, "signed-tags")) {
                        data->signed_tags = 1;
-               } else if (!prefixcmp(capname, "export-marks ")) {
+               } else if (starts_with(capname, "export-marks ")) {
                        struct strbuf arg = STRBUF_INIT;
                        strbuf_addstr(&arg, "--export-marks=");
                        strbuf_addstr(&arg, capname + strlen("export-marks "));
                        data->export_marks = strbuf_detach(&arg, NULL);
-               } else if (!prefixcmp(capname, "import-marks")) {
+               } else if (starts_with(capname, "import-marks")) {
                        struct strbuf arg = STRBUF_INIT;
                        strbuf_addstr(&arg, "--import-marks=");
                        strbuf_addstr(&arg, capname + strlen("import-marks "));
                        data->import_marks = strbuf_detach(&arg, NULL);
-               } else if (!prefixcmp(capname, "no-private-update")) {
+               } else if (starts_with(capname, "no-private-update")) {
                        data->no_private_update = 1;
                } else if (mandatory) {
                        die("Unknown mandatory capability %s. This remote "
@@ -311,7 +311,7 @@ static int set_helper_option(struct transport *transport,
 
        if (!strcmp(buf.buf, "ok"))
                ret = 0;
-       else if (!prefixcmp(buf.buf, "error")) {
+       else if (starts_with(buf.buf, "error")) {
                ret = -1;
        } else if (!strcmp(buf.buf, "unsupported"))
                ret = 1;
@@ -375,7 +375,7 @@ static int fetch_with_fetch(struct transport *transport,
        while (1) {
                recvline(data, &buf);
 
-               if (!prefixcmp(buf.buf, "lock ")) {
+               if (starts_with(buf.buf, "lock ")) {
                        const char *name = buf.buf + 5;
                        if (transport->pack_lockfile)
                                warning("%s also locked %s", data->name, name);
@@ -646,10 +646,10 @@ static int push_update_ref_status(struct strbuf *buf,
        char *refname, *msg;
        int status;
 
-       if (!prefixcmp(buf->buf, "ok ")) {
+       if (starts_with(buf->buf, "ok ")) {
                status = REF_STATUS_OK;
                refname = buf->buf + 3;
-       } else if (!prefixcmp(buf->buf, "error ")) {
+       } else if (starts_with(buf->buf, "error ")) {
                status = REF_STATUS_REMOTE_REJECT;
                refname = buf->buf + 6;
        } else
index 7202b7777d804b75eb2ec54f666e81173690678c..824c5b93f9e1c44887b17ef116b360ec377076a6 100644 (file)
@@ -169,13 +169,13 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
                remotename = ref->name;
                tmp = resolve_ref_unsafe(localname, sha, 1, &flag);
                if (tmp && flag & REF_ISSYMREF &&
-                       !prefixcmp(tmp, "refs/heads/"))
+                       starts_with(tmp, "refs/heads/"))
                        localname = tmp;
 
                /* Both source and destination must be local branches. */
-               if (!localname || prefixcmp(localname, "refs/heads/"))
+               if (!localname || !starts_with(localname, "refs/heads/"))
                        continue;
-               if (!remotename || prefixcmp(remotename, "refs/heads/"))
+               if (!remotename || !starts_with(remotename, "refs/heads/"))
                        continue;
 
                if (!pretend)
@@ -191,7 +191,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 
 static const char *rsync_url(const char *url)
 {
-       return prefixcmp(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
+       return !starts_with(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
 }
 
 static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
@@ -296,8 +296,8 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
        FILE *f;
 
        /* when called via for_each_ref(), flags is non-zero */
-       if (flags && prefixcmp(name, "refs/heads/") &&
-                       prefixcmp(name, "refs/tags/"))
+       if (flags && !starts_with(name, "refs/heads/") &&
+                       !starts_with(name, "refs/tags/"))
                return 0;
 
        strbuf_addstr(buf, name);
@@ -652,7 +652,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
                print_ref_status('-', "[deleted]", ref, NULL, NULL, porcelain);
        else if (is_null_sha1(ref->old_sha1))
                print_ref_status('*',
-                       (!prefixcmp(ref->name, "refs/tags/") ? "[new tag]" :
+                       (starts_with(ref->name, "refs/tags/") ? "[new tag]" :
                        "[new branch]"),
                        ref, ref->peer_ref, NULL, porcelain);
        else {
@@ -885,14 +885,6 @@ void transport_take_over(struct transport *transport,
        transport->cannot_reuse = 1;
 }
 
-static int is_local(const char *url)
-{
-       const char *colon = strchr(url, ':');
-       const char *slash = strchr(url, '/');
-       return !colon || (slash && slash < colon) ||
-               has_dos_drive_prefix(url);
-}
-
 static int is_file(const char *url)
 {
        struct stat buf;
@@ -930,18 +922,18 @@ struct transport *transport_get(struct remote *remote, const char *url)
 
                while (is_urlschemechar(p == url, *p))
                        p++;
-               if (!prefixcmp(p, "::"))
+               if (starts_with(p, "::"))
                        helper = xstrndup(url, p - url);
        }
 
        if (helper) {
                transport_helper_init(ret, helper);
-       } else if (!prefixcmp(url, "rsync:")) {
+       } else if (starts_with(url, "rsync:")) {
                ret->get_refs_list = get_refs_via_rsync;
                ret->fetch = fetch_objs_via_rsync;
                ret->push = rsync_transport_push;
                ret->smart_options = NULL;
-       } else if (is_local(url) && is_file(url) && is_bundle(url, 1)) {
+       } else if (url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)) {
                struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
                ret->data = data;
                ret->get_refs_list = get_refs_from_bundle;
@@ -949,11 +941,11 @@ struct transport *transport_get(struct remote *remote, const char *url)
                ret->disconnect = close_bundle;
                ret->smart_options = NULL;
        } else if (!is_url(url)
-               || !prefixcmp(url, "file://")
-               || !prefixcmp(url, "git://")
-               || !prefixcmp(url, "ssh://")
-               || !prefixcmp(url, "git+ssh://")
-               || !prefixcmp(url, "ssh+git://")) {
+               || starts_with(url, "file://")
+               || starts_with(url, "git://")
+               || starts_with(url, "ssh://")
+               || starts_with(url, "git+ssh://")
+               || starts_with(url, "ssh+git://")) {
                /* These are builtin smart transports. */
                struct git_transport_data *data = xcalloc(1, sizeof(*data));
                ret->data = data;
@@ -1297,7 +1289,7 @@ char *transport_anonymize_url(const char *url)
        size_t anon_len, prefix_len = 0;
 
        anon_part = strchr(url, '@');
-       if (is_local(url) || !anon_part)
+       if (url_is_local_not_ssh(url) || !anon_part)
                goto literal_copy;
 
        anon_len = strlen(++anon_part);
index 35cb05e92bed9fb273747adc4718458b9f500898..ad3e9a04fe8ccb9286b94480f4484b0569f70a57 100644 (file)
@@ -1763,14 +1763,23 @@ int twoway_merge(const struct cache_entry * const *src,
                newtree = NULL;
 
        if (current) {
-               if ((!oldtree && !newtree) || /* 4 and 5 */
-                   (!oldtree && newtree &&
-                    same(current, newtree)) || /* 6 and 7 */
-                   (oldtree && newtree &&
-                    same(oldtree, newtree)) || /* 14 and 15 */
-                   (oldtree && newtree &&
-                    !same(oldtree, newtree) && /* 18 and 19 */
-                    same(current, newtree))) {
+               if (current->ce_flags & CE_CONFLICTED) {
+                       if (same(oldtree, newtree) || o->reset) {
+                               if (!newtree)
+                                       return deleted_entry(current, current, o);
+                               else
+                                       return merged_entry(newtree, current, o);
+                       }
+                       return o->gently ? -1 : reject_merge(current, o);
+               }
+               else if ((!oldtree && !newtree) || /* 4 and 5 */
+                        (!oldtree && newtree &&
+                         same(current, newtree)) || /* 6 and 7 */
+                        (oldtree && newtree &&
+                         same(oldtree, newtree)) || /* 14 and 15 */
+                        (oldtree && newtree &&
+                         !same(oldtree, newtree) && /* 18 and 19 */
+                         same(current, newtree))) {
                        return keep_entry(current, o);
                }
                else if (oldtree && !newtree && same(current, oldtree)) {
index d30f339e707fe3263b9c186e54b6b3317afc986c..ec56cdbce9fe0bf87aeafb3567e09cbf546e7218 100644 (file)
@@ -394,7 +394,7 @@ static int get_common_commits(void)
                        got_other = 0;
                        continue;
                }
-               if (!prefixcmp(line, "have ")) {
+               if (starts_with(line, "have ")) {
                        switch (got_sha1(line+5, sha1)) {
                        case -1: /* they have what we do not */
                                got_other = 1;
@@ -540,7 +540,7 @@ static void receive_needs(void)
                if (!line)
                        break;
 
-               if (!prefixcmp(line, "shallow ")) {
+               if (starts_with(line, "shallow ")) {
                        unsigned char sha1[20];
                        struct object *object;
                        if (get_sha1_hex(line + 8, sha1))
@@ -556,14 +556,14 @@ static void receive_needs(void)
                        }
                        continue;
                }
-               if (!prefixcmp(line, "deepen ")) {
+               if (starts_with(line, "deepen ")) {
                        char *end;
                        depth = strtol(line + 7, &end, 0);
                        if (end == line + 7 || depth <= 0)
                                die("Invalid deepen: %s", line);
                        continue;
                }
-               if (prefixcmp(line, "want ") ||
+               if (!starts_with(line, "want ") ||
                    get_sha1_hex(line+5, sha1_buf))
                        die("git upload-pack: protocol error, "
                            "expected to get sha, not '%s'", line);
@@ -814,7 +814,7 @@ int main(int argc, char **argv)
                        strict = 1;
                        continue;
                }
-               if (!prefixcmp(arg, "--timeout=")) {
+               if (starts_with(arg, "--timeout=")) {
                        timeout = atoi(arg+10);
                        daemon_mode = 1;
                        continue;
index f2b23c81de11a63c2c1c2ac925be9081ad5bea5c..bd0f2c2b86847708e5ebe668773f0fd08b9efc5d 100644 (file)
@@ -162,22 +162,13 @@ static void die_short_read(struct line_buffer *input)
        die("invalid dump: unexpected end of file");
 }
 
-static int ends_with(const char *s, size_t len, const char *suffix)
-{
-       const size_t suffixlen = strlen(suffix);
-       if (len < suffixlen)
-               return 0;
-       return !memcmp(s + len - suffixlen, suffix, suffixlen);
-}
-
 static int parse_cat_response_line(const char *header, off_t *len)
 {
-       size_t headerlen = strlen(header);
        uintmax_t n;
        const char *type;
        const char *end;
 
-       if (ends_with(header, headerlen, " missing"))
+       if (ends_with(header, " missing"))
                return error("cat-blob reports missing blob: %s", header);
        type = strstr(header, " blob ");
        if (!type)
index b4e44baa2917dfcf33824c3d6fc08756886b9ae1..4e5581005936a1e7832e3ab224cfe142ac777a63 100644 (file)
 #include "submodule.h"
 #include "column.h"
 #include "strbuf.h"
+#include "utf8.h"
+
+static char cut_line[] =
+"------------------------ >8 ------------------------\n";
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -264,6 +268,30 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
        strbuf_release(&onebuf);
 }
 
+static const char *wt_status_diff_status_string(int status)
+{
+       switch (status) {
+       case DIFF_STATUS_ADDED:
+               return _("new file");
+       case DIFF_STATUS_COPIED:
+               return _("copied");
+       case DIFF_STATUS_DELETED:
+               return _("deleted");
+       case DIFF_STATUS_MODIFIED:
+               return _("modified");
+       case DIFF_STATUS_RENAMED:
+               return _("renamed");
+       case DIFF_STATUS_TYPE_CHANGED:
+               return _("typechange");
+       case DIFF_STATUS_UNKNOWN:
+               return _("unknown");
+       case DIFF_STATUS_UNMERGED:
+               return _("unmerged");
+       default:
+               return NULL;
+       }
+}
+
 static void wt_status_print_change_data(struct wt_status *s,
                                        int change_type,
                                        struct string_list_item *it)
@@ -276,6 +304,23 @@ static void wt_status_print_change_data(struct wt_status *s,
        const char *one, *two;
        struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
        struct strbuf extra = STRBUF_INIT;
+       static char *padding;
+       const char *what;
+       int len;
+
+       if (!padding) {
+               int width = 0;
+               /* If DIFF_STATUS_* uses outside this range, we're in trouble */
+               for (status = 'A'; status <= 'Z'; status++) {
+                       what = wt_status_diff_status_string(status);
+                       len = what ? strlen(what) : 0;
+                       if (len > width)
+                               width = len;
+               }
+               width += 2;     /* colon and a space */
+               padding = xmallocz(width);
+               memset(padding, ' ', width);
+       }
 
        one_name = two_name = it->string;
        switch (change_type) {
@@ -307,34 +352,18 @@ static void wt_status_print_change_data(struct wt_status *s,
        two = quote_path(two_name, s->prefix, &twobuf);
 
        status_printf(s, color(WT_STATUS_HEADER, s), "\t");
-       switch (status) {
-       case DIFF_STATUS_ADDED:
-               status_printf_more(s, c, _("new file:   %s"), one);
-               break;
-       case DIFF_STATUS_COPIED:
-               status_printf_more(s, c, _("copied:     %s -> %s"), one, two);
-               break;
-       case DIFF_STATUS_DELETED:
-               status_printf_more(s, c, _("deleted:    %s"), one);
-               break;
-       case DIFF_STATUS_MODIFIED:
-               status_printf_more(s, c, _("modified:   %s"), one);
-               break;
-       case DIFF_STATUS_RENAMED:
-               status_printf_more(s, c, _("renamed:    %s -> %s"), one, two);
-               break;
-       case DIFF_STATUS_TYPE_CHANGED:
-               status_printf_more(s, c, _("typechange: %s"), one);
-               break;
-       case DIFF_STATUS_UNKNOWN:
-               status_printf_more(s, c, _("unknown:    %s"), one);
-               break;
-       case DIFF_STATUS_UNMERGED:
-               status_printf_more(s, c, _("unmerged:   %s"), one);
-               break;
-       default:
+       what = wt_status_diff_status_string(status);
+       if (!what)
                die(_("bug: unhandled diff status %c"), status);
-       }
+       /* 1 for colon, which is not part of "what" */
+       len = strlen(padding) - (utf8_strwidth(what) + 1);
+       assert(len >= 0);
+       if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
+               status_printf_more(s, c, "%s:%.*s%s -> %s",
+                                  what, len, padding, one, two);
+       else
+               status_printf_more(s, c, "%s:%.*s%s",
+                                  what, len, padding, one);
        if (extra.len) {
                status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
                strbuf_release(&extra);
@@ -767,6 +796,18 @@ static void wt_status_print_other(struct wt_status *s,
        status_printf_ln(s, GIT_COLOR_NORMAL, "");
 }
 
+void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
+{
+       const char *p;
+       struct strbuf pattern = STRBUF_INIT;
+
+       strbuf_addf(&pattern, "%c %s", comment_line_char, cut_line);
+       p = strstr(buf->buf, pattern.buf);
+       if (p && (p == buf->buf || p[-1] == '\n'))
+               strbuf_setlen(buf, p - buf->buf);
+       strbuf_release(&pattern);
+}
+
 static void wt_status_print_verbose(struct wt_status *s)
 {
        struct rev_info rev;
@@ -787,10 +828,20 @@ static void wt_status_print_verbose(struct wt_status *s)
         * If we're not going to stdout, then we definitely don't
         * want color, since we are going to the commit message
         * file (and even the "auto" setting won't work, since it
-        * will have checked isatty on stdout).
+        * will have checked isatty on stdout). But we then do want
+        * to insert the scissor line here to reliably remove the
+        * diff before committing.
         */
-       if (s->fp != stdout)
+       if (s->fp != stdout) {
+               const char *explanation = _("Do not touch the line above.\nEverything below will be removed.");
+               struct strbuf buf = STRBUF_INIT;
+
                rev.diffopt.use_color = 0;
+               fprintf(s->fp, "%c %s", comment_line_char, cut_line);
+               strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
+               fputs(buf.buf, s->fp);
+               strbuf_release(&buf);
+       }
        run_diff_index(&rev, 1);
 }
 
@@ -803,7 +854,7 @@ static void wt_status_print_tracking(struct wt_status *s)
        int i;
 
        assert(s->branch && !s->is_initial);
-       if (prefixcmp(s->branch, "refs/heads/"))
+       if (!starts_with(s->branch, "refs/heads/"))
                return;
        branch = branch_get(s->branch + 11);
        if (!format_tracking_info(branch, &sb))
@@ -1062,9 +1113,9 @@ static char *read_and_strip_branch(const char *path)
                strbuf_setlen(&sb, sb.len - 1);
        if (!sb.len)
                goto got_nothing;
-       if (!prefixcmp(sb.buf, "refs/heads/"))
+       if (starts_with(sb.buf, "refs/heads/"))
                strbuf_remove(&sb,0, strlen("refs/heads/"));
-       else if (!prefixcmp(sb.buf, "refs/"))
+       else if (starts_with(sb.buf, "refs/"))
                ;
        else if (!get_sha1_hex(sb.buf, sha1)) {
                const char *abbrev;
@@ -1094,7 +1145,7 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
        struct grab_1st_switch_cbdata *cb = cb_data;
        const char *target = NULL, *end;
 
-       if (prefixcmp(message, "checkout: moving from "))
+       if (!starts_with(message, "checkout: moving from "))
                return 0;
        message += strlen("checkout: moving from ");
        target = strstr(message, " to ");
@@ -1129,9 +1180,9 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
             ((commit = lookup_commit_reference_gently(sha1, 1)) != NULL &&
              !hashcmp(cb.nsha1, commit->object.sha1)))) {
                int ofs;
-               if (!prefixcmp(ref, "refs/tags/"))
+               if (starts_with(ref, "refs/tags/"))
                        ofs = strlen("refs/tags/");
-               else if (!prefixcmp(ref, "refs/remotes/"))
+               else if (starts_with(ref, "refs/remotes/"))
                        ofs = strlen("refs/remotes/");
                else
                        ofs = 0;
@@ -1220,7 +1271,7 @@ void wt_status_print(struct wt_status *s)
        if (s->branch) {
                const char *on_what = _("On branch ");
                const char *branch_name = s->branch;
-               if (!prefixcmp(branch_name, "refs/heads/"))
+               if (starts_with(branch_name, "refs/heads/"))
                        branch_name += 11;
                else if (!strcmp(branch_name, "HEAD")) {
                        branch_status_color = color(WT_STATUS_NOBRANCH, s);
@@ -1421,7 +1472,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
                return;
        branch_name = s->branch;
 
-       if (!prefixcmp(branch_name, "refs/heads/"))
+       if (starts_with(branch_name, "refs/heads/"))
                branch_name += 11;
        else if (!strcmp(branch_name, "HEAD")) {
                branch_name = _("HEAD (no branch)");
index 6c29e6f5e57f84eb7acdc3cf1ee621cc717fd5a9..30a481258366733ad5d6a65e3a9c3ae1ee74e833 100644 (file)
@@ -91,6 +91,7 @@ struct wt_status_state {
        unsigned char cherry_pick_head_sha1[20];
 };
 
+void wt_status_truncate_message_at_cut_line(struct strbuf *);
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);