Merge branch 'rj/git-version-gen-do-not-force-abbrev'
authorJunio C Hamano <gitster@pobox.com>
Mon, 19 Dec 2016 22:45:33 +0000 (14:45 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Dec 2016 22:45:33 +0000 (14:45 -0800)
A minor build update.

* rj/git-version-gen-do-not-force-abbrev:
GIT-VERSION-GEN: do not force abbreviation length used by 'describe'

84 files changed:
.travis.yml
Documentation/RelNotes/2.12.0.txt
Documentation/config.txt
Documentation/git-branch.txt
Documentation/git-for-each-ref.txt
Documentation/git-p4.txt
Documentation/git-svn.txt
Documentation/git-tag.txt
bisect.c
branch.c
builtin/branch.c
builtin/clone.c
builtin/commit.c
builtin/fetch.c
builtin/for-each-ref.c
builtin/receive-pack.c
builtin/rev-parse.c
builtin/tag.c
builtin/worktree.c
commit.c
commit.h
compat/mingw.h
compat/winansi.c
convert.c
git-mergetool--lib.sh
git-p4.py
git-stash.sh
http-walker.c
http.c
http.h
merge-recursive.c
mergetools/araxis
mergetools/bc
mergetools/codecompare
mergetools/deltawalker
mergetools/diffmerge
mergetools/diffuse
mergetools/ecmerge
mergetools/emerge
mergetools/examdiff
mergetools/kdiff3
mergetools/kompare
mergetools/meld
mergetools/opendiff
mergetools/p4merge
mergetools/tkdiff
mergetools/tortoisemerge
mergetools/vimdiff
mergetools/winmerge
mergetools/xxdiff
perl/Git/SVN/Ra.pm
ref-filter.c
ref-filter.h
remote-curl.c
sequencer.c
submodule.c
submodule.h
t/lib-httpd/apache.conf
t/t0021-conversion.sh
t/t2027-worktree-list.sh
t/t3030-merge-recursive.sh
t/t3203-branch-output.sh
t/t3426-rebase-submodule.sh
t/t3501-revert-cherry-pick.sh
t/t3511-cherry-pick-x.sh
t/t3903-stash.sh
t/t4014-format-patch.sh
t/t5531-deep-submodule-push.sh
t/t5550-http-fetch-dumb.sh
t/t5551-http-fetch-smart.sh
t/t5812-proto-disable-http.sh
t/t6101-rev-parse-parents.sh
t/t7004-tag.sh
t/t7501-commit.sh
t/t7609-merge-co-error-msgs.sh
t/t7610-mergetool.sh
t/t9807-git-p4-submit.sh
t/t9824-git-p4-git-lfs.sh
trailer.c
trailer.h
transport.c
unpack-trees.c
worktree.c
worktree.h
index 0b2ea5c3e2daa057cb88763f1943f6a250d019d9..3843967a692d1642e43f536d5e2652b566ca554d 100644 (file)
@@ -27,8 +27,8 @@ env:
     # The Linux build installs the defined dependency versions below.
     # The OS X build installs the latest available versions. Keep that
     # in mind when you encounter a broken OS X build!
-    - LINUX_P4_VERSION="16.1"
-    - LINUX_GIT_LFS_VERSION="1.2.0"
+    - LINUX_P4_VERSION="16.2"
+    - LINUX_GIT_LFS_VERSION="1.5.2"
     - DEFAULT_TEST_TARGET=prove
     - GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
     - GIT_TEST_OPTS="--verbose-log"
index 08152d64b93917349fef047f0845c0ce837683ee..01db423a92c0a559efead5f39124ceab4d6a1447 100644 (file)
@@ -20,7 +20,7 @@ Updates since v2.11
 
 UI, Workflows & Features
 
- *
+ * Various updates to "git p4".
 
 
 Performance, Internal Implementation, Development Support etc.
@@ -40,4 +40,47 @@ Unless otherwise noted, all the fixes since v2.9 in the maintenance
 track are contained in this release (see the maintenance releases'
 notes for details).
 
+ * We often decide if a session is interactive by checking if the
+   standard I/O streams are connected to a TTY, but isatty() that
+   comes with Windows incorrectly returned true if it is used on NUL
+   (i.e. an equivalent to /dev/null).  This has been fixed.
+   (merge cbb3f3c9b1 js/mingw-isatty later to maint).
+
+ * "git svn" did not work well with path components that are "0", and
+   some configuration variable it uses were not documented.
+   (merge ea9a93dcc2 ew/svn-fixes later to maint).
+
+ * "git rev-parse --symbolic" failed with a more recent notation like
+   "HEAD^-1" and "HEAD^!".
+   (merge a2e7b04c44 jk/rev-parse-symbolic-parents-fix later to maint).
+
+ * An empty directory in a working tree that can simply be nuked used
+   to interfere while merging or cherry-picking a change to create a
+   submodule directory there, which has been fixed..
+   (merge 5423d2e700 dt/empty-submodule-in-merge later to maint).
+
+ * The code in "git push" to compute if any commit being pushed in the
+   superproject binds a commit in a submodule that hasn't been pushed
+   out was overly inefficient, making it unusable even for a small
+   project that does not have any submodule but have a reasonable
+   number of refs.
+   (merge 250ab24ab3 hv/submodule-not-yet-pushed-fix later to maint).
+
+ * "git push --dry-run --recurse-submodule=on-demand" wasn't
+   "--dry-run" in the submodules.
+   (merge 0301c821c5 bw/push-dry-run later to maint).
+
+ * The output from "git worktree list" was made in readdir() order,
+   and was unstable.
+   (merge 4df1d4d466 nd/worktree-list-fixup later to maint).
+
+ * mergetool.<tool>.trustExitCode configuration variable did not apply
+   to built-in tools, but now it does.
+   (merge 2967284456 da/mergetool-trust-exit-code later to maint).
+
+ * "git p4" LFS support was broken when LFS stores an empty blob.
+   (merge d5eb3cf5e7 ls/p4-empty-file-on-lfs later to maint).
+
  * Other minor doc, test and build updates and code cleanups.
+   (merge fa6ca11105 nd/qsort-in-merge-recursive later to maint).
+   (merge fa3142c919 ak/lazy-prereq-mktemp later to maint).
index a0ab66aae70db90bd18e14ec5bc5c95007b118f7..d51182a0606aa30168d640d2d821a3ec1bc2458d 100644 (file)
@@ -1891,6 +1891,16 @@ http.userAgent::
        of common USER_AGENT strings (but not including those like git/1.7.1).
        Can be overridden by the `GIT_HTTP_USER_AGENT` environment variable.
 
+http.followRedirects::
+       Whether git should follow HTTP redirects. If set to `true`, git
+       will transparently follow any redirect issued by a server it
+       encounters. If set to `false`, git will treat all redirects as
+       errors. If set to `initial`, git will follow redirects only for
+       the initial request to a remote, but not for subsequent
+       follow-up HTTP requests. Since git uses the redirected URL as
+       the base for the follow-up requests, this is generally
+       sufficient. The default is `initial`.
+
 http.<url>.*::
        Any of the http.* options above can be applied selectively to some URLs.
        For a config key to match a URL, each element of the config key is
index 1fe73448f3f5a3ff48f939924156771cabfc1f77..5516a47b5490ff1e79ead61cd2229946cc1a7fe2 100644 (file)
@@ -118,6 +118,10 @@ OPTIONS
        default to color output.
        Same as `--color=never`.
 
+-i::
+--ignore-case::
+       Sorting and filtering branches are case insensitive.
+
 --column[=<options>]::
 --no-column::
        Display branch listing in columns. See configuration variable
index f57e69bc83e33e3de3d02e339fd71066b93e7d4d..6d22974da6e8fea45881d6a2ce08e47cc2ed78b7 100644 (file)
@@ -79,6 +79,9 @@ OPTIONS
        Only list refs which contain the specified commit (HEAD if not
        specified).
 
+--ignore-case::
+       Sorting and filtering refs are case insensitive.
+
 FIELD NAMES
 -----------
 
index c83aaf39c33505ead72d523f278620fcc6f8f757..bae862ddcb9fe85765ea5bb126ced4fad8e98268 100644 (file)
@@ -303,6 +303,15 @@ These options can be used to modify 'git p4 submit' behavior.
        submit manually or revert.  This option always stops after the
        first (oldest) commit.  Git tags are not exported to p4.
 
+--shelve::
+       Instead of submitting create a series of shelved changelists.
+       After creating each shelve, the relevant files are reverted/deleted.
+       If you have multiple commits pending multiple shelves will be created.
+
+--update-shelve CHANGELIST::
+       Update an existing shelved changelist with this commit. Implies
+       --shelve.
+
 --conflict=(ask|skip|quit)::
        Conflicts can occur when applying a commit to p4.  When this
        happens, the default behavior ("ask") is to prompt whether to
@@ -467,6 +476,10 @@ git-p4.client::
        Client specified as an option to all p4 commands, with
        '-c <client>', including the client spec.
 
+git-p4.retries::
+       Specifies the number of times to retry a p4 command (notably,
+       'p4 sync') if the network times out. The default value is 3.
+
 Clone and sync variables
 ~~~~~~~~~~~~~~~~~~~~~~~~
 git-p4.syncFromOrigin::
index 5f9e65b0c4de117942babf0a14d255922d02b4ad..9bee9b0c4c53692bab569577d584797c0bd9e217 100644 (file)
@@ -664,13 +664,19 @@ creating the branch or tag.
        When retrieving svn commits into Git (as part of 'fetch', 'rebase', or
        'dcommit' operations), look for the first `From:` or `Signed-off-by:` line
        in the log message and use that as the author string.
++
+[verse]
+config key: svn.useLogAuthor
+
 --add-author-from::
        When committing to svn from Git (as part of 'commit-diff', 'set-tree' or 'dcommit'
        operations), if the existing log message doesn't already have a
        `From:` or `Signed-off-by:` line, append a `From:` line based on the
        Git commit's author string.  If you use this, then `--use-log-author`
        will retrieve a valid author string for all commits.
-
++
+[verse]
+config key: svn.addAuthorFrom
 
 ADVANCED OPTIONS
 ----------------
index 80019c584b11b35b2b14da83a31f326634bc6708..76cfe40d969bc5f37dce674f43857ec89f25ae67 100644 (file)
@@ -108,6 +108,10 @@ OPTIONS
        variable if it exists, or lexicographic order otherwise. See
        linkgit:git-config[1].
 
+-i::
+--ignore-case::
+       Sorting and filtering tags are case insensitive.
+
 --column[=<options>]::
 --no-column::
        Display tag listing in columns. See configuration variable
index 21bc6daa4393cb33994ba2eb305354e56d166cc0..8e63c40d274d7693b0c41e702cbe9ed03b1d12ae 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -747,7 +747,7 @@ static void handle_bad_merge_base(void)
                exit(3);
        }
 
