Imported Upstream version 2.3.5 upstream/2.3.5
authorDongHun Kwak <dh0128.kwak@samsung.com>
Wed, 3 Mar 2021 06:14:56 +0000 (15:14 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Wed, 3 Mar 2021 06:14:56 +0000 (15:14 +0900)
33 files changed:
.mailmap
Documentation/RelNotes/2.3.2.txt
Documentation/RelNotes/2.3.5.txt [new file with mode: 0644]
Documentation/SubmittingPatches
Documentation/git-pull.txt
Documentation/git-push.txt
Documentation/git-rebase.txt
Documentation/git.txt
GIT-VERSION-GEN
RelNotes
builtin/clone.c
builtin/grep.c
builtin/ls-files.c
builtin/prune.c
builtin/repack.c
builtin/tag.c
cache.h
contrib/completion/git-completion.bash
contrib/completion/git-prompt.sh
csum-file.c
dir.c
dir.h
environment.c
fetch-pack.c
read-cache.c
refs.c
t/t1700-split-index.sh
t/t5312-prune-corruption.sh [new file with mode: 0755]
t/t5516-fetch-push.sh
t/t5551-http-fetch-smart.sh
t/t9903-bash-prompt.sh
transport.c
upload-pack.c

index bb6f52e..ece2951 100644 (file)
--- a/.mailmap
+++ b/.mailmap
@@ -13,6 +13,7 @@ Alex Riesen <raa.lkml@gmail.com> <raa@limbo.localdomain>
 Alex Riesen <raa.lkml@gmail.com> <raa@steel.home>
 Alex Vandiver <alex@chmrr.net> <alexmv@MIT.EDU>
 Alexander Gavrilov <angavrilov@gmail.com>
+Alexander Kuleshov <kuleshovmail@gmail.com>
 Alexey Shumkin <alex.crezoff@gmail.com> <zapped@mail.ru>
 Alexey Shumkin <alex.crezoff@gmail.com> <Alex.Crezoff@gmail.com>
 Anders Kaseorg <andersk@MIT.EDU> <andersk@ksplice.com>
index f4caf54..93462e4 100644 (file)
@@ -24,7 +24,7 @@ Fixes since v2.3.1
    "curl-config --vernum", which confused our build system.
 
  * An earlier workaround to squelch unhelpful deprecation warnings
-   from the complier on Mac OSX unnecessarily set minimum required
+   from the compiler on Mac OSX unnecessarily set minimum required
    version of the OS, which the user might want to raise (or lower)
    for other reasons.
 
diff --git a/Documentation/RelNotes/2.3.5.txt b/Documentation/RelNotes/2.3.5.txt
new file mode 100644 (file)
index 0000000..5b309db
--- /dev/null
@@ -0,0 +1,44 @@
+Git v2.3.5 Release Notes
+========================
+
+Fixes since v2.3.4
+------------------
+
+ * The prompt script (in contrib/) did not show the untracked sign
+   when working in a subdirectory without any untracked files.
+
+ * Even though "git grep --quiet" is run merely to ask for the exit
+   status, we spawned the pager regardless.  Stop doing that.
+
+ * Recommend format-patch and send-email for those who want to submit
+   patches to this project.
+
+ * An failure early in the "git clone" that started creating the
+   working tree and repository could have resulted in some directories
+   and files left without getting cleaned up.
+
+ * "git fetch" that fetches a commit using the allow-tip-sha1-in-want
+   extension could have failed to fetch all the requested refs.
+
+ * The split-index mode introduced at v2.3.0-rc0~41 was broken in the
+   codepath to protect us against a broken reimplementation of Git
+   that writes an invalid index with duplicated index entries, etc.
+
+ * "git prune" used to largely ignore broken refs when deciding which
+   objects are still being used, which could spread an existing small
+   damage and make it a larger one.
+
+ * "git tag -h" used to show the "--column" and "--sort" options
+   that are about listing in a wrong section.
+
+ * The transfer.hiderefs support did not quite work for smart-http
+   transport.
+
+ * The code that reads from the ctags file in the completion script
+   (in contrib/) did not spell ${param/pattern/string} substitution
+   correctly, which happened to work with bash but not with zsh.
+
+ * The explanation on "rebase --preserve-merges", "pull --rebase=preserve",
+   and "push --force-with-lease" in the documentation was unclear.
+
+Also contains typofixes, documentation updates and trivial code clean-ups.
index ef0eeb4..98fc4cc 100644 (file)
@@ -136,6 +136,11 @@ that is fine, but please mark it as such.
 
 (4) Sending your patches.
 
+Learn to use format-patch and send-email if possible.  These commands
+are optimized for the workflow of sending patches, avoiding many ways
+your existing e-mail client that is optimized for "multipart/*" mime
+type e-mails to corrupt and render your patches unusable.
+
 People on the Git mailing list need to be able to read and
 comment on the changes you are submitting.  It is important for
 a developer to be able to "quote" your changes, using standard
index 200eb22..4064452 100644 (file)
@@ -111,9 +111,8 @@ include::merge-options.txt[]
        was rebased since last fetched, the rebase uses that information
        to avoid rebasing non-local changes.
 +
-When preserve, also rebase the current branch on top of the upstream
-branch, but pass `--preserve-merges` along to `git rebase` so that
-locally created merge commits will not be flattened.
+When set to preserve, rebase with the `--preserve-merges` option passed
+to `git rebase` so that locally created merge commits will not be flattened.
 +
 When false, merge the current branch into the upstream branch.
 +
index 58cc59f..3593774 100644 (file)
@@ -149,9 +149,8 @@ already exists on the remote side.
        Usually, "git push" refuses to update a remote ref that is
        not an ancestor of the local ref used to overwrite it.
 +
-This option bypasses the check, but instead requires that the
-current value of the ref to be the expected value.  "git push"
-fails otherwise.
+This option overrides this restriction if the current value of the
+remote ref is the expected value.  "git push" fails otherwise.
 +
 Imagine that you have to rebase what you have already published.
 You will have to bypass the "must fast-forward" rule in order to
@@ -163,15 +162,14 @@ commit, and blindly pushing with `--force` will lose her work.
 This option allows you to say that you expect the history you are
 updating is what you rebased and want to replace. If the remote ref
 still points at the commit you specified, you can be sure that no
-other people did anything to the ref (it is like taking a "lease" on
-the ref without explicitly locking it, and you update the ref while
-making sure that your earlier "lease" is still valid).
+other people did anything to the ref. It is like taking a "lease" on
+the ref without explicitly locking it, and the remote ref is updated
+only if the "lease" is still valid.
 +
 `--force-with-lease` alone, without specifying the details, will protect
 all remote refs that are going to be updated by requiring their
 current value to be the same as the remote-tracking branch we have
-for them, unless specified with a `--force-with-lease=<refname>:<expect>`
-option that explicitly states what the expected value is.
+for them.
 +
 `--force-with-lease=<refname>`, without specifying the expected value, will
 protect the named ref (alone), if it is going to be updated, by
index 924827d..c8ab48d 100644 (file)
@@ -362,7 +362,9 @@ default is `--no-fork-point`, otherwise the default is `--fork-point`.
 
 -p::
 --preserve-merges::
-       Instead of ignoring merges, try to recreate them.
+       Recreate merge commits instead of flattening the history by replaying
+       commits a merge commit introduces. Merge conflict resolutions or manual
+       amendments to merge commits are not preserved.
 +
 This uses the `--interactive` machinery internally, but combining it
 with the `--interactive` option explicitly is generally not a good
index 9c75617..8f5220c 100644 (file)
@@ -43,9 +43,10 @@ unreleased) version of Git, that is available from the 'master'
 branch of the `git.git` repository.
 Documentation for older releases are available here:
 
