Merge branch 'jk/fully-peeled-packed-ref' into maint-1.8.1
authorJunio C Hamano <gitster@pobox.com>
Wed, 3 Apr 2013 15:43:03 +0000 (08:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Apr 2013 15:43:03 +0000 (08:43 -0700)
* jk/fully-peeled-packed-ref:
pack-refs: add fully-peeled trait
pack-refs: write peeled entry for non-tags
use parse_object_or_die instead of die("bad object")
avoid segfaults on parse_object failure

1  2 
builtin/grep.c
builtin/prune.c
bundle.c
refs.c
diff --combined builtin/grep.c
index 0e1b6c860e18c6c47f343fad885cbd24f641862e,08ea5fdec844604e6a48b9a5f6c7bbc74df651dc..e8f0f92cf739c87c19d2be1722b6093ddbed7330
@@@ -19,7 -19,7 +19,7 @@@
  #include "dir.h"
  
  static char const * const grep_usage[] = {
 -      "git grep [options] [-e] <pattern> [<rev>...] [[--] <path>...]",
 +      N_("git grep [options] [-e] <pattern> [<rev>...] [[--] <path>...]"),
        NULL
  };
  
@@@ -86,7 -86,7 +86,7 @@@ static pthread_cond_t cond_result
  static int skip_first_line;
  
  static void add_work(struct grep_opt *opt, enum grep_source_type type,
 -                   const char *name, const void *id)
 +                   const char *name, const char *path, const void *id)
  {
        grep_lock();
  
@@@ -94,7 -94,7 +94,7 @@@
                pthread_cond_wait(&cond_write, &grep_mutex);
        }
  
 -      grep_source_init(&todo[todo_end].source, type, name, id);
 +      grep_source_init(&todo[todo_end].source, type, name, path, id);
        if (opt->binary != GREP_BINARY_TEXT)
                grep_source_load_driver(&todo[todo_end].source);
        todo[todo_end].done = 0;
@@@ -261,12 -261,51 +261,12 @@@ static int wait_all(void
  }
  #endif
  
 -static int grep_config(const char *var, const char *value, void *cb)
 +static int grep_cmd_config(const char *var, const char *value, void *cb)
  {
 -      struct grep_opt *opt = cb;
 -      char *color = NULL;
 -
 -      if (userdiff_config(var, value) < 0)
 -              return -1;
 -
 -      if (!strcmp(var, "grep.extendedregexp")) {
 -              if (git_config_bool(var, value))
 -                      opt->regflags |= REG_EXTENDED;
 -              else
 -                      opt->regflags &= ~REG_EXTENDED;
 -              return 0;
 -      }
 -
 -      if (!strcmp(var, "grep.linenumber")) {
 -              opt->linenum = git_config_bool(var, value);
 -              return 0;
 -      }
 -
 -      if (!strcmp(var, "color.grep"))
 -              opt->color = git_config_colorbool(var, value);
 -      else if (!strcmp(var, "color.grep.context"))
 -              color = opt->color_context;
 -      else if (!strcmp(var, "color.grep.filename"))
 -              color = opt->color_filename;
 -      else if (!strcmp(var, "color.grep.function"))
 -              color = opt->color_function;
 -      else if (!strcmp(var, "color.grep.linenumber"))
 -              color = opt->color_lineno;
 -      else if (!strcmp(var, "color.grep.match"))
 -              color = opt->color_match;
 -      else if (!strcmp(var, "color.grep.selected"))
 -              color = opt->color_selected;
 -      else if (!strcmp(var, "color.grep.separator"))
 -              color = opt->color_sep;
 -      else
 -              return git_color_default_config(var, value, cb);
 -      if (color) {
 -              if (!value)
 -                      return config_error_nonbool(var);
 -              color_parse(value, var, color);
 -      }
 -      return 0;
 +      int st = grep_config(var, value, cb);
 +      if (git_color_default_config(var, value, cb) < 0)
 +              st = -1;
 +      return st;
  }
  
  static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
  }
  
  static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
 -                   const char *filename, int tree_name_len)
 +                   const char *filename, int tree_name_len,
 +                   const char *path)
  {
        struct strbuf pathbuf = STRBUF_INIT;
  
  
  #ifndef NO_PTHREADS
        if (use_threads) {
 -              add_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, sha1);
 +              add_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1);
                strbuf_release(&pathbuf);
                return 0;
        } else
                struct grep_source gs;
                int hit;
  
 -              grep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, sha1);
 +              grep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1);
                strbuf_release(&pathbuf);
                hit = grep_source(opt, &gs);
  
