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
255836dd
Commit
255836dd
authored
Sep 01, 2013
by
Krzysztof Adamski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding credentials callback to ls-remote and fetch too.
parent
d6d52348
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
33 deletions
+45
-33
examples/network/Makefile
+2
-1
examples/network/clone.c
+1
-32
examples/network/common.c
+34
-0
examples/network/common.h
+6
-0
examples/network/fetch.c
+1
-0
examples/network/ls-remote.c
+1
-0
No files found.
examples/network/Makefile
View file @
255836dd
...
@@ -11,7 +11,8 @@ OBJECTS = \
...
@@ -11,7 +11,8 @@ OBJECTS = \
ls-remote.o
\
ls-remote.o
\
fetch.o
\
fetch.o
\
clone.o
\
clone.o
\
index-pack.o
index-pack.o
\
common.o
all
:
$(OBJECTS)
all
:
$(OBJECTS)
$(CC)
$(CFLAGS)
$(LDFLAGS)
-o
git2
$(OBJECTS)
$(LIBRARIES)
$(CC)
$(CFLAGS)
$(LDFLAGS)
-o
git2
$(OBJECTS)
$(LIBRARIES)
...
...
examples/network/clone.c
View file @
255836dd
...
@@ -9,19 +9,6 @@
...
@@ -9,19 +9,6 @@
# include <unistd.h>
# include <unistd.h>
#endif
#endif
/* Shamelessly borrowed from http://stackoverflow.com/questions/3417837/
* with permission of the original author, Martin Pool.
* http://sourcefrog.net/weblog/software/languages/C/unused.html
*/
#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(__LCLINT__)
# define UNUSED(x)
/*@unused@*/
x
#else
# define UNUSED(x) x
#endif
typedef
struct
progress_data
{
typedef
struct
progress_data
{
git_transfer_progress
fetch_progress
;
git_transfer_progress
fetch_progress
;
size_t
completed_steps
;
size_t
completed_steps
;
...
@@ -63,24 +50,6 @@ static void checkout_progress(const char *path, size_t cur, size_t tot, void *pa
...
@@ -63,24 +50,6 @@ static void checkout_progress(const char *path, size_t cur, size_t tot, void *pa
print_progress
(
pd
);
print_progress
(
pd
);
}
}
static
int
cred_acquire
(
git_cred
**
out
,
const
char
*
UNUSED
(
url
),
const
char
*
UNUSED
(
username_from_url
),
unsigned
int
UNUSED
(
allowed_types
),
void
*
UNUSED
(
payload
))
{
char
username
[
128
]
=
{
0
};
char
password
[
128
]
=
{
0
};
printf
(
"Username: "
);
scanf
(
"%s"
,
username
);
/* Yup. Right there on your terminal. Careful where you copy/paste output. */
printf
(
"Password: "
);
scanf
(
"%s"
,
password
);
return
git_cred_userpass_plaintext_new
(
out
,
username
,
password
);
}
int
do_clone
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
int
do_clone
(
git_repository
*
repo
,
int
argc
,
char
**
argv
)
{
{
...
@@ -107,7 +76,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
...
@@ -107,7 +76,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
clone_opts
.
checkout_opts
=
checkout_opts
;
clone_opts
.
checkout_opts
=
checkout_opts
;
clone_opts
.
fetch_progress_cb
=
&
fetch_progress
;
clone_opts
.
fetch_progress_cb
=
&
fetch_progress
;
clone_opts
.
fetch_progress_payload
=
&
pd
;
clone_opts
.
fetch_progress_payload
=
&
pd
;
clone_opts
.
cred_acquire_cb
=
cred_acquire
;
clone_opts
.
cred_acquire_cb
=
cred_acquire
_cb
;
// Do the clone
// Do the clone
error
=
git_clone
(
&
cloned_repo
,
url
,
path
,
&
clone_opts
);
error
=
git_clone
(
&
cloned_repo
,
url
,
path
,
&
clone_opts
);
...
...
examples/network/common.c
0 → 100644
View file @
255836dd
#include "common.h"
#include <stdio.h>
/* Shamelessly borrowed from http://stackoverflow.com/questions/3417837/
* with permission of the original author, Martin Pool.
* http://sourcefrog.net/weblog/software/languages/C/unused.html
*/
#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(__LCLINT__)
# define UNUSED(x)
/*@unused@*/
x
#else
# define UNUSED(x) x
#endif
int
cred_acquire_cb
(
git_cred
**
out
,
const
char
*
UNUSED
(
url
),
const
char
*
UNUSED
(
username_from_url
),
unsigned
int
UNUSED
(
allowed_types
),
void
*
UNUSED
(
payload
))
{
char
username
[
128
]
=
{
0
};
char
password
[
128
]
=
{
0
};
printf
(
"Username: "
);
scanf
(
"%s"
,
username
);
/* Yup. Right there on your terminal. Careful where you copy/paste output. */
printf
(
"Password: "
);
scanf
(
"%s"
,
password
);
return
git_cred_userpass_plaintext_new
(
out
,
username
,
password
);
}
examples/network/common.h
View file @
255836dd
...
@@ -12,6 +12,12 @@ int fetch(git_repository *repo, int argc, char **argv);
...
@@ -12,6 +12,12 @@ int fetch(git_repository *repo, int argc, char **argv);
int
index_pack
(
git_repository
*
repo
,
int
argc
,
char
**
argv
);
int
index_pack
(
git_repository
*
repo
,
int
argc
,
char
**
argv
);
int
do_clone
(
git_repository
*
repo
,
int
argc
,
char
**
argv
);
int
do_clone
(
git_repository
*
repo
,
int
argc
,
char
**
argv
);
int
cred_acquire_cb
(
git_cred
**
out
,
const
char
*
url
,
const
char
*
username_from_url
,
unsigned
int
allowed_types
,
void
*
payload
);
#ifndef PRIuZ
#ifndef PRIuZ
/* Define the printf format specifer to use for size_t output */
/* Define the printf format specifer to use for size_t output */
#if defined(_MSC_VER) || defined(__MINGW32__)
#if defined(_MSC_VER) || defined(__MINGW32__)
...
...
examples/network/fetch.c
View file @
255836dd
...
@@ -92,6 +92,7 @@ int fetch(git_repository *repo, int argc, char **argv)
...
@@ -92,6 +92,7 @@ int fetch(git_repository *repo, int argc, char **argv)
callbacks
.
update_tips
=
&
update_cb
;
callbacks
.
update_tips
=
&
update_cb
;
callbacks
.
progress
=
&
progress_cb
;
callbacks
.
progress
=
&
progress_cb
;
git_remote_set_callbacks
(
remote
,
&
callbacks
);
git_remote_set_callbacks
(
remote
,
&
callbacks
);
git_remote_set_cred_acquire_cb
(
remote
,
&
cred_acquire_cb
,
NULL
);
// Set up the information for the background worker thread
// Set up the information for the background worker thread
data
.
remote
=
remote
;
data
.
remote
=
remote
;
...
...
examples/network/ls-remote.c
View file @
255836dd
...
@@ -27,6 +27,7 @@ static int use_remote(git_repository *repo, char *name)
...
@@ -27,6 +27,7 @@ static int use_remote(git_repository *repo, char *name)
goto
cleanup
;
goto
cleanup
;
}
}
git_remote_set_cred_acquire_cb
(
remote
,
&
cred_acquire_cb
,
NULL
);
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
);
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
);
if
(
error
<
0
)
if
(
error
<
0
)
...
...
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