@matheusbsbs / matheus-bagliano / commits / a9c37a72c4
Fork 0

Use a common function to get the pretty name of refs

The result should be consistent between fetch and push, so we ought to use the same code in both cases, even though it's short. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Daniel Barkalow committed Mar 8, 2009 at 21:06 UTC a9c37a72c4fbc8537de294d66b05bdfd7f9a4016
4 files changed +13 -15
builtin-fetch.c
+1 -5
@@ -197,11 +197,7 @@ static int update_local_ref(struct ref *ref,
197 struct commit *current = NULL, *updated;
198 enum object_type type;
199 struct branch *current_branch = branch_get(NULL);
200 - const char *pretty_ref = ref->name + (
201 - !prefixcmp(ref->name, "refs/heads/") ? 11 :
202 - !prefixcmp(ref->name, "refs/tags/") ? 10 :
203 - !prefixcmp(ref->name, "refs/remotes/") ? 13 :
204 - 0);
200 + const char *pretty_ref = prettify_ref(ref);
201
202 *display = 0;
203 type = sha1_object_info(ref->new_sha1, NULL);
builtin-send-pack.c
-10
@@ -172,16 +172,6 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref)
172 }
173 }
174
175 -static const char *prettify_ref(const struct ref *ref)
176 -{
177 - const char *name = ref->name;
178 - return name + (
179 - !prefixcmp(name, "refs/heads/") ? 11 :
180 - !prefixcmp(name, "refs/tags/") ? 10 :
181 - !prefixcmp(name, "refs/remotes/") ? 13 :
182 - 0);
183 -}
184 -
175 #define SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
176
177 static void print_ref_status(char flag, const char *summary, struct ref *to, struct ref *from, const char *msg)
refs.c
+10
@@ -736,6 +736,16 @@ int check_ref_format(const char *ref)
736 }
737 }
738
739 +const char *prettify_ref(const struct ref *ref)
740 +{
741 + const char *name = ref->name;
742 + return name + (
743 + !prefixcmp(name, "refs/heads/") ? 11 :
744 + !prefixcmp(name, "refs/tags/") ? 10 :
745 + !prefixcmp(name, "refs/remotes/") ? 13 :
746 + 0);
747 +}
748 +
749 const char *ref_rev_parse_rules[] = {
750 "%.*s",
751 "refs/%.*s",
refs.h
+2
@@ -79,6 +79,8 @@ extern int for_each_reflog(each_ref_fn, void *);
79 #define CHECK_REF_FORMAT_WILDCARD (-3)
80 extern int check_ref_format(const char *target);
81
82 +extern const char *prettify_ref(const struct ref *ref);
83 +
84 /** rename ref, return 0 on success **/
85 extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);
86