@@@ -324,7 -362,7 +324,7 @@@ static int grep_file(struct grep_opt *o
  
  #ifndef NO_PTHREADS
        if (use_threads) {
 -              add_work(opt, GREP_SOURCE_FILE, buf.buf, filename);
 +              add_work(opt, GREP_SOURCE_FILE, buf.buf, filename, filename);
                strbuf_release(&buf);
                return 0;
        } else
                struct grep_source gs;
                int hit;
  
 -              grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename);
 +              grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename);
                strbuf_release(&buf);
                hit = grep_source(opt, &gs);
  
@@@ -389,7 -427,7 +389,7 @@@ static int grep_cache(struct grep_opt *
                if (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) {
                        if (ce_stage(ce))
                                continue;
 -                      hit |= grep_sha1(opt, ce->sha1, ce->name, 0);
 +                      hit |= grep_sha1(opt, ce->sha1, ce->name, 0, ce->name);
                }
                else
                        hit |= grep_file(opt, ce->name);
  }
  
  static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
 -                   struct tree_desc *tree, struct strbuf *base, int tn_len)
 +                   struct tree_desc *tree, struct strbuf *base, int tn_len,
 +                   int check_attr)
  {
        int hit = 0;
        enum interesting match = entry_not_interesting;
                strbuf_add(base, entry.path, te_len);
  
                if (S_ISREG(entry.mode)) {
 -                      hit |= grep_sha1(opt, entry.sha1, base->buf, tn_len);
 +                      hit |= grep_sha1(opt, entry.sha1, base->buf, tn_len,
 +                                       check_attr ? base->buf + tn_len : NULL);
                }
                else if (S_ISDIR(entry.mode)) {
                        enum object_type type;
  
                        strbuf_addch(base, '/');
                        init_tree_desc(&sub, data, size);
 -                      hit |= grep_tree(opt, pathspec, &sub, base, tn_len);
 +                      hit |= grep_tree(opt, pathspec, &sub, base, tn_len,
 +                                       check_attr);
                        free(data);
                }
                strbuf_setlen(base, old_baselen);
@@@ -461,7 -496,7 +461,7 @@@ static int grep_object(struct grep_opt 
                       struct object *obj, const char *name)
  {
        if (obj->type == OBJ_BLOB)
 -              return grep_sha1(opt, obj->sha1, name, 0);
 +              return grep_sha1(opt, obj->sha1, name, 0, NULL);
        if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
                struct tree_desc tree;
                void *data;
                        strbuf_addch(&base, ':');
                }
                init_tree_desc(&tree, data, size);
 -              hit = grep_tree(opt, pathspec, &tree, &base, base.len);
 +              hit = grep_tree(opt, pathspec, &tree, &base, base.len,
 +                              obj->type == OBJ_COMMIT);
                strbuf_release(&base);
                free(data);
                return hit;
@@@ -636,88 -670,95 +636,88 @@@ int cmd_grep(int argc, const char **arg
        int i;
        int dummy;
        int use_index = 1;
 -      enum {
 -              pattern_type_unspecified = 0,
 -              pattern_type_bre,
 -              pattern_type_ere,
 -              pattern_type_fixed,
 -              pattern_type_pcre,
 -      };
 -      int pattern_type = pattern_type_unspecified;
 +      int pattern_type_arg = GREP_PATTERN_TYPE_UNSPECIFIED;
  
        struct option options[] = {
                OPT_BOOLEAN(0, "cached", &cached,
 -                      "search in index instead of in the work tree"),
 +                      N_("search in index instead of in the work tree")),
                OPT_NEGBIT(0, "no-index", &use_index,
 -                       "finds in contents not managed by git", 1),
 +                       N_("find in contents not managed by git"), 1),
                OPT_BOOLEAN(0, "untracked", &untracked,
 -                      "search in both tracked and untracked files"),
 +                      N_("search in both tracked and untracked files")),
                OPT_SET_INT(0, "exclude-standard", &opt_exclude,
 -                          "search also in ignored files", 1),
 +                          N_("search also in ignored files"), 1),
                OPT_GROUP(""),
                OPT_BOOLEAN('v', "invert-match", &opt.invert,
 -                      "show non-matching lines"),
 +                      N_("show non-matching lines")),
                OPT_BOOLEAN('i', "ignore-case", &opt.ignore_case,
 -                      "case insensitive matching"),
 +                      N_("case insensitive matching")),
                OPT_BOOLEAN('w', "word-regexp", &opt.word_regexp,
 -                      "match patterns only at word boundaries"),
 +                      N_("match patterns only at word boundaries")),
                OPT_SET_INT('a', "text", &opt.binary,
 -                      "process binary files as text", GREP_BINARY_TEXT),
 +                      N_("process binary files as text"), GREP_BINARY_TEXT),
                OPT_SET_INT('I', NULL, &opt.binary,
 -                      "don't match patterns in binary files",
 +                      N_("don't match patterns in binary files"),
                        GREP_BINARY_NOMATCH),
 -              { OPTION_INTEGER, 0, "max-depth", &opt.max_depth, "depth",
 -                      "descend at most <depth> levels", PARSE_OPT_NONEG,
 +              { OPTION_INTEGER, 0, "max-depth", &opt.max_depth, N_("depth"),
 +                      N_("descend at most <depth> levels"), PARSE_OPT_NONEG,
                        NULL, 1 },
                OPT_GROUP(""),
 -              OPT_SET_INT('E', "extended-regexp", &pattern_type,
 -                          "use extended POSIX regular expressions",
 -                          pattern_type_ere),
 -              OPT_SET_INT('G', "basic-regexp", &pattern_type,
 -                          "use basic POSIX regular expressions (default)",
 -                          pattern_type_bre),
 -              OPT_SET_INT('F', "fixed-strings", &pattern_type,
 -                          "interpret patterns as fixed strings",
 -                          pattern_type_fixed),
 -              OPT_SET_INT('P', "perl-regexp", &pattern_type,
 -                          "use Perl-compatible regular expressions",
 -                          pattern_type_pcre),
 +              OPT_SET_INT('E', "extended-regexp", &pattern_type_arg,
 +                          N_("use extended POSIX regular expressions"),
 +                          GREP_PATTERN_TYPE_ERE),
 +              OPT_SET_INT('G', "basic-regexp", &pattern_type_arg,
 +                          N_("use basic POSIX regular expressions (default)"),
 +                          GREP_PATTERN_TYPE_BRE),
 +              OPT_SET_INT('F', "fixed-strings", &pattern_type_arg,
 +                          N_("interpret patterns as fixed strings"),
 +                          GREP_PATTERN_TYPE_FIXED),
 +              OPT_SET_INT('P', "perl-regexp", &pattern_type_arg,
 +                          N_("use Perl-compatible regular expressions"),
 +                          GREP_PATTERN_TYPE_PCRE),
                OPT_GROUP(""),
 -              OPT_BOOLEAN('n', "line-number", &opt.linenum, "show line numbers"),
 -              OPT_NEGBIT('h', NULL, &opt.pathname, "don't show filenames", 1),
 -              OPT_BIT('H', NULL, &opt.pathname, "show filenames", 1),
 +              OPT_BOOLEAN('n', "line-number", &opt.linenum, N_("show line numbers")),
 +              OPT_NEGBIT('h', NULL, &opt.pathname, N_("don't show filenames"), 1),
 +              OPT_BIT('H', NULL, &opt.pathname, N_("show filenames"), 1),
                OPT_NEGBIT(0, "full-name", &opt.relative,
 -                      "show filenames relative to top directory", 1),
 +                      N_("show filenames relative to top directory"), 1),
                OPT_BOOLEAN('l', "files-with-matches", &opt.name_only,
 -                      "show only filenames instead of matching lines"),
 +                      N_("show only filenames instead of matching lines")),
                OPT_BOOLEAN(0, "name-only", &opt.name_only,
 -                      "synonym for --files-with-matches"),
 +                      N_("synonym for --files-with-matches")),
                OPT_BOOLEAN('L', "files-without-match",
                        &opt.unmatch_name_only,
 -                      "show only the names of files without match"),
 +                      N_("show only the names of files without match")),
                OPT_BOOLEAN('z', "null", &opt.null_following_name,
 -                      "print NUL after filenames"),
 +                      N_("print NUL after filenames")),
                OPT_BOOLEAN('c', "count", &opt.count,
 -                      "show the number of matches instead of matching lines"),
 -              OPT__COLOR(&opt.color, "highlight matches"),
 +                      N_("show the number of matches instead of matching lines")),
 +              OPT__COLOR(&opt.color, N_("highlight matches")),
                OPT_BOOLEAN(0, "break", &opt.file_break,
 -                      "print empty line between matches from different files"),
 +                      N_("print empty line between matches from different files")),
                OPT_BOOLEAN(0, "heading", &opt.heading,
 -                      "show filename only once above matches from same file"),
 +                      N_("show filename only once above matches from same file")),
                OPT_GROUP(""),
 -              OPT_CALLBACK('C', "context", &opt, "n",
 -                      "show <n> context lines before and after matches",
 +              OPT_CALLBACK('C', "context", &opt, N_("n"),
 +                      N_("show <n> context lines before and after matches"),
                        context_callback),
                OPT_INTEGER('B', "before-context", &opt.pre_context,
 -                      "show <n> context lines before matches"),
 +                      N_("show <n> context lines before matches")),
                OPT_INTEGER('A', "after-context", &opt.post_context,
 -                      "show <n> context lines after matches"),
 -              OPT_NUMBER_CALLBACK(&opt, "shortcut for -C NUM",
 +                      N_("show <n> context lines after matches")),
 +              OPT_NUMBER_CALLBACK(&opt, N_("shortcut for -C NUM"),
                        context_callback),
                OPT_BOOLEAN('p', "show-function", &opt.funcname,
 -                      "show a line with the function name before matches"),
 +                      N_("show a line with the function name before matches")),
                OPT_BOOLEAN('W', "function-context", &opt.funcbody,
 -                      "show the surrounding function"),
 +                      N_("show the surrounding function")),
                OPT_GROUP(""),
 -              OPT_CALLBACK('f', NULL, &opt, "file",
 -                      "read patterns from file", file_callback),
 -              { OPTION_CALLBACK, 'e', NULL, &opt, "pattern",
 -                      "match <pattern>", PARSE_OPT_NONEG, pattern_callback },
 +              OPT_CALLBACK('f', NULL, &opt, N_("file"),
 +                      N_("read patterns from file"), file_callback),
 +              { OPTION_CALLBACK, 'e', NULL, &opt, N_("pattern"),
 +                      N_("match <pattern>"), PARSE_OPT_NONEG, pattern_callback },
                { OPTION_CALLBACK, 0, "and", &opt, NULL,
 -                "combine patterns specified with -e",
 +                N_("combine patterns specified with -e"),
                  PARSE_OPT_NOARG | PARSE_OPT_NONEG, and_callback },
                OPT_BOOLEAN(0, "or", &dummy, ""),
                { OPTION_CALLBACK, 0, "not", &opt, NULL, "",
                  PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH,
                  close_callback },
                OPT__QUIET(&opt.status_only,
 -                         "indicate hit with exit status without output"),
 +                         N_("indicate hit with exit status without output")),
                OPT_BOOLEAN(0, "all-match", &opt.all_match,
 -                      "show only matches from files that match all patterns"),
 +                      N_("show only matches from files that match all patterns")),
                { OPTION_SET_INT, 0, "debug", &opt.debug, NULL,
 -                "show parse tree for grep expression",
 +                N_("show parse tree for grep expression"),
                  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 },
                OPT_GROUP(""),
                { OPTION_STRING, 'O', "open-files-in-pager", &show_in_pager,
 -                      "pager", "show matching files in the pager",
 +                      N_("pager"), N_("show matching files in the pager"),
                        PARSE_OPT_OPTARG, NULL, (intptr_t)default_pager },
                OPT_BOOLEAN(0, "ext-grep", &external_grep_allowed__ignored,
 -                          "allow calling of grep(1) (ignored by this build)"),
 -              { OPTION_CALLBACK, 0, "help-all", &options, NULL, "show usage",
 +                          N_("allow calling of grep(1) (ignored by this build)")),
 +              { OPTION_CALLBACK, 0, "help-all", &options, NULL, N_("show usage"),
                  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback },
                OPT_END()
        };
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(grep_usage, options);
  
 -      memset(&opt, 0, sizeof(opt));
 -      opt.prefix = prefix;
 -      opt.prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;
 -      opt.relative = 1;
 -      opt.pathname = 1;
 -      opt.pattern_tail = &opt.pattern_list;
 -      opt.header_tail = &opt.header_list;
 -      opt.regflags = REG_NEWLINE;
 -      opt.max_depth = -1;
 -
 -      strcpy(opt.color_context, "");
 -      strcpy(opt.color_filename, "");
 -      strcpy(opt.color_function, "");
 -      strcpy(opt.color_lineno, "");
 -      strcpy(opt.color_match, GIT_COLOR_BOLD_RED);
 -      strcpy(opt.color_selected, "");
 -      strcpy(opt.color_sep, GIT_COLOR_CYAN);
 -      opt.color = -1;
 -      git_config(grep_config, &opt);
 +      init_grep_defaults();
 +      git_config(grep_cmd_config, NULL);
 +      grep_init(&opt, prefix);
  
        /*
         * If there is no -- then the paths must exist in the working
                             PARSE_OPT_KEEP_DASHDASH |
                             PARSE_OPT_STOP_AT_NON_OPTION |
                             PARSE_OPT_NO_INTERNAL_HELP);
 -      switch (pattern_type) {
 -      case pattern_type_fixed:
 -              opt.fixed = 1;
 -              opt.pcre = 0;
 -              break;
 -      case pattern_type_bre:
 -              opt.fixed = 0;
 -              opt.pcre = 0;
 -              opt.regflags &= ~REG_EXTENDED;
 -              break;
 -      case pattern_type_ere:
 -              opt.fixed = 0;
 -              opt.pcre = 0;
 -              opt.regflags |= REG_EXTENDED;
 -              break;
 -      case pattern_type_pcre:
 -              opt.fixed = 0;
 -              opt.pcre = 1;
 -              break;
 -      default:
 -              break; /* nothing */
 -      }
 +      grep_commit_pattern_type(pattern_type_arg, &opt);
  
        if (use_index && !startup_info->have_repository)
                /* die the same way as if we did it at the beginning */
                unsigned char sha1[20];
                /* Is it a rev? */
                if (!get_sha1(arg, sha1)) {
-                       struct object *object = parse_object(sha1);
-                       if (!object)
-                               die(_("bad object %s"), arg);
+                       struct object *object = parse_object_or_die(sha1, arg);
                        add_object_array(object, arg, &list);
                        continue;
                }
