Merge branch 'rs/plug-strbuf-reak-in-read-alt-refs'
authorJunio C Hamano <gitster@pobox.com>
Fri, 9 Aug 2019 17:13:14 +0000 (10:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Aug 2019 17:13:14 +0000 (10:13 -0700)
Leakfix.

* rs/plug-strbuf-reak-in-read-alt-refs:
sha1-file: release strbuf after use

15 files changed:
Documentation/config/transfer.txt
Documentation/git-cvsserver.txt
Documentation/git-fetch.txt
Documentation/git-pull.txt
Documentation/git-restore.txt
Documentation/glossary-content.txt
Documentation/technical/api-ref-iteration.txt
builtin/checkout.c
builtin/fetch.c
commit-graph.c
merge-recursive.c
refs/files-backend.c
t/helper/test-dir-iterator.c
t/t5324-split-commit-graph.sh
t/t6043-merge-rename-directories.sh
index 4a5dfe2fc1670346485838522ad42a6cc22fabc8..f5b6245270e0e8ddd029eb1f520b3e27210792f4 100644 (file)
@@ -17,7 +17,7 @@ linkgit:git-receive-pack[1]. On the fetch side, malformed objects will
 instead be left unreferenced in the repository.
 +
 Due to the non-quarantine nature of the `fetch.fsckObjects`
-implementation it can not be relied upon to leave the object store
+implementation it cannot be relied upon to leave the object store
 clean like `receive.fsckObjects` can.
 +
 As objects are unpacked they're written to the object store, so there
index f98b7c6ed7c0fe4df8a0e3211eaa53ea7c95d5d9..79e22b1f3a131ea5301a1c11fb558ec16e6c16e6 100644 (file)
@@ -232,7 +232,7 @@ write so it might not be enough to grant the users using
 'git-cvsserver' write access to the database file without granting
 them write access to the directory, too.
 
-The database can not be reliably regenerated in a
+The database cannot be reliably regenerated in a
 consistent form after the branch it is tracking has changed.
 Example: For merged branches, 'git-cvsserver' only tracks
 one branch of development, and after a 'git merge' an
index 266d63cf111c8a73420c5fa945543384e9825b55..5b1909fdf4ffcf00d52997eb1a1c2b42385689a7 100644 (file)
@@ -262,7 +262,7 @@ This updates (or creates, as necessary) branches `pu` and `tmp` in
 the local repository by fetching from the branches (respectively)
 `pu` and `maint` from the remote repository.
 +
-The `pu` branch will be updated even if it is does not fast-forward,
+The `pu` branch will be updated even if it does not fast-forward,
 because it is prefixed with a plus sign; `tmp` will not be.
 
 * Peek at a remote's branch, without configuring the remote in your local
@@ -285,7 +285,7 @@ BUGS
 ----
 Using --recurse-submodules can only fetch new commits in already checked
 out submodules right now. When e.g. upstream added a new submodule in the
-just fetched commits of the superproject the submodule itself can not be
+just fetched commits of the superproject the submodule itself cannot be
 fetched, making it impossible to check out that submodule later without
 having to do a fetch again. This is expected to be fixed in a future Git
 version.
index a5e9501a0aa6503eaab62190253afa750dd76eef..dfb901f8b8358ea309e6403079e3c87fb82fee6f 100644 (file)
@@ -249,7 +249,7 @@ BUGS
 ----
 Using --recurse-submodules can only fetch new commits in already checked
 out submodules right now. When e.g. upstream added a new submodule in the
-just fetched commits of the superproject the submodule itself can not be
+just fetched commits of the superproject the submodule itself cannot be
 fetched, making it impossible to check out that submodule later without
 having to do a fetch again. This is expected to be fixed in a future Git
 version.
index d90093f195bc6a9b2b3d2d20be89c59e4d708739..1ab2e40ea938195aa8f1bd45f5bf3ae711b7055a 100644 (file)
@@ -39,7 +39,7 @@ OPTIONS
        commit, branch or tag associated with it.
 +
 If not specified, the default restore source for the working tree is
-the index, and the default restore source for the index index is
+the index, and the default restore source for the index is
 `HEAD`. When both `--staged` and `--worktree` are specified,
 `--source` must also be specified.
 
index 8d38ae6010866a157dfdb7d52b58605d1cd2f3b6..090c888335d3292331d012a5e9074f970035d83e 100644 (file)
@@ -255,7 +255,7 @@ This commit is referred to as a "merge commit", or sometimes just a
 [[def_object]]object::
        The unit of storage in Git. It is uniquely identified by the
        <<def_SHA1,SHA-1>> of its contents. Consequently, an
-       object can not be changed.
+       object cannot be changed.
 
 [[def_object_database]]object database::
        Stores a set of "objects", and an individual <<def_object,object>> is
index 46c3d5c3550a1ba7c83b6937fe68538c3c12074e..ad9d019ff9b4602a72f9542dd15b17a324f95758 100644 (file)
@@ -54,7 +54,7 @@ this:
 do not do this you will get an error for each ref that it does not point
 to a valid object.
 
-Note: As a side-effect of this you can not safely assume that all
+Note: As a side-effect of this you cannot safely assume that all
 objects you lookup are available in superproject. All submodule objects
 will be available the same way as the superprojects objects.
 
index 91f8509f85396cb957ee87d1b0e8ba1284c8c800..6123f732a2c84f975c576e7077a0c6da369e6b31 100644 (file)
@@ -1769,7 +1769,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
        struct option *options;
        struct option restore_options[] = {
                OPT_STRING('s', "source", &opts.from_treeish, "<tree-ish>",
-                          N_("where the checkout from")),
+                          N_("which tree-ish to checkout from")),
                OPT_BOOL('S', "staged", &opts.checkout_index,
                           N_("restore the index")),
                OPT_BOOL('W', "worktree", &opts.checkout_worktree,
index 53ce99d2bbc4efd0a37ad45feaad546ae2db7e13..717dd14e896117c56101f7f56df0261576c323d0 100644 (file)
@@ -850,6 +850,15 @@ static int iterate_ref_map(void *cb_data, struct object_id *oid)
        return 0;
 }
 
+static const char warn_show_forced_updates[] =
+N_("Fetch normally indicates which branches had a forced update,\n"
+   "but that check has been disabled. To re-enable, use '--show-forced-updates'\n"
+   "flag or run 'git config fetch.showForcedUpdates true'.");
+static const char warn_time_show_forced_updates[] =
+N_("It took %.2f seconds to check forced updates. You can use\n"
+   "'--no-show-forced-updates' or run 'git config fetch.showForcedUpdates false'\n"
+   " to avoid this check.\n");
+
 static int store_updated_refs(const char *raw_url, const char *remote_name,
                              int connectivity_checked, struct ref *ref_map)
 {
@@ -1005,12 +1014,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 
        if (advice_fetch_show_forced_updates) {
                if (!fetch_show_forced_updates) {
-                       warning(_("Fetch normally indicates which branches had a forced update, but that check has been disabled."));
-                       warning(_("To re-enable, use '--show-forced-updates' flag or run 'git config fetch.showForcedUpdates true'."));
+                       warning(_(warn_show_forced_updates));
                } else if (forced_updates_ms > FORCED_UPDATES_DELAY_WARNING_IN_MS) {
-                       warning(_("It took %.2f seconds to check forced updates. You can use '--no-show-forced-updates'\n"),
+                       warning(_(warn_time_show_forced_updates),
                                forced_updates_ms / 1000.0);
-                       warning(_("or run 'git config fetch.showForcedUpdates false' to avoid this check.\n"));
                }
        }
 
index b3c4de79b6da4502726dbec5e21b11734d76e28e..fe954ab5f845e65bc5cad987308aeb6598f2fd24 100644 (file)
@@ -434,6 +434,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r, const
 
        free(oids);
        fclose(fp);
+       strbuf_release(&line);
 
        return graph_chain;
 }
@@ -1186,7 +1187,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
        }
 
        stop_progress(&ctx->progress);
-       strbuf_reset(&progress_title);
+       strbuf_release(&progress_title);
        strbuf_release(&packname);
 
        return 0;
@@ -1636,7 +1637,7 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
                                num_parents++;
 
                        if (num_parents > 2)
-                               ctx->num_extra_edges += num_parents - 2;
+                               ctx->num_extra_edges += num_parents - 1;
                }
        }
 
