-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name":"git2json", | ||
"version":"0.0.1", | ||
"description": "convert git log to json", | ||
"author": "stephan blecher <stephan@blecher.at>", | ||
"keywords": [ "git", "soap" ], | ||
"bin": { "git-json": "src/main/cli.js" }, | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "src/test/index.js", | ||
"start": "src/main/server.js" }, | ||
"preferGlobal": true, | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Compatibility to browser js without node | ||
if(module == undefined) { var exports = {}} | ||
|
||
|
||
exports.retrieve = function(limit, callback) { | ||
var exec = require('child_process').exec; | ||
var git_params = { | ||
'sha': 'H', | ||
'ssha': 'h', // abbreviated hash | ||
'parenthashes': 'P', | ||
'authorname': 'an', | ||
'authoremail': 'ae', | ||
'authordate': 'at', | ||
'committername': 'cn', | ||
'committeremail': 'ce', | ||
'committerdate': 'ct', | ||
'encoding': 'e', | ||
'subject': 's', | ||
'ssubject': 'f', | ||
'body': 'b', | ||
'refnames': 'd' | ||
}; | ||
|
||
var pattern = ""; | ||
|
||
// Build git log format. | ||
Object.keys(git_params).forEach(function(key) { | ||
var val = git_params[key]; | ||
pattern += "%H-"+key+" %"+val+ "/%H%n" | ||
}); | ||
|
||
// Run git log and push output to callback - TODO: streaming | ||
exec('git log --all -n '+limit+' --pretty="'+pattern+'"', function (error, stdout, stderr) { | ||
callback(stdout) | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function (key, value) { | ||
if(key == 'parenthashes') { | ||
if(value.trim().length == 0) return [] | ||
else return value.trim().split(" ") | ||
} else return value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
/* this parses the reflog entry of git %d in format " (head1, head2)" to an array. */ | ||
module.exports = function (key, value) { | ||
if(key == "refnames") { | ||
if(value == '') return []; | ||
value = value.replace(/^ \(/,'').replace(/\)$/,'').split(", ") | ||
} | ||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Simple parser for the log created by the gitlogger module. | ||
Entries are in format "HASH-key value/HASH". this is used to make the parser immune to any special characters in the commit message. | ||
*/ | ||
|
||
module.exports = function(text, plugins) { | ||
var commits = {} | ||
var index = 0 | ||
var length = text.length | ||
var HL=40 | ||
|
||
while(text.length > 10) { | ||
// find hash | ||
var hash = text.substring(0, HL); | ||
var end = text.indexOf("/"+hash); | ||
var kvsep = text.indexOf(" "); | ||
|
||
var key = text.substring(HL+1, kvsep); | ||
var value = text.substring(kvsep+1, end); | ||
|
||
var commit = commits[hash]; | ||
if(commit == undefined) { | ||
commit = commits[hash] = {}; | ||
} | ||
|
||
// Apply any transformation plugins on the value | ||
if(plugins) plugins.forEach(function(f) { value = f(key, value)}); | ||
commit[key] = value; | ||
|
||
// move pointer to the next entry | ||
var index = end + HL + 1; | ||
text = text.substring(index).trim(); | ||
} | ||
|
||
return commits | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* module to link heads to all parents */ | ||
module.exports = function(commits) { | ||
|
||
Object.keys(commits).forEach(function(hash) { | ||
var commit = commits[hash]; | ||
commit.inHeads = [] | ||
}) | ||
|
||
Object.keys(commits).forEach(function(hash) { | ||
var commit = commits[hash]; | ||
if(commit.refnames.length > 0) { | ||
assignHeads(commits, commit) | ||
} | ||
}) | ||
} | ||
|
||
function assignHeads(commits, commit) { | ||
var parents1 = commit.parenthashes.slice(0) // copy array | ||
|
||
while(parents1.length > 0) { | ||
var newParents = [] | ||
parents1.forEach(function(parentHash) { | ||
var p = commits[parentHash] | ||
if(p != undefined) { | ||
p.inHeads.push(commit.commithash) | ||
// add all grandparents to the newparents | ||
newParents = newParents.concat(p.parenthashes) | ||
} | ||
}); | ||
parents1 = newParents | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* module to assign index */ | ||
module.exports = function(commits) { | ||
|
||
var index = 0; | ||
Object.keys(commits).forEach(function(hash) { | ||
var commit = commits[hash]; | ||
commit.index = index++; | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* module to link commits to each other */ | ||
|
||
module.exports = function(commits) { | ||
Object.keys(commits).forEach(function(hash) { | ||
var commit = commits[hash]; | ||
commit.parents = []; | ||
commit.children = []; | ||
}); | ||
|
||
|
||
Object.keys(commits).forEach(function(hash) { | ||
var commit = commits[hash]; | ||
commit.parenthashes.forEach(function(parenthash) { | ||
var parentCommit = commits[parenthash]; | ||
if(parentCommit != undefined) { | ||
parentCommit.children.push(hash); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
processor. only processes all processor plugins | ||
*/ | ||
module.exports = function(commits, plugins) { | ||
// Apply any processing plugins on the value | ||
if(plugins) plugins.forEach(function(f) { value = f(commits)}); | ||
|
||
Object.keys(commits).forEach(function(hash) { | ||
var commit = commits[hash]; | ||
}) | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
var gitlogger = require('./gitlogger.js') | ||
var gitparser = require('./gitparser.js') | ||
var gitprocessor = require('./gitprocessor.js') | ||
var defaultParserplugins = [ | ||
require('./gitparser-plugin-refnames.js'), | ||
require('./gitparser-plugin-parents.js') ] | ||
|
||
var defaultProcessorplugins = [ | ||
require('./gitprocessor-plugin-relations.js'), | ||
require('./gitprocessor-plugin-heads.js'), | ||
require('./gitprocessor-plugin-index.js') ] | ||
|
||
module.exports = { | ||
logger : gitlogger, | ||
parser : gitparser, | ||
processor : gitprocessor, | ||
parserplugins : defaultParserplugins, | ||
processorplugins : defaultProcessorplugins, | ||
|
||
run : function(callback, maxCommits) { | ||
var parserplugins = this.parserplugins; | ||
var processorplugins = this.processorplugins; | ||
var loggerCallback = function(text) { | ||
var commits = gitparser(text, parserplugins) | ||
gitprocessor(commits, processorplugins); | ||
|
||
callback(commits); | ||
} | ||
|
||
gitlogger.retrieve(maxCommits || 300, loggerCallback) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env node | ||
|
||
var git2json = require("../index.js") | ||
|
||
git2json.run(function(commits) { | ||
console.log("%s", JSON.stringify(commits, null, 2)); | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
var git2json = require('../index.js') | ||
|
||
var loggerCallback = function(text) { | ||
var commits = git2json.gitparser(text, git2json.defaultParserplugins) | ||
git2json.gitprocessor(commits, git2json.defaultProcessorplugins); | ||
|
||
console.log("commit: %s", JSON.stringify(commits, null, 2)); | ||
} | ||
|
||
git2json.gitlogger.retrieve(30, loggerCallback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
- git logger -> load history into json model | ||
{ | ||
'commit-hash': 'H', | ||
'parent-hash': 'T', | ||
'author-name': 'an', | ||
'author-email': 'ae', | ||
'author-date': 'at', | ||
'committer-name': 'cn', | ||
'committer-email': 'ce', | ||
'committer-date': 'ct', | ||
'encoding': 'e', | ||
'subject': 's', | ||
'sanitized-subject': 'f', | ||
'body': 'b', | ||
} | ||
|
||
|
||
|
||
|
||
- git parser -> parse history and figure out branches, relations | ||
- serverside | ||
|
||
|
||
- renderer - render history | ||
- render branches | ||
- add button to checkout | ||
- render commit | ||
- plugin able. add button for merge, | ||
- render relation | ||
|
||
|
||
|
||
https://github.com/nickola/web-console | ||
https://github.com/jcubic/jquery.terminal |