Merge fixes up to GIT 1.1.2
authorJunio C Hamano <junkio@cox.net>
Sat, 14 Jan 2006 00:51:21 +0000 (16:51 -0800)
committerJunio C Hamano <junkio@cox.net>
Sat, 14 Jan 2006 00:51:21 +0000 (16:51 -0800)
1  2 
describe.c
show-branch.c
diff --combined describe.c
index 1e764026b1554e03eacb0915efbf9b475a6e9c84,5548a16e4d97690e207a6e7cd0699aa8de73f81f..fabadb827fb5d7852028e5d8e437e315215f90b1
@@@ -98,20 -98,12 +98,20 @@@ static int compare_names(const void *_a
        return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
  }
  
 -static void describe(struct commit *cmit)
 +static void describe(char *arg)
  {
 +      unsigned char sha1[20];
 +      struct commit *cmit;
        struct commit_list *list;
        static int initialized = 0;
        struct commit_name *n;
  
 +      if (get_sha1(arg, sha1) < 0)
 +              usage(describe_usage);
 +      cmit = lookup_commit_reference(sha1);
 +      if (!cmit)
 +              usage(describe_usage);
 +
        if (!initialized) {
                initialized = 1;
                for_each_ref(get_name);
                if (n) {
                        printf("%s-g%s\n", n->path,
                               find_unique_abbrev(cmit->object.sha1, abbrev));
-                       break;
+                       clear_commit_marks(cmit, SEEN);
+                       return;
                }
        }
-       clear_commit_marks(cmit, SEEN);
+       die("cannot describe '%s'", sha1_to_hex(cmit->object.sha1));
  }
  
  int main(int argc, char **argv)
  
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
 -              unsigned char sha1[20];
 -              struct commit *cmit;
  
 -              if (!strcmp(arg, "--all")) {
 +              if (*arg != '-')
 +                      break;
 +              else if (!strcmp(arg, "--all"))
                        all = 1;
 -                      continue;
 -              }
 -              if (!strcmp(arg, "--tags")) {
 +              else if (!strcmp(arg, "--tags"))
                        tags = 1;
 -                      continue;
 -              }
 -              if (!strncmp(arg, "--abbrev=", 9)) {
 +              else if (!strncmp(arg, "--abbrev=", 9)) {
                        abbrev = strtoul(arg + 9, NULL, 10);
                        if (abbrev < 4 || 40 <= abbrev)
                                abbrev = DEFAULT_ABBREV;
 -                      continue;
                }
 -              if (get_sha1(arg, sha1) < 0)
 -                      usage(describe_usage);
 -              cmit = lookup_commit_reference(sha1);
 -              if (!cmit)
 +              else
                        usage(describe_usage);
 -              describe(cmit);
        }
 +
 +      if (i == argc)
 +              describe("HEAD");
 +      else
 +              while (i < argc)
 +                      describe(argv[i++]);
 +
        return 0;
  }
diff --combined show-branch.c
index f43c4064699fb86e31dba2737d232e70330944d0,1935c448f4c50e8b9b4302162747a6a099dc718c..f1bce499baeb780fbea77e84b6bc14633c178180
@@@ -7,10 -7,6 +7,10 @@@
  static const char show_branch_usage[] =
  "git-show-branch [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [<refs>...]";
  
 +static int default_num = 0;
 +static int default_alloc = 0;
 +static char **default_arg = NULL;
 +
  #define UNINTERESTING 01
  
  #define REV_SHIFT      2
@@@ -496,7 -492,7 +496,7 @@@ static void append_one_rev(const char *
                append_ref(av, revkey);
                return;
        }
-       if (strchr(av, '*') || strchr(av, '?')) {
+       if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
                /* glob style match */
                int saved_matches = ref_name_cnt;
                match_ref_pattern = av;
        die("bad sha1 reference %s", av);
  }
  
 +static int git_show_branch_config(const char *var, const char *value)
 +{
 +      if (!strcmp(var, "showbranch.default")) {
 +              if (default_alloc <= default_num + 1) {
 +                      default_alloc = default_alloc * 3 / 2 + 20;
 +                      default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
 +              }
 +              default_arg[default_num++] = strdup(value);
 +              default_arg[default_num] = NULL;
 +              return 0;
 +      }
 +
 +      return git_default_config(var, value);
 +}
 +
  int main(int ac, char **av)
  {
        struct commit *rev[MAX_REVS], *commit;
        int shown_merge_point = 0;
        int topo_order = 0;
  
 +      git_config(git_show_branch_config);
        setup_git_directory();
  
 +      /* If nothing is specified, try the default first */
 +      if (ac == 1 && default_num) {
 +              ac = default_num + 1;
 +              av = default_arg - 1; /* ick; we would not address av[0] */
 +      }
 +
        while (1 < ac && av[1][0] == '-') {
                char *arg = av[1];
 -              if (!strcmp(arg, "--all"))
 +              if (!strcmp(arg, "--")) {
 +                      ac--; av++;
 +                      break;
 +              }
 +              else if (!strcmp(arg, "--all"))
                        all_heads = all_tags = 1;
                else if (!strcmp(arg, "--heads"))
                        all_heads = 1;