Merge branch 'jk/grep-double-dash' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 17 Feb 2010 22:55:15 +0000 (14:55 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Feb 2010 22:55:15 +0000 (14:55 -0800)
* jk/grep-double-dash:
accept "git grep -- pattern"

1  2 
builtin-grep.c
diff --combined builtin-grep.c
index 362122c4325a0419a038fda52768d78d3e12dc31,63d4b95b0d8d1d0f3a3cc8acc50bab9cdf67deaa..26979577d3f753cdc8b3358954249708d4cb53ef
@@@ -408,25 -408,15 +408,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));
@@@ -615,7 -605,10 +615,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));
@@@ -868,6 -861,16 +868,16 @@@ int cmd_grep(int argc, const char **arg
                             PARSE_OPT_STOP_AT_NON_OPTION |
                             PARSE_OPT_NO_INTERNAL_HELP);
  
+       /*
+        * 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,