gitToFs moved to a separate module

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 10 years ago
parent 7af3a3d4a9
commit 749de1e28f
  1. 2
      BuildServer/lib/builder.js
  2. 54
      BuildServer/lib/git/copy.js
  3. 47
      BuildServer/lib/git/loader.js

@ -3,7 +3,7 @@
var fs = require('fs'); var fs = require('fs');
var fse = require('fs-extra'); var fse = require('fs-extra');
var async = require('async'); var async = require('async');
var gitLoader = require('./git-loader'); var gitLoader = require('./git/loader');
var processor = require('./task-processor'); var processor = require('./task-processor');
var mailSender = require('./mail-sender'); var mailSender = require('./mail-sender');
var settings = require('../settings'); var settings = require('../settings');

@ -0,0 +1,54 @@
"use strict";
var nodegit = require('nodegit'),
async = require('async'),
fs = require('fs'),
fse = require('fs-extra'),
mkdirs = function (path) {
/*jslint stupid: true */
fse.mkdirsSync(path);
},
removedirs = function (path) {
/*jslint stupid: true */
fse.removeSync(path);
};
exports.gitToFs = function (commit, exportDir, globalCallback) {
var q = async.queue(function (task, callback) {
//console.log("Going to write file " + task.path + " (" + task.buffer.length + " bytes)");
task.entry.getBlob(function (err, blob) {
if (err) {
return callback(err);
}
fs.writeFile(exportDir + "/" + task.path, blob.content(), function (err, result) {
//console.log("Done writing file " + task.path);
callback(err, result);
});
});
}, 10);
commit.getTree(function (err, tree) {
if (err) {
return globalCallback(err);
}
tree.walk(false)
.on('entry', function (entry) {
if (entry.isTree()) {
mkdirs(exportDir + "/" + entry.path());
} else if (entry.isFile()) {
q.push({path: entry.path(), entry: entry });
}
})
.on('end', function () {
if (q.length() === 0) {
process.nextTick(globalCallback);
} else {
q.drain = globalCallback;
}
return;
})
.start();
});
};

@ -1,10 +1,8 @@
"use strict"; "use strict";
var nodegit = require('nodegit'), var nodegit = require('nodegit'),
async = require('async'),
fs = require('fs'),
fse = require('fs-extra'), fse = require('fs-extra'),
basename = require('path').basename, gitToFs = require('./copy').gitToFs,
mkdirs = function (path) { mkdirs = function (path) {
/*jslint stupid: true */ /*jslint stupid: true */
fse.mkdirsSync(path); fse.mkdirsSync(path);
@ -27,10 +25,7 @@ options = {
module.exports = function (options, globalCallback) { module.exports = function (options, globalCallback) {
var url = options.remote, var url = options.remote,
path = options.local + "/" + options.hash, path = options.local + "/" + options.hash,
exported = options.exported, exported = options.exported;
done = function () {
globalCallback();
};
removedirs(path); removedirs(path);
mkdirs(path); mkdirs(path);
@ -46,20 +41,6 @@ module.exports = function (options, globalCallback) {
return globalCallback(err); return globalCallback(err);
} }
var q = async.queue(function (task, callback) {
//console.log("Going to write file " + task.path + " (" + task.buffer.length + " bytes)");
task.entry.getBlob(function (err, blob) {
if (err) {
return callback(err);
}
fs.writeFile(exported + "/" + task.path, blob.content(), function (err, result) {
//console.log("Done writing file " + task.path);
callback(err, result);
});
});
}, 10);
repo.getCommit(options.hash, function (err, commit) { repo.getCommit(options.hash, function (err, commit) {
if (err) { if (err) {
return globalCallback(err); return globalCallback(err);
@ -68,29 +49,7 @@ module.exports = function (options, globalCallback) {
removedirs(exported); removedirs(exported);
mkdirs(exported); mkdirs(exported);
commit.getTree(function (err, tree) { gitToFs(commit, exported, globalCallback);
if (err) {
return globalCallback(err);
}
tree.walk(false)
.on('entry', function (entry) {
if (entry.isTree()) {
mkdirs(exported + "/" + entry.path());
} else if (entry.isFile()) {
q.push({path: entry.path(), entry: entry });
}
})
.on('end', function () {
if (q.length() === 0) {
process.nextTick(done);
} else {
q.drain = done;
}
return;
})
.start();
});
}); });
}); });
}; };
Loading…
Cancel
Save