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
af3dcb0e
Commit
af3dcb0e
authored
Dec 15, 2016
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refdb_fs: optionally fsync loose references
parent
5312621b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
4 deletions
+40
-4
src/refdb_fs.c
+13
-4
tests/refs/create.c
+27
-0
No files found.
src/refdb_fs.c
View file @
af3dcb0e
...
...
@@ -736,7 +736,7 @@ static int reference_path_available(
static
int
loose_lock
(
git_filebuf
*
file
,
refdb_fs_backend
*
backend
,
const
char
*
name
)
{
int
error
;
int
error
,
filebuf_flags
;
git_buf
ref_path
=
GIT_BUF_INIT
;
assert
(
file
&&
backend
&&
name
);
...
...
@@ -755,7 +755,11 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
if
(
git_buf_joinpath
(
&
ref_path
,
backend
->
gitpath
,
name
)
<
0
)
return
-
1
;
error
=
git_filebuf_open
(
file
,
ref_path
.
ptr
,
GIT_FILEBUF_FORCE
,
GIT_REFS_FILE_MODE
);
filebuf_flags
=
GIT_FILEBUF_FORCE
;
if
(
git_object__synchronized_writing
)
filebuf_flags
|=
GIT_FILEBUF_FSYNC
;
error
=
git_filebuf_open
(
file
,
ref_path
.
ptr
,
filebuf_flags
,
GIT_REFS_FILE_MODE
);
if
(
error
==
GIT_EDIRECTORY
)
giterr_set
(
GITERR_REFERENCE
,
"cannot lock ref '%s', there are refs beneath that folder"
,
name
);
...
...
@@ -1784,7 +1788,7 @@ success:
/* Append to the reflog, must be called under reference lock */
static
int
reflog_append
(
refdb_fs_backend
*
backend
,
const
git_reference
*
ref
,
const
git_oid
*
old
,
const
git_oid
*
new
,
const
git_signature
*
who
,
const
char
*
message
)
{
int
error
,
is_symbolic
;
int
error
,
is_symbolic
,
open_flags
;
git_oid
old_id
=
{{
0
}},
new_id
=
{{
0
}};
git_buf
buf
=
GIT_BUF_INIT
,
path
=
GIT_BUF_INIT
;
git_repository
*
repo
=
backend
->
repo
;
...
...
@@ -1852,7 +1856,12 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
goto
cleanup
;
}
error
=
git_futils_writebuffer
(
&
buf
,
git_buf_cstr
(
&
path
),
O_WRONLY
|
O_CREAT
|
O_APPEND
,
GIT_REFLOG_FILE_MODE
);
open_flags
=
O_WRONLY
|
O_CREAT
|
O_APPEND
;
if
(
git_object__synchronized_writing
)
open_flags
|=
O_FSYNC
;
error
=
git_futils_writebuffer
(
&
buf
,
git_buf_cstr
(
&
path
),
open_flags
,
GIT_REFLOG_FILE_MODE
);
cleanup
:
git_buf_free
(
&
buf
);
...
...
tests/refs/create.c
View file @
af3dcb0e
...
...
@@ -13,6 +13,7 @@ static git_repository *g_repo;
void
test_refs_create__initialize
(
void
)
{
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
p_fsync__cnt
=
0
;
}
void
test_refs_create__cleanup
(
void
)
...
...
@@ -21,6 +22,7 @@ void test_refs_create__cleanup(void)
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_ENABLE_STRICT_OBJECT_CREATION
,
1
));
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION
,
1
));
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION
,
0
));
}
void
test_refs_create__symbolic
(
void
)
...
...
@@ -297,3 +299,28 @@ void test_refs_create__creating_a_loose_ref_with_invalid_windows_name(void)
test_win32_name
(
"refs/heads/com1"
);
}
void
test_refs_create__does_not_fsync_by_default
(
void
)
{
git_reference
*
ref
=
NULL
;
git_oid
id
;
git_oid_fromstr
(
&
id
,
current_master_tip
);
cl_git_pass
(
git_reference_create
(
&
ref
,
g_repo
,
"refs/heads/fsync_test"
,
&
id
,
0
,
"log message"
));
git_reference_free
(
ref
);
cl_assert_equal_i
(
0
,
p_fsync__cnt
);
}
void
test_refs_create__fsyncs_when_requested
(
void
)
{
git_reference
*
ref
=
NULL
;
git_oid
id
;
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION
,
1
));
p_fsync__cnt
=
0
;
git_oid_fromstr
(
&
id
,
current_master_tip
);
cl_git_pass
(
git_reference_create
(
&
ref
,
g_repo
,
"refs/heads/fsync_test"
,
&
id
,
0
,
"log message"
));
git_reference_free
(
ref
);
cl_assert_equal_i
(
2
,
p_fsync__cnt
);
}
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