Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion css/explaingit.css
Original file line numberDiff line numberDiff line change
Expand Up@@ -134,7 +134,7 @@ span.cmd {

.control-box input[type="text"] {
position: absolute;
bottom: 0;
bottom: 0;
padding-left: 15px;
color: #FFF;
line-height: 14px;
Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -523,12 +523,12 @@ <h2>Specific Examples</h2>

window.addEventListener('hashchange', open, false);
window.addEventListener('load', open, false);

function open() {
var hash = window.location.hash.substr(1),
linkId = 'open-' + hash,
example = examples[hash];

if (example) {
explainGit.reset();
document.getElementById(linkId).classList.add('selected');
Expand All@@ -540,7 +540,7 @@ <h2>Specific Examples</h2>
elements[i].style.display = 'none';
}
document.getElementById('fork-me').style.display = 'none';

explainGit.reset();

explainGit.open({
Expand Down
2 changes: 1 addition & 1 deletion js/controlbox.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -239,7 +239,7 @@ define(['d3'], function () {

return;
}

while (args.length > 0) {
var arg = args.shift();

Expand Down
2 changes: 1 addition & 1 deletion js/explaingit.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,4 +71,4 @@ define(['historyview', 'controlbox', 'd3'], function (HistoryView, ControlBox, d
window.explainGit = explainGit;

return explainGit;
});
});
91 changes: 69 additions & 22 deletions js/historyview.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,18 +269,33 @@ define(['d3'], function () {
* @return {Object} the commit datum object
*/
getCommit: function getCommit(ref) {
// Optimization, doesn't seem to break anything
if (!ref) return null;

var commitData = this.commitData,
headMatcher = /HEAD(\^+)/.exec(ref),
matchedCommit = null;

var parts = /^([^\^\~]+)(.*)$/.exec(ref),
ref = parts[1],
modifier = parts[2];

if (ref === 'initial') {
return this.initialCommit;
}

if (headMatcher) {
if (ref.toLowerCase() === 'head') {
ref = 'HEAD';
}

var commitsThatStartWith = commitData
.filter(function(c) { return c.id.indexOf(ref) === 0})

if (commitsThatStartWith.length === 1) {
return commitsThatStartWith[0]
} else if (commitsThatStartWith.length > 1) {
throw new Error("Ref " + ref + " is ambiguous")
}

for (var i = 0; i < commitData.length; i++) {
var commit = commitData[i];
if (commit === ref) {
Expand All@@ -293,14 +308,14 @@ define(['d3'], function () {
break;
}

var matchedTag = function() {
var matchedTag = function() {
for (var j = 0; j < commit.tags.length; j++) {
var tag = commit.tags[j];
if (tag === ref) {
matchedCommit = commit;
return true;
}

if (tag.indexOf('[') === 0 && tag.indexOf(']') === tag.length - 1) {
tag = tag.substring(1, tag.length - 1);
}
Expand All@@ -315,10 +330,35 @@ define(['d3'], function () {
}
}

if (headMatcher && matchedCommit) {
for (var h = 0; h < headMatcher[1].length; h++) {
matchedCommit = getCommit.call(this, matchedCommit.parent);
if (matchedCommit && modifier) {
while(modifier) {
var nextToken = modifier[0]
modifier = modifier.substr(1)
var amountMatch = modifier.match(/^(\d+)(.*)$/),
amount = 1;

if (amountMatch) {
var amount = ~~amountMatch[1]
}

if (nextToken === '^') {
if (amount === 0) {
/* do nothing, refers to this commit */
} else if (amount === 1) {
matchedCommit = this.getCommit(matchedCommit.parent)
} else if (amount === 2) {
matchedCommit = this.getCommit(matchedCommit.parent2)
} else {
matchedCommit = null
}
} else if (nextToken === '~') {
for (var i = 0; i < amount; i++) {
if (matchedCommit && matchedCommit.parent) {
matchedCommit = this.getCommit(matchedCommit.parent)
}
}
}
}
}

return matchedCommit;
Expand DownExpand Up@@ -360,7 +400,7 @@ define(['d3'], function () {
svgContainer = container.append('div')
.classed('svg-container', true)
.classed('remote-container', this.isRemote);

svg = svgContainer.append('svg:svg');

svg.attr('id', this.name)
Expand DownExpand Up@@ -417,7 +457,7 @@ define(['d3'], function () {
preventOverlap(commit, this);
}
},

_resizeSvg: function() {
var ele = document.getElementById(this.svg.node().id);
var container = ele.parentNode;
Expand DownExpand Up@@ -453,7 +493,7 @@ define(['d3'], function () {
this._renderMergePointers();
this._renderIdLabels();
this._resizeSvg();
this.checkout(this.currentBranch);
this.currentBranch && this.checkout(this.currentBranch);
},

_renderCircles: function () {
Expand DownExpand Up@@ -726,8 +766,8 @@ define(['d3'], function () {
newTags.append('svg:text')
.text(function (d) {
if (d.name.indexOf('[') === 0 && d.name.indexOf(']') === d.name.length - 1)
return d.name.substring(1, d.name.length - 1);
return d.name;
return d.name.substring(1, d.name.length - 1);
return d.name;
})
.attr('y', function (d) {
return tagY(d, view) + 14;
Expand DownExpand Up@@ -815,19 +855,23 @@ define(['d3'], function () {

commit.message = message;
if (!commit.parent) {
if (!this.currentBranch) {
throw new Error('Not a good idea to make commits while in a detached HEAD state.');
}

commit.parent = this.getCommit(this.currentBranch).id;
commit.parent = this.getCommit('HEAD').id;
}

this.commitData.push(commit);
this.moveTag(this.currentBranch, commit.id);
if (this.currentBranch) {
this.moveTag(this.currentBranch, commit.id);
}

this.renderCommits();

this.checkout(this.currentBranch);
if (this.currentBranch) {
console.log('branch', this.currentBranch)
this.checkout(this.currentBranch);
} else {
console.log('commit', commit.id)
this.checkout(commit.id)
}
return this;
},

Expand DownExpand Up@@ -887,6 +931,7 @@ define(['d3'], function () {
},

checkout: function (ref) {
console.log("checking out", ref)
var commit = this.getCommit(ref);

if (!commit) {
Expand All@@ -900,7 +945,9 @@ define(['d3'], function () {
previousHead.classed('checked-out', false);
}

this._setCurrentBranch(ref === commit.id ? null : ref);
var startsWithCommit = commit.id.indexOf(ref) === 0
var startsWithHead = ref.toLowerCase().indexOf('head') === 0
this._setCurrentBranch(startsWithCommit || startsWithHead ? null : ref);
this.moveTag('HEAD', commit.id);
this.renderTags();

Expand DownExpand Up@@ -969,9 +1016,9 @@ define(['d3'], function () {
while (branchStartCommit.parent !== currentCommit.id) {
branchStartCommit = this.getCommit(branchStartCommit.parent);
}

branchStartCommit.isNoFFBranch = true;

this.commit({parent2: mergeTarget.id, isNoFFCommit: true});
} else if (this.isAncestor(currentCommit, mergeTarget)) {
this.fastForward(mergeTarget);
Expand Down
2 changes: 1 addition & 1 deletion js/main.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,4 +52,4 @@ require.config({
exports: 'd3'
}
}
});
});
2 changes: 1 addition & 1 deletion memtest.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,4 +41,4 @@ <h3><a id="start-test" href="#">Start Test</a></h3>
</script>
<h3><a href="index.html">Back to Home</a></h3>
</body>
</html>
</html>