]> git.ipfire.org Git - thirdparty/git.git/blobdiff - refs.c
Documentation: option to render literal text as bold for manpages
[thirdparty/git.git] / refs.c
diff --git a/refs.c b/refs.c
index 6eb5f5384611bb5d159d892a1bfd120d72e54b9b..26b001453bd1566f2ab3554fffeb63ec0437ceaa 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -694,6 +694,7 @@ static inline int bad_ref_char(int ch)
 int check_ref_format(const char *ref)
 {
        int ch, level, bad_type;
+       int ret = CHECK_REF_FORMAT_OK;
        const char *cp = ref;
 
        level = 0;
@@ -709,18 +710,18 @@ int check_ref_format(const char *ref)
                        return CHECK_REF_FORMAT_ERROR;
                bad_type = bad_ref_char(ch);
                if (bad_type) {
-                       return (bad_type == 2 && !*cp)
-                               ? CHECK_REF_FORMAT_WILDCARD
-                               : CHECK_REF_FORMAT_ERROR;
+                       if (bad_type == 2 && (!*cp || *cp == '/') &&
+                           ret == CHECK_REF_FORMAT_OK)
+                               ret = CHECK_REF_FORMAT_WILDCARD;
+                       else
+                               return CHECK_REF_FORMAT_ERROR;
                }
 
                /* scan the rest of the path component */
                while ((ch = *cp++) != 0) {
                        bad_type = bad_ref_char(ch);
                        if (bad_type) {
-                               return (bad_type == 2 && !*cp)
-                                       ? CHECK_REF_FORMAT_WILDCARD
-                                       : CHECK_REF_FORMAT_ERROR;
+                               return CHECK_REF_FORMAT_ERROR;
                        }
                        if (ch == '/')
                                break;
@@ -731,11 +732,21 @@ int check_ref_format(const char *ref)
                if (!ch) {
                        if (level < 2)
                                return CHECK_REF_FORMAT_ONELEVEL;
-                       return CHECK_REF_FORMAT_OK;
+                       return ret;
                }
        }
 }
 
+const char *prettify_ref(const struct ref *ref)
+{
+       const char *name = ref->name;
+       return name + (
+               !prefixcmp(name, "refs/heads/") ? 11 :
+               !prefixcmp(name, "refs/tags/") ? 10 :
+               !prefixcmp(name, "refs/remotes/") ? 13 :
+               0);
+}
+
 const char *ref_rev_parse_rules[] = {
        "%.*s",
        "refs/%.*s",
@@ -995,7 +1006,7 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
 
        err = unlink(git_path("logs/%s", lock->ref_name));
        if (err && errno != ENOENT)
-               fprintf(stderr, "warning: unlink(%s) failed: %s",
+               warning("unlink(%s) failed: %s",
                        git_path("logs/%s", lock->ref_name), strerror(errno));
        invalidate_cached_refs();
        unlock_ref(lock);
@@ -1437,8 +1448,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
                                if (get_sha1_hex(rec + 41, sha1))
                                        die("Log %s is corrupt.", logfile);
                                if (hashcmp(logged_sha1, sha1)) {
-                                       fprintf(stderr,
-                                               "warning: Log %s has gap after %s.\n",
+                                       warning("Log %s has gap after %s.",
                                                logfile, show_date(date, tz, DATE_RFC2822));
                                }
                        }
@@ -1450,8 +1460,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
                                if (get_sha1_hex(rec + 41, logged_sha1))
                                        die("Log %s is corrupt.", logfile);
                                if (hashcmp(logged_sha1, sha1)) {
-                                       fprintf(stderr,
-                                               "warning: Log %s unexpectedly ended on %s.\n",
+                                       warning("Log %s unexpectedly ended on %s.",
                                                logfile, show_date(date, tz, DATE_RFC2822));
                                }
                        }
@@ -1628,10 +1637,10 @@ int update_ref(const char *action, const char *refname,
        return 0;
 }
 
-struct ref *find_ref_by_name(struct ref *list, const char *name)
+struct ref *find_ref_by_name(const struct ref *list, const char *name)
 {
        for ( ; list; list = list->next)
                if (!strcmp(list->name, name))
-                       return list;
+                       return (struct ref *)list;
        return NULL;
 }