Merge branch 'jk/peel-ref'
authorJeff King <peff@peff.net>
Thu, 25 Oct 2012 10:42:27 +0000 (06:42 -0400)
committerJeff King <peff@peff.net>
Thu, 25 Oct 2012 10:42:27 +0000 (06:42 -0400)
Speeds up "git upload-pack" (what is invoked by "git fetch" on the
other side of the connection) by reducing the cost to advertise the
branches and tags that are available in the repository.

* jk/peel-ref:
upload-pack: use peel_ref for ref advertisements
peel_ref: check object type before loading
peel_ref: do not return a null sha1
peel_ref: use faster deref_tag_noverify

1  2 
builtin/describe.c
builtin/pack-objects.c
builtin/show-ref.c
diff --combined builtin/describe.c
index 9fe11ed9de7b9e5c13187a630c45d8e44f50c851,94b06069a0f79e2300c6e56239d61eeebde992d5..04c185b1fbdc51ba9958fdb83d1c6616bcb0c18e
@@@ -12,8 -12,8 +12,8 @@@
  #define MAX_TAGS      (FLAG_BITS - 1)
  
  static const char * const describe_usage[] = {
 -      "git describe [options] <committish>*",
 -      "git describe [options] --dirty",
 +      N_("git describe [options] <committish>*"),
 +      N_("git describe [options] --dirty"),
        NULL
  };
  
