Merge branch 'maint-1.8.5' into maint-1.9
authorJunio C Hamano <gitster@pobox.com>
Wed, 16 Jul 2014 18:10:30 +0000 (11:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Jul 2014 18:10:30 +0000 (11:10 -0700)
* maint-1.8.5:
annotate: use argv_array
t7300: repair filesystem permissions with test_when_finished
enums: remove trailing ',' after last item in enum

1  2 
builtin/clean.c
pretty.c
t/t7300-clean.sh
diff --combined builtin/clean.c
index 977a068f110a5ecfaeb3b680325f11a86be52251,ceab18257e8bd412c87a4b2ed5404d548ca72ea0..8926ca851c697d7a867dd4e5572f88656d7bbc4c
@@@ -48,7 -48,7 +48,7 @@@ enum color_clean 
        CLEAN_COLOR_PROMPT = 2,
        CLEAN_COLOR_HEADER = 3,
        CLEAN_COLOR_HELP = 4,
-       CLEAN_COLOR_ERROR = 5,
+       CLEAN_COLOR_ERROR = 5
  };
  
  #define MENU_OPTS_SINGLETON           01
@@@ -100,7 -100,7 +100,7 @@@ static int parse_clean_color_slot(cons
  
  static int git_clean_config(const char *var, const char *value, void *cb)
  {
 -      if (!prefixcmp(var, "column."))
 +      if (starts_with(var, "column."))
                return git_column_config(var, value, "clean", &colopts);
  
        /* honors the color.interactive* config variables which also
                clean_use_color = git_config_colorbool(var, value);
                return 0;
        }
 -      if (!prefixcmp(var, "color.interactive.")) {
 +      if (starts_with(var, "color.interactive.")) {
                int slot = parse_clean_color_slot(var +
                                                  strlen("color.interactive."));
                if (slot < 0)
@@@ -903,11 -903,11 +903,11 @@@ int cmd_clean(int argc, const char **ar
  
        if (!interactive && !dry_run && !force) {
                if (config_set)
 -                      die(_("clean.requireForce set to true and neither -i, -n nor -f given; "
 +                      die(_("clean.requireForce set to true and neither -i, -n, nor -f given; "
                                  "refusing to clean"));
                else
 -                      die(_("clean.requireForce defaults to true and neither -i, -n nor -f given; "
 -                                "refusing to clean"));
 +                      die(_("clean.requireForce defaults to true and neither -i, -n, nor -f given;"
 +                                " refusing to clean"));
        }
  
        if (force > 1)
  
        for (i = 0; i < dir.nr; i++) {
                struct dir_entry *ent = dir.entries[i];
 -              int len, pos;
                int matches = 0;
 -              const struct cache_entry *ce;
                struct stat st;
                const char *rel;
  
 -              /*
 -               * Remove the '/' at the end that directory
 -               * walking adds for directory entries.
 -               */
 -              len = ent->len;
 -              if (len && ent->name[len-1] == '/')
 -                      len--;
 -              pos = cache_name_pos(ent->name, len);
 -              if (0 <= pos)
 -                      continue;       /* exact match */
 -              pos = -pos - 1;
 -              if (pos < active_nr) {
 -                      ce = active_cache[pos];
 -                      if (ce_namelen(ce) == len &&
 -                          !memcmp(ce->name, ent->name, len))
 -                              continue; /* Yup, this one exists unmerged */
 -              }
 +              if (!cache_name_is_other(ent->name, ent->len))
 +                      continue;
  
                if (lstat(ent->name, &st))
                        die_errno("Cannot lstat '%s'", ent->name);
  
                if (pathspec.nr)
 -                      matches = match_pathspec_depth(&pathspec, ent->name,
 -                                                     len, 0, NULL);
 +                      matches = dir_path_match(ent, &pathspec, 0, NULL);
  
 -              if (S_ISDIR(st.st_mode)) {
 -                      if (remove_directories || (matches == MATCHED_EXACTLY)) {
 -                              rel = relative_path(ent->name, prefix, &buf);
 -                              string_list_append(&del_list, rel);
 -                      }
 -              } else {
 -                      if (pathspec.nr && !matches)
 -                              continue;
 -                      rel = relative_path(ent->name, prefix, &buf);
 -                      string_list_append(&del_list, rel);
 -              }
 +              if (pathspec.nr && !matches)
 +                      continue;
 +
 +              if (S_ISDIR(st.st_mode) && !remove_directories &&
 +                  matches != MATCHED_EXACTLY)
 +                      continue;
 +
 +              rel = relative_path(ent->name, prefix, &buf);
 +              string_list_append(&del_list, rel);
        }
  
        if (interactive && del_list.nr > 0)
diff --combined pretty.c
index 6e266ddf2749ab1b2388f72e3a1101e98fa656cc,296cb5680ac6ba7a7c7670652e9287f56a1c1338..f64ff9a10c212df35ef2b31803a7bec78ff156ba
+++ b/pretty.c
@@@ -40,7 -40,7 +40,7 @@@ static int git_pretty_formats_config(co
        const char *fmt;
        int i;
  
 -      if (prefixcmp(var, "pretty."))
 +      if (!starts_with(var, "pretty."))
                return 0;
  
        name = var + strlen("pretty.");
@@@ -67,7 -67,7 +67,7 @@@
        commit_format->name = xstrdup(name);
        commit_format->format = CMIT_FMT_USERFORMAT;
        git_config_string(&fmt, var, value);
 -      if (!prefixcmp(fmt, "format:") || !prefixcmp(fmt, "tformat:")) {
 +      if (starts_with(fmt, "format:") || starts_with(fmt, "tformat:")) {
                commit_format->is_tformat = fmt[0] == 't';
                fmt = strchr(fmt, ':') + 1;
        } else if (strchr(fmt, '%'))
@@@ -115,7 -115,7 +115,7 @@@ static struct cmt_fmt_map *find_commit_
        for (i = 0; i < commit_formats_len; i++) {
                size_t match_len;
  
 -              if (prefixcmp(commit_formats[i].name, sought))
 +              if (!starts_with(commit_formats[i].name, sought))
                        continue;
  
                match_len = strlen(commit_formats[i].name);
@@@ -151,7 -151,7 +151,7 @@@ void get_commit_format(const char *arg
                rev->commit_format = CMIT_FMT_DEFAULT;
                return;
        }
 -      if (!prefixcmp(arg, "format:") || !prefixcmp(arg, "tformat:")) {
 +      if (starts_with(arg, "format:") || starts_with(arg, "tformat:")) {
                save_user_format(rev, strchr(arg, ':') + 1, arg[0] == 't');
                return;
        }
@@@ -274,7 -274,7 +274,7 @@@ static void add_rfc822_quoted(struct st
  
  enum rfc2047_type {
        RFC2047_SUBJECT,
-       RFC2047_ADDRESS,
+       RFC2047_ADDRESS
  };
  
  static int is_rfc2047_special(char ch, enum rfc2047_type type)
@@@ -397,18 -397,12 +397,18 @@@ static const char *show_ident_date(cons
                                   enum date_mode mode)
  {
        unsigned long date = 0;
 -      int tz = 0;
 +      long tz = 0;
  
        if (ident->date_begin && ident->date_end)
                date = strtoul(ident->date_begin, NULL, 10);
 -      if (ident->tz_begin && ident->tz_end)
 -              tz = strtol(ident->tz_begin, NULL, 10);
 +      if (date_overflows(date))
 +              date = 0;
 +      else {
 +              if (ident->tz_begin && ident->tz_end)
 +                      tz = strtol(ident->tz_begin, NULL, 10);
 +              if (tz >= INT_MAX || tz <= INT_MIN)
 +                      tz = 0;
 +      }
        return show_date(date, tz, mode);
  }
  
@@@ -846,10 -840,10 +846,10 @@@ static void parse_commit_header(struct 
  
                if (i == eol) {
                        break;
 -              } else if (!prefixcmp(msg + i, "author ")) {
 +              } else if (starts_with(msg + i, "author ")) {
                        context->author.off = i + 7;
                        context->author.len = eol - i - 7;
 -              } else if (!prefixcmp(msg + i, "committer ")) {
 +              } else if (starts_with(msg + i, "committer ")) {
                        context->committer.off = i + 10;
                        context->committer.len = eol - i - 10;
                }
@@@ -989,7 -983,7 +989,7 @@@ static size_t parse_color(struct strbu
  
                if (!end)
                        return 0;
 -              if (!prefixcmp(begin, "auto,")) {
 +              if (starts_with(begin, "auto,")) {
                        if (!want_color(c->pretty_ctx->color))
                                return end - placeholder + 1;
                        begin += 5;
                strbuf_addstr(sb, color);
                return end - placeholder + 1;
        }
 -      if (!prefixcmp(placeholder + 1, "red")) {
 +      if (starts_with(placeholder + 1, "red")) {
                strbuf_addstr(sb, GIT_COLOR_RED);
                return 4;
 -      } else if (!prefixcmp(placeholder + 1, "green")) {
 +      } else if (starts_with(placeholder + 1, "green")) {
                strbuf_addstr(sb, GIT_COLOR_GREEN);
                return 6;
 -      } else if (!prefixcmp(placeholder + 1, "blue")) {
 +      } else if (starts_with(placeholder + 1, "blue")) {
                strbuf_addstr(sb, GIT_COLOR_BLUE);
                return 5;
 -      } else if (!prefixcmp(placeholder + 1, "reset")) {
 +      } else if (starts_with(placeholder + 1, "reset")) {
                strbuf_addstr(sb, GIT_COLOR_RESET);
                return 6;
        } else
@@@ -1066,11 -1060,11 +1066,11 @@@ static size_t parse_padding_placeholder
                        end = strchr(start, ')');
                        if (!end || end == start)
                                return 0;
 -                      if (!prefixcmp(start, "trunc)"))
 +                      if (starts_with(start, "trunc)"))
                                c->truncate = trunc_right;
 -                      else if (!prefixcmp(start, "ltrunc)"))
 +                      else if (starts_with(start, "ltrunc)"))
                                c->truncate = trunc_left;
 -                      else if (!prefixcmp(start, "mtrunc)"))
 +                      else if (starts_with(start, "mtrunc)"))
                                c->truncate = trunc_middle;
                        else
                                return 0;
@@@ -1095,7 -1089,7 +1095,7 @@@ static size_t format_commit_one(struct 
        /* these are independent of the commit */
        switch (placeholder[0]) {
        case 'C':
 -              if (!prefixcmp(placeholder + 1, "(auto)")) {
 +              if (starts_with(placeholder + 1, "(auto)")) {
                        c->auto_color = 1;
                        return 7; /* consumed 7 bytes, "C(auto)" */
                } else {
@@@ -1562,7 -1556,7 +1562,7 @@@ static void pp_header(struct pretty_pri
                        continue;
                }
  
 -              if (!prefixcmp(line, "parent ")) {
 +              if (starts_with(line, "parent ")) {
                        if (linelen != 48)
                                die("bad parent line in commit");
                        continue;
                 * FULL shows both authors but not dates.
                 * FULLER shows both authors and dates.
                 */
 -              if (!prefixcmp(line, "author ")) {
 +              if (starts_with(line, "author ")) {
                        strbuf_grow(sb, linelen + 80);
                        pp_user_info(pp, "Author", sb, line + 7, encoding);
                }
 -              if (!prefixcmp(line, "committer ") &&
 +              if (starts_with(line, "committer ") &&
                    (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
                        strbuf_grow(sb, linelen + 80);
                        pp_user_info(pp, "Commit", sb, line + 10, encoding);
diff --combined t/t7300-clean.sh
index 74de814aec1465848ba316e867106a18635139f6,8dbe950bb09bad34b46496508b2afd0242a8d2aa..04118ad75be8462fa2ee1e5e870feb0a44ac0482
@@@ -426,10 -426,10 +426,10 @@@ test_expect_success SANITY 'removal fai
  
        mkdir foo &&
        touch foo/bar &&
+       test_when_finished "chmod 755 foo" &&
        (exec <foo/bar &&
         chmod 0 foo &&
-        test_must_fail git clean -f -d &&
-        chmod 755 foo)
+        test_must_fail git clean -f -d)
  '
  
  test_expect_success 'nested git work tree' '
@@@ -511,20 -511,4 +511,20 @@@ test_expect_success SANITY 'git clean -
        ! test -d foo
  '
  
 +test_expect_success 'git clean -d respects pathspecs (dir is prefix of pathspec)' '
 +      mkdir -p foo &&
 +      mkdir -p foobar &&
 +      git clean -df foobar &&
 +      test_path_is_dir foo &&
 +      test_path_is_missing foobar
 +'
 +
 +test_expect_success 'git clean -d respects pathspecs (pathspec is prefix of dir)' '
 +      mkdir -p foo &&
 +      mkdir -p foobar &&
 +      git clean -df foo &&
 +      test_path_is_missing foo &&
 +      test_path_is_dir foobar
 +'
 +
  test_done