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
048c5ea7
Commit
048c5ea7
authored
Jan 21, 2017
by
Edward Thomson
Committed by
GitHub
Jan 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4053 from chescock/extend-packfile-by-pages
Extend packfile in increments of page_size.
parents
8d3b39a6
c7a1535f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletions
+24
-1
src/indexer.c
+24
-1
No files found.
src/indexer.c
View file @
048c5ea7
...
...
@@ -483,13 +483,29 @@ static int write_at(git_indexer *idx, const void *data, git_off_t offset, size_t
static
int
append_to_pack
(
git_indexer
*
idx
,
const
void
*
data
,
size_t
size
)
{
git_off_t
new_size
;
size_t
mmap_alignment
;
size_t
page_offset
;
git_off_t
page_start
;
git_off_t
current_size
=
idx
->
pack
->
mwf
.
size
;
int
fd
=
idx
->
pack
->
mwf
.
fd
;
int
error
;
if
(
!
size
)
return
0
;
if
(
p_lseek
(
fd
,
current_size
+
size
-
1
,
SEEK_SET
)
<
0
||
if
((
error
=
git__mmap_alignment
(
&
mmap_alignment
))
<
0
)
return
error
;
/* Write a single byte to force the file system to allocate space now or
* report an error, since we can't report errors when writing using mmap.
* Round the size up to the nearest page so that we only need to perform file
* I/O when we add a page, instead of whenever we write even a single byte. */
new_size
=
current_size
+
size
;
page_offset
=
new_size
%
mmap_alignment
;
page_start
=
new_size
-
page_offset
;
if
(
p_lseek
(
fd
,
page_start
+
mmap_alignment
-
1
,
SEEK_SET
)
<
0
||
p_write
(
idx
->
pack
->
mwf
.
fd
,
data
,
1
)
<
0
)
{
giterr_set
(
GITERR_OS
,
"cannot extend packfile '%s'"
,
idx
->
pack
->
pack_name
);
return
-
1
;
...
...
@@ -1047,6 +1063,13 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
goto
on_error
;
git_mwindow_free_all
(
&
idx
->
pack
->
mwf
);
/* Truncate file to undo rounding up to next page_size in append_to_pack */
if
(
p_ftruncate
(
idx
->
pack
->
mwf
.
fd
,
idx
->
pack
->
mwf
.
size
)
<
0
)
{
giterr_set
(
GITERR_OS
,
"failed to truncate pack file '%s'"
,
idx
->
pack
->
pack_name
);
return
-
1
;
}
/* We need to close the descriptor here so Windows doesn't choke on commit_at */
if
(
p_close
(
idx
->
pack
->
mwf
.
fd
)
<
0
)
{
giterr_set
(
GITERR_OS
,
"failed to close packfile"
);
...
...
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