2016-03-26 22:16:47 +05:30
|
|
|
var crypto = require("crypto");
|
|
|
|
var Logger = require('../../logger');
|
|
|
|
var log = new Logger.Log();
|
|
|
|
|
2016-03-27 11:00:44 +05:30
|
|
|
|
2016-03-26 22:16:47 +05:30
|
|
|
var commits = {};
|
|
|
|
var head = null;
|
|
|
|
var branches = { "master" : head };
|
|
|
|
var curBranch = "master";
|
2016-03-27 11:00:44 +05:30
|
|
|
var direction = "LR";
|
2016-03-26 22:16:47 +05:30
|
|
|
|
|
|
|
function getId() {
|
|
|
|
return crypto.randomBytes(20).toString('hex').substring(0, 7);
|
|
|
|
}
|
2016-03-27 11:00:44 +05:30
|
|
|
|
|
|
|
exports.setDirection = function(dir) {
|
|
|
|
direction = dir;
|
|
|
|
}
|
|
|
|
exports.pushCommit = function(msg) {
|
2016-03-26 22:16:47 +05:30
|
|
|
var commit = { id: getId(),
|
2016-03-27 11:00:44 +05:30
|
|
|
message: msg,
|
2016-03-26 22:16:47 +05:30
|
|
|
parent: head == null ? null : head.id};
|
|
|
|
head = commit;
|
|
|
|
commits[commit.id] = commit;
|
|
|
|
branches[curBranch] = commit.id;
|
|
|
|
log.debug("in pushCommit");
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.createBranch = function(name) {
|
2016-03-27 11:00:44 +05:30
|
|
|
branches[name] = head != null ? head.id: null;
|
2016-03-26 22:16:47 +05:30
|
|
|
log.debug("in createBranch");
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.mergeBranch = function() {
|
|
|
|
log.debug("in mergeBranch");
|
|
|
|
}
|
|
|
|
|
2016-03-27 11:00:44 +05:30
|
|
|
exports.checkout = function(branch) {
|
|
|
|
log.debug("in checkout");
|
|
|
|
curBranch = branch;
|
|
|
|
var id = branches[curBranch];
|
|
|
|
head = commits[id];
|
|
|
|
}
|
2016-03-26 22:16:47 +05:30
|
|
|
exports.reset = function () {
|
|
|
|
commits = {};
|
|
|
|
head = null;
|
|
|
|
branches = { "master" : head };
|
|
|
|
curBranch = "master";
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.getBranches = function() { return branches; }
|
|
|
|
exports.getCommits = function() { return commits; }
|
|
|
|
exports.getCurrentBranch = function() { return curBranch; }
|
2016-03-27 11:00:44 +05:30
|
|
|
exports.getDirection = function() { return direction; }
|