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
3a97bff3
Commit
3a97bff3
authored
Aug 16, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #372 from schu/reflog-return-oid
reflog: assimilate API
parents
bae88c0d
bcb080b0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
18 deletions
+27
-18
include/git2/reflog.h
+2
-2
src/reflog.c
+13
-10
src/reflog.h
+2
-2
tests/t10-refs.c
+10
-4
No files found.
include/git2/reflog.h
View file @
3a97bff3
...
...
@@ -91,7 +91,7 @@ GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(git_reflog *reflog
* @param entry a reflog entry
* @return the old oid
*/
GIT_EXTERN
(
c
har
*
)
git_reflog_entry_oidold
(
const
git_reflog_entry
*
entry
);
GIT_EXTERN
(
c
onst
git_oid
*
)
git_reflog_entry_oidold
(
const
git_reflog_entry
*
entry
);
/**
* Get the new oid
...
...
@@ -99,7 +99,7 @@ GIT_EXTERN(char *) git_reflog_entry_oidold(const git_reflog_entry *entry);
* @param entry a reflog entry
* @return the new oid at this time
*/
GIT_EXTERN
(
c
har
*
)
git_reflog_entry_oidnew
(
const
git_reflog_entry
*
entry
);
GIT_EXTERN
(
c
onst
git_oid
*
)
git_reflog_entry_oidnew
(
const
git_reflog_entry
*
entry
);
/**
* Get the committer of this entry
...
...
src/reflog.c
View file @
3a97bff3
...
...
@@ -113,10 +113,12 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
if
(
entry
==
NULL
)
return
GIT_ENOMEM
;
entry
->
oid_old
=
git__strndup
(
buf
,
GIT_OID_HEXSZ
);
if
(
git_oid_fromstrn
(
&
entry
->
oid_old
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
return
GIT_ERROR
;
seek_forward
(
GIT_OID_HEXSZ
+
1
);
entry
->
oid_cur
=
git__strndup
(
buf
,
GIT_OID_HEXSZ
);
if
(
git_oid_fromstrn
(
&
entry
->
oid_cur
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
return
GIT_ERROR
;
seek_forward
(
GIT_OID_HEXSZ
+
1
);
ptr
=
buf
;
...
...
@@ -165,9 +167,6 @@ void git_reflog_free(git_reflog *reflog)
for
(
i
=
0
;
i
<
reflog
->
entries
.
length
;
i
++
)
{
entry
=
git_vector_get
(
&
reflog
->
entries
,
i
);
free
(
entry
->
oid_old
);
free
(
entry
->
oid_cur
);
git_signature_free
(
entry
->
committer
);
free
(
entry
->
msg
);
...
...
@@ -193,8 +192,10 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
git_path_join_n
(
log_path
,
3
,
ref
->
owner
->
path_repository
,
GIT_REFLOG_DIR
,
ref
->
name
);
if
((
error
=
git_futils_readbuffer
(
&
log_file
,
log_path
))
<
GIT_SUCCESS
)
if
((
error
=
git_futils_readbuffer
(
&
log_file
,
log_path
))
<
GIT_SUCCESS
)
{
git_reflog_free
(
log
);
return
git__rethrow
(
error
,
"Failed to read reflog. Cannot read file `%s`"
,
log_path
);
}
error
=
reflog_parse
(
log
,
log_file
.
data
,
log_file
.
len
);
...
...
@@ -202,6 +203,8 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
if
(
error
==
GIT_SUCCESS
)
*
reflog
=
log
;
else
git_reflog_free
(
log
);
return
error
==
GIT_SUCCESS
?
GIT_SUCCESS
:
git__rethrow
(
error
,
"Failed to read reflog"
);
}
...
...
@@ -255,16 +258,16 @@ const git_reflog_entry * git_reflog_entry_byindex(git_reflog *reflog, unsigned i
return
git_vector_get
(
&
reflog
->
entries
,
idx
);
}
c
har
*
git_reflog_entry_oidold
(
const
git_reflog_entry
*
entry
)
c
onst
git_oid
*
git_reflog_entry_oidold
(
const
git_reflog_entry
*
entry
)
{
assert
(
entry
);
return
entry
->
oid_old
;
return
&
entry
->
oid_old
;
}
c
har
*
git_reflog_entry_oidnew
(
const
git_reflog_entry
*
entry
)
c
onst
git_oid
*
git_reflog_entry_oidnew
(
const
git_reflog_entry
*
entry
)
{
assert
(
entry
);
return
entry
->
oid_cur
;
return
&
entry
->
oid_cur
;
}
git_signature
*
git_reflog_entry_committer
(
const
git_reflog_entry
*
entry
)
...
...
src/reflog.h
View file @
3a97bff3
...
...
@@ -10,8 +10,8 @@
#define GIT_REFLOG_SIZE_MIN (2*GIT_OID_HEXSZ+2+17)
struct
git_reflog_entry
{
char
*
oid_old
;
char
*
oid_cur
;
git_oid
oid_old
;
git_oid
oid_cur
;
git_signature
*
committer
;
...
...
tests/t10-refs.c
View file @
3a97bff3
...
...
@@ -1026,6 +1026,7 @@ BEGIN_TEST(reflog0, "write a reflog for a given reference and ensure it can be r
git_signature
*
committer
;
git_reflog
*
reflog
;
git_reflog_entry
*
entry
;
char
oid_str
[
GIT_OID_HEXSZ
+
1
];
must_pass
(
open_temp_repo
(
&
repo
,
REPOSITORY_FOLDER
));
...
...
@@ -1037,6 +1038,7 @@ BEGIN_TEST(reflog0, "write a reflog for a given reference and ensure it can be r
must_pass
(
git_signature_now
(
&
committer
,
"foo"
,
"foo@bar"
));
must_pass
(
git_reflog_write
(
ref
,
NULL
,
committer
,
NULL
));
must_fail
(
git_reflog_write
(
ref
,
NULL
,
committer
,
"no ancestor NULL for an existing reflog"
));
must_fail
(
git_reflog_write
(
ref
,
NULL
,
committer
,
"no
\n
newline"
));
must_pass
(
git_reflog_write
(
ref
,
&
oid
,
committer
,
commit_msg
));
...
...
@@ -1054,14 +1056,18 @@ BEGIN_TEST(reflog0, "write a reflog for a given reference and ensure it can be r
entry
=
(
git_reflog_entry
*
)
git_vector_get
(
&
reflog
->
entries
,
0
);
must_pass
(
assert_signature
(
committer
,
entry
->
committer
));
must_be_true
(
strcmp
(
"0000000000000000000000000000000000000000"
,
entry
->
oid_old
)
==
0
);
must_be_true
(
strcmp
(
current_master_tip
,
entry
->
oid_cur
)
==
0
);
git_oid_to_string
(
oid_str
,
GIT_OID_HEXSZ
+
1
,
&
entry
->
oid_old
);
must_be_true
(
strcmp
(
"0000000000000000000000000000000000000000"
,
oid_str
)
==
0
);
git_oid_to_string
(
oid_str
,
GIT_OID_HEXSZ
+
1
,
&
entry
->
oid_cur
);
must_be_true
(
strcmp
(
current_master_tip
,
oid_str
)
==
0
);
must_be_true
(
entry
->
msg
==
NULL
);
entry
=
(
git_reflog_entry
*
)
git_vector_get
(
&
reflog
->
entries
,
1
);
must_pass
(
assert_signature
(
committer
,
entry
->
committer
));
must_be_true
(
strcmp
(
current_master_tip
,
entry
->
oid_old
)
==
0
);
must_be_true
(
strcmp
(
current_master_tip
,
entry
->
oid_cur
)
==
0
);
git_oid_to_string
(
oid_str
,
GIT_OID_HEXSZ
+
1
,
&
entry
->
oid_old
);
must_be_true
(
strcmp
(
current_master_tip
,
oid_str
)
==
0
);
git_oid_to_string
(
oid_str
,
GIT_OID_HEXSZ
+
1
,
&
entry
->
oid_cur
);
must_be_true
(
strcmp
(
current_master_tip
,
oid_str
)
==
0
);
must_be_true
(
strcmp
(
commit_msg
,
entry
->
msg
)
==
0
);
git_signature_free
(
committer
);
...
...
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