From a5cb4d6a9327bcf7ad20fad66440e2319340e25c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Wed, 8 Jul 2015 11:42:35 +0300 Subject: [PATCH] Parse the commits --- lib/index.js | 53 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/lib/index.js b/lib/index.js index 2186026..85e9300 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,7 +9,10 @@ var Ul = require("ul") , CliPie = require("cli-pie") , CliGhCal = require("cli-gh-cal") , GitLogParser = require("gitlog-parser").parse - , Exec = require("child_process").exec + , ChildProcess = require("child_process") + , Exec = ChildProcess.exec + , Spawn = ChildProcess.spawn + , ProgressBar = require("progress") ; // Constants @@ -367,22 +370,42 @@ GitStats.globalActivity = function (options, callback) { var commits = {} , today = null , cal = [] + , isFinished = false + , timeout = null + , progress = null + , complete = 0 ; - GitLogParser(Exec("git log", { cwd: options.repo }).stdout).on("commit", function(commit) { - today = Moment(commit.date).format(DATE_FORMAT); - commits[today] = commits[today] || 0; - ++commits[today]; - }).on("error", function (err) { - callback(err); - }).on("finish", function () { - Object.keys(commits).forEach(function (c) { - cal.push([c, commits[c]]) + Exec("git rev-list HEAD --count", { cwd: options.repo }, function (err, commitCount) { + if (err) { return callback(err); } + commitCount = parseInt(commitCount); + setTimeout(function () { + if (isFinished) { return; } + progress = new ProgressBar(":bar", { total: commitCount - complete }); + }, 10); + // TODO Take only the commits from the provided range (start - end) + GitLogParser(Spawn("git", ["log"], { cwd: options.repo }).stdout).on("commit", function(commit) { + today = Moment(commit.date).format(DATE_FORMAT); + commits[today] = commits[today] || 0; + ++commits[today]; + ++complete; + if (progress) { + progress.tick(); + } + }).on("error", function (err) { + clearTimeout(timeout); + callback(err); + }).on("finish", function () { + clearTimeout(timeout); + isFinished = true; + Object.keys(commits).forEach(function (c) { + cal.push([c, commits[c]]) + }); + callback(null, CliGhCal(cal, { + theme: options.theme + , start: options.start + , end: options.end + })); }); - callback(null, CliGhCal(cal, { - theme: options.theme - , start: options.start - , end: options.end - })); }); };