Skip to content

Commit 4a93dbf

Browse files
authored
Merge pull request #1195 from implausible/feature/enable-curl-support
build against shared library for libcurl
2 parents 3828c83 + 308f0ae commit 4a93dbf

File tree

8 files changed

+155
-39
lines changed

8 files changed

+155
-39
lines changed

generate/input/libgit2-supplement.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@
481481
"name": "prune",
482482
"type": "git_fetch_prune_t"
483483
},
484+
{
485+
"name": "proxy_opts",
486+
"type": "git_proxy_options"
487+
},
484488
{
485489
"name": "update_fetchhead",
486490
"type": "int"

generate/templates/templates/binding.gyp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,22 @@
8787
}
8888
}
8989
}
90-
], [
90+
],
91+
[
92+
"OS=='linux' or OS=='mac'", {
93+
"libraries": [
94+
"-lcurl"
95+
]
96+
}
97+
],
98+
[
9199
"OS=='linux' and '<!(echo \"$CXX\")'=='clang++'", {
92100
"cflags": [
93101
"-Wno-c++11-extensions"
94102
]
95103
}
96-
], [
104+
],
105+
[
97106
"OS=='linux' and '<!(echo \"$CXX\")'!='clang++'", {
98107
"cflags": [
99108
"-std=c++0x"

generate/templates/templates/nodegit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ rawApi.Utils = {};
7979
require("./utils/lookup_wrapper");
8080
require("./utils/normalize_options");
8181
require("./utils/shallow_clone");
82+
require("./utils/normalize_fetch_options");
8283

8384
// Load up extra types;
8485
require("./status_file");

lib/clone.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var NodeGit = require("../");
22
var shallowClone = NodeGit.Utils.shallowClone;
3+
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
34
var normalizeOptions = NodeGit.Utils.normalizeOptions;
45

56
var Clone = NodeGit.Clone;
@@ -15,29 +16,15 @@ var _clone = Clone.clone;
1516
* @return {Repository} repo
1617
*/
1718
Clone.clone = function(url, local_path, options) {
18-
var remoteCallbacks = {};
19-
var fetchOpts = {};
19+
var fetchOpts = normalizeFetchOptions(options && options.fetchOpts);
2020

2121
if (options) {
2222
options = shallowClone(options);
23-
if (options.fetchOpts) {
24-
fetchOpts = shallowClone(options.fetchOpts);
25-
}
2623
delete options.fetchOpts;
2724
}
2825

2926
options = normalizeOptions(options, NodeGit.CloneOptions);
3027

31-
if (fetchOpts.callbacks) {
32-
remoteCallbacks = shallowClone(fetchOpts.callbacks);
33-
delete fetchOpts.callbacks;
34-
}
35-
36-
fetchOpts = normalizeOptions(fetchOpts, NodeGit.FetchOptions);
37-
38-
fetchOpts.callbacks =
39-
normalizeOptions(remoteCallbacks, NodeGit.RemoteCallbacks);
40-
4128
if (options) {
4229
options.fetchOpts = fetchOpts;
4330
}

lib/remote.js

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var NodeGit = require("../");
2+
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
23
var normalizeOptions = NodeGit.Utils.normalizeOptions;
34
var lookupWrapper = NodeGit.Utils.lookupWrapper;
45
var shallowClone = NodeGit.Utils.shallowClone;
@@ -8,6 +9,7 @@ var _connect = Remote.prototype.connect;
89
var _download = Remote.prototype.download;
910
var _fetch = Remote.prototype.fetch;
1011
var _push = Remote.prototype.push;
12+
var _upload = Remote.prototype.upload;
1113

1214
/**
1315
* Retrieves the remote by name
@@ -53,24 +55,8 @@ Remote.prototype.connect = function(
5355
* @return {Number} error code
5456
*/
5557
Remote.prototype.download = function(refspecs, opts) {
56-
var callbacks;
57-
58-
if (opts) {
59-
opts = shallowClone(opts);
60-
callbacks = opts.callbacks;
61-
delete opts.callbacks;
62-
} else {
63-
opts = {};
64-
}
65-
66-
opts = normalizeOptions(opts, NodeGit.FetchOptions);
67-
68-
if (callbacks) {
69-
opts.callbacks =
70-
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
71-
}
72-
73-
return _download.call(this, refspecs, opts);
58+
return _download
59+
.call(this, refspecs, normalizeFetchOptions(opts));
7460
};
7561

7662
/**
@@ -84,24 +70,61 @@ Remote.prototype.download = function(refspecs, opts) {
8470
* @return {Number} error code
8571
*/
8672
Remote.prototype.fetch = function(refspecs, opts, reflog_message) {
73+
return _fetch
74+
.call(this, refspecs, normalizeFetchOptions(opts), reflog_message);
75+
};
76+
77+
/**
78+
* Pushes to a remote
79+
*
80+
* @async
81+
* @param {Array} refSpecs The ref specs that should be pushed
82+
* @param {PushOptions} options Options for the checkout
83+
* @param {Function} callback
84+
* @return {Number} error code
85+
*/
86+
Remote.prototype.push = function(refSpecs, opts) {
8787
var callbacks;
88+
var proxyOpts;
8889

8990
if (opts) {
9091
opts = shallowClone(opts);
9192
callbacks = opts.callbacks;
93+
proxyOpts = opts.proxyOpts;
9294
delete opts.callbacks;
95+
delete opts.proxyOpts;
9396
} else {
9497
opts = {};
9598
}
9699

97-
opts = normalizeOptions(opts, NodeGit.FetchOptions);
100+
opts = normalizeOptions(opts, NodeGit.PushOptions);
98101

99102
if (callbacks) {
100103
opts.callbacks =
101104
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
102105
}
103106

104-
return _fetch.call(this, refspecs, opts, reflog_message);
107+
if (proxyOpts) {
108+
opts.proxyOpts =
109+
normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
110+
}
111+
112+
return _push.call(this, refSpecs, opts);
113+
};
114+
115+
/**
116+
* Connects to a remote
117+
*
118+
* @async
119+
* @param {Array} refSpecs The ref specs that should be pushed
120+
* @param {FetchOptions} opts The fetch options for download, contains callbacks
121+
* @param {String} message The message to use for the update reflog messages
122+
* @param {Function} callback
123+
* @return {Number} error code
124+
*/
125+
Remote.prototype.fetch = function(refspecs, opts, reflog_message) {
126+
return _fetch
127+
.call(this, refspecs, normalizeFetchOptions(opts), reflog_message);
105128
};
106129

107130
/**
@@ -113,12 +136,16 @@ Remote.prototype.fetch = function(refspecs, opts, reflog_message) {
113136
* @param {Function} callback
114137
* @return {Number} error code
115138
*/
116-
Remote.prototype.push = function(refSpecs, opts) {
139+
Remote.prototype.upload = function(refSpecs, opts) {
117140
var callbacks;
141+
var proxyOpts;
142+
118143
if (opts) {
119144
opts = shallowClone(opts);
120145
callbacks = opts.callbacks;
146+
proxyOpts = opts.proxyOpts;
121147
delete opts.callbacks;
148+
delete opts.proxyOpts;
122149
} else {
123150
opts = {};
124151
}
@@ -130,5 +157,10 @@ Remote.prototype.push = function(refSpecs, opts) {
130157
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
131158
}
132159

133-
return _push.call(this, refSpecs, opts);
160+
if (proxyOpts) {
161+
opts.proxyOpts =
162+
normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
163+
}
164+
165+
return _upload.call(this, refSpecs, opts);
134166
};

lib/submodule.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
var NodeGit = require("../");
2+
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
3+
var normalizeOptions = NodeGit.Utils.normalizeOptions;
4+
var shallowClone = NodeGit.Utils.shallowClone;
25

36
var Submodule = NodeGit.Submodule;
47

58
var _foreach = Submodule.foreach;
9+
var _update = Submodule.prototype.update;
610

711
// Override Submodule.foreach to eliminate the need to pass null payload
812
Submodule.foreach = function(repo, callback) {
913
return _foreach(repo, callback, null);
1014
};
15+
16+
/**
17+
* Updates a submodule
18+
*
19+
* @async
20+
* @param {Number} init Setting this to 1 will initialize submodule
21+
* before updating
22+
* @param {SubmoduleUpdateOptions} options Submodule update settings
23+
* @return {Number} 0 on success, any non-zero return value from a callback
24+
*/
25+
Submodule.prototype.update = function(init, options) {
26+
var fetchOpts = normalizeFetchOptions(options && options.fetchOpts);
27+
28+
if (options) {
29+
options = shallowClone(options);
30+
delete options.fetchOpts;
31+
}
32+
33+
options = normalizeOptions(options, NodeGit.SubmoduleUpdateOptions);
34+
35+
if (options) {
36+
options.fetchOpts = fetchOpts;
37+
}
38+
39+
return _update.call(this, init, options);
40+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var NodeGit = require("../../");
2+
var normalizeOptions = NodeGit.Utils.normalizeOptions;
3+
var shallowClone = NodeGit.Utils.shallowClone;
4+
5+
/**
6+
* Normalize an object to match a struct.
7+
*
8+
* @param {String, Object} oid - The oid string or instance.
9+
* @return {Object} An Oid instance.
10+
*/
11+
function normalizeFetchOptions(options) {
12+
if (options instanceof NodeGit.FetchOptions) {
13+
return options;
14+
}
15+
16+
var callbacks;
17+
var proxyOpts;
18+
19+
if (options) {
20+
options = shallowClone(options);
21+
callbacks = options.callbacks;
22+
proxyOpts = options.proxyOpts;
23+
delete options.callbacks;
24+
delete options.proxyOpts;
25+
} else {
26+
options = {};
27+
}
28+
29+
options = normalizeOptions(options, NodeGit.FetchOptions);
30+
31+
if (callbacks) {
32+
options.callbacks =
33+
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
34+
}
35+
36+
if (proxyOpts) {
37+
options.proxyOpts =
38+
normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
39+
}
40+
return options;
41+
}
42+
43+
NodeGit.Utils.normalizeFetchOptions = normalizeFetchOptions;

vendor/libgit2.gyp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
"libgit2/src/config_file.h",
7575
"libgit2/src/config.c",
7676
"libgit2/src/config.h",
77+
"libgit2/src/curl_stream.c",
78+
"libgit2/src/curl_stream.h",
7779
"libgit2/src/crlf.c",
7880
"libgit2/src/date.c",
7981
"libgit2/src/delta.c",
@@ -289,6 +291,14 @@
289291
}
290292
}
291293
}],
294+
["OS=='mac' or OS=='linux' or OS.endswith('bsd')", {
295+
"cflags": [
296+
"-DGIT_CURL"
297+
],
298+
"defines": [
299+
"GIT_CURL"
300+
]
301+
}],
292302
["OS=='linux' or OS.endswith('bsd')" , {
293303
"cflags": [
294304
"-DGIT_SSH",

0 commit comments

Comments
 (0)