-       fprintf(stderr, _("Some %s revs are not ancestor of the %s rev.\n"
+       fprintf(stderr, _("Some %s revs are not ancestors of the %s rev.\n"
                "git bisect cannot work properly in this case.\n"
                "Maybe you mistook %s and %s revs?\n"),
                term_good, term_bad, term_good, term_bad);
index 0d459b3cfe507b3906760fbea7f35e6191366057..c431cbf6a9f08dedc791317cc1a357730bdf3515 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -348,7 +348,7 @@ void die_if_checked_out(const char *branch, int ignore_current_worktree)
 int replace_each_worktree_head_symref(const char *oldref, const char *newref)
 {
        int ret = 0;
-       struct worktree **worktrees = get_worktrees();
+       struct worktree **worktrees = get_worktrees(0);
        int i;
 
        for (i = 0; worktrees[i]; i++) {
index 60cc5c8e8da08e628d05f245003bc558657f6237..9d30f55b0b83cfc09294e2cb7cabdc9aa72e2508 100644 (file)
@@ -512,15 +512,6 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
        if (filter->verbose)
                maxwidth = calc_maxwidth(&array, strlen(remote_prefix));
 
-       /*
-        * If no sorting parameter is given then we default to sorting
-        * by 'refname'. This would give us an alphabetically sorted
-        * array with the 'HEAD' ref at the beginning followed by
-        * local branches 'refs/heads/...' and finally remote-tacking
-        * branches 'refs/remotes/...'.
-        */
-       if (!sorting)
-               sorting = ref_default_sorting();
        ref_array_sort(sorting, &array);
 
        for (i = 0; i < array.nr; i++)
@@ -531,7 +522,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
 
 static void reject_rebase_or_bisect_branch(const char *target)
 {
-       struct worktree **worktrees = get_worktrees();
+       struct worktree **worktrees = get_worktrees(0);
        int i;
 
        for (i = 0; worktrees[i]; i++) {
@@ -645,6 +636,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        const char *new_upstream = NULL;
        enum branch_track track;
        struct ref_filter filter;
+       int icase = 0;
        static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
 
        struct option options[] = {
@@ -686,6 +678,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                        OPTION_CALLBACK, 0, "points-at", &filter.points_at, N_("object"),
                        N_("print only branches of the object"), 0, parse_opt_object_name
                },
+               OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
                OPT_END(),
        };
 
@@ -723,6 +716,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
        if (filter.abbrev == -1)
                filter.abbrev = DEFAULT_ABBREV;
+       filter.ignore_case = icase;
+
        finalize_colopts(&colopts, -1);
        if (filter.verbose) {
                if (explicitly_enable_column(colopts))
@@ -744,6 +739,16 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                if ((filter.kind & FILTER_REFS_BRANCHES) && filter.detached)
                        filter.kind |= FILTER_REFS_DETACHED_HEAD;
                filter.name_patterns = argv;
+               /*
+                * If no sorting parameter is given then we default to sorting
+                * by 'refname'. This would give us an alphabetically sorted
+                * array with the 'HEAD' ref at the beginning followed by
+                * local branches 'refs/heads/...' and finally remote-tacking
+                * branches 'refs/remotes/...'.
+                */
+               if (!sorting)
+                       sorting = ref_default_sorting();
+               sorting->ignore_case = icase;
                print_ref_list(&filter, sorting);
                print_columns(&output, colopts, NULL);
                string_list_clear(&output, 0);
index 6c76a6ed66fef567ca06e3e864b37fc3bed151d5..e3cb8082f7e83b4f233d55bfba78417ebdada114 100644 (file)
@@ -99,7 +99,7 @@ static struct option builtin_clone_options[] = {
        OPT_STRING(0, "shallow-since", &option_since, N_("time"),
                    N_("create a shallow clone since a specific time")),
        OPT_STRING_LIST(0, "shallow-exclude", &option_not, N_("revision"),
-                       N_("deepen history of shallow clone by excluding rev")),
+                       N_("deepen history of shallow clone, excluding rev")),
        OPT_BOOL(0, "single-branch", &option_single_branch,
                    N_("clone only one branch, HEAD or --branch")),
        OPT_BOOL(0, "shallow-submodules", &option_shallow_submodules,
index 8976c3d29bf817be789f983697f7052fe5769f39..887ccc7577a12a16b40e67eb2819356e888f1965 100644 (file)
@@ -790,7 +790,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                strbuf_stripspace(&sb, 0);
 
        if (signoff)
-               append_signoff(&sb, ignore_non_trailer(&sb), 0);
+               append_signoff(&sb, ignore_non_trailer(sb.buf, sb.len), 0);
 
        if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
                die_errno(_("could not write commit template"));
index b6a5597cbf332fc56b5feabfd29d03c98d4d6686..fc74c8471cec5d1d1855c7d4362e465e44259e6c 100644 (file)
@@ -122,7 +122,7 @@ static struct option builtin_fetch_options[] = {
        OPT_STRING(0, "shallow-since", &deepen_since, N_("time"),
                   N_("deepen history of shallow repository based on time")),
        OPT_STRING_LIST(0, "shallow-exclude", &deepen_not, N_("revision"),
-                       N_("deepen history of shallow clone by excluding rev")),
+                       N_("deepen history of shallow clone, excluding rev")),
        OPT_INTEGER(0, "deepen", &deepen_relative,
                    N_("deepen history of shallow clone")),
        { OPTION_SET_INT, 0, "unshallow", &unshallow, NULL,
index 4e9f6c29bf1e0c1cc7b44548f49077c2e4a81ec8..df41fa035004e1cf8a0c7c9ff09081a47b944f38 100644 (file)
@@ -18,7 +18,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
        int i;
        const char *format = "%(objectname) %(objecttype)\t%(refname)";
        struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
-       int maxcount = 0, quote_style = 0;
+       int maxcount = 0, quote_style = 0, icase = 0;
        struct ref_array array;
        struct ref_filter filter;
 
@@ -43,6 +43,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
                OPT_MERGED(&filter, N_("print only refs that are merged")),
                OPT_NO_MERGED(&filter, N_("print only refs that are not merged")),
                OPT_CONTAINS(&filter.with_commit, N_("print only refs which contain the commit")),
+               OPT_BOOL(0, "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
                OPT_END(),
        };
 
@@ -63,6 +64,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
 
        if (!sorting)
                sorting = ref_default_sorting();
+       sorting->ignore_case = icase;
+       filter.ignore_case = icase;
 
        /* for warn_ambiguous_refs */
        git_config(git_default_config, NULL);
index e6b3879a5b90034937dfb8eee32f8d2981f6bb53..6b97cbdbe9444d72d575c149678e4b609a154842 100644 (file)
@@ -795,8 +795,8 @@ static char *refuse_unconfigured_deny_msg =
           "with what you pushed, and will require 'git reset --hard' to match\n"
           "the work tree to HEAD.\n"
           "\n"
-          "You can set 'receive.denyCurrentBranch' configuration variable to\n"
-          "'ignore' or 'warn' in the remote repository to allow pushing into\n"
+          "You can set the 'receive.denyCurrentBranch' configuration variable\n"
+          "to 'ignore' or 'warn' in the remote repository to allow pushing into\n"
           "its current branch; however, this is not recommended unless you\n"
           "arranged to update its work tree to match what you pushed in some\n"
           "other way.\n"
index cfb0f1510c59674abe68fb67ff45142b5c92ac89..ff13e59e1dbd200b6e7cf7d1c508b620b19e8cc7 100644 (file)
@@ -342,11 +342,16 @@ static int try_parent_shorthands(const char *arg)
        for (parents = commit->parents, parent_number = 1;
             parents;
             parents = parents->next, parent_number++) {
+               char *name = NULL;
+
                if (exclude_parent && parent_number != exclude_parent)
                        continue;
 
+               if (symbolic)
+                       name = xstrfmt("%s^%d", arg, parent_number);
                show_rev(include_parents ? NORMAL : REVERSED,
-                        parents->item->object.oid.hash, arg);
+                        parents->item->object.oid.hash, name);
+               free(name);
        }
 
        *dotdot = '^';
index 50e4ae5678c21f348c3ce0e0d0662c9d5f995847..73df728114e81ac87dd1b84604947d739d948fb6 100644 (file)
@@ -335,6 +335,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
        struct ref_filter filter;
        static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
        const char *format = NULL;
+       int icase = 0;
        struct option options[] = {
                OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
                { OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
@@ -370,6 +371,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                        N_("print only tags of the object"), 0, parse_opt_object_name
                },
                OPT_STRING(  0 , "format", &format, N_("format"), N_("format to use for the output")),
+               OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
                OPT_END()
        };
 
@@ -401,6 +403,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
        }
        if (!sorting)
                sorting = ref_default_sorting();
+       sorting->ignore_case = icase;
+       filter.ignore_case = icase;
        if (cmdmode == 'l') {
                int ret;
                if (column_active(colopts)) {
index 5c4854d3e4a679f59f4a7db7cb3f37bd0e210622..9a97e37a3fa53e730f0963f8f00bbca9f6d6efc6 100644 (file)
@@ -388,7 +388,7 @@ static void show_worktree_porcelain(struct worktree *wt)
                printf("HEAD %s\n", sha1_to_hex(wt->head_sha1));
                if (wt->is_detached)
                        printf("detached\n");
-               else
+               else if (wt->head_ref)
                        printf("branch %s\n", wt->head_ref);
        }
        printf("\n");
@@ -406,10 +406,12 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
        else {
                strbuf_addf(&sb, "%-*s ", abbrev_len,
                                find_unique_abbrev(wt->head_sha1, DEFAULT_ABBREV));
-               if (!wt->is_detached)
+               if (wt->is_detached)
+                       strbuf_addstr(&sb, "(detached HEAD)");
+               else if (wt->head_ref)
                        strbuf_addf(&sb, "[%s]", shorten_unambiguous_ref(wt->head_ref, 0));
                else
-                       strbuf_addstr(&sb, "(detached HEAD)");
+                       strbuf_addstr(&sb, "(error)");
        }
        printf("%s\n", sb.buf);
 
@@ -445,7 +447,7 @@ static int list(int ac, const char **av, const char *prefix)
        if (ac)
                usage_with_options(worktree_usage, options);
        else {
-               struct worktree **worktrees = get_worktrees();
+               struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);
                int path_maxlen = 0, abbrev = DEFAULT_ABBREV, i;
 
                if (!porcelain)
@@ -476,7 +478,7 @@ static int lock_worktree(int ac, const char **av, const char *prefix)
        if (ac != 1)
                usage_with_options(worktree_usage, options);
 
-       worktrees = get_worktrees();
+       worktrees = get_worktrees(0);
        wt = find_worktree(worktrees, prefix, av[0]);
        if (!wt)
                die(_("'%s' is not a working tree"), av[0]);
@@ -509,7 +511,7 @@ static int unlock_worktree(int ac, const char **av, const char *prefix)
        if (ac != 1)
                usage_with_options(worktree_usage, options);
 
-       worktrees = get_worktrees();
+       worktrees = get_worktrees(0);
        wt = find_worktree(worktrees, prefix, av[0]);
        if (!wt)
                die(_("'%s' is not a working tree"), av[0]);
index 856fd4aeeff654c45ba0a6149f9db2c22806e0cb..2cf85158b4899b664a3cbae8d0777f5a9e473318 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -1649,7 +1649,7 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len
 }
 
 /*
- * Inspect sb and determine the true "end" of the log message, in
+ * Inspect the given string and determine the true "end" of the log message, in
  * order to find where to put a new Signed-off-by: line.  Ignored are
  * trailing comment lines and blank lines, and also the traditional
  * "Conflicts:" block that is not commented out, so that we can use
@@ -1659,37 +1659,37 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len
  * Returns the number of bytes from the tail to ignore, to be fed as
  * the second parameter to append_signoff().
  */
-int ignore_non_trailer(struct strbuf *sb)
+int ignore_non_trailer(const char *buf, size_t len)
 {
        int boc = 0;
        int bol = 0;
        int in_old_conflicts_block = 0;
 
-       while (bol < sb->len) {
-               char *next_line;
+       while (bol < len) {
+               const char *next_line = memchr(buf + bol, '\n', len - bol);
 
-               if (!(next_line = memchr(sb->buf + bol, '\n', sb->len - bol)))
-                       next_line = sb->buf + sb->len;
+               if (!next_line)
+                       next_line = buf + len;
                else
                        next_line++;
 
-               if (sb->buf[bol] == comment_line_char || sb->buf[bol] == '\n') {
+               if (buf[bol] == comment_line_char || buf[bol] == '\n') {
                        /* is this the first of the run of comments? */
                        if (!boc)
                                boc = bol;
                        /* otherwise, it is just continuing */
-               } else if (starts_with(sb->buf + bol, "Conflicts:\n")) {
+               } else if (starts_with(buf + bol, "Conflicts:\n")) {
                        in_old_conflicts_block = 1;
                        if (!boc)
                                boc = bol;
-               } else if (in_old_conflicts_block && sb->buf[bol] == '\t') {
+               } else if (in_old_conflicts_block && buf[bol] == '\t') {
                        ; /* a pathname in the conflicts block */
                } else if (boc) {
                        /* the previous was not trailing comment */
                        boc = 0;
                        in_old_conflicts_block = 0;
                }
-               bol = next_line - sb->buf;
+               bol = next_line - buf;
        }
-       return boc ? sb->len - boc : 0;
+       return boc ? len - boc : 0;
 }
index afd14f318c0c4d18f3a03781d3229f2fdc0f64c6..9c12abb91110151e3a982c4d8baf8753d0382441 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -355,7 +355,7 @@ extern const char *find_commit_header(const char *msg, const char *key,
                                      size_t *out_len);
 
 /* Find the end of the log message, the right place for a new trailer. */
-extern int ignore_non_trailer(struct strbuf *sb);
+extern int ignore_non_trailer(const char *buf, size_t len);
 
 typedef void (*each_mergetag_fn)(struct commit *commit, struct commit_extra_header *extra,
                                 void *cb_data);
index 034fff9479d03d2a2e3c7017a4fe4131461f0ec6..33501695550accdb08368aa867b9addb25c90d5f 100644 (file)
@@ -384,6 +384,9 @@ int mingw_raise(int sig);
  * ANSI emulation wrappers
  */
 
+int winansi_isatty(int fd);
+#define isatty winansi_isatty
+
 void winansi_init(void);
 HANDLE winansi_get_osfhandle(int fd);
 
index db4a5b0a37d687218ab085f22b57eb35e28893b8..cb725fb02f6e4f48c4f314c3c6c5e8535aa6eda8 100644 (file)
@@ -7,6 +7,9 @@
 #include <wingdi.h>
 #include <winreg.h>
 
+/* In this file, we actually want to use Windows' own isatty(). */
+#undef isatty
+
 /*
  ANSI codes used by git: m, K
 
@@ -570,6 +573,36 @@ static void detect_msys_tty(int fd)
 
 #endif
 
+int winansi_isatty(int fd)
+{
+       int res = isatty(fd);
+
+       if (res) {
+               /*
+                * Make sure that /dev/null is not fooling Git into believing
+                * that we are connected to a terminal, as "_isatty() returns a
+                * nonzero value if the descriptor is associated with a
+                * character device."; for more information, see
+                *
+                * https://msdn.microsoft.com/en-us/library/f4s0ddew.aspx
+                */
+               HANDLE handle = (HANDLE)_get_osfhandle(fd);
+               if (fd == STDIN_FILENO) {
+                       DWORD dummy;
+
+                       if (!GetConsoleMode(handle, &dummy))
+                               res = 0;
+               } else if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
+                       CONSOLE_SCREEN_BUFFER_INFO dummy;
+
+                       if (!GetConsoleScreenBufferInfo(handle, &dummy))
+                               res = 0;
+               }
+       }
+
+       return res;
+}
+
 void winansi_init(void)
 {
        int con1, con2;
index be91358462a72c9d5a6c02f2b0e44585a76d4783..4e17e45ed265b3f4861d1b7a1e86edaa4df3b1ac 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -279,15 +279,16 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
                if (convert_is_binary(len, &stats))
                        return 0;
                /*
-                * If the file in the index has any CR in it, do not convert.
-                * This is the new safer autocrlf handling.
+                * If the file in the index has any CR in it, do not
+                * convert.  This is the new safer autocrlf handling,
+                * unless we want to renormalize in a merge or
+                * cherry-pick.
                 */
-               if (checksafe == SAFE_CRLF_RENORMALIZE)
-                       checksafe = SAFE_CRLF_FALSE;
-               else if (has_cr_in_index(path))
+               if ((checksafe != SAFE_CRLF_RENORMALIZE) && has_cr_in_index(path))
                        convert_crlf_into_lf = 0;
        }
-       if (checksafe && len) {
+       if ((checksafe == SAFE_CRLF_WARN ||
+           (checksafe == SAFE_CRLF_FAIL)) && len) {
                struct text_stat new_stats;
                memcpy(&new_stats, &stats, sizeof(new_stats));
                /* simulate "git add" */
index 9abd00be212b3e55883c0f9fa0487c7b31a6039f..9a8b97a2aba9aa9fabb095558c03cb8f27df3d50 100644 (file)
@@ -125,16 +125,7 @@ setup_user_tool () {
        }
 
        merge_cmd () {
-               trust_exit_code=$(git config --bool \
-                       "mergetool.$1.trustExitCode" || echo false)
-               if test "$trust_exit_code" = "false"
-               then
-                       touch "$BACKUP"
-                       ( eval $merge_tool_cmd )
-                       check_unchanged
-               else
-                       ( eval $merge_tool_cmd )
-               fi
+               ( eval $merge_tool_cmd )
        }
 }
 
@@ -162,6 +153,28 @@ setup_tool () {
                echo "$1"
        }
 
+       # Most tools' exit codes cannot be trusted, so By default we ignore
+       # their exit code and check the merged file's modification time in
+       # check_unchanged() to determine whether or not the merge was
+       # successful.  The return value from run_merge_cmd, by default, is
+       # determined by check_unchanged().
+       #
+       # When a tool's exit code can be trusted then the return value from
+       # run_merge_cmd is simply the tool's exit code, and check_unchanged()
+       # is not called.
+       #
+       # The return value of exit_code_trustable() tells us whether or not we
+       # can trust the tool's exit code.
+       #
+       # User-defined and built-in tools default to false.
+       # Built-in tools advertise that their exit code is trustable by
+       # redefining exit_code_trustable() to true.
+
+       exit_code_trustable () {
+               false
+       }
+
+
        if ! test -f "$MERGE_TOOLS_DIR/$tool"
        then
                setup_user_tool
@@ -197,6 +210,19 @@ get_merge_tool_cmd () {
        fi
 }
 
+trust_exit_code () {
+       if git config --bool "mergetool.$1.trustExitCode"
+       then
+               :; # OK
+       elif exit_code_trustable
+       then
+               echo true
+       else
+               echo false
+       fi
+}
+
+
 # Entry point for running tools
 run_merge_tool () {
        # If GIT_PREFIX is empty then we cannot use it in tools
@@ -225,7 +251,15 @@ run_diff_cmd () {
 
 # Run a either a configured or built-in merge tool
 run_merge_cmd () {
-       merge_cmd "$1"
+       mergetool_trust_exit_code=$(trust_exit_code "$1")
+       if test "$mergetool_trust_exit_code" = "true"
+       then
+               merge_cmd "$1"
+       else
+               touch "$BACKUP"
+               merge_cmd "$1"
+               check_unchanged
+       fi
 }
 
 list_merge_tool_candidates () {
index fd5ca524626c40823371422e52a3457fd1d45579..13bf44768b352c2cd5b34e718bdc7aaef7d6014d 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -78,6 +78,11 @@ def p4_build_cmd(cmd):
     if len(client) > 0:
         real_cmd += ["-c", client]
 
+    retries = gitConfigInt("git-p4.retries")
+    if retries is None:
+        # Perform 3 retries by default
+        retries = 3
+    real_cmd += ["-r", str(retries)]
 
     if isinstance(cmd,basestring):
         real_cmd = ' '.join(real_cmd) + ' ' + cmd
@@ -262,6 +267,10 @@ def p4_revert(f):
 def p4_reopen(type, f):
     p4_system(["reopen", "-t", type, wildcard_encode(f)])
 
+def p4_reopen_in_change(changelist, files):
+    cmd = ["reopen", "-c", str(changelist)] + files
+    p4_system(cmd)
+
 def p4_move(src, dest):
     p4_system(["move", "-k", wildcard_encode(src), wildcard_encode(dest)])
 
@@ -1005,18 +1014,20 @@ def processContent(self, git_mode, relPath, contents):
            steps."""
         if self.exceedsLargeFileThreshold(relPath, contents) or self.hasLargeFileExtension(relPath):
             contentTempFile = self.generateTempFile(contents)
-            (git_mode, contents, localLargeFile) = self.generatePointer(contentTempFile)
-
-            # Move temp file to final location in large file system
-            largeFileDir = os.path.dirname(localLargeFile)
-            if not os.path.isdir(largeFileDir):
-                os.makedirs(largeFileDir)
-            shutil.move(contentTempFile, localLargeFile)
-            self.addLargeFile(relPath)
-            if gitConfigBool('git-p4.largeFilePush'):
-                self.pushFile(localLargeFile)
-            if verbose:
-                sys.stderr.write("%s moved to large file system (%s)\n" % (relPath, localLargeFile))
+            (pointer_git_mode, contents, localLargeFile) = self.generatePointer(contentTempFile)
+            if pointer_git_mode:
+                git_mode = pointer_git_mode
+            if localLargeFile:
+                # Move temp file to final location in large file system
+                largeFileDir = os.path.dirname(localLargeFile)
+                if not os.path.isdir(largeFileDir):
+                    os.makedirs(largeFileDir)
+                shutil.move(contentTempFile, localLargeFile)
+                self.addLargeFile(relPath)
+                if gitConfigBool('git-p4.largeFilePush'):
+                    self.pushFile(localLargeFile)
+                if verbose:
+                    sys.stderr.write("%s moved to large file system (%s)\n" % (relPath, localLargeFile))
         return (git_mode, contents)
 
 class MockLFS(LargeFileSystem):
@@ -1056,6 +1067,9 @@ def generatePointer(self, contentFile):
            the actual content. Return also the new location of the actual
            content.
            """
+        if os.path.getsize(contentFile) == 0:
+            return (None, '', None)
+
         pointerProcess = subprocess.Popen(
             ['git', 'lfs', 'pointer', '--file=' + contentFile],
             stdout=subprocess.PIPE
@@ -1289,6 +1303,12 @@ def __init__(self):
                 optparse.make_option("--conflict", dest="conflict_behavior",
                                      choices=self.conflict_behavior_choices),
                 optparse.make_option("--branch", dest="branch"),
+                optparse.make_option("--shelve", dest="shelve", action="store_true",
+                                     help="Shelve instead of submit. Shelved files are reverted, "
+                                     "restoring the workspace to the state before the shelve"),
+                optparse.make_option("--update-shelve", dest="update_shelve", action="store", type="int",
+                                     metavar="CHANGELIST",
+                                     help="update an existing shelved changelist, implies --shelve")
         ]
         self.description = "Submit changes from git to the perforce depot."
         self.usage += " [name of git branch to submit into perforce depot]"
@@ -1296,6 +1316,8 @@ def __init__(self):
         self.detectRenames = False
         self.preserveUser = gitConfigBool("git-p4.preserveUser")
         self.dry_run = False
+        self.shelve = False
+        self.update_shelve = None
         self.prepare_p4_only = False
         self.conflict_behavior = None
         self.isWindows = (platform.system() == "Windows")
@@ -1464,7 +1486,7 @@ def canChangeChangelists(self):
                     return 1
         return 0
 
-    def prepareSubmitTemplate(self):
+    def prepareSubmitTemplate(self, changelist=None):
         """Run "p4 change -o" to grab a change specification template.
            This does not use "p4 -G", as it is nice to keep the submission
            template in original order, since a human might edit it.
@@ -1476,7 +1498,11 @@ def prepareSubmitTemplate(self):
 
         template = ""
         inFilesSection = False
-        for line in p4_read_pipe_lines(['change', '-o']):
+        args = ['change', '-o']
+        if changelist:
+            args.append(str(changelist))
+
+        for line in p4_read_pipe_lines(args):
             if line.endswith("\r\n"):
                 line = line[:-2] + "\n"
             if inFilesSection:
@@ -1575,11 +1601,14 @@ def applyCommit(self, id):
         editedFiles = set()
         pureRenameCopy = set()
         filesToChangeExecBit = {}
+        all_files = list()
 
         for line in diff:
             diff = parseDiffTreeEntry(line)
             modifier = diff['status']
             path = diff['src']
+            all_files.append(path)
+
             if modifier == "M":
                 p4_edit(path)
                 if isModeExecChanged(diff['src_mode'], diff['dst_mode']):
@@ -1705,6 +1734,10 @@ def applyCommit(self, id):
             mode = filesToChangeExecBit[f]
             setP4ExecBit(f, mode)
 
+        if self.update_shelve:
+            print("all_files = %s" % str(all_files))
+            p4_reopen_in_change(self.update_shelve, all_files)
+
         #
         # Build p4 change description, starting with the contents
         # of the git commit message.
@@ -1713,7 +1746,7 @@ def applyCommit(self, id):
         logMessage = logMessage.strip()
         (logMessage, jobs) = self.separate_jobs_from_description(logMessage)
 
-        template = self.prepareSubmitTemplate()
+        template = self.prepareSubmitTemplate(self.update_shelve)
         submitTemplate = self.prepareLogMessage(template, logMessage, jobs)
 
         if self.preserveUser:
@@ -1785,7 +1818,17 @@ def applyCommit(self, id):
                 if self.isWindows:
                     message = message.replace("\r\n", "\n")
                 submitTemplate = message[:message.index(separatorLine)]
-                p4_write_pipe(['submit', '-i'], submitTemplate)
+
+                if self.update_shelve:
+                    p4_write_pipe(['shelve', '-r', '-i'], submitTemplate)
+                elif self.shelve:
+                    p4_write_pipe(['shelve', '-i'], submitTemplate)
+                else:
+                    p4_write_pipe(['submit', '-i'], submitTemplate)
+                    # The rename/copy happened by applying a patch that created a
+                    # new file.  This leaves it writable, which confuses p4.
+                    for f in pureRenameCopy:
+                        p4_sync(f, "-f")
 
                 if self.preserveUser:
                     if p4User:
@@ -1795,23 +1838,20 @@ def applyCommit(self, id):
                         changelist = self.lastP4Changelist()
                         self.modifyChangelistUser(changelist, p4User)
 
-                # The rename/copy happened by applying a patch that created a
-                # new file.  This leaves it writable, which confuses p4.
-                for f in pureRenameCopy:
-                    p4_sync(f, "-f")
                 submitted = True
 
         finally:
             # skip this patch
-            if not submitted:
-                print "Submission cancelled, undoing p4 changes."
-                for f in editedFiles:
+            if not submitted or self.shelve:
+                if self.shelve:
+                    print ("Reverting shelved files.")
+                else:
+                    print ("Submission cancelled, undoing p4 changes.")
+                for f in editedFiles | filesToDelete:
                     p4_revert(f)
                 for f in filesToAdd:
                     p4_revert(f)
                     os.remove(f)
-                for f in filesToDelete:
-                    p4_revert(f)
 
         os.remove(fileName)
         return submitted
@@ -1907,6 +1947,9 @@ def run(self, args):
         if len(self.origin) == 0:
             self.origin = upstream
 
+        if self.update_shelve:
+            self.shelve = True
+
         if self.preserveUser:
             if not self.canChangeChangelists():
                 die("Cannot preserve user names without p4 super-user or admin permissions")
@@ -2067,13 +2110,13 @@ def run(self, args):
                         break
 
         chdir(self.oldWorkingDirectory)
-
+        shelved_applied = "shelved" if self.shelve else "applied"
         if self.dry_run:
             pass
         elif self.prepare_p4_only:
             pass
         elif len(commits) == len(applied):
-            print "All commits applied!"
+            print ("All commits {0}!".format(shelved_applied))
 
             sync = P4Sync()
             if self.branch:
@@ -2085,9 +2128,9 @@ def run(self, args):
 
         else:
             if len(applied) == 0:
-                print "No commits applied."
+                print ("No commits {0}.".format(shelved_applied))
             else:
-                print "Applied only the commits marked with '*':"
+                print ("{0} only the commits marked with '*':".format(shelved_applied.capitalize()))
                 for c in commits:
                     if c in applied:
                         star = "*"
index 4546abaaef3dab9e0c4dc719f111682f1cb1dd57..10c284d1aa2273a3dfe5cc39f1d6738830d02462 100755 (executable)
@@ -115,7 +115,7 @@ create_stash () {
                        git read-tree --index-output="$TMPindex" -m $i_tree &&
                        GIT_INDEX_FILE="$TMPindex" &&
                        export GIT_INDEX_FILE &&
-                       git diff --name-only -z HEAD -- >"$TMP-stagenames" &&
+                       git diff-index --name-only -z HEAD -- >"$TMP-stagenames" &&
                        git update-index -z --add --remove --stdin <"$TMP-stagenames" &&
                        git write-tree &&
                        rm -f "$TMPindex"
index 0b2425531a8120fb29f37ee473a1e6e974959605..c2f81cd6af9d9da0f10fa2e657e6fe62bdbdc4bc 100644 (file)
@@ -274,9 +274,8 @@ static void process_alternates_response(void *callback_data)
                                struct strbuf target = STRBUF_INIT;
                                strbuf_add(&target, base, serverlen);
                                strbuf_add(&target, data + i, posn - i - 7);
-                               if (walker->get_verbosely)
-                                       fprintf(stderr, "Also look at %s\n",
-                                               target.buf);
+                               warning("adding alternate object store: %s",
+                                       target.buf);
                                newalt = xmalloc(sizeof(*newalt));
                                newalt->next = NULL;
                                newalt->base = strbuf_detach(&target, NULL);
@@ -302,6 +301,9 @@ static void fetch_alternates(struct walker *walker, const char *base)
        struct alternates_request alt_req;
        struct walker_data *cdata = walker->data;
 
+       if (http_follow_config != HTTP_FOLLOW_ALWAYS)
+               return;
+
        /*
         * If another request has already started fetching alternates,
         * wait for them to arrive and return to processing this request's
@@ -480,10 +482,13 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
         * we turned off CURLOPT_FAILONERROR to avoid losing a
         * persistent connection and got CURLE_OK.
         */
-       if (req->http_code == 404 && req->curl_result == CURLE_OK &&
+       if (req->http_code >= 300 && req->curl_result == CURLE_OK &&
                        (starts_with(req->url, "http://") ||
-                        starts_with(req->url, "https://")))
+                        starts_with(req->url, "https://"))) {
                req->curl_result = CURLE_HTTP_RETURNED_ERROR;
+               xsnprintf(req->errorstr, sizeof(req->errorstr),
+                         "HTTP request failed");
+       }
 
        if (obj_req->state == ABORTED) {
                ret = error("Request for %s aborted", hex);
diff --git a/http.c b/http.c
index 4c4a812fcc39509e32fbcae3db21871b97a1a5eb..051fe6e5ab77a5dc6e53dce7011d0fc445f15ab0 100644 (file)
--- a/http.c
+++ b/http.c
@@ -111,6 +111,8 @@ static int http_proactive_auth;
 static const char *user_agent;
 static int curl_empty_auth;
 
+enum http_follow_config http_follow_config = HTTP_FOLLOW_INITIAL;
+
 #if LIBCURL_VERSION_NUM >= 0x071700
 /* Use CURLOPT_KEYPASSWD as is */
 #elif LIBCURL_VERSION_NUM >= 0x070903
@@ -366,6 +368,16 @@ static int http_options(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (!strcmp("http.followredirects", var)) {
+               if (value && !strcmp(value, "initial"))
+                       http_follow_config = HTTP_FOLLOW_INITIAL;
+               else if (git_config_bool(var, value))
+                       http_follow_config = HTTP_FOLLOW_ALWAYS;
+               else
+                       http_follow_config = HTTP_FOLLOW_NONE;
+               return 0;
+       }
+
        /* Fall back on the default ones */
        return git_default_config(var, value, cb);
 }
@@ -717,7 +729,6 @@ static CURL *get_curl_handle(void)
                                 curl_low_speed_time);
        }
 
-       curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
        curl_easy_setopt(result, CURLOPT_MAXREDIRS, 20);
 #if LIBCURL_VERSION_NUM >= 0x071301
        curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
@@ -734,6 +745,7 @@ static CURL *get_curl_handle(void)
        if (is_transport_allowed("ftps"))
                allowed_protocols |= CURLPROTO_FTPS;
        curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS, allowed_protocols);
+       curl_easy_setopt(result, CURLOPT_PROTOCOLS, allowed_protocols);
 #else
        if (transport_restrict_protocols())
                warning("protocol restrictions not applied to curl redirects because\n"
@@ -1044,6 +1056,16 @@ struct active_request_slot *get_active_slot(void)
        curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 1);
        curl_easy_setopt(slot->curl, CURLOPT_RANGE, NULL);
 
+       /*
+        * Default following to off unless "ALWAYS" is configured; this gives
+        * callers a sane starting point, and they can tweak for individual
+        * HTTP_FOLLOW_* cases themselves.
+        */
+       if (http_follow_config == HTTP_FOLLOW_ALWAYS)
+               curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 1);
+       else
+               curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 0);
+
 #if LIBCURL_VERSION_NUM >= 0x070a08
        curl_easy_setopt(slot->curl, CURLOPT_IPRESOLVE, git_curl_ipresolve);
 #endif
@@ -1286,9 +1308,12 @@ static int handle_curl_result(struct slot_results *results)
         * If we see a failing http code with CURLE_OK, we have turned off
         * FAILONERROR (to keep the server's custom error response), and should
         * translate the code into failure here.
+        *
+        * Likewise, if we see a redirect (30x code), that means we turned off
+        * redirect-following, and we should treat the result as an error.
         */
        if (results->curl_result == CURLE_OK &&
-           results->http_code >= 400) {
+           results->http_code >= 300) {
                results->curl_result = CURLE_HTTP_RETURNED_ERROR;
                /*
                 * Normally curl will already have put the "reason phrase"
@@ -1607,6 +1632,9 @@ static int http_request(const char *url,
                strbuf_addstr(&buf, " no-cache");
        if (options && options->keep_error)
                curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0);
+       if (options && options->initial_request &&
+           http_follow_config == HTTP_FOLLOW_INITIAL)
+               curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 1);
 
        headers = curl_slist_append(headers, buf.buf);
 
@@ -1655,16 +1683,16 @@ static int http_request(const char *url,
  *
  * Note that this assumes a sane redirect scheme. It's entirely possible
  * in the example above to end up at a URL that does not even end in
- * "info/refs".  In such a case we simply punt, as there is not much we can
- * do (and such a scheme is unlikely to represent a real git repository,
- * which means we are likely about to abort anyway).
+ * "info/refs".  In such a case we die. There's not much we can do, such a
+ * scheme is unlikely to represent a real git repository, and failing to
+ * rewrite the base opens options for malicious redirects to do funny things.
  */
 static int update_url_from_redirect(struct strbuf *base,
                                    const char *asked,
                                    const struct strbuf *got)
 {
        const char *tail;
-       size_t tail_len;
+       size_t new_len;
 
        if (!strcmp(asked, got->buf))
                return 0;
@@ -1673,14 +1701,16 @@ static int update_url_from_redirect(struct strbuf *base,
                die("BUG: update_url_from_redirect: %s is not a superset of %s",
                    asked, base->buf);
 
-       tail_len = strlen(tail);
-
-       if (got->len < tail_len ||
-           strcmp(tail, got->buf + got->len - tail_len))
-               return 0; /* insane redirect scheme */
+       new_len = got->len;
+       if (!strip_suffix_mem(got->buf, &new_len, tail))
+               die(_("unable to update url base from redirection:\n"
+                     "  asked for: %s\n"
+                     "   redirect: %s"),
+                   asked, got->buf);
 
        strbuf_reset(base);
-       strbuf_add(base, got->buf, got->len - tail_len);
+       strbuf_add(base, got->buf, new_len);
+
        return 1;
 }
 
@@ -2028,7 +2058,7 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
                if (c != CURLE_OK)
                        die("BUG: curl_easy_getinfo for HTTP code failed: %s",
                                curl_easy_strerror(c));
-               if (slot->http_code >= 400)
+               if (slot->http_code >= 300)
                        return size;
        }
 
diff --git a/http.h b/http.h
index 5ab9d9c329378f4f254c9d912dd7f05105ea6695..02bccb7b0caf9f2b1be0b98cb16c6fc84b95cc74 100644 (file)
--- a/http.h
+++ b/http.h
@@ -116,6 +116,13 @@ extern struct credential http_auth;
 
 extern char curl_errorstr[CURL_ERROR_SIZE];
 
+enum http_follow_config {
+       HTTP_FOLLOW_NONE,
+       HTTP_FOLLOW_ALWAYS,
+       HTTP_FOLLOW_INITIAL
+};
+extern enum http_follow_config http_follow_config;
+
 static inline int missing__target(int code, int result)
 {
        return  /* file:// URL -- do we ever use one??? */
@@ -139,7 +146,8 @@ extern char *get_remote_object_url(const char *url, const char *hex,
 /* Options for http_get_*() */
 struct http_get_options {
        unsigned no_cache:1,
-                keep_error:1;
+                keep_error:1,
+                initial_request:1;
 
        /* If non-NULL, returns the content-type of the response. */
        struct strbuf *content_type;
index 9041c2f149c01134ce02119354455894533e713c..23d6992f4037b37a9c3e133001af16595e8da394 100644 (file)
@@ -235,6 +235,8 @@ static int add_cacheinfo(struct merge_options *o,
                struct cache_entry *nce;
 
                nce = refresh_cache_entry(ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
+               if (!nce)
+                       return err(o, _("addinfo_cache failed for path '%s'"), path);
                if (nce != ce)
                        ret = add_cache_entry(nce, options);
        }
@@ -388,12 +390,10 @@ static struct string_list *get_unmerged(void)
        return unmerged;
 }
 
-static int string_list_df_name_compare(const void *a, const void *b)
+static int string_list_df_name_compare(const char *one, const char *two)
 {
-       const struct string_list_item *one = a;
-       const struct string_list_item *two = b;
-       int onelen = strlen(one->string);
-       int twolen = strlen(two->string);
+       int onelen = strlen(one);
+       int twolen = strlen(two);
        /*
         * Here we only care that entries for D/F conflicts are
         * adjacent, in particular with the file of the D/F conflict
@@ -406,8 +406,8 @@ static int string_list_df_name_compare(const void *a, const void *b)
         * since in other cases any changes in their order due to
         * sorting cause no problems for us.
         */
-       int cmp = df_name_compare(one->string, onelen, S_IFDIR,
-                                 two->string, twolen, S_IFDIR);
+       int cmp = df_name_compare(one, onelen, S_IFDIR,
+                                 two, twolen, S_IFDIR);
        /*
         * Now that 'foo' and 'foo/bar' compare equal, we have to make sure
         * that 'foo' comes before 'foo/bar'.
@@ -451,8 +451,8 @@ static void record_df_conflict_files(struct merge_options *o,
                string_list_append(&df_sorted_entries, next->string)->util =
                                   next->util;
        }
-       qsort(df_sorted_entries.items, entries->nr, sizeof(*entries->items),
-             string_list_df_name_compare);
+       df_sorted_entries.cmp = string_list_df_name_compare;
+       string_list_sort(&df_sorted_entries);
 
        string_list_clear(&o->df_conflict_file_set, 1);
        for (i = 0; i < df_sorted_entries.nr; i++) {
@@ -664,7 +664,13 @@ static char *unique_path(struct merge_options *o, const char *path, const char *
        return strbuf_detach(&newpath, NULL);
 }
 
-static int dir_in_way(const char *path, int check_working_copy)
+/**
+ * Check whether a directory in the index is in the way of an incoming
+ * file.  Return 1 if so.  If check_working_copy is non-zero, also
+ * check the working directory.  If empty_ok is non-zero, also return
+ * 0 in the case where the working-tree dir exists but is empty.
+ */
+static int dir_in_way(const char *path, int check_working_copy, int empty_ok)
 {
        int pos;
        struct strbuf dirpath = STRBUF_INIT;
@@ -684,7 +690,8 @@ static int dir_in_way(const char *path, int check_working_copy)
        }
 
        strbuf_release(&dirpath);
-       return check_working_copy && !lstat(path, &st) && S_ISDIR(st.st_mode);
+       return check_working_copy && !lstat(path, &st) && S_ISDIR(st.st_mode) &&
+               !(empty_ok && is_empty_dir(path));
 }
 
 static int was_tracked(const char *path)
@@ -1062,7 +1069,7 @@ static int handle_change_delete(struct merge_options *o,
 {
        char *renamed = NULL;
        int ret = 0;
-       if (dir_in_way(path, !o->call_depth)) {
+       if (dir_in_way(path, !o->call_depth, 0)) {
                renamed = unique_path(o, path, a_oid ? o->branch1 : o->branch2);
        }
 
@@ -1195,7 +1202,7 @@ static int handle_file(struct merge_options *o,
                remove_file(o, 0, rename->path, 0);
                dst_name = unique_path(o, rename->path, cur_branch);
        } else {
-               if (dir_in_way(rename->path, !o->call_depth)) {
+               if (dir_in_way(rename->path, !o->call_depth, 0)) {
                        dst_name = unique_path(o, rename->path, cur_branch);
                        output(o, 1, _("%s is a directory in %s adding as %s instead"),
                               rename->path, other_branch, dst_name);
@@ -1704,7 +1711,8 @@ static int merge_content(struct merge_options *o,
                         o->branch2 == rename_conflict_info->branch1) ?
                        pair1->two->path : pair1->one->path;
 
-               if (dir_in_way(path, !o->call_depth))
+               if (dir_in_way(path, !o->call_depth,
+                              S_ISGITLINK(pair1->two->mode)))
                        df_conflict_remains = 1;
        }
        if (merge_file_special_markers(o, &one, &a, &b,
@@ -1862,7 +1870,8 @@ static int process_entry(struct merge_options *o,
                        oid = b_oid;
                        conf = _("directory/file");
                }
-               if (dir_in_way(path, !o->call_depth)) {
+               if (dir_in_way(path, !o->call_depth,
+                              S_ISGITLINK(a_mode))) {
                        char *new_path = unique_path(o, path, add_branch);
                        clean_merge = 0;
                        output(o, 1, _("CONFLICT (%s): There is a directory with name %s in %s. "
index 64f97c5e9755d54ace864cb53bf0e7844f530f49..e2407b65b70d1e622979cdb2fe0e425ba6403ee1 100644 (file)
@@ -3,7 +3,6 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        if $base_present
        then
                "$merge_tool_path" -wait -merge -3 -a1 \
@@ -12,7 +11,6 @@ merge_cmd () {
                "$merge_tool_path" -wait -2 \
                        "$LOCAL" "$REMOTE" "$MERGED" >/dev/null 2>&1
        fi
-       check_unchanged
 }
 
 translate_merge_tool_path() {
index b6319d206e2333e42469486604d4635e846e5faa..3a69e60faa9c95dcf388cd295d040e9b88e0defd 100644 (file)
@@ -3,7 +3,6 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        if $base_present
        then
                "$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \
@@ -12,7 +11,6 @@ merge_cmd () {
                "$merge_tool_path" "$LOCAL" "$REMOTE" \
                        -mergeoutput="$MERGED"
        fi
-       check_unchanged
 }
 
 translate_merge_tool_path() {
index 3f0486bc807133f50abcaab27c991d4a806ec63c..9f60e8da6527cf28dcc5ad4a3e5f7f0ca9442cb4 100644 (file)
@@ -3,7 +3,6 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        if $base_present
        then
                "$merge_tool_path" -MF="$LOCAL" -TF="$REMOTE" -BF="$BASE" \
@@ -12,7 +11,6 @@ merge_cmd () {
                "$merge_tool_path" -MF="$LOCAL" -TF="$REMOTE" \
                        -RF="$MERGED"
        fi
-       check_unchanged
 }
 
 translate_merge_tool_path() {
index b3c71b6236e343dd3b268a2288af853804b3acf6..ee6f374bceb8e14af5b424e64fbe9787006091e8 100644 (file)
@@ -16,6 +16,10 @@ merge_cmd () {
        fi >/dev/null 2>&1
 }
 
-translate_merge_tool_path() {
+translate_merge_tool_path () {
        echo DeltaWalker
 }
+
+exit_code_trustable () {
+       true
+}
index f138cb4e731018b40426337eb8062f40512df088..9b6355b98a71da2627b68c6543cea4f2515b8d54 100644 (file)
@@ -12,3 +12,7 @@ merge_cmd () {
                        --result="$MERGED" "$LOCAL" "$REMOTE"
        fi
 }
+
+exit_code_trustable () {
+       true
+}
index 02e0843f47e09a7cc6cdd2a9c70e36773ecc96af..5a3ae8b5695d3141ff0310a706495ea52037b464 100644 (file)
@@ -3,7 +3,6 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        if $base_present
        then
                "$merge_tool_path" \
@@ -13,5 +12,4 @@ merge_cmd () {
                "$merge_tool_path" \
                        "$LOCAL" "$MERGED" "$REMOTE" | cat
        fi
-       check_unchanged
 }
index 13c2e439def45fe6cf58ae4345355894463ba34f..6c5101c4f729d49c544436e9262ca75e4ce6cddd 100644 (file)
@@ -3,7 +3,6 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        if $base_present
        then
                "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" \
@@ -12,5 +11,4 @@ merge_cmd () {
                "$merge_tool_path" "$LOCAL" "$REMOTE" \
                        --default --mode=merge2 --to="$MERGED"
        fi
-       check_unchanged
 }
index 7b895fdb1f9955eb470a2614e0634bfcd26d90c9..d1ce513ff5d3b3db14dd1270d2181099e1134c2c 100644 (file)
@@ -20,3 +20,7 @@ merge_cmd () {
 translate_merge_tool_path() {
        echo emacs
 }
+
+exit_code_trustable () {
+       true
+}
index 7b524d4088ff198d70c5e40a378011f2e515770e..e72b06fc4d8ff76e06a0b972ae28df73efd4180d 100644 (file)
@@ -3,14 +3,12 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        if $base_present
        then
                "$merge_tool_path" -merge "$LOCAL" "$BASE" "$REMOTE" -o:"$MERGED" -nh
        else
                "$merge_tool_path" -merge "$LOCAL" "$REMOTE" -o:"$MERGED" -nh
        fi
-       check_unchanged
 }
 
 translate_merge_tool_path() {
index 793d1293b16c9b28a9ec5c70ec7fa0875ab0da54..0264ed5b20b29fec0fc5586408f88b0e8755d212 100644 (file)
@@ -21,3 +21,7 @@ merge_cmd () {
                >/dev/null 2>&1
        fi
 }
+
+exit_code_trustable () {
+       true
+}
index 433686c12a088195bbf21b2e409c21df199ba988..e8c0bfa678547258ff0f330ae756f3621e6aadc7 100644 (file)
@@ -5,3 +5,7 @@ can_merge () {
 diff_cmd () {
        "$merge_tool_path" "$LOCAL" "$REMOTE"
 }
+
+exit_code_trustable () {
+       true
+}
index 83ebdfb4c328ac79af38bfe935f0dbfa7fb6f53b..bc178e88827a1a0558e9fbee1a6f18f6ede83df1 100644 (file)
@@ -7,7 +7,7 @@ merge_cmd () {
        then
                check_meld_for_output_version
        fi
-       touch "$BACKUP"
+
        if test "$meld_has_output_option" = true
        then
                "$merge_tool_path" --output "$MERGED" \
@@ -15,7 +15,6 @@ merge_cmd () {
        else
                "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
        fi
-       check_unchanged
 }
 
 # Check whether we should use 'meld --output <file>'
index 0942b2a733592d3f0a5a39b4fc1defd635eb7b04..b608dd6de30aaab9b30729145029761330f9fb55 100644 (file)
@@ -3,7 +3,6 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        if $base_present
        then
                "$merge_tool_path" "$LOCAL" "$REMOTE" \
@@ -12,5 +11,4 @@ merge_cmd () {
                "$merge_tool_path" "$LOCAL" "$REMOTE" \
                        -merge "$MERGED" | cat
        fi
-       check_unchanged
 }
index 5a608abf9c77f436ab1472592e3d5777ef83805d..7a5b291dd28ad5b60ca0492480b800aaa9cc929e 100644 (file)
@@ -20,14 +20,12 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        if ! $base_present
        then
                cp -- "$LOCAL" "$BASE"
                create_virtual_base "$BASE" "$REMOTE"
        fi
        "$merge_tool_path" "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
-       check_unchanged
 }
 
 create_empty_file () {
index 618c438e8765a485ffcc70a105fb0cf46010540c..eee5cb57e3ccf7f1ad7ad150c37a8b6d7ab6d436 100644 (file)
@@ -10,3 +10,7 @@ merge_cmd () {
                "$merge_tool_path" -o "$MERGED" "$LOCAL" "$REMOTE"
        fi
 }
+
+exit_code_trustable () {
+       true
+}
index 3b89f1c82dc944fcbec889d24e8e7032fda612fc..d7ab666a59a2c8690861146bb6ae4874ed48e0de 100644 (file)
@@ -5,7 +5,6 @@ can_diff () {
 merge_cmd () {
        if $base_present
        then
-               touch "$BACKUP"
                basename="$(basename "$merge_tool_path" .exe)"
                if test "$basename" = "tortoisegitmerge"
                then
@@ -17,7 +16,6 @@ merge_cmd () {
                                -base:"$BASE" -mine:"$LOCAL" \
                                -theirs:"$REMOTE" -merged:"$MERGED"
                fi
-               check_unchanged
        else
                echo "$merge_tool_path cannot be used without a base" 1>&2
                return 1
index 74ea6d54793f62188cd88e93f1adfe74c5957dda..10d86f3e19304125cecf06ddad928b9ffe2d0c08 100644 (file)
@@ -4,7 +4,6 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        case "$1" in
        gvimdiff|vimdiff)
                if $base_present
@@ -31,7 +30,6 @@ merge_cmd () {
                fi
                ;;
        esac
-       check_unchanged
 }
 
 translate_merge_tool_path() {
@@ -44,3 +42,7 @@ translate_merge_tool_path() {
                ;;
        esac
 }
+
+exit_code_trustable () {
+       true
+}
index f3819d316a2c05d9fe1f850d6ac20b04d9df0417..74d03259fdf157c9ee07eec7b2c40727f5ce49dc 100644 (file)
@@ -6,10 +6,8 @@ diff_cmd () {
 merge_cmd () {
        # mergetool.winmerge.trustExitCode is implicitly false.
        # touch $BACKUP so that we can check_unchanged.
-       touch "$BACKUP"
        "$merge_tool_path" -u -e -dl Local -dr Remote \
                "$LOCAL" "$REMOTE" "$MERGED"
-       check_unchanged
 }
 
 translate_merge_tool_path() {
index 05b443394ba166a82a22abfcf27865b4627405e2..e284811ff28563458e76b3f03f95bf9eb11fa726 100644 (file)
@@ -6,7 +6,6 @@ diff_cmd () {
 }
 
 merge_cmd () {
-       touch "$BACKUP"
        if $base_present
        then
                "$merge_tool_path" -X --show-merged-pane \
@@ -21,5 +20,4 @@ merge_cmd () {
                        -R 'Accel.SearchForward: "Ctrl-G"' \
                        --merged-file "$MERGED" "$LOCAL" "$REMOTE"
        fi
-       check_unchanged
 }
index e7646968011234c09e1565577357a7678c015762..56ad9870bcfdfae68bd0fb5b57aa73e208bcb0fd 100644 (file)
@@ -606,7 +606,7 @@ sub minimize_url {
                        my $latest = $ra->get_latest_revnum;
                        $ra->get_log("", $latest, 0, 1, 0, 1, sub {});
                };
-       } while ($@ && ($c = shift @components));
+       } while ($@ && defined($c = shift @components));
 
        return canonicalize_url($url);
 }
index f5f7a70c6d9b8ef36ecfe282167714640cace6b1..bd9801024c9cc95b2846ae5ec221c4e9d18d5e94 100644 (file)
@@ -1231,8 +1231,14 @@ static int commit_contains(struct ref_filter *filter, struct commit *commit)
  * matches a pattern "refs/heads/mas") or a wildcard (e.g. the same ref
  * matches "refs/heads/mas*", too).
  */
-static int match_pattern(const char **patterns, const char *refname)
+static int match_pattern(const struct ref_filter *filter, const char *refname)
 {
+       const char **patterns = filter->name_patterns;
+       unsigned flags = 0;
+
+       if (filter->ignore_case)
+               flags |= WM_CASEFOLD;
+
        /*
         * When no '--format' option is given we need to skip the prefix
         * for matching refs of tags and branches.
@@ -1243,7 +1249,7 @@ static int match_pattern(const char **patterns, const char *refname)
               skip_prefix(refname, "refs/", &refname));
 
        for (; *patterns; patterns++) {
-               if (!wildmatch(*patterns, refname, 0, NULL))
+               if (!wildmatch(*patterns, refname, flags, NULL))
                        return 1;
        }
        return 0;
@@ -1255,9 +1261,15 @@ static int match_pattern(const char **patterns, const char *refname)
  * matches a pattern "refs/heads/" but not "refs/heads/m") or a
  * wildcard (e.g. the same ref matches "refs/heads/m*", too).
  */
-static int match_name_as_path(const char **pattern, const char *refname)
+static int match_name_as_path(const struct ref_filter *filter, const char *refname)
 {
+       const char **pattern = filter->name_patterns;
        int namelen = strlen(refname);
+       unsigned flags = WM_PATHNAME;
+
+       if (filter->ignore_case)
+               flags |= WM_CASEFOLD;
+
        for (; *pattern; pattern++) {
                const char *p = *pattern;
                int plen = strlen(p);
@@ -1280,8 +1292,8 @@ static int filter_pattern_match(struct ref_filter *filter, const char *refname)
        if (!*filter->name_patterns)
                return 1; /* No pattern always matches */
        if (filter->match_as_path)
-               return match_name_as_path(filter->name_patterns, refname);
-       return match_pattern(filter->name_patterns, refname);
+               return match_name_as_path(filter, refname);
+       return match_pattern(filter, refname);
 }
 
 /*
@@ -1536,18 +1548,20 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
        struct atom_value *va, *vb;
        int cmp;
        cmp_type cmp_type = used_atom[s->atom].type;
+       int (*cmp_fn)(const char *, const char *);
 
        get_ref_atom_value(a, s->atom, &va);
        get_ref_atom_value(b, s->atom, &vb);
+       cmp_fn = s->ignore_case ? strcasecmp : strcmp;
        if (s->version)
                cmp = versioncmp(va->s, vb->s);
        else if (cmp_type == FIELD_STR)
-               cmp = strcmp(va->s, vb->s);
+               cmp = cmp_fn(va->s, vb->s);
        else {
                if (va->ul < vb->ul)
                        cmp = -1;
                else if (va->ul == vb->ul)
-                       cmp = strcmp(a->refname, b->refname);
+                       cmp = cmp_fn(a->refname, b->refname);
                else
                        cmp = 1;
        }
index 14d435e2ccf0204312d1f72555f1c2c36fabd215..fc55fa3574620bfdc76b2997afc56909528e2275 100644 (file)
@@ -29,6 +29,7 @@ struct ref_sorting {
        struct ref_sorting *next;
        int atom; /* index into used_atom array (internal) */
        unsigned reverse : 1,
+               ignore_case : 1,
                version : 1;
 };
 
@@ -62,6 +63,7 @@ struct ref_filter {
 
        unsigned int with_commit_tag_algo : 1,
                match_as_path : 1,
+               ignore_case : 1,
                detached : 1;
        unsigned int kind,
                lines;
index f14c41f4c0d6d6c9bbfd18d6417d16f0e6068c1d..28d9d1063880b9b7e6ec18ea18c18f77fb99ef32 100644 (file)
@@ -274,7 +274,7 @@ static struct discovery *discover_refs(const char *service, int for_push)
        struct strbuf effective_url = STRBUF_INIT;
        struct discovery *last = last_discovery;
        int http_ret, maybe_smart = 0;
-       struct http_get_options options;
+       struct http_get_options http_options;
 
        if (last && !strcmp(service, last->service))
                return last;
@@ -291,15 +291,16 @@ static struct discovery *discover_refs(const char *service, int for_push)
                strbuf_addf(&refs_url, "service=%s", service);
        }
 
-       memset(&options, 0, sizeof(options));
-       options.content_type = &type;
-       options.charset = &charset;
-       options.effective_url = &effective_url;
-       options.base_url = &url;
-       options.no_cache = 1;
-       options.keep_error = 1;
+       memset(&http_options, 0, sizeof(http_options));
+       http_options.content_type = &type;
+       http_options.charset = &charset;
+       http_options.effective_url = &effective_url;
+       http_options.base_url = &url;
+       http_options.initial_request = 1;
+       http_options.no_cache = 1;
+       http_options.keep_error = 1;
 
-       http_ret = http_get_strbuf(refs_url.buf, &buffer, &options);
+       http_ret = http_get_strbuf(refs_url.buf, &buffer, &http_options);
        switch (http_ret) {
        case HTTP_OK:
                break;
@@ -314,6 +315,9 @@ static struct discovery *discover_refs(const char *service, int for_push)
                die("unable to access '%s': %s", url.buf, curl_errorstr);
        }
 
+       if (options.verbosity && !starts_with(refs_url.buf, url.buf))
+               warning(_("redirecting to %s"), url.buf);
+
        last= xcalloc(1, sizeof(*last_discovery));
        last->service = service;
        last->buf_alloc = strbuf_detach(&buffer, &last->len);
index 30b10ba143959bf2618872427f730a9f0e30d369..050e28bbc3d136509e8b7d909b27e9d954fa7754 100644 (file)
@@ -16,6 +16,7 @@
 #include "refs.h"
 #include "argv-array.h"
 #include "quote.h"
+#include "trailer.h"
 
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
 
@@ -56,30 +57,6 @@ static const char *get_todo_path(const struct replay_opts *opts)
        return git_path_todo_file();
 }
 
-static int is_rfc2822_line(const char *buf, int len)
-{
-       int i;
-
-       for (i = 0; i < len; i++) {
-               int ch = buf[i];
-               if (ch == ':')
-                       return 1;
-               if (!isalnum(ch) && ch != '-')
-                       break;
-       }
-
-       return 0;
-}
-
-static int is_cherry_picked_from_line(const char *buf, int len)
-{
-       /*
-        * We only care that it looks roughly like (cherry picked from ...)
-        */
-       return len > strlen(cherry_picked_prefix) + 1 &&
-               starts_with(buf, cherry_picked_prefix) && buf[len - 1] == ')';
-}
-
 /*
  * Returns 0 for non-conforming footer
  * Returns 1 for conforming footer
@@ -89,49 +66,25 @@ static int is_cherry_picked_from_line(const char *buf, int len)
 static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
        int ignore_footer)
 {
-       char prev;
-       int i, k;
-       int len = sb->len - ignore_footer;
-       const char *buf = sb->buf;
-       int found_sob = 0;
-
-       /* footer must end with newline */
-       if (!len || buf[len - 1] != '\n')
-               return 0;
+       struct trailer_info info;
+       int i;
+       int found_sob = 0, found_sob_last = 0;
 
-       prev = '\0';
-       for (i = len - 1; i > 0; i--) {
-               char ch = buf[i];
-               if (prev == '\n' && ch == '\n') /* paragraph break */
-                       break;
-               prev = ch;
-       }
+       trailer_info_get(&info, sb->buf);
 
-       /* require at least one blank line */
-       if (prev != '\n' || buf[i] != '\n')
+       if (info.trailer_start == info.trailer_end)
                return 0;
 
-       /* advance to start of last paragraph */
-       while (i < len - 1 && buf[i] == '\n')
-               i++;
-
-       for (; i < len; i = k) {
-               int found_rfc2822;
-
-               for (k = i; k < len && buf[k] != '\n'; k++)
-                       ; /* do nothing */
-               k++;
+       for (i = 0; i < info.trailer_nr; i++)
+               if (sob && !strncmp(info.trailers[i], sob->buf, sob->len)) {
+                       found_sob = 1;
+                       if (i == info.trailer_nr - 1)
+                               found_sob_last = 1;
+               }
 
-               found_rfc2822 = is_rfc2822_line(buf + i, k - i - 1);
-               if (found_rfc2822 && sob &&
-                   !strncmp(buf + i, sob->buf, sob->len))
-                       found_sob = k;
+       trailer_info_release(&info);
 
-               if (!(found_rfc2822 ||
-                     is_cherry_picked_from_line(buf + i, k - i - 1)))
-                       return 0;
-       }
-       if (found_sob == i)
+       if (found_sob_last)
                return 3;
        if (found_sob)
                return 2;
index 6f7d883de950af8ba6427537d09e021a4bed36bd..ece17315d671cf182f21c261d879c58f193cde09 100644 (file)
@@ -500,27 +500,67 @@ static int has_remote(const char *refname, const struct object_id *oid,
        return 1;
 }
 
-static int submodule_needs_pushing(const char *path, const unsigned char sha1[20])
+static int append_sha1_to_argv(const unsigned char sha1[20], void *data)
 {
-       if (add_submodule_odb(path) || !lookup_commit_reference(sha1))
+       struct argv_array *argv = data;
+       argv_array_push(argv, sha1_to_hex(sha1));
+       return 0;
+}
+
+static int check_has_commit(const unsigned char sha1[20], void *data)
+{
+       int *has_commit = data;
+
+       if (!lookup_commit_reference(sha1))
+               *has_commit = 0;
+
+       return 0;
+}
+
+static int submodule_has_commits(const char *path, struct sha1_array *commits)
+{
+       int has_commit = 1;
+
+       if (add_submodule_odb(path))
+               return 0;
+
+       sha1_array_for_each_unique(commits, check_has_commit, &has_commit);
+       return has_commit;
+}
+
+static int submodule_needs_pushing(const char *path, struct sha1_array *commits)
+{
+       if (!submodule_has_commits(path, commits))
+               /*
+                * NOTE: We do consider it safe to return "no" here. The
+                * correct answer would be "We do not know" instead of
+                * "No push needed", but it is quite hard to change
+                * the submodule pointer without having the submodule
+                * around. If a user did however change the submodules
+                * without having the submodule around, this indicates
+                * an expert who knows what they are doing or a
+                * maintainer integrating work from other people. In
+                * both cases it should be safe to skip this check.
+                */
                return 0;
 
        if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
                struct child_process cp = CHILD_PROCESS_INIT;
-               const char *argv[] = {"rev-list", NULL, "--not", "--remotes", "-n", "1" , NULL};
                struct strbuf buf = STRBUF_INIT;
                int needs_pushing = 0;
 
-               argv[1] = sha1_to_hex(sha1);
-               cp.argv = argv;
+               argv_array_push(&cp.args, "rev-list");
+               sha1_array_for_each_unique(commits, append_sha1_to_argv, &cp.args);
+               argv_array_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL);
+
                prepare_submodule_repo_env(&cp.env_array);
                cp.git_cmd = 1;
                cp.no_stdin = 1;
                cp.out = -1;
                cp.dir = path;
                if (start_command(&cp))
-                       die("Could not run 'git rev-list %s --not --remotes -n 1' command in submodule %s",
-                               sha1_to_hex(sha1), path);
+                       die("Could not run 'git rev-list <commits> --not --remotes -n 1' command in submodule %s",
+                                       path);
                if (strbuf_read(&buf, cp.out, 41))
                        needs_pushing = 1;
                finish_command(&cp);
@@ -532,19 +572,34 @@ static int submodule_needs_pushing(const char *path, const unsigned char sha1[20
        return 0;
 }
 
+static struct sha1_array *submodule_commits(struct string_list *submodules,
+                                           const char *path)
+{
+       struct string_list_item *item;
+
+       item = string_list_insert(submodules, path);
+       if (item->util)
+               return (struct sha1_array *) item->util;
+
+       /* NEEDSWORK: should we have sha1_array_init()? */
+       item->util = xcalloc(1, sizeof(struct sha1_array));
+       return (struct sha1_array *) item->util;
+}
+
 static void collect_submodules_from_diff(struct diff_queue_struct *q,
                                         struct diff_options *options,
                                         void *data)
 {
        int i;
-       struct string_list *needs_pushing = data;
+       struct string_list *submodules = data;
 
        for (i = 0; i < q->nr; i++) {
                struct diff_filepair *p = q->queue[i];
+               struct sha1_array *commits;
                if (!S_ISGITLINK(p->two->mode))
                        continue;
-               if (submodule_needs_pushing(p->two->path, p->two->oid.hash))
-                       string_list_insert(needs_pushing, p->two->path);
+               commits = submodule_commits(submodules, p->two->path);
+               sha1_array_append(commits, p->two->oid.hash);
        }
 }
 
@@ -560,46 +615,63 @@ static void find_unpushed_submodule_commits(struct commit *commit,
        diff_tree_combined_merge(commit, 1, &rev);
 }
 
-int find_unpushed_submodules(unsigned char new_sha1[20],
+static void free_submodules_sha1s(struct string_list *submodules)
+{
+       struct string_list_item *item;
+       for_each_string_list_item(item, submodules)
+               sha1_array_clear((struct sha1_array *) item->util);
+       string_list_clear(submodules, 1);
+}
+
+int find_unpushed_submodules(struct sha1_array *commits,
                const char *remotes_name, struct string_list *needs_pushing)
 {
        struct rev_info rev;
        struct commit *commit;
-       const char *argv[] = {NULL, NULL, "--not", "NULL", NULL};
-       int argc = ARRAY_SIZE(argv) - 1;
-       char *sha1_copy;
-
-       struct strbuf remotes_arg = STRBUF_INIT;
+       struct string_list submodules = STRING_LIST_INIT_DUP;
+       struct string_list_item *submodule;
+       struct argv_array argv = ARGV_ARRAY_INIT;
 
-       strbuf_addf(&remotes_arg, "--remotes=%s", remotes_name);
        init_revisions(&rev, NULL);
-       sha1_copy = xstrdup(sha1_to_hex(new_sha1));
-       argv[1] = sha1_copy;
-       argv[3] = remotes_arg.buf;
-       setup_revisions(argc, argv, &rev, NULL);
+
+       /* argv.argv[0] will be ignored by setup_revisions */
+       argv_array_push(&argv, "find_unpushed_submodules");
+       sha1_array_for_each_unique(commits, append_sha1_to_argv, &argv);
+       argv_array_push(&argv, "--not");
+       argv_array_pushf(&argv, "--remotes=%s", remotes_name);
+
+       setup_revisions(argv.argc, argv.argv, &rev, NULL);
        if (prepare_revision_walk(&rev))
                die("revision walk setup failed");
 
        while ((commit = get_revision(&rev)) != NULL)
-               find_unpushed_submodule_commits(commit, needs_pushing);
+               find_unpushed_submodule_commits(commit, &submodules);
 
        reset_revision_walk();
-       free(sha1_copy);
-       strbuf_release(&remotes_arg);
+       argv_array_clear(&argv);
+
+       for_each_string_list_item(submodule, &submodules) {
+               struct sha1_array *commits = (struct sha1_array *) submodule->util;
+
+               if (submodule_needs_pushing(submodule->string, commits))
+                       string_list_insert(needs_pushing, submodule->string);
+       }
+       free_submodules_sha1s(&submodules);
 
        return needs_pushing->nr;
 }
 
-static int push_submodule(const char *path)
+static int push_submodule(const char *path, int dry_run)
 {
        if (add_submodule_odb(path))
                return 1;
 
        if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
                struct child_process cp = CHILD_PROCESS_INIT;
-               const char *argv[] = {"push", NULL};
+               argv_array_push(&cp.args, "push");
+               if (dry_run)
+                       argv_array_push(&cp.args, "--dry-run");
 
-               cp.argv = argv;
                prepare_submodule_repo_env(&cp.env_array);
                cp.git_cmd = 1;
                cp.no_stdin = 1;
@@ -612,18 +684,20 @@ static int push_submodule(const char *path)
        return 1;
 }
 
-int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name)
+int push_unpushed_submodules(struct sha1_array *commits,
+                            const char *remotes_name,
+                            int dry_run)
 {
        int i, ret = 1;
        struct string_list needs_pushing = STRING_LIST_INIT_DUP;
 
-       if (!find_unpushed_submodules(new_sha1, remotes_name, &needs_pushing))
+       if (!find_unpushed_submodules(commits, remotes_name, &needs_pushing))
                return 1;
 
        for (i = 0; i < needs_pushing.nr; i++) {
                const char *path = needs_pushing.items[i].string;
                fprintf(stderr, "Pushing submodule '%s'\n", path);
-               if (!push_submodule(path)) {
+               if (!push_submodule(path, dry_run)) {
                        fprintf(stderr, "Unable to push submodule '%s'\n", path);
                        ret = 0;
                }
index d9e197a948fdab44b7a5df4161a5df9c3a2938ff..23d76682b1ea123d040a29f6f9613c3e1794f87d 100644 (file)
@@ -3,6 +3,7 @@
 
 struct diff_options;
 struct argv_array;
+struct sha1_array;
 
 enum {
        RECURSE_SUBMODULES_CHECK = -4,
@@ -62,9 +63,11 @@ int submodule_uses_gitfile(const char *path);
 int ok_to_remove_submodule(const char *path);
 int merge_submodule(unsigned char result[20], const char *path, const unsigned char base[20],
                    const unsigned char a[20], const unsigned char b[20], int search);
-int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name,
+int find_unpushed_submodules(struct sha1_array *commits, const char *remotes_name,
                struct string_list *needs_pushing);
-int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
+extern int push_unpushed_submodules(struct sha1_array *commits,
+                                   const char *remotes_name,
+                                   int dry_run);
 void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
 int parallel_submodules(void);
 
index c3e631394f4a47f32e62e266431607861929f328..69174c6e3110d5e214c048aceccf07232b813ce7 100644 (file)
@@ -123,6 +123,7 @@ ScriptAlias /error/ error.sh/
 </Files>
 
 RewriteEngine on
+RewriteRule ^/dumb-redir/(.*)$ /dumb/$1 [R=301]
 RewriteRule ^/smart-redir-perm/(.*)$ /smart/$1 [R=301]
 RewriteRule ^/smart-redir-temp/(.*)$ /smart/$1 [R=302]
 RewriteRule ^/smart-redir-auth/(.*)$ /auth/smart/$1 [R=301]
@@ -132,6 +133,19 @@ RewriteRule ^/ftp-redir/(.*)$ ftp://localhost:1000/$1 [R=302]
 RewriteRule ^/loop-redir/x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-(.*) /$1 [R=302]
 RewriteRule ^/loop-redir/(.*)$ /loop-redir/x-$1 [R=302]
 
+# The first rule issues a client-side redirect to something
+# that _doesn't_ look like a git repo. The second rule is a
+# server-side rewrite, so that it turns out the odd-looking
+# thing _is_ a git repo. The "[PT]" tells Apache to match
+# the usual ScriptAlias rules for /smart.
+RewriteRule ^/insane-redir/(.*)$ /intern-redir/$1/foo [R=301]
+RewriteRule ^/intern-redir/(.*)/foo$ /smart/$1 [PT]
+
+# Serve info/refs internally without redirecting, but
+# issue a redirect for any object requests.
+RewriteRule ^/redir-objects/(.*/info/refs)$ /dumb/$1 [PT]
+RewriteRule ^/redir-objects/(.*/objects/.*)$ /dumb/$1 [R=301]
+
 # Apache 2.2 does not understand <RequireAll>, so we use RewriteCond.
 # And as RewriteCond does not allow testing for non-matches, we match
 # the desired case first (one has abra, two has cadabra), and let it
index 4ea534e9fa70ea302d4a88a8bc922c100f896873..34891c4b1ad1c53ebc78b18484c7c146659ce68d 100755 (executable)
@@ -350,10 +350,9 @@ test_expect_success PERL 'required process filter should filter data' '
                cd repo &&
                git init &&
 
-               echo "git-stderr.log" >.gitignore &&
                echo "*.r filter=protocol" >.gitattributes &&
                git add . &&
-               git commit -m "test commit 1" &&
+               git commit -m "test commit 1" &&
                git branch empty-branch &&
 
                cp "$TEST_ROOT/test.o" test.r &&
@@ -378,7 +377,7 @@ test_expect_success PERL 'required process filter should filter data' '
                EOF
                test_cmp_count expected.log rot13-filter.log &&
 
-               filter_git commit -m "test commit 2" &&
+               filter_git commit -m "test commit 2" &&
                cat >expected.log <<-EOF &&
                        START
                        init handshake complete
index 1b1b65a6b0fc7ace4e18e8642a6c47631d7e6a43..465eeeacd3de1971c7256c84583377b3b47d520b 100755 (executable)
@@ -96,4 +96,44 @@ test_expect_success 'bare repo cleanup' '
        rm -rf bare1
 '
 
+test_expect_success 'broken main worktree still at the top' '
+       git init broken-main &&
+       (
+               cd broken-main &&
+               test_commit new &&
+               git worktree add linked &&
+               cat >expected <<-EOF &&
+               worktree $(pwd)
+               HEAD $_z40
+
+               EOF
+               cd linked &&
+               echo "worktree $(pwd)" >expected &&
+               echo "ref: .broken" >../.git/HEAD &&
+               git worktree list --porcelain | head -n 3 >actual &&
+               test_cmp ../expected actual &&
+               git worktree list | head -n 1 >actual.2 &&
+               grep -F "(error)" actual.2
+       )
+'
+
+test_expect_success 'linked worktrees are sorted' '
+       mkdir sorted &&
+       git init sorted/main &&
+       (
+               cd sorted/main &&
+               test_tick &&
+               test_commit new &&
+               git worktree add ../first &&
+               git worktree add ../second &&
+               git worktree list --porcelain | grep ^worktree >actual
+       ) &&
+       cat >expected <<-EOF &&
+       worktree $(pwd)/sorted/main
+       worktree $(pwd)/sorted/first
+       worktree $(pwd)/sorted/second
+       EOF
+       test_cmp expected sorted/main/actual
+'
+
 test_done
index 470f33466ca561484da080a522add72bed51ad6e..9a893b5fe746f03521454972199ecb2d243d79ab 100755 (executable)
@@ -575,13 +575,13 @@ test_expect_success 'merge removes empty directories' '
        test_must_fail test -d d
 '
 
-test_expect_failure 'merge-recursive simple w/submodule' '
+test_expect_success 'merge-recursive simple w/submodule' '
 
        git checkout submod &&
        git merge remove
 '
 
-test_expect_failure 'merge-recursive simple w/submodule result' '
+test_expect_success 'merge-recursive simple w/submodule result' '
 
        git ls-files -s >actual &&
        (
index c6a3ccba1b992cff7412bcf8139da7557981de94..52283dfc8cdafabba485fa6896279d600230abf9 100755 (executable)
@@ -89,6 +89,11 @@ test_expect_success 'git branch --list -v pattern shows branch summaries' '
        awk "{print \$NF}" <tmp >actual &&
        test_cmp expect actual
 '
+test_expect_success 'git branch --ignore-case --list -v pattern shows branch summaries' '
+       git branch --list --ignore-case -v BRANCH* >tmp &&
+       awk "{print \$NF}" <tmp >actual &&
+       test_cmp expect actual
+'
 
 test_expect_success 'git branch -v pattern does not show branch summaries' '
        test_must_fail git branch -v branch*
@@ -196,4 +201,28 @@ test_expect_success 'local-branch symrefs shortened properly' '
        test_cmp expect actual
 '
 
+test_expect_success 'sort branches, ignore case' '
+       (
+               git init sort-icase &&
+               cd sort-icase &&
+               test_commit initial &&
+               git branch branch-one &&
+               git branch BRANCH-two &&
+               git branch --list | awk "{print \$NF}" >actual &&
+               cat >expected <<-\EOF &&
+               BRANCH-two
+               branch-one
+               master
+               EOF
+               test_cmp expected actual &&
+               git branch --list -i | awk "{print \$NF}" >actual &&
+               cat >expected <<-\EOF &&
+               branch-one
+               BRANCH-two
+               master
+               EOF
+               test_cmp expected actual
+       )
+'
+
 test_done
index d5b896d4459e82cdc7eb363af77d8eef28871229..ebf4f5e4b2c1c1cc20a49888df14cedd14b49a8b 100755 (executable)
@@ -38,9 +38,6 @@ git_rebase_interactive () {
        git rebase -i "$1"
 }
 
-KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
-# The real reason "replace directory with submodule" fails is because a
-# directory "sub1" exists, but we reuse the suppression added for merge here
 test_submodule_switch "git_rebase_interactive"
 
 test_done
index 394f0005a195c1fbc713226c97ecee5cf4600007..4f2a263b63e14348032959059c15b160fecba39c 100755 (executable)
@@ -141,4 +141,16 @@ test_expect_success 'cherry-pick "-" works with arguments' '
        test_cmp expect actual
 '
 
+test_expect_success 'cherry-pick works with dirty renamed file' '
+       test_commit to-rename &&
+       git checkout -b unrelated &&
+       test_commit unrelated &&
+       git checkout @{-1} &&
+       git mv to-rename.t renamed &&
+       test_tick &&
+       git commit -m renamed &&
+       echo modified >renamed &&
+       git cherry-pick refs/heads/unrelated
+'
+
 test_done
index 9cce5ae8815a11e3453f5669b0592f7f7659009b..bf0a5c9887235afb5e336a34815d6bb3d64875d8 100755 (executable)
@@ -25,9 +25,8 @@ Signed-off-by: B.U. Thor <buthor@example.com>"
 
 mesg_broken_footer="$mesg_no_footer
 
-The signed-off-by string should begin with the words Signed-off-by followed
-by a colon and space, and then the signers name and email address. e.g.
-Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
+This is not recognized as a footer because Myfooter is not a recognized token.
+Myfooter: A.U. Thor <author@example.com>"
 
 mesg_with_footer_sob="$mesg_with_footer
 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
@@ -112,6 +111,17 @@ test_expect_success 'cherry-pick -s inserts blank line after non-conforming foot
        test_cmp expect actual
 '
 
+test_expect_success 'cherry-pick -s recognizes trailer config' '
+       pristine_detach initial &&
+       git -c "trailer.Myfooter.ifexists=add" cherry-pick -s mesg-broken-footer &&
+       cat <<-EOF >expect &&
+               $mesg_broken_footer
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'cherry-pick -x inserts blank line when conforming footer not found' '
        pristine_detach initial &&
        sha1=$(git rev-parse mesg-no-footer^0) &&
index e1a6ccc00c5988cfa8808bccc49a5e21703166b6..2de3e18ce68a94111c8dfcca858b8515ea8919c1 100755 (executable)
@@ -766,4 +766,13 @@ test_expect_success 'stash list --cc shows combined diff' '
        test_cmp expect actual
 '
 
+test_expect_success 'stash is not confused by partial renames' '
+       mv file renamed &&
+       git add renamed &&
+       git stash &&
+       git stash apply &&
+       test_path_is_file renamed &&
+       test_path_is_missing file
+'
+
 test_done
index ba4902df2b605f89ec2abcac50abefc2f23fc9bf..482112ca339f05fc31e6f9c2c6168971a1121e87 100755 (executable)
@@ -1294,8 +1294,7 @@ EOF
 4:Subject: [PATCH] subject
 8:
 10:Signed-off-by: example happens to be wrapped here.
-11:
-12:Signed-off-by: C O Mitter <committer@example.com>
+11:Signed-off-by: C O Mitter <committer@example.com>
 EOF
        test_cmp expected actual
 '
@@ -1368,7 +1367,7 @@ EOF
        test_cmp expected actual
 '
 
-test_expect_success 'signoff: detect garbage in non-conforming footer' '
+test_expect_success 'signoff: tolerate garbage in conforming footer' '
        append_signoff <<\EOF >actual &&
 subject
 
@@ -1383,8 +1382,36 @@ EOF
 8:
 10:
 13:Signed-off-by: C O Mitter <committer@example.com>
-14:
-15:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: respect trailer config' '
+       append_signoff <<\EOF >actual &&
+subject
+
+Myfooter: x
+Some Trash
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+11:
+12:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual &&
+
+       test_config trailer.Myfooter.ifexists add &&
+       append_signoff <<\EOF >actual &&
+subject
+
+Myfooter: x
+Some Trash
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+11:Signed-off-by: C O Mitter <committer@example.com>
 EOF
        test_cmp expected actual
 '
index 198ce8475416be494fc023de3835828332da424d..1524ff5ba692d9c962ec51ef0c7948aca6ddf240 100755 (executable)
@@ -427,7 +427,31 @@ test_expect_success 'push unpushable submodule recursively fails' '
                cd submodule.git &&
                git rev-parse master >../actual
        ) &&
+       test_when_finished git -C work reset --hard master^ &&
        test_cmp expected actual
 '
 
+test_expect_success 'push --dry-run does not recursively update submodules' '
+       (
+               cd work/gar/bage &&
+               git checkout master &&
+               git rev-parse master >../../../expected_submodule &&
+               > junk9 &&
+               git add junk9 &&
+               git commit -m "Ninth junk" &&
+
+               # Go up to 'work' directory
+               cd ../.. &&
+               git checkout master &&
+               git rev-parse master >../expected_pub &&
+               git add gar/bage &&
+               git commit -m "Ninth commit for gar/bage" &&
+               git push --dry-run --recurse-submodules=on-demand ../pub.git master
+       ) &&
+       git -C submodule.git rev-parse master >actual_submodule &&
+       git -C pub.git rev-parse master >actual_pub &&
+       test_cmp expected_pub actual_pub &&
+       test_cmp expected_submodule actual_submodule
+'
+
 test_done
index 7641417b4a3848fa9d065572e5a8248fea5c7574..264a1ab8b0ea794ce398d9d5c3a40adb31bd0ff9 100755 (executable)
@@ -307,5 +307,66 @@ test_expect_success 'remote-http complains cleanly about malformed urls' '
        test_must_fail git remote-http http::/example.com/repo.git
 '
 
+test_expect_success 'redirects can be forbidden/allowed' '
+       test_must_fail git -c http.followRedirects=false \
+               clone $HTTPD_URL/dumb-redir/repo.git dumb-redir &&
+       git -c http.followRedirects=true \
+               clone $HTTPD_URL/dumb-redir/repo.git dumb-redir 2>stderr
+'
+
+test_expect_success 'redirects are reported to stderr' '
+       # just look for a snippet of the redirected-to URL
+       test_i18ngrep /dumb/ stderr
+'
+
+test_expect_success 'non-initial redirects can be forbidden' '
+       test_must_fail git -c http.followRedirects=initial \
+               clone $HTTPD_URL/redir-objects/repo.git redir-objects &&
+       git -c http.followRedirects=true \
+               clone $HTTPD_URL/redir-objects/repo.git redir-objects
+'
+
+test_expect_success 'http.followRedirects defaults to "initial"' '
+       test_must_fail git clone $HTTPD_URL/redir-objects/repo.git default
+'
+
+# The goal is for a clone of the "evil" repository, which has no objects
+# itself, to cause the client to fetch objects from the "victim" repository.
+test_expect_success 'set up evil alternates scheme' '
+       victim=$HTTPD_DOCUMENT_ROOT_PATH/victim.git &&
+       git init --bare "$victim" &&
+       git -C "$victim" --work-tree=. commit --allow-empty -m secret &&
+       git -C "$victim" repack -ad &&
+       git -C "$victim" update-server-info &&
+       sha1=$(git -C "$victim" rev-parse HEAD) &&
+
+       evil=$HTTPD_DOCUMENT_ROOT_PATH/evil.git &&
+       git init --bare "$evil" &&
+       # do this by hand to avoid object existence check
+       printf "%s\\t%s\\n" $sha1 refs/heads/master >"$evil/info/refs"
+'
+
+# Here we'll just redirect via HTTP. In a real-world attack these would be on
+# different servers, but we should reject it either way.
+test_expect_success 'http-alternates is a non-initial redirect' '
+       echo "$HTTPD_URL/dumb/victim.git/objects" \
+               >"$evil/objects/info/http-alternates" &&
+       test_must_fail git -c http.followRedirects=initial \
+               clone $HTTPD_URL/dumb/evil.git evil-initial &&
+       git -c http.followRedirects=true \
+               clone $HTTPD_URL/dumb/evil.git evil-initial
+'
+
+# Curl supports a lot of protocols that we'd prefer not to allow
+# http-alternates to use, but it's hard to test whether curl has
+# accessed, say, the SMTP protocol, because we are not running an SMTP server.
+# But we can check that it does not allow access to file://, which would
+# otherwise allow this clone to complete.
+test_expect_success 'http-alternates cannot point at funny protocols' '
+       echo "file://$victim/objects" >"$evil/objects/info/http-alternates" &&
+       test_must_fail git -c http.followRedirects=true \
+               clone "$HTTPD_URL/dumb/evil.git" evil-file
+'
+
 stop_httpd
 test_done
index 1ec5b2747a2100d3ae043cde5a2436eed2d52aec..6e5b9e42fb6d3f8c25c1a08388c4eb5ec3284500 100755 (executable)
@@ -119,6 +119,10 @@ test_expect_success 'redirects re-root further requests' '
        git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
 '
 
+test_expect_success 're-rooting dies on insane schemes' '
+       test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
+'
+
 test_expect_success 'clone from password-protected repository' '
        echo two >expect &&
        set_askpass user@host pass@host &&
index 0d105d54174e061b20707de808b284314f730667..044cc152f83b05e090a65268c8818d56adb4422b 100755 (executable)
@@ -18,6 +18,7 @@ test_proto "smart http" http "$HTTPD_URL/smart/repo.git"
 
 test_expect_success 'curl redirects respect whitelist' '
        test_must_fail env GIT_ALLOW_PROTOCOL=http:https \
+                          GIT_SMART_HTTP=0 \
                git clone "$HTTPD_URL/ftp-redir/repo.git" 2>stderr &&
        {
                test_i18ngrep "ftp.*disabled" stderr ||
index 64a9850e3197dc2cbff00593f04a5fa196dbd632..8c617981a3a06c1ff49f03a2914bfdc31c0e293c 100755 (executable)
@@ -83,12 +83,24 @@ test_expect_success 'final^1^@ = final^1^1 final^1^2' '
        test_cmp expect actual
 '
 
+test_expect_success 'symbolic final^1^@ = final^1^1 final^1^2' '
+       git rev-parse --symbolic final^1^1 final^1^2 >expect &&
+       git rev-parse --symbolic final^1^@ >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'final^1^! = final^1 ^final^1^1 ^final^1^2' '
        git rev-parse final^1 ^final^1^1 ^final^1^2 >expect &&
        git rev-parse final^1^! >actual &&
        test_cmp expect actual
 '
 
+test_expect_success 'symbolic final^1^! = final^1 ^final^1^1 ^final^1^2' '
+       git rev-parse --symbolic final^1 ^final^1^1 ^final^1^2 >expect &&
+       git rev-parse --symbolic final^1^! >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'large graft octopus' '
        test_cmp_rev_output b31 "git rev-parse --verify b1^30"
 '
@@ -143,6 +155,12 @@ test_expect_success 'rev-parse merge^-2 = merge^2..merge' '
        test_cmp expect actual
 '
 
+test_expect_success 'symbolic merge^-1 = merge^1..merge' '
+       git rev-parse --symbolic merge^1..merge >expect &&
+       git rev-parse --symbolic merge^-1 >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'rev-parse merge^-0 (invalid parent)' '
        test_must_fail git rev-parse merge^-0
 '
index 8b0f71a2ac15d65f977b0daa2a53ad47b64a043a..07869b0c09da1313dd5564c2318dc5d44818f3a9 100755 (executable)
@@ -27,6 +27,30 @@ test_expect_success 'listing all tags in an empty tree should output nothing' '
        test $(git tag | wc -l) -eq 0
 '
 
+test_expect_success 'sort tags, ignore case' '
+       (
+               git init sort &&
+               cd sort &&
+               test_commit initial &&
+               git tag tag-one &&
+               git tag TAG-two &&
+               git tag -l >actual &&
+               cat >expected <<-\EOF &&
+               TAG-two
+               initial
+               tag-one
+               EOF
+               test_cmp expected actual &&
+               git tag -l -i >actual &&
+               cat >expected <<-\EOF &&
+               initial
+               tag-one
+               TAG-two
+               EOF
+               test_cmp expected actual
+       )
+'
+
 test_expect_success 'looking for a tag in an empty tree should fail' \
        '! (tag_exists mytag)'
 
@@ -81,6 +105,9 @@ test_expect_success 'listing all tags if one exists should output that tag' '
 test_expect_success 'listing a tag using a matching pattern should succeed' \
        'git tag -l mytag'
 
+test_expect_success 'listing a tag with --ignore-case' \
+       'test $(git tag -l --ignore-case MYTAG) = mytag'
+
 test_expect_success \
        'listing a tag using a matching pattern should output that tag' \
        'test $(git tag -l mytag) = mytag'
index d84897a67a3c365e280f88b36f43fc49e1ac9d7b..4003a27e6aa117e30446bca2d91f230f144ae8a9 100755 (executable)
@@ -460,6 +460,42 @@ $alt" &&
        test_cmp expected actual
 '
 
+test_expect_success 'signoff respects trailer config' '
+
+       echo 5 >positive &&
+       git add positive &&
+       git commit -s -m "subject
+
+non-trailer line
+Myfooter: x" &&
+       git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+       (
+               echo subject
+               echo
+               echo non-trailer line
+               echo Myfooter: x
+               echo
+               echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
+       ) >expected &&
+       test_cmp expected actual &&
+
+       echo 6 >positive &&
+       git add positive &&
+       git -c "trailer.Myfooter.ifexists=add" commit -s -m "subject
+
+non-trailer line
+Myfooter: x" &&
+       git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+       (
+               echo subject
+               echo
+               echo non-trailer line
+               echo Myfooter: x
+               echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
+       ) >expected &&
+       test_cmp expected actual
+'
+
 test_expect_success 'multiple -m' '
 
        >negative &&
index f80bdb81e1f12124e32d5cd2c5c0ecdcd82dc782..e90413204ee32cafc3380244a5cf013eadcd72c1 100755 (executable)
@@ -105,7 +105,7 @@ test_expect_success 'not uptodate file porcelain checkout error' '
 '
 
 cat >expect <<\EOF
-error: Updating the following directories would lose untracked files in it:
+error: Updating the following directories would lose untracked files in them:
        rep
        rep2
 
index 6d9f21511fe1062565d8d08f60c385cffd94cac6..63d36fb28e44426708a743979c4bc341bdac714e 100755 (executable)
@@ -591,7 +591,8 @@ test_expect_success 'filenames seen by tools start with ./' '
 
 test_lazy_prereq MKTEMP '
        tempdir=$(mktemp -d -t foo.XXXXXX) &&
-       test -d "$tempdir"
+       test -d "$tempdir" &&
+       rmdir "$tempdir"
 '
 
 test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToTemp' '
index 593152817dadaf1804f4a851c51b8bf1cbf52db9..e37239e657964e948e51e5ac186f5fdf4fab6003 100755 (executable)
@@ -413,6 +413,75 @@ test_expect_success 'submit --prepare-p4-only' '
        )
 '
 
+test_expect_success 'submit --shelve' '
+       test_when_finished cleanup_git &&
+       git p4 clone --dest="$git" //depot &&
+       (
+               cd "$cli" &&
+               p4 revert ... &&
+               cd "$git" &&
+               git config git-p4.skipSubmitEdit true &&
+               test_commit "shelveme1" &&
+               git p4 submit --origin=HEAD^ &&
+
+               echo 654321 >shelveme2.t &&
+               echo 123456 >>shelveme1.t &&
+               git add shelveme* &&
+               git commit -m"shelvetest" &&
+               git p4 submit --shelve --origin=HEAD^ &&
+
+               test_path_is_file shelveme1.t &&
+               test_path_is_file shelveme2.t
+       ) &&
+       (
+               cd "$cli" &&
+               change=$(p4 -G changes -s shelved -m 1 //depot/... | \
+                        marshal_dump change) &&
+               p4 describe -S $change | grep shelveme2 &&
+               p4 describe -S $change | grep 123456 &&
+               test_path_is_file shelveme1.t &&
+               test_path_is_missing shelveme2.t
+       )
+'
+
+# Update an existing shelved changelist
+
+test_expect_success 'submit --update-shelve' '
+       test_when_finished cleanup_git &&
+       git p4 clone --dest="$git" //depot &&
+       (
+               cd "$cli" &&
+               p4 revert ... &&
+               cd "$git" &&
+               git config git-p4.skipSubmitEdit true &&
+               test_commit "test-update-shelved-change" &&
+               git p4 submit --origin=HEAD^ --shelve &&
+
+               shelf_cl=$(p4 -G changes -s shelved -m 1 |\
+                       marshal_dump change) &&
+               test -n $shelf_cl &&
+               echo "updating shelved change list $shelf_cl" &&
+
+               echo "updated-line" >>shelf.t &&
+               echo added-file.t >added-file.t &&
+               git add shelf.t added-file.t &&
+               git rm -f test-update-shelved-change.t &&
+               git commit --amend -C HEAD &&
+               git show --stat HEAD &&
+               git p4 submit -v --origin HEAD^ --update-shelve $shelf_cl &&
+               echo "done git p4 submit"
+       ) &&
+       (
+               cd "$cli" &&
+               change=$(p4 -G changes -s shelved -m 1 //depot/... | \
+                        marshal_dump change) &&
+               p4 unshelve -c $change -s $change &&
+               grep -q updated-line shelf.t &&
+               p4 describe -S $change | grep added-file.t &&
+               test_path_is_missing test-update-shelved-change.t
+       )
+'
+
 test_expect_success 'kill p4d' '
        kill_p4d
 '
index 110a7e792475fcf19ef782fae1d265ae81653853..734b8db4cbd557cf8e703cc4e2b085185634baba 100755 (executable)
@@ -42,6 +42,8 @@ test_expect_success 'Create repo with binary files' '
        (
                cd "$cli" &&
 
+               >file0.dat &&
+               p4 add file0.dat &&
                echo "content 1 txt 23 bytes" >file1.txt &&
                p4 add file1.txt &&
                echo "content 2-3 bin 25 bytes" >file2.dat &&
index f0ecde2d2f8b35c565ab176c76882a5fee8d8fb2..11f0b9fb40bcedbfcd3111fa8076ce0d9e1eb20f 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -46,6 +46,8 @@ static LIST_HEAD(conf_head);
 
 static char *separators = ":";
 
+static int configured;
+
 #define TRAILER_ARG_STRING "$ARG"
 
 static const char *git_generated_prefixes[] = {
@@ -102,12 +104,12 @@ static int same_trailer(struct trailer_item *a, struct arg_item *b)
        return same_token(a, b) && same_value(a, b);
 }
 
-static inline int contains_only_spaces(const char *str)
+static inline int is_blank_line(const char *str)
 {
        const char *s = str;
-       while (*s && isspace(*s))
+       while (*s && *s != '\n' && isspace(*s))
                s++;
-       return !*s;
+       return !*s || *s == '\n';
 }
 
 static inline void strbuf_replace(struct strbuf *sb, const char *a, const char *b)
@@ -546,6 +548,17 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb)
        return 0;
 }
 
+static void ensure_configured(void)
+{
+       if (configured)
+               return;
+
+       /* Default config must be setup first */
+       git_config(git_trailer_default_config, NULL);
+       git_config(git_trailer_config, NULL);
+       configured = 1;
+}
+
 static const char *token_from_item(struct arg_item *item, char *tok)
 {
        if (item->conf.key)
@@ -563,15 +576,32 @@ static int token_matches_item(const char *tok, struct arg_item *item, int tok_le
 }
 
 /*
- * Return the location of the first separator in line, or -1 if there is no
- * separator.
+ * If the given line is of the form
+ * "<token><optional whitespace><separator>..." or "<separator>...", return the
+ * location of the separator. Otherwise, return -1.  The optional whitespace
+ * is allowed there primarily to allow things like "Bug #43" where <token> is
+ * "Bug" and <separator> is "#".
+ *
+ * The separator-starts-line case (in which this function returns 0) is
+ * distinguished from the non-well-formed-line case (in which this function
+ * returns -1) because some callers of this function need such a distinction.
  */
 static int find_separator(const char *line, const char *separators)
 {
-       int loc = strcspn(line, separators);
-       if (!line[loc])
-               return -1;
-       return loc;
+       int whitespace_found = 0;
+       const char *c;
+       for (c = line; *c; c++) {
+               if (strchr(separators, *c))
+                       return c - line;
+               if (!whitespace_found && (isalnum(*c) || *c == '-'))
+                       continue;
+               if (c != line && (*c == ' ' || *c == '\t')) {
+                       whitespace_found = 1;
+                       continue;
+               }
+               break;
+       }
+       return -1;
 }
 
 /*
@@ -685,51 +715,71 @@ static void process_command_line_args(struct list_head *arg_head,
        free(cl_separators);
 }
 
-static struct strbuf **read_input_file(const char *file)
+static void read_input_file(struct strbuf *sb, const char *file)
 {
-       struct strbuf **lines;
-       struct strbuf sb = STRBUF_INIT;
-
        if (file) {
-               if (strbuf_read_file(&sb, file, 0) < 0)
+               if (strbuf_read_file(sb, file, 0) < 0)
                        die_errno(_("could not read input file '%s'"), file);
        } else {
-               if (strbuf_read(&sb, fileno(stdin), 0) < 0)
+               if (strbuf_read(sb, fileno(stdin), 0) < 0)
                        die_errno(_("could not read from stdin"));
        }
+}
 
-       lines = strbuf_split(&sb, '\n');
+static const char *next_line(const char *str)
+{
+       const char *nl = strchrnul(str, '\n');
+       return nl + !!*nl;
+}
 
-       strbuf_release(&sb);
+/*
+ * Return the position of the start of the last line. If len is 0, return -1.
+ */
+static int last_line(const char *buf, size_t len)
+{
+       int i;
+       if (len == 0)
+               return -1;
+       if (len == 1)
+               return 0;
+       /*
+        * Skip the last character (in addition to the null terminator),
+        * because if the last character is a newline, it is considered as part
+        * of the last line anyway.
+        */
+       i = len - 2;
 
-       return lines;
+       for (; i >= 0; i--) {
+               if (buf[i] == '\n')
+                       return i + 1;
+       }
+       return 0;
 }
 
 /*
- * Return the (0 based) index of the start of the patch or the line
- * count if there is no patch in the message.
+ * Return the position of the start of the patch or the length of str if there
+ * is no patch in the message.
  */
-static int find_patch_start(struct strbuf **lines, int count)
+static int find_patch_start(const char *str)
 {
-       int i;
+       const char *s;
 
-       /* Get the start of the patch part if any */
-       for (i = 0; i < count; i++) {
-               if (starts_with(lines[i]->buf, "---"))
-                       return i;
+       for (s = str; *s; s = next_line(s)) {
+               if (starts_with(s, "---"))
+                       return s - str;
        }
 
-       return count;
+       return s - str;
 }
 
 /*
- * Return the (0 based) index of the first trailer line or count if
- * there are no trailers. Trailers are searched only in the lines from
- * index (count - 1) down to index 0.
+ * Return the position of the first trailer line or len if there are no
+ * trailers.
  */
-static int find_trailer_start(struct strbuf **lines, int count)
+static int find_trailer_start(const char *buf, size_t len)
 {
-       int start, end_of_title, only_spaces = 1;
+       const char *s;
+       int end_of_title, l, only_spaces = 1;
        int recognized_prefix = 0, trailer_lines = 0, non_trailer_lines = 0;
        /*
         * Number of possible continuation lines encountered. This will be
@@ -741,13 +791,13 @@ static int find_trailer_start(struct strbuf **lines, int count)
        int possible_continuation_lines = 0;
 
        /* The first paragraph is the title and cannot be trailers */
-       for (start = 0; start < count; start++) {
-               if (lines[start]->buf[0] == comment_line_char)
+       for (s = buf; s < buf + len; s = next_line(s)) {
+               if (s[0] == comment_line_char)
                        continue;
-               if (contains_only_spaces(lines[start]->buf))
+               if (is_blank_line(s))
                        break;
        }
-       end_of_title = start;
+       end_of_title = s - buf;
 
        /*
         * Get the start of the trailers by looking starting from the end for a
@@ -755,30 +805,33 @@ static int find_trailer_start(struct strbuf **lines, int count)
         * trailers, or (ii) contains at least one Git-generated trailer and
         * consists of at least 25% trailers.
         */
-       for (start = count - 1; start >= end_of_title; start--) {
+       for (l = last_line(buf, len);
+            l >= end_of_title;
+            l = last_line(buf, l)) {
+               const char *bol = buf + l;
                const char **p;
                int separator_pos;
 
-               if (lines[start]->buf[0] == comment_line_char) {
+               if (bol[0] == comment_line_char) {
                        non_trailer_lines += possible_continuation_lines;
                        possible_continuation_lines = 0;
                        continue;
                }
-               if (contains_only_spaces(lines[start]->buf)) {
+               if (is_blank_line(bol)) {
                        if (only_spaces)
                                continue;
                        non_trailer_lines += possible_continuation_lines;
                        if (recognized_prefix &&
                            trailer_lines * 3 >= non_trailer_lines)
-                               return start + 1;
-                       if (trailer_lines && !non_trailer_lines)
-                               return start + 1;
-                       return count;
+                               return next_line(bol) - buf;
+                       else if (trailer_lines && !non_trailer_lines)
+                               return next_line(bol) - buf;
+                       return len;
                }
                only_spaces = 0;
 
                for (p = git_generated_prefixes; *p; p++) {
-                       if (starts_with(lines[start]->buf, *p)) {
+                       if (starts_with(bol, *p)) {
                                trailer_lines++;
                                possible_continuation_lines = 0;
                                recognized_prefix = 1;
@@ -786,8 +839,8 @@ static int find_trailer_start(struct strbuf **lines, int count)
                        }
                }
 
-               separator_pos = find_separator(lines[start]->buf, separators);
-               if (separator_pos >= 1 && !isspace(lines[start]->buf[0])) {
+               separator_pos = find_separator(bol, separators);
+               if (separator_pos >= 1 && !isspace(bol[0])) {
                        struct list_head *pos;
 
                        trailer_lines++;
@@ -797,13 +850,13 @@ static int find_trailer_start(struct strbuf **lines, int count)
                        list_for_each(pos, &conf_head) {
                                struct arg_item *item;
                                item = list_entry(pos, struct arg_item, list);
-                               if (token_matches_item(lines[start]->buf, item,
+                               if (token_matches_item(bol, item,
                                                       separator_pos)) {
                                        recognized_prefix = 1;
                                        break;
                                }
                        }
-               } else if (isspace(lines[start]->buf[0]))
+               } else if (isspace(bol[0]))
                        possible_continuation_lines++;
                else {
                        non_trailer_lines++;
@@ -814,97 +867,64 @@ static int find_trailer_start(struct strbuf **lines, int count)
                ;
        }
 
-       return count;
-}
-
-/* Get the index of the end of the trailers */
-static int find_trailer_end(struct strbuf **lines, int patch_start)
-{
-       struct strbuf sb = STRBUF_INIT;
-       int i, ignore_bytes;
-
-       for (i = 0; i < patch_start; i++)
-               strbuf_addbuf(&sb, lines[i]);
-       ignore_bytes = ignore_non_trailer(&sb);
-       strbuf_release(&sb);
-       for (i = patch_start - 1; i >= 0 && ignore_bytes > 0; i--)
-               ignore_bytes -= lines[i]->len;
-
-       return i + 1;
+       return len;
 }
 
-static int has_blank_line_before(struct strbuf **lines, int start)
+/* Return the position of the end of the trailers. */
+static int find_trailer_end(const char *buf, size_t len)
 {
-       for (;start >= 0; start--) {
-               if (lines[start]->buf[0] == comment_line_char)
-                       continue;
-               return contains_only_spaces(lines[start]->buf);
-       }
-       return 0;
+       return len - ignore_non_trailer(buf, len);
 }
 
-static void print_lines(FILE *outfile, struct strbuf **lines, int start, int end)
+static int ends_with_blank_line(const char *buf, size_t len)
 {
-       int i;
-       for (i = start; lines[i] && i < end; i++)
-               fprintf(outfile, "%s", lines[i]->buf);
+       int ll = last_line(buf, len);
+       if (ll < 0)
+               return 0;
+       return is_blank_line(buf + ll);
 }
 
 static int process_input_file(FILE *outfile,
-                             struct strbuf **lines,
+                             const char *str,
                              struct list_head *head)
 {
-       int count = 0;
-       int patch_start, trailer_start, trailer_end, i;
+       struct trailer_info info;
        struct strbuf tok = STRBUF_INIT;
        struct strbuf val = STRBUF_INIT;
-       struct trailer_item *last = NULL;
-
-       /* Get the line count */
-       while (lines[count])
-               count++;
+       int i;
 
-       patch_start = find_patch_start(lines, count);
-       trailer_end = find_trailer_end(lines, patch_start);
-       trailer_start = find_trailer_start(lines, trailer_end);
+       trailer_info_get(&info, str);
 
        /* Print lines before the trailers as is */
-       print_lines(outfile, lines, 0, trailer_start);
+       fwrite(str, 1, info.trailer_start - str, outfile);
 
-       if (!has_blank_line_before(lines, trailer_start - 1))
+       if (!info.blank_line_before_trailer)
                fprintf(outfile, "\n");
 
-       /* Parse trailer lines */
-       for (i = trailer_start; i < trailer_end; i++) {
+       for (i = 0; i < info.trailer_nr; i++) {
                int separator_pos;
-               if (lines[i]->buf[0] == comment_line_char)
+               char *trailer = info.trailers[i];
+               if (trailer[0] == comment_line_char)
                        continue;
-               if (last && isspace(lines[i]->buf[0])) {
-                       struct strbuf sb = STRBUF_INIT;
-                       strbuf_addf(&sb, "%s\n%s", last->value, lines[i]->buf);
-                       strbuf_strip_suffix(&sb, "\n");
-                       free(last->value);
-                       last->value = strbuf_detach(&sb, NULL);
-                       continue;
-               }
-               separator_pos = find_separator(lines[i]->buf, separators);
+               separator_pos = find_separator(trailer, separators);
                if (separator_pos >= 1) {
-                       parse_trailer(&tok, &val, NULL, lines[i]->buf,
+                       parse_trailer(&tok, &val, NULL, trailer,
                                      separator_pos);
-                       last = add_trailer_item(head,
-                                               strbuf_detach(&tok, NULL),
-                                               strbuf_detach(&val, NULL));
+                       add_trailer_item(head,
+                                        strbuf_detach(&tok, NULL),
+                                        strbuf_detach(&val, NULL));
                } else {
-                       strbuf_addbuf(&val, lines[i]);
+                       strbuf_addstr(&val, trailer);
                        strbuf_strip_suffix(&val, "\n");
                        add_trailer_item(head,
                                         NULL,
                                         strbuf_detach(&val, NULL));
-                       last = NULL;
                }
        }
 
-       return trailer_end;
+       trailer_info_release(&info);
+
+       return info.trailer_end - str;
 }
 
 static void free_all(struct list_head *head)
@@ -951,21 +971,19 @@ void process_trailers(const char *file, int in_place, int trim_empty, struct str
 {
        LIST_HEAD(head);
        LIST_HEAD(arg_head);
-       struct strbuf **lines;
+       struct strbuf sb = STRBUF_INIT;
        int trailer_end;
        FILE *outfile = stdout;
 
-       /* Default config must be setup first */
-       git_config(git_trailer_default_config, NULL);
-       git_config(git_trailer_config, NULL);
+       ensure_configured();
 
-       lines = read_input_file(file);
+       read_input_file(&sb, file);
 
        if (in_place)
                outfile = create_in_place_tempfile(file);
 
        /* Print the lines before the trailers */
-       trailer_end = process_input_file(outfile, lines, &head);
+       trailer_end = process_input_file(outfile, sb.buf, &head);
 
        process_command_line_args(&arg_head, trailers);
 
@@ -976,11 +994,62 @@ void process_trailers(const char *file, int in_place, int trim_empty, struct str
        free_all(&head);
 
        /* Print the lines after the trailers as is */
-       print_lines(outfile, lines, trailer_end, INT_MAX);
+       fwrite(sb.buf + trailer_end, 1, sb.len - trailer_end, outfile);
 
        if (in_place)
                if (rename_tempfile(&trailers_tempfile, file))
                        die_errno(_("could not rename temporary file to %s"), file);
 
-       strbuf_list_free(lines);
+       strbuf_release(&sb);
+}
+
+void trailer_info_get(struct trailer_info *info, const char *str)
+{
+       int patch_start, trailer_end, trailer_start;
+       struct strbuf **trailer_lines, **ptr;
+       char **trailer_strings = NULL;
+       size_t nr = 0, alloc = 0;
+       char **last = NULL;
+
+       ensure_configured();
+
+       patch_start = find_patch_start(str);
+       trailer_end = find_trailer_end(str, patch_start);
+       trailer_start = find_trailer_start(str, trailer_end);
+
+       trailer_lines = strbuf_split_buf(str + trailer_start,
+                                        trailer_end - trailer_start,
+                                        '\n',
+                                        0);
+       for (ptr = trailer_lines; *ptr; ptr++) {
+               if (last && isspace((*ptr)->buf[0])) {
+                       struct strbuf sb = STRBUF_INIT;
+                       strbuf_attach(&sb, *last, strlen(*last), strlen(*last));
+                       strbuf_addbuf(&sb, *ptr);
+                       *last = strbuf_detach(&sb, NULL);
+                       continue;
+               }
+               ALLOC_GROW(trailer_strings, nr + 1, alloc);
+               trailer_strings[nr] = strbuf_detach(*ptr, NULL);
+               last = find_separator(trailer_strings[nr], separators) >= 1
+                       ? &trailer_strings[nr]
+                       : NULL;
+               nr++;
+       }
+       strbuf_list_free(trailer_lines);
+
+       info->blank_line_before_trailer = ends_with_blank_line(str,
+                                                              trailer_start);
+       info->trailer_start = str + trailer_start;
+       info->trailer_end = str + trailer_end;
+       info->trailers = trailer_strings;
+       info->trailer_nr = nr;
+}
+
+void trailer_info_release(struct trailer_info *info)
+{
+       int i;
+       for (i = 0; i < info->trailer_nr; i++)
+               free(info->trailers[i]);
+       free(info->trailers);
 }
index 36b40b81761f95742c9c6fe7e94ba89f19aabfde..65cc5d79c6cecfce5cf3302dd7dcb6323f9f85dc 100644 (file)
--- a/trailer.h
+++ b/trailer.h
@@ -1,7 +1,32 @@
 #ifndef TRAILER_H
 #define TRAILER_H
 
+struct trailer_info {
+       /*
+        * True if there is a blank line before the location pointed to by
+        * trailer_start.
+        */
+       int blank_line_before_trailer;
+
+       /*
+        * Pointers to the start and end of the trailer block found. If there
+        * is no trailer block found, these 2 pointers point to the end of the
+        * input string.
+        */
+       const char *trailer_start, *trailer_end;
+
+       /*
+        * Array of trailers found.
+        */
+       char **trailers;
+       size_t trailer_nr;
+};
+
 void process_trailers(const char *file, int in_place, int trim_empty,
                      struct string_list *trailers);
 
+void trailer_info_get(struct trailer_info *info, const char *str);
+
+void trailer_info_release(struct trailer_info *info);
+
 #endif /* TRAILER_H */
index d57e8dec28d6890ce981a8422e9b8b60b697ecd6..04e5d6623e39014622e0a185d37f8a456fd352e6 100644 (file)
@@ -949,23 +949,39 @@ int transport_push(struct transport *transport,
 
                if ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) && !is_bare_repository()) {
                        struct ref *ref = remote_refs;
+                       struct sha1_array commits = SHA1_ARRAY_INIT;
+
                        for (; ref; ref = ref->next)
-                               if (!is_null_oid(&ref->new_oid) &&
-                                   !push_unpushed_submodules(ref->new_oid.hash,
-                                           transport->remote->name))
-                                   die ("Failed to push all needed submodules!");
+                               if (!is_null_oid(&ref->new_oid))
+                                       sha1_array_append(&commits, ref->new_oid.hash);
+
+                       if (!push_unpushed_submodules(&commits,
+                                                     transport->remote->name,
+                                                     pretend)) {
+                               sha1_array_clear(&commits);
+                               die("Failed to push all needed submodules!");
+                       }
+                       sha1_array_clear(&commits);
                }
 
-               if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
-                             TRANSPORT_RECURSE_SUBMODULES_CHECK)) && !is_bare_repository()) {
+               if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
+                    ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) &&
+                     !pretend)) && !is_bare_repository()) {
                        struct ref *ref = remote_refs;
                        struct string_list needs_pushing = STRING_LIST_INIT_DUP;
+                       struct sha1_array commits = SHA1_ARRAY_INIT;
 
                        for (; ref; ref = ref->next)
-                               if (!is_null_oid(&ref->new_oid) &&
-                                   find_unpushed_submodules(ref->new_oid.hash,
-                                           transport->remote->name, &needs_pushing))
-                                       die_with_unpushed_submodules(&needs_pushing);
+                               if (!is_null_oid(&ref->new_oid))
+                                       sha1_array_append(&commits, ref->new_oid.hash);
+
+                       if (find_unpushed_submodules(&commits, transport->remote->name,
+                                               &needs_pushing)) {
+                               sha1_array_clear(&commits);
+                               die_with_unpushed_submodules(&needs_pushing);
+                       }
+                       string_list_clear(&needs_pushing, 0);
+                       sha1_array_clear(&commits);
                }
 
                push_ret = transport->push_refs(transport, remote_refs, flags);
index ea6bdd20e0491554e88f4b84bd3b6354867021bc..7a6df99d10e1dbabc9f7df74316fd91bd55c1fd5 100644 (file)
@@ -78,7 +78,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
                xstrfmt(msg, cmd, cmd);
 
        msgs[ERROR_NOT_UPTODATE_DIR] =
-               _("Updating the following directories would lose untracked files in it:\n%s");
+               _("Updating the following directories would lose untracked files in them:\n%s");
 
        if (!strcmp(cmd, "checkout"))
                msg = advice_commit_before_merge
index f7869f8d6072c98c3e9be3387a9a3c19508e13ea..eb6121263b0d56b6b7ea7c5024e9ceb68256c1c5 100644 (file)
@@ -88,21 +88,13 @@ static struct worktree *get_main_worktree(void)
 
        strbuf_addf(&path, "%s/HEAD", get_git_common_dir());
 
-       if (parse_ref(path.buf, &head_ref, &is_detached) < 0)
-               goto done;
-
-       worktree = xmalloc(sizeof(struct worktree));
+       worktree = xcalloc(1, sizeof(*worktree));
        worktree->path = strbuf_detach(&worktree_path, NULL);
-       worktree->id = NULL;
        worktree->is_bare = is_bare;
-       worktree->head_ref = NULL;
        worktree->is_detached = is_detached;
-       worktree->is_current = 0;
-       add_head_info(&head_ref, worktree);
-       worktree->lock_reason = NULL;
-       worktree->lock_reason_valid = 0;
+       if (!parse_ref(path.buf, &head_ref, &is_detached))
+               add_head_info(&head_ref, worktree);
 
-done:
        strbuf_release(&path);
        strbuf_release(&worktree_path);
        strbuf_release(&head_ref);
@@ -138,16 +130,11 @@ static struct worktree *get_linked_worktree(const char *id)
        if (parse_ref(path.buf, &head_ref, &is_detached) < 0)
                goto done;
 
-       worktree = xmalloc(sizeof(struct worktree));
+       worktree = xcalloc(1, sizeof(*worktree));
        worktree->path = strbuf_detach(&worktree_path, NULL);
        worktree->id = xstrdup(id);
-       worktree->is_bare = 0;
-       worktree->head_ref = NULL;
        worktree->is_detached = is_detached;
-       worktree->is_current = 0;
        add_head_info(&head_ref, worktree);
-       worktree->lock_reason = NULL;
-       worktree->lock_reason_valid = 0;
 
 done:
        strbuf_release(&path);
@@ -173,7 +160,14 @@ static void mark_current_worktree(struct worktree **worktrees)
        free(git_dir);
 }
 
-struct worktree **get_worktrees(void)
+static int compare_worktree(const void *a_, const void *b_)
+{
+       const struct worktree *const *a = a_;
+       const struct worktree *const *b = b_;
+       return fspathcmp((*a)->path, (*b)->path);
+}
+
+struct worktree **get_worktrees(unsigned flags)
 {
        struct worktree **list = NULL;
        struct strbuf path = STRBUF_INIT;
@@ -183,8 +177,7 @@ struct worktree **get_worktrees(void)
 
        list = xmalloc(alloc * sizeof(struct worktree *));
 
-       if ((list[counter] = get_main_worktree()))
-               counter++;
+       list[counter++] = get_main_worktree();
 
        strbuf_addf(&path, "%s/worktrees", get_git_common_dir());
        dir = opendir(path.buf);
@@ -205,6 +198,13 @@ struct worktree **get_worktrees(void)
        ALLOC_GROW(list, counter + 1, alloc);
        list[counter] = NULL;
 
+       if (flags & GWT_SORT_LINKED)
+               /*
+                * don't sort the first item (main worktree), which will
+                * always be the first
+                */
+               QSORT(list + 1, counter - 1, compare_worktree);
+
        mark_current_worktree(list);
        return list;
 }
@@ -341,7 +341,7 @@ const struct worktree *find_shared_symref(const char *symref,
 
        if (worktrees)
                free_worktrees(worktrees);
-       worktrees = get_worktrees();
+       worktrees = get_worktrees(0);
 
        for (i = 0; worktrees[i]; i++) {
                struct worktree *wt = worktrees[i];
index 90e1311fa73fa6bdde5249d68818eacb6dc8edd0..d59ce1fee875800462a1e464592fd9dd01828e17 100644 (file)
@@ -15,6 +15,8 @@ struct worktree {
 
 /* Functions for acting on the information about worktrees. */
 
+#define GWT_SORT_LINKED (1 << 0) /* keeps linked worktrees sorted */
+
 /*
  * Get the worktrees.  The primary worktree will always be the first returned,
  * and linked worktrees will be pointed to by 'next' in each subsequent
@@ -23,7 +25,7 @@ struct worktree {
  * The caller is responsible for freeing the memory from the returned
  * worktree(s).
  */
-extern struct worktree **get_worktrees(void);
+extern struct worktree **get_worktrees(unsigned flags);
 
 /*
  * Return git dir of the worktree. Note that the path may be relative.