@@ -1713,10 +1714,8 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
        strbuf_addstr(&path, "/info/commit-graphs");
        dir = opendir(path.buf);
 
-       if (!dir) {
-               strbuf_release(&path);
-               return;
-       }
+       if (!dir)
+               goto out;
 
        strbuf_addch(&path, '/');
        dirnamelen = path.len;
@@ -1745,6 +1744,9 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
                if (!found)
                        unlink(path.buf);
        }
+
+out:
+       strbuf_release(&path);
 }
 
 int write_commit_graph(const char *obj_dir,
index 12300131fc12b15fbc9514e90ca45d76113d7267..6b812d67e3ecd54ece21c2465ede3e28d6fba325 100644 (file)
@@ -2863,7 +2863,8 @@ static int detect_and_process_renames(struct merge_options *opt,
        head_pairs = get_diffpairs(opt, common, head);
        merge_pairs = get_diffpairs(opt, common, merge);
 
-       if (opt->detect_directory_renames) {
+       if ((opt->detect_directory_renames == 2) ||
+           (opt->detect_directory_renames == 1 && !opt->call_depth)) {
                dir_re_head = get_directory_renames(head_pairs);
                dir_re_merge = get_directory_renames(merge_pairs);
 
index b1f8f53a098da3525fdff5011b93f39138df3df2..d60767ab739f0e20e45c700368f7f9f24a52c3f8 100644 (file)
@@ -2151,8 +2151,10 @@ static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
        strbuf_addf(&sb, "%s/logs", gitdir);
 
        diter = dir_iterator_begin(sb.buf, 0);
-       if(!diter)
+       if (!diter) {
+               strbuf_release(&sb);
                return empty_ref_iterator_begin();
+       }
 
        iter = xcalloc(1, sizeof(*iter));
        ref_iterator = &iter->base;
index c7c30664dad2a027c4cf6b0bac7ecb78080cbcf1..659b6bfa81df6d0bcffb8d0a975492d54d79d6bc 100644 (file)
@@ -19,7 +19,6 @@ static const char *error_name(int error_number)
  */
 int cmd__dir_iterator(int argc, const char **argv)
 {
-       struct strbuf path = STRBUF_INIT;
        struct dir_iterator *diter;
        unsigned int flags = 0;
        int iter_status;
@@ -36,8 +35,7 @@ int cmd__dir_iterator(int argc, const char **argv)
        if (!*argv || argc != 1)
                die("dir-iterator needs exactly one non-option argument");
 
-       strbuf_add(&path, *argv, strlen(*argv));
-       diter = dir_iterator_begin(path.buf, flags);
+       diter = dir_iterator_begin(*argv, flags);
 
        if (!diter) {
                printf("dir_iterator_begin failure: %s\n", error_name(errno));
index 03f45a1ed9023c2b3371bdac70f7abadd14b4202..99f4ef4c19dff028facac6da810c973b3a82a4fc 100755 (executable)
@@ -319,7 +319,9 @@ test_expect_success 'add octopus merge' '
        git merge commits/3 commits/4 &&
        git branch merge/octopus &&
        git commit-graph write --reachable --split &&
-       git commit-graph verify &&
+       git commit-graph verify 2>err &&
+       test_line_count = 3 err &&
+       test_i18ngrep ! warning err &&
        test_line_count = 3 $graphdir/commit-graph-chain
 '
 
index 50b7543483e9988f3a97d7782e11504f82558af4..c966147d5d73ee669321f3efcf57e32a80259076 100755 (executable)
@@ -4403,4 +4403,115 @@ test_expect_success '13d-check(info): messages for rename/rename(1to1) via dual
        )
 '
 
+# Testcase 13e, directory rename in virtual merge base
+#
+# This testcase has a slightly different setup than all the above cases, in
+# order to include a recursive case:
+#
+#      A   C
+#      o - o
+#     / \ / \
+#  O o   X   ?
+#     \ / \ /
+#      o   o
+#      B   D
+#
+#   Commit O: a/{z,y}
+#   Commit A: b/{z,y}
+#   Commit B: a/{z,y,x}
+#   Commit C: b/{z,y,x}
+#   Commit D: b/{z,y}, a/x
+#   Expected: b/{z,y,x}  (sort of; see below for why this might not be expected)
+#
+#   NOTES: 'X' represents a virtual merge base.  With the default of
+#          directory rename detection yielding conflicts, merging A and B
+#          results in a conflict complaining about whether 'x' should be
+#          under 'a/' or 'b/'.  However, when creating the virtual merge
+#          base 'X', since virtual merge bases need to be written out as a
+#          tree, we cannot have a conflict, so some resolution has to be
+#          picked.
+#
+#          In choosing the right resolution, it's worth noting here that
+#          commits C & D are merges of A & B that choose different
+#          locations for 'x' (i.e. they resolve the conflict differently),
+#          and so it would be nice when merging C & D if git could detect
+#          this difference of opinion and report a conflict.  But the only
+#          way to do so that I can think of would be to have the virtual
+#          merge base place 'x' in some directory other than either 'a/' or
+#          'b/', which seems a little weird -- especially since it'd result
+#          in a rename/rename(1to2) conflict with a source path that never
+#          existed in any version.
+#
+#          So, for now, when directory rename detection is set to
+#          'conflict' just avoid doing directory rename detection at all in
+#          the recursive case.  This will not allow us to detect a conflict
+#          in the outer merge for this special kind of setup, but it at
+#          least avoids hitting a BUG().
+#
+test_expect_success '13e-setup: directory rename detection in recursive case' '
+       test_create_repo 13e &&
+       (
+               cd 13e &&
+
+               mkdir a &&
+               echo z >a/z &&
+               echo y >a/y &&
+               git add a &&
+               test_tick &&
+               git commit -m "O" &&
+
+               git branch O &&
+               git branch A &&
+               git branch B &&
+
+               git checkout A &&
+               git mv a/ b/ &&
+               test_tick &&
+               git commit -m "A" &&
+
+               git checkout B &&
+               echo x >a/x &&
+               git add a &&
+               test_tick &&
+               git commit -m "B" &&
+
+               git branch C A &&
+               git branch D B &&
+
+               git checkout C &&
+               test_must_fail git -c merge.directoryRenames=conflict merge B &&
+               git add b/x &&
+               test_tick &&
+               git commit -m "C" &&
+
+
+               git checkout D &&
+               test_must_fail git -c merge.directoryRenames=conflict merge A &&
+               git add b/x &&
+               mkdir a &&
+               git mv b/x a/x &&
+               test_tick &&
+               git commit -m "D"
+       )
+'
+
+test_expect_success '13e-check: directory rename detection in recursive case' '
+       (
+               cd 13e &&
+
+               git checkout --quiet D^0 &&
+
+               git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
+
+               test_i18ngrep ! CONFLICT out &&
+               test_i18ngrep ! BUG: err &&
+               test_i18ngrep ! core.dumped err &&
+               test_must_be_empty err &&
+
+               git ls-files >paths &&
+               ! grep a/x paths &&
+               grep b/x paths
+       )
+'
+
 test_done