Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Wed, 17 Feb 2010 06:40:45 +0000 (22:40 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Feb 2010 06:40:45 +0000 (22:40 -0800)
* maint:
Prepare 1.7.0.1 release notes
Fix use of mutex in threaded grep
dwim_ref: fix dangling symref warning
stash pop: remove 'apply' options during 'drop' invocation
diff: make sure --output=/bad/path is caught
Remove hyphen from "git-command" in two error messages

1  2 
builtin-grep.c
git.c
diff --combined builtin-grep.c
index 46ffc1d1d917dd9388ae76899630b717811205a6,362122c4325a0419a038fda52768d78d3e12dc31..552ef1face1e25c11d5f114c8d5c1265c6c3ae9b
@@@ -14,7 -14,6 +14,7 @@@
  #include "userdiff.h"
  #include "grep.h"
  #include "quote.h"
 +#include "dir.h"
  
  #ifndef NO_PTHREADS
  #include "thread-utils.h"
@@@ -409,15 -408,25 +409,25 @@@ static int pathspec_matches(const char 
        return 0;
  }
  
+ static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
+ {
+       void *data;
+       if (use_threads) {
+               read_sha1_lock();
+               data = read_sha1_file(sha1, type, size);
+               read_sha1_unlock();
+       } else {
+               data = read_sha1_file(sha1, type, size);
+       }
+       return data;
+ }
  static void *load_sha1(const unsigned char *sha1, unsigned long *size,
                       const char *name)
  {
        enum object_type type;
-       char *data;
-       read_sha1_lock();
-       data = read_sha1_file(sha1, &type, size);
-       read_sha1_unlock();
+       void *data = lock_and_read_sha1_file(sha1, &type, size);
  
        if (!data)
                error("'%s': unable to read %s", name, sha1_to_hex(sha1));
@@@ -606,10 -615,7 +616,7 @@@ static int grep_tree(struct grep_opt *o
                        void *data;
                        unsigned long size;
  
-                       read_sha1_lock();
-                       data = read_sha1_file(entry.sha1, &type, &size);
-                       read_sha1_unlock();
+                       data = lock_and_read_sha1_file(entry.sha1, &type, &size);
                        if (!data)
                                die("unable to read tree (%s)",
                                    sha1_to_hex(entry.sha1));
@@@ -646,24 -652,6 +653,24 @@@ static int grep_object(struct grep_opt 
        die("unable to grep from object of type %s", typename(obj->type));
  }
  
 +static int grep_directory(struct grep_opt *opt, const char **paths)
 +{
 +      struct dir_struct dir;
 +      int i, hit = 0;
 +
 +      memset(&dir, 0, sizeof(dir));
 +      setup_standard_excludes(&dir);
 +
 +      fill_directory(&dir, paths);
 +      for (i = 0; i < dir.nr; i++) {
 +              hit |= grep_file(opt, dir.entries[i]->name);
 +              if (hit && opt->status_only)
 +                      break;
 +      }
 +      free_grep_patterns(opt);
 +      return hit;
 +}
 +
  static int context_callback(const struct option *opt, const char *arg,
                            int unset)
  {
@@@ -758,12 -746,9 +765,12 @@@ int cmd_grep(int argc, const char **arg
        const char **paths = NULL;
        int i;
        int dummy;
 +      int nongit = 0, use_index = 1;
        struct option options[] = {
                OPT_BOOLEAN(0, "cached", &cached,
                        "search in index instead of in the work tree"),
 +              OPT_BOOLEAN(0, "index", &use_index,
 +                      "--no-index finds in contents not managed by git"),
                OPT_GROUP(""),
                OPT_BOOLEAN('v', "invert-match", &opt.invert,
                        "show non-matching lines"),
                OPT_END()
        };
  
 +      prefix = setup_git_directory_gently(&nongit);
 +
        /*
         * 'git grep -h', unlike 'git grep -h <pattern>', is a request
         * to show usage information and exit.
                             PARSE_OPT_STOP_AT_NON_OPTION |
                             PARSE_OPT_NO_INTERNAL_HELP);
  
 +      if (use_index && nongit)
 +              /* die the same way as if we did it at the beginning */
 +              setup_git_directory();
 +
 +      /*
 +       * skip a -- separator; we know it cannot be
 +       * separating revisions from pathnames if
 +       * we haven't even had any patterns yet
 +       */
 +      if (argc > 0 && !opt.pattern_list && !strcmp(argv[0], "--")) {
 +              argv++;
 +              argc--;
 +      }
 +
        /* First unrecognized non-option token */
        if (argc > 0 && !opt.pattern_list) {
                append_grep_pattern(&opt, argv[0], "command line", 0,
                paths[1] = NULL;
        }
  
 +      if (!use_index) {
 +              int hit;
 +              if (cached)
 +                      die("--cached cannot be used with --no-index.");
 +              if (list.nr)
 +                      die("--no-index cannot be used with revs.");
 +              hit = grep_directory(&opt, paths);
 +              if (use_threads)
 +                      hit |= wait_all();
 +              return !hit;
 +      }
 +
        if (!list.nr) {
                int hit;
                if (!cached)
diff --combined git.c
index b3e23f10441924de45ab768e086ead90b214d4c7,c445d7bcc256c68fe53df4886bd7b7af81640056..90c6daf153493f70a35c99212a3cf0461f7fb03e
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -317,7 -317,7 +317,7 @@@ static void handle_internal_command(in
                { "fsck-objects", cmd_fsck, RUN_SETUP },
                { "gc", cmd_gc, RUN_SETUP },
                { "get-tar-commit-id", cmd_get_tar_commit_id },
 -              { "grep", cmd_grep, RUN_SETUP | USE_PAGER },
 +              { "grep", cmd_grep, USE_PAGER },
                { "hash-object", cmd_hash_object },
                { "help", cmd_help },
                { "index-pack", cmd_index_pack },
@@@ -527,7 -527,7 +527,7 @@@ int main(int argc, const char **argv
                        break;
                if (was_alias) {
                        fprintf(stderr, "Expansion of alias '%s' failed; "
-                               "'%s' is not a git-command\n",
+                               "'%s' is not a git command\n",
                                cmd, argv[0]);
                        exit(1);
                }