Skip to content

Commit

Permalink
Use a common function to get the pretty name of refs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Daniel Barkalow authored and Junio C Hamano committed Mar 9, 2009
1 parent 8321c56 commit a9c37a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
6 changes: 1 addition & 5 deletions builtin-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,7 @@ static int update_local_ref(struct ref *ref,
struct commit *current = NULL, *updated;
enum object_type type;
struct branch *current_branch = branch_get(NULL);
const char *pretty_ref = ref->name + (
!prefixcmp(ref->name, "refs/heads/") ? 11 :
!prefixcmp(ref->name, "refs/tags/") ? 10 :
!prefixcmp(ref->name, "refs/remotes/") ? 13 :
0);
const char *pretty_ref = prettify_ref(ref);

*display = 0;
type = sha1_object_info(ref->new_sha1, NULL);
Expand Down
10 changes: 0 additions & 10 deletions builtin-send-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref)
}
}

static 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);
}

#define SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)

static void print_ref_status(char flag, const char *summary, struct ref *to, struct ref *from, const char *msg)
Expand Down
10 changes: 10 additions & 0 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,16 @@ int check_ref_format(const char *ref)
}
}

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",
Expand Down
2 changes: 2 additions & 0 deletions refs.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ extern int for_each_reflog(each_ref_fn, void *);
#define CHECK_REF_FORMAT_WILDCARD (-3)
extern int check_ref_format(const char *target);

extern const char *prettify_ref(const struct ref *ref);

/** rename ref, return 0 on success **/
extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);

Expand Down

0 comments on commit a9c37a7

Please sign in to comment.