-* link:v2.3.4/git.html[documentation for release 2.3.4]
+* link:v2.3.5/git.html[documentation for release 2.3.5]
 
 * release notes for
+  link:RelNotes/2.3.5.txt[2.3.5],
   link:RelNotes/2.3.4.txt[2.3.4],
   link:RelNotes/2.3.3.txt[2.3.3],
   link:RelNotes/2.3.2.txt[2.3.2],
@@ -769,7 +770,8 @@ Git so take care if using Cogito etc.
 'GIT_INDEX_VERSION'::
        This environment variable allows the specification of an index
        version for new repositories.  It won't affect existing index
-       files.  By default index file version [23] is used.
+       files.  By default index file version 2 or 3 is used. See
+       linkgit:git-update-index[1] for more information.
 
 'GIT_OBJECT_DIRECTORY'::
        If the object storage directory is specified via this
@@ -1027,6 +1029,17 @@ GIT_ICASE_PATHSPECS::
        variable when it is invoked as the top level command by the
        end user, to be recorded in the body of the reflog.
 
+`GIT_REF_PARANOIA`::
+       If set to `1`, include broken or badly named refs when iterating
+       over lists of refs. In a normal, non-corrupted repository, this
+       does nothing. However, enabling it may help git to detect and
+       abort some operations in the presence of broken refs. Git sets
+       this variable automatically when performing destructive
+       operations like linkgit:git-prune[1]. You should not need to set
+       it yourself unless you want to be paranoid about making sure
+       an operation has touched every ref (e.g., because you are
+       cloning a repository to make a backup).
+
 
 Discussion[[Discussion]]
 ------------------------
