Comparing version 0.2.1 to 0.4.0
57
merge.js
@@ -0,1 +1,9 @@ | ||
var defaultRef = 'refs/heads/master' | ||
function compareRefs(a, b) { | ||
// prefer update where repoBranch is set. prefer newer updates | ||
return !!a.link.value.content.repoBranch - !!b.link.value.content.repoBranch | ||
|| a.link.value.timestamp - b.link.value.timestamp | ||
} | ||
module.exports = function mergeRepo(states, msg) { | ||
@@ -42,5 +50,5 @@ var obj = { | ||
var updates = refsUpdates[key][author] | ||
var maxSeq = -Infinity | ||
var maxRef | ||
for (var i = 0; i < updates.length; i++) { | ||
var maxSeq = updates[0].sequence | ||
var maxRef = updates[0].ref | ||
for (var i = 1; i < updates.length; i++) { | ||
var update = updates[i] | ||
@@ -54,3 +62,3 @@ if (update.sequence > maxSeq) { | ||
obj.author = author | ||
obj.sequence = update.sequence | ||
obj.sequence = maxSeq | ||
} | ||
@@ -66,3 +74,3 @@ | ||
var conflictRefname = refname.replace(/^refs\/[^\/]*/, function ($0) { | ||
return $0 + '/' + author | ||
return $0 + '/' + ref.link.key | ||
}) | ||
@@ -110,11 +118,36 @@ appendRef(conflictRefname, { | ||
if (!msg) { | ||
// at root, if a branch is in conflict and has no base, add one | ||
// i.e. there are prefixed conflict branches but no corresponding branch | ||
// without the prefix. this happens if an old client pushes to a repo and | ||
// doesn't set repoBranch or any link to previous updates | ||
var refsInConflict = {} | ||
for (var i = 0; i < obj.refs.length; i++) { | ||
var ref = obj.refs[i] | ||
if (ref.conflict) { | ||
var name = ref.realname | ||
var refs = refsInConflict[name] || (refsInConflict[name] = []) | ||
refs.push(ref) | ||
} | ||
} | ||
for (var name in refsInConflict) { | ||
var refs = refsInConflict[name] | ||
if (!(name in obj.refUpdates)) { | ||
// pick which ref should win as the base. | ||
var ref = refs.sort(compareRefs).pop() | ||
// transform prefixed branch into unprefixed branch | ||
var i = obj.refUpdates[name] = obj.refUpdates[ref.name] | ||
delete obj.refUpdates[ref.name] | ||
delete ref.realname | ||
ref.name = name | ||
} | ||
} | ||
} | ||
if (!c || !c.head || !obj.head || obj.refUpdates[obj.head] < 0) { | ||
// pick an existing branch to use as HEAD, preferring the default branch | ||
// or something starting with it | ||
var refNames = obj.refs.map(function (ref) { return ref.name }) | ||
obj.head = ['refs/heads/master'].concat(refNames, | ||
refNames.filter(function (name) { | ||
return /^refs\/heads\/(.*\/)?master$/.test(name) | ||
}) | ||
).pop() | ||
// or another unprefixed branch | ||
obj.head = obj.refUpdates[defaultRef] >= 0 ? defaultRef | ||
: obj.refs.filter(function (ref) { return !ref.realname}).concat(obj.refs) | ||
.map(function (ref) { return ref.name }).pop() || defaultRef | ||
} | ||
@@ -121,0 +154,0 @@ |
{ | ||
"name": "ssb-git", | ||
"version": "0.2.1", | ||
"version": "0.4.0", | ||
"description": "logic for working with git-ssb repos", | ||
"author": "Charles Lehner (http://celehner.com/)", | ||
"devDependencies": { | ||
"kvgraph": "^0.1.0", | ||
"tape": "^4.6.0" | ||
}, | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
}, | ||
"license": "Fair" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9752
4
319
2
1