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
c3be5c5a
Commit
c3be5c5a
authored
Jul 21, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reflog: keep the reflog name in sync with the reference name
parent
40c75652
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
src/reflog.c
+22
-0
tests-clar/refs/reflog/reflog.c
+21
-0
No files found.
src/reflog.c
View file @
c3be5c5a
...
...
@@ -183,6 +183,18 @@ static int retrieve_reflog_path(git_buf *path, git_reference *ref)
git_reference_owner
(
ref
)
->
path_repository
,
GIT_REFLOG_DIR
,
ref
->
name
);
}
int
create_new_reflog_file
(
const
char
*
filepath
)
{
int
fd
;
if
((
fd
=
p_open
(
filepath
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
GIT_REFLOG_FILE_MODE
))
<
0
)
return
-
1
;
return
p_close
(
fd
);
}
int
git_reflog_read
(
git_reflog
**
reflog
,
git_reference
*
ref
)
{
int
error
;
...
...
@@ -204,6 +216,10 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
goto
cleanup
;
if
((
error
==
GIT_ENOTFOUND
)
&&
((
error
=
create_new_reflog_file
(
git_buf_cstr
(
&
log_path
)))
<
0
))
goto
cleanup
;
if
((
error
=
reflog_parse
(
log
,
git_buf_cstr
(
&
log_file
),
git_buf_len
(
&
log_file
)))
<
0
)
goto
cleanup
;
...
...
@@ -237,6 +253,12 @@ int git_reflog_write(git_reflog *reflog)
git_repository_path
(
reflog
->
owner
),
GIT_REFLOG_DIR
,
reflog
->
ref_name
)
<
0
)
return
-
1
;
if
(
!
git_path_isfile
(
git_buf_cstr
(
&
log_path
)))
{
giterr_set
(
GITERR_INVALID
,
"Log file for reference '%s' doesn't exist."
,
reflog
->
ref_name
);
goto
cleanup
;
}
if
((
error
=
git_filebuf_open
(
&
fbuf
,
git_buf_cstr
(
&
log_path
),
0
))
<
0
)
goto
cleanup
;
...
...
tests-clar/refs/reflog/reflog.c
View file @
c3be5c5a
...
...
@@ -149,3 +149,24 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re
git_reference_free
(
subtrees
);
git_buf_free
(
&
subtrees_log_path
);
}
void
test_refs_reflog_reflog__cannot_write_a_moved_reflog
(
void
)
{
git_reference
*
master
;
git_buf
master_log_path
=
GIT_BUF_INIT
,
moved_log_path
=
GIT_BUF_INIT
;
git_reflog
*
reflog
;
cl_git_pass
(
git_reference_lookup
(
&
master
,
g_repo
,
"refs/heads/master"
));
cl_git_pass
(
git_reflog_read
(
&
reflog
,
master
));
cl_git_pass
(
git_reflog_write
(
reflog
));
cl_git_pass
(
git_reference_rename
(
master
,
"refs/moved"
,
0
));
cl_git_fail
(
git_reflog_write
(
reflog
));
git_reflog_free
(
reflog
);
git_reference_free
(
master
);
git_buf_free
(
&
moved_log_path
);
git_buf_free
(
&
master_log_path
);
}
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