gitToFs rewritten using recursive-tree-copy

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 11 years ago
parent 749de1e28f
commit 91284c36e6
  1. 105
      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);
var gitToFsCopier = new Copier({
concurrency: 4,
walkSourceTree: function (tree) {
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) {
return callback(err);
}
emitter.emit('tree', { gitTree: subTree, name: entry.name() });
callback();
});
} else if (entry.isFile()) {
emitter.emit('leaf', entry);
callback();
} else {
callback();
}
};
}), function (err) {
if (err) {
return emitter.emit('error', err);
}
return emitter.emit('done');
});
});
return emitter;
}, },
removedirs = function (path) { createTargetTree: function (tree, targetDir, callback) {
/*jslint stupid: true */ var targetSubdir = path.join(targetDir, tree.name);
fse.removeSync(path); fs.mkdir(targetSubdir, function (err) {
};
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) { if (err) {
return callback(err); return callback(err);
} }
fs.writeFile(exportDir + "/" + task.path, blob.content(), function (err, result) { callback(undefined, targetSubdir);
//console.log("Done writing file " + task.path); });
callback(err, result); },
}); finalizeTargetTree: function (targetSubdir, callback) {
callback();
},
copyLeaf: function (entry, targetDir, callback) {
var targetPath = path.join(targetDir, entry.name());
entry.getBlob(function (err, blob) {
if (err) {
return callback(err);
}
fs.writeFile(targetPath, blob.content(), callback);
}); });
}, 10); }
});
exports.gitToFs = function (commit, exportDir, callback) {
commit.getTree(function (err, tree) { commit.getTree(function (err, tree) {
if (err) { if (err) {
return globalCallback(err); return callback(err);
} }
tree.walk(false) gitToFsCopier.copy({ gitTree: tree, name: "." }, exportDir, 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) {
process.nextTick(globalCallback);
} else {
q.drain = globalCallback;
}
return;
})
.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