diff --combined builtin/prune.c
index 8cb8b9186a3a268630680e4b224d3767017e1e38,67ca3d5699beb41394e722b7e0ab128eb3a9aa8f..85843d4f1728a907aafab9938b4c827990a7695f
@@@ -9,7 -9,7 +9,7 @@@
  #include "dir.h"
  
  static const char * const prune_usage[] = {
 -      "git prune [-n] [-v] [--expire <time>] [--] [<head>...]",
 +      N_("git prune [-n] [-v] [--expire <time>] [--] [<head>...]"),
        NULL
  };
  static int show_only;
@@@ -129,11 -129,11 +129,11 @@@ int cmd_prune(int argc, const char **ar
        struct rev_info revs;
        struct progress *progress = NULL;
        const struct option options[] = {
 -              OPT__DRY_RUN(&show_only, "do not remove, show only"),
 -              OPT__VERBOSE(&verbose, "report pruned objects"),
 -              OPT_BOOL(0, "progress", &show_progress, "show progress"),
 +              OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
 +              OPT__VERBOSE(&verbose, N_("report pruned objects")),
 +              OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
                OPT_DATE(0, "expire", &expire,
 -                       "expire objects older than <time>"),
 +                       N_("expire objects older than <time>")),
                OPT_END()
        };
        char *s;
                const char *name = *argv++;
  
                if (!get_sha1(name, sha1)) {
-                       struct object *object = parse_object(sha1);
-                       if (!object)
-                               die("bad object: %s", name);
+                       struct object *object = parse_object_or_die(sha1, name);
                        add_pending_object(&revs, object, "");
                }
                else
  
        prune_packed_objects(show_only);
        remove_temporary_files(get_object_directory());
 -      s = xstrdup(mkpath("%s/pack", get_object_directory()));
 +      s = mkpathdup("%s/pack", get_object_directory());
        remove_temporary_files(s);
        free(s);
        return 0;