@@@ -144,7 -144,7 +144,7 @@@ static int get_name(const char *path, c
        if (!all && !might_be_tag)
                return 0;
  
-       if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {
+       if (!peel_ref(path, peeled)) {
                is_tag = !!hashcmp(sha1, peeled);
        } else {
                hashcpy(peeled, sha1);
@@@ -400,22 -400,22 +400,22 @@@ int cmd_describe(int argc, const char *
  {
        int contains = 0;
        struct option options[] = {
 -              OPT_BOOLEAN(0, "contains",   &contains, "find the tag that comes after the commit"),
 -              OPT_BOOLEAN(0, "debug",      &debug, "debug search strategy on stderr"),
 -              OPT_BOOLEAN(0, "all",        &all, "use any ref in .git/refs"),
 -              OPT_BOOLEAN(0, "tags",       &tags, "use any tag in .git/refs/tags"),
 -              OPT_BOOLEAN(0, "long",       &longformat, "always use long format"),
 +              OPT_BOOLEAN(0, "contains",   &contains, N_("find the tag that comes after the commit")),
 +              OPT_BOOLEAN(0, "debug",      &debug, N_("debug search strategy on stderr")),
 +              OPT_BOOLEAN(0, "all",        &all, N_("use any ref in .git/refs")),
 +              OPT_BOOLEAN(0, "tags",       &tags, N_("use any tag in .git/refs/tags")),
 +              OPT_BOOLEAN(0, "long",       &longformat, N_("always use long format")),
                OPT__ABBREV(&abbrev),
                OPT_SET_INT(0, "exact-match", &max_candidates,
 -                          "only output exact matches", 0),
 +                          N_("only output exact matches"), 0),
                OPT_INTEGER(0, "candidates", &max_candidates,
 -                          "consider <n> most recent tags (default: 10)"),
 -              OPT_STRING(0, "match",       &pattern, "pattern",
 -                         "only consider tags matching <pattern>"),
 +                          N_("consider <n> most recent tags (default: 10)")),
 +              OPT_STRING(0, "match",       &pattern, N_("pattern"),
 +                         N_("only consider tags matching <pattern>")),
                OPT_BOOLEAN(0, "always",     &always,
 -                         "show abbreviated commit object as fallback"),
 -              {OPTION_STRING, 0, "dirty",  &dirty, "mark",
 -                         "append <mark> on dirty working tree (default: \"-dirty\")",
 +                         N_("show abbreviated commit object as fallback")),
 +              {OPTION_STRING, 0, "dirty",  &dirty, N_("mark"),
 +                         N_("append <mark> on dirty working tree (default: \"-dirty\")"),
                 PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"},
                OPT_END(),
        };
diff --combined builtin/pack-objects.c
index 5e140640947cd9c38da00a01d8db9f036e8babd7,035ed3b2d0e21a725c002779aad54987e317cee1..f069462cb03bbae46dae8d6b97420b3726690c47
@@@ -20,8 -20,8 +20,8 @@@
  #include "thread-utils.h"
  
  static const char *pack_usage[] = {
 -      "git pack-objects --stdout [options...] [< ref-list | < object-list]",
 -      "git pack-objects [options...] base-name [< ref-list | < object-list]",
 +      N_("git pack-objects --stdout [options...] [< ref-list | < object-list]"),
 +      N_("git pack-objects [options...] base-name [< ref-list | < object-list]"),
        NULL
  };
  
@@@ -2033,7 -2033,6 +2033,6 @@@ static int add_ref_tag(const char *path
  
        if (!prefixcmp(path, "refs/tags/") && /* is a tag? */
            !peel_ref(path, peeled)        && /* peelable? */
-           !is_null_sha1(peeled)          && /* annotated tag? */
            locate_object_entry(peeled))      /* object packed? */
                add_object_entry(sha1, OBJ_TAG, NULL, 0);
        return 0;
@@@ -2445,67 -2444,67 +2444,67 @@@ int cmd_pack_objects(int argc, const ch
        int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0;
        struct option pack_objects_options[] = {
                OPT_SET_INT('q', "quiet", &progress,
 -                          "do not show progress meter", 0),
 +                          N_("do not show progress meter"), 0),
                OPT_SET_INT(0, "progress", &progress,
 -                          "show progress meter", 1),
 +                          N_("show progress meter"), 1),
                OPT_SET_INT(0, "all-progress", &progress,
 -                          "show progress meter during object writing phase", 2),
 +                          N_("show progress meter during object writing phase"), 2),
                OPT_BOOL(0, "all-progress-implied",
                         &all_progress_implied,
 -                       "similar to --all-progress when progress meter is shown"),
 -              { OPTION_CALLBACK, 0, "index-version", NULL, "version[,offset]",
 -                "write the pack index file in the specified idx format version",
 +                       N_("similar to --all-progress when progress meter is shown")),
 +              { OPTION_CALLBACK, 0, "index-version", NULL, N_("version[,offset]"),
 +                N_("write the pack index file in the specified idx format version"),
                  0, option_parse_index_version },
                OPT_ULONG(0, "max-pack-size", &pack_size_limit,
 -                        "maximum size of each output pack file"),
 +                        N_("maximum size of each output pack file")),
                OPT_BOOL(0, "local", &local,
 -                       "ignore borrowed objects from alternate object store"),
 +                       N_("ignore borrowed objects from alternate object store")),
                OPT_BOOL(0, "incremental", &incremental,
 -                       "ignore packed objects"),
 +                       N_("ignore packed objects")),
                OPT_INTEGER(0, "window", &window,
 -                          "limit pack window by objects"),
 +                          N_("limit pack window by objects")),
                OPT_ULONG(0, "window-memory", &window_memory_limit,
 -                        "limit pack window by memory in addition to object limit"),
 +                        N_("limit pack window by memory in addition to object limit")),
                OPT_INTEGER(0, "depth", &depth,
 -                          "maximum length of delta chain allowed in the resulting pack"),
 +                          N_("maximum length of delta chain allowed in the resulting pack")),
                OPT_BOOL(0, "reuse-delta", &reuse_delta,
 -                       "reuse existing deltas"),
 +                       N_("reuse existing deltas")),
                OPT_BOOL(0, "reuse-object", &reuse_object,
 -                       "reuse existing objects"),
 +                       N_("reuse existing objects")),
                OPT_BOOL(0, "delta-base-offset", &allow_ofs_delta,
 -                       "use OFS_DELTA objects"),
 +                       N_("use OFS_DELTA objects")),
                OPT_INTEGER(0, "threads", &delta_search_threads,
 -                          "use threads when searching for best delta matches"),
 +                          N_("use threads when searching for best delta matches")),
                OPT_BOOL(0, "non-empty", &non_empty,
 -                       "do not create an empty pack output"),
 +                       N_("do not create an empty pack output")),
                OPT_BOOL(0, "revs", &use_internal_rev_list,
 -                       "read revision arguments from standard input"),
 +                       N_("read revision arguments from standard input")),
                { OPTION_SET_INT, 0, "unpacked", &rev_list_unpacked, NULL,
 -                "limit the objects to those that are not yet packed",
 +                N_("limit the objects to those that are not yet packed"),
                  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },
                { OPTION_SET_INT, 0, "all", &rev_list_all, NULL,
 -                "include objects reachable from any reference",
 +                N_("include objects reachable from any reference"),
                  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },
                { OPTION_SET_INT, 0, "reflog", &rev_list_reflog, NULL,
 -                "include objects referred by reflog entries",
 +                N_("include objects referred by reflog entries"),
                  PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },
                OPT_BOOL(0, "stdout", &pack_to_stdout,
 -                       "output pack to stdout"),
 +                       N_("output pack to stdout")),
                OPT_BOOL(0, "include-tag", &include_tag,
 -                       "include tag objects that refer to objects to be packed"),
 +                       N_("include tag objects that refer to objects to be packed")),
                OPT_BOOL(0, "keep-unreachable", &keep_unreachable,
 -                       "keep unreachable objects"),
 -              { OPTION_CALLBACK, 0, "unpack-unreachable", NULL, "time",
 -                "unpack unreachable objects newer than <time>",
 +                       N_("keep unreachable objects")),
 +              { OPTION_CALLBACK, 0, "unpack-unreachable", NULL, N_("time"),
 +                N_("unpack unreachable objects newer than <time>"),
                  PARSE_OPT_OPTARG, option_parse_unpack_unreachable },
                OPT_BOOL(0, "thin", &thin,
 -                       "create thin packs"),
 +                       N_("create thin packs")),
                OPT_BOOL(0, "honor-pack-keep", &ignore_packed_keep,
 -                       "ignore packs that have companion .keep file"),
 +                       N_("ignore packs that have companion .keep file")),
                OPT_INTEGER(0, "compression", &pack_compression_level,
 -                          "pack compression level"),
 +                          N_("pack compression level")),
                OPT_SET_INT(0, "keep-true-parents", &grafts_replace_parents,
 -                          "do not hide commits by grafts", 0),
 +                          N_("do not hide commits by grafts"), 0),
                OPT_END(),
        };
  