index 9905751..7e0ccef 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v2.3.4
+DEF_VER=v2.3.5
 
 LF='
 '
index f631b25..99d78b7 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/2.3.4.txt
\ No newline at end of file
+Documentation/RelNotes/2.3.5.txt
\ No newline at end of file
index 316c75d..2d77a2d 100644 (file)
@@ -842,20 +842,21 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                git_dir = mkpathdup("%s/.git", dir);
        }
 
+       atexit(remove_junk);
+       sigchain_push_common(remove_junk_on_signal);
+
        if (!option_bare) {
-               junk_work_tree = work_tree;
                if (safe_create_leading_directories_const(work_tree) < 0)
                        die_errno(_("could not create leading directories of '%s'"),
                                  work_tree);
                if (!dest_exists && mkdir(work_tree, 0777))
-                       die_errno(_("could not create work tree dir '%s'."),
+                       die_errno(_("could not create work tree dir '%s'"),
                                  work_tree);
+               junk_work_tree = work_tree;
                set_git_work_tree(work_tree);
        }
-       junk_git_dir = git_dir;
-       atexit(remove_junk);
-       sigchain_push_common(remove_junk_on_signal);
 
+       junk_git_dir = git_dir;
        if (safe_create_leading_directories_const(git_dir) < 0)
                die(_("could not create leading directories of '%s'"), git_dir);
 
index e77f7cf..fe7b9fd 100644 (file)
@@ -885,7 +885,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                }
        }
 
-       if (!show_in_pager)
+       if (!show_in_pager && !opt.status_only)
                setup_pager();
 
        if (!use_index && (untracked || cached))
index 99cee20..19063eb 100644 (file)
@@ -354,49 +354,6 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
        }
 }
 
-int report_path_error(const char *ps_matched,
-                     const struct pathspec *pathspec,
-                     const char *prefix)
-{
-       /*
-        * Make sure all pathspec matched; otherwise it is an error.
-        */
-       struct strbuf sb = STRBUF_INIT;
-       int num, errors = 0;
-       for (num = 0; num < pathspec->nr; num++) {
-               int other, found_dup;
-
-               if (ps_matched[num])
-                       continue;
-               /*
-                * The caller might have fed identical pathspec
-                * twice.  Do not barf on such a mistake.
-                * FIXME: parse_pathspec should have eliminated
-                * duplicate pathspec.
-                */
-               for (found_dup = other = 0;
-                    !found_dup && other < pathspec->nr;
-                    other++) {
-                       if (other == num || !ps_matched[other])
-                               continue;
-                       if (!strcmp(pathspec->items[other].original,
-                                   pathspec->items[num].original))
-                               /*
-                                * Ok, we have a match already.
-                                */
-                               found_dup = 1;
-               }
-               if (found_dup)
-                       continue;
-
-               error("pathspec '%s' did not match any file(s) known to git.",
-                     pathspec->items[num].original);
-               errors++;
-       }
-       strbuf_release(&sb);
-       return errors;
-}
-
 static const char * const ls_files_usage[] = {
        N_("git ls-files [options] [<file>...]"),
        NULL
index 04d3b12..17094ad 100644 (file)
@@ -115,6 +115,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
        expire = ULONG_MAX;
        save_commit_buffer = 0;
        check_replace_refs = 0;
+       ref_paranoia = 1;
        init_revisions(&revs, prefix);
 
        argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
index 3f852f3..2fe1b30 100644 (file)
@@ -228,13 +228,17 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                get_non_kept_pack_filenames(&existing_packs);
 
                if (existing_packs.nr && delete_redundant) {
-                       if (unpack_unreachable)
+                       if (unpack_unreachable) {
                                argv_array_pushf(&cmd.args,
                                                "--unpack-unreachable=%s",
                                                unpack_unreachable);
-                       else if (pack_everything & LOOSEN_UNREACHABLE)
+                               argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
+                       } else if (pack_everything & LOOSEN_UNREACHABLE) {
                                argv_array_push(&cmd.args,
                                                "--unpack-unreachable");
+                       } else {
+                               argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
+                       }
                }
        } else {
                argv_array_push(&cmd.args, "--unpacked");
index e633f4e..d315827 100644 (file)
@@ -605,13 +605,13 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                OPT_STRING('u', "local-user", &keyid, N_("key-id"),
                                        N_("use another key to sign the tag")),
                OPT__FORCE(&force, N_("replace the tag if exists")),
+
+               OPT_GROUP(N_("Tag listing options")),
                OPT_COLUMN(0, "column", &colopts, N_("show tag list in columns")),
                {
                        OPTION_CALLBACK, 0, "sort", &tag_sort, N_("type"), N_("sort tags"),
                        PARSE_OPT_NONEG, parse_opt_sort
                },
-
-               OPT_GROUP(N_("Tag listing options")),
                {
                        OPTION_CALLBACK, 0, "contains", &with_commit, N_("commit"),
                        N_("print only tags that contain the commit"),
diff --git a/cache.h b/cache.h
index 4d02efc..28d769f 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -614,6 +614,14 @@ extern int protect_hfs;
 extern int protect_ntfs;
 
 /*
+ * Include broken refs in all ref iterations, which will
+ * generally choke dangerous operations rather than letting
+ * them silently proceed without taking the broken ref into
+ * account.
+ */
+extern int ref_paranoia;
+
+/*
  * The character that begins a commented line in user-editable file
  * that is subject to stripspace.
  */
@@ -1569,7 +1577,6 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
 #define ws_tab_width(rule)     ((rule) & WS_TAB_WIDTH_MASK)
 
 /* ls-files */
-int report_path_error(const char *ps_matched, const struct pathspec *pathspec, const char *prefix);
 void overlay_tree_on_cache(const char *tree_name, const char *prefix);
 
 char *alias_lookup(const char *alias);
index b892908..661a829 100644 (file)
@@ -977,7 +977,7 @@ _git_branch ()
 
        case "$cur" in
        --set-upstream-to=*)
-               __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
+               __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
                ;;
        --*)
                __gitcomp "
@@ -1045,7 +1045,7 @@ _git_checkout ()
 
 _git_cherry ()
 {
-       __gitcomp "$(__git_refs)"
+       __gitcomp_nl "$(__git_refs)"
 }
 
 _git_cherry_pick ()
@@ -1302,7 +1302,7 @@ _git_gitk ()
 }
 
 __git_match_ctag() {
-       awk "/^${1////\\/}/ { print \$1 }" "$2"
+       awk "/^${1//\//\\/}/ { print \$1 }" "$2"
 }
 
 _git_grep ()
index 214e859..f18aedc 100644 (file)
@@ -487,7 +487,7 @@ __git_ps1 ()
 
                if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
                   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
-                  git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null
+                  git ls-files --others --exclude-standard --error-unmatch -- ':/*' >/dev/null 2>/dev/null
                then
                        u="%${ZSH_VERSION+%}"
                fi
index b00b215..a172199 100644 (file)
@@ -130,14 +130,10 @@ struct sha1file *sha1fd_check(const char *name)
 
        sink = open("/dev/null", O_WRONLY);
        if (sink < 0)
-               return NULL;
+               die_errno("unable to open /dev/null");
        check = open(name, O_RDONLY);
-       if (check < 0) {
-               int saved_errno = errno;
-               close(sink);
-               errno = saved_errno;
-               return NULL;
-       }
+       if (check < 0)
+               die_errno("unable to open '%s'", name);
        f = sha1fd(sink, name);
        f->check_fd = check;
        return f;
diff --git a/dir.c b/dir.c
index 3f7a025..0943a81 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -377,6 +377,49 @@ int match_pathspec(const struct pathspec *ps,
        return negative ? 0 : positive;
 }
 
+int report_path_error(const char *ps_matched,
+                     const struct pathspec *pathspec,
+                     const char *prefix)
+{
+       /*
+        * Make sure all pathspec matched; otherwise it is an error.
+        */
+       struct strbuf sb = STRBUF_INIT;
+       int num, errors = 0;
+       for (num = 0; num < pathspec->nr; num++) {
+               int other, found_dup;
+
+               if (ps_matched[num])
+                       continue;
+               /*
+                * The caller might have fed identical pathspec
+                * twice.  Do not barf on such a mistake.
+                * FIXME: parse_pathspec should have eliminated
+                * duplicate pathspec.
+                */
+               for (found_dup = other = 0;
+                    !found_dup && other < pathspec->nr;
+                    other++) {
+                       if (other == num || !ps_matched[other])
+                               continue;
+                       if (!strcmp(pathspec->items[other].original,
+                                   pathspec->items[num].original))
+                               /*
+                                * Ok, we have a match already.
+                                */
+                               found_dup = 1;
+               }
+               if (found_dup)
+                       continue;
+
+               error("pathspec '%s' did not match any file(s) known to git.",
+                     pathspec->items[num].original);
+               errors++;
+       }
+       strbuf_release(&sb);
+       return errors;
+}
+
 /*
  * Return the length of the "simple" part of a path match limiter.
  */
