[Pkg-javascript-commits] [node-coveralls] 105/332: Fix step 3: code cleanup + faster/nimbler use of Git to obtain data (rev-parse and cat-file instead of multiple log calls)
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Nov 9 13:53:46 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-coveralls.
commit a49eaa7f533bb7c3338d7864e3d118d43ede861e
Author: Christophe Porteneuve <tdd at tddsworld.com>
Date: Fri Nov 8 19:31:19 2013 +0100
Fix step 3: code cleanup + faster/nimbler use of Git to obtain data (rev-parse and cat-file instead of multiple log calls)
---
lib/fetchGitData.js | 78 +++++++++++++++++++----------------------------------
lib/handleInput.js | 6 ++---
2 files changed, 31 insertions(+), 53 deletions(-)
diff --git a/lib/fetchGitData.js b/lib/fetchGitData.js
index f75ca82..1633bd5 100644
--- a/lib/fetchGitData.js
+++ b/lib/fetchGitData.js
@@ -1,37 +1,19 @@
var exec = require('child_process').exec;
var logger = require('./logger')();
-var fetchGitData = function(git, cb) {
+function fetchGitData(git, cb) {
if (!cb){
throw new Error("fetchGitData requires a callback");
}
- var i;
- var execGit = true;
- var head = {
- "author_name": {
- "format": "'%aN'",
- },
- "author_email": {
- "format": "'%ae'",
- },
- "committer_name": {
- "format": "'%cN'",
- },
- "committer_email": {
- "format": "'%ce'",
- },
- "message": {
- "format": "'%s'",
- }
- };
-
//-- Malformed/undefined git object
if ('undefined' === typeof git) {
return cb(new Error('No options passed'));
- } else if (!git.hasOwnProperty('head')) {
+ }
+ if (!git.hasOwnProperty('head')) {
return cb(new Error('You must provide the head'));
- } else if (!git.head.hasOwnProperty('id')) {
+ }
+ if (!git.head.hasOwnProperty('id')) {
return cb(new Error('You must provide the head.id'));
}
@@ -52,7 +34,7 @@ var fetchGitData = function(git, cb) {
}
//-- Use git?
- exec("git log -1 " + git.head.id + " --pretty=format:'%H'", function(err, response){
+ exec("git rev-parse --verify " + git.head.id, function(err, response){
if (err){
// git is not available...
git.head.author_name = git.head.author_name || "Unknown Author";
@@ -63,32 +45,7 @@ var fetchGitData = function(git, cb) {
return cb(null, git);
}
- //-- Head
- var commands = [];
- var fields = [];
- for (var field in head) {
- fields.push(field);
- var command = "git log -1 " + git.head.id + " --pretty=format:" + head[field].format;
- commands.push(command);
- }
- var i = 0;
- var remaining = commands.length;
- commands.forEach(function(command){
- var field = fields[i];
- i++;
- exec(command, function(err, response){
- if (err) return cb(err);
- git.head[field] = response;
- remaining--;
- if (remaining === 0){
- if (git.branch) {
- fetchRemotes(git, cb);
- } else {
- fetchBranch(git, cb);
- }
- }
- });
- });
+ fetchHeadDetails(git, cb);
});
}
@@ -102,6 +59,27 @@ function fetchBranch(git, cb) {
});
}
+var REGEX_COMMIT_DETAILS = /\nauthor (.+?) <(.+?)>.+\ncommitter (.+?) <(.+?)>.+\n\n(.*)/m;
+
+function fetchHeadDetails(git, cb) {
+ exec('git cat-file -p ' + git.head.id, function(err, response) {
+ if (err)
+ return cb(err);
+
+ var items = response.match(REGEX_COMMIT_DETAILS).slice(1);
+ var fields = ['author_name', 'author_email', 'committer_name', 'committer_email', 'message'];
+ fields.forEach(function(field, index) {
+ git.head[field] = items[index];
+ });
+
+ if (git.branch) {
+ fetchRemotes(git, cb);
+ } else {
+ fetchBranch(git, cb);
+ }
+ });
+}
+
function fetchRemotes(git, cb) {
exec("git remote -v", function(err, remotes){
if (err)
diff --git a/lib/handleInput.js b/lib/handleInput.js
index 1435c1c..807e31d 100644
--- a/lib/handleInput.js
+++ b/lib/handleInput.js
@@ -1,9 +1,10 @@
var index = require('../index');
var logger = require('./logger')();
-var handleInput = function(input){
+function handleInput(input) {
logger.debug(input);
var options = index.getOptions(function(err, options){
+
if (err){
logger.error("error from getOptions");
throw err;
@@ -28,7 +29,6 @@ var handleInput = function(input){
});
});
});
-
-};
+}
module.exports = handleInput;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-coveralls.git
More information about the Pkg-javascript-commits
mailing list