v0.2.90
This commit is contained in:
1 parent
0abc8e871d
commit
4da41a1404
10 files changed
+458
-49
No files matched your search
+22
-1
@@ -116,13 +116,34 @@ export function authorshipOwners(model) {
|
||||
}
|
||||
|
||||
export function lineAuthors(content, model) {
|
||||
const spans = model?.spans || [];
|
||||
const starts = [0];
|
||||
for (let i = 0; i < content.length; i++) if (content.charCodeAt(i) === 10) starts.push(i + 1);
|
||||
|
||||
// Parsed authorship spans are sorted and non-overlapping. Retain the old
|
||||
// result for non-canonical callers instead of silently changing semantics.
|
||||
let canonical = true;
|
||||
for (let i = 0, previousEnd = 0; i < spans.length; i++) {
|
||||
const span = spans[i];
|
||||
if (!Number.isFinite(span?.start) || !Number.isFinite(span?.end)
|
||||
|| span.start < previousEnd || span.end < span.start) {
|
||||
canonical = false;
|
||||
break;
|
||||
}
|
||||
previousEnd = span.end;
|
||||
}
|
||||
|
||||
let cursor = 0;
|
||||
return starts.map((start, index) => {
|
||||
const end = index + 1 < starts.length ? starts[index + 1] : content.length;
|
||||
const totals = new Map();
|
||||
const representatives = new Map();
|
||||
for (const span of model?.spans || []) {
|
||||
if (canonical) {
|
||||
while (cursor < spans.length && spans[cursor].end <= start) cursor++;
|
||||
}
|
||||
for (let i = canonical ? cursor : 0; i < spans.length; i++) {
|
||||
const span = spans[i];
|
||||
if (canonical && span.start >= end) break;
|
||||
const overlap = Math.max(0, Math.min(end, span.end) - Math.max(start, span.start));
|
||||
if (!overlap) continue;
|
||||
const identity = ownerIdentity(span.owner);
|
||||
|
||||
Reference in new issue
Block a user