Merge branch 'jc/sha1-name-find-fix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 13 Aug 2010 01:32:49 +0000 (18:32 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 13 Aug 2010 01:32:49 +0000 (18:32 -0700)
* jc/sha1-name-find-fix:
sha1_name.c: fix parsing of ":/token" syntax

Conflicts:
sha1_name.c

1  2 
sha1_name.c
diff --combined sha1_name.c
index 4f2af8da934b125f2c09ceb4d8185dabc58f7831,8a551025f0f4a1f02f60b1611d412ae0e125dbb7..4af94fa59806c570c177a68139b54d46772d68a5
@@@ -659,6 -659,16 +659,16 @@@ static int get_sha1_1(const char *name
        return get_short_sha1(name, len, sha1, 0);
  }
  
 - * with the given string.
+ /*
+  * This interprets names like ':/Initial revision of "git"' by searching
+  * through history and returning the first commit whose message starts
++ * the given regular expression.
+  *
+  * For future extension, ':/!' is reserved. If you want to match a message
+  * beginning with a '!', you have to repeat the exclamation mark.
+  */
+ #define ONELINE_SEEN (1u<<20)
  static int handle_one_ref(const char *path,
                const unsigned char *sha1, int flag, void *cb_data)
  {
        if (object->type != OBJ_COMMIT)
                return 0;
        insert_by_date((struct commit *)object, list);
+       object->flags |= ONELINE_SEEN;
        return 0;
  }
  
- /*
-  * This interprets names like ':/Initial revision of "git"' by searching
-  * through history and returning the first commit whose message matches
-  * the given regular expression.
-  *
-  * For future extension, ':/!' is reserved. If you want to match a message
-  * beginning with a '!', you have to repeat the exclamation mark.
-  */
- #define ONELINE_SEEN (1u<<20)
  static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
  {
        struct commit_list *list = NULL, *backup = NULL, *l;
        int retval = -1;
        char *temp_commit_buffer = NULL;
 +      regex_t regex;
  
        if (prefix[0] == '!') {
                if (prefix[1] != '!')
                        die ("Invalid search pattern: %s", prefix);
                prefix++;
        }
 +
 +      if (regcomp(&regex, prefix, REG_EXTENDED))
 +              die("Invalid search pattern: %s", prefix);
 +
        for_each_ref(handle_one_ref, &list);
        for (l = list; l; l = l->next)
                commit_list_insert(l->item, &backup);
                }
                if (!(p = strstr(p, "\n\n")))
                        continue;
 -              if (!prefixcmp(p + 2, prefix)) {
 +              if (!regexec(&regex, p + 2, 0, NULL, 0)) {
                        hashcpy(sha1, commit->object.sha1);
                        retval = 0;
                        break;
                }
        }
 +      regfree(&regex);
        free(temp_commit_buffer);
        free_commit_list(list);
        for (l = backup; l; l = l->next)
@@@ -939,8 -934,8 +940,8 @@@ int interpret_branch_name(const char *n
   */
  int get_sha1(const char *name, unsigned char *sha1)
  {
 -      unsigned unused;
 -      return get_sha1_with_mode(name, sha1, &unused);
 +      struct object_context unused;
 +      return get_sha1_with_context(name, sha1, &unused);
  }
  
  /* Must be called only when object_name:filename doesn't exist. */
@@@ -1037,24 -1032,12 +1038,24 @@@ static void diagnose_invalid_index_path
  
  
  int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode, int gently, const char *prefix)
 +{
 +      struct object_context oc;
 +      int ret;
 +      ret = get_sha1_with_context_1(name, sha1, &oc, gently, prefix);
 +      *mode = oc.mode;
 +      return ret;
 +}
 +
 +int get_sha1_with_context_1(const char *name, unsigned char *sha1,
 +                          struct object_context *oc,
 +                          int gently, const char *prefix)
  {
        int ret, bracket_depth;
        int namelen = strlen(name);
        const char *cp;
  
 -      *mode = S_IFINVALID;
 +      memset(oc, 0, sizeof(*oc));
 +      oc->mode = S_IFINVALID;
        ret = get_sha1_1(name, namelen, sha1);
        if (!ret)
                return ret;
                        cp = name + 3;
                }
                namelen = namelen - (cp - name);
 +
 +              strncpy(oc->path, cp,
 +                      sizeof(oc->path));
 +              oc->path[sizeof(oc->path)-1] = '\0';
 +
                if (!active_cache)
                        read_cache();
                pos = cache_name_pos(cp, namelen);
                                break;
                        if (ce_stage(ce) == stage) {
                                hashcpy(sha1, ce->sha1);
 -                              *mode = ce->ce_mode;
                                return 0;
                        }
                        pos++;
                }
                if (!get_sha1_1(name, cp-name, tree_sha1)) {
                        const char *filename = cp+1;
 -                      ret = get_tree_entry(tree_sha1, filename, sha1, mode);
 +                      ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
                        if (!gently) {
                                diagnose_invalid_sha1_path(prefix, filename,
                                                           tree_sha1, object_name);
                                free(object_name);
                        }
 +                      hashcpy(oc->tree, tree_sha1);
 +                      strncpy(oc->path, filename,
 +                              sizeof(oc->path));
 +                      oc->path[sizeof(oc->path)-1] = '\0';
 +
                        return ret;
                } else {
                        if (!gently)