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
908f24fd
Commit
908f24fd
authored
Apr 22, 2016
by
Arthur Schreiber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow creating copies of `git_reference` objects.
parent
1dc44910
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
1 deletions
+64
-1
include/git2/refs.h
+11
-0
src/refs.c
+13
-1
tests/refs/dup.c
+40
-0
No files found.
include/git2/refs.h
View file @
908f24fd
...
@@ -462,6 +462,17 @@ GIT_EXTERN(int) git_reference_foreach_name(
...
@@ -462,6 +462,17 @@ GIT_EXTERN(int) git_reference_foreach_name(
void
*
payload
);
void
*
payload
);
/**
/**
* Create a copy of an existing reference.
*
* Call `git_reference_free` to free the data.
*
* @param dest pointer where to store the copy
* @param source object to copy
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_reference_dup
(
git_reference
**
dest
,
git_reference
*
source
);
/**
* Free the given reference.
* Free the given reference.
*
*
* @param ref git_reference
* @param ref git_reference
...
...
src/refs.c
View file @
908f24fd
...
@@ -105,6 +105,18 @@ git_reference *git_reference__set_name(
...
@@ -105,6 +105,18 @@ git_reference *git_reference__set_name(
return
rewrite
;
return
rewrite
;
}
}
int
git_reference_dup
(
git_reference
**
dest
,
git_reference
*
source
)
{
if
(
source
->
type
==
GIT_REF_SYMBOLIC
)
*
dest
=
git_reference__alloc_symbolic
(
source
->
name
,
source
->
target
.
symbolic
);
else
*
dest
=
git_reference__alloc
(
source
->
name
,
&
source
->
target
.
oid
,
&
source
->
peel
);
GITERR_CHECK_ALLOC
(
*
dest
);
return
0
;
}
void
git_reference_free
(
git_reference
*
reference
)
void
git_reference_free
(
git_reference
*
reference
)
{
{
if
(
reference
==
NULL
)
if
(
reference
==
NULL
)
...
@@ -448,7 +460,7 @@ int git_reference_create_matching(
...
@@ -448,7 +460,7 @@ int git_reference_create_matching(
{
{
int
error
;
int
error
;
git_signature
*
who
=
NULL
;
git_signature
*
who
=
NULL
;
assert
(
id
);
assert
(
id
);
if
((
error
=
git_reference__log_signature
(
&
who
,
repo
))
<
0
)
if
((
error
=
git_reference__log_signature
(
&
who
,
repo
))
<
0
)
...
...
tests/refs/dup.c
0 → 100644
View file @
908f24fd
#include "clar_libgit2.h"
#include "refs.h"
static
git_repository
*
g_repo
;
void
test_refs_dup__initialize
(
void
)
{
g_repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
}
void
test_refs_dup__cleanup
(
void
)
{
cl_git_sandbox_cleanup
();
}
void
test_refs_dup__direct
(
void
)
{
git_reference
*
a
,
*
b
;
cl_git_pass
(
git_reference_lookup
(
&
a
,
g_repo
,
"refs/heads/master"
));
cl_git_pass
(
git_reference_dup
(
&
b
,
a
));
cl_assert
(
git_reference_cmp
(
a
,
b
)
==
0
);
git_reference_free
(
b
);
git_reference_free
(
a
);
}
void
test_refs_dup__symbolic
(
void
)
{
git_reference
*
a
,
*
b
;
cl_git_pass
(
git_reference_lookup
(
&
a
,
g_repo
,
"HEAD"
));
cl_git_pass
(
git_reference_dup
(
&
b
,
a
));
cl_assert
(
git_reference_cmp
(
a
,
b
)
==
0
);
git_reference_free
(
b
);
git_reference_free
(
a
);
}
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