diff --git a/dir.h b/dir.h
index 6c45e9d..72b73c6 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -137,6 +137,7 @@ extern char *common_prefix(const struct pathspec *pathspec);
 extern int match_pathspec(const struct pathspec *pathspec,
                          const char *name, int namelen,
                          int prefix, char *seen, int is_dir);
+extern int report_path_error(const char *ps_matched, const struct pathspec *pathspec, const char *prefix);
 extern int within_depth(const char *name, int namelen, int depth, int max_depth);
 
 extern int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec);
index 1ade5c9..a40044c 100644 (file)
@@ -24,6 +24,7 @@ int is_bare_repository_cfg = -1; /* unspecified */
 int log_all_ref_updates = -1; /* unspecified */
 int warn_ambiguous_refs = 1;
 int warn_on_object_refname_ambiguity = 1;
+int ref_paranoia = -1;
 int repository_format_version;
 const char *git_commit_encoding;
 const char *git_log_output_encoding;
index 655ee64..48526aa 100644 (file)
@@ -544,16 +544,19 @@ static void filter_refs(struct fetch_pack_args *args,
        /* Append unmatched requests to the list */
        if (allow_tip_sha1_in_want) {
                for (i = 0; i < nr_sought; i++) {
+                       unsigned char sha1[20];
+
                        ref = sought[i];
                        if (ref->matched)
                                continue;
-                       if (get_sha1_hex(ref->name, ref->old_sha1))
+                       if (get_sha1_hex(ref->name, sha1) ||
+                           ref->name[40] != '\0' ||
+                           hashcmp(sha1, ref->old_sha1))
                                continue;
 
                        ref->matched = 1;
-                       *newtail = ref;
-                       ref->next = NULL;
-                       newtail = &ref->next;
+                       *newtail = copy_ref(ref);
+                       newtail = &(*newtail)->next;
                }
        }
        *refs = newlist;
@@ -625,7 +628,6 @@ static int everything_local(struct fetch_pack_args *args,
 
        for (retval = 1, ref = *refs; ref ; ref = ref->next) {
                const unsigned char *remote = ref->old_sha1;
-               unsigned char local[20];
                struct object *o;
 
                o = lookup_object(remote);
@@ -638,8 +640,6 @@ static int everything_local(struct fetch_pack_args *args,
                                ref->name);
                        continue;
                }
-
-               hashcpy(ref->new_sha1, local);
                if (!args->verbose)
                        continue;
                fprintf(stderr,
index 8d71860..1bf78a4 100644 (file)
@@ -1486,18 +1486,25 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
        return ce;
 }
 
-static void check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce)
-{
-       int name_compare = strcmp(ce->name, next_ce->name);
-       if (0 < name_compare)
-               die("unordered stage entries in index");
-       if (!name_compare) {
-               if (!ce_stage(ce))
-                       die("multiple stage entries for merged file '%s'",
-                               ce->name);
-               if (ce_stage(ce) > ce_stage(next_ce))
-                       die("unordered stage entries for '%s'",
-                               ce->name);
+static void check_ce_order(struct index_state *istate)
+{
+       unsigned int i;
+
+       for (i = 1; i < istate->cache_nr; i++) {
+               struct cache_entry *ce = istate->cache[i - 1];
+               struct cache_entry *next_ce = istate->cache[i];
+               int name_compare = strcmp(ce->name, next_ce->name);
+
+               if (0 < name_compare)
+                       die("unordered stage entries in index");
+               if (!name_compare) {
+                       if (!ce_stage(ce))
+                               die("multiple stage entries for merged file '%s'",
+                                   ce->name);
+                       if (ce_stage(ce) > ce_stage(next_ce))
+                               die("unordered stage entries for '%s'",
+                                   ce->name);
+               }
        }
 }
 
@@ -1562,9 +1569,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
                ce = create_from_disk(disk_ce, &consumed, previous_name);
                set_index_entry(istate, i, ce);
 
-               if (i > 0)
-                       check_ce_order(istate->cache[i - 1], ce);
-
                src_offset += consumed;
        }
        strbuf_release(&previous_name_buf);
@@ -1608,11 +1612,10 @@ int read_index_from(struct index_state *istate, const char *path)
 
        ret = do_read_index(istate, path, 0);
        split_index = istate->split_index;
-       if (!split_index)
-               return ret;
-
-       if (is_null_sha1(split_index->base_sha1))
+       if (!split_index || is_null_sha1(split_index->base_sha1)) {
+               check_ce_order(istate);
                return ret;
+       }
 
        if (split_index->base)
                discard_index(split_index->base);
@@ -1628,6 +1631,7 @@ int read_index_from(struct index_state *istate, const char *path)
                                     sha1_to_hex(split_index->base_sha1)),
                    sha1_to_hex(split_index->base->sha1));
        merge_base_index(istate);
+       check_ce_order(istate);
        return ret;
 }
 
diff --git a/refs.c b/refs.c
index 9edf18b..3a26ad4 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1907,6 +1907,11 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base,
        data.fn = fn;
        data.cb_data = cb_data;
 
+       if (ref_paranoia < 0)
+               ref_paranoia = git_env_bool("GIT_REF_PARANOIA", 0);
+       if (ref_paranoia)
+               data.flags |= DO_FOR_EACH_INCLUDE_BROKEN;
+
        return do_for_each_entry(refs, base, do_one_ref, &data);
 }
 
@@ -2591,68 +2596,10 @@ int pack_refs(unsigned int flags)
        return 0;
 }
 
-/*
- * If entry is no longer needed in packed-refs, add it to the string
- * list pointed to by cb_data.  Reasons for deleting entries:
- *
- * - Entry is broken.
- * - Entry is overridden by a loose ref.
- * - Entry does not point at a valid object.
- *
- * In the first and third cases, also emit an error message because these
- * are indications of repository corruption.
- */
-static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data)
-{
-       struct string_list *refs_to_delete = cb_data;
-
-       if (entry->flag & REF_ISBROKEN) {
-               /* This shouldn't happen to packed refs. */
-               error("%s is broken!", entry->name);
-               string_list_append(refs_to_delete, entry->name);
-               return 0;
-       }
-       if (!has_sha1_file(entry->u.value.sha1)) {
-               unsigned char sha1[20];
-               int flags;
-
-               if (read_ref_full(entry->name, 0, sha1, &flags))
-                       /* We should at least have found the packed ref. */
-                       die("Internal error");
-               if ((flags & REF_ISSYMREF) || !(flags & REF_ISPACKED)) {
-                       /*
-                        * This packed reference is overridden by a
-                        * loose reference, so it is OK that its value
-                        * is no longer valid; for example, it might
-                        * refer to an object that has been garbage
-                        * collected.  For this purpose we don't even
-                        * care whether the loose reference itself is
-                        * invalid, broken, symbolic, etc.  Silently
-                        * remove the packed reference.
-                        */
-                       string_list_append(refs_to_delete, entry->name);
-                       return 0;
-               }
-               /*
-                * There is no overriding loose reference, so the fact
-                * that this reference doesn't refer to a valid object
-                * indicates some kind of repository corruption.
-                * Report the problem, then omit the reference from
-                * the output.
-                */
-               error("%s does not point to a valid object!", entry->name);
-               string_list_append(refs_to_delete, entry->name);
-               return 0;
-       }
-
-       return 0;
-}
-
 int repack_without_refs(struct string_list *refnames, struct strbuf *err)
 {
        struct ref_dir *packed;
-       struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
-       struct string_list_item *refname, *ref_to_delete;
+       struct string_list_item *refname;
        int ret, needs_repacking = 0, removed = 0;
 
        assert(err);
@@ -2688,13 +2635,6 @@ int repack_without_refs(struct string_list *refnames, struct strbuf *err)
                return 0;
        }
 
-       /* Remove any other accumulated cruft */
-       do_for_each_entry_in_dir(packed, 0, curate_packed_ref_fn, &refs_to_delete);
-       for_each_string_list_item(ref_to_delete, &refs_to_delete) {
-               if (remove_entry(packed, ref_to_delete->string) == -1)
-                       die("internal error");
-       }
-
        /* Write what remains */
        ret = commit_packed_refs();
        if (ret)
index 94fb473..92f7298 100755 (executable)
@@ -10,9 +10,18 @@ sane_unset GIT_TEST_SPLIT_INDEX
 test_expect_success 'enable split index' '
        git update-index --split-index &&
        test-dump-split-index .git/index >actual &&
+       indexversion=$(test-index-version <.git/index) &&
+       if test "$indexversion" = "4"
+       then
+               own=432ef4b63f32193984f339431fd50ca796493569
+               base=508851a7f0dfa8691e9f69c7f055865389012491
+       else
+               own=8299b0bcd1ac364e5f1d7768efb62fa2da79a339
+               base=39d890139ee5356c7ef572216cebcd27aa41f9df
+       fi &&
        cat >expect <<EOF &&
