Merge branch 'jk/pack-bitmap-progress'
authorJunio C Hamano <gitster@pobox.com>
Fri, 28 Mar 2014 20:50:56 +0000 (13:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 28 Mar 2014 20:50:56 +0000 (13:50 -0700)
The progress output while repacking and transferring objects showed
an apparent large silence while writing the objects out of existing
packfiles, when the reachability bitmap was in use.

* jk/pack-bitmap-progress:
pack-objects: show reused packfile objects in "Counting objects"
pack-objects: show progress for reused packfiles

98 files changed:
Documentation/RelNotes/1.9.1.txt [new file with mode: 0644]
Documentation/RelNotes/2.0.0.txt
Documentation/config.txt
Documentation/git-am.txt
Documentation/git-commit.txt
Documentation/git-pack-objects.txt
Documentation/git-repack.txt
Documentation/git-request-pull.txt
Documentation/git-tag.txt
Documentation/git.txt
Documentation/gitremote-helpers.txt
Documentation/gitrepository-layout.txt
Documentation/glossary-content.txt
Documentation/merge-strategies.txt
Makefile
archive.c
attr.c
branch.c
builtin/cat-file.c
builtin/clean.c
builtin/commit.c
builtin/index-pack.c
builtin/mktree.c
builtin/mv.c
builtin/pack-objects.c
builtin/receive-pack.c
builtin/repack.c
builtin/tag.c
bulk-checkin.c
bundle.c
cache-tree.c
cache.h
commit.c
commit.h
configure.ac
connect.c
contrib/remote-helpers/git-remote-bzr
contrib/remote-helpers/test-bzr.sh
contrib/remote-helpers/test-hg.sh
diff-no-index.c
diff.c
diffcore-rename.c
diffcore.h
dir.c
entry.c
fast-import.c
fetch-pack.c
git-compat-util.h
git-rebase--interactive.sh
git-remote-testgit.sh
git-request-pull.sh
git-stash.sh
grep.c
match-trees.c
pack-bitmap-write.c
pack-write.c
pack.h
parse-options.c
patch-ids.c
pretty.c
read-cache.c
reflog-walk.c
refs.c
remote-testsvn.c
remote.c
remote.h
replace_object.c
revision.c
sh-i18n--envsubst.c
sha1_file.c
shallow.c
t/lib-terminal.sh
t/t1020-subdirectory.sh
t/t3200-branch.sh
t/t5150-request-pull.sh
t/t5310-pack-bitmaps.sh
t/t5510-fetch.sh
t/t5529-push-errors.sh [new file with mode: 0755]
t/t5537-fetch-shallow.sh
t/t5801-remote-helpers.sh
t/t7001-mv.sh
t/t7004-tag.sh
t/t7060-wtstatus.sh
t/t7300-clean.sh
t/t7501-commit.sh
t/t7502-commit.sh
t/t7512-status-help.sh
t/t7700-repack.sh
t/t7810-grep.sh
t/t9001-send-email.sh
t/test-lib.sh
transport-helper.c
transport.c
upload-pack.c
versioncmp.c [new file with mode: 0644]
ws.c
wt-status.c
wt-status.h
diff --git a/Documentation/RelNotes/1.9.1.txt b/Documentation/RelNotes/1.9.1.txt
new file mode 100644 (file)
index 0000000..5b06020
--- /dev/null
@@ -0,0 +1,59 @@
+Git v1.9.1 Release Notes
+========================
+
+Fixes since v1.9.0
+------------------
+
+ * "git clean -d pathspec" did not use the given pathspec correctly
+   and ended up cleaning too much.
+
+ * "git difftool" misbehaved when the repository is bound to the
+   working tree with the ".git file" mechanism, where a textual file
+   ".git" tells us where it is.
+
+ * "git push" did not pay attention to branch.*.pushremote if it is
+   defined earlier than remote.pushdefault; the order of these two
+   variables in the configuration file should not matter, but it did
+   by mistake.
+
+ * Codepaths that parse timestamps in commit objects have been
+   tightened.
+
+ * "git diff --external-diff" incorrectly fed the submodule directory
+   in the working tree to the external diff driver when it knew it is
+   the same as one of the versions being compared.
+
+ * "git reset" needs to refresh the index when working in a working
+   tree (it can also be used to match the index to the HEAD in an
+   otherwise bare repository), but it failed to set up the working
+   tree properly, causing GIT_WORK_TREE to be ignored.
+
+ * "git check-attr" when working on a repository with a working tree
+   did not work well when the working tree was specified via the
+   --work-tree (and obviously with --git-dir) option.
+
+ * "merge-recursive" was broken in 1.7.7 era and stopped working in
+   an empty (temporary) working tree, when there are renames
+   involved.  This has been corrected.
+
+ * "git rev-parse" was loose in rejecting command line arguments
+   that do not make sense, e.g. "--default" without the required
+   value for that option.
+
+ * include.path variable (or any variable that expects a path that
+   can use ~username expansion) in the configuration file is not a
+   boolean, but the code failed to check it.
+
+ * "git diff --quiet -- pathspec1 pathspec2" sometimes did not return
+   correct status value.
+
+ * Attempting to deepen a shallow repository by fetching over smart
+   HTTP transport failed in the protocol exchange, when no-done
+   extension was used.  The fetching side waited for the list of
+   shallow boundary commits after the sending end stopped talking to
+   it.
+
+ * Allow "git cmd path/", when the 'path' is where a submodule is
+   bound to the top-level working tree, to match 'path', despite the
+   extra and unnecessary trailing slash (such a slash is often
+   given by command line completion).
index 0c71d9d54db729a43171be014d60a46dd365de81..50bbc28e2169849f89b9ea4427b58221a35aff3b 100644 (file)
@@ -39,14 +39,32 @@ The "-q" option to "git diff-files", which does *NOT* mean "quiet",
 has been removed (it told Git to ignore deletion, which you can do
 with "git diff-files --diff-filter=d").
 
+"git request-pull" lost a few "heuristics" that often led to mistakes.
+
 
 Updates since v1.9 series
 -------------------------
 
-Foreign interfaces, subsystems and ports.
+UI, Workflows & Features
+
+ * "git commit --cleanup=<mode>" learned a new mode, scissors.
 
+ * "git tag --list" output can be sorted using "version sort" with
+   "--sort=version:refname".
 
-UI, Workflows & Features
+ * Discard the accumulated "heuristics" to guess from which branch the
+   result wants to be pulled from and make sure what the end user
+   specified is not second-guessed by "git request-pull", to avoid
+   mistakes.  When you pushed out your 'master' branch to your public
+   repository as 'for-linus', use the new "master:for-linus" syntax to
+   denote the branch to be pulled.
+
+ * "git grep" learned to behave in a way similar to native grep when
+   "-h" (no header) and "-c" (count) options are given.
+
+ * transport-helper, fast-import and fast-export have been updated to
+   allow the ref mapping and ref deletion in a way similar to the
+   natively supported transports.
 
  * The "simple" mode is the default for "git push".
 
@@ -137,6 +155,52 @@ Unless otherwise noted, all the fixes since v1.9 in the maintenance
 track are contained in this release (see the maintenance releases'
 notes for details).
 
+ * "git mv" that moves a submodule forgot to adjust the array that
+   uses to keep track of which submodules were to be moved to update
+   its configuration.
+   (merge fb8a4e8 jk/mv-submodules-fix later to maint).
+
+ * Length limit for the pathname used when removing a path in a deep
+   subdirectory has been removed to avoid buffer overflows.
+   (merge 2f29e0c mh/remove-subtree-long-pathname-fix later to maint).
+
+ * The test helper lib-terminal always run an actual test_expect_*
+   when included, which screwed up with the use of skil-all that may
+   have to be done later.
+   (merge 7e27173 jk/lib-terminal-lazy later to maint).
+
+ * "git index-pack" used a wrong variable to name the keep-file in an
+   error message when the file cannot be written or closed.
+   (merge de983a0 nd/index-pack-error-message later to maint).
+
+ * "rebase -i" produced a broken insn sheet when the title of a commit
+   happened to contain '\n' (or ended with '\c') due to a careless use
+   of 'echo'.
+   (merge cb1aefd us/printf-not-echo later to maint).
+
+ * There were a few instances of 'git-foo' remaining in the
+   documentation that should have been spelled 'git foo'.
+   (merge 3c3e6f5 rr/doc-merge-strategies later to maint).
+
+ * Serving objects from a shallow repository needs to write a
+   new file to hold the temporary shallow boundaries but it was not
+   cleaned when we exit due to die() or a signal.
+   (merge 7839632 jk/shallow-update-fix later to maint).
+
+ * When "git stash pop" stops after failing to apply the stash
+   (e.g. due to conflicting changes), the stash is not dropped. State
+   that explicitly in the output to let the users know.
+   (merge 2d4c993 jc/stash-pop-not-popped later to maint).
+
+ * The labels in "git status" output that describe the nature of
+   conflicts (e.g. "both deleted") were limited to 20 bytes, which was
+   too short for some l10n (e.g. fr).
+   (merge c7cb333 jn/wt-status later to maint).
+
+ * "git clean -d pathspec" did not use the given pathspec correctly
+   and ended up cleaning too much.
+   (merge 1f2e108 jk/clean-d-pathspec later to maint).
+
  * "git difftool" misbehaved when the repository is bound to the
    working tree with the ".git file" mechanism, where a textual file
    ".git" tells us where it is.
index 79e576878af5eb44b21fc0763faeb30519e022c3..73c8973aae5bfad789a998e5623fc219959edaf6 100644 (file)
@@ -2156,6 +2156,13 @@ repack.usedeltabaseoffset::
        "false" and repack. Access from old Git versions over the
        native protocol are unaffected by this option.
 
+repack.packKeptObjects::
+       If set to true, makes `git repack` act as if
+       `--pack-kept-objects` was passed. See linkgit:git-repack[1] for
+       details. Defaults to `false` normally, but `true` if a bitmap
+       index is being written (either via `--write-bitmap-index` or
+       `pack.writeBitmaps`).
+
 rerere.autoupdate::
        When set to true, `git-rerere` updates the index with the
        resulting contents after it cleanly resolves conflicts using
index a2b97582fe010ffcab70db30e006a7a94d6b767b..9adce372ec6e6ec0d371c411da1e5002baea5f51 100644 (file)
@@ -14,7 +14,7 @@ SYNOPSIS
         [--ignore-date] [--ignore-space-change | --ignore-whitespace]
         [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
         [--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
-        [--[no-]scissors] [-S[<keyid>]]
+        [--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>]
         [(<mbox> | <Maildir>)...]
 'git am' (--continue | --skip | --abort)
 
@@ -97,6 +97,12 @@ default.   You can use `--no-utf8` to override this.
        program that applies
        the patch.
 
+--patch-format::
+       By default the command will try to detect the patch format
+       automatically. This option allows the user to bypass the automatic
+       detection and specify the patch format that the patch(es) should be
+       interpreted as. Valid formats are mbox, stgit, stgit-series and hg.
+
 -i::
 --interactive::
        Run interactively.
index 7c42e9cabcb250b93cd286e8efe23df90ea0f71c..429267abf640ef42b5bf9361ed8ab78f6509f77f 100644 (file)
@@ -176,7 +176,7 @@ OPTIONS
 --cleanup=<mode>::
        This option determines how the supplied commit message should be
        cleaned up before committing.  The '<mode>' can be `strip`,
-       `whitespace`, `verbatim`, or `default`.
+       `whitespace`, `verbatim`, `scissors` or `default`.
 +
 --
 strip::
@@ -186,6 +186,12 @@ whitespace::
        Same as `strip` except #commentary is not removed.
 verbatim::
        Do not change the message at all.
+scissors::
+       Same as `whitespace`, except that everything from (and
+       including) the line
+       "`# ------------------------ >8 ------------------------`"
+       is truncated if the message is to be edited. "`#`" can be
+       customized with core.commentChar.
 default::
        Same as `strip` if the message is to be edited.
        Otherwise `whitespace`.
index cdab9ed503a5adaace14b06863f31347725d06db..d2d8f4792afaf5dc1105457493b070bcf163ecef 100644 (file)
@@ -64,6 +64,8 @@ base-name::
        the same way as 'git rev-list' with the `--objects` flag
        uses its `commit` arguments to build the list of objects it
        outputs.  The objects on the resulting list are packed.
+       Besides revisions, `--not` or `--shallow <SHA-1>` lines are
+       also accepted.
 
 --unpacked::
        This implies `--revs`.  When processing the list of
index 002cfd5eb959ce7c8afea32388477f3a1062c485..4786a780b5443e6c021e1ce49c3d0f1d96865aba 100644 (file)
@@ -117,6 +117,14 @@ other objects in that pack they already have locally.
        must be able to refer to all reachable objects. This option
        overrides the setting of `pack.writebitmaps`.
 
+--pack-kept-objects::
+       Include objects in `.keep` files when repacking.  Note that we
+       still do not delete `.keep` packs after `pack-objects` finishes.
+       This means that we may duplicate objects, but this makes the
+       option safe to use when there are concurrent pushes or fetches.
+       This option is generally only useful if you are writing bitmaps
+       with `-b` or `pack.writebitmaps`, as it ensures that the
+       bitmapped packfile has the necessary objects.
 
 Configuration
 -------------
index b99681ce85abc0879f11e99654e1bdb6ba5dd688..283577b0b6ca1ef7a35758686edf548025e6db76 100644 (file)
@@ -13,22 +13,65 @@ SYNOPSIS
 DESCRIPTION
 -----------
 
-Summarizes the changes between two commits to the standard output, and includes
-the given URL in the generated summary.
+Generate a request asking your upstream project to pull changes into
+their tree.  The request, printed to the standard output, summarizes
+the changes and indicates from where they can be pulled.
+
+The upstream project is expected to have the commit named by
+`<start>` and the output asks it to integrate the changes you made
+since that commit, up to the commit named by `<end>`, by visiting
+the repository named by `<url>`.
+
 
 OPTIONS
 -------
 -p::
-       Show patch text
+       Include patch text in the output.
 
 <start>::
-       Commit to start at.
+       Commit to start at.  This names a commit that is already in
+       the upstream history.
 
 <url>::
-       URL to include in the summary.
+       The repository URL to be pulled from.
 
 <end>::
-       Commit to end at; defaults to HEAD.
+       Commit to end at (defaults to HEAD).  This names the commit
+       at the tip of the history you are asking to be pulled.
++
+When the repository named by `<url>` has the commit at a tip of a
+ref that is different from the ref you have locally, you can use the
+`<local>:<remote>` syntax, to have its local name, a colon `:`, and
+its remote name.
+
+
+EXAMPLE
+-------
+
+Imagine that you built your work on your `master` branch on top of
+the `v1.0` release, and want it to be integrated to the project.
+First you push that change to your public repository for others to
+see:
+
+       git push https://git.ko.xz/project master
+
+Then, you run this command:
+
+       git request-pull v1.0 https://git.ko.xz/project master
+
+which will produce a request to the upstream, summarizing the
+changes between the `v1.0` release and your `master`, to pull it
+from your public repository.
+
+If you pushed your change to a branch whose name is different from
+the one you have locally, e.g.
+
+       git push https://git.ko.xz/project master:for-linus
+
+then you can ask that to be pulled with
+
+       git request-pull v1.0 https://git.ko.xz/project master:for-linus
+
 
 GIT
 ---
index 404257df9fcad2ac5428b0608341e0c6d1337384..b424a1bc48bba96513da17ee63bee4383453c3b4 100644 (file)
@@ -95,6 +95,12 @@ OPTIONS
        using fnmatch(3)).  Multiple patterns may be given; if any of
        them matches, the tag is shown.
 
+--sort=<type>::
+       Sort in a specific order. Supported type is "refname"
+       (lexicographic order), "version:refname" or "v:refname" (tag
+       names are treated as versions). Prepend "-" to reverse sort
+       order.
+
 --column[=<options>]::
 --no-column::
        Display tag listing in columns. See configuration variable
index 27a199ca1af53c25f7b3e41501402244b11614d4..e5f8ed0940d296613a05d3b23981215e39a5ba1a 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.9.0/git.html[documentation for release 1.9.0]
+* link:v1.9.1/git.html[documentation for release 1.9.1]
 
 * release notes for
+  link:RelNotes/1.9.1.txt[1.9.1],
   link:RelNotes/1.9.0.txt[1.9.0].
 
 * link:v1.8.5.5/git.html[documentation for release 1.8.5.5]
index c2908db76317c91cf5502065e9c4bf1d97da19bd..64f7ad26b40085ced91e73fd806c11e90ad2eb9a 100644 (file)
@@ -437,6 +437,10 @@ set by Git if the remote helper has the 'option' capability.
 'option check-connectivity' \{'true'|'false'\}::
        Request the helper to check connectivity of a clone.
 
+'option force' \{'true'|'false'\}::
+       Request the helper to perform a force update.  Defaults to
+       'false'.
+
 'option cloning \{'true'|'false'\}::
        Notify the helper this is a clone request (i.e. the current
        repository is guaranteed empty).
index aa03882ddb119d2e61da50079a72e1a6ab12f636..17d2ea6c1e48733d85a8caa49f6143c76edb09aa 100644 (file)
@@ -176,6 +176,10 @@ info/grafts::
        per line describes a commit and its fake parents by
        listing their 40-byte hexadecimal object names separated
        by a space and terminated by a newline.
++
+Note that the grafts mechanism is outdated and can lead to problems
+transferring objects between repositories; see linkgit:git-replace[1]
+for a more flexible and robust system to do the same thing.
 
 info/exclude::
        This file, by convention among Porcelains, stores the
index 378306f58162fdfee900b48b8bb6ad8171cbfca3..be0858c188184eb510688ffc0598664541c1d10c 100644 (file)
@@ -176,6 +176,10 @@ current branch integrates with) obviously do not work, as there is no
        you can make Git pretend the set of <<def_parent,parents>> a <<def_commit,commit>> has
        is different from what was recorded when the commit was
        created. Configured via the `.git/info/grafts` file.
++
+Note that the grafts mechanism is outdated and can lead to problems
+transferring objects between repositories; see linkgit:git-replace[1]
+for a more flexible and robust system to do the same thing.
 
 [[def_hash]]hash::
        In Git's context, synonym for <<def_object_name,object name>>.
index 350949810e224c9963278cbc73351011448e9b56..7bbd19b30032ca76966cbcf44a0b5b738c8f5ced 100644 (file)
@@ -1,10 +1,10 @@
 MERGE STRATEGIES
 ----------------
 
-The merge mechanism ('git-merge' and 'git-pull' commands) allows the
+The merge mechanism (`git merge` and `git pull` commands) allows the
 backend 'merge strategies' to be chosen with `-s` option.  Some strategies
 can also take their own options, which can be passed by giving `-X<option>`
-arguments to 'git-merge' and/or 'git-pull'.
+arguments to `git merge` and/or `git pull`.
 
 resolve::
        This can only resolve two heads (i.e. the current branch
index f818eecaf380c109be248f424d5c8f3a537359e0..36463919afd6ee40c3a0487e481ebbaadce7b6d8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -892,6 +892,7 @@ LIB_OBJS += userdiff.o
 LIB_OBJS += utf8.o
 LIB_OBJS += varint.o
 LIB_OBJS += version.o
+LIB_OBJS += versioncmp.o
 LIB_OBJS += walker.o
 LIB_OBJS += wildmatch.o
 LIB_OBJS += wrapper.o
index 7d0976fe55b8ef7b9009d080f7c1c0651a05def7..3fc0fb2928f1007ec5d8763d9d3a9b88152059ad 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -260,8 +260,8 @@ static void parse_treeish_arg(const char **argv,
        /* Remotes are only allowed to fetch actual refs */
        if (remote && !remote_allow_unreachable) {
                char *ref = NULL;
-               const char *colon = strchr(name, ':');
-               int refnamelen = colon ? colon - name : strlen(name);
+               const char *colon = strchrnul(name, ':');
+               int refnamelen = colon - name;
 
                if (!dwim_ref(name, refnamelen, sha1, &ref))
                        die("no such ref: %.*s", refnamelen, name);
diff --git a/attr.c b/attr.c
index 8d13d70e80d6d52794d53ed071b8800f9c905a05..734222dc45c588736f963dea7907258e76024415 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -338,12 +338,7 @@ static void handle_attr_line(struct attr_stack *res,
        a = parse_attr_line(line, src, lineno, macro_ok);
        if (!a)
                return;
-       if (res->alloc <= res->num_matches) {
-               res->alloc = alloc_nr(res->num_matches);
-               res->attrs = xrealloc(res->attrs,
-                                     sizeof(struct match_attr *) *
-                                     res->alloc);
-       }
+       ALLOC_GROW(res->attrs, res->num_matches + 1, res->alloc);
        res->attrs[res->num_matches++] = a;
 }
 
index 723a36bc540e41fe30b7b4fc2c8e893c4744ef3a..8eecb1d8c08b9793399b7eb834b2529c590b9a20 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
 #include "cache.h"
 #include "branch.h"
 #include "refs.h"
@@ -49,12 +50,11 @@ 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 = starts_with(remote, "refs/heads/");
+       const char *shortname = skip_prefix(remote, "refs/heads/");
        struct strbuf key = STRBUF_INIT;
        int rebasing = should_setup_rebase(origin);
 
-       if (remote_is_branch
+       if (shortname
            && !strcmp(local, shortname)
            && !origin) {
                warning(_("Not setting branch %s as its own upstream."),
@@ -77,29 +77,29 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
        strbuf_release(&key);
 
        if (flag & BRANCH_CONFIG_VERBOSE) {
-               if (remote_is_branch && origin)
+               if (shortname && origin)
                        printf_ln(rebasing ?
                                  _("Branch %s set up to track remote branch %s from %s by rebasing.") :
                                  _("Branch %s set up to track remote branch %s from %s."),
                                  local, shortname, origin);
-               else if (remote_is_branch && !origin)
+               else if (shortname && !origin)
                        printf_ln(rebasing ?
                                  _("Branch %s set up to track local branch %s by rebasing.") :
                                  _("Branch %s set up to track local branch %s."),
                                  local, shortname);
-               else if (!remote_is_branch && origin)
+               else if (!shortname && origin)
                        printf_ln(rebasing ?
                                  _("Branch %s set up to track remote ref %s by rebasing.") :
                                  _("Branch %s set up to track remote ref %s."),
                                  local, remote);
-               else if (!remote_is_branch && !origin)
+               else if (!shortname && !origin)
                        printf_ln(rebasing ?
                                  _("Branch %s set up to track local ref %s by rebasing.") :
                                  _("Branch %s set up to track local ref %s."),
                                  local, remote);
                else
-                       die("BUG: impossible combination of %d and %p",
-                           remote_is_branch, origin);
+                       die("BUG: impossible combination of %p and %p",
+                           shortname, origin);
        }
 }
 
@@ -114,10 +114,6 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
        struct tracking tracking;
        int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE;
 
-       if (strlen(new_ref) > 1024 - 7 - 7 - 1)
-               return error(_("Tracking not set up: name too long: %s"),
-                               new_ref);
-
        memset(&tracking, 0, sizeof(tracking));
        tracking.spec.dst = (char *)orig_ref;
        if (for_each_remote(find_tracked_branch, &tracking))
index d5a93e0e911ccbe4560a03ed78436bfb174e0f68..707330499fad66a0bddbb5cf96ff0569e2fe3433 100644 (file)
@@ -269,6 +269,8 @@ static int batch_objects(struct batch_options *opt)
 {
        struct strbuf buf = STRBUF_INIT;
        struct expand_data data;
+       int save_warning;
+       int retval = 0;
 
        if (!opt->format)
                opt->format = "%(objectname) %(objecttype) %(objectsize)";
@@ -297,11 +299,10 @@ static int batch_objects(struct batch_options *opt)
         * warn) ends up dwarfing the actual cost of the object lookups
         * themselves. We can work around it by just turning off the warning.
         */
+       save_warning = warn_on_object_refname_ambiguity;
        warn_on_object_refname_ambiguity = 0;
 
        while (strbuf_getline(&buf, stdin, '\n') != EOF) {
-               int error;
-
                if (data.split_on_whitespace) {
                        /*
                         * Split at first whitespace, tying off the beginning
@@ -316,12 +317,14 @@ static int batch_objects(struct batch_options *opt)
                        data.rest = p;
                }
 
-               error = batch_one_object(buf.buf, opt, &data);
-               if (error)
-                       return error;
+               retval = batch_one_object(buf.buf, opt, &data);
+               if (retval)
+                       break;
        }
 
-       return 0;
+       strbuf_release(&buf);
+       warn_on_object_refname_ambiguity = save_warning;
+       return retval;
 }
 
 static const char * const cat_file_usage[] = {
index 114d7bf879690fb1c1c33f768b86776b6ff60ef8..cf76b1f412e5423df42528c928c557764f31ad02 100644 (file)
@@ -947,17 +947,15 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                if (pathspec.nr)
                        matches = dir_path_match(ent, &pathspec, 0, NULL);
 
-               if (S_ISDIR(st.st_mode)) {
-                       if (remove_directories || (matches == MATCHED_EXACTLY)) {
-                               rel = relative_path(ent->name, prefix, &buf);
-                               string_list_append(&del_list, rel);
-                       }
-               } else {
-                       if (pathspec.nr && !matches)
-                               continue;
-                       rel = relative_path(ent->name, prefix, &buf);
-                       string_list_append(&del_list, rel);
-               }
+               if (pathspec.nr && !matches)
+                       continue;
+
+               if (S_ISDIR(st.st_mode) && !remove_directories &&
+                   matches != MATCHED_EXACTLY)
+                       continue;
+
+               rel = relative_path(ent->name, prefix, &buf);
+               string_list_append(&del_list, rel);
        }
 
        if (interactive && del_list.nr > 0)
index 3783bcadcd5232ceccab7f4fd2559a9999c53ffa..38f34e7cd3c7ffd482eb13fcf810346e1da4d944 100644 (file)
@@ -113,6 +113,7 @@ static char *sign_commit;
 static enum {
        CLEANUP_SPACE,
        CLEANUP_NONE,
+       CLEANUP_SCISSORS,
        CLEANUP_ALL
 } cleanup_mode;
 static const char *cleanup_arg;
@@ -755,7 +756,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                int ident_shown = 0;
                int saved_color_setting;
                char *ai_tmp, *ci_tmp;
-               if (whence != FROM_COMMIT)
+               if (whence != FROM_COMMIT) {
+                       if (cleanup_mode == CLEANUP_SCISSORS)
+                               wt_status_add_cut_line(s->fp);
                        status_printf_ln(s, GIT_COLOR_NORMAL,
                            whence == FROM_MERGE
                                ? _("\n"
@@ -771,6 +774,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                                git_path(whence == FROM_MERGE
                                         ? "MERGE_HEAD"
                                         : "CHERRY_PICK_HEAD"));
+               }
 
                fprintf(s->fp, "\n");
                if (cleanup_mode == CLEANUP_ALL)
@@ -778,6 +782,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                                _("Please enter the commit message for your changes."
                                  " Lines starting\nwith '%c' will be ignored, and an empty"
                                  " message aborts the commit.\n"), comment_line_char);
+               else if (cleanup_mode == CLEANUP_SCISSORS && whence == FROM_COMMIT)
+                       wt_status_add_cut_line(s->fp);
                else /* CLEANUP_SPACE, that is. */
                        status_printf(s, GIT_COLOR_NORMAL,
                                _("Please enter the commit message for your changes."
@@ -1133,6 +1139,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
                cleanup_mode = CLEANUP_SPACE;
        else if (!strcmp(cleanup_arg, "strip"))
                cleanup_mode = CLEANUP_ALL;
+       else if (!strcmp(cleanup_arg, "scissors"))
+               cleanup_mode = use_editor ? CLEANUP_SCISSORS : CLEANUP_SPACE;
        else
                die(_("Invalid cleanup mode %s"), cleanup_arg);
 
@@ -1605,8 +1613,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                die(_("could not read commit message: %s"), strerror(saved_errno));
        }
 
-       /* Truncate the message just before the diff, if any. */
-       if (verbose)
+       if (verbose || /* Truncate the message just before the diff, if any. */
+           cleanup_mode == CLEANUP_SCISSORS)
                wt_status_truncate_message_at_cut_line(&sb);
 
        if (cleanup_mode != CLEANUP_NONE)
index a6b1c17996da28cef97560378e7586bbf1bd8b6b..b9f6e12c0e91635eafd8510dc7cf20d6c3e58433 100644 (file)
@@ -1291,7 +1291,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
                if (keep_fd < 0) {
                        if (errno != EEXIST)
                                die_errno(_("cannot write keep file '%s'"),
-                                         keep_name);
+                                         keep_name ? keep_name : name);
                } else {
                        if (keep_msg_len > 0) {
                                write_or_die(keep_fd, keep_msg, keep_msg_len);
@@ -1299,7 +1299,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
                        }
                        if (close(keep_fd) != 0)
                                die_errno(_("cannot close written keep file '%s'"),
-                                   keep_name);
+                                         keep_name ? keep_name : name);
                        report = "keep";
                }
        }
index f92ba404abd5cea0cde344936f697e46c1a46045..a964d6be521c09a241ab0ccdc9f313e182769412 100644 (file)
@@ -23,10 +23,7 @@ static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
        if (strchr(path, '/'))
                die("path %s contains slash", path);
 
-       if (alloc <= used) {
-               alloc = alloc_nr(used);
-               entries = xrealloc(entries, sizeof(*entries) * alloc);
-       }
+       ALLOC_GROW(entries, used + 1, alloc);
        ent = entries[used++] = xmalloc(sizeof(**entries) + len + 1);
        ent->mode = mode;
        ent->len = len;
index 7e26eb5229a0c8a526314cecb9860c3dfb0fed00..2a7243f52e413c821f9f75969edcc0a9822c8e21 100644 (file)
@@ -180,6 +180,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                                                modes = xrealloc(modes,
                                                                (argc + last - first)
                                                                * sizeof(enum update_mode));
+                                               submodule_gitfile = xrealloc(submodule_gitfile,
+                                                               (argc + last - first)
+                                                               * sizeof(char *));
                                        }
 
                                        dst = add_slash(dst);
@@ -193,6 +196,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                                                        prefix_path(dst, dst_len,
                                                                path + length + 1);
                                                modes[argc + j] = INDEX;
+                                               submodule_gitfile[argc + j] = NULL;
                                        }
                                        argc += last - first;
                                }
@@ -228,6 +232,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                                        memmove(destination + i,
                                                destination + i + 1,
                                                (argc - i) * sizeof(char *));
+                                       memmove(modes + i, modes + i + 1,
+                                               (argc - i) * sizeof(enum update_mode));
+                                       memmove(submodule_gitfile + i,
+                                               submodule_gitfile + i + 1,
+                                               (argc - i) * sizeof(char *));
                                        i--;
                                }
                        } else
index 021ec7ad794f6f2537bd6f02a029f771a3d3b7fd..7950c4342f81544f719b20add2e1233be36fc718 100644 (file)
@@ -816,7 +816,7 @@ static void write_pack_file(void)
 
                if (!pack_to_stdout) {
                        struct stat st;
-                       char tmpname[PATH_MAX];
+                       struct strbuf tmpname = STRBUF_INIT;
 
                        /*
                         * Packs are runtime accessed in their mtime
@@ -839,23 +839,19 @@ static void write_pack_file(void)
                                                pack_tmp_name, strerror(errno));
                        }
 
-                       /* Enough space for "-<sha-1>.pack"? */
-                       if (sizeof(tmpname) <= strlen(base_name) + 50)
-                               die("pack base name '%s' too long", base_name);
-                       snprintf(tmpname, sizeof(tmpname), "%s-", base_name);
+                       strbuf_addf(&tmpname, "%s-", base_name);
 
                        if (write_bitmap_index) {
                                bitmap_writer_set_checksum(sha1);
                                bitmap_writer_build_type_index(written_list, nr_written);
                        }
 
-                       finish_tmp_packfile(tmpname, pack_tmp_name,
+                       finish_tmp_packfile(&tmpname, pack_tmp_name,
                                            written_list, nr_written,
                                            &pack_idx_opts, sha1);
 
                        if (write_bitmap_index) {
-                               char *end_of_name_prefix = strrchr(tmpname, 0);
-                               sprintf(end_of_name_prefix, "%s.bitmap", sha1_to_hex(sha1));
+                               strbuf_addf(&tmpname, "%s.bitmap", sha1_to_hex(sha1));
 
                                stop_progress(&progress_state);
 
@@ -864,10 +860,11 @@ static void write_pack_file(void)
                                bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1);
                                bitmap_writer_build(&to_pack);
                                bitmap_writer_finish(written_list, nr_written,
-                                                    tmpname, write_bitmap_options);
+                                                    tmpname.buf, write_bitmap_options);
                                write_bitmap_index = 0;
                        }
 
+                       strbuf_release(&tmpname);
                        free(pack_tmp_name);
                        puts(sha1_to_hex(sha1));
                }
