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
7d633572
Commit
7d633572
authored
Mar 20, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2194 from libgit2/cmn/reflog-bare
reflog: follow core.logallrefupdates
parents
f29e4899
1c351659
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
13 deletions
+104
-13
src/refdb_fs.c
+31
-13
tests/refs/reflog/reflog.c
+73
-0
No files found.
src/refdb_fs.c
View file @
7d633572
...
...
@@ -925,16 +925,34 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
static
int
has_reflog
(
git_repository
*
repo
,
const
char
*
name
);
/* We only write if it's under heads/, remotes/ or notes/ or if it already has a log */
static
bool
should_write_reflog
(
git_repository
*
repo
,
const
char
*
name
)
static
int
should_write_reflog
(
int
*
write
,
git_repository
*
repo
,
const
char
*
name
)
{
if
(
has_reflog
(
repo
,
name
))
return
1
;
git_config
*
config
;
int
error
,
logall
,
is_bare
;
if
(
!
git__prefixcmp
(
name
,
GIT_REFS_HEADS_DIR
)
||
!
git__strcmp
(
name
,
GIT_HEAD_FILE
)
||
!
git__prefixcmp
(
name
,
GIT_REFS_REMOTES_DIR
)
||
!
git__prefixcmp
(
name
,
GIT_REFS_NOTES_DIR
))
return
1
;
/* Defaults to the oppsite of being bare */
is_bare
=
git_repository_is_bare
(
repo
);
logall
=
!
is_bare
;
if
((
error
=
git_repository_config__weakptr
(
&
config
,
repo
))
<
0
)
return
error
;
error
=
git_config_get_bool
(
&
logall
,
config
,
"core.logallrefupdates"
);
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
return
error
;
if
(
!
logall
)
{
*
write
=
0
;
}
else
if
(
has_reflog
(
repo
,
name
))
{
*
write
=
1
;
}
else
if
(
!
git__prefixcmp
(
name
,
GIT_REFS_HEADS_DIR
)
||
!
git__strcmp
(
name
,
GIT_HEAD_FILE
)
||
!
git__prefixcmp
(
name
,
GIT_REFS_REMOTES_DIR
)
||
!
git__prefixcmp
(
name
,
GIT_REFS_NOTES_DIR
))
{
*
write
=
1
;
}
else
{
*
write
=
0
;
}
return
0
;
}
...
...
@@ -1030,9 +1048,6 @@ static int maybe_append_head(refdb_fs_backend *backend, const git_reference *ref
name
=
git_reference_name
(
tmp
);
}
if
(
error
<
0
)
goto
cleanup
;
if
(
strcmp
(
name
,
ref
->
name
))
goto
cleanup
;
...
...
@@ -1056,7 +1071,7 @@ static int refdb_fs_backend__write(
{
refdb_fs_backend
*
backend
=
(
refdb_fs_backend
*
)
_backend
;
git_filebuf
file
=
GIT_FILEBUF_INIT
;
int
error
=
0
,
cmp
=
0
;
int
error
=
0
,
cmp
=
0
,
should_write
;
const
char
*
new_target
=
NULL
;
const
git_oid
*
new_id
=
NULL
;
...
...
@@ -1094,7 +1109,10 @@ static int refdb_fs_backend__write(
goto
on_error
;
/* not really error */
}
if
(
should_write_reflog
(
backend
->
repo
,
ref
->
name
))
{
if
((
error
=
should_write_reflog
(
&
should_write
,
backend
->
repo
,
ref
->
name
))
<
0
)
goto
on_error
;
if
(
should_write
)
{
if
((
error
=
reflog_append
(
backend
,
ref
,
NULL
,
NULL
,
who
,
message
))
<
0
)
goto
on_error
;
if
((
error
=
maybe_append_head
(
backend
,
ref
,
who
,
message
))
<
0
)
...
...
tests/refs/reflog/reflog.c
View file @
7d633572
...
...
@@ -261,3 +261,76 @@ void test_refs_reflog_reflog__do_not_append_when_no_update(void)
cl_assert_equal_i
(
nlogs_after
,
nlogs
);
}
static
void
assert_no_reflog_update
(
void
)
{
size_t
nlogs
,
nlogs_after
;
size_t
nlogs_master
,
nlogs_master_after
;
git_reference
*
ref
;
git_reflog
*
log
;
git_oid
id
;
cl_git_pass
(
git_reflog_read
(
&
log
,
g_repo
,
"HEAD"
));
nlogs
=
git_reflog_entrycount
(
log
);
git_reflog_free
(
log
);
cl_git_pass
(
git_reflog_read
(
&
log
,
g_repo
,
"refs/heads/master"
));
nlogs_master
=
git_reflog_entrycount
(
log
);
git_reflog_free
(
log
);
/* Move it back */
git_oid_fromstr
(
&
id
,
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
);
cl_git_pass
(
git_reference_create
(
&
ref
,
g_repo
,
"refs/heads/master"
,
&
id
,
1
,
NULL
,
NULL
));
git_reference_free
(
ref
);
cl_git_pass
(
git_reflog_read
(
&
log
,
g_repo
,
"HEAD"
));
nlogs_after
=
git_reflog_entrycount
(
log
);
git_reflog_free
(
log
);
cl_assert_equal_i
(
nlogs_after
,
nlogs
);
cl_git_pass
(
git_reflog_read
(
&
log
,
g_repo
,
"refs/heads/master"
));
nlogs_master_after
=
git_reflog_entrycount
(
log
);
git_reflog_free
(
log
);
cl_assert_equal_i
(
nlogs_after
,
nlogs
);
cl_assert_equal_i
(
nlogs_master_after
,
nlogs_master
);
}
void
test_refs_reflog_reflog__logallrefupdates_bare_set_false
(
void
)
{
git_config
*
config
;
cl_git_pass
(
git_repository_config
(
&
config
,
g_repo
));
cl_git_pass
(
git_config_set_bool
(
config
,
"core.logallrefupdates"
,
false
));
git_config_free
(
config
);
assert_no_reflog_update
();
}
void
test_refs_reflog_reflog__logallrefupdates_bare_unset
(
void
)
{
git_config
*
config
;
cl_git_pass
(
git_repository_config
(
&
config
,
g_repo
));
cl_git_pass
(
git_config_delete_entry
(
config
,
"core.logallrefupdates"
));
git_config_free
(
config
);
assert_no_reflog_update
();
}
void
test_refs_reflog_reflog__logallrefupdates_nonbare_set_false
(
void
)
{
git_config
*
config
;
cl_git_sandbox_cleanup
();
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
cl_git_pass
(
git_repository_config
(
&
config
,
g_repo
));
cl_git_pass
(
git_config_set_bool
(
config
,
"core.logallrefupdates"
,
false
));
git_config_free
(
config
);
assert_no_reflog_update
();
}
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