Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
9afc5971
Commit
9afc5971
authored
May 31, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1559 from carlosmn/ref-shorthand
Introduce git_reference_shorthand
parents
af2c72d2
4f2eb2b7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
0 deletions
+59
-0
include/git2/refs.h
+15
-0
src/refs.c
+17
-0
tests-clar/refs/shorthand.c
+27
-0
No files found.
include/git2/refs.h
View file @
9afc5971
...
...
@@ -525,6 +525,21 @@ GIT_EXTERN(int) git_reference_peel(
*/
GIT_EXTERN
(
int
)
git_reference_is_valid_name
(
const
char
*
refname
);
/**
* Get the reference's short name
*
* This will transform the reference name into a name "human-readable"
* version. If no shortname is appropriate, it will return the full
* name.
*
* The memory is owned by the reference and must not be freed.
*
* @param ref a reference
* @return the human-readable version of the name
*/
GIT_EXTERN
(
const
char
*
)
git_reference_shorthand
(
git_reference
*
ref
);
/** @} */
GIT_END_DECL
#endif
src/refs.c
View file @
9afc5971
...
...
@@ -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
;
}
tests-clar/refs/shorthand.c
0 → 100644
View file @
9afc5971
#include "clar_libgit2.h"
#include "repository.h"
void
assert_shorthand
(
git_repository
*
repo
,
const
char
*
refname
,
const
char
*
shorthand
)
{
git_reference
*
ref
;
cl_git_pass
(
git_reference_lookup
(
&
ref
,
repo
,
refname
));
cl_assert_equal_s
(
git_reference_shorthand
(
ref
),
shorthand
);
git_reference_free
(
ref
);
}
void
test_refs_shorthand__0
(
void
)
{
git_repository
*
repo
;
cl_git_pass
(
git_repository_open
(
&
repo
,
cl_fixture
(
"testrepo.git"
)));
assert_shorthand
(
repo
,
"refs/heads/master"
,
"master"
);
assert_shorthand
(
repo
,
"refs/tags/test"
,
"test"
);
assert_shorthand
(
repo
,
"refs/remotes/test/master"
,
"test/master"
);
assert_shorthand
(
repo
,
"refs/notes/fanout"
,
"notes/fanout"
);
git_repository_free
(
repo
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment