Skip to content

Commit e43c6ee

Browse files
Merge jonasmalacofilho#9: improve logging and update remote URLs before fetch
from kurzdigital/master
2 parents 5301858 + 4167cb6 commit e43c6ee

File tree

2 files changed

+136
-41
lines changed

2 files changed

+136
-41
lines changed

bin/git-cache-http-server.js

+113-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Main.hx

+23-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Main {
77
{
88
var parts = s.split(" ");
99
if (parts[0] != "Basic")
10-
throw "HTTP authentication schemes other than Basic not supported";
10+
throw "ERR: HTTP authentication schemes other than Basic not supported";
1111
return haxe.crypto.Base64.decode(parts[1]);
1212
}
1313

@@ -29,14 +29,16 @@ class Main {
2929
ChildProcess.exec('git clone --quiet --mirror "$remote" "$local"', callback);
3030
}
3131

32-
static function fetch(local, callback)
32+
static function fetch(remote, local, callback)
3333
{
34-
ChildProcess.exec('git -C "$local" fetch --quiet', callback);
34+
ChildProcess.exec('git -C "$local" remote set-url origin "$remote"', function(err, stdout, stderr) {
35+
ChildProcess.exec('git -C "$local" fetch --quiet', callback);
36+
});
3537
}
3638

3739
static function authenticate(params, callback)
3840
{
39-
trace("authenticating on the upstream repo");
41+
trace('INFO: authenticating on the upstream repo ${params.repo}');
4042
var req = Https.request('https://${params.repo}/info/refs?service=${params.service}', callback);
4143
req.setHeader("User-Agent", "git/");
4244
if (params.auth != null)
@@ -48,20 +50,25 @@ class Main {
4850
{
4951
if (!updatePromises.exists(local)) {
5052
updatePromises[local] = new Promise(function(resolve, reject) {
51-
trace("updating: fetching");
52-
fetch(local, function (ferr, stdout, stderr) {
53+
trace('INFO: updating: fetching from $remote');
54+
fetch(remote, local, function (ferr, stdout, stderr) {
5355
if (ferr != null) {
54-
trace("updating: fetch failed, cloning");
56+
trace("WARN: updating: fetch failed");
57+
trace(stdout);
58+
trace(stderr);
59+
trace("WARN: continuing with clone");
5560
clone(remote, local, function (cerr, stdout, stderr) {
5661
if (cerr != null) {
57-
resolve('git clone exited with non-zero status: ${cerr.code}');
62+
trace(stdout);
63+
trace(stderr);
64+
resolve('ERR: git clone exited with non-zero status: ${cerr.code}');
5865
} else {
59-
trace("updating: success");
66+
trace("INFO: updating via clone: success");
6067
resolve(null);
6168
}
6269
});
6370
} else {
64-
trace("updating: success");
71+
trace("INFO: updating via fetch: success");
6572
resolve(null);
6673
}
6774
});
@@ -75,11 +82,11 @@ class Main {
7582
return Promise.reject(err);
7683
});
7784
} else {
78-
trace("reusing existing promise");
85+
trace("INFO: reusing existing promise");
7986
}
8087
return updatePromises[local]
8188
.then(function(nothing:Dynamic) {
82-
trace("promise fulfilled");
89+
trace("INFO: promise fulfilled");
8390
callback(null);
8491
}, function(err:Dynamic) {
8592
callback(err);
@@ -118,7 +125,7 @@ class Main {
118125
if (params.isInfoRequest) {
119126
update(remote, local, function (err) {
120127
if (err != null) {
121-
trace('ERROR: $err');
128+
trace('ERR: $err');
122129
trace(haxe.CallStack.toString(haxe.CallStack.exceptionStack()));
123130
res.statusCode = 500;
124131
res.end();
@@ -134,7 +141,7 @@ class Main {
134141
up.on("exit", function (code) {
135142
if (code != 0)
136143
res.end();
137-
trace('${params.service} done with exit $code');
144+
trace('INFO: ${params.service} done with exit $code');
138145
});
139146
});
140147
} else {
@@ -190,8 +197,8 @@ Options:
190197
if (listenPort == null || listenPort < 1 || listenPort > 65535)
191198
throw 'Invalid port number: ${options["--port"]}';
192199

193-
trace('cache directory: $cacheDir');
194-
trace('listening to port: $listenPort');
200+
trace('INFO: cache directory: $cacheDir');
201+
trace('INFO: listening to port: $listenPort');
195202
Http.createServer(handleRequest).listen(listenPort);
196203
}
197204
}

0 commit comments

Comments
 (0)