Comparing version 0.2.0 to 0.2.1
61
merge.js
module.exports = function mergeRepo(states, msg) { | ||
var obj = { | ||
refs: [/* {name, hash} */], | ||
refUpdates: {/* key: index */}, | ||
branches: [] | ||
refs: [/* {name, hash, title, link} */], | ||
refUpdates: {/* key: index */} | ||
} | ||
@@ -14,9 +13,4 @@ | ||
var refsUpdates = {/* ref: {author: [{sequence, value}]} */} | ||
var refsUpdates = {/* name: {author: [{sequence, ref}]} */} | ||
states.forEach(function (state) { | ||
obj.branches.push(state.key) | ||
// conflict on head: pick one | ||
if (state.head) obj.head = state.head | ||
for (var name in state.refUpdates) { | ||
@@ -31,2 +25,15 @@ var i = state.refUpdates[name] | ||
for (var i = 0; i < states.length; i++) { | ||
var head = states[i].head | ||
if (head) { | ||
// ignore conflicting head values | ||
if (obj.head && obj.head !== head) { | ||
delete obj.head | ||
break | ||
} else { | ||
obj.head = head | ||
} | ||
} | ||
} | ||
for (var key in refsUpdates) { | ||
@@ -38,3 +45,3 @@ var items = [] | ||
var maxSeq = -Infinity | ||
var maxRef = null | ||
var maxRef | ||
for (var i = 0; i < updates.length; i++) { | ||
@@ -48,11 +55,8 @@ var update = updates[i] | ||
items.push(maxRef) | ||
obj.author = author | ||
obj.sequence = update.sequence | ||
} | ||
if (items.length === 1) { | ||
var ref = items[0] | ||
appendRef(key, ref && { | ||
hash: ref.hash, | ||
link: ref.link, | ||
title: ref.title, | ||
}) | ||
appendRef(key, items[0]) | ||
} else { | ||
@@ -90,20 +94,17 @@ for (var i = 0; i < items.length; i++) { | ||
if (c.refs) { | ||
obj.refs = obj.refs.filter(function (ref) { | ||
return !(ref.name in c.refs) | ||
}) | ||
for (var name in c.refs) { | ||
var hash = c.refs[name] | ||
appendRef(name, { | ||
hash: hash, | ||
link: msg, | ||
title: commitTitles[hash] | ||
}) | ||
if (!(name in obj.refUpdates)) { | ||
var hash = c.refs[name] | ||
appendRef(name, { | ||
hash: hash, | ||
link: msg, | ||
title: commitTitles[hash] | ||
}) | ||
} | ||
} | ||
} | ||
if (c.head) obj.head = c.head | ||
obj.author = msg.value.author | ||
obj.sequence = msg.value.sequence | ||
obj.key = msg.key | ||
if (!obj.head) obj.head = c.head | ||
if (!obj.author) obj.author = msg.value.author | ||
if (!obj.sequence) obj.sequence = msg.value.sequence | ||
} | ||
@@ -110,0 +111,0 @@ |
{ | ||
"name": "ssb-git", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "logic for working with git-ssb repos", | ||
@@ -5,0 +5,0 @@ "author": "Charles Lehner (http://celehner.com/)", |
@@ -22,7 +22,5 @@ # ssb-git | ||
refUpdates: {<ref>: integer}, | ||
branches: [MsgId], | ||
} | ||
``` | ||
- `branches`: head updates, suitable for `repoBranch` of a new git-update msg | ||
- `refs`: list of current refs and their values | ||
@@ -29,0 +27,0 @@ - `refUpdates`: index in `refs` of which refs are updated. index is -1 if the |
109
4482
42