Skip to content

Commit a9c37a7

Browse files
iabervongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8321c56 commit a9c37a7

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

builtin-fetch.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,7 @@ static int update_local_ref(struct ref *ref,
197197
struct commit *current = NULL, *updated;
198198
enum object_type type;
199199
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);
205201

206202
*display = 0;
207203
type = sha1_object_info(ref->new_sha1, NULL);

builtin-send-pack.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,6 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref)
172172
}
173173
}
174174

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-
185175
#define SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
186176

187177
static void print_ref_status(char flag, const char *summary, struct ref *to, struct ref *from, const char *msg)

refs.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,16 @@ int check_ref_format(const char *ref)
736736
}
737737
}
738738

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+
739749
const char *ref_rev_parse_rules[] = {
740750
"%.*s",
741751
"refs/%.*s",

refs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ extern int for_each_reflog(each_ref_fn, void *);
7979
#define CHECK_REF_FORMAT_WILDCARD (-3)
8080
extern int check_ref_format(const char *target);
8181

82+
extern const char *prettify_ref(const struct ref *ref);
83+
8284
/** rename ref, return 0 on success **/
8385
extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);
8486

0 commit comments

Comments
 (0)