-own 8299b0bcd1ac364e5f1d7768efb62fa2da79a339
-base 39d890139ee5356c7ef572216cebcd27aa41f9df
+own $own
+base $base
 replacements:
 deletions:
 EOF
@@ -30,7 +39,7 @@ EOF
 
        test-dump-split-index .git/index | sed "/^own/d" >actual &&
        cat >expect <<EOF &&
-base 39d890139ee5356c7ef572216cebcd27aa41f9df
+base $base
 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0      one
 replacements:
 deletions:
diff --git a/t/t5312-prune-corruption.sh b/t/t5312-prune-corruption.sh
new file mode 100755 (executable)
index 0000000..8e98b44
--- /dev/null
@@ -0,0 +1,114 @@
+#!/bin/sh
+
+test_description='
+Test pruning of repositories with minor corruptions. The goal
+here is that we should always be erring on the side of safety. So
+if we see, for example, a ref with a bogus name, it is OK either to
+bail out or to proceed using it as a reachable tip, but it is _not_
+OK to proceed as if it did not exist. Otherwise we might silently
+delete objects that cannot be recovered.
+'
+. ./test-lib.sh
+
+test_expect_success 'disable reflogs' '
+       git config core.logallrefupdates false &&
+       rm -rf .git/logs
+'
+
+test_expect_success 'create history reachable only from a bogus-named ref' '
+       test_tick && git commit --allow-empty -m master &&
+       base=$(git rev-parse HEAD) &&
+       test_tick && git commit --allow-empty -m bogus &&
+       bogus=$(git rev-parse HEAD) &&
+       git cat-file commit $bogus >saved &&
+       echo $bogus >.git/refs/heads/bogus..name &&
+       git reset --hard HEAD^
+'
+
+test_expect_success 'pruning does not drop bogus object' '
+       test_when_finished "git hash-object -w -t commit saved" &&
+       test_might_fail git prune --expire=now &&
+       verbose git cat-file -e $bogus
+'
+
+test_expect_success 'put bogus object into pack' '
+       git tag reachable $bogus &&
+       git repack -ad &&
+       git tag -d reachable &&
+       verbose git cat-file -e $bogus
+'
+
+test_expect_success 'destructive repack keeps packed object' '
+       test_might_fail git repack -Ad --unpack-unreachable=now &&
+       verbose git cat-file -e $bogus &&
+       test_might_fail git repack -ad &&
+       verbose git cat-file -e $bogus
+'
+
+# subsequent tests will have different corruptions
+test_expect_success 'clean up bogus ref' '
+       rm .git/refs/heads/bogus..name
+'
+
+# We create two new objects here, "one" and "two". Our
+# master branch points to "two", which is deleted,
+# corrupting the repository. But we'd like to make sure
+# that the otherwise unreachable "one" is not pruned
+# (since it is the user's best bet for recovering
+# from the corruption).
+#
+# Note that we also point HEAD somewhere besides "two",
+# as we want to make sure we test the case where we
+# pick up the reference to "two" by iterating the refs,
+# not by resolving HEAD.
+test_expect_success 'create history with missing tip commit' '
+       test_tick && git commit --allow-empty -m one &&
+       recoverable=$(git rev-parse HEAD) &&
+       git cat-file commit $recoverable >saved &&
+       test_tick && git commit --allow-empty -m two &&
+       missing=$(git rev-parse HEAD) &&
+       git checkout --detach $base &&
+       rm .git/objects/$(echo $missing | sed "s,..,&/,") &&
+       test_must_fail git cat-file -e $missing
+'
+
+test_expect_success 'pruning with a corrupted tip does not drop history' '
+       test_when_finished "git hash-object -w -t commit saved" &&
+       test_might_fail git prune --expire=now &&
+       verbose git cat-file -e $recoverable
+'
+
+test_expect_success 'pack-refs does not silently delete broken loose ref' '
+       git pack-refs --all --prune &&
+       echo $missing >expect &&
+       git rev-parse refs/heads/master >actual &&
+       test_cmp expect actual
+'
+
+# we do not want to count on running pack-refs to
+# actually pack it, as it is perfectly reasonable to
+# skip processing a broken ref
+test_expect_success 'create packed-refs file with broken ref' '
+       rm -f .git/refs/heads/master &&
+       cat >.git/packed-refs <<-EOF &&
+       $missing refs/heads/master
+       $recoverable refs/heads/other
+       EOF
+       echo $missing >expect &&
+       git rev-parse refs/heads/master >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'pack-refs does not silently delete broken packed ref' '
+       git pack-refs --all --prune &&
+       git rev-parse refs/heads/master >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'pack-refs does not drop broken refs during deletion' '
+       git update-ref -d refs/heads/other &&
+       git rev-parse refs/heads/master >actual &&
+       test_cmp expect actual
+'
+
+test_done
index 594d7a6..050877f 100755 (executable)
@@ -1107,9 +1107,16 @@ test_expect_success 'fetch exact SHA1' '
                        git config uploadpack.allowtipsha1inwant true
                ) &&
 
