Merge branch 'cb/add-pathspec'
authorJunio C Hamano <gitster@pobox.com>
Mon, 26 Jan 2009 01:13:11 +0000 (17:13 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Jan 2009 01:13:11 +0000 (17:13 -0800)
* cb/add-pathspec:
remove pathspec_match, use match_pathspec instead
clean up pathspec matching

1  2 
builtin-checkout.c
builtin-commit.c
cache.h
dir.c
diff --combined builtin-checkout.c
index 275176d15daeb6de6195e4beb2a887f1c3859942,84a28257b6d3e0aa0b8c4b80811c41ef44e454f2..6cdb320ae72b438031049892a9bb78e5bc523c73
@@@ -38,13 -38,23 +38,13 @@@ struct checkout_opts 
  static int post_checkout_hook(struct commit *old, struct commit *new,
                              int changed)
  {
 -      struct child_process proc;
 -      const char *name = git_path("hooks/post-checkout");
 -      const char *argv[5];
 +      return run_hook(NULL, "post-checkout",
 +                      sha1_to_hex(old ? old->object.sha1 : null_sha1),
 +                      sha1_to_hex(new ? new->object.sha1 : null_sha1),
 +                      changed ? "1" : "0", NULL);
 +      /* "new" can be NULL when checking out from the index before
 +         a commit exists. */
  
 -      if (access(name, X_OK) < 0)
 -              return 0;
 -
 -      memset(&proc, 0, sizeof(proc));
 -      argv[0] = name;
 -      argv[1] = xstrdup(sha1_to_hex(old ? old->object.sha1 : null_sha1));
 -      argv[2] = xstrdup(sha1_to_hex(new->object.sha1));
 -      argv[3] = changed ? "1" : "0";
 -      argv[4] = NULL;
 -      proc.argv = argv;
 -      proc.no_stdin = 1;
 -      proc.stdout_to_stderr = 1;
 -      return run_command(&proc);
  }
  
  static int update_some(const unsigned char *sha1, const char *base, int baselen,
@@@ -230,7 -240,7 +230,7 @@@ static int checkout_paths(struct tree *
  
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
-               pathspec_match(pathspec, ps_matched, ce->name, 0);
+               match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, ps_matched);
        }
  
        if (report_path_error(ps_matched, pathspec, 0))
        /* Any unmerged paths? */
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
-               if (pathspec_match(pathspec, NULL, ce->name, 0)) {
+               if (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {
                        if (!ce_stage(ce))
                                continue;
                        if (opts->force) {
        state.refresh_cache = 1;
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
-               if (pathspec_match(pathspec, NULL, ce->name, 0)) {
+               if (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {
                        if (!ce_stage(ce)) {
                                errs |= checkout_entry(ce, &state, NULL);
                                continue;
diff --combined builtin-commit.c
index 7aaa5304c7d573f2f7750d58888621b0e82f3712,3d1867ac17d9d802572cf5b00b12e2ff0f176ca1..d6a3a6203aee399218c89d31ff5cb28f16dc0cc6
@@@ -166,7 -166,7 +166,7 @@@ static int list_paths(struct string_lis
                struct cache_entry *ce = active_cache[i];
                if (ce->ce_flags & CE_UPDATE)
                        continue;
-               if (!pathspec_match(pattern, m, ce->name, 0))
+               if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
                        continue;
                string_list_insert(ce->name, list);
        }
@@@ -361,6 -361,40 +361,6 @@@ static int run_status(FILE *fp, const c
        return s.commitable;
  }
  
 -static int run_hook(const char *index_file, const char *name, ...)
 -{
 -      struct child_process hook;
 -      const char *argv[10], *env[2];
 -      char index[PATH_MAX];
 -      va_list args;
 -      int i;
 -
 -      va_start(args, name);
 -      argv[0] = git_path("hooks/%s", name);
 -      i = 0;
 -      do {
 -              if (++i >= ARRAY_SIZE(argv))
 -                      die ("run_hook(): too many arguments");
 -              argv[i] = va_arg(args, const char *);
 -      } while (argv[i]);
 -      va_end(args);
 -
 -      snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
 -      env[0] = index;
 -      env[1] = NULL;
 -
 -      if (access(argv[0], X_OK) < 0)
 -              return 0;
 -
 -      memset(&hook, 0, sizeof(hook));
 -      hook.argv = argv;
 -      hook.no_stdin = 1;
 -      hook.stdout_to_stderr = 1;
 -      hook.env = env;
 -
 -      return run_command(&hook);
 -}
 -
  static int is_a_merge(const unsigned char *sha1)
  {
        struct commit *commit = lookup_commit(sha1);
@@@ -590,6 -624,7 +590,6 @@@ static int prepare_to_commit(const cha
        if (!commitable && !in_merge && !allow_empty &&
            !(amend && is_a_merge(head_sha1))) {
                run_status(stdout, index_file, prefix, 0);
 -              unlink(commit_editmsg);
                return 0;
        }
  
@@@ -831,9 -866,6 +831,9 @@@ int cmd_status(int argc, const char **a
        if (wt_status_use_color == -1)
                wt_status_use_color = git_use_color_default;
  
 +      if (diff_use_color_default == -1)
 +              diff_use_color_default = git_use_color_default;
 +
        argc = parse_and_validate_options(argc, argv, builtin_status_usage, prefix);
  
        index_file = prepare_index(argc, argv, prefix);
@@@ -849,7 -881,7 +849,7 @@@ static void print_summary(const char *p
  {
        struct rev_info rev;
        struct commit *commit;
 -      static const char *format = "format:%h: \"%s\"";
 +      static const char *format = "format:%h] %s";
        unsigned char junk_sha1[20];
        const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
  
        rev.diffopt.break_opt = 0;
        diff_setup_done(&rev.diffopt);
  
 -      printf("[%s%s]: created ",
 +      printf("[%s%s ",
                !prefixcmp(head, "refs/heads/") ?
                        head + 11 :
                        !strcmp(head, "HEAD") ?
@@@ -913,9 -945,6 +913,9 @@@ int cmd_commit(int argc, const char **a
  
        git_config(git_commit_config, NULL);
  
 +      if (wt_status_use_color == -1)
 +              wt_status_use_color = git_use_color_default;
 +
        argc = parse_and_validate_options(argc, argv, builtin_commit_usage, prefix);
  
        index_file = prepare_index(argc, argv, prefix);
diff --combined cache.h
index 8d965b8c981d80a252dd69ca32d8e44fa545177a,c60259d492c87b5a48613e8346e1ac309c113f08..c96854a0d67a84bde5d139a3d6d7ba058a10181e
+++ b/cache.h
  #define deflateBound(c,s)  ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
  #endif
  
 +void git_inflate_init(z_streamp strm);
 +void git_inflate_end(z_streamp strm);
 +int git_inflate(z_streamp strm, int flush);
 +
  #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
  #define DTYPE(de)     ((de)->d_type)
  #else
@@@ -635,6 -631,9 +635,6 @@@ extern int write_sha1_file(void *buf, u
  extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
  extern int force_object_loose(const unsigned char *sha1, time_t mtime);
  
 -/* just like read_sha1_file(), but non fatal in presence of bad objects */
 -extern void *read_object(const unsigned char *sha1, enum object_type *type, unsigned long *size);
 -
  /* global flag to enable extra checks when accessing packed objects */
  extern int do_check_packed_object_crc;
  
@@@ -937,7 -936,6 +937,6 @@@ extern int ws_fix_copy(char *, const ch
  extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
  
  /* ls-files */
- int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen);
  int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset);
  void overlay_tree_on_cache(const char *tree_name, const char *prefix);
  
diff --combined dir.c
index d55a41a5abde946177e1123b075a13967d2f850f,c50ecc8d692a2cb3b29b256e1bcf9eeeadbc2a57..cfd1ea587d9cce825e238ca81ea99b752543dada
--- 1/dir.c
--- 2/dir.c
+++ b/dir.c
@@@ -75,7 -75,7 +75,7 @@@ static int match_one(const char *match
        for (;;) {
                unsigned char c1 = *match;
                unsigned char c2 = *name;
 -              if (isspecial(c1))
 +              if (c1 == '\0' || is_glob_special(c1))
                        break;
                if (c1 != c2)
                        return 0;
   * and a mark is left in seen[] array for pathspec element that
   * actually matched anything.
   */
- int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen)
+ int match_pathspec(const char **pathspec, const char *name, int namelen,
+               int prefix, char *seen)
  {
-       int retval;
-       const char *match;
+       int i, retval = 0;
+       if (!pathspec)
+               return 1;
  
        name += prefix;
        namelen -= prefix;
  
-       for (retval = 0; (match = *pathspec++) != NULL; seen++) {
+       for (i = 0; pathspec[i] != NULL; i++) {
                int how;
-               if (retval && *seen == MATCHED_EXACTLY)
+               const char *match = pathspec[i] + prefix;
+               if (seen && seen[i] == MATCHED_EXACTLY)
                        continue;
-               match += prefix;
                how = match_one(match, name, namelen);
                if (how) {
                        if (retval < how)
                                retval = how;
-                       if (*seen < how)
-                               *seen = how;
+                       if (seen && seen[i] < how)
+                               seen[i] = how;
                }
        }
        return retval;
@@@ -585,8 -588,10 +588,8 @@@ static int read_directory_recursive(str
                        int len, dtype;
                        int exclude;
  
 -                      if ((de->d_name[0] == '.') &&
 -                          (de->d_name[1] == 0 ||
 -                           !strcmp(de->d_name + 1, ".") ||
 -                           !strcmp(de->d_name + 1, "git")))
 +                      if (is_dot_or_dotdot(de->d_name) ||
 +                           !strcmp(de->d_name, ".git"))
                                continue;
                        len = strlen(de->d_name);
                        /* Ignore overly long pathnames! */
@@@ -678,7 -683,7 +681,7 @@@ static int simple_length(const char *ma
        for (;;) {
                unsigned char c = *match++;
                len++;
 -              if (isspecial(c))
 +              if (c == '\0' || is_glob_special(c))
                        return len;
        }
  }
@@@ -777,25 -782,6 +780,25 @@@ int is_inside_dir(const char *dir
        return get_relative_cwd(buffer, sizeof(buffer), dir) != NULL;
  }
  
 +int is_empty_dir(const char *path)
 +{
 +      DIR *dir = opendir(path);
 +      struct dirent *e;
 +      int ret = 1;
 +
 +      if (!dir)
 +              return 0;
 +
 +      while ((e = readdir(dir)) != NULL)
 +              if (!is_dot_or_dotdot(e->d_name)) {
 +                      ret = 0;
 +                      break;
 +              }
 +
 +      closedir(dir);
 +      return ret;
 +}
 +
  int remove_dir_recursively(struct strbuf *path, int only_empty)
  {
        DIR *dir = opendir(path->buf);
        len = path->len;
        while ((e = readdir(dir)) != NULL) {
                struct stat st;
 -              if ((e->d_name[0] == '.') &&
 -                  ((e->d_name[1] == 0) ||
 -                   ((e->d_name[1] == '.') && e->d_name[2] == 0)))
 -                      continue; /* "." and ".." */
 +              if (is_dot_or_dotdot(e->d_name))
 +                      continue;
  
                strbuf_setlen(path, len);
                strbuf_addstr(path, e->d_name);