gitToFs rewritten using recursive-tree-copy

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 11 years ago
parent 749de1e28f
commit 91284c36e6
  1. 101
      BuildServer/lib/git/copy.js
  2. 3
      BuildServer/package.json

@ -1,54 +1,83 @@
"use strict"; "use strict";
var nodegit = require('nodegit'), var EventEmitter = require('events').EventEmitter,
async = require('async'), path = require('path'),
fs = require('fs'), fs = require('fs'),
fse = require('fs-extra'), nodegit = require('nodegit'),
mkdirs = function (path) { async = require('async'),
/*jslint stupid: true */ Copier = require('recursive-tree-copy').Copier;
fse.mkdirsSync(path);
},
removedirs = function (path) {
/*jslint stupid: true */
fse.removeSync(path);
};
exports.gitToFs = function (commit, exportDir, globalCallback) { var gitToFsCopier = new Copier({
var q = async.queue(function (task, callback) { concurrency: 4,
//console.log("Going to write file " + task.path + " (" + task.buffer.length + " bytes)"); walkSourceTree: function (tree) {
task.entry.getBlob(function (err, blob) { var emitter = new EventEmitter();
process.nextTick(function () {
var entries;
try {
entries = tree.gitTree.entries();
} catch(err) {
return emitter.emit('error', err);
}
async.parallel(entries.map(function (entry) {
return function (callback) {
if (entry.isTree()) {
entry.getTree(function (err, subTree) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
fs.writeFile(exportDir + "/" + task.path, blob.content(), function (err, result) { emitter.emit('tree', { gitTree: subTree, name: entry.name() });
//console.log("Done writing file " + task.path); callback();
callback(err, result); });
} else if (entry.isFile()) {
emitter.emit('leaf', entry);
callback();
} else {
callback();
}
};
}), function (err) {
if (err) {
return emitter.emit('error', err);
}
return emitter.emit('done');
}); });
}); });
}, 10); return emitter;
},
createTargetTree: function (tree, targetDir, callback) {
var targetSubdir = path.join(targetDir, tree.name);
fs.mkdir(targetSubdir, function (err) {
if (err) {
return callback(err);
}
commit.getTree(function (err, tree) { callback(undefined, targetSubdir);
});
},
finalizeTargetTree: function (targetSubdir, callback) {
callback();
},
copyLeaf: function (entry, targetDir, callback) {
var targetPath = path.join(targetDir, entry.name());
entry.getBlob(function (err, blob) {
if (err) { if (err) {
return globalCallback(err); return callback(err);
} }
tree.walk(false) fs.writeFile(targetPath, blob.content(), callback);
.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) { exports.gitToFs = function (commit, exportDir, callback) {
process.nextTick(globalCallback); commit.getTree(function (err, tree) {
} else { if (err) {
q.drain = globalCallback; return callback(err);
} }
return;
}) gitToFsCopier.copy({ gitTree: tree, name: "." }, exportDir, callback);
.start();
}); });
}; };

@ -15,6 +15,7 @@
"glob": "~3.2.7", "glob": "~3.2.7",
"nodemailer": "~0.6.0", "nodemailer": "~0.6.0",
"mustache": "~0.8.1", "mustache": "~0.8.1",
"adm-zip": "~0.4.4" "adm-zip": "~0.4.4",
"recursive-tree-copy": "0.0.1"
} }
} }

Loading…
Cancel
Save