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
55d354d8
Unverified
Commit
55d354d8
authored
Sep 07, 2018
by
Patrick Steinhardt
Committed by
GitHub
Sep 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4785 from tiennou/fix/cleanup-remote
remote: store the connection data in a private struct
parents
db17b31b
1c176883
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
18 deletions
+37
-18
src/push.c
+3
-2
src/push.h
+2
-1
src/remote.c
+23
-15
src/remote.h
+9
-0
No files found.
src/push.c
View file @
55d354d8
...
@@ -73,7 +73,8 @@ int git_push_set_options(git_push *push, const git_push_options *opts)
...
@@ -73,7 +73,8 @@ int git_push_set_options(git_push *push, const git_push_options *opts)
GITERR_CHECK_VERSION
(
opts
,
GIT_PUSH_OPTIONS_VERSION
,
"git_push_options"
);
GITERR_CHECK_VERSION
(
opts
,
GIT_PUSH_OPTIONS_VERSION
,
"git_push_options"
);
push
->
pb_parallelism
=
opts
->
pb_parallelism
;
push
->
pb_parallelism
=
opts
->
pb_parallelism
;
push
->
custom_headers
=
&
opts
->
custom_headers
;
push
->
connection
.
custom_headers
=
&
opts
->
custom_headers
;
push
->
connection
.
proxy
=
&
opts
->
proxy_opts
;
return
0
;
return
0
;
}
}
...
@@ -475,7 +476,7 @@ int git_push_finish(git_push *push, const git_remote_callbacks *callbacks)
...
@@ -475,7 +476,7 @@ int git_push_finish(git_push *push, const git_remote_callbacks *callbacks)
int
error
;
int
error
;
if
(
!
git_remote_connected
(
push
->
remote
)
&&
if
(
!
git_remote_connected
(
push
->
remote
)
&&
(
error
=
git_remote_
connect
(
push
->
remote
,
GIT_DIRECTION_PUSH
,
callbacks
,
NULL
,
push
->
custom_headers
))
<
0
)
(
error
=
git_remote_
_connect
(
push
->
remote
,
GIT_DIRECTION_PUSH
,
callbacks
,
&
push
->
connection
))
<
0
)
return
error
;
return
error
;
if
((
error
=
filter_refs
(
push
->
remote
))
<
0
||
if
((
error
=
filter_refs
(
push
->
remote
))
<
0
||
...
...
src/push.h
View file @
55d354d8
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include "git2.h"
#include "git2.h"
#include "refspec.h"
#include "refspec.h"
#include "remote.h"
typedef
struct
push_spec
{
typedef
struct
push_spec
{
struct
git_refspec
refspec
;
struct
git_refspec
refspec
;
...
@@ -40,7 +41,7 @@ struct git_push {
...
@@ -40,7 +41,7 @@ struct git_push {
/* options */
/* options */
unsigned
pb_parallelism
;
unsigned
pb_parallelism
;
const
git_strarray
*
custom_headers
;
git_remote_connection_opts
connection
;
};
};
/**
/**
...
...
src/remote.c
View file @
55d354d8
...
@@ -657,7 +657,7 @@ static int set_transport_custom_headers(git_transport *t, const git_strarray *cu
...
@@ -657,7 +657,7 @@ static int set_transport_custom_headers(git_transport *t, const git_strarray *cu
return
t
->
set_custom_headers
(
t
,
custom_headers
);
return
t
->
set_custom_headers
(
t
,
custom_headers
);
}
}
int
git_remote_
connect
(
git_remote
*
remote
,
git_direction
direction
,
const
git_remote_callbacks
*
callbacks
,
const
git_proxy_options
*
proxy
,
const
git_strarray
*
custom_headers
)
int
git_remote_
_connect
(
git_remote
*
remote
,
git_direction
direction
,
const
git_remote_callbacks
*
callbacks
,
const
git_remote_connection_opts
*
conn
)
{
{
git_transport
*
t
;
git_transport
*
t
;
const
char
*
url
;
const
char
*
url
;
...
@@ -676,8 +676,8 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re
...
@@ -676,8 +676,8 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re
payload
=
callbacks
->
payload
;
payload
=
callbacks
->
payload
;
}
}
if
(
proxy
)
if
(
conn
->
proxy
)
GITERR_CHECK_VERSION
(
proxy
,
GIT_PROXY_OPTIONS_VERSION
,
"git_proxy_options"
);
GITERR_CHECK_VERSION
(
conn
->
proxy
,
GIT_PROXY_OPTIONS_VERSION
,
"git_proxy_options"
);
t
=
remote
->
transport
;
t
=
remote
->
transport
;
...
@@ -701,11 +701,11 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re
...
@@ -701,11 +701,11 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re
if
(
!
t
&&
(
error
=
git_transport_new
(
&
t
,
remote
,
url
))
<
0
)
if
(
!
t
&&
(
error
=
git_transport_new
(
&
t
,
remote
,
url
))
<
0
)
return
error
;
return
error
;
if
((
error
=
set_transport_custom_headers
(
t
,
custom_headers
))
!=
0
)
if
((
error
=
set_transport_custom_headers
(
t
,
c
onn
->
c
ustom_headers
))
!=
0
)
goto
on_error
;
goto
on_error
;
if
((
error
=
set_transport_callbacks
(
t
,
callbacks
))
<
0
||
if
((
error
=
set_transport_callbacks
(
t
,
callbacks
))
<
0
||
(
error
=
t
->
connect
(
t
,
url
,
credentials
,
payload
,
proxy
,
direction
,
flags
))
!=
0
)
(
error
=
t
->
connect
(
t
,
url
,
credentials
,
payload
,
conn
->
proxy
,
direction
,
flags
))
!=
0
)
goto
on_error
;
goto
on_error
;
remote
->
transport
=
t
;
remote
->
transport
=
t
;
...
@@ -721,6 +721,16 @@ on_error:
...
@@ -721,6 +721,16 @@ on_error:
return
error
;
return
error
;
}
}
int
git_remote_connect
(
git_remote
*
remote
,
git_direction
direction
,
const
git_remote_callbacks
*
callbacks
,
const
git_proxy_options
*
proxy
,
const
git_strarray
*
custom_headers
)
{
git_remote_connection_opts
conn
;
conn
.
proxy
=
proxy
;
conn
.
custom_headers
=
custom_headers
;
return
git_remote__connect
(
remote
,
direction
,
callbacks
,
&
conn
);
}
int
git_remote_ls
(
const
git_remote_head
***
out
,
size_t
*
size
,
git_remote
*
remote
)
int
git_remote_ls
(
const
git_remote_head
***
out
,
size_t
*
size
,
git_remote
*
remote
)
{
{
assert
(
remote
);
assert
(
remote
);
...
@@ -949,21 +959,20 @@ int git_remote_fetch(
...
@@ -949,21 +959,20 @@ int git_remote_fetch(
bool
prune
=
false
;
bool
prune
=
false
;
git_buf
reflog_msg_buf
=
GIT_BUF_INIT
;
git_buf
reflog_msg_buf
=
GIT_BUF_INIT
;
const
git_remote_callbacks
*
cbs
=
NULL
;
const
git_remote_callbacks
*
cbs
=
NULL
;
const
git_strarray
*
custom_headers
=
NULL
;
git_remote_connection_opts
conn
=
GIT_REMOTE_CONNECTION_OPTIONS_INIT
;
const
git_proxy_options
*
proxy
=
NULL
;
if
(
opts
)
{
if
(
opts
)
{
GITERR_CHECK_VERSION
(
&
opts
->
callbacks
,
GIT_REMOTE_CALLBACKS_VERSION
,
"git_remote_callbacks"
);
GITERR_CHECK_VERSION
(
&
opts
->
callbacks
,
GIT_REMOTE_CALLBACKS_VERSION
,
"git_remote_callbacks"
);
cbs
=
&
opts
->
callbacks
;
cbs
=
&
opts
->
callbacks
;
custom_headers
=
&
opts
->
custom_headers
;
c
onn
.
c
ustom_headers
=
&
opts
->
custom_headers
;
update_fetchhead
=
opts
->
update_fetchhead
;
update_fetchhead
=
opts
->
update_fetchhead
;
tagopt
=
opts
->
download_tags
;
tagopt
=
opts
->
download_tags
;
GITERR_CHECK_VERSION
(
&
opts
->
proxy_opts
,
GIT_PROXY_OPTIONS_VERSION
,
"git_proxy_options"
);
GITERR_CHECK_VERSION
(
&
opts
->
proxy_opts
,
GIT_PROXY_OPTIONS_VERSION
,
"git_proxy_options"
);
proxy
=
&
opts
->
proxy_opts
;
conn
.
proxy
=
&
opts
->
proxy_opts
;
}
}
/* Connect and download everything */
/* Connect and download everything */
if
((
error
=
git_remote_
connect
(
remote
,
GIT_DIRECTION_FETCH
,
cbs
,
proxy
,
custom_headers
))
!=
0
)
if
((
error
=
git_remote_
_connect
(
remote
,
GIT_DIRECTION_FETCH
,
cbs
,
&
conn
))
!=
0
)
return
error
;
return
error
;
error
=
git_remote_download
(
remote
,
refspecs
,
opts
);
error
=
git_remote_download
(
remote
,
refspecs
,
opts
);
...
@@ -2373,8 +2382,7 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
...
@@ -2373,8 +2382,7 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
git_push
*
push
;
git_push
*
push
;
git_refspec
*
spec
;
git_refspec
*
spec
;
const
git_remote_callbacks
*
cbs
=
NULL
;
const
git_remote_callbacks
*
cbs
=
NULL
;
const
git_strarray
*
custom_headers
=
NULL
;
git_remote_connection_opts
conn
=
GIT_REMOTE_CONNECTION_OPTIONS_INIT
;
const
git_proxy_options
*
proxy
=
NULL
;
assert
(
remote
);
assert
(
remote
);
...
@@ -2385,12 +2393,12 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
...
@@ -2385,12 +2393,12 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
if
(
opts
)
{
if
(
opts
)
{
cbs
=
&
opts
->
callbacks
;
cbs
=
&
opts
->
callbacks
;
custom_headers
=
&
opts
->
custom_headers
;
c
onn
.
c
ustom_headers
=
&
opts
->
custom_headers
;
proxy
=
&
opts
->
proxy_opts
;
conn
.
proxy
=
&
opts
->
proxy_opts
;
}
}
if
(
!
git_remote_connected
(
remote
)
&&
if
(
!
git_remote_connected
(
remote
)
&&
(
error
=
git_remote_
connect
(
remote
,
GIT_DIRECTION_PUSH
,
cbs
,
proxy
,
custom_headers
))
<
0
)
(
error
=
git_remote_
_connect
(
remote
,
GIT_DIRECTION_PUSH
,
cbs
,
&
conn
))
<
0
)
goto
cleanup
;
goto
cleanup
;
free_refspecs
(
&
remote
->
active_refspecs
);
free_refspecs
(
&
remote
->
active_refspecs
);
...
...
src/remote.h
View file @
55d354d8
...
@@ -36,6 +36,15 @@ struct git_remote {
...
@@ -36,6 +36,15 @@ struct git_remote {
int
passed_refspecs
;
int
passed_refspecs
;
};
};
typedef
struct
git_remote_connection_opts
{
const
git_strarray
*
custom_headers
;
const
git_proxy_options
*
proxy
;
}
git_remote_connection_opts
;
#define GIT_REMOTE_CONNECTION_OPTIONS_INIT { NULL, NULL }
int
git_remote__connect
(
git_remote
*
remote
,
git_direction
direction
,
const
git_remote_callbacks
*
callbacks
,
const
git_remote_connection_opts
*
conn
);
const
char
*
git_remote__urlfordirection
(
struct
git_remote
*
remote
,
int
direction
);
const
char
*
git_remote__urlfordirection
(
struct
git_remote
*
remote
,
int
direction
);
int
git_remote__get_http_proxy
(
git_remote
*
remote
,
bool
use_ssl
,
char
**
proxy_url
);
int
git_remote__get_http_proxy
(
git_remote
*
remote
,
bool
use_ssl
,
char
**
proxy_url
);
...
...
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