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
942a7698
Commit
942a7698
authored
Nov 05, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1034 from carlosmn/packbuilder-foreach
Let the user grab the packfile as it's being written
parents
1e99ce9a
b4b935d8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
2 deletions
+69
-2
include/git2/pack.h
+24
-0
src/pack-objects.c
+16
-0
tests-clar/pack/packbuilder.c
+29
-2
No files found.
include/git2/pack.h
View file @
942a7698
...
...
@@ -78,6 +78,30 @@ GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *
GIT_EXTERN
(
int
)
git_packbuilder_write
(
git_packbuilder
*
pb
,
const
char
*
file
);
/**
* Create the new pack and pass each object to the callback
*
* @param pb the packbuilder
* @param cb the callback to call with each packed object's buffer
* @param data the callback's data
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_packbuilder_foreach
(
git_packbuilder
*
pb
,
int
(
*
cb
)(
void
*
buf
,
size_t
size
,
void
*
data
),
void
*
data
);
/**
* Get the total number of objects the packbuilder will write out
*
* @param pb the packbuilder
*/
GIT_EXTERN
(
uint32_t
)
git_packbuilder_object_count
(
git_packbuilder
*
pb
);
/**
* Get the number of objects the packbuilder has already written out
*
* @param pb the packbuilder
*/
GIT_EXTERN
(
uint32_t
)
git_packbuilder_written
(
git_packbuilder
*
pb
);
/**
* Free the packbuilder and all associated data
*
* @param pb The packbuilder
...
...
src/pack-objects.c
View file @
942a7698
...
...
@@ -1237,6 +1237,12 @@ int git_packbuilder_send(git_packbuilder *pb, gitno_socket *s)
return
write_pack
(
pb
,
&
send_pack_file
,
s
);
}
int
git_packbuilder_foreach
(
git_packbuilder
*
pb
,
int
(
*
cb
)(
void
*
buf
,
size_t
size
,
void
*
payload
),
void
*
payload
)
{
PREPARE_PACK
;
return
write_pack
(
pb
,
cb
,
payload
);
}
int
git_packbuilder_write_buf
(
git_buf
*
buf
,
git_packbuilder
*
pb
)
{
PREPARE_PACK
;
...
...
@@ -1286,6 +1292,16 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
return
0
;
}
uint32_t
git_packbuilder_object_count
(
git_packbuilder
*
pb
)
{
return
pb
->
nr_objects
;
}
uint32_t
git_packbuilder_written
(
git_packbuilder
*
pb
)
{
return
pb
->
nr_written
;
}
void
git_packbuilder_free
(
git_packbuilder
*
pb
)
{
if
(
pb
==
NULL
)
...
...
tests-clar/pack/packbuilder.c
View file @
942a7698
...
...
@@ -28,12 +28,12 @@ void test_pack_packbuilder__cleanup(void)
git_packbuilder_free
(
_packbuilder
);
git_revwalk_free
(
_revwalker
);
git_indexer_free
(
_indexer
);
_indexer
=
NULL
;
git_repository_free
(
_repo
);
}
void
test_pack_packbuilder__create_pack
(
void
)
static
void
seed_packbuilder
(
void
)
{
git_transfer_progress
stats
;
git_oid
oid
,
*
o
;
unsigned
int
i
;
...
...
@@ -58,10 +58,37 @@ void test_pack_packbuilder__create_pack(void)
git_commit_tree_oid
((
git_commit
*
)
obj
)));
git_object_free
(
obj
);
}
}
void
test_pack_packbuilder__create_pack
(
void
)
{
git_transfer_progress
stats
;
seed_packbuilder
();
cl_git_pass
(
git_packbuilder_write
(
_packbuilder
,
"testpack.pack"
));
cl_git_pass
(
git_indexer_new
(
&
_indexer
,
"testpack.pack"
));
cl_git_pass
(
git_indexer_run
(
_indexer
,
&
stats
));
cl_git_pass
(
git_indexer_write
(
_indexer
));
}
static
git_transfer_progress
stats
;
static
int
foreach_cb
(
void
*
buf
,
size_t
len
,
void
*
payload
)
{
git_indexer_stream
*
idx
=
(
git_indexer_stream
*
)
payload
;
cl_git_pass
(
git_indexer_stream_add
(
idx
,
buf
,
len
,
&
stats
));
return
0
;
}
void
test_pack_packbuilder__foreach
(
void
)
{
git_indexer_stream
*
idx
;
seed_packbuilder
();
cl_git_pass
(
git_indexer_stream_new
(
&
idx
,
"."
,
NULL
,
NULL
));
cl_git_pass
(
git_packbuilder_foreach
(
_packbuilder
,
foreach_cb
,
idx
));
cl_git_pass
(
git_indexer_stream_finalize
(
idx
,
&
stats
));
git_indexer_stream_free
(
idx
);
}
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