diff --combined bundle.c
index 6210a6be894fb3f5538eb2939c6dc4212382ae2d,26ceebdb4bdd22949ac35acb5e07b3bce6f22339..505e07e93468b68454c7ec906f40eacea9746551
+++ b/bundle.c
@@@ -183,17 -183,17 +183,17 @@@ int verify_bundle(struct bundle_header 
                struct ref_list *r;
  
                r = &header->references;
 -              printf_ln(Q_("The bundle contains %d ref",
 -                           "The bundle contains %d refs",
 +              printf_ln(Q_("The bundle contains this ref:",
 +                           "The bundle contains these %d refs:",
                             r->nr),
                          r->nr);
                list_refs(r, 0, NULL);
 +              r = &header->prerequisites;
                if (!r->nr) {
                        printf_ln(_("The bundle records a complete history."));
                } else {
 -                      r = &header->prerequisites;
 -                      printf_ln(Q_("The bundle requires this ref",
 -                                   "The bundle requires these %d refs",
 +                      printf_ln(Q_("The bundle requires this ref:",
 +                                   "The bundle requires these %d refs:",
                                     r->nr),
                                  r->nr);
                        list_refs(r, 0, NULL);
@@@ -279,12 -279,12 +279,12 @@@ int create_bundle(struct bundle_header 
                if (buf.len > 0 && buf.buf[0] == '-') {
                        write_or_die(bundle_fd, buf.buf, buf.len);
                        if (!get_sha1_hex(buf.buf + 1, sha1)) {
-                               struct object *object = parse_object(sha1);
+                               struct object *object = parse_object_or_die(sha1, buf.buf);
                                object->flags |= UNINTERESTING;
                                add_pending_object(&revs, object, xstrdup(buf.buf));
                        }
                } else if (!get_sha1_hex(buf.buf, sha1)) {
-                       struct object *object = parse_object(sha1);
+                       struct object *object = parse_object_or_die(sha1, buf.buf);
                        object->flags |= SHOWN;
                }
        }
                                 * end up triggering "empty bundle"
                                 * error.
                                 */
-                               obj = parse_object(sha1);
+                               obj = parse_object_or_die(sha1, e->name);
                                obj->flags |= SHOWN;
                                add_pending_object(&revs, obj, e->name);
                        }
diff --combined refs.c
index 541fec20658082f13ef4b73b621787512b300ba6,f5d954c27e8994b60a9f7d937700693db8b51221..6770e962a94cc4f1709fe7e7741f0a896a416aed
--- 1/refs.c
--- 2/refs.c
+++ b/refs.c
@@@ -804,11 -804,38 +804,38 @@@ static const char *parse_ref_line(char 
        return line;
  }
  
+ /*
+  * Read f, which is a packed-refs file, into dir.
+  *
+  * A comment line of the form "# pack-refs with: " may contain zero or
+  * more traits. We interpret the traits as follows:
+  *
+  *   No traits:
+  *
+  *      Probably no references are peeled. But if the file contains a
+  *      peeled value for a reference, we will use it.
+  *
+  *   peeled:
+  *
+  *      References under "refs/tags/", if they *can* be peeled, *are*
+  *      peeled in this file. References outside of "refs/tags/" are
+  *      probably not peeled even if they could have been, but if we find
+  *      a peeled value for such a reference we will use it.
+  *
+  *   fully-peeled:
+  *
+  *      All references in the file that can be peeled are peeled.
+  *      Inversely (and this is more important), any references in the
+  *      file for which no peeled value is recorded is not peelable. This
+  *      trait should typically be written alongside "peeled" for
+  *      compatibility with older clients, but we do not require it
+  *      (i.e., "peeled" is a no-op if "fully-peeled" is set).
+  */
  static void read_packed_refs(FILE *f, struct ref_dir *dir)
  {
        struct ref_entry *last = NULL;
        char refline[PATH_MAX];
-       int flag = REF_ISPACKED;
+       enum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled = PEELED_NONE;
  
        while (fgets(refline, sizeof(refline), f)) {
                unsigned char sha1[20];
  
                if (!strncmp(refline, header, sizeof(header)-1)) {
                        const char *traits = refline + sizeof(header) - 1;
-                       if (strstr(traits, " peeled "))
-                               flag |= REF_KNOWS_PEELED;
+                       if (strstr(traits, " fully-peeled "))
+                               peeled = PEELED_FULLY;
+                       else if (strstr(traits, " peeled "))
+                               peeled = PEELED_TAGS;
                        /* perhaps other traits later as well */
                        continue;
                }
  
                refname = parse_ref_line(refline, sha1);
                if (refname) {
-                       last = create_ref_entry(refname, sha1, flag, 1);
+                       last = create_ref_entry(refname, sha1, REF_ISPACKED, 1);
+                       if (peeled == PEELED_FULLY ||
+                           (peeled == PEELED_TAGS && !prefixcmp(refname, "refs/tags/")))
+                               last->flag |= REF_KNOWS_PEELED;
                        add_ref(dir, last);
                        continue;
                }
                    refline[0] == '^' &&
                    strlen(refline) == 42 &&
                    refline[41] == '\n' &&
-                   !get_sha1_hex(refline + 1, sha1))
+                   !get_sha1_hex(refline + 1, sha1)) {
                        hashcpy(last->u.value.peeled, sha1);
+                       /*
+                        * Regardless of what the file header said,
+                        * we definitely know the value of *this*
+                        * reference:
+                        */
+                       last->flag |= REF_KNOWS_PEELED;
+               }
        }
  }
  
@@@ -1202,8 -1241,6 +1241,8 @@@ int peel_ref(const char *refname, unsig
        if (current_ref && (current_ref->name == refname
                || !strcmp(current_ref->name, refname))) {
                if (current_ref->flag & REF_KNOWS_PEELED) {
 +                      if (is_null_sha1(current_ref->u.value.peeled))
 +                          return -1;
                        hashcpy(sha1, current_ref->u.value.peeled);
                        return 0;
                }
        }
  
  fallback:
 -      o = parse_object(base);
 -      if (o && o->type == OBJ_TAG) {
 -              o = deref_tag(o, refname, 0);
 +      o = lookup_unknown_object(base);
 +      if (o->type == OBJ_NONE) {
 +              int type = sha1_object_info(base, NULL);
 +              if (type < 0)
 +                      return -1;
 +              o->type = type;
 +      }
 +
 +      if (o->type == OBJ_TAG) {
 +              o = deref_tag_noverify(o);
                if (o) {
                        hashcpy(sha1, o->sha1);
                        return 0;
@@@ -1744,8 -1774,7 +1783,8 @@@ static struct lock_file packlock
  static int repack_without_ref(const char *refname)
  {
        struct repack_without_ref_sb data;
 -      struct ref_dir *packed = get_packed_refs(get_ref_cache(NULL));
 +      struct ref_cache *refs = get_ref_cache(NULL);
 +      struct ref_dir *packed = get_packed_refs(refs);
        if (find_ref(packed, refname) == NULL)
                return 0;
        data.refname = refname;
                unable_to_lock_error(git_path("packed-refs"), errno);
                return error("cannot delete '%s' from packed refs", refname);
        }
 +      clear_packed_ref_cache(refs);
 +      packed = get_packed_refs(refs);
        do_for_each_ref_in_dir(packed, 0, "", repack_without_ref_fn, 0, 0, &data);
        return commit_lock_file(&packlock);
  }
@@@ -1765,24 -1792,32 +1804,24 @@@ int delete_ref(const char *refname, con
        struct ref_lock *lock;
        int err, i = 0, ret = 0, flag = 0;
  
 -      lock = lock_ref_sha1_basic(refname, sha1, 0, &flag);
 +      lock = lock_ref_sha1_basic(refname, sha1, delopt, &flag);
        if (!lock)
                return 1;
        if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
                /* loose */
 -              const char *path;
 -
 -              if (!(delopt & REF_NODEREF)) {
 -                      i = strlen(lock->lk->filename) - 5; /* .lock */
 -                      lock->lk->filename[i] = 0;
 -                      path = lock->lk->filename;
 -              } else {
 -                      path = git_path("%s", refname);
 -              }
 -              err = unlink_or_warn(path);
 +              i = strlen(lock->lk->filename) - 5; /* .lock */
 +              lock->lk->filename[i] = 0;
 +              err = unlink_or_warn(lock->lk->filename);
                if (err && errno != ENOENT)
                        ret = 1;
  
 -              if (!(delopt & REF_NODEREF))
 -                      lock->lk->filename[i] = '.';
 +              lock->lk->filename[i] = '.';
        }
        /* removing the loose one could have resurrected an earlier
         * packed one.  Also, if it was not loose we need to repack
         * without it.
         */
 -      ret |= repack_without_ref(refname);
 +      ret |= repack_without_ref(lock->ref_name);
  
        unlink_or_warn(git_path("logs/%s", lock->ref_name));
        invalidate_ref_cache(NULL);