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
ae789622
Commit
ae789622
authored
Jul 25, 2012
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: fix warnings in network/
parent
ad4b5beb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
46 deletions
+24
-46
examples/network/fetch.c
+5
-4
examples/network/git2.c
+3
-2
examples/network/index-pack.c
+10
-37
examples/network/ls-remote.c
+6
-3
No files found.
examples/network/fetch.c
View file @
ae789622
...
@@ -40,9 +40,8 @@ exit:
...
@@ -40,9 +40,8 @@ exit:
pthread_exit
(
&
data
->
ret
);
pthread_exit
(
&
data
->
ret
);
}
}
int
update_cb
(
const
char
*
refname
,
const
git_oid
*
a
,
const
git_oid
*
b
,
void
*
data
)
static
int
update_cb
(
const
char
*
refname
,
const
git_oid
*
a
,
const
git_oid
*
b
,
void
*
data
)
{
{
const
char
*
action
;
char
a_str
[
GIT_OID_HEXSZ
+
1
],
b_str
[
GIT_OID_HEXSZ
+
1
];
char
a_str
[
GIT_OID_HEXSZ
+
1
],
b_str
[
GIT_OID_HEXSZ
+
1
];
git_oid_fmt
(
b_str
,
b
);
git_oid_fmt
(
b_str
,
b
);
...
@@ -68,6 +67,7 @@ int fetch(git_repository *repo, int argc, char **argv)
...
@@ -68,6 +67,7 @@ int fetch(git_repository *repo, int argc, char **argv)
struct
dl_data
data
;
struct
dl_data
data
;
git_remote_callbacks
callbacks
;
git_remote_callbacks
callbacks
;
argc
=
argc
;
// Figure out whether it's a named remote or a URL
// Figure out whether it's a named remote or a URL
printf
(
"Fetching %s
\n
"
,
argv
[
1
]);
printf
(
"Fetching %s
\n
"
,
argv
[
1
]);
if
(
git_remote_load
(
&
remote
,
repo
,
argv
[
1
])
<
0
)
{
if
(
git_remote_load
(
&
remote
,
repo
,
argv
[
1
])
<
0
)
{
...
@@ -96,13 +96,14 @@ int fetch(git_repository *repo, int argc, char **argv)
...
@@ -96,13 +96,14 @@ int fetch(git_repository *repo, int argc, char **argv)
// the download rate.
// the download rate.
do
{
do
{
usleep
(
10000
);
usleep
(
10000
);
printf
(
"
\r
Received %d/%d objects in %
d
bytes"
,
stats
.
processed
,
stats
.
total
,
bytes
);
printf
(
"
\r
Received %d/%d objects in %
zu
bytes"
,
stats
.
processed
,
stats
.
total
,
bytes
);
}
while
(
!
data
.
finished
);
}
while
(
!
data
.
finished
);
if
(
data
.
ret
<
0
)
if
(
data
.
ret
<
0
)
goto
on_error
;
goto
on_error
;
printf
(
"
\r
Received %d/%d objects in %d bytes
\n
"
,
stats
.
processed
,
stats
.
total
,
bytes
);
pthread_join
(
worker
,
NULL
);
printf
(
"
\r
Received %d/%d objects in %zu bytes
\n
"
,
stats
.
processed
,
stats
.
total
,
bytes
);
// Disconnect the underlying connection to prevent from idling.
// Disconnect the underlying connection to prevent from idling.
git_remote_disconnect
(
remote
);
git_remote_disconnect
(
remote
);
...
...
examples/network/git2.c
View file @
ae789622
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "common.h"
...
@@ -16,7 +17,7 @@ struct {
...
@@ -16,7 +17,7 @@ struct {
{
NULL
,
NULL
}
{
NULL
,
NULL
}
};
};
int
run_command
(
git_cb
fn
,
int
argc
,
char
**
argv
)
static
int
run_command
(
git_cb
fn
,
int
argc
,
char
**
argv
)
{
{
int
error
;
int
error
;
git_repository
*
repo
;
git_repository
*
repo
;
...
@@ -45,7 +46,7 @@ int run_command(git_cb fn, int argc, char **argv)
...
@@ -45,7 +46,7 @@ int run_command(git_cb fn, int argc, char **argv)
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
i
,
error
;
int
i
;
if
(
argc
<
2
)
{
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"usage: %s <cmd> [repo]
\n
"
,
argv
[
0
]);
fprintf
(
stderr
,
"usage: %s <cmd> [repo]
\n
"
,
argv
[
0
]);
...
...
examples/network/index-pack.c
View file @
ae789622
...
@@ -2,13 +2,20 @@
...
@@ -2,13 +2,20 @@
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "common.h"
#include "common.h"
// This could be run in the main loop whilst the application waits for
// This could be run in the main loop whilst the application waits for
// the indexing to finish in a worker thread
// the indexing to finish in a worker thread
int
index_cb
(
const
git_indexer_stats
*
stats
,
void
*
data
)
static
int
index_cb
(
const
git_indexer_stats
*
stats
,
void
*
data
)
{
{
data
=
data
;
printf
(
"
\r
Processing %d of %d"
,
stats
->
processed
,
stats
->
total
);
printf
(
"
\r
Processing %d of %d"
,
stats
->
processed
,
stats
->
total
);
return
0
;
}
}
int
index_pack
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
int
index_pack
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
...
@@ -20,6 +27,7 @@ int index_pack(git_repository *repo, int argc, char **argv)
...
@@ -20,6 +27,7 @@ int index_pack(git_repository *repo, int argc, char **argv)
ssize_t
read_bytes
;
ssize_t
read_bytes
;
char
buf
[
512
];
char
buf
[
512
];
repo
=
repo
;
if
(
argc
<
2
)
{
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"I need a packfile
\n
"
);
fprintf
(
stderr
,
"I need a packfile
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
...
@@ -43,7 +51,7 @@ int index_pack(git_repository *repo, int argc, char **argv)
...
@@ -43,7 +51,7 @@ int index_pack(git_repository *repo, int argc, char **argv)
if
((
error
=
git_indexer_stream_add
(
idx
,
buf
,
read_bytes
,
&
stats
))
<
0
)
if
((
error
=
git_indexer_stream_add
(
idx
,
buf
,
read_bytes
,
&
stats
))
<
0
)
goto
cleanup
;
goto
cleanup
;
printf
(
"
\r
Indexing %d of %d"
,
stats
.
processed
,
stats
.
total
);
index_cb
(
&
stats
,
NULL
);
}
while
(
read_bytes
>
0
);
}
while
(
read_bytes
>
0
);
if
(
read_bytes
<
0
)
{
if
(
read_bytes
<
0
)
{
...
@@ -65,38 +73,3 @@ int index_pack(git_repository *repo, int argc, char **argv)
...
@@ -65,38 +73,3 @@ int index_pack(git_repository *repo, int argc, char **argv)
git_indexer_stream_free
(
idx
);
git_indexer_stream_free
(
idx
);
return
error
;
return
error
;
}
}
int
index_pack_old
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
{
git_indexer
*
indexer
;
git_indexer_stats
stats
;
int
error
;
char
hash
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"I need a packfile
\n
"
);
return
EXIT_FAILURE
;
}
// Create a new indexer
error
=
git_indexer_new
(
&
indexer
,
argv
[
1
]);
if
(
error
<
0
)
return
error
;
// Index the packfile. This function can take a very long time and
// should be run in a worker thread.
error
=
git_indexer_run
(
indexer
,
&
stats
);
if
(
error
<
0
)
return
error
;
// Write the information out to an index file
error
=
git_indexer_write
(
indexer
);
// Get the packfile's hash (which should become it's filename)
git_oid_fmt
(
hash
,
git_indexer_hash
(
indexer
));
puts
(
hash
);
git_indexer_free
(
indexer
);
return
0
;
}
examples/network/ls-remote.c
View file @
ae789622
...
@@ -7,12 +7,14 @@
...
@@ -7,12 +7,14 @@
static
int
show_ref__cb
(
git_remote_head
*
head
,
void
*
payload
)
static
int
show_ref__cb
(
git_remote_head
*
head
,
void
*
payload
)
{
{
char
oid
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
char
oid
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
payload
=
payload
;
git_oid_fmt
(
oid
,
&
head
->
oid
);
git_oid_fmt
(
oid
,
&
head
->
oid
);
printf
(
"%s
\t
%s
\n
"
,
oid
,
head
->
name
);
printf
(
"%s
\t
%s
\n
"
,
oid
,
head
->
name
);
return
0
;
return
0
;
}
}
int
use_unnamed
(
git_repository
*
repo
,
const
char
*
url
)
static
int
use_unnamed
(
git_repository
*
repo
,
const
char
*
url
)
{
{
git_remote
*
remote
=
NULL
;
git_remote
*
remote
=
NULL
;
int
error
;
int
error
;
...
@@ -37,7 +39,7 @@ cleanup:
...
@@ -37,7 +39,7 @@ cleanup:
return
error
;
return
error
;
}
}
int
use_remote
(
git_repository
*
repo
,
char
*
name
)
static
int
use_remote
(
git_repository
*
repo
,
char
*
name
)
{
{
git_remote
*
remote
=
NULL
;
git_remote
*
remote
=
NULL
;
int
error
;
int
error
;
...
@@ -63,8 +65,9 @@ cleanup:
...
@@ -63,8 +65,9 @@ cleanup:
int
ls_remote
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
int
ls_remote
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
{
{
int
error
,
i
;
int
error
;
argc
=
argc
;
/* If there's a ':' in the name, assume it's an URL */
/* If there's a ':' in the name, assume it's an URL */
if
(
strchr
(
argv
[
1
],
':'
)
!=
NULL
)
{
if
(
strchr
(
argv
[
1
],
':'
)
!=
NULL
)
{
error
=
use_unnamed
(
repo
,
argv
[
1
]);
error
=
use_unnamed
(
repo
,
argv
[
1
]);
...
...
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