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
4d384d6b
Commit
4d384d6b
authored
May 02, 2016
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3759 from libgit2/cmn/faster-header
odb: avoid inflating the full delta to read the header
parents
d24425fa
a97b769a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
6 deletions
+48
-6
src/delta-apply.c
+31
-0
src/delta-apply.h
+12
-0
src/pack.c
+5
-6
No files found.
src/delta-apply.c
View file @
4d384d6b
...
@@ -49,6 +49,37 @@ int git__delta_read_header(
...
@@ -49,6 +49,37 @@ int git__delta_read_header(
return
0
;
return
0
;
}
}
#define DELTA_HEADER_BUFFER_LEN 16
int
git__delta_read_header_fromstream
(
size_t
*
base_sz
,
size_t
*
res_sz
,
git_packfile_stream
*
stream
)
{
static
const
size_t
buffer_len
=
DELTA_HEADER_BUFFER_LEN
;
unsigned
char
buffer
[
DELTA_HEADER_BUFFER_LEN
];
const
unsigned
char
*
delta
,
*
delta_end
;
size_t
len
;
ssize_t
read
;
len
=
read
=
0
;
while
(
len
<
buffer_len
)
{
read
=
git_packfile_stream_read
(
stream
,
&
buffer
[
len
],
buffer_len
-
len
);
if
(
read
==
0
)
break
;
if
(
read
==
GIT_EBUFS
)
continue
;
len
+=
read
;
}
delta
=
buffer
;
delta_end
=
delta
+
len
;
if
((
hdr_sz
(
base_sz
,
&
delta
,
delta_end
)
<
0
)
||
(
hdr_sz
(
res_sz
,
&
delta
,
delta_end
)
<
0
))
return
-
1
;
return
0
;
}
int
git__delta_apply
(
int
git__delta_apply
(
git_rawobj
*
out
,
git_rawobj
*
out
,
const
unsigned
char
*
base
,
const
unsigned
char
*
base
,
...
...
src/delta-apply.h
View file @
4d384d6b
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#define INCLUDE_delta_apply_h__
#define INCLUDE_delta_apply_h__
#include "odb.h"
#include "odb.h"
#include "pack.h"
/**
/**
* Apply a git binary delta to recover the original content.
* Apply a git binary delta to recover the original content.
...
@@ -47,4 +48,15 @@ extern int git__delta_read_header(
...
@@ -47,4 +48,15 @@ extern int git__delta_read_header(
size_t
*
base_sz
,
size_t
*
base_sz
,
size_t
*
res_sz
);
size_t
*
res_sz
);
/**
* Read the header of a git binary delta
*
* This variant reads just enough from the packfile stream to read the
* delta header.
*/
extern
int
git__delta_read_header_fromstream
(
size_t
*
base_sz
,
size_t
*
res_sz
,
git_packfile_stream
*
stream
);
#endif
#endif
src/pack.c
View file @
4d384d6b
...
@@ -499,15 +499,14 @@ int git_packfile_resolve_header(
...
@@ -499,15 +499,14 @@ int git_packfile_resolve_header(
if
(
type
==
GIT_OBJ_OFS_DELTA
||
type
==
GIT_OBJ_REF_DELTA
)
{
if
(
type
==
GIT_OBJ_OFS_DELTA
||
type
==
GIT_OBJ_REF_DELTA
)
{
size_t
base_size
;
size_t
base_size
;
git_rawobj
delta
;
git_packfile_stream
stream
;
base_offset
=
get_delta_base
(
p
,
&
w_curs
,
&
curpos
,
type
,
offset
);
base_offset
=
get_delta_base
(
p
,
&
w_curs
,
&
curpos
,
type
,
offset
);
git_mwindow_close
(
&
w_curs
);
git_mwindow_close
(
&
w_curs
);
error
=
packfile_unpack_compressed
(
&
delta
,
p
,
&
w_curs
,
&
curpos
,
size
,
type
);
if
((
error
=
git_packfile_stream_open
(
&
stream
,
p
,
curpos
))
<
0
)
git_mwindow_close
(
&
w_curs
);
if
(
error
<
0
)
return
error
;
return
error
;
error
=
git__delta_read_header
(
delta
.
data
,
delta
.
len
,
&
base_size
,
size_p
);
error
=
git__delta_read_header
_fromstream
(
&
base_size
,
size_p
,
&
stream
);
git_
_free
(
delta
.
data
);
git_
packfile_stream_free
(
&
stream
);
if
(
error
<
0
)
if
(
error
<
0
)
return
error
;
return
error
;
}
else
}
else
...
...
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