@@ -1011,6 +1008,10 @@ static void create_object_entry(const unsigned char *sha1,
        entry->no_try_delta = no_try_delta;
 }
 
+static const char no_closure_warning[] = N_(
+"disabling bitmap writing, as some objects are not being packed"
+);
+
 static int add_object_entry(const unsigned char *sha1, enum object_type type,
                            const char *name, int exclude)
 {
@@ -1021,8 +1022,14 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
        if (have_duplicate_entry(sha1, exclude, &index_pos))
                return 0;
 
-       if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset))
+       if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset)) {
+               /* The pack is missing an object, so it will not have closure */
+               if (write_bitmap_index) {
+                       warning(_(no_closure_warning));
+                       write_bitmap_index = 0;
+               }
                return 0;
+       }
 
        create_object_entry(sha1, type, pack_name_hash(name),
                            exclude, name && no_try_delta(name),
@@ -1226,12 +1233,9 @@ static int check_pbase_path(unsigned hash)
        if (0 <= pos)
                return 1;
        pos = -pos - 1;
-       if (done_pbase_paths_alloc <= done_pbase_paths_num) {
-               done_pbase_paths_alloc = alloc_nr(done_pbase_paths_alloc);
-               done_pbase_paths = xrealloc(done_pbase_paths,
-                                           done_pbase_paths_alloc *
-                                           sizeof(unsigned));
-       }
+       ALLOC_GROW(done_pbase_paths,
+                  done_pbase_paths_num + 1,
+                  done_pbase_paths_alloc);
        done_pbase_paths_num++;
        if (pos < done_pbase_paths_num)
                memmove(done_pbase_paths + pos + 1,
@@ -2463,6 +2467,9 @@ static void get_object_list(int ac, const char **av)
        save_commit_buffer = 0;
        setup_revisions(ac, av, &revs, NULL);
 
+       /* make sure shallows are read */
+       is_repository_shallow();
+
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
                if (len && line[len - 1] == '\n')
@@ -2475,6 +2482,13 @@ static void get_object_list(int ac, const char **av)
                                write_bitmap_index = 0;
                                continue;
                        }
+                       if (starts_with(line, "--shallow ")) {
+                               unsigned char sha1[20];
+                               if (get_sha1_hex(line + 10, sha1))
+                                       die("not an SHA-1 '%s'", line + 10);
+                               register_shallow(sha1);
+                               continue;
+                       }
                        die("not a rev '%s'", line);
                }
                if (handle_revision_arg(line, &revs, flags, REVARG_CANNOT_BE_FILENAME))
index 85bba356fab7743506f00bb0c5ca955eb9112bd5..c3230817db4a7676eb74335b254f30597e66edd9 100644 (file)
@@ -828,14 +828,10 @@ static void execute_commands(struct command *commands,
                }
        }
 
-       if (shallow_update) {
-               if (!checked_connectivity)
-                       error("BUG: run 'git fsck' for safety.\n"
-                             "If there are errors, try to remove "
-                             "the reported refs above");
-               if (alt_shallow_file && *alt_shallow_file)
-                       unlink(alt_shallow_file);
-       }
+       if (shallow_update && !checked_connectivity)
+               error("BUG: run 'git fsck' for safety.\n"
+                     "If there are errors, try to remove "
+                     "the reported refs above");
 }
 
 static struct command *read_head_info(struct sha1_array *shallow)
