Fixed #38. Implemented the new schema.

Now we only store the date days and the commit hashes. The remote url is not used anymore. Fixes #29.
After this change, the data file is simplified a lot.
This commit is contained in:
Ionică Bizău 2015-07-13 08:26:51 +03:00
parent 6965300e5b
commit 12182f1537
1 changed files with 13 additions and 16 deletions

View File

@ -14,12 +14,14 @@ var Ul = require("ul")
, Typpy = require("typpy")
, Exec = ChildProcess.exec
, Spawn = ChildProcess.spawn
, LowDb = require("lowdb")
;
// Constants
const DATE_FORMAT = "MMM D, YYYY"
, DEFAULT_STORE = Abs("~/.git-stats")
, DEFAULT_DATA = {
commits: {}
}
;
function GitStats(dataPath) {
@ -65,20 +67,18 @@ GitStats.prototype.record = function (data, callback) {
}
if (typeof data.url !== "string" || !data.url) {
callback(new Error("Invalid url field. This commit is not recorded into the git-stats history since you haven't added the remote url. You can import the previous commits using the git-stats-importer tool."));
return GitStats;
delete data.url;
}
// Get stats
self.get(function (err, stats) {
stats = stats || {};
var day = data.date.format(DATE_FORMAT)
, today = stats[day] = Object(stats[day])
, repo = today[data.url] = Object(today[data.url])
var commits = stats.commits
, day = data.date.format(DATE_FORMAT)
, today = commits[day] = Object(commits[day])
;
repo[data.hash] = { date: data.date };
today[data.hash] = 1;
self.save(stats, callback);
});
@ -100,8 +100,8 @@ GitStats.prototype.get = function (callback) {
ReadJson(self.path, function (err, data) {
if (err && err.code === "ENOENT") {
return self.save({}, function (err) {
callback(err, {});
return self.save(DEFAULT_DATA, function (err) {
callback(err, DEFAULT_DATA);
});
}
@ -198,14 +198,11 @@ GitStats.prototype.graph = function (data, callback) {
// Iterate days
self.iterateDays(data, function (cDay) {
cDayObj = Object(stats.commits[cDay]);
cDayObj = year[cDay] = {
_: stats[cDay] || {}
, c: 0
_: cDayObj
, c: Object.keys(cDayObj).length
};
Object.keys(cDayObj._).forEach(function (c) {
cDayObj.c += Object.keys(cDayObj._[c]).length;
});
});
callback(null, year);