better merge commit tree layout algorithm

This commit is contained in:
Peter Cottle 2012-10-25 12:30:09 -07:00
parent 647bba9903
commit 385e3be236
2 changed files with 17 additions and 6 deletions

View file

@ -1070,6 +1070,8 @@ GitEngine.prototype.merge = function(targetSource, currentLocation) {
var msg = 'Merge ' + this.resolveName(targetSource) + var msg = 'Merge ' + this.resolveName(targetSource) +
' into ' + this.resolveName(currentLocation); ' into ' + this.resolveName(currentLocation);
// since we specify parent 1 as the first parent, it is the "main" parent
// and the node will be displayed below that branch / commit / whatever
var commit = this.makeCommit( var commit = this.makeCommit(
[parent1, parent2], [parent1, parent2],
null, null,
@ -1493,6 +1495,11 @@ var Commit = Backbone.Model.extend({
gitVisuals.addEdge(this.get('id'), parent.get('id')); gitVisuals.addEdge(this.get('id'), parent.get('id'));
}, },
isMainParent: function(parent) {
var index = this.get('parents').indexOf(parent);
return index === 0;
},
initialize: function() { initialize: function() {
this.validateAtInit(); this.validateAtInit();
this.addNodeToVisuals(); this.addNodeToVisuals();

View file

@ -279,8 +279,12 @@ GitVisuals.prototype.calcWidth = function() {
GitVisuals.prototype.maxWidthRecursive = function(commit) { GitVisuals.prototype.maxWidthRecursive = function(commit) {
var childrenTotalWidth = 0; var childrenTotalWidth = 0;
_.each(commit.get('children'), function(child) { _.each(commit.get('children'), function(child) {
var childWidth = this.maxWidthRecursive(child); // only include this if we are the "main" parent of
childrenTotalWidth += childWidth; // this child
if (child.isMainParent(commit)) {
var childWidth = this.maxWidthRecursive(child);
childrenTotalWidth += childWidth;
}
}, this); }, this);
var maxWidth = Math.max(1, childrenTotalWidth); var maxWidth = Math.max(1, childrenTotalWidth);
@ -326,7 +330,7 @@ GitVisuals.prototype.calcDepth = function() {
var maxDepth = this.calcDepthRecursive(this.rootCommit, 0); var maxDepth = this.calcDepthRecursive(this.rootCommit, 0);
if (maxDepth > 15) { if (maxDepth > 15) {
// issue warning // issue warning
// TODO console.warn('graphics are degrading from too many layers');
} }
var depthIncrement = this.getDepthIncrement(maxDepth); var depthIncrement = this.getDepthIncrement(maxDepth);
@ -405,10 +409,10 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
var children = commit.get('children'); var children = commit.get('children');
var maxDepth = depth; var maxDepth = depth;
for (var i = 0; i < children.length; i++) { _.each(children, function(child) {
var d = this.calcDepthRecursive(children[i], depth + 1); var d = this.calcDepthRecursive(child, depth + 1);
maxDepth = Math.max(d, maxDepth); maxDepth = Math.max(d, maxDepth);
} }, this);
return maxDepth; return maxDepth;
// TODO for merge commits, a specific fancy schamncy "main" commit line // TODO for merge commits, a specific fancy schamncy "main" commit line