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
84595a30
Commit
84595a30
authored
Jul 30, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add clone to the network example.
parent
f1587b97
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
0 deletions
+72
-0
examples/network/Makefile
+1
-0
examples/network/clone.c
+69
-0
examples/network/common.h
+1
-0
examples/network/git2.c
+1
-0
No files found.
examples/network/Makefile
View file @
84595a30
...
...
@@ -8,6 +8,7 @@ OBJECTS = \
git2.o
\
ls-remote.o
\
fetch.o
\
clone.o
\
index-pack.o
all
:
$(OBJECTS)
...
...
examples/network/clone.c
0 → 100644
View file @
84595a30
#include "common.h"
#include <git2.h>
#include <git2/clone.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
struct
dl_data
{
git_indexer_stats
fetch_stats
;
git_indexer_stats
checkout_stats
;
git_checkout_opts
opts
;
int
ret
;
int
finished
;
const
char
*
url
;
const
char
*
path
;
};
static
void
*
clone_thread
(
void
*
ptr
)
{
struct
dl_data
*
data
=
(
struct
dl_data
*
)
ptr
;
git_repository
*
repo
=
NULL
;
// Kick off the clone
data
->
ret
=
git_clone
(
&
repo
,
data
->
url
,
data
->
path
,
&
data
->
fetch_stats
,
&
data
->
checkout_stats
,
&
data
->
opts
);
if
(
repo
)
git_repository_free
(
repo
);
data
->
finished
=
1
;
pthread_exit
(
&
data
->
ret
);
}
int
clone
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
{
struct
dl_data
data
=
{
0
};
pthread_t
worker
;
// Validate args
printf
(
"argc %d
\n
"
);
if
(
argc
<
3
)
{
printf
(
"USAGE: %s <url> <path>
\n
"
,
argv
[
0
]);
return
-
1
;
}
// Data for background thread
data
.
url
=
argv
[
1
];
data
.
path
=
argv
[
2
];
data
.
opts
.
disable_filters
=
1
;
printf
(
"Cloning '%s' to '%s'
\n
"
,
data
.
url
,
data
.
path
);
// Create the worker thread
pthread_create
(
&
worker
,
NULL
,
clone_thread
,
&
data
);
// Watch for progress information
do
{
usleep
(
10000
);
printf
(
"Fetch %d/%d – Checkout %d/%d
\n
"
,
data
.
fetch_stats
.
processed
,
data
.
fetch_stats
.
total
,
data
.
checkout_stats
.
processed
,
data
.
checkout_stats
.
total
);
}
while
(
!
data
.
finished
);
printf
(
"Fetch %d/%d – Checkout %d/%d
\n
"
,
data
.
fetch_stats
.
processed
,
data
.
fetch_stats
.
total
,
data
.
checkout_stats
.
processed
,
data
.
checkout_stats
.
total
);
return
data
.
ret
;
}
examples/network/common.h
View file @
84595a30
...
...
@@ -10,5 +10,6 @@ int parse_pkt_line(git_repository *repo, int argc, char **argv);
int
show_remote
(
git_repository
*
repo
,
int
argc
,
char
**
argv
);
int
fetch
(
git_repository
*
repo
,
int
argc
,
char
**
argv
);
int
index_pack
(
git_repository
*
repo
,
int
argc
,
char
**
argv
);
int
clone
(
git_repository
*
repo
,
int
argc
,
char
**
argv
);
#endif
/* __COMMON_H__ */
examples/network/git2.c
View file @
84595a30
...
...
@@ -12,6 +12,7 @@ struct {
}
commands
[]
=
{
{
"ls-remote"
,
ls_remote
},
{
"fetch"
,
fetch
},
{
"clone"
,
clone
},
{
"index-pack"
,
index_pack
},
{
NULL
,
NULL
}
};
...
...
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