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
ef5a3851
Unverified
Commit
ef5a3851
authored
Oct 11, 2019
by
Patrick Steinhardt
Committed by
GitHub
Oct 11, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5257 from henkesn/master
Fix file locking on POSIX OS
parents
1f9b4970
3335a034
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
36 additions
and
19 deletions
+36
-19
src/cherrypick.c
+2
-2
src/filebuf.c
+5
-9
src/filebuf.h
+1
-1
src/merge.c
+3
-3
src/refdb_fs.c
+1
-1
src/repository.c
+1
-1
src/revert.c
+2
-2
tests/refs/transactions.c
+21
-0
No files found.
src/cherrypick.c
View file @
ef5a3851
...
@@ -30,7 +30,7 @@ static int write_cherrypick_head(
...
@@ -30,7 +30,7 @@ static int write_cherrypick_head(
int
error
=
0
;
int
error
=
0
;
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_CHERRYPICK_HEAD_FILE
))
>=
0
&&
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_CHERRYPICK_HEAD_FILE
))
>=
0
&&
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
FORCE
,
GIT_CHERRYPICK_FILE_MODE
))
>=
0
&&
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
CREATE_LEADING_DIRS
,
GIT_CHERRYPICK_FILE_MODE
))
>=
0
&&
(
error
=
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
commit_oidstr
))
>=
0
)
(
error
=
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
commit_oidstr
))
>=
0
)
error
=
git_filebuf_commit
(
&
file
);
error
=
git_filebuf_commit
(
&
file
);
...
@@ -51,7 +51,7 @@ static int write_merge_msg(
...
@@ -51,7 +51,7 @@ static int write_merge_msg(
int
error
=
0
;
int
error
=
0
;
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_MSG_FILE
))
<
0
||
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_MSG_FILE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
FORCE
,
GIT_CHERRYPICK_FILE_MODE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
CREATE_LEADING_DIRS
,
GIT_CHERRYPICK_FILE_MODE
))
<
0
||
(
error
=
git_filebuf_printf
(
&
file
,
"%s"
,
commit_msg
))
<
0
)
(
error
=
git_filebuf_printf
(
&
file
,
"%s"
,
commit_msg
))
<
0
)
goto
cleanup
;
goto
cleanup
;
...
...
src/filebuf.c
View file @
ef5a3851
...
@@ -44,18 +44,14 @@ static int verify_last_error(git_filebuf *file)
...
@@ -44,18 +44,14 @@ static int verify_last_error(git_filebuf *file)
static
int
lock_file
(
git_filebuf
*
file
,
int
flags
,
mode_t
mode
)
static
int
lock_file
(
git_filebuf
*
file
,
int
flags
,
mode_t
mode
)
{
{
if
(
git_path_exists
(
file
->
path_lock
)
==
true
)
{
if
(
git_path_exists
(
file
->
path_lock
)
==
true
)
{
if
(
flags
&
GIT_FILEBUF_FORCE
)
git_error_clear
();
/* actual OS error code just confuses */
p_unlink
(
file
->
path_lock
);
git_error_set
(
GIT_ERROR_OS
,
else
{
"failed to lock file '%s' for writing"
,
file
->
path_lock
);
git_error_clear
();
/* actual OS error code just confuses */
return
GIT_ELOCKED
;
git_error_set
(
GIT_ERROR_OS
,
"failed to lock file '%s' for writing"
,
file
->
path_lock
);
return
GIT_ELOCKED
;
}
}
}
/* create path to the file buffer is required */
/* create path to the file buffer is required */
if
(
flags
&
GIT_FILEBUF_
FORCE
)
{
if
(
flags
&
GIT_FILEBUF_
CREATE_LEADING_DIRS
)
{
/* XXX: Should dirmode here be configurable? Or is 0777 always fine? */
/* XXX: Should dirmode here be configurable? Or is 0777 always fine? */
file
->
fd
=
git_futils_creat_locked_withpath
(
file
->
path_lock
,
0777
,
mode
);
file
->
fd
=
git_futils_creat_locked_withpath
(
file
->
path_lock
,
0777
,
mode
);
}
else
{
}
else
{
...
...
src/filebuf.h
View file @
ef5a3851
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
#define GIT_FILEBUF_HASH_CONTENTS (1 << 0)
#define GIT_FILEBUF_HASH_CONTENTS (1 << 0)
#define GIT_FILEBUF_APPEND (1 << 2)
#define GIT_FILEBUF_APPEND (1 << 2)
#define GIT_FILEBUF_
FORCE
(1 << 3)
#define GIT_FILEBUF_
CREATE_LEADING_DIRS
(1 << 3)
#define GIT_FILEBUF_TEMPORARY (1 << 4)
#define GIT_FILEBUF_TEMPORARY (1 << 4)
#define GIT_FILEBUF_DO_NOT_BUFFER (1 << 5)
#define GIT_FILEBUF_DO_NOT_BUFFER (1 << 5)
#define GIT_FILEBUF_FSYNC (1 << 6)
#define GIT_FILEBUF_FSYNC (1 << 6)
...
...
src/merge.c
View file @
ef5a3851
...
@@ -2431,7 +2431,7 @@ static int write_merge_head(
...
@@ -2431,7 +2431,7 @@ static int write_merge_head(
assert
(
repo
&&
heads
);
assert
(
repo
&&
heads
);
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_HEAD_FILE
))
<
0
||
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_HEAD_FILE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
FORCE
,
GIT_MERGE_FILE_MODE
))
<
0
)
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
CREATE_LEADING_DIRS
,
GIT_MERGE_FILE_MODE
))
<
0
)
goto
cleanup
;
goto
cleanup
;
for
(
i
=
0
;
i
<
heads_len
;
i
++
)
{
for
(
i
=
0
;
i
<
heads_len
;
i
++
)
{
...
@@ -2459,7 +2459,7 @@ static int write_merge_mode(git_repository *repo)
...
@@ -2459,7 +2459,7 @@ static int write_merge_mode(git_repository *repo)
assert
(
repo
);
assert
(
repo
);
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_MODE_FILE
))
<
0
||
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_MODE_FILE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
FORCE
,
GIT_MERGE_FILE_MODE
))
<
0
)
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
CREATE_LEADING_DIRS
,
GIT_MERGE_FILE_MODE
))
<
0
)
goto
cleanup
;
goto
cleanup
;
if
((
error
=
git_filebuf_write
(
&
file
,
"no-ff"
,
5
))
<
0
)
if
((
error
=
git_filebuf_write
(
&
file
,
"no-ff"
,
5
))
<
0
)
...
@@ -2690,7 +2690,7 @@ static int write_merge_msg(
...
@@ -2690,7 +2690,7 @@ static int write_merge_msg(
entries
[
i
].
merge_head
=
heads
[
i
];
entries
[
i
].
merge_head
=
heads
[
i
];
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_MSG_FILE
))
<
0
||
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_MSG_FILE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
FORCE
,
GIT_MERGE_FILE_MODE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
CREATE_LEADING_DIRS
,
GIT_MERGE_FILE_MODE
))
<
0
||
(
error
=
git_filebuf_write
(
&
file
,
"Merge "
,
6
))
<
0
)
(
error
=
git_filebuf_write
(
&
file
,
"Merge "
,
6
))
<
0
)
goto
cleanup
;
goto
cleanup
;
...
...
src/refdb_fs.c
View file @
ef5a3851
...
@@ -804,7 +804,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
...
@@ -804,7 +804,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
if
(
git_buf_joinpath
(
&
ref_path
,
basedir
,
name
)
<
0
)
if
(
git_buf_joinpath
(
&
ref_path
,
basedir
,
name
)
<
0
)
return
-
1
;
return
-
1
;
filebuf_flags
=
GIT_FILEBUF_
FORCE
;
filebuf_flags
=
GIT_FILEBUF_
CREATE_LEADING_DIRS
;
if
(
backend
->
fsync
)
if
(
backend
->
fsync
)
filebuf_flags
|=
GIT_FILEBUF_FSYNC
;
filebuf_flags
|=
GIT_FILEBUF_FSYNC
;
...
...
src/repository.c
View file @
ef5a3851
...
@@ -2485,7 +2485,7 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
...
@@ -2485,7 +2485,7 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
git_oid_fmt
(
orig_head_str
,
orig_head
);
git_oid_fmt
(
orig_head_str
,
orig_head
);
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_ORIG_HEAD_FILE
))
==
0
&&
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_ORIG_HEAD_FILE
))
==
0
&&
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
FORCE
,
GIT_MERGE_FILE_MODE
))
==
0
&&
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
CREATE_LEADING_DIRS
,
GIT_MERGE_FILE_MODE
))
==
0
&&
(
error
=
git_filebuf_printf
(
&
file
,
"%.*s
\n
"
,
GIT_OID_HEXSZ
,
orig_head_str
))
==
0
)
(
error
=
git_filebuf_printf
(
&
file
,
"%.*s
\n
"
,
GIT_OID_HEXSZ
,
orig_head_str
))
==
0
)
error
=
git_filebuf_commit
(
&
file
);
error
=
git_filebuf_commit
(
&
file
);
...
...
src/revert.c
View file @
ef5a3851
...
@@ -29,7 +29,7 @@ static int write_revert_head(
...
@@ -29,7 +29,7 @@ static int write_revert_head(
int
error
=
0
;
int
error
=
0
;
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_REVERT_HEAD_FILE
))
>=
0
&&
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_REVERT_HEAD_FILE
))
>=
0
&&
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
FORCE
,
GIT_REVERT_FILE_MODE
))
>=
0
&&
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
CREATE_LEADING_DIRS
,
GIT_REVERT_FILE_MODE
))
>=
0
&&
(
error
=
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
commit_oidstr
))
>=
0
)
(
error
=
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
commit_oidstr
))
>=
0
)
error
=
git_filebuf_commit
(
&
file
);
error
=
git_filebuf_commit
(
&
file
);
...
@@ -51,7 +51,7 @@ static int write_merge_msg(
...
@@ -51,7 +51,7 @@ static int write_merge_msg(
int
error
=
0
;
int
error
=
0
;
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_MSG_FILE
))
<
0
||
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
gitdir
,
GIT_MERGE_MSG_FILE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
FORCE
,
GIT_REVERT_FILE_MODE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_
CREATE_LEADING_DIRS
,
GIT_REVERT_FILE_MODE
))
<
0
||
(
error
=
git_filebuf_printf
(
&
file
,
"Revert
\"
%s
\"\n\n
This reverts commit %s.
\n
"
,
(
error
=
git_filebuf_printf
(
&
file
,
"Revert
\"
%s
\"\n\n
This reverts commit %s.
\n
"
,
commit_msgline
,
commit_oidstr
))
<
0
)
commit_msgline
,
commit_oidstr
))
<
0
)
goto
cleanup
;
goto
cleanup
;
...
...
tests/refs/transactions.c
View file @
ef5a3851
...
@@ -108,3 +108,24 @@ void test_refs_transactions__unlocked_set(void)
...
@@ -108,3 +108,24 @@ void test_refs_transactions__unlocked_set(void)
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_transaction_set_target
(
g_tx
,
"refs/heads/foo"
,
&
id
,
NULL
,
NULL
));
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_transaction_set_target
(
g_tx
,
"refs/heads/foo"
,
&
id
,
NULL
,
NULL
));
cl_git_pass
(
git_transaction_commit
(
g_tx
));
cl_git_pass
(
git_transaction_commit
(
g_tx
));
}
}
void
test_refs_transactions__error_on_locking_locked_ref
(
void
)
{
git_oid
id
;
git_transaction
*
g_tx_with_lock
;
git_repository
*
g_repo_with_locking_tx
;
const
char
*
g_repo_path
=
git_repository_path
(
g_repo
);
/* prepare a separate transaction in another instance of testrepo and lock master */
cl_git_pass
(
git_repository_open
(
&
g_repo_with_locking_tx
,
g_repo_path
));
cl_git_pass
(
git_transaction_new
(
&
g_tx_with_lock
,
g_repo_with_locking_tx
));
cl_git_pass
(
git_transaction_lock_ref
(
g_tx_with_lock
,
"refs/heads/master"
));
/* lock reference for set_target */
cl_git_pass
(
git_oid_fromstr
(
&
id
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
));
cl_git_fail_with
(
GIT_ELOCKED
,
git_transaction_lock_ref
(
g_tx
,
"refs/heads/master"
));
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_transaction_set_target
(
g_tx
,
"refs/heads/master"
,
&
id
,
NULL
,
NULL
));
git_transaction_free
(
g_tx_with_lock
);
git_repository_free
(
g_repo_with_locking_tx
);
}
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