@@ -1087,10 +1083,6 @@ static void update_shallow_info(struct command *commands,
                        cmd->skip_update = 1;
                }
        }
-       if (alt_shallow_file && *alt_shallow_file) {
-               unlink(alt_shallow_file);
-               alt_shallow_file = NULL;
-       }
        free(ref_status);
 }
 
index 49f5857627fd616b1019063f3f2d1937b20004fd..6b0b62dcb2687e78ec433e7de1103f0c0f74a1fc 100644 (file)
@@ -9,6 +9,7 @@
 #include "argv-array.h"
 
 static int delta_base_offset = 1;
+static int pack_kept_objects = -1;
 static char *packdir, *packtmp;
 
 static const char *const git_repack_usage[] = {
@@ -22,6 +23,10 @@ static int repack_config(const char *var, const char *value, void *cb)
                delta_base_offset = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "repack.packkeptobjects")) {
+               pack_kept_objects = git_config_bool(var, value);
+               return 0;
+       }
        return git_default_config(var, value, cb);
 }
 
@@ -175,6 +180,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                                N_("limits the maximum delta depth")),
                OPT_STRING(0, "max-pack-size", &max_pack_size, N_("bytes"),
                                N_("maximum size of each packfile")),
+               OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects,
+                               N_("repack objects in packs marked with .keep")),
                OPT_END()
        };
 
@@ -183,6 +190,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, builtin_repack_options,
                                git_repack_usage, 0);
 
+       if (pack_kept_objects < 0)
+               pack_kept_objects = write_bitmap;
+
        packdir = mkpathdup("%s/pack", get_object_directory());
        packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid());
 
@@ -190,7 +200,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 
        argv_array_push(&cmd_args, "pack-objects");
        argv_array_push(&cmd_args, "--keep-true-parents");
-       argv_array_push(&cmd_args, "--honor-pack-keep");
+       if (!pack_kept_objects)
+               argv_array_push(&cmd_args, "--honor-pack-keep");
        argv_array_push(&cmd_args, "--non-empty");
        argv_array_push(&cmd_args, "--all");
        argv_array_push(&cmd_args, "--reflog");
index 169c676636ff6b320f32f13126a5ff46b222f879..40356e3e41b44f87b565ebbed8ad0f7a5000b31d 100644 (file)
@@ -27,9 +27,16 @@ static const char * const git_tag_usage[] = {
        NULL
 };
 
+#define STRCMP_SORT     0      /* must be zero */
+#define VERCMP_SORT     1
+#define SORT_MASK       0x7fff
+#define REVERSE_SORT    0x8000
+
 struct tag_filter {
        const char **patterns;
        int lines;
+       int sort;
+       struct string_list tags;
        struct commit_list *with_commit;
 };
 
@@ -166,7 +173,10 @@ static int show_reference(const char *refname, const unsigned char *sha1,
                        return 0;
 
                if (!filter->lines) {
-                       printf("%s\n", refname);
+                       if (filter->sort)
+                               string_list_append(&filter->tags, refname);
+                       else
+                               printf("%s\n", refname);
                        return 0;
                }
                printf("%-15s ", refname);
@@ -177,17 +187,39 @@ static int show_reference(const char *refname, const unsigned char *sha1,
        return 0;
 }
 
+static int sort_by_version(const void *a_, const void *b_)
+{
+       const struct string_list_item *a = a_;
+       const struct string_list_item *b = b_;
+       return versioncmp(a->string, b->string);
+}
+
 static int list_tags(const char **patterns, int lines,
-                       struct commit_list *with_commit)
+                    struct commit_list *with_commit, int sort)
 {
        struct tag_filter filter;
 
        filter.patterns = patterns;
        filter.lines = lines;
+       filter.sort = sort;
        filter.with_commit = with_commit;
+       memset(&filter.tags, 0, sizeof(filter.tags));
+       filter.tags.strdup_strings = 1;
 
        for_each_tag_ref(show_reference, (void *) &filter);
-
+       if (sort) {
+               int i;
+               if ((sort & SORT_MASK) == VERCMP_SORT)
+                       qsort(filter.tags.items, filter.tags.nr,
+                             sizeof(struct string_list_item), sort_by_version);
+               if (sort & REVERSE_SORT)
+                       for (i = filter.tags.nr - 1; i >= 0; i--)
+                               printf("%s\n", filter.tags.items[i].string);
+               else
+                       for (i = 0; i < filter.tags.nr; i++)
+                               printf("%s\n", filter.tags.items[i].string);
+               string_list_clear(&filter.tags, 0);
+       }
        return 0;
 }
 
@@ -427,6 +459,29 @@ static int parse_opt_points_at(const struct option *opt __attribute__((unused)),
        return 0;
 }
 
+static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
+{
+       int *sort = opt->value;
+       int flags = 0;
+
+       if (*arg == '-') {
+               flags |= REVERSE_SORT;
+               arg++;
+       }
+       if (starts_with(arg, "version:")) {
+               *sort = VERCMP_SORT;
+               arg += 8;
+       } else if (starts_with(arg, "v:")) {
+               *sort = VERCMP_SORT;
+               arg += 2;
+       } else
+               *sort = STRCMP_SORT;
+       if (strcmp(arg, "refname"))
+               die(_("unsupported sort specification %s"), arg);
+       *sort |= flags;
+       return 0;
+}
+
 int cmd_tag(int argc, const char **argv, const char *prefix)
 {
        struct strbuf buf = STRBUF_INIT;
@@ -437,7 +492,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
        struct create_tag_options opt;
        char *cleanup_arg = NULL;
        int annotate = 0, force = 0, lines = -1;
-       int cmdmode = 0;
+       int cmdmode = 0, sort = 0;
        const char *msgfile = NULL, *keyid = NULL;
        struct msg_arg msg = { 0, STRBUF_INIT };
        struct commit_list *with_commit = NULL;
@@ -462,6 +517,10 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                                        N_("use another key to sign the tag")),
                OPT__FORCE(&force, N_("replace the tag if exists")),
                OPT_COLUMN(0, "column", &colopts, N_("show tag list in columns")),
+               {
+                       OPTION_CALLBACK, 0, "sort", &sort, N_("type"), N_("sort tags"),
+                       PARSE_OPT_NONEG, parse_opt_sort
+               },
 
                OPT_GROUP(N_("Tag listing options")),
                {
@@ -470,6 +529,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                        PARSE_OPT_LASTARG_DEFAULT,
                        parse_opt_with_commit, (intptr_t)"HEAD",
                },
+               {
+                       OPTION_CALLBACK, 0, "with", &with_commit, N_("commit"),
+                       N_("print only tags that contain the commit"),
+                       PARSE_OPT_HIDDEN | PARSE_OPT_LASTARG_DEFAULT,
+                       parse_opt_with_commit, (intptr_t)"HEAD",
+               },
                {
                        OPTION_CALLBACK, 0, "points-at", NULL, N_("object"),
                        N_("print only tags of the object"), 0, parse_opt_points_at
@@ -509,7 +574,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                        copts.padding = 2;
                        run_column_filter(colopts, &copts);
                }
-               ret = list_tags(argv, lines == -1 ? 0 : lines, with_commit);
+               if (lines != -1 && sort)
+                       die(_("--sort and -n are incompatible"));
+               ret = list_tags(argv, lines == -1 ? 0 : lines, with_commit, sort);
                if (column_active(colopts))
                        stop_column_filter();
                return ret;
index 118c62528b0bb6c919d146d60516825a5336fe75..98e651c284254b3c96c59b4f444cbc0f54edd90e 100644 (file)
@@ -4,6 +4,7 @@
 #include "bulk-checkin.h"
 #include "csum-file.h"
 #include "pack.h"
+#include "strbuf.h"
 
 static int pack_compression_level = Z_DEFAULT_COMPRESSION;
 
@@ -23,7 +24,7 @@ static struct bulk_checkin_state {
 static void finish_bulk_checkin(struct bulk_checkin_state *state)
 {
        unsigned char sha1[20];
-       char packname[PATH_MAX];
+       struct strbuf packname = STRBUF_INIT;
        int i;
 
        if (!state->f)
@@ -43,8 +44,8 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
                close(fd);
        }
 
-       sprintf(packname, "%s/pack/pack-", get_object_directory());
-       finish_tmp_packfile(packname, state->pack_tmp_name,
+       strbuf_addf(&packname, "%s/pack/pack-", get_object_directory());
+       finish_tmp_packfile(&packname, state->pack_tmp_name,
                            state->written, state->nr_written,
                            &state->pack_idx_opts, sha1);
        for (i = 0; i < state->nr_written; i++)
@@ -54,6 +55,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
        free(state->written);
        memset(state, 0, sizeof(*state));
 
+       strbuf_release(&packname);
        /* Make objects we just wrote available to ourselves */
        reprepare_packed_git();
 }
index e99065ce425ad6e816d946626ef83075ab70bf85..a85e0e4532ad10934b3d9c510db9e26b338f14f1 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -14,12 +14,8 @@ static const char bundle_signature[] = "# v2 git bundle\n";
 static void add_to_ref_list(const unsigned char *sha1, const char *name,
                struct ref_list *list)
 {
-       if (list->nr + 1 >= list->alloc) {
-               list->alloc = alloc_nr(list->nr + 1);
-               list->list = xrealloc(list->list,
-                               list->alloc * sizeof(list->list[0]));
-       }
-       memcpy(list->list[list->nr].sha1, sha1, 20);
+       ALLOC_GROW(list->list, list->nr + 1, list->alloc);
+       hashcpy(list->list[list->nr].sha1, sha1);
        list->list[list->nr].name = xstrdup(name);
        list->nr++;
 }
index 0bbec432165874bd36b1f220301de7f1363626dc..7fa524a11323621d24c352b0a1108ae953a60cf5 100644 (file)
@@ -75,11 +75,7 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,
                return NULL;
 
        pos = -pos-1;
-       if (it->subtree_alloc <= it->subtree_nr) {
-               it->subtree_alloc = alloc_nr(it->subtree_alloc);
-               it->down = xrealloc(it->down, it->subtree_alloc *
-                                   sizeof(*it->down));
-       }
+       ALLOC_GROW(it->down, it->subtree_nr + 1, it->subtree_alloc);
        it->subtree_nr++;
 
        down = xmalloc(sizeof(*down) + pathlen + 1);
@@ -121,11 +117,11 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
 
        if (!it)
                return;
-       slash = strchr(path, '/');
+       slash = strchrnul(path, '/');
+       namelen = slash - path;
        it->entry_count = -1;
-       if (!slash) {
+       if (!*slash) {
                int pos;
-               namelen = strlen(path);
                pos = subtree_pos(it, path, namelen);
                if (0 <= pos) {
                        cache_tree_free(&it->down[pos]->cache_tree);
@@ -143,7 +139,6 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
                }
                return;
        }
-       namelen = slash - path;
        down = find_subtree(it, path, namelen, 0);
        if (down)
                cache_tree_invalidate_path(down->cache_tree, slash + 1);
@@ -554,22 +549,19 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
                const char *slash;
                struct cache_tree_sub *sub;
 
-               slash = strchr(path, '/');
-               if (!slash)
-                       slash = path + strlen(path);
-               /* between path and slash is the name of the
-                * subtree to look for.
+               slash = strchrnul(path, '/');
+               /*
+                * Between path and slash is the name of the subtree
+                * to look for.
                 */
                sub = find_subtree(it, path, slash - path, 0);
                if (!sub)
                        return NULL;
                it = sub->cache_tree;
-               if (slash)
-                       while (*slash && *slash == '/')
-                               slash++;
-               if (!slash || !*slash)
-                       return it; /* prefix ended with slashes */
+
                path = slash;
+               while (*path == '/')
+                       path++;
        }
        return it;
 }
diff --git a/cache.h b/cache.h
index b66cb49b7486e905993fef636b4d3696a57015d5..107ac61b68f15b1e15532c09fda9e9799f830e44 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1458,4 +1458,6 @@ int stat_validity_check(struct stat_validity *sv, const char *path);
  */
 void stat_validity_update(struct stat_validity *sv, int fd);
 
+int versioncmp(const char *s1, const char *s2);
+
 #endif /* CACHE_H */
index fa401ae7b06f3c62345ccaec08b89757966687c1..0f28902bc351fef9d621cfe290f887921ec779c4 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -10,6 +10,7 @@
 #include "mergesort.h"
 #include "commit-slab.h"
 #include "prio-queue.h"
+#include "sha1-lookup.h"
 
 static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
 
@@ -114,23 +115,16 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
 static struct commit_graft **commit_graft;
 static int commit_graft_alloc, commit_graft_nr;
 
+static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
+{
+       struct commit_graft **commit_graft_table = table;
+       return commit_graft_table[index]->sha1;
+}
+
 static int commit_graft_pos(const unsigned char *sha1)
 {
-       int lo, hi;
-       lo = 0;
-       hi = commit_graft_nr;
-       while (lo < hi) {
-               int mi = (lo + hi) / 2;
-               struct commit_graft *graft = commit_graft[mi];
-               int cmp = hashcmp(sha1, graft->sha1);
-               if (!cmp)
-                       return mi;
-               if (cmp < 0)
-                       hi = mi;
-               else
-                       lo = mi + 1;
-       }
-       return -lo - 1;
+       return sha1_pos(sha1, commit_graft, commit_graft_nr,
+                       commit_graft_sha1_access);
 }
 
 int register_commit_graft(struct commit_graft *graft, int ignore_dups)
@@ -147,12 +141,8 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
                return 1;
        }
        pos = -pos - 1;
