Merge branch 'mh/check-ref-format-print-normalize'
authorJunio C Hamano <gitster@pobox.com>
Tue, 6 Sep 2011 18:42:52 +0000 (11:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Sep 2011 18:42:52 +0000 (11:42 -0700)
* mh/check-ref-format-print-normalize:
Forbid DEL characters in reference names
check-ref-format --print: Normalize refnames that start with slashes

1  2 
refs.c
diff --combined refs.c
index e5b2b1ac2bf535e931165ff1cb4691163c1843a2,6f471d42c37ab4e66f402d1c983d3d42e4ebb2d8..a615043b34cd6d0507d8a30f7bd69445ec9f2456
--- 1/refs.c
--- 2/refs.c
+++ b/refs.c
@@@ -451,7 -451,7 +451,7 @@@ int resolve_gitlink_ref(const char *pat
        memcpy(gitdir + len, "/.git", 6);
        len += 5;
  
 -      tmp = read_gitfile_gently(gitdir);
 +      tmp = read_gitfile(gitdir);
        if (tmp) {
                free(gitdir);
                len = strlen(tmp);
@@@ -584,7 -584,7 +584,7 @@@ int read_ref(const char *ref, unsigned 
  static int do_one_ref(const char *base, each_ref_fn fn, int trim,
                      int flags, void *cb_data, struct ref_list *entry)
  {
 -      if (strncmp(base, entry->name, trim))
 +      if (prefixcmp(entry->name, base))
                return 0;
  
        if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {
@@@ -728,12 -728,12 +728,12 @@@ int head_ref_submodule(const char *subm
  
  int for_each_ref(each_ref_fn fn, void *cb_data)
  {
 -      return do_for_each_ref(NULL, "refs/", fn, 0, 0, cb_data);
 +      return do_for_each_ref(NULL, "", fn, 0, 0, cb_data);
  }
  
  int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
  {
 -      return do_for_each_ref(submodule, "refs/", fn, 0, 0, cb_data);
 +      return do_for_each_ref(submodule, "", fn, 0, 0, cb_data);
  }
  
  int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
@@@ -782,31 -782,6 +782,31 @@@ int for_each_replace_ref(each_ref_fn fn
        return do_for_each_ref(NULL, "refs/replace/", fn, 13, 0, cb_data);
  }
  
 +int head_ref_namespaced(each_ref_fn fn, void *cb_data)
 +{
 +      struct strbuf buf = STRBUF_INIT;
 +      int ret = 0;
 +      unsigned char sha1[20];
 +      int flag;
 +
 +      strbuf_addf(&buf, "%sHEAD", get_git_namespace());
 +      if (resolve_ref(buf.buf, sha1, 1, &flag))
 +              ret = fn(buf.buf, sha1, flag, cb_data);
 +      strbuf_release(&buf);
 +
 +      return ret;
 +}
 +
 +int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
 +{
 +      struct strbuf buf = STRBUF_INIT;
 +      int ret;
 +      strbuf_addf(&buf, "%srefs/", get_git_namespace());
 +      ret = do_for_each_ref(NULL, buf.buf, fn, 0, 0, cb_data);
 +      strbuf_release(&buf);
 +      return ret;
 +}
 +
  int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
        const char *prefix, void *cb_data)
  {
@@@ -844,7 -819,7 +844,7 @@@ int for_each_glob_ref(each_ref_fn fn, c
  
  int for_each_rawref(each_ref_fn fn, void *cb_data)
  {
 -      return do_for_each_ref(NULL, "refs/", fn, 0,
 +      return do_for_each_ref(NULL, "", fn, 0,
                               DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
  }
  
  
  static inline int bad_ref_char(int ch)
  {
-       if (((unsigned) ch) <= ' ' ||
+       if (((unsigned) ch) <= ' ' || ch == 0x7f ||
            ch == '~' || ch == '^' || ch == ':' || ch == '\\')
                return 1;
        /* 2.13 Pattern Matching Notation */
@@@ -1476,7 -1451,7 +1476,7 @@@ int write_ref_sha1(struct ref_lock *loc
        }
        o = parse_object(sha1);
        if (!o) {
 -              error("Trying to write ref %s with nonexistant object %s",
 +              error("Trying to write ref %s with nonexistent object %s",
                        lock->ref_name, sha1_to_hex(sha1));
                unlock_ref(lock);
                return -1;
@@@ -1851,12 -1826,6 +1851,12 @@@ int update_ref(const char *action, cons
        return 0;
  }
  
 +int ref_exists(char *refname)
 +{
 +      unsigned char sha1[20];
 +      return !!resolve_ref(refname, sha1, 1, NULL);
 +}
 +
  struct ref *find_ref_by_name(const struct ref *list, const char *name)
  {
        for ( ; list; list = list->next)