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
ef4ef36e
Commit
ef4ef36e
authored
Jan 23, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1275 from ethomson/examples_windows
update examples to work on windows
parents
0d52cb4a
c27e2112
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
9 deletions
+36
-9
CMakeLists.txt
+5
-1
examples/network/clone.c
+5
-3
examples/network/fetch.c
+12
-3
examples/network/index-pack.c
+14
-2
No files found.
CMakeLists.txt
View file @
ef4ef36e
...
...
@@ -288,7 +288,11 @@ ENDIF ()
IF (BUILD_EXAMPLES)
FILE(GLOB_RECURSE EXAMPLE_SRC examples/network/*.c)
ADD_EXECUTABLE(cgit2
${
EXAMPLE_SRC
}
)
TARGET_LINK_LIBRARIES(cgit2 git2 pthread)
IF(WIN32)
TARGET_LINK_LIBRARIES(cgit2 git2)
ELSE()
TARGET_LINK_LIBRARIES(cgit2 git2 pthread)
ENDIF()
ADD_EXECUTABLE(git-diff examples/diff.c)
TARGET_LINK_LIBRARIES(git-diff git2)
...
...
examples/network/clone.c
View file @
ef4ef36e
...
...
@@ -4,8 +4,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#ifndef _WIN32
# include <pthread.h>
# include <unistd.h>
#endif
/* Shamelessly borrowed from http://stackoverflow.com/questions/3417837/ */
#ifdef UNUSED
...
...
@@ -94,7 +96,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
}
// Set up options
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
_CREATE
;
checkout_opts
.
progress_cb
=
checkout_progress
;
checkout_opts
.
progress_payload
=
&
pd
;
clone_opts
.
checkout_opts
=
checkout_opts
;
...
...
examples/network/fetch.c
View file @
ef4ef36e
...
...
@@ -3,8 +3,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#ifndef _WIN32
# include <pthread.h>
# include <unistd.h>
#endif
struct
dl_data
{
git_remote
*
remote
;
...
...
@@ -68,9 +70,11 @@ int fetch(git_repository *repo, int argc, char **argv)
{
git_remote
*
remote
=
NULL
;
const
git_transfer_progress
*
stats
;
pthread_t
worker
;
struct
dl_data
data
;
git_remote_callbacks
callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
#ifndef _WIN32
pthread_t
worker
;
#endif
argc
=
argc
;
// Figure out whether it's a named remote or a URL
...
...
@@ -92,6 +96,9 @@ int fetch(git_repository *repo, int argc, char **argv)
stats
=
git_remote_stats
(
remote
);
#ifdef _WIN32
download
(
&
data
);
#else
pthread_create
(
&
worker
,
NULL
,
download
,
&
data
);
// Loop while the worker thread is still running. Here we show processed
...
...
@@ -111,6 +118,8 @@ int fetch(git_repository *repo, int argc, char **argv)
goto
on_error
;
pthread_join
(
worker
,
NULL
);
#endif
printf
(
"
\r
Received %d/%d objects in %zu bytes
\n
"
,
stats
->
indexed_objects
,
stats
->
total_objects
,
stats
->
received_bytes
);
...
...
examples/network/index-pack.c
View file @
ef4ef36e
...
...
@@ -5,7 +5,18 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef _WIN32
# include <io.h>
# include <Windows.h>
# define open _open
# define read _read
# define close _close
#define ssize_t unsigned int
#else
# include <unistd.h>
#endif
#include "common.h"
// This could be run in the main loop whilst the application waits for
...
...
@@ -22,8 +33,9 @@ int index_pack(git_repository *repo, int argc, char **argv)
{
git_indexer_stream
*
idx
;
git_transfer_progress
stats
=
{
0
,
0
};
int
error
,
fd
;
int
error
;
char
hash
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
int
fd
;
ssize_t
read_bytes
;
char
buf
[
512
];
...
...
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