diff --combined builtin/show-ref.c
index 4eb016d6e53628f19d51a50aeb074bf424154026,aaac2b22f942e0ea69404a0af4c198a8287154b0..8d9b76a02fd115c0285216c27c5232f345d0582d
@@@ -7,8 -7,8 +7,8 @@@
  #include "parse-options.h"
  
  static const char * const show_ref_usage[] = {
 -      "git show-ref [-q|--quiet] [--verify] [--head] [-d|--dereference] [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [pattern*] ",
 -      "git show-ref --exclude-existing[=pattern] < ref-list",
 +      N_("git show-ref [-q|--quiet] [--verify] [--head] [-d|--dereference] [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [pattern*] "),
 +      N_("git show-ref --exclude-existing[=pattern] < ref-list"),
        NULL
  };
  
@@@ -28,7 -28,6 +28,6 @@@ static void show_one(const char *refnam
  
  static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
  {
-       struct object *obj;
        const char *hex;
        unsigned char peeled[20];
  
@@@ -79,25 -78,9 +78,9 @@@ match
        if (!deref_tags)
                return 0;
  
-       if ((flag & REF_ISPACKED) && !peel_ref(refname, peeled)) {
-               if (!is_null_sha1(peeled)) {
-                       hex = find_unique_abbrev(peeled, abbrev);
-                       printf("%s %s^{}\n", hex, refname);
-               }
-       }
-       else {
-               obj = parse_object(sha1);
-               if (!obj)
-                       die("git show-ref: bad ref %s (%s)", refname,
-                           sha1_to_hex(sha1));
-               if (obj->type == OBJ_TAG) {
-                       obj = deref_tag(obj, refname, 0);
-                       if (!obj)
-                               die("git show-ref: bad tag at ref %s (%s)", refname,
-                                   sha1_to_hex(sha1));
-                       hex = find_unique_abbrev(obj->sha1, abbrev);
-                       printf("%s %s^{}\n", hex, refname);
-               }
+       if (!peel_ref(refname, peeled)) {
+               hex = find_unique_abbrev(peeled, abbrev);
+               printf("%s %s^{}\n", hex, refname);
        }
        return 0;
  }
@@@ -179,26 -162,26 +162,26 @@@ static int help_callback(const struct o
  }
  
  static const struct option show_ref_options[] = {
 -      OPT_BOOLEAN(0, "tags", &tags_only, "only show tags (can be combined with heads)"),
 -      OPT_BOOLEAN(0, "heads", &heads_only, "only show heads (can be combined with tags)"),
 -      OPT_BOOLEAN(0, "verify", &verify, "stricter reference checking, "
 -                  "requires exact ref path"),
 +      OPT_BOOLEAN(0, "tags", &tags_only, N_("only show tags (can be combined with heads)")),
 +      OPT_BOOLEAN(0, "heads", &heads_only, N_("only show heads (can be combined with tags)")),
 +      OPT_BOOLEAN(0, "verify", &verify, N_("stricter reference checking, "
 +                  "requires exact ref path")),
        { OPTION_BOOLEAN, 'h', NULL, &show_head, NULL,
 -        "show the HEAD reference",
 +        N_("show the HEAD reference"),
          PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
 -      OPT_BOOLEAN(0, "head", &show_head, "show the HEAD reference"),
 +      OPT_BOOLEAN(0, "head", &show_head, N_("show the HEAD reference")),
        OPT_BOOLEAN('d', "dereference", &deref_tags,
 -                  "dereference tags into object IDs"),
 -      { OPTION_CALLBACK, 's', "hash", &abbrev, "n",
 -        "only show SHA1 hash using <n> digits",
 +                  N_("dereference tags into object IDs")),
 +      { OPTION_CALLBACK, 's', "hash", &abbrev, N_("n"),
 +        N_("only show SHA1 hash using <n> digits"),
          PARSE_OPT_OPTARG, &hash_callback },
        OPT__ABBREV(&abbrev),
        OPT__QUIET(&quiet,
 -                 "do not print results to stdout (useful with --verify)"),
 +                 N_("do not print results to stdout (useful with --verify)")),
        { OPTION_CALLBACK, 0, "exclude-existing", &exclude_existing_arg,
 -        "pattern", "show refs from stdin that aren't in local repository",
 +        N_("pattern"), N_("show refs from stdin that aren't in local repository"),
          PARSE_OPT_OPTARG | PARSE_OPT_NONEG, exclude_existing_callback },
 -      { OPTION_CALLBACK, 0, "help-all", NULL, NULL, "show usage",
 +      { OPTION_CALLBACK, 0, "help-all", NULL, NULL, N_("show usage"),
          PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback },
        OPT_END()
  };