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
907ebe85
Commit
907ebe85
authored
Apr 13, 2012
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: stream indexer example
parent
453ab98d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
examples/network/index-pack.c
+55
-0
No files found.
examples/network/index-pack.c
View file @
907ebe85
...
...
@@ -13,6 +13,61 @@ int index_cb(const git_indexer_stats *stats, void *data)
int
index_pack
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
{
git_indexer_stream
*
idx
;
git_indexer_stats
stats
=
{
0
,
0
};
int
error
,
fd
;
char
hash
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
ssize_t
read_bytes
;
char
buf
[
512
];
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"I need a packfile
\n
"
);
return
EXIT_FAILURE
;
}
if
(
git_indexer_stream_new
(
&
idx
,
".git"
)
<
0
)
{
puts
(
"bad idx"
);
return
-
1
;
}
if
((
fd
=
open
(
argv
[
1
],
0
))
<
0
)
{
perror
(
"open"
);
return
-
1
;
}
do
{
read_bytes
=
read
(
fd
,
buf
,
sizeof
(
buf
));
if
(
read_bytes
<
0
)
break
;
if
((
error
=
git_indexer_stream_add
(
idx
,
buf
,
read_bytes
,
&
stats
))
<
0
)
goto
cleanup
;
printf
(
"
\r
Indexing %d of %d"
,
stats
.
processed
,
stats
.
total
);
}
while
(
read_bytes
>
0
);
if
(
read_bytes
<
0
)
{
error
=
-
1
;
perror
(
"failed reading"
);
goto
cleanup
;
}
if
((
error
=
git_indexer_stream_finalize
(
idx
,
&
stats
))
<
0
)
goto
cleanup
;
printf
(
"
\r
Indexing %d of %d
\n
"
,
stats
.
processed
,
stats
.
total
);
git_oid_fmt
(
hash
,
git_indexer_stream_hash
(
idx
));
puts
(
hash
);
cleanup:
close
(
fd
);
git_indexer_stream_free
(
idx
);
return
error
;
}
int
index_pack_old
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
{
git_indexer
*
indexer
;
git_indexer_stats
stats
;
int
error
;
...
...
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