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
1d3a8aeb
Commit
1d3a8aeb
authored
Nov 04, 2013
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move mode_t to filebuf_open instead of _commit
parent
f966acd1
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
80 additions
and
77 deletions
+80
-77
src/blob.c
+1
-1
src/checkout.c
+2
-2
src/config_file.c
+2
-2
src/fetchhead.c
+2
-2
src/filebuf.c
+9
-20
src/filebuf.h
+3
-3
src/fileops.c
+10
-1
src/fileops.h
+1
-1
src/index.c
+2
-2
src/indexer.c
+6
-4
src/merge.c
+8
-8
src/merge.h
+1
-0
src/odb_loose.c
+6
-4
src/refdb_fs.c
+7
-7
src/repository.c
+3
-3
tests-clar/config/stress.c
+2
-2
tests-clar/core/filebuf.c
+10
-10
tests-clar/index/tests.c
+3
-3
tests-clar/odb/alternates.c
+2
-2
No files found.
src/blob.c
View file @
1d3a8aeb
...
...
@@ -284,7 +284,7 @@ int git_blob_create_fromchunks(
content
=
git__malloc
(
BUFFER_SIZE
);
GITERR_CHECK_ALLOC
(
content
);
if
(
git_filebuf_open
(
&
file
,
git_buf_cstr
(
&
path
),
GIT_FILEBUF_TEMPORARY
)
<
0
)
if
(
git_filebuf_open
(
&
file
,
git_buf_cstr
(
&
path
),
GIT_FILEBUF_TEMPORARY
,
0666
)
<
0
)
goto
cleanup
;
while
(
1
)
{
...
...
src/checkout.c
View file @
1d3a8aeb
...
...
@@ -1673,9 +1673,9 @@ static int checkout_write_merge(
goto
done
;
if
((
error
=
git_futils_mkpath2file
(
path_workdir
.
ptr
,
0755
))
<
0
||
(
error
=
git_filebuf_open
(
&
output
,
path_workdir
.
ptr
,
GIT_FILEBUF_DO_NOT_BUFFER
))
<
0
||
(
error
=
git_filebuf_open
(
&
output
,
path_workdir
.
ptr
,
GIT_FILEBUF_DO_NOT_BUFFER
,
result
.
mode
))
<
0
||
(
error
=
git_filebuf_write
(
&
output
,
result
.
data
,
result
.
len
))
<
0
||
(
error
=
git_filebuf_commit
(
&
output
,
result
.
mode
))
<
0
)
(
error
=
git_filebuf_commit
(
&
output
))
<
0
)
goto
done
;
done
:
...
...
src/config_file.c
View file @
1d3a8aeb
...
...
@@ -1210,7 +1210,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
write_start
=
data_start
;
/* Lock the file */
if
(
git_filebuf_open
(
&
file
,
cfg
->
file_path
,
0
)
<
0
)
if
(
git_filebuf_open
(
&
file
,
cfg
->
file_path
,
0
,
GIT_CONFIG_FILE_MODE
)
<
0
)
return
-
1
;
skip_bom
(
reader
);
...
...
@@ -1369,7 +1369,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
/* refresh stats - if this errors, then commit will error too */
(
void
)
git_filebuf_stats
(
&
reader
->
file_mtime
,
&
reader
->
file_size
,
&
file
);
result
=
git_filebuf_commit
(
&
file
,
GIT_CONFIG_FILE_MODE
);
result
=
git_filebuf_commit
(
&
file
);
git_buf_free
(
&
reader
->
buffer
);
return
result
;
...
...
src/fetchhead.c
View file @
1d3a8aeb
...
...
@@ -112,7 +112,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
if
(
git_buf_joinpath
(
&
path
,
repo
->
path_repository
,
GIT_FETCH_HEAD_FILE
)
<
0
)
return
-
1
;
if
(
git_filebuf_open
(
&
file
,
path
.
ptr
,
GIT_FILEBUF_FORCE
)
<
0
)
{
if
(
git_filebuf_open
(
&
file
,
path
.
ptr
,
GIT_FILEBUF_FORCE
,
GIT_REFS_FILE_MODE
)
<
0
)
{
git_buf_free
(
&
path
);
return
-
1
;
}
...
...
@@ -124,7 +124,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
git_vector_foreach
(
fetchhead_refs
,
i
,
fetchhead_ref
)
fetchhead_ref_write
(
&
file
,
fetchhead_ref
);
return
git_filebuf_commit
(
&
file
,
GIT_REFS_FILE_MODE
);
return
git_filebuf_commit
(
&
file
);
}
static
int
fetchhead_ref_parse
(
...
...
src/filebuf.c
View file @
1d3a8aeb
...
...
@@ -10,8 +10,6 @@
#include "filebuf.h"
#include "fileops.h"
#define GIT_LOCK_FILE_MODE 0644
static
const
size_t
WRITE_BUFFER_SIZE
=
(
4096
*
2
);
enum
buferr_t
{
...
...
@@ -44,7 +42,7 @@ static int verify_last_error(git_filebuf *file)
}
}
static
int
lock_file
(
git_filebuf
*
file
,
int
flags
)
static
int
lock_file
(
git_filebuf
*
file
,
int
flags
,
mode_t
mode
)
{
if
(
git_path_exists
(
file
->
path_lock
)
==
true
)
{
if
(
flags
&
GIT_FILEBUF_FORCE
)
...
...
@@ -60,9 +58,9 @@ static int lock_file(git_filebuf *file, int flags)
/* create path to the file buffer is required */
if
(
flags
&
GIT_FILEBUF_FORCE
)
{
/* XXX: Should dirmode here be configurable? Or is 0777 always fine? */
file
->
fd
=
git_futils_creat_locked_withpath
(
file
->
path_lock
,
0777
,
GIT_LOCK_FILE_MODE
);
file
->
fd
=
git_futils_creat_locked_withpath
(
file
->
path_lock
,
0777
,
mode
);
}
else
{
file
->
fd
=
git_futils_creat_locked
(
file
->
path_lock
,
GIT_LOCK_FILE_MODE
);
file
->
fd
=
git_futils_creat_locked
(
file
->
path_lock
,
mode
);
}
if
(
file
->
fd
<
0
)
...
...
@@ -195,7 +193,7 @@ static int write_deflate(git_filebuf *file, void *source, size_t len)
return
0
;
}
int
git_filebuf_open
(
git_filebuf
*
file
,
const
char
*
path
,
int
flags
)
int
git_filebuf_open
(
git_filebuf
*
file
,
const
char
*
path
,
int
flags
,
mode_t
mode
)
{
int
compression
,
error
=
-
1
;
size_t
path_len
;
...
...
@@ -255,7 +253,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
git_buf
tmp_path
=
GIT_BUF_INIT
;
/* Open the file as temporary for locking */
file
->
fd
=
git_futils_mktmp
(
&
tmp_path
,
path
);
file
->
fd
=
git_futils_mktmp
(
&
tmp_path
,
path
,
mode
);
if
(
file
->
fd
<
0
)
{
git_buf_free
(
&
tmp_path
);
...
...
@@ -282,7 +280,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
memcpy
(
file
->
path_lock
+
path_len
,
GIT_FILELOCK_EXTENSION
,
GIT_FILELOCK_EXTLENGTH
);
/* open the file for locking */
if
((
error
=
lock_file
(
file
,
flags
))
<
0
)
if
((
error
=
lock_file
(
file
,
flags
,
mode
))
<
0
)
goto
cleanup
;
}
...
...
@@ -309,24 +307,20 @@ int git_filebuf_hash(git_oid *oid, git_filebuf *file)
return
0
;
}
int
git_filebuf_commit_at
(
git_filebuf
*
file
,
const
char
*
path
,
mode_t
mode
)
int
git_filebuf_commit_at
(
git_filebuf
*
file
,
const
char
*
path
)
{
git__free
(
file
->
path_original
);
file
->
path_original
=
git__strdup
(
path
);
GITERR_CHECK_ALLOC
(
file
->
path_original
);
return
git_filebuf_commit
(
file
,
mode
);
return
git_filebuf_commit
(
file
);
}
int
git_filebuf_commit
(
git_filebuf
*
file
,
mode_t
mode
)
int
git_filebuf_commit
(
git_filebuf
*
file
)
{
mode_t
mask
;
/* temporary files cannot be committed */
assert
(
file
&&
file
->
path_original
);
p_umask
(
mask
=
p_umask
(
0
));
file
->
flush_mode
=
Z_FINISH
;
flush_buffer
(
file
);
...
...
@@ -342,11 +336,6 @@ int git_filebuf_commit(git_filebuf *file, mode_t mode)
file
->
fd
=
-
1
;
if
(
p_chmod
(
file
->
path_lock
,
(
mode
&
~
mask
)))
{
giterr_set
(
GITERR_OS
,
"Failed to set attributes for file at '%s'"
,
file
->
path_lock
);
goto
on_error
;
}
p_unlink
(
file
->
path_original
);
if
(
p_rename
(
file
->
path_lock
,
file
->
path_original
)
<
0
)
{
...
...
src/filebuf.h
View file @
1d3a8aeb
...
...
@@ -77,9 +77,9 @@ int git_filebuf_write(git_filebuf *lock, const void *buff, size_t len);
int
git_filebuf_reserve
(
git_filebuf
*
file
,
void
**
buff
,
size_t
len
);
int
git_filebuf_printf
(
git_filebuf
*
file
,
const
char
*
format
,
...)
GIT_FORMAT_PRINTF
(
2
,
3
);
int
git_filebuf_open
(
git_filebuf
*
lock
,
const
char
*
path
,
int
flags
);
int
git_filebuf_commit
(
git_filebuf
*
lock
,
mode_t
mode
);
int
git_filebuf_commit_at
(
git_filebuf
*
lock
,
const
char
*
path
,
mode_t
mode
);
int
git_filebuf_open
(
git_filebuf
*
lock
,
const
char
*
path
,
int
flags
,
mode_t
mode
);
int
git_filebuf_commit
(
git_filebuf
*
lock
);
int
git_filebuf_commit_at
(
git_filebuf
*
lock
,
const
char
*
path
);
void
git_filebuf_cleanup
(
git_filebuf
*
lock
);
int
git_filebuf_hash
(
git_oid
*
oid
,
git_filebuf
*
file
);
int
git_filebuf_flush
(
git_filebuf
*
file
);
...
...
src/fileops.c
View file @
1d3a8aeb
...
...
@@ -19,9 +19,12 @@ int git_futils_mkpath2file(const char *file_path, const mode_t mode)
GIT_MKDIR_PATH
|
GIT_MKDIR_SKIP_LAST
|
GIT_MKDIR_VERIFY_DIR
);
}
int
git_futils_mktmp
(
git_buf
*
path_out
,
const
char
*
filename
)
int
git_futils_mktmp
(
git_buf
*
path_out
,
const
char
*
filename
,
mode_t
mode
)
{
int
fd
;
mode_t
mask
;
p_umask
(
mask
=
p_umask
(
0
));
git_buf_sets
(
path_out
,
filename
);
git_buf_puts
(
path_out
,
"_git2_XXXXXX"
);
...
...
@@ -35,6 +38,12 @@ int git_futils_mktmp(git_buf *path_out, const char *filename)
return
-
1
;
}
if
(
p_chmod
(
path_out
->
ptr
,
(
mode
&
~
mask
)))
{
giterr_set
(
GITERR_OS
,
"Failed to set permissions on file '%s'"
,
path_out
->
ptr
);
return
-
1
;
}
return
fd
;
}
...
...
src/fileops.h
View file @
1d3a8aeb
...
...
@@ -141,7 +141,7 @@ extern int git_futils_rmdir_r(const char *path, const char *base, uint32_t flags
* Writes the filename into path_out.
* @return On success, an open file descriptor, else an error code < 0.
*/
extern
int
git_futils_mktmp
(
git_buf
*
path_out
,
const
char
*
filename
);
extern
int
git_futils_mktmp
(
git_buf
*
path_out
,
const
char
*
filename
,
mode_t
mode
);
/**
* Move a file on the filesystem, create the
...
...
src/index.c
View file @
1d3a8aeb
...
...
@@ -500,7 +500,7 @@ int git_index_write(git_index *index)
git_vector_sort
(
&
index
->
reuc
);
if
((
error
=
git_filebuf_open
(
&
file
,
index
->
index_file_path
,
GIT_FILEBUF_HASH_CONTENTS
))
<
0
)
{
&
file
,
index
->
index_file_path
,
GIT_FILEBUF_HASH_CONTENTS
,
GIT_INDEX_FILE_MODE
))
<
0
)
{
if
(
error
==
GIT_ELOCKED
)
giterr_set
(
GITERR_INDEX
,
"The index is locked. This might be due to a concurrrent or crashed process"
);
...
...
@@ -512,7 +512,7 @@ int git_index_write(git_index *index)
return
error
;
}
if
((
error
=
git_filebuf_commit
(
&
file
,
GIT_INDEX_FILE_MODE
))
<
0
)
if
((
error
=
git_filebuf_commit
(
&
file
))
<
0
)
return
error
;
error
=
git_futils_filestamp_check
(
&
index
->
stamp
,
index
->
index_file_path
);
...
...
src/indexer.c
View file @
1d3a8aeb
...
...
@@ -140,7 +140,8 @@ int git_indexer_new(
goto
cleanup
;
error
=
git_filebuf_open
(
&
idx
->
pack_file
,
path
.
ptr
,
GIT_FILEBUF_TEMPORARY
|
GIT_FILEBUF_DO_NOT_BUFFER
);
GIT_FILEBUF_TEMPORARY
|
GIT_FILEBUF_DO_NOT_BUFFER
,
GIT_PACK_FILE_MODE
);
git_buf_free
(
&
path
);
if
(
error
<
0
)
goto
cleanup
;
...
...
@@ -903,7 +904,8 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
if
(
git_buf_oom
(
&
filename
))
return
-
1
;
if
(
git_filebuf_open
(
&
index_file
,
filename
.
ptr
,
GIT_FILEBUF_HASH_CONTENTS
)
<
0
)
if
(
git_filebuf_open
(
&
index_file
,
filename
.
ptr
,
GIT_FILEBUF_HASH_CONTENTS
,
GIT_PACK_FILE_MODE
)
<
0
)
goto
on_error
;
/* Write out the header */
...
...
@@ -969,7 +971,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
goto
on_error
;
/* Commit file */
if
(
git_filebuf_commit_at
(
&
index_file
,
filename
.
ptr
,
GIT_PACK_FILE_MODE
)
<
0
)
if
(
git_filebuf_commit_at
(
&
index_file
,
filename
.
ptr
)
<
0
)
goto
on_error
;
git_mwindow_free_all
(
&
idx
->
pack
->
mwf
);
...
...
@@ -980,7 +982,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
if
(
index_path
(
&
filename
,
idx
,
".pack"
)
<
0
)
goto
on_error
;
/* And don't forget to rename the packfile to its new place. */
if
(
git_filebuf_commit_at
(
&
idx
->
pack_file
,
filename
.
ptr
,
GIT_PACK_FILE_MODE
)
<
0
)
if
(
git_filebuf_commit_at
(
&
idx
->
pack_file
,
filename
.
ptr
)
<
0
)
return
-
1
;
git_buf_free
(
&
filename
);
...
...
src/merge.c
View file @
1d3a8aeb
...
...
@@ -1623,9 +1623,9 @@ static int write_orig_head(
git_oid_tostr
(
orig_oid_str
,
GIT_OID_HEXSZ
+
1
,
&
our_head
->
oid
);
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
path_repository
,
GIT_ORIG_HEAD_FILE
))
==
0
&&
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_FORCE
))
==
0
&&
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_FORCE
,
GIT_MERGE_FILE_MODE
))
==
0
&&
(
error
=
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
orig_oid_str
))
==
0
)
error
=
git_filebuf_commit
(
&
file
,
0666
);
error
=
git_filebuf_commit
(
&
file
);
if
(
error
<
0
)
git_filebuf_cleanup
(
&
file
);
...
...
@@ -1649,7 +1649,7 @@ static int write_merge_head(
assert
(
repo
&&
heads
);
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
path_repository
,
GIT_MERGE_HEAD_FILE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_FORCE
))
<
0
)
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_FORCE
,
GIT_MERGE_FILE_MODE
))
<
0
)
goto
cleanup
;
for
(
i
=
0
;
i
<
heads_len
;
i
++
)
{
...
...
@@ -1659,7 +1659,7 @@ static int write_merge_head(
goto
cleanup
;
}
error
=
git_filebuf_commit
(
&
file
,
0666
);
error
=
git_filebuf_commit
(
&
file
);
cleanup
:
if
(
error
<
0
)
...
...
@@ -1682,10 +1682,10 @@ static int write_merge_mode(git_repository *repo, unsigned int flags)
assert
(
repo
);
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
path_repository
,
GIT_MERGE_MODE_FILE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_FORCE
))
<
0
)
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_FORCE
,
GIT_MERGE_FILE_MODE
))
<
0
)
goto
cleanup
;
error
=
git_filebuf_commit
(
&
file
,
0666
);
error
=
git_filebuf_commit
(
&
file
);
cleanup
:
if
(
error
<
0
)
...
...
@@ -1911,7 +1911,7 @@ static int write_merge_msg(
entries
[
i
].
merge_head
=
heads
[
i
];
if
((
error
=
git_buf_joinpath
(
&
file_path
,
repo
->
path_repository
,
GIT_MERGE_MSG_FILE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_FORCE
))
<
0
||
(
error
=
git_filebuf_open
(
&
file
,
file_path
.
ptr
,
GIT_FILEBUF_FORCE
,
GIT_MERGE_FILE_MODE
))
<
0
||
(
error
=
git_filebuf_write
(
&
file
,
"Merge "
,
6
))
<
0
)
goto
cleanup
;
...
...
@@ -1988,7 +1988,7 @@ static int write_merge_msg(
}
if
((
error
=
git_filebuf_printf
(
&
file
,
"
\n
"
))
<
0
||
(
error
=
git_filebuf_commit
(
&
file
,
0666
))
<
0
)
(
error
=
git_filebuf_commit
(
&
file
))
<
0
)
goto
cleanup
;
cleanup:
...
...
src/merge.h
View file @
1d3a8aeb
...
...
@@ -16,6 +16,7 @@
#define GIT_MERGE_MSG_FILE "MERGE_MSG"
#define GIT_MERGE_MODE_FILE "MERGE_MODE"
#define GIT_MERGE_FILE_MODE 0666
#define GIT_MERGE_TREE_RENAME_THRESHOLD 50
#define GIT_MERGE_TREE_TARGET_LIMIT 1000
...
...
src/odb_loose.c
View file @
1d3a8aeb
...
...
@@ -789,7 +789,7 @@ static int loose_backend__stream_fwrite(git_odb_stream *_stream, const git_oid *
error
=
-
1
;
else
error
=
git_filebuf_commit_at
(
&
stream
->
fbuf
,
final_path
.
ptr
,
backend
->
object_file_mode
);
&
stream
->
fbuf
,
final_path
.
ptr
);
git_buf_free
(
&
final_path
);
...
...
@@ -838,7 +838,8 @@ static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_
if
(
git_buf_joinpath
(
&
tmp_path
,
backend
->
objects_dir
,
"tmp_object"
)
<
0
||
git_filebuf_open
(
&
stream
->
fbuf
,
tmp_path
.
ptr
,
GIT_FILEBUF_TEMPORARY
|
(
backend
->
object_zlib_level
<<
GIT_FILEBUF_DEFLATE_SHIFT
))
<
0
||
(
backend
->
object_zlib_level
<<
GIT_FILEBUF_DEFLATE_SHIFT
),
backend
->
object_file_mode
)
<
0
||
stream
->
stream
.
write
((
git_odb_stream
*
)
stream
,
hdr
,
hdrlen
)
<
0
)
{
git_filebuf_cleanup
(
&
stream
->
fbuf
);
...
...
@@ -867,7 +868,8 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c
if
(
git_buf_joinpath
(
&
final_path
,
backend
->
objects_dir
,
"tmp_object"
)
<
0
||
git_filebuf_open
(
&
fbuf
,
final_path
.
ptr
,
GIT_FILEBUF_TEMPORARY
|
(
backend
->
object_zlib_level
<<
GIT_FILEBUF_DEFLATE_SHIFT
))
<
0
)
(
backend
->
object_zlib_level
<<
GIT_FILEBUF_DEFLATE_SHIFT
),
backend
->
object_file_mode
)
<
0
)
{
error
=
-
1
;
goto
cleanup
;
...
...
@@ -878,7 +880,7 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c
if
(
object_file_name
(
&
final_path
,
backend
,
oid
)
<
0
||
object_mkdir
(
&
final_path
,
backend
)
<
0
||
git_filebuf_commit_at
(
&
fbuf
,
final_path
.
ptr
,
backend
->
object_file_mode
)
<
0
)
git_filebuf_commit_at
(
&
fbuf
,
final_path
.
ptr
)
<
0
)
error
=
-
1
;
cleanup
:
...
...
src/refdb_fs.c
View file @
1d3a8aeb
...
...
@@ -702,7 +702,7 @@ static int loose_write(refdb_fs_backend *backend, const git_reference *ref)
if
(
git_buf_joinpath
(
&
ref_path
,
backend
->
path
,
ref
->
name
)
<
0
)
return
-
1
;
if
(
git_filebuf_open
(
&
file
,
ref_path
.
ptr
,
GIT_FILEBUF_FORCE
)
<
0
)
{
if
(
git_filebuf_open
(
&
file
,
ref_path
.
ptr
,
GIT_FILEBUF_FORCE
,
GIT_REFS_FILE_MODE
)
<
0
)
{
git_buf_free
(
&
ref_path
);
return
-
1
;
}
...
...
@@ -720,7 +720,7 @@ static int loose_write(refdb_fs_backend *backend, const git_reference *ref)
assert
(
0
);
/* don't let this happen */
}
return
git_filebuf_commit
(
&
file
,
GIT_REFS_FILE_MODE
);
return
git_filebuf_commit
(
&
file
);
}
/*
...
...
@@ -865,7 +865,7 @@ static int packed_write(refdb_fs_backend *backend)
return
-
1
;
/* Open the file! */
if
(
git_filebuf_open
(
&
pack_file
,
git_sortedcache_path
(
refcache
),
0
)
<
0
)
if
(
git_filebuf_open
(
&
pack_file
,
git_sortedcache_path
(
refcache
),
0
,
GIT_PACKEDREFS_FILE_MODE
)
<
0
)
goto
fail
;
/* Packfiles have a header... apparently
...
...
@@ -886,7 +886,7 @@ static int packed_write(refdb_fs_backend *backend)
/* if we've written all the references properly, we can commit
* the packfile to make the changes effective */
if
(
git_filebuf_commit
(
&
pack_file
,
GIT_PACKEDREFS_FILE_MODE
)
<
0
)
if
(
git_filebuf_commit
(
&
pack_file
)
<
0
)
goto
fail
;
/* when and only when the packfile has been properly written,
...
...
@@ -1289,7 +1289,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
goto
cleanup
;
}
if
((
error
=
git_filebuf_open
(
&
fbuf
,
git_buf_cstr
(
&
log_path
),
0
))
<
0
)
if
((
error
=
git_filebuf_open
(
&
fbuf
,
git_buf_cstr
(
&
log_path
),
0
,
GIT_REFLOG_FILE_MODE
))
<
0
)
goto
cleanup
;
git_vector_foreach
(
&
reflog
->
entries
,
i
,
entry
)
{
...
...
@@ -1300,7 +1300,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
goto
cleanup
;
}
error
=
git_filebuf_commit
(
&
fbuf
,
GIT_REFLOG_FILE_MODE
);
error
=
git_filebuf_commit
(
&
fbuf
);
goto
success
;
cleanup
:
...
...
@@ -1350,7 +1350,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
if
(
git_buf_joinpath
(
&
temp_path
,
git_buf_cstr
(
&
temp_path
),
"temp_reflog"
)
<
0
)
return
-
1
;
if
((
fd
=
git_futils_mktmp
(
&
temp_path
,
git_buf_cstr
(
&
temp_path
)))
<
0
)
{
if
((
fd
=
git_futils_mktmp
(
&
temp_path
,
git_buf_cstr
(
&
temp_path
)
,
GIT_REFLOG_FILE_MODE
))
<
0
)
{
error
=
-
1
;
goto
cleanup
;
}
...
...
src/repository.c
View file @
1d3a8aeb
...
...
@@ -816,7 +816,7 @@ static int repo_init_create_head(const char *git_dir, const char *ref_name)
const
char
*
fmt
;
if
(
git_buf_joinpath
(
&
ref_path
,
git_dir
,
GIT_HEAD_FILE
)
<
0
||
git_filebuf_open
(
&
ref
,
ref_path
.
ptr
,
0
)
<
0
)
git_filebuf_open
(
&
ref
,
ref_path
.
ptr
,
0
,
GIT_REFS_FILE_MODE
)
<
0
)
goto
fail
;
if
(
!
ref_name
)
...
...
@@ -828,7 +828,7 @@ static int repo_init_create_head(const char *git_dir, const char *ref_name)
fmt
=
"ref: "
GIT_REFS_HEADS_DIR
"%s
\n
"
;
if
(
git_filebuf_printf
(
&
ref
,
fmt
,
ref_name
)
<
0
||
git_filebuf_commit
(
&
ref
,
GIT_REFS_FILE_MODE
)
<
0
)
git_filebuf_commit
(
&
ref
)
<
0
)
goto
fail
;
git_buf_free
(
&
ref_path
);
...
...
@@ -875,7 +875,7 @@ static bool are_symlinks_supported(const char *wd_path)
struct
stat
st
;
int
symlinks_supported
=
-
1
;
if
((
fd
=
git_futils_mktmp
(
&
path
,
wd_path
))
<
0
||
if
((
fd
=
git_futils_mktmp
(
&
path
,
wd_path
,
0666
))
<
0
||
p_close
(
fd
)
<
0
||
p_unlink
(
path
.
ptr
)
<
0
||
p_symlink
(
"testing"
,
path
.
ptr
)
<
0
||
...
...
tests-clar/config/stress.c
View file @
1d3a8aeb
...
...
@@ -10,12 +10,12 @@ void test_config_stress__initialize(void)
{
git_filebuf
file
=
GIT_FILEBUF_INIT
;
cl_git_pass
(
git_filebuf_open
(
&
file
,
TEST_CONFIG
,
0
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
TEST_CONFIG
,
0
,
0666
));
git_filebuf_printf
(
&
file
,
"[color]
\n\t
ui = auto
\n
"
);
git_filebuf_printf
(
&
file
,
"[core]
\n\t
editor =
\n
"
);
cl_git_pass
(
git_filebuf_commit
(
&
file
,
0666
));
cl_git_pass
(
git_filebuf_commit
(
&
file
));
}
void
test_config_stress__cleanup
(
void
)
...
...
tests-clar/core/filebuf.c
View file @
1d3a8aeb
...
...
@@ -13,7 +13,7 @@ void test_core_filebuf__0(void)
cl_must_pass
(
fd
);
cl_must_pass
(
p_close
(
fd
));
cl_git_fail
(
git_filebuf_open
(
&
file
,
test
,
0
));
cl_git_fail
(
git_filebuf_open
(
&
file
,
test
,
0
,
0666
));
cl_assert
(
git_path_exists
(
testlock
));
cl_must_pass
(
p_unlink
(
testlock
));
...
...
@@ -28,9 +28,9 @@ void test_core_filebuf__1(void)
cl_git_mkfile
(
test
,
"libgit2 rocks
\n
"
);
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
GIT_FILEBUF_APPEND
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
GIT_FILEBUF_APPEND
,
0666
));
cl_git_pass
(
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
"libgit2 rocks"
));
cl_git_pass
(
git_filebuf_commit
(
&
file
,
0666
));
cl_git_pass
(
git_filebuf_commit
(
&
file
));
cl_assert_equal_file
(
"libgit2 rocks
\n
libgit2 rocks
\n
"
,
0
,
test
);
...
...
@@ -47,9 +47,9 @@ void test_core_filebuf__2(void)
memset
(
buf
,
0xfe
,
sizeof
(
buf
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
0
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
0
,
0666
));
cl_git_pass
(
git_filebuf_write
(
&
file
,
buf
,
sizeof
(
buf
)));
cl_git_pass
(
git_filebuf_commit
(
&
file
,
0666
));
cl_git_pass
(
git_filebuf_commit
(
&
file
));
cl_assert_equal_file
((
char
*
)
buf
,
sizeof
(
buf
),
test
);
...
...
@@ -64,7 +64,7 @@ void test_core_filebuf__4(void)
cl_assert
(
file
.
buffer
==
NULL
);
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
0
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
0
,
0666
));
cl_assert
(
file
.
buffer
!=
NULL
);
git_filebuf_cleanup
(
&
file
);
...
...
@@ -80,12 +80,12 @@ void test_core_filebuf__5(void)
cl_assert
(
file
.
buffer
==
NULL
);
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
0
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
0
,
0666
));
cl_assert
(
file
.
buffer
!=
NULL
);
cl_git_pass
(
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
"libgit2 rocks"
));
cl_assert
(
file
.
buffer
!=
NULL
);
cl_git_pass
(
git_filebuf_commit
(
&
file
,
0666
));
cl_git_pass
(
git_filebuf_commit
(
&
file
));
cl_assert
(
file
.
buffer
==
NULL
);
cl_must_pass
(
p_unlink
(
test
));
...
...
@@ -110,12 +110,12 @@ void test_core_filebuf__umask(void)
cl_assert
(
file
.
buffer
==
NULL
);
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
0
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
test
,
0
,
0666
));
cl_assert
(
file
.
buffer
!=
NULL
);
cl_git_pass
(
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
"libgit2 rocks"
));
cl_assert
(
file
.
buffer
!=
NULL
);
cl_git_pass
(
git_filebuf_commit
(
&
file
,
0666
));
cl_git_pass
(
git_filebuf_commit
(
&
file
));
cl_assert
(
file
.
buffer
==
NULL
);
cl_must_pass
(
p_stat
(
"test"
,
&
statbuf
));
...
...
tests-clar/index/tests.c
View file @
1d3a8aeb
...
...
@@ -224,9 +224,9 @@ void test_index_tests__add(void)
/* Create a new file in the working directory */
cl_git_pass
(
git_futils_mkpath2file
(
"myrepo/test.txt"
,
0777
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
"myrepo/test.txt"
,
0
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
"myrepo/test.txt"
,
0
,
0666
));
cl_git_pass
(
git_filebuf_write
(
&
file
,
"hey there
\n
"
,
10
));
cl_git_pass
(
git_filebuf_commit
(
&
file
,
0666
));
cl_git_pass
(
git_filebuf_commit
(
&
file
));
/* Store the expected hash of the file/blob
* This has been generated by executing the following
...
...
@@ -474,7 +474,7 @@ void test_index_tests__elocked(void)
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
/* Lock the index file so we fail to lock it */
cl_git_pass
(
git_filebuf_open
(
&
file
,
index
->
index_file_path
,
0
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
index
->
index_file_path
,
0
,
0666
));
error
=
git_index_write
(
index
);
cl_assert_equal_i
(
GIT_ELOCKED
,
error
);
...
...
tests-clar/odb/alternates.c
View file @
1d3a8aeb
...
...
@@ -32,9 +32,9 @@ static void init_linked_repo(const char *path, const char *alternate)
cl_git_pass
(
git_futils_mkdir
(
filepath
.
ptr
,
NULL
,
0755
,
GIT_MKDIR_PATH
));
cl_git_pass
(
git_buf_joinpath
(
&
filepath
,
filepath
.
ptr
,
"alternates"
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
git_buf_cstr
(
&
filepath
),
0
));
cl_git_pass
(
git_filebuf_open
(
&
file
,
git_buf_cstr
(
&
filepath
),
0
,
0666
));
git_filebuf_printf
(
&
file
,
"%s
\n
"
,
git_buf_cstr
(
&
destpath
));
cl_git_pass
(
git_filebuf_commit
(
&
file
,
0644
));
cl_git_pass
(
git_filebuf_commit
(
&
file
));
git_repository_free
(
repo
);
}
...
...
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