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
c6f26b48
Commit
c6f26b48
authored
Dec 13, 2013
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor zlib for easier deflate streaming
parent
be29dd82
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
65 deletions
+109
-65
src/compress.c
+0
-53
src/indexer.c
+2
-4
src/pack-objects.c
+3
-3
src/zstream.c
+90
-0
src/zstream.h
+14
-5
No files found.
src/compress.c
deleted
100644 → 0
View file @
be29dd82
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "compress.h"
#include <zlib.h>
#define BUFFER_SIZE (1024 * 1024)
int
git__compress
(
git_buf
*
buf
,
const
void
*
buff
,
size_t
len
)
{
z_stream
zs
;
char
*
zb
;
size_t
have
;
memset
(
&
zs
,
0
,
sizeof
(
zs
));
if
(
deflateInit
(
&
zs
,
Z_DEFAULT_COMPRESSION
)
!=
Z_OK
)
return
-
1
;
zb
=
git__malloc
(
BUFFER_SIZE
);
GITERR_CHECK_ALLOC
(
zb
);
zs
.
next_in
=
(
void
*
)
buff
;
zs
.
avail_in
=
(
uInt
)
len
;
do
{
zs
.
next_out
=
(
unsigned
char
*
)
zb
;
zs
.
avail_out
=
BUFFER_SIZE
;
if
(
deflate
(
&
zs
,
Z_FINISH
)
==
Z_STREAM_ERROR
)
{
git__free
(
zb
);
return
-
1
;
}
have
=
BUFFER_SIZE
-
(
size_t
)
zs
.
avail_out
;
if
(
git_buf_put
(
buf
,
zb
,
have
)
<
0
)
{
git__free
(
zb
);
return
-
1
;
}
}
while
(
zs
.
avail_out
==
0
);
assert
(
zs
.
avail_in
==
0
);
deflateEnd
(
&
zs
);
git__free
(
zb
);
return
0
;
}
src/indexer.c
View file @
c6f26b48
...
...
@@ -5,8 +5,6 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
#include <zlib.h>
#include "git2/indexer.h"
#include "git2/object.h"
...
...
@@ -18,7 +16,7 @@
#include "filebuf.h"
#include "oid.h"
#include "oidmap.h"
#include "
compress
.h"
#include "
zstream
.h"
#define UINT31_MAX (0x7FFFFFFF)
...
...
@@ -662,7 +660,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
idx
->
pack
->
mwf
.
size
+=
hdr_len
;
entry
->
crc
=
crc32
(
entry
->
crc
,
hdr
,
hdr_len
);
if
((
error
=
git_
_compress
(
&
buf
,
data
,
len
))
<
0
)
if
((
error
=
git_
zstream_deflatebuf
(
&
buf
,
data
,
len
))
<
0
)
goto
cleanup
;
/* And then the compressed object */
...
...
src/pack-objects.c
View file @
c6f26b48
...
...
@@ -7,7 +7,7 @@
#include "pack-objects.h"
#include "
compress
.h"
#include "
zstream
.h"
#include "delta.h"
#include "iterator.h"
#include "netops.h"
...
...
@@ -319,7 +319,7 @@ static int write_object(git_buf *buf, git_packbuilder *pb, git_pobject *po)
/* Write data */
if
(
po
->
z_delta_size
)
size
=
po
->
z_delta_size
;
else
if
(
git_
_compress
(
&
zbuf
,
data
,
size
)
<
0
)
else
if
(
git_
zstream_deflatebuf
(
&
zbuf
,
data
,
size
)
<
0
)
goto
on_error
;
else
{
if
(
po
->
delta
)
...
...
@@ -931,7 +931,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
* between writes at that moment.
*/
if
(
po
->
delta_data
)
{
if
(
git_
_compress
(
&
zbuf
,
po
->
delta_data
,
po
->
delta_size
)
<
0
)
if
(
git_
zstream_deflatebuf
(
&
zbuf
,
po
->
delta_data
,
po
->
delta_size
)
<
0
)
goto
on_error
;
git__free
(
po
->
delta_data
);
...
...
src/zstream.c
0 → 100644
View file @
c6f26b48
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include <zlib.h>
#include "zstream.h"
#include "buffer.h"
#define BUFFER_SIZE (1024 * 1024)
static
int
zstream_seterr
(
int
zerr
,
git_zstream
*
zstream
)
{
if
(
zerr
==
Z_MEM_ERROR
)
giterr_set_oom
();
else
if
(
zstream
->
msg
)
giterr_set
(
GITERR_ZLIB
,
zstream
->
msg
);
else
giterr_set
(
GITERR_ZLIB
,
"Unknown compression error"
);
return
-
1
;
}
int
git_zstream_init
(
git_zstream
*
zstream
)
{
int
zerr
;
if
((
zerr
=
deflateInit
(
zstream
,
Z_DEFAULT_COMPRESSION
))
!=
Z_OK
)
return
zstream_seterr
(
zerr
,
zstream
);
return
0
;
}
ssize_t
git_zstream_deflate
(
void
*
out
,
size_t
out_len
,
git_zstream
*
zstream
,
const
void
*
in
,
size_t
in_len
)
{
int
zerr
;
if
((
ssize_t
)
out_len
<
0
)
out_len
=
INT_MAX
;
zstream
->
next_in
=
(
Bytef
*
)
in
;
zstream
->
avail_in
=
in_len
;
zstream
->
next_out
=
out
;
zstream
->
avail_out
=
out_len
;
if
((
zerr
=
deflate
(
zstream
,
Z_FINISH
))
==
Z_STREAM_ERROR
)
return
zstream_seterr
(
zerr
,
zstream
);
return
(
out_len
-
zstream
->
avail_out
);
}
void
git_zstream_free
(
git_zstream
*
zstream
)
{
deflateEnd
(
zstream
);
}
int
git_zstream_deflatebuf
(
git_buf
*
out
,
const
void
*
in
,
size_t
in_len
)
{
git_zstream
zstream
=
GIT_ZSTREAM_INIT
;
size_t
out_len
;
ssize_t
written
;
int
error
=
0
;
if
((
error
=
git_zstream_init
(
&
zstream
))
<
0
)
goto
done
;
do
{
if
(
out
->
asize
-
out
->
size
<
BUFFER_SIZE
)
git_buf_grow
(
out
,
out
->
asize
+
BUFFER_SIZE
);
out_len
=
out
->
asize
-
out
->
size
;
if
((
written
=
git_zstream_deflate
(
out
->
ptr
+
out
->
size
,
out_len
,
&
zstream
,
in
,
in_len
))
<=
0
)
break
;
in
=
(
char
*
)
in
+
written
;
in_len
-=
written
;
out
->
size
+=
written
;
}
while
(
written
>
0
);
if
(
written
<
0
)
error
=
written
;
done:
git_zstream_free
(
&
zstream
);
return
error
;
}
src/
compress
.h
→
src/
zstream
.h
View file @
c6f26b48
...
...
@@ -4,13 +4,22 @@
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_
compress
_h__
#define INCLUDE_
compress
_h__
#ifndef INCLUDE_
zstream
_h__
#define INCLUDE_
zstream
_h__
#include
"common.h"
#include
<zlib.h>
#include "common.h"
#include "buffer.h"
int
git__compress
(
git_buf
*
buf
,
const
void
*
buff
,
size_t
len
);
#define git_zstream z_stream
#define GIT_ZSTREAM_INIT {0}
int
git_zstream_init
(
git_zstream
*
zstream
);
ssize_t
git_zstream_deflate
(
void
*
out
,
size_t
out_len
,
git_zstream
*
zstream
,
const
void
*
in
,
size_t
in_len
);
void
git_zstream_free
(
git_zstream
*
zstream
);
int
git_zstream_deflatebuf
(
git_buf
*
out
,
const
void
*
in
,
size_t
in_len
);
#endif
/* INCLUDE_
compress
_h__ */
#endif
/* INCLUDE_
zstream
_h__ */
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