-       if (commit_graft_alloc <= ++commit_graft_nr) {
-               commit_graft_alloc = alloc_nr(commit_graft_alloc);
-               commit_graft = xrealloc(commit_graft,
-                                       sizeof(*commit_graft) *
-                                       commit_graft_alloc);
-       }
+       ALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);
+       commit_graft_nr++;
        if (pos < commit_graft_nr)
                memmove(commit_graft + pos + 1,
                        commit_graft + pos,
index 16d9c4351395ac55d6856d8d92d24ce7064df974..55631f191f2a01276e8a16192117fb3cf25bc958 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -209,7 +209,7 @@ extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
 extern void setup_alternate_shallow(struct lock_file *shallow_lock,
                                    const char **alternate_shallow_file,
                                    const struct sha1_array *extra);
-extern char *setup_temporary_shallow(const struct sha1_array *extra);
+extern const char *setup_temporary_shallow(const struct sha1_array *extra);
 extern void advertise_shallow_grafts(int);
 
 struct shallow_info {
index 24ab7383aecf36e010f838d04b671903d1d8a79f..b7112542b4b62fbbf0235c923f75803edc149e5c 100644 (file)
@@ -890,7 +890,7 @@ GIT_CONF_SUBST([HAVE_STRINGS_H])
 # and libcharset does
 CHARSET_LIB=
 AC_CHECK_LIB([iconv], [locale_charset],
-       [],
+       [CHARSET_LIB=-liconv],
        [AC_CHECK_LIB([charset], [locale_charset],
                      [CHARSET_LIB=-lcharset])])
 GIT_CONF_SUBST([CHARSET_LIB])
index 4150412e2c0ebf6129137baf41c9d268d50c60bd..a983d061a90f0b720afa1a9b50247da299164d79 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -727,7 +727,7 @@ struct child_process *git_connect(int fd[2], const char *url,
                                *arg++ = port;
                        }
                        *arg++ = ssh_host;
-               }       else {
+               } else {
                        /* remove repo-local variables from the environment */
                        conn->env = local_repo_env;
                        conn->use_shell = 1;
index 332aba784b8810120df8e1ddfafeb034a55337a3..5f4b2e3e160f60955e25f8b8fedf8c122dd5c73c 100755 (executable)
@@ -684,7 +684,8 @@ def do_export(parser):
                 peer = bzrlib.branch.Branch.open(peers[name],
                                                  possible_transports=transports)
                 try:
-                    peer.bzrdir.push_branch(branch, revision_id=revid)
+                    peer.bzrdir.push_branch(branch, revision_id=revid,
+                                            overwrite=force)
                 except bzrlib.errors.DivergedBranches:
                     print "error %s non-fast forward" % ref
                     continue
@@ -718,8 +719,32 @@ def do_capabilities(parser):
         print "*import-marks %s" % path
     print "*export-marks %s" % path
 
+    print "option"
     print
 
+class InvalidOptionValue(Exception):
+    pass
+
+def get_bool_option(val):
+    if val == 'true':
+        return True
+    elif val == 'false':
+        return False
+    else:
+        raise InvalidOptionValue()
+
+def do_option(parser):
+    global force
+    opt, val = parser[1:3]
+    try:
+        if opt == 'force':
+            force = get_bool_option(val)
+            print 'ok'
+        else:
+            print 'unsupported'
+    except InvalidOptionValue:
+        print "error '%s' is not a valid value for option '%s'" % (val, opt)
+
 def ref_is_valid(name):
     return not True in [c in name for c in '~^: \\']
 
@@ -882,6 +907,7 @@ def main(args):
     global is_tmp
     global branches, peers
     global transports
+    global force
 
     marks = None
     is_tmp = False
@@ -904,6 +930,7 @@ def main(args):
     branches = {}
     peers = {}
     transports = []
+    force = False
 
     if alias[5:] == url:
         is_tmp = True
@@ -936,6 +963,8 @@ def main(args):
             do_import(parser)
         elif parser.check('export'):
             do_export(parser)
+        elif parser.check('option'):
+            do_option(parser)
         else:
             die('unhandled command: %s' % line)
         sys.stdout.flush()
index 1e53ff9a584a302366dcbd647a2e27db3fd1b9fe..4f379c2ab499f2ca5556f844cbdcacb98fffa13c 100755 (executable)
@@ -66,13 +66,33 @@ test_expect_success 'pushing' '
        test_cmp expected actual
 '
 
+test_expect_success 'forced pushing' '
+       (
+       cd gitrepo &&
+       echo three-new >content &&
+       git commit -a --amend -m three-new &&
+       git push -f
+       ) &&
+
+       (
+       cd bzrrepo &&
+       # the forced update overwrites the bzr branch but not the bzr
+       # working directory (it tries to merge instead)
+       bzr revert
+       ) &&
+
+       echo three-new >expected &&
+       cat bzrrepo/content >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'roundtrip' '
        (
        cd gitrepo &&
        git pull &&
        git log --format="%s" -1 origin/master >actual
        ) &&
-       echo three >expected &&
+       echo three-new >expected &&
        test_cmp expected actual &&
 
        (cd gitrepo && git push && git pull) &&
index 5d128a5da9a1afd3bf441f58e75d4f02a64509d5..a933b1e30c6fe82393f3df1446333386d9795b12 100755 (executable)
@@ -680,7 +680,7 @@ test_expect_success 'remote big push fetch first' '
        )
 '
 
-test_expect_failure 'remote big push force' '
+test_expect_success 'remote big push force' '
        test_when_finished "rm -rf hgrepo gitrepo*" &&
 
        setup_big_push
@@ -710,7 +710,7 @@ test_expect_failure 'remote big push force' '
        check_bookmark hgrepo new_bmark six
 '
 
-test_expect_failure 'remote big push dry-run' '
+test_expect_success 'remote big push dry-run' '
        test_when_finished "rm -rf hgrepo gitrepo*" &&
 
        setup_big_push
index 8e10bff30e5269687e67866c2d3c66d62e3bb883..c554691df0bdb46eee26b4ca4c957fa86fc9f8c4 100644 (file)
@@ -15,8 +15,9 @@
 #include "log-tree.h"
 #include "builtin.h"
 #include "string-list.h"
+#include "dir.h"
 
-static int read_directory(const char *path, struct string_list *list)
+static int read_directory_contents(const char *path, struct string_list *list)
 {
        DIR *dir;
        struct dirent *e;
@@ -25,7 +26,7 @@ static int read_directory(const char *path, struct string_list *list)
                return error("Could not open directory %s", path);
 
        while ((e = readdir(dir)))
-               if (strcmp(".", e->d_name) && strcmp("..", e->d_name))
+               if (!is_dot_or_dotdot(e->d_name))
                        string_list_insert(list, e->d_name);
 
        closedir(dir);
@@ -107,9 +108,9 @@ static int queue_diff(struct diff_options *o,
                int i1, i2, ret = 0;
                size_t len1 = 0, len2 = 0;
 
-               if (name1 && read_directory(name1, &p1))
+               if (name1 && read_directory_contents(name1, &p1))
                        return -1;
-               if (name2 && read_directory(name2, &p2)) {
+               if (name2 && read_directory_contents(name2, &p2)) {
                        string_list_clear(&p1, 0);
                        return -1;
                }
diff --git a/diff.c b/diff.c
index e9a8874d069469f4893add139c4b5d999fc36630..e343191bdaba0dbf63a841a79287cbb5f56fc18a 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1361,11 +1361,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
 {
        struct diffstat_file *x;
        x = xcalloc(sizeof (*x), 1);
-       if (diffstat->nr == diffstat->alloc) {
-               diffstat->alloc = alloc_nr(diffstat->alloc);
-               diffstat->files = xrealloc(diffstat->files,
-                               diffstat->alloc * sizeof(x));
-       }
+       ALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);
        diffstat->files[diffstat->nr++] = x;
        if (name_b) {
                x->from_name = xstrdup(name_a);
@@ -3366,14 +3362,11 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
        if (c != '-')
                return 0;
        arg++;
-       eq = strchr(arg, '=');
-       if (eq)
-               len = eq - arg;
-       else
-               len = strlen(arg);
+       eq = strchrnul(arg, '=');
+       len = eq - arg;
        if (!len || strncmp(arg, arg_long, len))
                return 0;
-       if (eq) {
+       if (*eq) {
                int n;
                char *end;
                if (!isdigit(*++eq))
@@ -3958,11 +3951,7 @@ struct diff_queue_struct diff_queued_diff;
 
 void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)
 {
-       if (queue->alloc <= queue->nr) {
-               queue->alloc = alloc_nr(queue->alloc);
-               queue->queue = xrealloc(queue->queue,
-                                       sizeof(dp) * queue->alloc);
-       }
+       ALLOC_GROW(queue->queue, queue->nr + 1, queue->alloc);
        queue->queue[queue->nr++] = dp;
 }
 
index 39effecd843a8ba0435246755ce12cfdaf6919c3..749a35d2c2ab3271c6503a19271a5be6a6e97b4d 100644 (file)
@@ -38,11 +38,7 @@ static struct diff_rename_dst *locate_rename_dst(struct diff_filespec *two,
        if (!insert_ok)
                return NULL;
        /* insert to make it at "first" */
-       if (rename_dst_alloc <= rename_dst_nr) {
-               rename_dst_alloc = alloc_nr(rename_dst_alloc);
-               rename_dst = xrealloc(rename_dst,
-                                     rename_dst_alloc * sizeof(*rename_dst));
-       }
+       ALLOC_GROW(rename_dst, rename_dst_nr + 1, rename_dst_alloc);
        rename_dst_nr++;
        if (first < rename_dst_nr)
                memmove(rename_dst + first + 1, rename_dst + first,
@@ -82,11 +78,7 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
        }
 
        /* insert to make it at "first" */
-       if (rename_src_alloc <= rename_src_nr) {
-               rename_src_alloc = alloc_nr(rename_src_alloc);
-               rename_src = xrealloc(rename_src,
-                                     rename_src_alloc * sizeof(*rename_src));
-       }
+       ALLOC_GROW(rename_src, rename_src_nr + 1, rename_src_alloc);
        rename_src_nr++;
        if (first < rename_src_nr)
                memmove(rename_src + first + 1, rename_src + first,
index 92788ee4de8e59068a204729a8d6f7f89aaa6ee6..c876dac71a585abb1e138444eb28258e3bf6d7e8 100644 (file)
@@ -46,7 +46,7 @@ struct diff_filespec {
        unsigned is_stdin : 1;
        unsigned has_more_entries : 1; /* only appear in combined diff */
        /* data should be considered "binary"; -1 means "don't know yet" */
-       int is_binary : 2;
+       signed int is_binary : 2;
        struct userdiff_driver *driver;
 };
 
diff --git a/dir.c b/dir.c
index 70eefdd350429cc2a9a9238449b315512d189451..99f53033ba174301437c65b1dfa8f8cceb74f517 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -1364,10 +1364,7 @@ static struct path_simplify *create_simplify(const char **pathspec)
 
        for (nr = 0 ; ; nr++) {
                const char *match;
-               if (nr >= alloc) {
-                       alloc = alloc_nr(alloc);
-                       simplify = xrealloc(simplify, alloc * sizeof(*simplify));
-               }
+               ALLOC_GROW(simplify, nr + 1, alloc);
                match = *pathspec++;
                if (!match)
                        break;
diff --git a/entry.c b/entry.c
index 7b7aa8167adade20f38cfb2709e02b3ed31f11a4..77c688262477e783b4bcbc237ef281eecab0661d 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -44,33 +44,33 @@ static void create_directories(const char *path, int path_len,
        free(buf);
 }
 
-static void remove_subtree(const char *path)
+static void remove_subtree(struct strbuf *path)
 {
-       DIR *dir = opendir(path);
+       DIR *dir = opendir(path->buf);
        struct dirent *de;
-       char pathbuf[PATH_MAX];
-       char *name;
+       int origlen = path->len;
 
        if (!dir)
-               die_errno("cannot opendir '%s'", path);
-       strcpy(pathbuf, path);
-       name = pathbuf + strlen(path);
-       *name++ = '/';
+               die_errno("cannot opendir '%s'", path->buf);
        while ((de = readdir(dir)) != NULL) {
                struct stat st;
+
                if (is_dot_or_dotdot(de->d_name))
                        continue;
-               strcpy(name, de->d_name);
-               if (lstat(pathbuf, &st))
-                       die_errno("cannot lstat '%s'", pathbuf);
+
+               strbuf_addch(path, '/');
+               strbuf_addstr(path, de->d_name);
+               if (lstat(path->buf, &st))
+                       die_errno("cannot lstat '%s'", path->buf);
                if (S_ISDIR(st.st_mode))
-                       remove_subtree(pathbuf);
-               else if (unlink(pathbuf))
-                       die_errno("cannot unlink '%s'", pathbuf);
+                       remove_subtree(path);
+               else if (unlink(path->buf))
+                       die_errno("cannot unlink '%s'", path->buf);
+               strbuf_setlen(path, origlen);
        }
        closedir(dir);
-       if (rmdir(path))
-               die_errno("cannot rmdir '%s'", path);
+       if (rmdir(path->buf))
+               die_errno("cannot rmdir '%s'", path->buf);
 }
 
 static int create_file(const char *path, unsigned int mode)
@@ -245,27 +245,25 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
 int checkout_entry(struct cache_entry *ce,
                   const struct checkout *state, char *topath)
 {
-       static struct strbuf path_buf = STRBUF_INIT;
-       char *path;
+       static struct strbuf path = STRBUF_INIT;
        struct stat st;
-       int len;
 
        if (topath)
                return write_entry(ce, topath, state, 1);
 
-       strbuf_reset(&path_buf);
-       strbuf_add(&path_buf, state->base_dir, state->base_dir_len);
-       strbuf_add(&path_buf, ce->name, ce_namelen(ce));
-       path = path_buf.buf;
-       len = path_buf.len;
+       strbuf_reset(&path);
+       strbuf_add(&path, state->base_dir, state->base_dir_len);
+       strbuf_add(&path, ce->name, ce_namelen(ce));
 
-       if (!check_path(pathlen, &st, state->base_dir_len)) {
+       if (!check_path(path.buf, path.len, &st, state->base_dir_len)) {
                unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
                if (!changed)
                        return 0;
                if (!state->force) {
                        if (!state->quiet)
-                               fprintf(stderr, "%s already exists, no checkout\n", path);
+                               fprintf(stderr,
+                                       "%s already exists, no checkout\n",
+                                       path.buf);
                        return -1;
                }
 
@@ -280,12 +278,14 @@ int checkout_entry(struct cache_entry *ce,
                        if (S_ISGITLINK(ce->ce_mode))
                                return 0;
                        if (!state->force)
-                               return error("%s is a directory", path);
-                       remove_subtree(path);
-               } else if (unlink(path))
-                       return error("unable to unlink old '%s' (%s)", path, strerror(errno));
+                               return error("%s is a directory", path.buf);
+                       remove_subtree(&path);
+               } else if (unlink(path.buf))
+                       return error("unable to unlink old '%s' (%s)",
+                                    path.buf, strerror(errno));
        } else if (state->not_new)
                return 0;
-       create_directories(path, len, state);
-       return write_entry(ce, path, state, 0);
+
+       create_directories(path.buf, path.len, state);
+       return write_entry(ce, path.buf, state, 0);
 }
index 4fd18a3574a6e72bb7a299b26b3f97fa20b8052d..fb4738d373a5a1048c2ff388a729e6088515ca9b 100644 (file)
@@ -1485,14 +1485,11 @@ static int tree_content_set(
        unsigned int i, n;
        struct tree_entry *e;
 
-       slash1 = strchr(p, '/');
-       if (slash1)
-               n = slash1 - p;
-       else
-               n = strlen(p);
+       slash1 = strchrnul(p, '/');
+       n = slash1 - p;
        if (!n)
                die("Empty path component found in input");
-       if (!slash1 && !S_ISDIR(mode) && subtree)
+       if (!*slash1 && !S_ISDIR(mode) && subtree)
                die("Non-directories cannot have subtrees");
 
        if (!root->tree)
@@ -1501,7 +1498,7 @@ static int tree_content_set(
        for (i = 0; i < t->entry_count; i++) {
                e = t->entries[i];
                if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) {
-                       if (!slash1) {
+                       if (!*slash1) {
                                if (!S_ISDIR(mode)
                                                && e->versions[1].mode == mode
                                                && !hashcmp(e->versions[1].sha1, sha1))
@@ -1552,7 +1549,7 @@ static int tree_content_set(
        e->versions[0].mode = 0;
        hashclr(e->versions[0].sha1);
        t->entries[t->entry_count++] = e;
-       if (slash1) {
+       if (*slash1) {
                e->tree = new_tree_content(8);
                e->versions[1].mode = S_IFDIR;
                tree_content_set(e, slash1 + 1, sha1, mode, subtree);
@@ -1576,11 +1573,8 @@ static int tree_content_remove(
        unsigned int i, n;
        struct tree_entry *e;
 
-       slash1 = strchr(p, '/');
-       if (slash1)
-               n = slash1 - p;
-       else
-               n = strlen(p);
+       slash1 = strchrnul(p, '/');
+       n = slash1 - p;
 
        if (!root->tree)
                load_tree(root);
@@ -1594,7 +1588,7 @@ static int tree_content_remove(
        for (i = 0; i < t->entry_count; i++) {
                e = t->entries[i];
                if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) {
-                       if (slash1 && !S_ISDIR(e->versions[1].mode))
+                       if (*slash1 && !S_ISDIR(e->versions[1].mode))
                                /*
                                 * If p names a file in some subdirectory, and a
                                 * file or symlink matching the name of the
@@ -1602,7 +1596,7 @@ static int tree_content_remove(
                                 * exist and need not be deleted.
                                 */
                                return 1;
-                       if (!slash1 || !S_ISDIR(e->versions[1].mode))
+                       if (!*slash1 || !S_ISDIR(e->versions[1].mode))
                                goto del_entry;
                        if (!e->tree)
                                load_tree(e);
@@ -1644,11 +1638,8 @@ static int tree_content_get(
        unsigned int i, n;
        struct tree_entry *e;
 
-       slash1 = strchr(p, '/');
-       if (slash1)
-               n = slash1 - p;
-       else
-               n = strlen(p);
+       slash1 = strchrnul(p, '/');
+       n = slash1 - p;
        if (!n && !allow_root)
                die("Empty path component found in input");
 
@@ -1664,7 +1655,7 @@ static int tree_content_get(
        for (i = 0; i < t->entry_count; i++) {
                e = t->entries[i];
                if (e->name->str_len == n && !strncmp_icase(p, e->name->str_dat, n)) {
-                       if (!slash1)
+                       if (!*slash1)
                                goto found_entry;
                        if (!S_ISDIR(e->versions[1].mode))
                                return 0;
index f061f1fe85ea20549f860c4bf37980941f480833..90d47da8a902f24bb6a7ae63654a104626751b1e 100644 (file)
@@ -948,17 +948,6 @@ static void update_shallow(struct fetch_pack_args *args,
        if (!si->shallow || !si->shallow->nr)
                return;
 
-       if (alternate_shallow_file) {
-               /*
-                * The temporary shallow file is only useful for
-                * index-pack and unpack-objects because it may
-                * contain more roots than we want. Delete it.
-                */
-               if (*alternate_shallow_file)
-                       unlink(alternate_shallow_file);
-               free((char *)alternate_shallow_file);
-       }
-
        if (args->cloning) {
                /*
                 * remote is shallow, but this is a clone, there are
index 585ef8a79bd9fa66a34a840eae30658894a213f1..892032bc79b88c9180f9f4c8ba171407d7c784ed 100644 (file)
@@ -343,8 +343,11 @@ extern int ends_with(const char *str, const char *suffix);
 
 static inline const char *skip_prefix(const char *str, const char *prefix)
 {
-       size_t len = strlen(prefix);
-       return strncmp(str, prefix, len) ? NULL : str + len;
+       do {
+               if (!*prefix)
+                       return str;
+       } while (*str++ == *prefix++);
+       return NULL;
 }
 
 #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
index a1adae83131b5918ec6f994043f3f3ccd3b8c3d8..1c41cbd66c77641772c41898362b7fc550c4faca 100644 (file)
@@ -749,7 +749,7 @@ rearrange_squash () {
                                        ;;
                                esac
                        done
-                       echo "$sha1 $action $prefix $rest"
+                       printf '%s %s %s %s\n' "$sha1" "$action" "$prefix" "$rest"
                        # if it's a single word, try to resolve to a full sha1 and
                        # emit a second copy. This allows us to match on both message
                        # and on sha1 prefix
index 6d2f282d32212b605a1237bae224ecbba05cacd1..1c006a0518e247d58759df98602f6dae3935caf6 100755 (executable)
@@ -15,6 +15,8 @@ test -z "$refspec" && prefix="refs"
 
 export GIT_DIR="$url/.git"
 
+force=
+
 mkdir -p "$dir"
 
 if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
@@ -39,6 +41,7 @@ do
                fi
                test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
                test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
+               echo 'option'
                echo
                ;;
        list)
@@ -93,6 +96,7 @@ do
                before=$(git for-each-ref --format=' %(refname) %(objectname) ')
 
                git fast-import \
+                       ${force:+--force} \
                        ${testgitmarks:+"--import-marks=$testgitmarks"} \
                        ${testgitmarks:+"--export-marks=$testgitmarks"} \
                        --quiet
@@ -115,6 +119,20 @@ do
 
                echo
                ;;
+       option\ *)
+               read cmd opt val <<-EOF
+               $line
+               EOF
+               case $opt in
+               force)
+                       test $val = "true" && force="true" || force=
+                       echo "ok"
+                       ;;
+               *)
+                       echo "unsupported"
+                       ;;
+               esac
+               ;;
        '')
                exit
                ;;
index cf4f1505a54bb6d2fdd580ab7e8186dc8103de49..5c1599752314696ef1f317095d1786493fbfc935 100755 (executable)
@@ -36,20 +36,7 @@ do
        shift
 done
 
-base=$1 url=$2 head=${3-HEAD} status=0 branch_name=
-
-headref=$(git symbolic-ref -q "$head")
-if git show-ref -q --verify "$headref"
-then
-       branch_name=${headref#refs/heads/}
-       if test "z$branch_name" = "z$headref" ||
-               ! git config "branch.$branch_name.description" >/dev/null
-       then
-               branch_name=
-       fi
-fi
-
-tag_name=$(git describe --exact "$head^0" 2>/dev/null)
+base=$1 url=$2 status=0
 
 test -n "$base" && test -n "$url" || usage
 
@@ -59,55 +46,78 @@ then
     die "fatal: Not a valid revision: $base"
 fi
 
+#
+# $3 must be a symbolic ref, a unique ref, or
+# a SHA object expression. It can also be of
+# the format 'local-name:remote-name'.
+#
+local=${3%:*}
+local=${local:-HEAD}
+remote=${3#*:}
+pretty_remote=${remote#refs/}
+pretty_remote=${pretty_remote#heads/}
+head=$(git symbolic-ref -q "$local")
+head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)}
+head=${head:-$(git rev-parse --quiet --verify "$local")}
+
+# None of the above? Bad.
+test -z "$head" && die "fatal: Not a valid revision: $local"
+
+# This also verifies that the resulting head is unique:
+# "git show-ref" could have shown multiple matching refs..
 headrev=$(git rev-parse --verify --quiet "$head"^0)
-if test -z "$headrev"
+test -z "$headrev" && die "fatal: Ambiguous revision: $local"
+
+# Was it a branch with a description?
+branch_name=${head#refs/heads/}
+if test "z$branch_name" = "z$headref" ||
+       ! git config "branch.$branch_name.description" >/dev/null
 then
-    die "fatal: Not a valid revision: $head"
+       branch_name=
 fi
 
 merge_base=$(git merge-base $baserev $headrev) ||
 die "fatal: No commits in common between $base and $head"
 
-# $head is the token given from the command line, and $tag_name, if
-# exists, is the tag we are going to show the commit information for.
-# If that tag exists at the remote and it points at the commit, use it.
-# Otherwise, if a branch with the same name as $head exists at the remote
-# and their values match, use that instead.
+# $head is the refname from the command line.
+# If a ref with the same name as $head exists at the remote
+# and their values match, use that.
 #
 # Otherwise find a random ref that matches $headrev.
 find_matching_ref='
-       sub abbr {
-               my $ref = shift;
-               if ($ref =~ s|^refs/heads/|| || $ref =~ s|^refs/tags/|tags/|) {
-                       return $ref;
-               } else {
-                       return $ref;
-               }
-       }
+       my ($head,$headrev) = (@ARGV);
+       my ($found);
 
-       my ($tagged, $branch, $found);
        while (<STDIN>) {
-               my ($sha1, $ref, $deref) = /^(\S+)\s+(\S+?)(\^\{\})?$/;
-               next unless ($sha1 eq $ARGV[1]);
-               $found = abbr($ref);
-               if ($deref && $ref eq "tags/$ARGV[2]") {
-                       $tagged = $found;
-                       last;
+               chomp;
+               my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
+               my ($pattern);
+               next unless ($sha1 eq $headrev);
+
+               $pattern="/$head\$";
+               if ($ref eq $head) {
+                       $found = $ref;
+               }
+               if ($ref =~ /$pattern/) {
+                       $found = $ref;
                }
-               if ($ref =~ m|/\Q$ARGV[0]\E$|) {
-                       $exact = $found;
+               if ($sha1 eq $head) {
+                       $found = $sha1;
                }
        }
-       if ($tagged) {
-               print "$tagged\n";
-       } elsif ($exact) {
-               print "$exact\n";
-       } elsif ($found) {
+       if ($found) {
                print "$found\n";
        }
 '
 
-ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "$head" "$headrev" "$tag_name")
+ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
+
+if test -z "$ref"
+then
+       echo "warn: No match for commit $headrev found at $url" >&2
+       echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
+       status=1
+fi
 
 url=$(git ls-remote --get-url "$url")
 
@@ -117,7 +127,7 @@ git show -s --format='The following changes since commit %H:
 
 are available in the git repository at:
 ' $merge_base &&
-echo "  $url${ref+ $ref}" &&
+echo "  $url $pretty_remote" &&
 git show -s --format='
 for you to fetch changes up to %H:
 
@@ -125,39 +135,23 @@ for you to fetch changes up to %H:
 
 ----------------------------------------------------------------' $headrev &&
 
-if test -n "$branch_name"
+if test $(git cat-file -t "$head") = tag
 then
-       echo "(from the branch description for $branch_name local branch)"
-       echo
-       git config "branch.$branch_name.description"
-fi &&
-
-if test -n "$tag_name"
-then
-       if test -z "$ref" || test "$ref" != "tags/$tag_name"
-       then
-               echo >&2 "warn: You locally have $tag_name but it does not (yet)"
-               echo >&2 "warn: appear to be at $url"
-               echo >&2 "warn: Do you want to push it there, perhaps?"
-       fi
-       git cat-file tag "$tag_name" |
+       git cat-file tag "$head" |
        sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
        echo
+       echo "----------------------------------------------------------------"
 fi &&
 
-if test -n "$branch_name" || test -n "$tag_name"
+if test -n "$branch_name"
 then
+       echo "(from the branch description for $branch_name local branch)"
+       echo
+       git config "branch.$branch_name.description"
        echo "----------------------------------------------------------------"
 fi &&
 
 git shortlog ^$baserev $headrev &&
 git diff -M --stat --summary $patch $merge_base..$headrev || status=1
 
-if test -z "$ref"
-then
-       echo "warn: No branch of $url is at:" >&2
-       git show -s --format='warn:   %h: %s' $headrev >&2
-       echo "warn: Are you sure you pushed '$head' there?" >&2
-       status=1
-fi
 exit $status
index f0a94abf1434c65d27caf4cd674f89de62e9333c..4798bcf0e51b705005215e9a6339310defe16d03 100755 (executable)
@@ -512,8 +512,14 @@ apply_stash () {
 pop_stash() {
        assert_stash_ref "$@"
 
-       apply_stash "$@" &&
-       drop_stash "$@"
+       if apply_stash "$@"
+       then
+               drop_stash "$@"
+       else
+               status=$?
+               say "The stash is kept in case you need it again."
+               exit $status
+       fi
 }
 
 drop_stash () {
diff --git a/grep.c b/grep.c
index c668034739258d0cd1e7108357da80d44891221f..4aef0a69d084deee61486e43bc62ae2da6b6b440 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -1562,8 +1562,11 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
         */
        if (opt->count && count) {
                char buf[32];
-               output_color(opt, gs->name, strlen(gs->name), opt->color_filename);
-               output_sep(opt, ':');
+               if (opt->pathname) {
+                       output_color(opt, gs->name, strlen(gs->name),
+                                    opt->color_filename);
+                       output_sep(opt, ':');
+               }
                snprintf(buf, sizeof(buf), "%u\n", count);
                opt->output(opt, buf, strlen(buf));
                return 1;
@@ -1650,7 +1653,7 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
                break;
        case GREP_SOURCE_SHA1:
                gs->identifier = xmalloc(20);
-               memcpy(gs->identifier, identifier, 20);
+               hashcpy(gs->identifier, identifier);
                break;
        case GREP_SOURCE_BUF:
                gs->identifier = NULL;
index 7873cdec581eea66feab06c22b83ef7c27c7c5b6..e80b4af354f87caa7a5130660e9c9c530246b8be 100644 (file)
@@ -182,13 +182,10 @@ static int splice_tree(const unsigned char *hash1,
        enum object_type type;
        int status;
 
-       subpath = strchr(prefix, '/');
-       if (!subpath)
-               toplen = strlen(prefix);
-       else {
-               toplen = subpath - prefix;
+       subpath = strchrnul(prefix, '/');
+       toplen = subpath - prefix;
+       if (*subpath)
                subpath++;
-       }
 
        buf = read_sha1_file(hash1, &type, &sz);
        if (!buf)
@@ -215,7 +212,7 @@ static int splice_tree(const unsigned char *hash1,
        if (!rewrite_here)
                die("entry %.*s not found in tree %s",
                    toplen, prefix, sha1_to_hex(hash1));
-       if (subpath) {
+       if (*subpath) {
                status = splice_tree(rewrite_here, subpath, hash2, subtree);
                if (status)
                        return status;
index 1218befaf2afa2f0be4be8a582a1f85bab334ed2..5f1791a59c5e9ecd553fb9109fa774d921f777c8 100644 (file)
@@ -530,7 +530,7 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
        header.version = htons(default_version);
        header.options = htons(flags | options);
        header.entry_count = htonl(writer.selected_nr);
-       memcpy(header.checksum, writer.pack_checksum, 20);
+       hashcpy(header.checksum, writer.pack_checksum);
 
        sha1write(f, &header, sizeof(header));
        dump_bitmap(f, writer.commits);
index 9b8308b7594263c4900a6d75c18b91cea959fd70..9ccf80419b06789aa3a1171869bd4179787e5eff 100644 (file)
@@ -336,7 +336,7 @@ struct sha1file *create_tmp_packfile(char **pack_tmp_name)
        return sha1fd(fd, *pack_tmp_name);
 }
 
-void finish_tmp_packfile(char *name_buffer,
+void finish_tmp_packfile(struct strbuf *name_buffer,
                         const char *pack_tmp_name,
                         struct pack_idx_entry **written_list,
                         uint32_t nr_written,
@@ -344,7 +344,7 @@ void finish_tmp_packfile(char *name_buffer,
                         unsigned char sha1[])
 {
        const char *idx_tmp_name;
-       char *end_of_name_prefix = strrchr(name_buffer, 0);
+       int basename_len = name_buffer->len;
 
        if (adjust_shared_perm(pack_tmp_name))
                die_errno("unable to make temporary pack file readable");
@@ -354,17 +354,19 @@ void finish_tmp_packfile(char *name_buffer,
        if (adjust_shared_perm(idx_tmp_name))
                die_errno("unable to make temporary index file readable");
 
-       sprintf(end_of_name_prefix, "%s.pack", sha1_to_hex(sha1));
-       free_pack_by_name(name_buffer);
+       strbuf_addf(name_buffer, "%s.pack", sha1_to_hex(sha1));
+       free_pack_by_name(name_buffer->buf);
 
-       if (rename(pack_tmp_name, name_buffer))
+       if (rename(pack_tmp_name, name_buffer->buf))
                die_errno("unable to rename temporary pack file");
 
-       sprintf(end_of_name_prefix, "%s.idx", sha1_to_hex(sha1));
-       if (rename(idx_tmp_name, name_buffer))
+       strbuf_setlen(name_buffer, basename_len);
+
+       strbuf_addf(name_buffer, "%s.idx", sha1_to_hex(sha1));
+       if (rename(idx_tmp_name, name_buffer->buf))
                die_errno("unable to rename temporary index file");
 
-       *end_of_name_prefix = '\0';
+       strbuf_setlen(name_buffer, basename_len);
 
        free((void *)idx_tmp_name);
 }
diff --git a/pack.h b/pack.h
index 12d951659c16462cf2da6a43e2c4974b85e39712..3223f5a0380f735509424bbdbad64097948ef85b 100644 (file)
--- a/pack.h
+++ b/pack.h
@@ -91,6 +91,6 @@ extern int encode_in_pack_object_header(enum object_type, uintmax_t, unsigned ch
 extern int read_pack_header(int fd, struct pack_header *);
 
 extern struct sha1file *create_tmp_packfile(char **pack_tmp_name);
-extern void finish_tmp_packfile(char *name_buffer, const char *pack_tmp_name, struct pack_idx_entry **written_list, uint32_t nr_written, struct pack_idx_option *pack_idx_opts, unsigned char sha1[]);
+extern void finish_tmp_packfile(struct strbuf *name_buffer, const char *pack_tmp_name, struct pack_idx_entry **written_list, uint32_t nr_written, struct pack_idx_option *pack_idx_opts, unsigned char sha1[]);
 
 #endif
index 7b8d3faa171309e84bff23c70206a9c8bd99cc71..a5fa0b8938cb2820635bbc620b1b26cc903a6c97 100644 (file)
@@ -223,13 +223,10 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
                           const struct option *options)
 {
        const struct option *all_opts = options;
-       const char *arg_end = strchr(arg, '=');
+       const char *arg_end = strchrnul(arg, '=');
        const struct option *abbrev_option = NULL, *ambiguous_option = NULL;
        int abbrev_flags = 0, ambiguous_flags = 0;
 
-       if (!arg_end)
-               arg_end = arg + strlen(arg);
-
        for (; options->type != OPTION_END; options++) {
                const char *rest, *long_name = options->long_name;
                int flags = 0, opt_flags = 0;
index bc8a28fdd71ae1476002d26adec64f54841f5cba..bf81b923610fe2473655560cd111adb3061673d9 100644 (file)
@@ -83,10 +83,7 @@ static struct patch_id *add_commit(struct commit *commit,
        ent = &bucket->bucket[bucket->nr++];
        hashcpy(ent->patch_id, sha1);
 
-       if (ids->alloc <= ids->nr) {
-               ids->alloc = alloc_nr(ids->nr);
-               ids->table = xrealloc(ids->table, sizeof(ent) * ids->alloc);
-       }
+       ALLOC_GROW(ids->table, ids->nr + 1, ids->alloc);
        if (pos < ids->nr)
                memmove(ids->table + pos + 1, ids->table + pos,
                        sizeof(ent) * (ids->nr - pos));
index 6e266ddf2749ab1b2388f72e3a1101e98fa656cc..3c43db558aee43b0ea69c23c6611dcc9fae0661f 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -555,14 +555,13 @@ static char *get_header(const struct commit *commit, const char *msg,
        const char *line = msg;
 
        while (line) {
-               const char *eol = strchr(line, '\n'), *next;
+               const char *eol = strchrnul(line, '\n'), *next;
 
                if (line == eol)
                        return NULL;
-               if (!eol) {
+               if (!*eol) {
                        warning("malformed commit (header is missing newline): %s",
                                sha1_to_hex(commit->object.sha1));
-                       eol = line + strlen(line);
                        next = NULL;
                } else
                        next = eol + 1;
index f23c44a81a56f43e95a0e14fb37a84bac1a06caf..ba13353b377d4f27b9ff6cf1b85811fcca61e224 100644 (file)
@@ -990,11 +990,7 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
        }
 
        /* Make sure the array is big enough .. */
-       if (istate->cache_nr == istate->cache_alloc) {
-               istate->cache_alloc = alloc_nr(istate->cache_alloc);
-               istate->cache = xrealloc(istate->cache,
-                                       istate->cache_alloc * sizeof(*istate->cache));
-       }
+       ALLOC_GROW(istate->cache, istate->cache_nr + 1, istate->cache_alloc);
 
        /* Add it in.. */
        istate->cache_nr++;
index b2fbdb2392f80a531d5f9a21630a036d45c0a827..0dd5084fe5c80fe9504cfe4ec4bff3722b733eaf 100644 (file)
@@ -26,14 +26,10 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,
        struct complete_reflogs *array = cb_data;
        struct reflog_info *item;
 
-       if (array->nr >= array->alloc) {
-               array->alloc = alloc_nr(array->nr + 1);
-               array->items = xrealloc(array->items, array->alloc *
-                       sizeof(struct reflog_info));
-       }
+       ALLOC_GROW(array->items, array->nr + 1, array->alloc);
        item = array->items + array->nr;
-       memcpy(item->osha1, osha1, 20);
-       memcpy(item->nsha1, nsha1, 20);
+       hashcpy(item->osha1, osha1);
+       hashcpy(item->nsha1, nsha1);
        item->email = xstrdup(email);
        item->timestamp = timestamp;
        item->tz = tz;
@@ -114,11 +110,7 @@ static void add_commit_info(struct commit *commit, void *util,
                struct commit_info_lifo *lifo)
 {
        struct commit_info *info;
-       if (lifo->nr >= lifo->alloc) {
-               lifo->alloc = alloc_nr(lifo->nr + 1);
-               lifo->items = xrealloc(lifo->items,
-                       lifo->alloc * sizeof(struct commit_info));
-       }
+       ALLOC_GROW(lifo->items, lifo->nr + 1, lifo->alloc);
        info = lifo->items + lifo->nr;
        info->commit = commit;
        info->util = util;
diff --git a/refs.c b/refs.c
index f89d589182fcfc595ff1d60f01ffe25e1ea81579..28d5eca8eaff7be48a4b89e6217886b8c96eb3b2 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1222,7 +1222,7 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs,
        if (ref == NULL)
                return -1;
 
-       memcpy(sha1, ref->u.value.sha1, 20);
+       hashcpy(sha1, ref->u.value.sha1);
        return 0;
 }
 
index 078f1ffa417092e1c783b16d782b2aa69417a591..6be55cbe9ed6cf4979ac0971c30f127c9667ab2e 100644 (file)
@@ -78,8 +78,8 @@ static int parse_rev_note(const char *msg, struct rev_note *res)
        size_t len;
 
        while (*msg) {
-               end = strchr(msg, '\n');
-               len = end ? end - msg : strlen(msg);
+               end = strchrnul(msg, '\n');
+               len = end - msg;
 
                key = "Revision-number: ";
                if (starts_with(msg, key)) {
index 5f63d55056e7f1087766374a20a23e794bf3530a..21b096932e033f0ebff92fc2224a79a132256ad2 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1036,11 +1036,13 @@ int count_refspec_match(const char *pattern,
                }
        }
        if (!matched) {
-               *matched_ref = matched_weak;
+               if (matched_ref)
+                       *matched_ref = matched_weak;
                return weak_match;
        }
        else {
-               *matched_ref = matched;
+               if (matched_ref)
+                       *matched_ref = matched;
                return match;
        }
 }
@@ -1060,18 +1062,25 @@ static struct ref *alloc_delete_ref(void)
        return ref;
 }
 
-static struct ref *try_explicit_object_name(const char *name)
+static int try_explicit_object_name(const char *name,
+                                   struct ref **match)
 {
        unsigned char sha1[20];
-       struct ref *ref;
 
-       if (!*name)
-               return alloc_delete_ref();
+       if (!*name) {
+               if (match)
+                       *match = alloc_delete_ref();
+               return 0;
+       }
+
        if (get_sha1(name, sha1))
-               return NULL;
-       ref = alloc_ref(name);
-       hashcpy(ref->new_sha1, sha1);
-       return ref;
+               return -1;
+
+       if (match) {
+               *match = alloc_ref(name);
+               hashcpy((*match)->new_sha1, sha1);
+       }
+       return 0;
 }
 
 static struct ref *make_linked_ref(const char *name, struct ref ***tail)
@@ -1101,12 +1110,37 @@ static char *guess_ref(const char *name, struct ref *peer)
        return strbuf_detach(&buf, NULL);
 }
 
+static int match_explicit_lhs(struct ref *src,
+                             struct refspec *rs,
+                             struct ref **match,
+                             int *allocated_match)
+{
+       switch (count_refspec_match(rs->src, src, match)) {
+       case 1:
+               if (allocated_match)
+                       *allocated_match = 0;
+               return 0;
+       case 0:
+               /* The source could be in the get_sha1() format
+                * not a reference name.  :refs/other is a
+                * way to delete 'other' ref at the remote end.
+                */
+               if (try_explicit_object_name(rs->src, match) < 0)
+                       return error("src refspec %s does not match any.", rs->src);
+               if (allocated_match)
+                       *allocated_match = 1;
+               return 0;
+       default:
+               return error("src refspec %s matches more than one.", rs->src);
+       }
+}
+
 static int match_explicit(struct ref *src, struct ref *dst,
                          struct ref ***dst_tail,
                          struct refspec *rs)
 {
        struct ref *matched_src, *matched_dst;
-       int copy_src;
+       int allocated_src;
 
        const char *dst_value = rs->dst;
        char *dst_guess;
@@ -1115,23 +1149,8 @@ static int match_explicit(struct ref *src, struct ref *dst,
                return 0;
 
        matched_src = matched_dst = NULL;
-       switch (count_refspec_match(rs->src, src, &matched_src)) {
-       case 1:
-               copy_src = 1;
-               break;
-       case 0:
-               /* The source could be in the get_sha1() format
-                * not a reference name.  :refs/other is a
-                * way to delete 'other' ref at the remote end.
-                */
-               matched_src = try_explicit_object_name(rs->src);
-               if (!matched_src)
-                       return error("src refspec %s does not match any.", rs->src);
-               copy_src = 0;
-               break;
-       default:
-               return error("src refspec %s matches more than one.", rs->src);
-       }
+       if (match_explicit_lhs(src, rs, &matched_src, &allocated_src) < 0)
+               return -1;
 
        if (!dst_value) {
                unsigned char sha1[20];
@@ -1176,7 +1195,9 @@ static int match_explicit(struct ref *src, struct ref *dst,
                return error("dst ref %s receives from more than one src.",
                      matched_dst->name);
        else {
-               matched_dst->peer_ref = copy_src ? copy_ref(matched_src) : matched_src;
+               matched_dst->peer_ref = allocated_src ?
+                                       matched_src :
+                                       copy_ref(matched_src);
                matched_dst->force = rs->force;
        }
        return 0;
@@ -1357,6 +1378,31 @@ static void prepare_ref_index(struct string_list *ref_index, struct ref *ref)
        sort_string_list(ref_index);
 }
 
+/*
+ * Given only the set of local refs, sanity-check the set of push
+ * refspecs. We can't catch all errors that match_push_refs would,
+ * but we can catch some errors early before even talking to the
+ * remote side.
+ */
+int check_push_refs(struct ref *src, int nr_refspec, const char **refspec_names)
+{
+       struct refspec *refspec = parse_push_refspec(nr_refspec, refspec_names);
+       int ret = 0;
+       int i;
+
+       for (i = 0; i < nr_refspec; i++) {
+               struct refspec *rs = refspec + i;
+
+               if (rs->pattern || rs->matching)
+                       continue;
+
+               ret |= match_explicit_lhs(src, rs, NULL, NULL);
+       }
+
+       free_refspec(nr_refspec, refspec);
+       return ret;
+}
+
 /*
  * Given the set of refs the local repository has, the set of refs the
  * remote repository has, and the refspec used for push, determine
index fb7647fab92aef651fbf2eb4118232a550450a55..917d383a80ddbfa377f10c3d1a4e132336065c2c 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -166,6 +166,7 @@ extern int query_refspecs(struct refspec *specs, int nr, struct refspec *query);
 char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
                     const char *name);
 
+int check_push_refs(struct ref *src, int nr_refspec, const char **refspec);
 int match_push_refs(struct ref *src, struct ref **dst,
                    int nr_refspec, const char **refspec, int all);
 void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
index 4ee4c8d1040f997193f2b43ec2755c06d3464c3a..0ab2dc137487259d50b69258e967792aa6c43619 100644 (file)
@@ -41,12 +41,8 @@ static int register_replace_object(struct replace_object *replace,
                return 1;
        }
        pos = -pos - 1;
-       if (replace_object_alloc <= ++replace_object_nr) {
-               replace_object_alloc = alloc_nr(replace_object_alloc);
-               replace_object = xrealloc(replace_object,
-                                         sizeof(*replace_object) *
-                                         replace_object_alloc);
-       }
+       ALLOC_GROW(replace_object, replace_object_nr + 1, replace_object_alloc);
+       replace_object_nr++;
        if (pos < replace_object_nr)
                memmove(replace_object + pos + 1,
                        replace_object + pos,
index 78b5c3ac0b2d7d436b35a69a3cf6c1b023c96dd5..85085501f66b02a9cff9b404f34c0925270cea7f 100644 (file)
@@ -1575,6 +1575,10 @@ static void read_revisions_from_stdin(struct rev_info *revs,
 {
        struct strbuf sb;
        int seen_dashdash = 0;
+       int save_warning;
+
+       save_warning = warn_on_object_refname_ambiguity;
+       warn_on_object_refname_ambiguity = 0;
 
        strbuf_init(&sb, 1000);
        while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
@@ -1596,7 +1600,9 @@ static void read_revisions_from_stdin(struct rev_info *revs,
        }
        if (seen_dashdash)
                read_pathspec_from_stdin(revs, &sb, prune);
+
        strbuf_release(&sb);
+       warn_on_object_refname_ambiguity = save_warning;
 }
 
 static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
index 5ddd6886c85356164e81c477d3a170343bc28049..855d28cf9440aba175489b63e5d24665126faf2a 100644 (file)
@@ -237,18 +237,6 @@ string_list_sort (string_list_ty *slp)
     qsort (slp->item, slp->nitems, sizeof (slp->item[0]), cmp_string);
 }
 
-/* Test whether a string list contains a given string.  */
-static inline int
-string_list_member (const string_list_ty *slp, const char *s)
-{
-  size_t j;
-
-  for (j = 0; j < slp->nitems; ++j)
-    if (strcmp (slp->item[j], s) == 0)
-      return 1;
-  return 0;
-}
-
 /* Test whether a sorted string list contains a given string.  */
 static int
 sorted_string_list_member (const string_list_ty *slp, const char *s)
index b37c6f67e4d97b95b4fb070aa03992eb92506421..400aa463a47c504feec3ca508e7340c6d5dc8268 100644 (file)
@@ -2288,6 +2288,10 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
        *final_size = size;
 
        unuse_pack(&w_curs);
+
+       if (delta_stack != small_delta_stack)
+               free(delta_stack);
+
        return data;
 }
 
@@ -2631,12 +2635,7 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
        hash_sha1_file(buf, len, typename(type), sha1);
        if (has_sha1_file(sha1) || find_cached_object(sha1))
                return 0;
-       if (cached_object_alloc <= cached_object_nr) {
-               cached_object_alloc = alloc_nr(cached_object_alloc);
-               cached_objects = xrealloc(cached_objects,
-                                         sizeof(*cached_objects) *
-                                         cached_object_alloc);
-       }
+       ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
        co = &cached_objects[cached_object_nr++];
        co->size = len;
        co->type = type;
index bbc98b55c07969474b0afb01d9c4da70455f1903..0b267b64117c5f1d2df662e3d413418d575a94bd 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -8,9 +8,10 @@
 #include "diff.h"
 #include "revision.h"
 #include "commit-slab.h"
+#include "sigchain.h"
 
 static int is_shallow = -1;
-static struct stat shallow_stat;
+static struct stat_validity shallow_stat;
 static char *alternate_shallow_file;
 
 void set_alternate_shallow_file(const char *path, int override)
@@ -52,12 +53,12 @@ int is_repository_shallow(void)
         * shallow file should be used. We could just open it and it
         * will likely fail. But let's do an explicit check instead.
         */
-       if (!*path ||
-           stat(path, &shallow_stat) ||
-           (fp = fopen(path, "r")) == NULL) {
+       if (!*path || (fp = fopen(path, "r")) == NULL) {
+               stat_validity_clear(&shallow_stat);
                is_shallow = 0;
                return is_shallow;
        }
+       stat_validity_update(&shallow_stat, fileno(fp));
        is_shallow = 1;
 
        while (fgets(buf, sizeof(buf), fp)) {
@@ -137,21 +138,11 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
 
 void check_shallow_file_for_update(void)
 {
-       struct stat st;
-
-       if (!is_shallow)
-               return;
-       else if (is_shallow == -1)
+       if (is_shallow == -1)
                die("BUG: shallow must be initialized by now");
 
-       if (stat(git_path("shallow"), &st))
-               die("shallow file was removed during fetch");
-       else if (st.st_mtime != shallow_stat.st_mtime
-#ifdef USE_NSEC
-                || ST_MTIME_NSEC(st) != ST_MTIME_NSEC(shallow_stat)
-#endif
-                  )
-               die("shallow file was changed during fetch");
+       if (!stat_validity_check(&shallow_stat, git_path("shallow")))
+               die("shallow file has changed since we read it");
 }
 
 #define SEEN_ONLY 1
@@ -216,27 +207,53 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
        return write_shallow_commits_1(out, use_pack_protocol, extra, 0);
 }
 
-char *setup_temporary_shallow(const struct sha1_array *extra)
+static struct strbuf temporary_shallow = STRBUF_INIT;
+
+static void remove_temporary_shallow(void)
+{
+       if (temporary_shallow.len) {
+               unlink_or_warn(temporary_shallow.buf);
+               strbuf_reset(&temporary_shallow);
+       }
+}
+
+static void remove_temporary_shallow_on_signal(int signo)
+{
+       remove_temporary_shallow();
+       sigchain_pop(signo);
+       raise(signo);
+}
+
+const char *setup_temporary_shallow(const struct sha1_array *extra)
 {
+       static int installed_handler;
        struct strbuf sb = STRBUF_INIT;
        int fd;
 
+       if (temporary_shallow.len)
+               die("BUG: attempt to create two temporary shallow files");
+
        if (write_shallow_commits(&sb, 0, extra)) {
-               struct strbuf path = STRBUF_INIT;
-               strbuf_addstr(&path, git_path("shallow_XXXXXX"));
-               fd = xmkstemp(path.buf);
+               strbuf_addstr(&temporary_shallow, git_path("shallow_XXXXXX"));
+               fd = xmkstemp(temporary_shallow.buf);
+
+               if (!installed_handler) {
+                       atexit(remove_temporary_shallow);
+                       sigchain_push_common(remove_temporary_shallow_on_signal);
+               }
+
                if (write_in_full(fd, sb.buf, sb.len) != sb.len)
                        die_errno("failed to write to %s",
-                                 path.buf);
+                                 temporary_shallow.buf);
                close(fd);
                strbuf_release(&sb);
-               return strbuf_detach(&path, NULL);
+               return temporary_shallow.buf;
        }
        /*
         * is_repository_shallow() sees empty string as "no shallow
         * file".
         */
-       return xstrdup("");
+       return temporary_shallow.buf;
 }
 
 void setup_alternate_shallow(struct lock_file *shallow_lock,
@@ -246,9 +263,9 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,
        struct strbuf sb = STRBUF_INIT;
        int fd;
 
-       check_shallow_file_for_update();
        fd = hold_lock_file_for_update(shallow_lock, git_path("shallow"),
                                       LOCK_DIE_ON_ERROR);
+       check_shallow_file_for_update();
        if (write_shallow_commits(&sb, 0, extra)) {
                if (write_in_full(fd, sb.buf, sb.len) != sb.len)
                        die_errno("failed to write to %s",
@@ -293,9 +310,9 @@ void prune_shallow(int show_only)
                strbuf_release(&sb);
                return;
        }
-       check_shallow_file_for_update();
        fd = hold_lock_file_for_update(&shallow_lock, git_path("shallow"),
                                       LOCK_DIE_ON_ERROR);
+       check_shallow_file_for_update();
        if (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) {
                if (write_in_full(fd, sb.buf, sb.len) != sb.len)
                        die_errno("failed to write to %s",
index 9a2dca506a8d6c15f52e6ded3aa22a0f08f507a1..51845491bb42ee72a1f7ec33c504e65c5bf8b248 100644 (file)
@@ -1,6 +1,20 @@
 # Helpers for terminal output tests.
 
-test_expect_success PERL 'set up terminal for tests' '
+# Catch tests which should depend on TTY but forgot to. There's no need
+# to aditionally check that the TTY prereq is set here.  If the test declared
+# it and we are running the test, then it must have been set.
+test_terminal () {
+       if ! test_declared_prereq TTY
+       then
+               echo >&4 "test_terminal: need to declare TTY prerequisite"
+               return 127
+       fi
+       perl "$TEST_DIRECTORY"/test-terminal.perl "$@"
+}
+
+test_lazy_prereq TTY '
+       test_have_prereq PERL &&
+
        # Reading from the pty master seems to get stuck _sometimes_
        # on Mac OS X 10.5.0, using Perl 5.10.0 or 5.8.9.
        #
@@ -15,21 +29,8 @@ test_expect_success PERL 'set up terminal for tests' '
        # After 2000 iterations or so it hangs.
        # https://rt.cpan.org/Ticket/Display.html?id=65692
        #
-       if test "$(uname -s)" = Darwin
-       then
-               :
-       elif
-               perl "$TEST_DIRECTORY"/test-terminal.perl \
-                       sh -c "test -t 1 && test -t 2"
-       then
-               test_set_prereq TTY &&
-               test_terminal () {
-                       if ! test_declared_prereq TTY
-                       then
-                               echo >&4 "test_terminal: need to declare TTY prerequisite"
-                               return 127
-                       fi
-                       perl "$TEST_DIRECTORY"/test-terminal.perl "$@"
-               }
-       fi
+       test "$(uname -s)" != Darwin &&
+
+       perl "$TEST_DIRECTORY"/test-terminal.perl \
+               sh -c "test -t 1 && test -t 2"
 '
index 1e2945ec7e397cf6b2e3b00bee0ca1df40a0e6a9..6902320e819651553beac7d80971b984b9168a8a 100755 (executable)
@@ -148,7 +148,7 @@ test_expect_success 'GIT_PREFIX for built-ins' '
        (
                cd dir &&
                printf "change" >two &&
-               env GIT_EXTERNAL_DIFF=./diff git diff >../actual
+               GIT_EXTERNAL_DIFF=./diff git diff >../actual
                git checkout -- two
        ) &&
        test_cmp expect actual
index fcdb867748f3c651fdb58c148016f3da1cf2c9be..83037b1cd94046ea1ec82819b7d30790b28634d2 100755 (executable)
@@ -507,6 +507,16 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
+       git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
+       cat >expected <<-\EOF &&
+       warning: Not setting branch my13 as its own upstream.
+       EOF
+       test_expect_code 1 git config branch.my13.remote &&
+       test_expect_code 1 git config branch.my13.merge &&
+       test_i18ncmp expected actual
+'
+
 # Keep this test last, as it changes the current branch
 cat >expect <<EOF
 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000        branch: Created from master
index 1afa0d5c44e00a401cb32ec4bca13c4c6882fd07..75d6b3843ad4070f225e82aec160eca494ab6238 100755 (executable)
@@ -86,7 +86,7 @@ test_expect_success 'setup: two scripts for reading pull requests' '
        s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
        s/        [^ ].*/        SUBJECT/g
        s/  [^ ].* (DATE)/  SUBJECT (DATE)/g
-       s/for-upstream/BRANCH/g
+       s|tags/full|BRANCH|g
        s/mnemonic.txt/FILENAME/g
        s/^version [0-9]/VERSION/
        /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
@@ -127,7 +127,7 @@ test_expect_success 'pull request when forgot to push' '
                test_must_fail git request-pull initial "$downstream_url" \
                        2>../err
        ) &&
-       grep "No branch of.*is at:\$" err &&
+       grep "No match for commit .*" err &&
        grep "Are you sure you pushed" err
 
 '
@@ -141,7 +141,7 @@ test_expect_success 'pull request after push' '
                git checkout initial &&
                git merge --ff-only master &&
                git push origin master:for-upstream &&
-               git request-pull initial origin >../request
+               git request-pull initial origin master:for-upstream >../request
        ) &&
        sed -nf read-request.sed <request >digest &&
        cat digest &&
@@ -160,7 +160,7 @@ test_expect_success 'pull request after push' '
 
 '
 
-test_expect_success 'request names an appropriate branch' '
+test_expect_success 'request asks HEAD to be pulled' '
 
        rm -fr downstream.git &&
        git init --bare downstream.git &&
@@ -179,7 +179,7 @@ test_expect_success 'request names an appropriate branch' '
                read repository &&
                read branch
        } <digest &&
-       test "$branch" = tags/full
+       test -z "$branch"
 
 '
 
@@ -212,12 +212,18 @@ test_expect_success 'pull request format' '
                cd local &&
                git checkout initial &&
                git merge --ff-only master &&
-               git push origin master:for-upstream &&
-               git request-pull initial "$downstream_url" >../request
+               git push origin tags/full &&
+               git request-pull initial "$downstream_url" tags/full >../request
        ) &&
        <request sed -nf fuzz.sed >request.fuzzy &&
-       test_i18ncmp expect request.fuzzy
+       test_i18ncmp expect request.fuzzy &&
 
+       (
+               cd local &&
+               git request-pull initial "$downstream_url" tags/full:refs/tags/full
+       ) >request &&
+       sed -nf fuzz.sed <request >request.fuzzy &&
+       test_i18ncmp expect request.fuzzy
 '
 
 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
@@ -229,7 +235,7 @@ test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
                git checkout initial &&
                git merge --ff-only master &&
                git push origin master:for-upstream &&
-               git request-pull -- initial "$downstream_url" >../request
+               git request-pull -- initial "$downstream_url" master:for-upstream >../request
        )
 
 '
index d3a3afaba821f8b70c5f365f1046ba7a707e5085..f13525caa309e48ab32f89066a3e9661dfc25e09 100755 (executable)
@@ -91,7 +91,10 @@ test_expect_success 'fetch (partial bitmap)' '
 
 test_expect_success 'incremental repack cannot create bitmaps' '
        test_commit more-1 &&
-       test_must_fail git repack -d
+       find .git/objects/pack -name "*.bitmap" >expect &&
+       git repack -d &&
+       find .git/objects/pack -name "*.bitmap" >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success 'incremental repack can disable bitmaps' '
index ab28594c62dd7cddc69d3afdb075b48c34091c45..5acd753dcff6b8a0e908b82dc86295a7727fb4b4 100755 (executable)
@@ -301,7 +301,7 @@ test_expect_success 'fetch via rsync' '
        mkdir rsynced &&
        (cd rsynced &&
         git init --bare &&
-        git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
+        git fetch "rsync:../.git" master:refs/heads/master &&
         git gc --prune &&
         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
         git fsck --full)
@@ -312,7 +312,7 @@ test_expect_success 'push via rsync' '
        (cd rsynced2 &&
         git init) &&
        (cd rsynced &&
-        git push "rsync:$(pwd)/../rsynced2/.git" master) &&
+        git push "rsync:../rsynced2/.git" master) &&
        (cd rsynced2 &&
         git gc --prune &&
         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
@@ -323,7 +323,7 @@ test_expect_success 'push via rsync' '
        mkdir rsynced3 &&
        (cd rsynced3 &&
         git init) &&
-       git push --all "rsync:$(pwd)/rsynced3/.git" &&
+       git push --all "rsync:rsynced3/.git" &&
        (cd rsynced3 &&
         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
         git fsck --full)
diff --git a/t/t5529-push-errors.sh b/t/t5529-push-errors.sh
new file mode 100755 (executable)
index 0000000..9871307
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+test_description='detect some push errors early (before contacting remote)'
+. ./test-lib.sh
+
+test_expect_success 'setup commits' '
+       test_commit one
+'
+
+test_expect_success 'setup remote' '
+       git init --bare remote.git &&
+       git remote add origin remote.git
+'
+
+test_expect_success 'setup fake receive-pack' '
+       FAKE_RP_ROOT=$(pwd) &&
+       export FAKE_RP_ROOT &&
+       write_script fake-rp <<-\EOF &&
+       echo yes >"$FAKE_RP_ROOT"/rp-ran
+       exit 1
+       EOF
+       git config remote.origin.receivepack "\"\$FAKE_RP_ROOT/fake-rp\""
+'
+
+test_expect_success 'detect missing branches early' '
+       echo no >rp-ran &&
+       echo no >expect &&
+       test_must_fail git push origin missing &&
+       test_cmp expect rp-ran
+'
+
+test_expect_success 'detect missing sha1 expressions early' '
+       echo no >rp-ran &&
+       echo no >expect &&
+       test_must_fail git push origin master~2:master &&
+       test_cmp expect rp-ran
+'
+
+test_expect_success 'detect ambiguous refs early' '
+       git branch foo &&
+       git tag foo &&
+       echo no >rp-ran &&
+       echo no >expect &&
+       test_must_fail git push origin foo &&
+       test_cmp expect rp-ran
+'
+
+test_done
index 3ae9092f5c2511e075c1bf6c215ea773f738f1f9..be951a46797c6b88d2a8d420cf160ea4f3ad71b0 100755 (executable)
@@ -173,4 +173,45 @@ EOF
        )
 '
 
+if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then
+       say 'skipping remaining tests, git built without http support'
+       test_done
+fi
+
+LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5537'}
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+test_expect_success 'clone http repository' '
+       git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+       git clone $HTTPD_URL/smart/repo.git clone &&
+       (
+       cd clone &&
+       git fsck &&
+       git log --format=%s origin/master >actual &&
+       cat <<EOF >expect &&
+7
+6
+5
+4
+3
+EOF
+       test_cmp expect actual
+       )
+'
+
+test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
+       cp -R .git read-only.git &&
+       find read-only.git -print | xargs chmod -w &&
+       test_when_finished "find read-only.git -type d -print | xargs chmod +w" &&
+       git clone --no-local --depth=2 read-only.git from-read-only &&
+       git --git-dir=from-read-only/.git log --format=%s >actual &&
+       cat >expect <<EOF &&
+add-1-back
+4
+EOF
+       test_cmp expect actual
+'
+
+stop_httpd
 test_done
index 613f69a254bab23e1f09126b4a7f3dca8692deaa..c33cc25805d2a913725355a183118a0dd5547800 100755 (executable)
@@ -94,6 +94,19 @@ test_expect_failure 'push new branch with old:new refspec' '
        compare_refs local HEAD server refs/heads/new-refspec
 '
 
+test_expect_success 'forced push' '
+       (cd local &&
+       git checkout -b force-test &&
+       echo content >> file &&
+       git commit -a -m eight &&
+       git push origin force-test &&
+       echo content >> file &&
+       git commit -a --amend -m eight-modified &&
+       git push --force origin force-test
+       ) &&
+       compare_refs local refs/heads/force-test server refs/heads/force-test
+'
+
 test_expect_success 'cloning without refspec' '
        GIT_REMOTE_TESTGIT_REFSPEC="" \
        git clone "testgit::${PWD}/server" local2 2>error &&
index e3c8c2c1b8817acd85866470c6f76c4a4f8d17d7..215d43d6a6c8ce7f2b30e32dce6dfe34adc98b15 100755 (executable)
@@ -294,7 +294,8 @@ test_expect_success 'setup submodule' '
        git submodule add ./. sub &&
        echo content >file &&
        git add file &&
-       git commit -m "added sub and file"
+       git commit -m "added sub and file" &&
+       git branch submodule
 '
 
 test_expect_success 'git mv cannot move a submodule in a file' '
@@ -463,4 +464,14 @@ test_expect_success 'checking out a commit before submodule moved needs manual u
        ! test -s actual
 '
 
+test_expect_success 'mv -k does not accidentally destroy submodules' '
+       git checkout submodule &&
+       mkdir dummy dest &&
+       git mv -k dummy sub dest &&
+       git status --porcelain >actual &&
+       grep "^R  sub -> dest/sub" actual &&
+       git reset --hard &&
+       git checkout .
+'
+
 test_done
index c8d6e9f88cc36f7e6a1208721ea6c45991452b9e..143a8ea60507a35bbdfb310eb74a33cf5b88bf1f 100755 (executable)
@@ -1380,4 +1380,47 @@ test_expect_success 'multiple --points-at are OR-ed together' '
        test_cmp expect actual
 '
 
+test_expect_success 'lexical sort' '
+       git tag foo1.3 &&
+       git tag foo1.6 &&
+       git tag foo1.10 &&
+       git tag -l --sort=refname "foo*" >actual &&
+       cat >expect <<EOF &&
+foo1.10
+foo1.3
+foo1.6
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'version sort' '
+       git tag -l --sort=version:refname "foo*" >actual &&
+       cat >expect <<EOF &&
+foo1.3
+foo1.6
+foo1.10
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'reverse version sort' '
+       git tag -l --sort=-version:refname "foo*" >actual &&
+       cat >expect <<EOF &&
+foo1.10
+foo1.6
+foo1.3
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'reverse lexical sort' '
+       git tag -l --sort=-refname "foo*" >actual &&
+       cat >expect <<EOF &&
+foo1.6
+foo1.3
+foo1.10
+EOF
+       test_cmp expect actual
+'
+
 test_done
index 7d467c034a27f50e8b60b4b0f390f08fdf126e55..741ec085767c9469f8ba15408af37cd558df1559 100755 (executable)
@@ -38,7 +38,7 @@ You have unmerged paths.
 Unmerged paths:
   (use "git add/rm <file>..." as appropriate to mark resolution)
 
-       deleted by us:      foo
+       deleted by us:   foo
 
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
@@ -142,8 +142,8 @@ You have unmerged paths.
 Unmerged paths:
   (use "git add/rm <file>..." as appropriate to mark resolution)
 
-       both added:         conflict.txt
-       deleted by them:    main.txt
+       both added:      conflict.txt
+       deleted by them: main.txt
 
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
@@ -175,9 +175,9 @@ You have unmerged paths.
 Unmerged paths:
   (use "git add/rm <file>..." as appropriate to mark resolution)
 
-       both deleted:       main.txt
-       added by them:      sub_master.txt
-       added by us:        sub_second.txt
+       both deleted:    main.txt
+       added by them:   sub_master.txt
+       added by us:     sub_second.txt
 
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
@@ -203,7 +203,7 @@ Changes to be committed:
 Unmerged paths:
   (use "git rm <file>..." to mark resolution)
 
-       both deleted:       main.txt
+       both deleted:    main.txt
 
 Untracked files not listed (use -u option to show untracked files)
 EOF
index 710be90489b2fd5d6ca1a98201c1ec635efcae9f..74de814aec1465848ba316e867106a18635139f6 100755 (executable)
@@ -511,4 +511,20 @@ test_expect_success SANITY 'git clean -d with an unreadable empty directory' '
        ! test -d foo
 '
 
+test_expect_success 'git clean -d respects pathspecs (dir is prefix of pathspec)' '
+       mkdir -p foo &&
+       mkdir -p foobar &&
+       git clean -df foobar &&
+       test_path_is_dir foo &&
+       test_path_is_missing foobar
+'
+
+test_expect_success 'git clean -d respects pathspecs (pathspec is prefix of dir)' '
+       mkdir -p foo &&
+       mkdir -p foobar &&
+       git clean -df foo &&
+       test_path_is_missing foo &&
+       test_path_is_dir foobar
+'
+
 test_done
index 94eec83b37f38699af91b3808051515f267f3a5f..d58b097ff3b3d0e6e68d15491d38f1f32460f6e7 100755 (executable)
@@ -61,11 +61,47 @@ test_expect_success 'nothing to commit' '
        test_must_fail git commit -m initial
 '
 
+test_expect_success '--dry-run fails with nothing to commit' '
+       test_must_fail git commit -m initial --dry-run
+'
+
+test_expect_success '--short fails with nothing to commit' '
+       test_must_fail git commit -m initial --short
+'
+
+test_expect_success '--porcelain fails with nothing to commit' '
+       test_must_fail git commit -m initial --porcelain
+'
+
+test_expect_success '--long fails with nothing to commit' '
+       test_must_fail git commit -m initial --long
+'
+
 test_expect_success 'setup: non-initial commit' '
        echo bongo bongo bongo >file &&
        git commit -m next -a
 '
 
+test_expect_success '--dry-run with stuff to commit returns ok' '
+       echo bongo bongo bongo >>file &&
+       git commit -m next -a --dry-run
+'
+
+test_expect_failure '--short with stuff to commit returns ok' '
+       echo bongo bongo bongo >>file &&
+       git commit -m next -a --short
+'
+
+test_expect_failure '--porcelain with stuff to commit returns ok' '
+       echo bongo bongo bongo >>file &&
+       git commit -m next -a --porcelain
+'
+
+test_expect_success '--long with stuff to commit returns ok' '
+       echo bongo bongo bongo >>file &&
+       git commit -m next -a --long
+'
+
 test_expect_success 'commit message from non-existing file' '
        echo more bongo: bongo bongo bongo bongo >file &&
        test_must_fail git commit -F gah -a
index 6313da2cdd979c6264e7a255711c6e444b768b96..9a3f3a1b4151ebf16cfd773a0f9efcb1b61d40d7 100755 (executable)
@@ -223,6 +223,22 @@ test_expect_success 'cleanup commit messages (whitespace option,-F)' '
 
 '
 
+test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
+
+       echo >>negative &&
+       cat >text <<EOF &&
+
+# to be kept
+# ------------------------ >8 ------------------------
+to be removed
+EOF
+       echo "# to be kept" >expect &&
+       git commit --cleanup=scissors -e -F text -a &&
+       git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
+       test_cmp expect actual
+
+'
+
 test_expect_success 'cleanup commit messages (strip option,-F)' '
 
        echo >>negative &&
index 3cec57af1ee0ca8ccbbbdc47871cd4ff07e0d034..68ad2d7454d6cbc93b5f7109fe836138c95ba684 100755 (executable)
@@ -33,7 +33,7 @@ You have unmerged paths.
 Unmerged paths:
   (use "git add <file>..." to mark resolution)
 
-       both modified:      main.txt
+       both modified:   main.txt
 
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
@@ -87,7 +87,7 @@ Unmerged paths:
   (use "git reset HEAD <file>..." to unstage)
   (use "git add <file>..." to mark resolution)
 
-       both modified:      main.txt
+       both modified:   main.txt
 
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
@@ -146,7 +146,7 @@ Unmerged paths:
   (use "git reset HEAD <file>..." to unstage)
   (use "git add <file>..." to mark resolution)
 
-       both modified:      main.txt
+       both modified:   main.txt
 
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
@@ -602,7 +602,7 @@ rebase in progress; onto $ONTO
 You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
 
 Unmerged paths:
-       both modified:      main.txt
+       both modified:   main.txt
 
 no changes added to commit
 EOF
@@ -636,7 +636,7 @@ You are currently cherry-picking commit $TO_CHERRY_PICK.
 Unmerged paths:
   (use "git add <file>..." to mark resolution)
 
-       both modified:      main.txt
+       both modified:   main.txt
 
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
@@ -707,7 +707,7 @@ Unmerged paths:
   (use "git reset HEAD <file>..." to unstage)
   (use "git add <file>..." to mark resolution)
 
-       both modified:      to-revert.txt
+       both modified:   to-revert.txt
 
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
index b45bd1e76cd24940545706c8f5611adce9b3803e..284018e3cdb31e7db179a93f7196fda47578c43c 100755 (executable)
@@ -21,7 +21,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
        objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
                sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
        mv pack-* .git/objects/pack/ &&
-       git repack -A -d -l &&
+       git repack --no-pack-kept-objects -A -d -l &&
        git prune-packed &&
        for p in .git/objects/pack/*.idx; do
                idx=$(basename $p)
@@ -35,6 +35,22 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
        test -z "$found_duplicate_object"
 '
 
+test_expect_success 'writing bitmaps can duplicate .keep objects' '
+       # build on $objsha1, $packsha1, and .keep state from previous
+       git repack -Adl &&
+       test_when_finished "found_duplicate_object=" &&
+       for p in .git/objects/pack/*.idx; do
+               idx=$(basename $p)
+               test "pack-$packsha1.idx" = "$idx" && continue
+               if git verify-pack -v $p | egrep "^$objsha1"; then
+                       found_duplicate_object=1
+                       echo "DUPLICATE OBJECT FOUND"
+                       break
+               fi
+       done &&
+       test "$found_duplicate_object" = 1
+'
+
 test_expect_success 'loose objects in alternate ODB are not repacked' '
        mkdir alt_objects &&
        echo `pwd`/alt_objects > .git/objects/info/alternates &&
index f698001c996ea20847c574f04dad9a65684f324f..63b303924307ad3a1d0658ec3b69a3ebf9e5670e 100755 (executable)
@@ -105,7 +105,7 @@ do
 
        test_expect_success "grep -w $L (w)" '
                : >expected &&
-               test_must_fail git grep -n -w -e "^w" >actual &&
+               test_must_fail git grep -n -w -e "^w" $H >actual &&
                test_cmp expected actual
        '
 
@@ -240,92 +240,104 @@ do
                test_cmp expected actual
        '
        test_expect_success "grep $L with grep.extendedRegexp=false" '
-               echo "ab:a+bc" >expected &&
-               git -c grep.extendedRegexp=false grep "a+b*c" ab >actual &&
+               echo "${HC}ab:a+bc" >expected &&
+               git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L with grep.extendedRegexp=true" '
-               echo "ab:abc" >expected &&
-               git -c grep.extendedRegexp=true grep "a+b*c" ab >actual &&
+               echo "${HC}ab:abc" >expected &&
+               git -c grep.extendedRegexp=true grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L with grep.patterntype=basic" '
-               echo "ab:a+bc" >expected &&
-               git -c grep.patterntype=basic grep "a+b*c" ab >actual &&
+               echo "${HC}ab:a+bc" >expected &&
+               git -c grep.patterntype=basic grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L with grep.patterntype=extended" '
-               echo "ab:abc" >expected &&
-               git -c grep.patterntype=extended grep "a+b*c" ab >actual &&
+               echo "${HC}ab:abc" >expected &&
+               git -c grep.patterntype=extended grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L with grep.patterntype=fixed" '
-               echo "ab:a+b*c" >expected &&
-               git -c grep.patterntype=fixed grep "a+b*c" ab >actual &&
+               echo "${HC}ab:a+b*c" >expected &&
+               git -c grep.patterntype=fixed grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
        test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" '
-               echo "ab:a+b*c" >expected &&
-               git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" ab >actual &&
+               echo "${HC}ab:a+b*c" >expected &&
+               git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" $H ab >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" '
-               echo "ab:abc" >expected &&
+               echo "${HC}ab:abc" >expected &&
                git \
                        -c grep.patternType=default \
                        -c grep.extendedRegexp=true \
-                       grep "a+b*c" ab >actual &&
+                       grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" '
-               echo "ab:abc" >expected &&
+               echo "${HC}ab:abc" >expected &&
                git \
                        -c grep.extendedRegexp=true \
                        -c grep.patternType=default \
-                       grep "a+b*c" ab >actual &&
+                       grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
-       test_expect_success 'grep $L with grep.patternType=extended and grep.extendedRegexp=false' '
-               echo "ab:abc" >expected &&
+       test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" '
+               echo "${HC}ab:abc" >expected &&
                git \
                        -c grep.patternType=extended \
                        -c grep.extendedRegexp=false \
-                       grep "a+b*c" ab >actual &&
+                       grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
-       test_expect_success 'grep $L with grep.patternType=basic and grep.extendedRegexp=true' '
-               echo "ab:a+bc" >expected &&
+       test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" '
+               echo "${HC}ab:a+bc" >expected &&
                git \
                        -c grep.patternType=basic \
                        -c grep.extendedRegexp=true \
-                       grep "a+b*c" ab >actual &&
+                       grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
-       test_expect_success 'grep $L with grep.extendedRegexp=false and grep.patternType=extended' '
-               echo "ab:abc" >expected &&
+       test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=extended" '
+               echo "${HC}ab:abc" >expected &&
                git \
                        -c grep.extendedRegexp=false \
                        -c grep.patternType=extended \
-                       grep "a+b*c" ab >actual &&
+                       grep "a+b*c" $H ab >actual &&
                test_cmp expected actual
        '
 
-       test_expect_success 'grep $L with grep.extendedRegexp=true and grep.patternType=basic' '
-               echo "ab:a+bc" >expected &&
+       test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" '
+               echo "${HC}ab:a+bc" >expected &&
                git \
                        -c grep.extendedRegexp=true \
                        -c grep.patternType=basic \
-                       grep "a+b*c" ab >actual &&
+                       grep "a+b*c" $H ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep --count $L" '
+               echo ${HC}ab:3 >expected &&
+               git grep --count -e b $H -- ab >actual &&
+               test_cmp expected actual
+       '
+
+       test_expect_success "grep --count -h $L" '
+               echo 3 >expected &&
+               git grep --count -h -e b $H -- ab >actual &&
                test_cmp expected actual
        '
 done
index 3119c8c523168922d42448ffbd1ee4c9647b0567..1ecdacb6fd0ceb7e43e6ec3bad018e7b6dc8100b 100755 (executable)
@@ -409,7 +409,7 @@ test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
        (echo "From Example <from@example.com>"
         echo "To Example <to@example.com>"
         echo ""
-       ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
+       ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
                --smtp-server="$(pwd)/fake.sendmail" \
                $patches 2>errors &&
        ! grep "^In-Reply-To: < *>" msgtxt1
index 569b52dc0fa32f48f37dc0d29771118cc624c5e7..87f327ff8bcd2c2a29fcbabe74c226232b54f728 100644 (file)
@@ -283,7 +283,7 @@ error "Test script did not set test_description."
 
 if test "$help" = "t"
 then
-       echo "$test_description"
+       printf '%s\n' "$test_description"
        exit 0
 fi
 
@@ -334,7 +334,7 @@ test_failure_ () {
        test_failure=$(($test_failure + 1))
        say_color error "not ok $test_count - $1"
        shift
-       echo "$@" | sed -e 's/^/#       /'
+       printf '%s\n' "$*" | sed -e 's/^/#      /'
        test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
 }
 
index ad72fbd53cb7bfc7fc037d98288b0cc831ea949a..86e1679c1e0e1e58ebe5297f4c5f48ca1a1f6418 100644 (file)
@@ -650,7 +650,7 @@ static int push_update_ref_status(struct strbuf *buf,
                                   struct ref *remote_refs)
 {
        char *refname, *msg;
-       int status;
+       int status, forced = 0;
 
        if (starts_with(buf->buf, "ok ")) {
                status = REF_STATUS_OK;
@@ -708,6 +708,11 @@ static int push_update_ref_status(struct strbuf *buf,
                        free(msg);
                        msg = NULL;
                }
+               else if (!strcmp(msg, "forced update")) {
+                       forced = 1;
+                       free(msg);
+                       msg = NULL;
+               }
        }
 
        if (*ref)
@@ -729,12 +734,14 @@ static int push_update_ref_status(struct strbuf *buf,
        }
 
        (*ref)->status = status;
+       (*ref)->forced_update |= forced;
        (*ref)->remote_status = msg;
        return !(status == REF_STATUS_OK);
 }
 
 static void push_update_refs_status(struct helper_data *data,
-                                   struct ref *remote_refs)
+                                   struct ref *remote_refs,
+                                   int flags)
 {
        struct strbuf buf = STRBUF_INIT;
        struct ref *ref = remote_refs;
@@ -748,7 +755,7 @@ static void push_update_refs_status(struct helper_data *data,
                if (push_update_ref_status(&buf, &ref, remote_refs))
                        continue;
 
-               if (!data->refspecs || data->no_private_update)
+               if (flags & TRANSPORT_PUSH_DRY_RUN || !data->refspecs || data->no_private_update)
                        continue;
 
                /* propagate back the update to the remote namespace */
@@ -839,7 +846,7 @@ static int push_refs_with_push(struct transport *transport,
        sendline(data, &buf);
        strbuf_release(&buf);
 
-       push_update_refs_status(data, remote_refs);
+       push_update_refs_status(data, remote_refs, flags);
        return 0;
 }
 
@@ -860,6 +867,11 @@ static int push_refs_with_export(struct transport *transport,
                        die("helper %s does not support dry-run", data->name);
        }
 
+       if (flags & TRANSPORT_PUSH_FORCE) {
+               if (set_helper_option(transport, "force", "true") != 0)
+                       warning("helper %s does not support 'force'", data->name);
+       }
+
        helper = get_helper(transport);
 
        write_constant(helper->in, "export\n");
@@ -881,9 +893,6 @@ static int push_refs_with_export(struct transport *transport,
                }
                free(private);
 
-               if (ref->deletion)
-                       die("remote-helpers do not support ref deletion");
-
                if (ref->peer_ref) {
                        if (strcmp(ref->peer_ref->name, ref->name))
                                die("remote-helpers do not support old:new syntax");
@@ -896,7 +905,7 @@ static int push_refs_with_export(struct transport *transport,
 
        if (finish_command(&exporter))
                die("Error while running fast-export");
-       push_update_refs_status(data, remote_refs);
+       push_update_refs_status(data, remote_refs, flags);
        return 0;
 }
 
index ca7bb441bf503c598d9679b338d7f7c0d8103cb0..325f03e1eef97df296bb1cc9f7d2d33c218dde26 100644 (file)
@@ -1132,8 +1132,7 @@ int transport_push(struct transport *transport,
 
                return transport->push(transport, refspec_nr, refspec, flags);
        } else if (transport->push_refs) {
-               struct ref *remote_refs =
-                       transport->get_refs_list(transport, 1);
+               struct ref *remote_refs;
                struct ref *local_refs = get_local_heads();
                int match_flags = MATCH_REFS_NONE;
                int verbose = (transport->verbose > 0);
@@ -1142,6 +1141,11 @@ int transport_push(struct transport *transport,
                int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
                int push_ret, ret, err;
 
+               if (check_push_refs(local_refs, refspec_nr, refspec) < 0)
+                       return -1;
+
+               remote_refs = transport->get_refs_list(transport, 1);
+
                if (flags & TRANSPORT_PUSH_ALL)
                        match_flags |= MATCH_REFS_ALL;
                if (flags & TRANSPORT_PUSH_MIRROR)
index 9314c250ffd72ef44dd6b675e0f3592e3e283a04..286a9ed3ea960d07c267f5e2992e63589361f5e9 100644 (file)
@@ -70,6 +70,14 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
        return sz;
 }
 
+static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
+{
+       FILE *fp = cb_data;
+       if (graft->nr_parent == -1)
+               fprintf(fp, "--shallow %s\n", sha1_to_hex(graft->sha1));
+       return 0;
+}
+
 static void create_pack_file(void)
 {
        struct child_process pack_objects;
@@ -81,12 +89,10 @@ static void create_pack_file(void)
        const char *argv[12];
        int i, arg = 0;
        FILE *pipe_fd;
-       char *shallow_file = NULL;
 
        if (shallow_nr) {
-               shallow_file = setup_temporary_shallow(NULL);
                argv[arg++] = "--shallow-file";
-               argv[arg++] = shallow_file;
+               argv[arg++] = "";
        }
        argv[arg++] = "pack-objects";
        argv[arg++] = "--revs";
@@ -114,6 +120,9 @@ static void create_pack_file(void)
 
        pipe_fd = xfdopen(pack_objects.in, "w");
 
+       if (shallow_nr)
+               for_each_commit_graft(write_one_shallow, pipe_fd);
+
        for (i = 0; i < want_obj.nr; i++)
                fprintf(pipe_fd, "%s\n",
                        sha1_to_hex(want_obj.objects[i].item->sha1));
@@ -242,11 +251,6 @@ static void create_pack_file(void)
                error("git upload-pack: git-pack-objects died with error.");
                goto fail;
        }
-       if (shallow_file) {
-               if (*shallow_file)
-                       unlink(shallow_file);
-               free(shallow_file);
-       }
 
        /* flush the data */
        if (0 <= buffered) {
diff --git a/versioncmp.c b/versioncmp.c
new file mode 100644 (file)
index 0000000..7511e08
--- /dev/null
@@ -0,0 +1,93 @@
+#include "cache.h"
+
+/*
+ * versioncmp(): copied from string/strverscmp.c in glibc commit
+ * ee9247c38a8def24a59eb5cfb7196a98bef8cfdc, reformatted to Git coding
+ * style. The implementation is under LGPL-2.1 and Git relicenses it
+ * to GPLv2.
+ */
+
+/*
+ * states: S_N: normal, S_I: comparing integral part, S_F: comparing
+ * fractionnal parts, S_Z: idem but with leading Zeroes only
+ */
+#define  S_N    0x0
+#define  S_I    0x3
+#define  S_F    0x6
+#define  S_Z    0x9
+
+/* result_type: CMP: return diff; LEN: compare using len_diff/diff */
+#define  CMP    2
+#define  LEN    3
+
+
+/*
+ * Compare S1 and S2 as strings holding indices/version numbers,
+ * returning less than, equal to or greater than zero if S1 is less
+ * than, equal to or greater than S2 (for more info, see the texinfo
+ * doc).
+ */
+
+int versioncmp(const char *s1, const char *s2)
+{
+       const unsigned char *p1 = (const unsigned char *) s1;
+       const unsigned char *p2 = (const unsigned char *) s2;
+       unsigned char c1, c2;
+       int state, diff;
+
+       /*
+        * Symbol(s)    0       [1-9]   others
+        * Transition   (10) 0  (01) d  (00) x
+        */
+       static const uint8_t next_state[] = {
+               /* state    x    d    0  */
+               /* S_N */  S_N, S_I, S_Z,
+               /* S_I */  S_N, S_I, S_I,
+               /* S_F */  S_N, S_F, S_F,
+               /* S_Z */  S_N, S_F, S_Z
+       };
+
+       static const int8_t result_type[] = {
+               /* state   x/x  x/d  x/0  d/x  d/d  d/0  0/x  0/d  0/0  */
+
+               /* S_N */  CMP, CMP, CMP, CMP, LEN, CMP, CMP, CMP, CMP,
+               /* S_I */  CMP, -1,  -1,  +1,  LEN, LEN, +1,  LEN, LEN,
+               /* S_F */  CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
+               /* S_Z */  CMP, +1,  +1,  -1,  CMP, CMP, -1,  CMP, CMP
+       };
+
+       if (p1 == p2)
+               return 0;
+
+       c1 = *p1++;
+       c2 = *p2++;
+       /* Hint: '0' is a digit too.  */
+       state = S_N + ((c1 == '0') + (isdigit (c1) != 0));
+
+       while ((diff = c1 - c2) == 0) {
+               if (c1 == '\0')
+                       return diff;
+
+               state = next_state[state];
+               c1 = *p1++;
+               c2 = *p2++;
+               state += (c1 == '0') + (isdigit (c1) != 0);
+       }
+
+       state = result_type[state * 3 + (((c2 == '0') + (isdigit (c2) != 0)))];
+
+       switch (state) {
+       case CMP:
+               return diff;
+
+       case LEN:
+               while (isdigit (*p1++))
+                       if (!isdigit (*p2++))
+                               return 1;
+
+               return isdigit (*p2) ? -1 : diff;
+
+       default:
+               return state;
+       }
+}
diff --git a/ws.c b/ws.c
index b498d7599d5ac09c2688ee829b29aa36a866ac9c..ea4b2b1dfd64ce41f4752a93f4d5478c4e53deda 100644 (file)
--- a/ws.c
+++ b/ws.c
@@ -33,11 +33,8 @@ unsigned parse_whitespace_rule(const char *string)
                int negated = 0;
 
                string = string + strspn(string, ", \t\n\r");
-               ep = strchr(string, ',');
-               if (!ep)
-                       len = strlen(string);
-               else
-                       len = ep - string;
+               ep = strchrnul(string, ',');
+               len = ep - string;
 
                if (*string == '-') {
                        negated = 1;
index a452407dad51940576db64b56d3a56cc7b364835..e1827faf073ce384bea6a697dd903ffc643bdfdc 100644 (file)
@@ -17,7 +17,7 @@
 #include "strbuf.h"
 #include "utf8.h"
 
-static char cut_line[] =
+static const char cut_line[] =
 "------------------------ >8 ------------------------\n";
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
@@ -245,53 +245,92 @@ static void wt_status_print_trailer(struct wt_status *s)
 
 #define quote_path quote_path_relative
 
-static void wt_status_print_unmerged_data(struct wt_status *s,
-                                         struct string_list_item *it)
+static const char *wt_status_unmerged_status_string(int stagemask)
 {
-       const char *c = color(WT_STATUS_UNMERGED, s);
-       struct wt_status_change_data *d = it->util;
-       struct strbuf onebuf = STRBUF_INIT;
-       const char *one, *how = _("bug");
-
-       one = quote_path(it->string, s->prefix, &onebuf);
-       status_printf(s, color(WT_STATUS_HEADER, s), "\t");
-       switch (d->stagemask) {
-       case 1: how = _("both deleted:"); break;
-       case 2: how = _("added by us:"); break;
-       case 3: how = _("deleted by them:"); break;
-       case 4: how = _("added by them:"); break;
-       case 5: how = _("deleted by us:"); break;
-       case 6: how = _("both added:"); break;
-       case 7: how = _("both modified:"); break;
+       switch (stagemask) {
+       case 1:
+               return _("both deleted:");
+       case 2:
+               return _("added by us:");
+       case 3:
+               return _("deleted by them:");
+       case 4:
+               return _("added by them:");
+       case 5:
+               return _("deleted by us:");
+       case 6:
+               return _("both added:");
+       case 7:
+               return _("both modified:");
+       default:
+               die(_("bug: unhandled unmerged status %x"), stagemask);
        }
-       status_printf_more(s, c, "%-20s%s\n", how, one);
-       strbuf_release(&onebuf);
 }
 
 static const char *wt_status_diff_status_string(int status)
 {
        switch (status) {
        case DIFF_STATUS_ADDED:
-               return _("new file");
+               return _("new file:");
        case DIFF_STATUS_COPIED:
-               return _("copied");
+               return _("copied:");
        case DIFF_STATUS_DELETED:
-               return _("deleted");
+               return _("deleted:");
        case DIFF_STATUS_MODIFIED:
-               return _("modified");
+               return _("modified:");
        case DIFF_STATUS_RENAMED:
-               return _("renamed");
+               return _("renamed:");
        case DIFF_STATUS_TYPE_CHANGED:
-               return _("typechange");
+               return _("typechange:");
        case DIFF_STATUS_UNKNOWN:
-               return _("unknown");
+               return _("unknown:");
        case DIFF_STATUS_UNMERGED:
-               return _("unmerged");
+               return _("unmerged:");
        default:
                return NULL;
        }
 }
 
+static int maxwidth(const char *(*label)(int), int minval, int maxval)
+{
+       int result = 0, i;
+
+       for (i = minval; i <= maxval; i++) {
+               const char *s = label(i);
+               int len = s ? utf8_strwidth(s) : 0;
+               if (len > result)
+                       result = len;
+       }
+       return result;
+}
+
+static void wt_status_print_unmerged_data(struct wt_status *s,
+                                         struct string_list_item *it)
+{
+       const char *c = color(WT_STATUS_UNMERGED, s);
+       struct wt_status_change_data *d = it->util;
+       struct strbuf onebuf = STRBUF_INIT;
+       static char *padding;
+       static int label_width;
+       const char *one, *how;
+       int len;
+
+       if (!padding) {
+               label_width = maxwidth(wt_status_unmerged_status_string, 1, 7);
+               label_width += strlen(" ");
+               padding = xmallocz(label_width);
+               memset(padding, ' ', label_width);
+       }
+
+       one = quote_path(it->string, s->prefix, &onebuf);
+       status_printf(s, color(WT_STATUS_HEADER, s), "\t");
+
+       how = wt_status_unmerged_status_string(d->stagemask);
+       len = label_width - utf8_strwidth(how);
+       status_printf_more(s, c, "%s%.*s%s\n", how, len, padding, one);
+       strbuf_release(&onebuf);
+}
+
 static void wt_status_print_change_data(struct wt_status *s,
                                        int change_type,
                                        struct string_list_item *it)
@@ -305,21 +344,16 @@ static void wt_status_print_change_data(struct wt_status *s,
        struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
        struct strbuf extra = STRBUF_INIT;
        static char *padding;
+       static int label_width;
        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);
+               /* If DIFF_STATUS_* uses outside the range [A..Z], we're in trouble */
+               label_width = maxwidth(wt_status_diff_status_string, 'A', 'Z');
+               label_width += strlen(" ");
+               padding = xmallocz(label_width);
+               memset(padding, ' ', label_width);
        }
 
        one_name = two_name = it->string;
@@ -355,14 +389,13 @@ static void wt_status_print_change_data(struct wt_status *s,
        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);
+       len = label_width - utf8_strwidth(what);
        assert(len >= 0);
        if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
-               status_printf_more(s, c, "%s:%.*s%s -> %s",
+               status_printf_more(s, c, "%s%.*s%s -> %s",
                                   what, len, padding, one, two);
        else
-               status_printf_more(s, c, "%s:%.*s%s",
+               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);
@@ -808,6 +841,17 @@ void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
        strbuf_release(&pattern);
 }
 
+void wt_status_add_cut_line(FILE *fp)
+{
+       const char *explanation = _("Do not touch the line above.\nEverything below will be removed.");
+       struct strbuf buf = STRBUF_INIT;
+
+       fprintf(fp, "%c %s", comment_line_char, cut_line);
+       strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
+       fputs(buf.buf, fp);
+       strbuf_release(&buf);
+}
+
 static void wt_status_print_verbose(struct wt_status *s)
 {
        struct rev_info rev;
@@ -833,14 +877,8 @@ static void wt_status_print_verbose(struct wt_status *s)
         * diff before committing.
         */
        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);
+               wt_status_add_cut_line(s->fp);
        }
        run_diff_index(&rev, 1);
 }
index 30a481258366733ad5d6a65e3a9c3ae1ee74e833..b56ce3f0355f3a1e188c7d9bd44ea90f0d06d76f 100644 (file)
@@ -92,6 +92,7 @@ struct wt_status_state {
 };
 
 void wt_status_truncate_message_at_cut_line(struct strbuf *);
+void wt_status_add_cut_line(FILE *fp);
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);