-               git fetch -v ../testrepo $the_commit:refs/heads/copy &&
-               result=$(git rev-parse --verify refs/heads/copy) &&
-               test "$the_commit" = "$result"
+               git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
+               cat >expect <<-EOF &&
+               $the_commit
+               $the_first_commit
+               EOF
+               {
+                       git rev-parse --verify refs/heads/copy &&
+                       git rev-parse --verify refs/heads/extra
+               } >actual &&
+               test_cmp expect actual
        )
 '
 
index 6cbc12d..b970773 100755 (executable)
@@ -213,6 +213,17 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
        test_cmp expect_cookies.txt cookies_tail.txt
 '
 
+test_expect_success 'transfer.hiderefs works over smart-http' '
+       test_commit hidden &&
+       test_commit visible &&
+       git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
+       git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
+               config transfer.hiderefs refs/heads/a &&
+       git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
+       test_must_fail git -C hidden.git rev-parse --verify a &&
+       git -C hidden.git rev-parse --verify b
+'
+
 test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
        (
        cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
index 51ecd3e..46d7d37 100755 (executable)
@@ -397,6 +397,17 @@ test_expect_success 'prompt - untracked files status indicator - untracked files
        test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' '
+       printf " (master %%)" >expected &&
+       (
+               mkdir -p ignored_dir &&
+               cd ignored_dir &&
+               GIT_PS1_SHOWUNTRACKEDFILES=y &&
+               __git_ps1 >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
 test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '
        printf " (master)" >expected &&
        test_config bash.showUntrackedFiles false &&
index 862f63f..88bde1d 100644 (file)
@@ -519,7 +519,7 @@ static int fetch_refs_via_pack(struct transport *transport,
                               int nr_heads, struct ref **to_fetch)
 {
        struct git_transport_data *data = transport->data;
-       const struct ref *refs;
+       struct ref *refs;
        char *dest = xstrdup(transport->url);
        struct fetch_pack_args args;
        struct ref *refs_tmp = NULL;
@@ -552,15 +552,17 @@ static int fetch_refs_via_pack(struct transport *transport,
                          &transport->pack_lockfile);
        close(data->fd[0]);
        close(data->fd[1]);
-       if (finish_connect(data->conn))
+       if (finish_connect(data->conn)) {
+               free_refs(refs);
                refs = NULL;
+       }
        data->conn = NULL;
        data->got_remote_heads = 0;
        data->options.self_contained_and_connected =
                args.self_contained_and_connected;
 
        free_refs(refs_tmp);
-
+       free_refs(refs);
        free(dest);
        return (refs ? 0 : -1);
 }
index b531a32..aa84576 100644 (file)
@@ -681,7 +681,7 @@ static void receive_needs(void)
 }
 
 /* return non-zero if the ref is hidden, otherwise 0 */
-static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+static int mark_our_ref(const char *refname, const unsigned char *sha1)
 {
        struct object *o = lookup_unknown_object(sha1);
 
@@ -689,12 +689,16 @@ static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag
                o->flags |= HIDDEN_REF;
                return 1;
        }
-       if (!o)
-               die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
        o->flags |= OUR_REF;
        return 0;
 }
 
+static int check_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+{
+       mark_our_ref(refname, sha1);
+       return 0;
+}
+
 static void format_symref_info(struct strbuf *buf, struct string_list *symref)
 {
        struct string_list_item *item;
@@ -713,7 +717,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
        const char *refname_nons = strip_namespace(refname);
        unsigned char peeled[20];
 
-       if (mark_our_ref(refname, sha1, flag, NULL))
+       if (mark_our_ref(refname, sha1))
                return 0;
 
        if (capabilities) {
@@ -767,8 +771,8 @@ static void upload_pack(void)
                advertise_shallow_grafts(1);
                packet_flush(1);
        } else {
-               head_ref_namespaced(mark_our_ref, NULL);
-               for_each_namespaced_ref(mark_our_ref, NULL);
+               head_ref_namespaced(check_ref, NULL);
+               for_each_namespaced_ref(check_ref, NULL);
        }
        string_list_clear(&symref, 1);
        if (advertise_refs)