Merge branch 'maint-1.8.5' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 2 Jul 2014 19:51:50 +0000 (12:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 Jul 2014 19:51:50 +0000 (12:51 -0700)
* maint-1.8.5:
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 9a9151575d3a8d4eb16d73e432835d3cda4374b8,ceab18257e8bd412c87a4b2ed5404d548ca72ea0..27701d222c78ed84691b65334a7909f90c589464
@@@ -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)
@@@ -154,7 -154,7 +154,7 @@@ static int remove_dirs(struct strbuf *p
        DIR *dir;
        struct strbuf quoted = STRBUF_INIT;
        struct dirent *e;
 -      int res = 0, ret = 0, gone = 1, original_len = path->len, len, i;
 +      int res = 0, ret = 0, gone = 1, original_len = path->len, len;
        unsigned char submodule_head[20];
        struct string_list dels = STRING_LIST_INIT_DUP;
  
        }
  
        if (!*dir_gone && !quiet) {
 +              int i;
                for (i = 0; i < dels.nr; i++)
                        printf(dry_run ?  _(msg_would_remove) : _(msg_remove), dels.items[i].string);
        }
@@@ -904,11 -903,11 +904,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 c9cf67ea7c85012ef7c57d0fe92cf62089afaf49,296cb5680ac6ba7a7c7670652e9287f56a1c1338..5c02b29cebd5b09b06d6032d9818f18ef35762b6
+++ 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);
  }
  
@@@ -555,13 -549,14 +555,13 @@@ static char *get_header(const struct co
        const char *line = msg;
  
        while (line) {
 -              const char *eol = strchr(line, '\n'), *next;
 +              const char *eol = strchrnul(line, '\n'), *next;
  
                if (line == eol)
                        return NULL;
 -              if (!eol) {
 +              if (!*eol) {
                        warning("malformed commit (header is missing newline): %s",
                                sha1_to_hex(commit->object.sha1));
 -                      eol = line + strlen(line);
                        next = NULL;
                } else
                        next = eol + 1;
@@@ -845,10 -840,10 +845,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;
                }
@@@ -988,7 -983,7 +988,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
@@@ -1065,11 -1060,11 +1065,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;
@@@ -1094,7 -1089,7 +1094,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 {
@@@ -1506,18 -1501,13 +1506,18 @@@ void format_commit_message(const struc
        context.commit = commit;
        context.pretty_ctx = pretty_ctx;
        context.wrap_start = sb->len;
 +      /*
 +       * convert a commit message to UTF-8 first
 +       * as far as 'format_commit_item' assumes it in UTF-8
 +       */
        context.message = logmsg_reencode(commit,
                                          &context.commit_encoding,
 -                                        output_enc);
 +                                        utf8);
  
        strbuf_expand(sb, format, format_commit_item, &context);
        rewrap_message_tail(sb, &context, 0, 0, 0);
  
 +      /* then convert a commit message to an actual output encoding */
        if (output_enc) {
                if (same_encoding(utf8, output_enc))
                        output_enc = NULL;
@@@ -1566,7 -1556,7 +1566,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