diff options
author | Vicent Martà <vicent@github.com> | 2013-05-31 14:09:38 +0400 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-05-31 14:09:38 +0400 |
commit | 9afc59710ebfd63f0265aec79bc5388e610935a1 (patch) | |
tree | 6236ff7246494726a699cc1f6ca055d05c864551 /src/refs.c | |
parent | af2c72d228eab2d380d47cb7a5c19ba562340429 (diff) | |
parent | 4f2eb2b7f4cf6b2b6594887edd8948cb149c8052 (diff) |
Merge pull request #1559 from carlosmn/ref-shorthand
Introduce git_reference_shorthand
Diffstat (limited to 'src/refs.c')
-rw-r--r-- | src/refs.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/refs.c b/src/refs.c index 9c6c5c623..166669ef2 100644 --- a/src/refs.c +++ b/src/refs.c @@ -1131,3 +1131,20 @@ int git_reference_is_valid_name( refname, GIT_REF_FORMAT_ALLOW_ONELEVEL); } + +const char *git_reference_shorthand(git_reference *ref) +{ + const char *name = ref->name; + + if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR)) + return name + strlen(GIT_REFS_HEADS_DIR); + else if (!git__prefixcmp(name, GIT_REFS_TAGS_DIR)) + return name + strlen(GIT_REFS_TAGS_DIR); + else if (!git__prefixcmp(name, GIT_REFS_REMOTES_DIR)) + return name + strlen(GIT_REFS_REMOTES_DIR); + else if (!git__prefixcmp(name, GIT_REFS_DIR)) + return name + strlen(GIT_REFS_DIR); + + /* No shorthands are avaiable, so just return the name */ + return name; +} |