@amalgm/live 0.2.81-preview.46147035832 → 0.2.81-preview.46155260343

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/git/plan.js CHANGED
@@ -1 +1 @@
1
- var O=Object.defineProperty;var n=(s,e)=>O(s,"name",{value:e,configurable:!0});import{fail as g,pass as $}from"../contracts/validate.js";import{gitBytesForm as F,gitOwnPath as M,isGitStoragePath as k}from"./state.js";import{compareGitText as B}from"./text.js";const r=n(s=>s.mode==="040000","isFolder"),P=n((s,e)=>s!==void 0&&s.mode===e.mode&&s.oid===e.oid,"same"),h=n((s,e)=>B(e.path,s.path),"deepestFirst");function T(s,e){if(s.format!==e.format)return g(`a ${s.format} repository cannot hold a ${e.format} state`);const m=F(e);if(m&&!F(s))return g("a state in byte form is reached from the state here read in byte form");const d=n(t=>!m&&k(t.path,e.home),"storage"),S=s.files.filter(t=>d(t)&&!r(t)).sort(h),i={...s,files:s.files.filter(t=>!d(t))},f=new Map(e.files.map(t=>[t.path,t])),v=new Set(i.files.filter(t=>f.has(t.path)&&r(f.get(t.path))!==r(t)).map(t=>t.path)),A=n(t=>{for(let a=t.length;a>0;a=t.lastIndexOf("/",a-1))if(v.has(t.slice(0,a)))return!0;return!1},"clashed"),u=[],p=[],x=new Map;for(const t of i.files)A(t.path)?u.push(t):f.has(t.path)?x.set(t.path,t):p.push(t);const l=e.files.filter(t=>!P(x.get(t.path),t)),w=n(t=>M(t.path)==="HEAD","isHead"),G=[...l.filter(r),...l.filter(t=>!r(t)&&!w(t)),...l.filter(w)],y=n(t=>t.index?.meaning??null,"meaning"),c=[];if(y(i)!==y(e)){const t=new Map(i.index?.files.map(o=>[o.path,o])),a=new Set(e.index?.files.map(o=>o.path));for(const o of e.index?.files??[])P(t.get(o.path),o)||c.push(o);const b=n(o=>+(M(o.path)==="index"),"last");c.sort((o,H)=>b(o)-b(H)),p.push(...i.index?.files.filter(o=>!a.has(o.path))??[])}return $({drop:S,clear:u.sort(h),writes:G,index:c,removals:p.sort(h)})}n(T,"gitApplyPlan");export{T as gitApplyPlan};
1
+ var O=Object.defineProperty;var n=(s,e)=>O(s,"name",{value:e,configurable:!0});import{fail as g,pass as $}from"../contracts/validate.js";import{gitBytesForm as F,gitOwnPath as M,isGitStoragePath as k}from"./state.js";import{compareGitText as B}from"./text.js";const r=n(s=>s.mode==="040000","isFolder"),P=n((s,e)=>s!==void 0&&s.mode===e.mode&&s.oid===e.oid,"same"),h=n((s,e)=>B(e.path,s.path),"deepestFirst");function T(s,e){if(s.format!==e.format)return g(`a ${s.format} repository cannot hold a ${e.format} state`);const m=F(e);if(m&&!F(s))return g("a state in byte form is reached only from the state here read in byte form");const d=n(t=>!m&&k(t.path,e.home),"storage"),S=s.files.filter(t=>d(t)&&!r(t)).sort(h),i={...s,files:s.files.filter(t=>!d(t))},f=new Map(e.files.map(t=>[t.path,t])),v=new Set(i.files.filter(t=>f.has(t.path)&&r(f.get(t.path))!==r(t)).map(t=>t.path)),A=n(t=>{for(let a=t.length;a>0;a=t.lastIndexOf("/",a-1))if(v.has(t.slice(0,a)))return!0;return!1},"clashed"),u=[],p=[],x=new Map;for(const t of i.files)A(t.path)?u.push(t):f.has(t.path)?x.set(t.path,t):p.push(t);const l=e.files.filter(t=>!P(x.get(t.path),t)),w=n(t=>M(t.path)==="HEAD","isHead"),G=[...l.filter(r),...l.filter(t=>!r(t)&&!w(t)),...l.filter(w)],y=n(t=>t.index?.meaning??null,"meaning"),c=[];if(y(i)!==y(e)){const t=new Map(i.index?.files.map(o=>[o.path,o])),a=new Set(e.index?.files.map(o=>o.path));for(const o of e.index?.files??[])P(t.get(o.path),o)||c.push(o);const b=n(o=>+(M(o.path)==="index"),"last");c.sort((o,H)=>b(o)-b(H)),p.push(...i.index?.files.filter(o=>!a.has(o.path))??[])}return $({drop:S,clear:u.sort(h),writes:G,index:c,removals:p.sort(h)})}n(T,"gitApplyPlan");export{T as gitApplyPlan};
package/dist/git/play.js CHANGED
@@ -1,4 +1,4 @@
1
- var se=Object.defineProperty;var r=(t,i)=>se(t,"name",{value:i,configurable:!0});import{utf8Decode as ie,utf8Encode as ae}from"../entities/bytes.js";import{GIT_ALTERNATES_PATH as fe}from"./alternates.js";import{gitBlobId as Z}from"./artifact.js";import{gitChainReflog as re,gitDropPackedRefs as ce,gitLooseRef as le,gitPackedRefs as de,gitReflogPlay as me,gitReflogTop as ee}from"./refs.js";import{gitBytesForm as ue,gitSelfHeld as he,gitSharesGitDir as ge,gitSharesObjects as pe,isGitOid as te}from"./state.js";import{compareGitText as H}from"./text.js";function we(t){return t.facets.some(f=>f==="create"||f==="retype"||f==="content")&&t.result.status==="active"?t.result.transportVersion:null}r(we,"gitOwnChange");function $e(t){let i=[],f=!1;for(const h of t){if(h.result.type!=="repo.git"){i=[],f=!0;continue}const d=we(h);d!==null&&i.push(d)}return{reached:i,ended:f}}r($e,"gitLineChanges");function Pe({line:t,basis:i,record:f}){const h=r(l=>l.files.find(c=>c.path===fe)?.oid??null,"borrowed"),d=r(l=>l.files.some(c=>c.path==="reftable"),"reftable");return t.format===f.format&&(i===null||i.format===f.format)&&!pe(t)&&!he(t.home)&&!ge(t.home)&&t.home?.entity===f.home?.entity&&t.home?.path===f.home?.path&&h(t)===h(f)&&![t,f,...i?[i]:[]].some(l=>d(l)||ue(l))}r(Pe,"gitPlayable");const O="040000",B=r(t=>new Map(t.map(i=>[i.path,i])),"byPath"),F=r((t,i)=>t===void 0?i===void 0:i!==void 0&&t.mode===i.mode&&t.oid===i.oid,"same"),N=r(t=>{const i=[];for(let f=t.indexOf("/");f>0;f=t.indexOf("/",f+1))i.push(t.slice(0,f));return i},"parents");function ke(t,i){const f=new Set;for(const d of t.keys()){const l=N(d).find(c=>t.has(c)&&t.get(c).mode!==O);l!==void 0&&f.add(l)}const h=r(d=>f.has(d)||N(d).some(l=>f.has(l)),"clashed");if(f.size>0){for(const d of[...t.keys()])h(d)&&t.delete(d);for(const[d,l]of i)h(d)&&t.set(d,l)}for(const d of[...t.keys()])for(const l of N(d))t.has(l)||t.set(l,{path:l,mode:O,oid:null});return[...t.values()].sort((d,l)=>H(d.path,l.path))}r(ke,"asTree");const x=["line","basis","record"],$=r(t=>t.mode!==O&&(t.path==="HEAD"||t.path.startsWith("refs/")),"isLooseRef"),ne=r(t=>$(t)||t.path==="packed-refs","isRefFile"),ye=r(t=>t.startsWith("logs/"),"isReflogPath"),j="refs/stash",V="refs/heads/",q=`${V}amalgm`,be=7,xe=/^[0-9a-f]{7,}$/,J=r((t,i)=>t.startsWith(`${i}/`),"beneath");async function Ie(t,i,f,h){const d={format:t.record.format,home:t.record.home,files:[],index:null},l={line:t.line,basis:t.basis??d,record:t.record},c={line:B(l.line.files),basis:B(l.basis.files),record:B(l.record.files)},D=new Map,A=r((e,n)=>{const o=ae(n),a=Z(o,h);return D.set(a,o),{path:e,mode:"100644",oid:a}},"make"),w=r(async e=>e?.oid?ie(D.get(e.oid)??await i(e.oid)):"","read"),P=new Map,I=r(e=>(P.has(e)||P.set(e,w(c[e].get("packed-refs")).then(de)),P.get(e)),"packedOf"),k=r(async(e,n)=>{const o=c[e].get(n);return o!==void 0&&$(o)?le(await w(o)):n==="HEAD"?null:(await I(e)).get(n)??null},"value"),M=r(e=>!F(c.basis.get(e),c.record.get(e)),"recordChanged"),u=new Map;for(const e of new Set([...c.line.keys(),...c.basis.keys(),...c.record.keys()])){const n=M(e)?c.record.get(e):c.line.get(e);n!==void 0&&u.set(e,n)}const T=new Set;for(const e of new Set(x.flatMap(n=>[...c[n].keys()]))){const[n,o,a]=x.map(s=>c[s].get(e));if(!(F(n,o)&&F(o,a)))if(e==="packed-refs")for(const s of x)for(const m of(await I(s)).keys())T.add(m);else[n,o,a].some(s=>s!==void 0&&$(s))&&T.add(e)}const K=r(async e=>{const[n,o,a]=x.map(s=>c[s].get(e));return[n,o,a].some(s=>s?.mode===O)?w(n):me(await w(o),await w(a),await w(n))},"playLog"),b=`logs/${j}`;let E=null;M(b)&&(E=re(await K(b)),E===""?u.delete(b):u.set(b,A(b,E)));const p=new Map,L=[];for(const e of[...T].sort(H)){const[n,o,a]=await Promise.all(x.map(m=>k(m,e)));let s=o!==a?a:n;if(e===j){if(E===null)continue;s=ee(E)}else e.startsWith(V)&&n!==null&&n!==o&&s!==n&&[n,a].every(m=>m===null||te(t.record.format,m))&&(a===null||!await f.builtOn(a,n))&&(s=n,a!==null&&!await f.builtOn(n,a)&&L.push({name:e,basis:o,record:a}));s!==n&&p.set(e,s)}const Q=[];if(L.length>0){const e=new Map;for(const o of new Set([...c.line.keys(),...(await I("line")).keys(),...p.keys()])){if(o!==q&&!J(o,q))continue;const a=p.has(o)?p.get(o):await k("line",o);a!==null&&e.set(o,a)}const n=r((o,a)=>(e.get(o)??a)===a&&![...e.keys()].some(s=>J(o,s)||J(s,o)),"free");for(const{name:o,basis:a,record:s}of L){const m=`${q}/${o.slice(V.length)}-`;let g=[...e.keys()].sort(H).find(y=>e.get(y)===a&&y.startsWith(m)&&xe.test(y.slice(m.length)));for(let y=be;g===void 0&&y<=s.length;y+=1)n(m+s.slice(0,y),s)&&(g=m+s.slice(0,y));g!==void 0&&(await k("line",g)!==s&&p.set(g,s),e.set(g,s),Q.push({branch:g,from:o,commit:s}))}}for(const[e,n]of[...u])ne(n)&&u.delete(e);for(const e of l.line.files)ne(e)&&u.set(e.path,e);const v=new Set;for(const[e,n]of p)n!==null?u.set(e,A(e,`${n}
2
- `)):(u.has(e)&&$(u.get(e))&&u.delete(e),v.add(e));const U=c.line.get("packed-refs");if(v.size>0&&U!==void 0){const e=await w(U),n=ce(e,v);n!==e&&u.set("packed-refs",A("packed-refs",n))}const C=r(e=>p.has(e)?Promise.resolve(p.get(e)):k("line",e),"final"),W=r(async(e,n)=>e?.startsWith("ref: ")?n(e.slice(5)):e,"commitOf"),S=await W(await C("HEAD"),C),R=new Set;for(const e of x)for(const n of c[e].keys())ye(n)&&n!==b&&R.add(n);for(const e of p.keys())e!==j&&R.add(`logs/${e}`);S!==await W(await k("line","HEAD"),e=>k("line",e))&&R.add("logs/HEAD");for(const e of[...R].sort(H)){const n=e.slice(5),o=n==="HEAD"?S:await C(n),a=M(e);if(!a&&(o===null||n!=="HEAD"&&!p.has(n)||!c.line.has(e)))continue;let s=a?await K(e):await w(c.line.get(e));const m=ee(s);if(o!==null&&m!==null&&m!==o&&te(t.record.format,o)){const g=s.trimEnd().split(`
3
- `).at(-1);s+=`${m} ${o}${g.slice(g.indexOf(" ",g.indexOf(" ")+1))}
4
- `}s===""?u.delete(e):u.set(e,A(e,s))}const G=r(e=>k(e,"HEAD").then(n=>W(n,o=>k(e,o))),"headOf"),X=await G("record"),oe=t.record.index?.meaning!==t.basis?.index?.meaning||X!==(t.basis===null?null:await G("basis")),[_,z]=oe?[t.record.index,X]:[t.line.index,await G("line")];let Y=_;if(_?.files.length===1&&z!==null&&S!==null&&z!==S){const e=await f.carryIndex(await i(_.files[0].oid),z,S);if(e!==null){const n=e.bytes,o=Z(n,h);D.set(o,n),Y={meaning:e.meaning,files:[{path:"index",mode:"100644",oid:o}]}}}return{state:{format:t.record.format,home:t.record.home,files:ke(u,c.record),index:Y},made:D,aside:Q}}r(Ie,"gitPlayRecord");export{$e as gitLineChanges,we as gitOwnChange,Ie as gitPlayRecord,Pe as gitPlayable};
1
+ var se=Object.defineProperty;var f=(t,i)=>se(t,"name",{value:i,configurable:!0});import{utf8Decode as ie,utf8Encode as ae}from"../entities/bytes.js";import{GIT_ALTERNATES_PATH as re}from"./alternates.js";import{gitBlobId as Y}from"./artifact.js";import{gitChainReflog as fe,gitDropPackedRefs as ce,gitLooseRef as le,gitPackedRefs as de,gitReflogPlay as me,gitReflogTop as Z}from"./refs.js";import{gitBytesForm as ue,gitSelfHeld as he,gitSharesGitDir as ge,gitSharesObjects as pe,gitTreeOf as we,isGitOid as ee}from"./state.js";import{compareGitText as _}from"./text.js";function ye(t){return t.facets.some(c=>c==="create"||c==="retype"||c==="content")&&t.result.status==="active"?t.result.transportVersion:null}f(ye,"gitOwnChange");function Pe(t){let i=[],c=!1;for(const u of t){if(u.result.type!=="repo.git"){i=[],c=!0;continue}const p=ye(u);p!==null&&i.push(p)}return{reached:i,ended:c}}f(Pe,"gitLineChanges");function Te({line:t,basis:i,record:c}){const u=f(l=>l.files.find(a=>a.path===re)?.oid??null,"borrowed"),p=f(l=>l.files.some(a=>a.path==="reftable"),"reftable");return t.format===c.format&&(i===null||i.format===c.format)&&!pe(t)&&!he(t.home)&&!ge(t.home)&&t.home?.entity===c.home?.entity&&t.home?.path===c.home?.path&&u(t)===u(c)&&![t,c,...i?[i]:[]].some(l=>p(l)||ue(l))}f(Te,"gitPlayable");const z="040000",B=f(t=>new Map(t.map(i=>[i.path,i])),"byPath"),F=f((t,i)=>t===void 0?i===void 0:i!==void 0&&t.mode===i.mode&&t.oid===i.oid,"same"),te=f(t=>{const i=[];for(let c=t.indexOf("/");c>0;c=t.indexOf("/",c+1))i.push(t.slice(0,c));return i},"parents");function ke(t,i,c){const u=new Set;for(const l of t.keys()){const a=te(l).find(b=>t.has(b)&&t.get(b).mode!==z);a!==void 0&&u.add(a)}const p=f(l=>u.has(l)||te(l).some(a=>u.has(a)),"clashed");if(u.size>0){for(const l of[...t.keys()])p(l)&&t.delete(l);for(const[l,a]of i)p(l)&&t.set(l,a)}return we(t.values(),c)}f(ke,"asTree");const E=["line","basis","record"],R=f(t=>t.mode!==z&&(t.path==="HEAD"||t.path.startsWith("refs/")),"isLooseRef"),ne=f(t=>R(t)||t.path==="packed-refs","isRefFile"),be=f(t=>t.startsWith("logs/"),"isReflogPath"),N="refs/stash",j="refs/heads/",V=`${j}amalgm`,xe=7,Ee=/^[0-9a-f]{7,}$/,q=f((t,i)=>t.startsWith(`${i}/`),"beneath");async function Ie(t,i,c,u){const p={format:t.record.format,home:t.record.home,files:[],index:null},l={line:t.line,basis:t.basis??p,record:t.record},a={line:B(l.line.files),basis:B(l.basis.files),record:B(l.record.files)},b=new Map,A=f((e,n)=>{const o=ae(n),r=Y(o,u);return b.set(r,o),{path:e,mode:"100644",oid:r}},"make"),w=f(async e=>e?.oid?ie(b.get(e.oid)??await i(e.oid)):"","read"),H=new Map,$=f(e=>(H.has(e)||H.set(e,w(a[e].get("packed-refs")).then(de)),H.get(e)),"packedOf"),y=f(async(e,n)=>{const o=a[e].get(n);return o!==void 0&&R(o)?le(await w(o)):n==="HEAD"?null:(await $(e)).get(n)??null},"value"),P=f(e=>!F(a.basis.get(e),a.record.get(e)),"recordChanged"),m=new Map;for(const e of new Set([...a.line.keys(),...a.basis.keys(),...a.record.keys()])){const n=P(e)?a.record.get(e):a.line.get(e);n!==void 0&&m.set(e,n)}const T=new Set;for(const e of new Set(E.flatMap(n=>[...a[n].keys()]))){const[n,o,r]=E.map(s=>a[s].get(e));if(!(F(n,o)&&F(o,r)))if(e==="packed-refs")for(const s of E)for(const d of(await $(s)).keys())T.add(d);else[n,o,r].some(s=>s!==void 0&&R(s))&&T.add(e)}const J=f(async e=>{const[n,o,r]=E.map(s=>a[s].get(e));return[n,o,r].some(s=>s?.mode===z)?w(n):me(await w(o),await w(r),await w(n))},"playLog"),x=`logs/${N}`;let S=null;P(x)&&(S=fe(await J(x)),S===""?m.delete(x):m.set(x,A(x,S)));const g=new Map,I=[];for(const e of[...T].sort(_)){const[n,o,r]=await Promise.all(E.map(d=>y(d,e)));let s=o!==r?r:n;if(e===N){if(S===null)continue;s=Z(S)}else e.startsWith(j)&&n!==null&&n!==o&&s!==n&&[n,r].every(d=>d===null||ee(t.record.format,d))&&(r===null||!await c.builtOn(r,n))&&(s=n,r!==null&&!await c.builtOn(n,r)&&I.push({name:e,basis:o,record:r}));s!==n&&g.set(e,s)}const K=[];if(I.length>0){const e=new Map;for(const o of new Set([...a.line.keys(),...(await $("line")).keys(),...g.keys()])){if(o!==V&&!q(o,V))continue;const r=g.has(o)?g.get(o):await y("line",o);r!==null&&e.set(o,r)}const n=f((o,r)=>(e.get(o)??r)===r&&![...e.keys()].some(s=>q(o,s)||q(s,o)),"free");for(const{name:o,basis:r,record:s}of I){const d=`${V}/${o.slice(j.length)}-`;let h=[...e.keys()].sort(_).find(k=>e.get(k)===r&&k.startsWith(d)&&Ee.test(k.slice(d.length)));for(let k=xe;h===void 0&&k<=s.length;k+=1)n(d+s.slice(0,k),s)&&(h=d+s.slice(0,k));h!==void 0&&(await y("line",h)!==s&&g.set(h,s),e.set(h,s),K.push({branch:h,from:o,commit:s}))}}for(const[e,n]of[...m])ne(n)&&m.delete(e);for(const e of l.line.files)ne(e)&&m.set(e.path,e);const M=new Set;for(const[e,n]of g)n!==null?m.set(e,A(e,`${n}
2
+ `)):(m.has(e)&&R(m.get(e))&&m.delete(e),M.add(e));const Q=a.line.get("packed-refs");if(M.size>0&&Q!==void 0){const e=await w(Q),n=ce(e,M);n!==e&&m.set("packed-refs",A("packed-refs",n))}const L=f(e=>g.has(e)?Promise.resolve(g.get(e)):y("line",e),"final"),v=f(async(e,n)=>e?.startsWith("ref: ")?n(e.slice(5)):e,"commitOf"),D=await v(await L("HEAD"),L),O=new Set;for(const e of E)for(const n of a[e].keys())be(n)&&n!==x&&O.add(n);for(const e of g.keys())e!==N&&O.add(`logs/${e}`);D!==await v(await y("line","HEAD"),e=>y("line",e))&&O.add("logs/HEAD");for(const e of[...O].sort(_)){const n=e.slice(5),o=n==="HEAD"?D:await L(n),r=P(e);if(!r&&(o===null||n!=="HEAD"&&!g.has(n)||!a.line.has(e)))continue;let s=r?await J(e):await w(a.line.get(e));const d=Z(s);if(o!==null&&d!==null&&d!==o&&ee(t.record.format,o)){const h=s.trimEnd().split(`
3
+ `).at(-1);s+=`${d} ${o}${h.slice(h.indexOf(" ",h.indexOf(" ")+1))}
4
+ `}s===""?m.delete(e):m.set(e,A(e,s))}const C=f(e=>y(e,"HEAD").then(n=>v(n,o=>y(e,o))),"headOf"),U=await C("record"),oe=t.record.index?.meaning!==t.basis?.index?.meaning||U!==(t.basis===null?null:await C("basis")),[W,G]=oe?[t.record.index,U]:[t.line.index,await C("line")];let X=W;if(W?.files.length===1&&G!==null&&D!==null&&G!==D){const e=await c.carryIndex(await i(W.files[0].oid),G,D);if(e!==null){const n=e.bytes,o=Y(n,u);b.set(o,n),X={meaning:e.meaning,files:[{path:"index",mode:"100644",oid:o}]}}}return{state:{format:t.record.format,home:t.record.home,files:ke(m,a.record,t.record.home),index:X},made:b,aside:K}}f(Ie,"gitPlayRecord");export{Pe as gitLineChanges,ye as gitOwnChange,Ie as gitPlayRecord,Te as gitPlayable};
@@ -1,2 +1,2 @@
1
- var I=Object.defineProperty;var r=(o,n)=>I(o,"name",{value:n,configurable:!0});import{fail as f,pass as A}from"../contracts/validate.js";import{utf8Decode as B,utf8Encode as E}from"../entities/bytes.js";import{gitBlobId as W}from"./artifact.js";import{GIT_PACKED_REFS as l,gitOwnFile as j,gitOwnRef as c}from"./parts.js";import{gitDropPackedRefs as q,gitPackedRefs as m}from"./refs.js";import{checkGitState as C,gitBytesForm as H,gitSelfHeld as K}from"./state.js";import{compareGitText as L}from"./text.js";const T=/^(rebase-merge|rebase-apply|sequencer)(\/|$)/,p=r(o=>o.mode==="040000","isFolder"),$=r(o=>c(o)||j(o),"restored");function Z(o,n,v,x){for(const t of[o,n]){if(H(t))return f("a repository in byte form cannot be restored");if(t.files.some(e=>e.path.startsWith("reftable/")))return f("a reftable repository cannot be restored");if(K(t.home))return f("a worktree of storage outside every folder cannot be restored")}if(o.format!==n.format)return f(`a ${o.format} repository cannot take a ${n.format} version`);const d=new Map,h=r((t,e)=>{const a=W(e,x);return d.set(a,e),{path:t,mode:"100644",oid:a}},"blob"),u=r(t=>t.files.find(e=>e.path===l),"packed"),k=r(t=>{const e=u(t);return e===void 0?null:B(v(e.oid))},"packedText"),i=k(o),g=k(n),b=g===null?new Map:m(g),w=r((t,e)=>new Set([...t.files.filter(a=>!p(a)&&c(a.path)).map(a=>a.path),...[...e.keys()].filter(c)]),"ownRefs"),F=w(n,b),G=new Set([...w(o,i===null?new Map:m(i))].filter(t=>!F.has(t)).map(t=>`logs/${t}`)),s=new Map;for(const[t,e]of b)c(t)&&s.set(t,h(t,E(`${e}
2
- `)));for(const t of n.files)(p(t)?T.test(t.path):$(t.path))&&s.set(t.path,t);if(i!==null){const t=q(i,new Set([...m(i).keys()].filter(c)));s.set(l,t===i?u(o):h(l,E(t)))}const y=r(t=>{const e=t.split("/");return e.slice(1).map((a,D)=>e.slice(0,D+1).join("/"))},"ancestors"),R=new Set([...s.keys()].flatMap(y)),O=r(t=>s.has(t.path)||!p(t)&&R.has(t.path)||y(t.path).some(e=>s.has(e)&&!p(s.get(e))),"inTheWay");for(const t of o.files)(p(t)?!T.test(t.path):t.path!==l&&!$(t.path)&&!G.has(t.path))&&!O(t)&&s.set(t.path,t);for(const t of R)s.has(t)||s.set(t,{path:t,mode:"040000",oid:null});const M=[...s.values()].sort((t,e)=>L(t.path,e.path)),P={...o,files:M,index:n.index},S=C(P);if(!S.ok)return f(`the version cannot stand over this repository: ${S.error}`);const _=new Map(M.flatMap(t=>d.has(t.oid)?[[t.oid,d.get(t.oid)]]:[]));return A({state:P,blobs:_})}r(Z,"gitRestoreGoal");export{Z as gitRestoreGoal};
1
+ var I=Object.defineProperty;var s=(o,n)=>I(o,"name",{value:n,configurable:!0});import{fail as f,pass as A}from"../contracts/validate.js";import{utf8Decode as B,utf8Encode as S}from"../entities/bytes.js";import{gitBlobId as W}from"./artifact.js";import{GIT_PACKED_REFS as l,gitOwnFile as j,gitOwnRef as c}from"./parts.js";import{gitDropPackedRefs as q,gitPackedRefs as m}from"./refs.js";import{checkGitState as C,gitBytesForm as H,gitSelfHeld as K,gitTreeOf as L}from"./state.js";const E=/^(rebase-merge|rebase-apply|sequencer)(\/|$)/,p=s(o=>o.mode==="040000","isFolder"),T=s(o=>c(o)||j(o),"restored");function Y(o,n,$,v){for(const t of[o,n]){if(H(t))return f("a repository in byte form cannot be restored");if(t.files.some(e=>e.path.startsWith("reftable/")))return f("a reftable repository cannot be restored");if(K(t.home))return f("a worktree of storage outside every folder cannot be restored")}if(o.format!==n.format)return f(`a ${o.format} repository cannot take a ${n.format} version`);const d=new Map,u=s((t,e)=>{const a=W(e,v);return d.set(a,e),{path:t,mode:"100644",oid:a}},"blob"),h=s(t=>t.files.find(e=>e.path===l),"packed"),k=s(t=>{const e=h(t);return e===void 0?null:B($(e.oid))},"packedText"),i=k(o),g=k(n),b=g===null?new Map:m(g),w=s((t,e)=>new Set([...t.files.filter(a=>!p(a)&&c(a.path)).map(a=>a.path),...[...e.keys()].filter(c)]),"ownRefs"),O=w(n,b),x=new Set([...w(o,i===null?new Map:m(i))].filter(t=>!O.has(t)).map(t=>`logs/${t}`)),r=new Map;for(const[t,e]of b)c(t)&&r.set(t,u(t,S(`${e}
2
+ `)));for(const t of n.files)(p(t)?E.test(t.path):T(t.path))&&r.set(t.path,t);if(i!==null){const t=q(i,new Set([...m(i).keys()].filter(c)));r.set(l,t===i?h(o):u(l,S(t)))}const y=s(t=>{const e=t.split("/");return e.slice(1).map((a,G)=>e.slice(0,G+1).join("/"))},"ancestors"),F=new Set([...r.keys()].flatMap(y)),_=s(t=>r.has(t.path)||!p(t)&&F.has(t.path)||y(t.path).some(e=>r.has(e)&&!p(r.get(e))),"inTheWay");for(const t of o.files)(p(t)?!E.test(t.path):t.path!==l&&!T(t.path)&&!x.has(t.path))&&!_(t)&&r.set(t.path,t);const R=L(r.values(),o.home),M={...o,files:R,index:n.index},P=C(M);if(!P.ok)return f(`the version cannot stand over this repository: ${P.error}`);const D=new Map(R.flatMap(t=>d.has(t.oid)?[[t.oid,d.get(t.oid)]]:[]));return A({state:M,blobs:D})}s(Y,"gitRestoreGoal");export{Y as gitRestoreGoal};
@@ -30,6 +30,7 @@ export declare const isGitIndexPath: (path: string) => boolean;
30
30
  export declare const isGitConfigurationPath: (path: string) => boolean;
31
31
  export declare function isGitStatePath(path: string, home: GitHome | null, bytes?: boolean): boolean;
32
32
  export declare const gitBytesForm: (state: GitState) => boolean;
33
+ export declare function gitTreeOf(files: Iterable<GitFile>, home: GitHome | null): GitFile[];
33
34
  export declare const isGitStoragePath: (path: string, home: GitHome | null) => boolean;
34
35
  export declare const gitSharesObjects: (state: GitState) => boolean;
35
36
  export declare const isGitNamingPath: (path: string) => boolean;
package/dist/git/state.js CHANGED
@@ -1,3 +1,3 @@
1
- var b=Object.defineProperty;var n=(t,e)=>b(t,"name",{value:e,configurable:!0});import{isLocalOnlyPath as _}from"@amalgm/core/identity";import{failShape as P,isRecord as m,pass as u}from"../contracts/validate.js";import{utf8Decode as $,utf8Encode as j}from"../entities/bytes.js";import{UUID_PATTERN as D}from"../entities/types.js";import{GIT_ALTERNATES_PATH as H}from"./alternates.js";import{compareGitText as I}from"./text.js";const L=["040000","100644","100755","120000"],N={sha1:40,sha256:64},E=n((t,e)=>typeof e=="string"&&e.length===N[t]&&/^[0-9a-f]+$/.test(e),"isGitOid"),S=n(t=>E("sha256",t),"isDigest"),l=n(t=>t!==null&&t.entity===null,"gitSelfHeld"),O=n(t=>t!==null&&t.entity!==null&&t.path==="","gitSharesGitDir"),p=n(t=>t.replace(/^worktrees\/[^/]+\//,""),"gitOwnPath"),k=n(t=>t.split("/").some(e=>e.endsWith(".lock")),"isGitLockPath"),g=n(t=>(e=>e==="index"||/^sharedindex\.[0-9a-f]+$/.test(e))(p(t)),"isGitIndexPath"),z=n(t=>["config","config.worktree"].includes(p(t)),"isGitConfigurationPath"),w=["worktrees","modules"],M=["objects",...w],x=n((t,e)=>t===H||t!=="gitdir"&&!(e?w:M).some(i=>t===i||t.startsWith(`${i}/`)),"isOwnStatePath");function c(t,e,i=!1){if(O(e)||_(t)||k(t))return!1;if(!l(e))return x(t,i);const s=e.path;return t==="worktrees"||t===s?!0:t.startsWith(`${s}/`)?x(t.slice(s.length+1),i):x(t,i)&&!g(t)}n(c,"isGitStatePath");const G=n(t=>t.some(e=>m(e)&&e.path==="objects"&&e.mode==="040000"),"listsObjects"),K=n(t=>G(t.files),"gitBytesForm"),Q=n((t,e)=>c(t,e,!0)&&!c(t,e),"isGitStoragePath"),Y=n(t=>!l(t.home)&&(t.home?.path.startsWith("worktrees/")??!1),"gitSharesObjects"),W=new Set(["AUTO_MERGE","BISECT_EXPECTED_REV","MERGE_AUTOSTASH","NOTES_MERGE_PARTIAL","NOTES_MERGE_REF"]),v=n(t=>(e=>/^[A-Z_-]+_HEAD$/.test(e)||W.has(e)||/^rebase-(apply|merge)\/(autostash|orig-head)$/.test(e))(p(t)),"isGitNamingPath"),tt=n((t,e)=>$(e).split(`
2
- `).map(i=>i.split(/[\t ]/,1)[0]).filter(i=>E(t,i)),"gitNamedObjects"),y=n(t=>typeof t=="string"&&t.length>0&&!t.includes("\0")&&t.split("/").every(e=>e!==""&&e!=="."&&e!==".."),"isPath");function et(t){const e=new Set;for(const i of[...t.files,...t.index?.files??[]])i.oid!==null&&e.add(i.oid);return e}n(et,"gitBlobs");const F='{ format: "sha1", home: { entity: <uuid>, path: "worktrees/<name>" | "modules/<name>" | "" } | { entity: null, path: "worktrees/<name>" } | null, files: [{ path: "HEAD", mode: "100644", oid: <sha256> }], index: { meaning: <sha256>, files: [...] } | null }',A=n(t=>typeof t=="string"&&/^worktrees\/[^/]+$/.test(t),"isWorktreeHome"),U=n(t=>m(t)&&Object.keys(t).length===2&&(t.entity===null?y(t.path)&&A(t.path):typeof t.entity=="string"&&D.test(t.entity)&&t.entity===t.entity.toLowerCase()&&(t.path===""||y(t.path)&&(A(t.path)||t.path.startsWith("modules/")))),"isGitHome");function T(t,e,i,s,r){if(!Array.isArray(t))return"not a list";for(const[h,o]of t.entries()){if(m(o)&&typeof o.path=="string"&&k(o.path))return`${o.path} is a lock, a write in progress, never state`;if(!m(o)||Object.keys(o).length!==3||!y(o.path)||!s(o.path))return`entry ${h} is not one { path, mode, oid } this list owns`;if(h>0&&I(t[h-1].path,o.path)>=0)return"paths are not sorted and unique";if(!L.includes(o.mode)||(o.mode==="040000"?o.oid!==null:!S(o.oid)))return`${o.path} is not a folder without a blob or a file, executable or link naming one`;const f=o.path.slice(0,Math.max(0,o.path.lastIndexOf("/")));if(f!==""&&c(f,e,i)&&!r.has(f))return`${o.path} stands in no listed folder`;o.mode==="040000"&&r.add(o.path)}return t}n(T,"checkFiles");function nt(t){const e=n(a=>P(F,a),"bad");if(!m(t)||Object.keys(t).length!==4)return e("the state is not { format, home, files, index }");const{format:i,index:s}=t;if(i!=="sha1"&&i!=="sha256")return e("format is not sha1 or sha256");if(t.home!==null&&!U(t.home))return e("home is not null or { entity, path } naming worktrees/, modules/ or, with an entity, nothing, with no entity only for worktrees/");const r=t.home&&{entity:t.home.entity,path:t.home.path},h=new Set,o=Array.isArray(t.files)&&G(t.files),f=T(t.files,r,o,a=>c(a,r,o)&&!g(a),h);if(typeof f=="string")return e(`files: ${f}`);if(s===null)return u({format:i,home:r,files:f,index:null});if(O(r))return e("a state that shares its owner's Git directory has an index");if(!m(s)||Object.keys(s).length!==2||!S(s.meaning))return e("index is not null or { meaning, files }");const d=T(s.files,r,o,a=>c(a,r)&&g(a),h);if(typeof d=="string")return e(`index files: ${d}`);const R=l(r)?`${r.path}/index`:"index";return!d.some(a=>a.path===R)||d.some(a=>a.mode!=="100644")?e("index files are not plain files including index"):u({format:i,home:r,files:f,index:{meaning:s.meaning,files:d}})}n(nt,"checkGitState");function it(t){const e=n(i=>i.map(s=>({path:s.path,mode:s.mode,oid:s.oid})),"files");return{format:t.format,home:t.home&&{entity:t.home.entity,path:t.home.path},files:e(t.files),index:t.index&&{meaning:t.index.meaning,files:e(t.index.files)}}}n(it,"gitStateJson");const ot=n((t,e)=>e(j(`amalgm.git-state.v3
3
- ${JSON.stringify({format:t.format,home:t.home&&[t.home.entity,t.home.path],files:t.files.map(i=>[i.path,i.mode,i.oid]),index:t.index?.meaning??null})}`)),"gitStateId");export{nt as checkGitState,et as gitBlobs,K as gitBytesForm,tt as gitNamedObjects,p as gitOwnPath,l as gitSelfHeld,O as gitSharesGitDir,Y as gitSharesObjects,ot as gitStateId,it as gitStateJson,z as isGitConfigurationPath,U as isGitHome,g as isGitIndexPath,k as isGitLockPath,v as isGitNamingPath,E as isGitOid,c as isGitStatePath,Q as isGitStoragePath};
1
+ var _=Object.defineProperty;var i=(t,e)=>_(t,"name",{value:e,configurable:!0});import{isLocalOnlyPath as P}from"@amalgm/core/identity";import{failShape as $,isRecord as c,pass as u}from"../contracts/validate.js";import{utf8Decode as j,utf8Encode as D}from"../entities/bytes.js";import{UUID_PATTERN as H}from"../entities/types.js";import{GIT_ALTERNATES_PATH as I}from"./alternates.js";import{compareGitText as E}from"./text.js";const L=["040000","100644","100755","120000"],M={sha1:40,sha256:64},O=i((t,e)=>typeof e=="string"&&e.length===M[t]&&/^[0-9a-f]+$/.test(e),"isGitOid"),S=i(t=>O("sha256",t),"isDigest"),m=i(t=>t!==null&&t.entity===null,"gitSelfHeld"),k=i(t=>t!==null&&t.entity!==null&&t.path==="","gitSharesGitDir"),p=i(t=>t.replace(/^worktrees\/[^/]+\//,""),"gitOwnPath"),w=i(t=>t.split("/").some(e=>e.endsWith(".lock")),"isGitLockPath"),g=i(t=>(e=>e==="index"||/^sharedindex\.[0-9a-f]+$/.test(e))(p(t)),"isGitIndexPath"),z=i(t=>["config","config.worktree"].includes(p(t)),"isGitConfigurationPath"),G=["worktrees","modules"],N=["objects",...G],x=i((t,e)=>t===I||t!=="gitdir"&&!(e?G:N).some(n=>t===n||t.startsWith(`${n}/`)),"isOwnStatePath");function d(t,e,n=!1){if(k(e)||P(t)||w(t))return!1;if(!m(e))return x(t,n);const o=e.path;return t==="worktrees"||t===o?!0:t.startsWith(`${o}/`)?x(t.slice(o.length+1),n):x(t,n)&&!g(t)}i(d,"isGitStatePath");const T=i(t=>t.some(e=>c(e)&&e.path==="objects"&&e.mode==="040000"),"listsObjects"),K=i(t=>T(t.files),"gitBytesForm");function Q(t,e){const n=new Map;for(const o of t)n.set(o.path,o);for(const o of[...n.keys()])for(let r=o.indexOf("/");r>0;r=o.indexOf("/",r+1)){const a=o.slice(0,r);!n.has(a)&&d(a,e)&&n.set(a,{path:a,mode:"040000",oid:null})}return[...n.values()].sort((o,r)=>E(o.path,r.path))}i(Q,"gitTreeOf");const Y=i((t,e)=>d(t,e,!0)&&!d(t,e),"isGitStoragePath"),v=i(t=>!m(t.home)&&(t.home?.path.startsWith("worktrees/")??!1),"gitSharesObjects"),W=new Set(["AUTO_MERGE","BISECT_EXPECTED_REV","MERGE_AUTOSTASH","NOTES_MERGE_PARTIAL","NOTES_MERGE_REF"]),tt=i(t=>(e=>/^[A-Z_-]+_HEAD$/.test(e)||W.has(e)||/^rebase-(apply|merge)\/(autostash|orig-head)$/.test(e))(p(t)),"isGitNamingPath"),et=i((t,e)=>j(e).split(`
2
+ `).map(n=>n.split(/[\t ]/,1)[0]).filter(n=>O(t,n)),"gitNamedObjects"),y=i(t=>typeof t=="string"&&t.length>0&&!t.includes("\0")&&t.split("/").every(e=>e!==""&&e!=="."&&e!==".."),"isPath");function nt(t){const e=new Set;for(const n of[...t.files,...t.index?.files??[]])n.oid!==null&&e.add(n.oid);return e}i(nt,"gitBlobs");const F='{ format: "sha1", home: { entity: <uuid>, path: "worktrees/<name>" | "modules/<name>" | "" } | { entity: null, path: "worktrees/<name>" } | null, files: [{ path: "HEAD", mode: "100644", oid: <sha256> }], index: { meaning: <sha256>, files: [...] } | null }',A=i(t=>typeof t=="string"&&/^worktrees\/[^/]+$/.test(t),"isWorktreeHome"),U=i(t=>c(t)&&Object.keys(t).length===2&&(t.entity===null?y(t.path)&&A(t.path):typeof t.entity=="string"&&H.test(t.entity)&&t.entity===t.entity.toLowerCase()&&(t.path===""||y(t.path)&&(A(t.path)||t.path.startsWith("modules/")))),"isGitHome");function R(t,e,n,o,r){if(!Array.isArray(t))return"not a list";for(const[a,s]of t.entries()){if(c(s)&&typeof s.path=="string"&&w(s.path))return`${s.path} is a lock, a write in progress, never state`;if(!c(s)||Object.keys(s).length!==3||!y(s.path)||!o(s.path))return`entry ${a} is not one { path, mode, oid } this list owns`;if(a>0&&E(t[a-1].path,s.path)>=0)return"paths are not sorted and unique";if(!L.includes(s.mode)||(s.mode==="040000"?s.oid!==null:!S(s.oid)))return`${s.path} is not a folder without a blob or a file, executable or link naming one`;const h=s.path.slice(0,Math.max(0,s.path.lastIndexOf("/")));if(h!==""&&d(h,e,n)&&!r.has(h))return`${s.path} stands in no listed folder`;s.mode==="040000"&&r.add(s.path)}return t}i(R,"checkFiles");function it(t){const e=i(f=>$(F,f),"bad");if(!c(t)||Object.keys(t).length!==4)return e("the state is not { format, home, files, index }");const{format:n,index:o}=t;if(n!=="sha1"&&n!=="sha256")return e("format is not sha1 or sha256");if(t.home!==null&&!U(t.home))return e("home is not null or { entity, path } naming worktrees/, modules/ or, with an entity, nothing, with no entity only for worktrees/");const r=t.home&&{entity:t.home.entity,path:t.home.path},a=new Set,s=Array.isArray(t.files)&&T(t.files),h=R(t.files,r,s,f=>d(f,r,s)&&!g(f),a);if(typeof h=="string")return e(`files: ${h}`);if(o===null)return u({format:n,home:r,files:h,index:null});if(k(r))return e("a state that shares its owner's Git directory has an index");if(!c(o)||Object.keys(o).length!==2||!S(o.meaning))return e("index is not null or { meaning, files }");const l=R(o.files,r,s,f=>d(f,r)&&g(f),a);if(typeof l=="string")return e(`index files: ${l}`);const b=m(r)?`${r.path}/index`:"index";return!l.some(f=>f.path===b)||l.some(f=>f.mode!=="100644")?e("index files are not plain files including index"):u({format:n,home:r,files:h,index:{meaning:o.meaning,files:l}})}i(it,"checkGitState");function ot(t){const e=i(n=>n.map(o=>({path:o.path,mode:o.mode,oid:o.oid})),"files");return{format:t.format,home:t.home&&{entity:t.home.entity,path:t.home.path},files:e(t.files),index:t.index&&{meaning:t.index.meaning,files:e(t.index.files)}}}i(ot,"gitStateJson");const st=i((t,e)=>e(D(`amalgm.git-state.v3
3
+ ${JSON.stringify({format:t.format,home:t.home&&[t.home.entity,t.home.path],files:t.files.map(n=>[n.path,n.mode,n.oid]),index:t.index?.meaning??null})}`)),"gitStateId");export{it as checkGitState,nt as gitBlobs,K as gitBytesForm,et as gitNamedObjects,p as gitOwnPath,m as gitSelfHeld,k as gitSharesGitDir,v as gitSharesObjects,st as gitStateId,ot as gitStateJson,Q as gitTreeOf,z as isGitConfigurationPath,U as isGitHome,g as isGitIndexPath,w as isGitLockPath,tt as isGitNamingPath,O as isGitOid,d as isGitStatePath,Y as isGitStoragePath};
@@ -1 +1 @@
1
- "use strict";var q=Object.defineProperty;var a=(e,s)=>q(e,"name",{value:s,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitApplyPlan=S;const h=require("../contracts/validate.js"),r=require("./state.js"),A=require("./text.js"),l=a(e=>e.mode==="040000","isFolder"),b=a((e,s)=>e!==void 0&&e.mode===s.mode&&e.oid===s.oid,"same"),m=a((e,s)=>(0,A.compareGitText)(s.path,e.path),"deepestFirst");function S(e,s){if(e.format!==s.format)return(0,h.fail)(`a ${e.format} repository cannot hold a ${s.format} state`);const u=(0,r.gitBytesForm)(s);if(u&&!(0,r.gitBytesForm)(e))return(0,h.fail)("a state in byte form is reached from the state here read in byte form");const x=a(t=>!u&&(0,r.isGitStoragePath)(t.path,s.home),"storage"),j=e.files.filter(t=>x(t)&&!l(t)).sort(m),i={...e,files:e.files.filter(t=>!x(t))},c=new Map(s.files.map(t=>[t.path,t])),v=new Set(i.files.filter(t=>c.has(t.path)&&l(c.get(t.path))!==l(t)).map(t=>t.path)),F=a(t=>{for(let o=t.length;o>0;o=t.lastIndexOf("/",o-1))if(v.has(t.slice(0,o)))return!0;return!1},"clashed"),w=[],f=[],y=new Map;for(const t of i.files)F(t.path)?w.push(t):c.has(t.path)?y.set(t.path,t):f.push(t);const p=s.files.filter(t=>!b(y.get(t.path),t)),_=a(t=>(0,r.gitOwnPath)(t.path)==="HEAD","isHead"),M=[...p.filter(l),...p.filter(t=>!l(t)&&!_(t)),...p.filter(_)],g=a(t=>t.index?.meaning??null,"meaning"),d=[];if(g(i)!==g(s)){const t=new Map(i.index?.files.map(n=>[n.path,n])),o=new Set(s.index?.files.map(n=>n.path));for(const n of s.index?.files??[])b(t.get(n.path),n)||d.push(n);const P=a(n=>+((0,r.gitOwnPath)(n.path)==="index"),"last");d.sort((n,O)=>P(n)-P(O)),f.push(...i.index?.files.filter(n=>!o.has(n.path))??[])}return(0,h.pass)({drop:j,clear:w.sort(m),writes:M,index:d,removals:f.sort(m)})}a(S,"gitApplyPlan");
1
+ "use strict";var q=Object.defineProperty;var o=(e,s)=>q(e,"name",{value:s,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitApplyPlan=S;const h=require("../contracts/validate.js"),r=require("./state.js"),A=require("./text.js"),l=o(e=>e.mode==="040000","isFolder"),b=o((e,s)=>e!==void 0&&e.mode===s.mode&&e.oid===s.oid,"same"),m=o((e,s)=>(0,A.compareGitText)(s.path,e.path),"deepestFirst");function S(e,s){if(e.format!==s.format)return(0,h.fail)(`a ${e.format} repository cannot hold a ${s.format} state`);const u=(0,r.gitBytesForm)(s);if(u&&!(0,r.gitBytesForm)(e))return(0,h.fail)("a state in byte form is reached only from the state here read in byte form");const x=o(t=>!u&&(0,r.isGitStoragePath)(t.path,s.home),"storage"),j=e.files.filter(t=>x(t)&&!l(t)).sort(m),i={...e,files:e.files.filter(t=>!x(t))},c=new Map(s.files.map(t=>[t.path,t])),v=new Set(i.files.filter(t=>c.has(t.path)&&l(c.get(t.path))!==l(t)).map(t=>t.path)),F=o(t=>{for(let a=t.length;a>0;a=t.lastIndexOf("/",a-1))if(v.has(t.slice(0,a)))return!0;return!1},"clashed"),y=[],f=[],w=new Map;for(const t of i.files)F(t.path)?y.push(t):c.has(t.path)?w.set(t.path,t):f.push(t);const p=s.files.filter(t=>!b(w.get(t.path),t)),_=o(t=>(0,r.gitOwnPath)(t.path)==="HEAD","isHead"),M=[...p.filter(l),...p.filter(t=>!l(t)&&!_(t)),...p.filter(_)],g=o(t=>t.index?.meaning??null,"meaning"),d=[];if(g(i)!==g(s)){const t=new Map(i.index?.files.map(n=>[n.path,n])),a=new Set(s.index?.files.map(n=>n.path));for(const n of s.index?.files??[])b(t.get(n.path),n)||d.push(n);const P=o(n=>+((0,r.gitOwnPath)(n.path)==="index"),"last");d.sort((n,O)=>P(n)-P(O)),f.push(...i.index?.files.filter(n=>!a.has(n.path))??[])}return(0,h.pass)({drop:j,clear:y.sort(m),writes:M,index:d,removals:f.sort(m)})}o(S,"gitApplyPlan");
@@ -1,4 +1,4 @@
1
- "use strict";var ae=Object.defineProperty;var r=(t,i)=>ae(t,"name",{value:i,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitOwnChange=se,exports.gitLineChanges=re,exports.gitPlayable=fe,exports.gitPlayRecord=ge;const te=require("../entities/bytes.js"),ce=require("./alternates.js"),ne=require("./artifact.js"),b=require("./refs.js"),E=require("./state.js"),H=require("./text.js");function se(t){return t.facets.some(c=>c==="create"||c==="retype"||c==="content")&&t.result.status==="active"?t.result.transportVersion:null}r(se,"gitOwnChange");function re(t){let i=[],c=!1;for(const g of t){if(g.result.type!=="repo.git"){i=[],c=!0;continue}const d=se(g);d!==null&&i.push(d)}return{reached:i,ended:c}}r(re,"gitLineChanges");function fe({line:t,basis:i,record:c}){const g=r(l=>l.files.find(f=>f.path===ce.GIT_ALTERNATES_PATH)?.oid??null,"borrowed"),d=r(l=>l.files.some(f=>f.path==="reftable"),"reftable");return t.format===c.format&&(i===null||i.format===c.format)&&!(0,E.gitSharesObjects)(t)&&!(0,E.gitSelfHeld)(t.home)&&!(0,E.gitSharesGitDir)(t.home)&&t.home?.entity===c.home?.entity&&t.home?.path===c.home?.path&&g(t)===g(c)&&![t,c,...i?[i]:[]].some(l=>d(l)||(0,E.gitBytesForm)(l))}r(fe,"gitPlayable");const P="040000",z=r(t=>new Map(t.map(i=>[i.path,i])),"byPath"),F=r((t,i)=>t===void 0?i===void 0:i!==void 0&&t.mode===i.mode&&t.oid===i.oid,"same"),N=r(t=>{const i=[];for(let c=t.indexOf("/");c>0;c=t.indexOf("/",c+1))i.push(t.slice(0,c));return i},"parents");function le(t,i){const c=new Set;for(const d of t.keys()){const l=N(d).find(f=>t.has(f)&&t.get(f).mode!==P);l!==void 0&&c.add(l)}const g=r(d=>c.has(d)||N(d).some(l=>c.has(l)),"clashed");if(c.size>0){for(const d of[...t.keys()])g(d)&&t.delete(d);for(const[d,l]of i)g(d)&&t.set(d,l)}for(const d of[...t.keys()])for(const l of N(d))t.has(l)||t.set(l,{path:l,mode:P,oid:null});return[...t.values()].sort((d,l)=>(0,H.compareGitText)(d.path,l.path))}r(le,"asTree");const S=["line","basis","record"],T=r(t=>t.mode!==P&&(t.path==="HEAD"||t.path.startsWith("refs/")),"isLooseRef"),oe=r(t=>T(t)||t.path==="packed-refs","isRefFile"),de=r(t=>t.startsWith("logs/"),"isReflogPath"),V="refs/stash",J="refs/heads/",K=`${J}amalgm`,ue=7,he=/^[0-9a-f]{7,}$/,Q=r((t,i)=>t.startsWith(`${i}/`),"beneath");async function ge(t,i,c,g){const d={format:t.record.format,home:t.record.home,files:[],index:null},l={line:t.line,basis:t.basis??d,record:t.record},f={line:z(l.line.files),basis:z(l.basis.files),record:z(l.record.files)},A=new Map,O=r((e,n)=>{const s=(0,te.utf8Encode)(n),a=(0,ne.gitBlobId)(s,g);return A.set(a,s),{path:e,mode:"100644",oid:a}},"make"),w=r(async e=>e?.oid?(0,te.utf8Decode)(A.get(e.oid)??await i(e.oid)):"","read"),$=new Map,I=r(e=>($.has(e)||$.set(e,w(f[e].get("packed-refs")).then(b.gitPackedRefs)),$.get(e)),"packedOf"),y=r(async(e,n)=>{const s=f[e].get(n);return s!==void 0&&T(s)?(0,b.gitLooseRef)(await w(s)):n==="HEAD"?null:(await I(e)).get(n)??null},"value"),M=r(e=>!F(f.basis.get(e),f.record.get(e)),"recordChanged"),h=new Map;for(const e of new Set([...f.line.keys(),...f.basis.keys(),...f.record.keys()])){const n=M(e)?f.record.get(e):f.line.get(e);n!==void 0&&h.set(e,n)}const j=new Set;for(const e of new Set(S.flatMap(n=>[...f[n].keys()]))){const[n,s,a]=S.map(o=>f[o].get(e));if(!(F(n,s)&&F(s,a)))if(e==="packed-refs")for(const o of S)for(const u of(await I(o)).keys())j.add(u);else[n,s,a].some(o=>o!==void 0&&T(o))&&j.add(e)}const U=r(async e=>{const[n,s,a]=S.map(o=>f[o].get(e));return[n,s,a].some(o=>o?.mode===P)?w(n):(0,b.gitReflogPlay)(await w(s),await w(a),await w(n))},"playLog"),x=`logs/${V}`;let D=null;M(x)&&(D=(0,b.gitChainReflog)(await U(x)),D===""?h.delete(x):h.set(x,O(x,D)));const p=new Map,C=[];for(const e of[...j].sort(H.compareGitText)){const[n,s,a]=await Promise.all(S.map(u=>y(u,e)));let o=s!==a?a:n;if(e===V){if(D===null)continue;o=(0,b.gitReflogTop)(D)}else e.startsWith(J)&&n!==null&&n!==s&&o!==n&&[n,a].every(u=>u===null||(0,E.isGitOid)(t.record.format,u))&&(a===null||!await c.builtOn(a,n))&&(o=n,a!==null&&!await c.builtOn(n,a)&&C.push({name:e,basis:s,record:a}));o!==n&&p.set(e,o)}const X=[];if(C.length>0){const e=new Map;for(const s of new Set([...f.line.keys(),...(await I("line")).keys(),...p.keys()])){if(s!==K&&!Q(s,K))continue;const a=p.has(s)?p.get(s):await y("line",s);a!==null&&e.set(s,a)}const n=r((s,a)=>(e.get(s)??a)===a&&![...e.keys()].some(o=>Q(s,o)||Q(o,s)),"free");for(const{name:s,basis:a,record:o}of C){const u=`${K}/${s.slice(J.length)}-`;let m=[...e.keys()].sort(H.compareGitText).find(k=>e.get(k)===a&&k.startsWith(u)&&he.test(k.slice(u.length)));for(let k=ue;m===void 0&&k<=o.length;k+=1)n(u+o.slice(0,k),o)&&(m=u+o.slice(0,k));m!==void 0&&(await y("line",m)!==o&&p.set(m,o),e.set(m,o),X.push({branch:m,from:s,commit:o}))}}for(const[e,n]of[...h])oe(n)&&h.delete(e);for(const e of l.line.files)oe(e)&&h.set(e.path,e);const G=new Set;for(const[e,n]of p)n!==null?h.set(e,O(e,`${n}
2
- `)):(h.has(e)&&T(h.get(e))&&h.delete(e),G.add(e));const Y=f.line.get("packed-refs");if(G.size>0&&Y!==void 0){const e=await w(Y),n=(0,b.gitDropPackedRefs)(e,G);n!==e&&h.set("packed-refs",O("packed-refs",n))}const L=r(e=>p.has(e)?Promise.resolve(p.get(e)):y("line",e),"final"),v=r(async(e,n)=>e?.startsWith("ref: ")?n(e.slice(5)):e,"commitOf"),_=await v(await L("HEAD"),L),R=new Set;for(const e of S)for(const n of f[e].keys())de(n)&&n!==x&&R.add(n);for(const e of p.keys())e!==V&&R.add(`logs/${e}`);_!==await v(await y("line","HEAD"),e=>y("line",e))&&R.add("logs/HEAD");for(const e of[...R].sort(H.compareGitText)){const n=e.slice(5),s=n==="HEAD"?_:await L(n),a=M(e);if(!a&&(s===null||n!=="HEAD"&&!p.has(n)||!f.line.has(e)))continue;let o=a?await U(e):await w(f.line.get(e));const u=(0,b.gitReflogTop)(o);if(s!==null&&u!==null&&u!==s&&(0,E.isGitOid)(t.record.format,s)){const m=o.trimEnd().split(`
3
- `).at(-1);o+=`${u} ${s}${m.slice(m.indexOf(" ",m.indexOf(" ")+1))}
4
- `}o===""?h.delete(e):h.set(e,O(e,o))}const q=r(e=>y(e,"HEAD").then(n=>v(n,s=>y(e,s))),"headOf"),Z=await q("record"),ie=t.record.index?.meaning!==t.basis?.index?.meaning||Z!==(t.basis===null?null:await q("basis")),[W,B]=ie?[t.record.index,Z]:[t.line.index,await q("line")];let ee=W;if(W?.files.length===1&&B!==null&&_!==null&&B!==_){const e=await c.carryIndex(await i(W.files[0].oid),B,_);if(e!==null){const n=e.bytes,s=(0,ne.gitBlobId)(n,g);A.set(s,n),ee={meaning:e.meaning,files:[{path:"index",mode:"100644",oid:s}]}}}return{state:{format:t.record.format,home:t.record.home,files:le(h,f.record),index:ee},made:A,aside:X}}r(ge,"gitPlayRecord");
1
+ "use strict";var ae=Object.defineProperty;var r=(t,i)=>ae(t,"name",{value:i,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitOwnChange=ne,exports.gitLineChanges=re,exports.gitPlayable=fe,exports.gitPlayRecord=he;const ee=require("../entities/bytes.js"),ce=require("./alternates.js"),te=require("./artifact.js"),E=require("./refs.js"),S=require("./state.js"),W=require("./text.js");function ne(t){return t.facets.some(f=>f==="create"||f==="retype"||f==="content")&&t.result.status==="active"?t.result.transportVersion:null}r(ne,"gitOwnChange");function re(t){let i=[],f=!1;for(const g of t){if(g.result.type!=="repo.git"){i=[],f=!0;continue}const p=ne(g);p!==null&&i.push(p)}return{reached:i,ended:f}}r(re,"gitLineChanges");function fe({line:t,basis:i,record:f}){const g=r(l=>l.files.find(a=>a.path===ce.GIT_ALTERNATES_PATH)?.oid??null,"borrowed"),p=r(l=>l.files.some(a=>a.path==="reftable"),"reftable");return t.format===f.format&&(i===null||i.format===f.format)&&!(0,S.gitSharesObjects)(t)&&!(0,S.gitSelfHeld)(t.home)&&!(0,S.gitSharesGitDir)(t.home)&&t.home?.entity===f.home?.entity&&t.home?.path===f.home?.path&&g(t)===g(f)&&![t,f,...i?[i]:[]].some(l=>p(l)||(0,S.gitBytesForm)(l))}r(fe,"gitPlayable");const B="040000",z=r(t=>new Map(t.map(i=>[i.path,i])),"byPath"),F=r((t,i)=>t===void 0?i===void 0:i!==void 0&&t.mode===i.mode&&t.oid===i.oid,"same"),se=r(t=>{const i=[];for(let f=t.indexOf("/");f>0;f=t.indexOf("/",f+1))i.push(t.slice(0,f));return i},"parents");function le(t,i,f){const g=new Set;for(const l of t.keys()){const a=se(l).find(k=>t.has(k)&&t.get(k).mode!==B);a!==void 0&&g.add(a)}const p=r(l=>g.has(l)||se(l).some(a=>g.has(a)),"clashed");if(g.size>0){for(const l of[...t.keys()])p(l)&&t.delete(l);for(const[l,a]of i)p(l)&&t.set(l,a)}return(0,S.gitTreeOf)(t.values(),f)}r(le,"asTree");const D=["line","basis","record"],H=r(t=>t.mode!==B&&(t.path==="HEAD"||t.path.startsWith("refs/")),"isLooseRef"),oe=r(t=>H(t)||t.path==="packed-refs","isRefFile"),de=r(t=>t.startsWith("logs/"),"isReflogPath"),N="refs/stash",V="refs/heads/",J=`${V}amalgm`,ue=7,ge=/^[0-9a-f]{7,}$/,K=r((t,i)=>t.startsWith(`${i}/`),"beneath");async function he(t,i,f,g){const p={format:t.record.format,home:t.record.home,files:[],index:null},l={line:t.line,basis:t.basis??p,record:t.record},a={line:z(l.line.files),basis:z(l.basis.files),record:z(l.record.files)},k=new Map,O=r((e,n)=>{const s=(0,ee.utf8Encode)(n),c=(0,te.gitBlobId)(s,g);return k.set(c,s),{path:e,mode:"100644",oid:c}},"make"),w=r(async e=>e?.oid?(0,ee.utf8Decode)(k.get(e.oid)??await i(e.oid)):"","read"),P=new Map,T=r(e=>(P.has(e)||P.set(e,w(a[e].get("packed-refs")).then(E.gitPackedRefs)),P.get(e)),"packedOf"),y=r(async(e,n)=>{const s=a[e].get(n);return s!==void 0&&H(s)?(0,E.gitLooseRef)(await w(s)):n==="HEAD"?null:(await T(e)).get(n)??null},"value"),$=r(e=>!F(a.basis.get(e),a.record.get(e)),"recordChanged"),u=new Map;for(const e of new Set([...a.line.keys(),...a.basis.keys(),...a.record.keys()])){const n=$(e)?a.record.get(e):a.line.get(e);n!==void 0&&u.set(e,n)}const I=new Set;for(const e of new Set(D.flatMap(n=>[...a[n].keys()]))){const[n,s,c]=D.map(o=>a[o].get(e));if(!(F(n,s)&&F(s,c)))if(e==="packed-refs")for(const o of D)for(const d of(await T(o)).keys())I.add(d);else[n,s,c].some(o=>o!==void 0&&H(o))&&I.add(e)}const Q=r(async e=>{const[n,s,c]=D.map(o=>a[o].get(e));return[n,s,c].some(o=>o?.mode===B)?w(n):(0,E.gitReflogPlay)(await w(s),await w(c),await w(n))},"playLog"),x=`logs/${N}`;let _=null;$(x)&&(_=(0,E.gitChainReflog)(await Q(x)),_===""?u.delete(x):u.set(x,O(x,_)));const m=new Map,M=[];for(const e of[...I].sort(W.compareGitText)){const[n,s,c]=await Promise.all(D.map(d=>y(d,e)));let o=s!==c?c:n;if(e===N){if(_===null)continue;o=(0,E.gitReflogTop)(_)}else e.startsWith(V)&&n!==null&&n!==s&&o!==n&&[n,c].every(d=>d===null||(0,S.isGitOid)(t.record.format,d))&&(c===null||!await f.builtOn(c,n))&&(o=n,c!==null&&!await f.builtOn(n,c)&&M.push({name:e,basis:s,record:c}));o!==n&&m.set(e,o)}const U=[];if(M.length>0){const e=new Map;for(const s of new Set([...a.line.keys(),...(await T("line")).keys(),...m.keys()])){if(s!==J&&!K(s,J))continue;const c=m.has(s)?m.get(s):await y("line",s);c!==null&&e.set(s,c)}const n=r((s,c)=>(e.get(s)??c)===c&&![...e.keys()].some(o=>K(s,o)||K(o,s)),"free");for(const{name:s,basis:c,record:o}of M){const d=`${J}/${s.slice(V.length)}-`;let h=[...e.keys()].sort(W.compareGitText).find(b=>e.get(b)===c&&b.startsWith(d)&&ge.test(b.slice(d.length)));for(let b=ue;h===void 0&&b<=o.length;b+=1)n(d+o.slice(0,b),o)&&(h=d+o.slice(0,b));h!==void 0&&(await y("line",h)!==o&&m.set(h,o),e.set(h,o),U.push({branch:h,from:s,commit:o}))}}for(const[e,n]of[...u])oe(n)&&u.delete(e);for(const e of l.line.files)oe(e)&&u.set(e.path,e);const j=new Set;for(const[e,n]of m)n!==null?u.set(e,O(e,`${n}
2
+ `)):(u.has(e)&&H(u.get(e))&&u.delete(e),j.add(e));const X=a.line.get("packed-refs");if(j.size>0&&X!==void 0){const e=await w(X),n=(0,E.gitDropPackedRefs)(e,j);n!==e&&u.set("packed-refs",O("packed-refs",n))}const C=r(e=>m.has(e)?Promise.resolve(m.get(e)):y("line",e),"final"),L=r(async(e,n)=>e?.startsWith("ref: ")?n(e.slice(5)):e,"commitOf"),A=await L(await C("HEAD"),C),R=new Set;for(const e of D)for(const n of a[e].keys())de(n)&&n!==x&&R.add(n);for(const e of m.keys())e!==N&&R.add(`logs/${e}`);A!==await L(await y("line","HEAD"),e=>y("line",e))&&R.add("logs/HEAD");for(const e of[...R].sort(W.compareGitText)){const n=e.slice(5),s=n==="HEAD"?A:await C(n),c=$(e);if(!c&&(s===null||n!=="HEAD"&&!m.has(n)||!a.line.has(e)))continue;let o=c?await Q(e):await w(a.line.get(e));const d=(0,E.gitReflogTop)(o);if(s!==null&&d!==null&&d!==s&&(0,S.isGitOid)(t.record.format,s)){const h=o.trimEnd().split(`
3
+ `).at(-1);o+=`${d} ${s}${h.slice(h.indexOf(" ",h.indexOf(" ")+1))}
4
+ `}o===""?u.delete(e):u.set(e,O(e,o))}const v=r(e=>y(e,"HEAD").then(n=>L(n,s=>y(e,s))),"headOf"),Y=await v("record"),ie=t.record.index?.meaning!==t.basis?.index?.meaning||Y!==(t.basis===null?null:await v("basis")),[G,q]=ie?[t.record.index,Y]:[t.line.index,await v("line")];let Z=G;if(G?.files.length===1&&q!==null&&A!==null&&q!==A){const e=await f.carryIndex(await i(G.files[0].oid),q,A);if(e!==null){const n=e.bytes,s=(0,te.gitBlobId)(n,g);k.set(s,n),Z={meaning:e.meaning,files:[{path:"index",mode:"100644",oid:s}]}}}return{state:{format:t.record.format,home:t.record.home,files:le(u,a.record,t.record.home),index:Z},made:k,aside:U}}r(he,"gitPlayRecord");
@@ -1,2 +1,2 @@
1
- "use strict";var I=Object.defineProperty;var n=(s,r)=>I(s,"name",{value:r,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitRestoreGoal=A;const f=require("../contracts/validate.js"),u=require("../entities/bytes.js"),$=require("./artifact.js"),a=require("./parts.js"),p=require("./refs.js"),_=require("./state.js"),x=require("./text.js"),j=/^(rebase-merge|rebase-apply|sequencer)(\/|$)/,l=n(s=>s.mode==="040000","isFolder"),O=n(s=>(0,a.gitOwnRef)(s)||(0,a.gitOwnFile)(s),"restored");function A(s,r,T,q){for(const e of[s,r]){if((0,_.gitBytesForm)(e))return(0,f.fail)("a repository in byte form cannot be restored");if(e.files.some(t=>t.path.startsWith("reftable/")))return(0,f.fail)("a reftable repository cannot be restored");if((0,_.gitSelfHeld)(e.home))return(0,f.fail)("a worktree of storage outside every folder cannot be restored")}if(s.format!==r.format)return(0,f.fail)(`a ${s.format} repository cannot take a ${r.format} version`);const d=new Map,g=n((e,t)=>{const i=(0,$.gitBlobId)(t,q);return d.set(i,t),{path:e,mode:"100644",oid:i}},"blob"),h=n(e=>e.files.find(t=>t.path===a.GIT_PACKED_REFS),"packed"),k=n(e=>{const t=h(e);return t===void 0?null:(0,u.utf8Decode)(T(t.oid))},"packedText"),c=k(s),R=k(r),m=R===null?new Map:(0,p.gitPackedRefs)(R),w=n((e,t)=>new Set([...e.files.filter(i=>!l(i)&&(0,a.gitOwnRef)(i.path)).map(i=>i.path),...[...t.keys()].filter(a.gitOwnRef)]),"ownRefs"),G=w(r,m),M=new Set([...w(s,c===null?new Map:(0,p.gitPackedRefs)(c))].filter(e=>!G.has(e)).map(e=>`logs/${e}`)),o=new Map;for(const[e,t]of m)(0,a.gitOwnRef)(e)&&o.set(e,g(e,(0,u.utf8Encode)(`${t}
2
- `)));for(const e of r.files)(l(e)?j.test(e.path):O(e.path))&&o.set(e.path,e);if(c!==null){const e=(0,p.gitDropPackedRefs)(c,new Set([...(0,p.gitPackedRefs)(c).keys()].filter(a.gitOwnRef)));o.set(a.GIT_PACKED_REFS,e===c?h(s):g(a.GIT_PACKED_REFS,(0,u.utf8Encode)(e)))}const b=n(e=>{const t=e.split("/");return t.slice(1).map((i,D)=>t.slice(0,D+1).join("/"))},"ancestors"),y=new Set([...o.keys()].flatMap(b)),v=n(e=>o.has(e.path)||!l(e)&&y.has(e.path)||b(e.path).some(t=>o.has(t)&&!l(o.get(t))),"inTheWay");for(const e of s.files)(l(e)?!j.test(e.path):e.path!==a.GIT_PACKED_REFS&&!O(e.path)&&!M.has(e.path))&&!v(e)&&o.set(e.path,e);for(const e of y)o.has(e)||o.set(e,{path:e,mode:"040000",oid:null});const E=[...o.values()].sort((e,t)=>(0,x.compareGitText)(e.path,t.path)),P={...s,files:E,index:r.index},S=(0,_.checkGitState)(P);if(!S.ok)return(0,f.fail)(`the version cannot stand over this repository: ${S.error}`);const F=new Map(E.flatMap(e=>d.has(e.oid)?[[e.oid,d.get(e.oid)]]:[]));return(0,f.pass)({state:P,blobs:F})}n(A,"gitRestoreGoal");
1
+ "use strict";var I=Object.defineProperty;var o=(s,a)=>I(s,"name",{value:a,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitRestoreGoal=A;const f=require("../contracts/validate.js"),g=require("../entities/bytes.js"),$=require("./artifact.js"),n=require("./parts.js"),d=require("./refs.js"),p=require("./state.js"),O=/^(rebase-merge|rebase-apply|sequencer)(\/|$)/,l=o(s=>s.mode==="040000","isFolder"),S=o(s=>(0,n.gitOwnRef)(s)||(0,n.gitOwnFile)(s),"restored");function A(s,a,T,j){for(const e of[s,a]){if((0,p.gitBytesForm)(e))return(0,f.fail)("a repository in byte form cannot be restored");if(e.files.some(t=>t.path.startsWith("reftable/")))return(0,f.fail)("a reftable repository cannot be restored");if((0,p.gitSelfHeld)(e.home))return(0,f.fail)("a worktree of storage outside every folder cannot be restored")}if(s.format!==a.format)return(0,f.fail)(`a ${s.format} repository cannot take a ${a.format} version`);const u=new Map,_=o((e,t)=>{const i=(0,$.gitBlobId)(t,j);return u.set(i,t),{path:e,mode:"100644",oid:i}},"blob"),k=o(e=>e.files.find(t=>t.path===n.GIT_PACKED_REFS),"packed"),R=o(e=>{const t=k(e);return t===void 0?null:(0,g.utf8Decode)(T(t.oid))},"packedText"),c=R(s),h=R(a),m=h===null?new Map:(0,d.gitPackedRefs)(h),w=o((e,t)=>new Set([...e.files.filter(i=>!l(i)&&(0,n.gitOwnRef)(i.path)).map(i=>i.path),...[...t.keys()].filter(n.gitOwnRef)]),"ownRefs"),M=w(a,m),q=new Set([...w(s,c===null?new Map:(0,d.gitPackedRefs)(c))].filter(e=>!M.has(e)).map(e=>`logs/${e}`)),r=new Map;for(const[e,t]of m)(0,n.gitOwnRef)(e)&&r.set(e,_(e,(0,g.utf8Encode)(`${t}
2
+ `)));for(const e of a.files)(l(e)?O.test(e.path):S(e.path))&&r.set(e.path,e);if(c!==null){const e=(0,d.gitDropPackedRefs)(c,new Set([...(0,d.gitPackedRefs)(c).keys()].filter(n.gitOwnRef)));r.set(n.GIT_PACKED_REFS,e===c?k(s):_(n.GIT_PACKED_REFS,(0,g.utf8Encode)(e)))}const b=o(e=>{const t=e.split("/");return t.slice(1).map((i,D)=>t.slice(0,D+1).join("/"))},"ancestors"),v=new Set([...r.keys()].flatMap(b)),F=o(e=>r.has(e.path)||!l(e)&&v.has(e.path)||b(e.path).some(t=>r.has(t)&&!l(r.get(t))),"inTheWay");for(const e of s.files)(l(e)?!O.test(e.path):e.path!==n.GIT_PACKED_REFS&&!S(e.path)&&!q.has(e.path))&&!F(e)&&r.set(e.path,e);const y=(0,p.gitTreeOf)(r.values(),s.home),E={...s,files:y,index:a.index},P=(0,p.checkGitState)(E);if(!P.ok)return(0,f.fail)(`the version cannot stand over this repository: ${P.error}`);const G=new Map(y.flatMap(e=>u.has(e.oid)?[[e.oid,u.get(e.oid)]]:[]));return(0,f.pass)({state:E,blobs:G})}o(A,"gitRestoreGoal");
@@ -1,3 +1,3 @@
1
- "use strict";var x=Object.defineProperty;var e=(t,i)=>x(t,"name",{value:i,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitStateId=exports.isGitHome=exports.gitNamedObjects=exports.isGitNamingPath=exports.gitSharesObjects=exports.isGitStoragePath=exports.gitBytesForm=exports.isGitConfigurationPath=exports.isGitIndexPath=exports.isGitLockPath=exports.gitOwnPath=exports.gitSharesGitDir=exports.gitSelfHeld=exports.isGitOid=void 0,exports.isGitStatePath=f,exports.gitBlobs=W,exports.checkGitState=X,exports.gitStateJson=V;const E=require("@amalgm/core/identity"),h=require("../contracts/validate.js"),G=require("../entities/bytes.js"),_=require("../entities/types.js"),k=require("./alternates.js"),w=require("./text.js"),b=["040000","100644","100755","120000"],R={sha1:40,sha256:64},j=e((t,i)=>typeof i=="string"&&i.length===R[t]&&/^[0-9a-f]+$/.test(i),"isGitOid");exports.isGitOid=j;const p=e(t=>(0,exports.isGitOid)("sha256",t),"isDigest"),A=e(t=>t!==null&&t.entity===null,"gitSelfHeld");exports.gitSelfHeld=A;const T=e(t=>t!==null&&t.entity!==null&&t.path==="","gitSharesGitDir");exports.gitSharesGitDir=T;const H=e(t=>t.replace(/^worktrees\/[^/]+\//,""),"gitOwnPath");exports.gitOwnPath=H;const I=e(t=>t.split("/").some(i=>i.endsWith(".lock")),"isGitLockPath");exports.isGitLockPath=I;const $=e(t=>(i=>i==="index"||/^sharedindex\.[0-9a-f]+$/.test(i))((0,exports.gitOwnPath)(t)),"isGitIndexPath");exports.isGitIndexPath=$;const D=e(t=>["config","config.worktree"].includes((0,exports.gitOwnPath)(t)),"isGitConfigurationPath");exports.isGitConfigurationPath=D;const u=["worktrees","modules"],L=["objects",...u],g=e((t,i)=>t===k.GIT_ALTERNATES_PATH||t!=="gitdir"&&!(i?u:L).some(s=>t===s||t.startsWith(`${s}/`)),"isOwnStatePath");function f(t,i,s=!1){if((0,exports.gitSharesGitDir)(i)||(0,E.isLocalOnlyPath)(t)||(0,exports.isGitLockPath)(t))return!1;if(!(0,exports.gitSelfHeld)(i))return g(t,s);const o=i.path;return t==="worktrees"||t===o?!0:t.startsWith(`${o}/`)?g(t.slice(o.length+1),s):g(t,s)&&!(0,exports.isGitIndexPath)(t)}e(f,"isGitStatePath");const y=e(t=>t.some(i=>(0,h.isRecord)(i)&&i.path==="objects"&&i.mode==="040000"),"listsObjects"),N=e(t=>y(t.files),"gitBytesForm");exports.gitBytesForm=N;const M=e((t,i)=>f(t,i,!0)&&!f(t,i),"isGitStoragePath");exports.isGitStoragePath=M;const q=e(t=>!(0,exports.gitSelfHeld)(t.home)&&(t.home?.path.startsWith("worktrees/")??!1),"gitSharesObjects");exports.gitSharesObjects=q;const F=new Set(["AUTO_MERGE","BISECT_EXPECTED_REV","MERGE_AUTOSTASH","NOTES_MERGE_PARTIAL","NOTES_MERGE_REF"]),B=e(t=>(i=>/^[A-Z_-]+_HEAD$/.test(i)||F.has(i)||/^rebase-(apply|merge)\/(autostash|orig-head)$/.test(i))((0,exports.gitOwnPath)(t)),"isGitNamingPath");exports.isGitNamingPath=B;const C=e((t,i)=>(0,G.utf8Decode)(i).split(`
2
- `).map(s=>s.split(/[\t ]/,1)[0]).filter(s=>(0,exports.isGitOid)(t,s)),"gitNamedObjects");exports.gitNamedObjects=C;const m=e(t=>typeof t=="string"&&t.length>0&&!t.includes("\0")&&t.split("/").every(i=>i!==""&&i!=="."&&i!==".."),"isPath");function W(t){const i=new Set;for(const s of[...t.files,...t.index?.files??[]])s.oid!==null&&i.add(s.oid);return i}e(W,"gitBlobs");const U='{ format: "sha1", home: { entity: <uuid>, path: "worktrees/<name>" | "modules/<name>" | "" } | { entity: null, path: "worktrees/<name>" } | null, files: [{ path: "HEAD", mode: "100644", oid: <sha256> }], index: { meaning: <sha256>, files: [...] } | null }',S=e(t=>typeof t=="string"&&/^worktrees\/[^/]+$/.test(t),"isWorktreeHome"),J=e(t=>(0,h.isRecord)(t)&&Object.keys(t).length===2&&(t.entity===null?m(t.path)&&S(t.path):typeof t.entity=="string"&&_.UUID_PATTERN.test(t.entity)&&t.entity===t.entity.toLowerCase()&&(t.path===""||m(t.path)&&(S(t.path)||t.path.startsWith("modules/")))),"isGitHome");exports.isGitHome=J;function O(t,i,s,o,r){if(!Array.isArray(t))return"not a list";for(const[c,n]of t.entries()){if((0,h.isRecord)(n)&&typeof n.path=="string"&&(0,exports.isGitLockPath)(n.path))return`${n.path} is a lock, a write in progress, never state`;if(!(0,h.isRecord)(n)||Object.keys(n).length!==3||!m(n.path)||!o(n.path))return`entry ${c} is not one { path, mode, oid } this list owns`;if(c>0&&(0,w.compareGitText)(t[c-1].path,n.path)>=0)return"paths are not sorted and unique";if(!b.includes(n.mode)||(n.mode==="040000"?n.oid!==null:!p(n.oid)))return`${n.path} is not a folder without a blob or a file, executable or link naming one`;const d=n.path.slice(0,Math.max(0,n.path.lastIndexOf("/")));if(d!==""&&f(d,i,s)&&!r.has(d))return`${n.path} stands in no listed folder`;n.mode==="040000"&&r.add(n.path)}return t}e(O,"checkFiles");function X(t){const i=e(a=>(0,h.failShape)(U,a),"bad");if(!(0,h.isRecord)(t)||Object.keys(t).length!==4)return i("the state is not { format, home, files, index }");const{format:s,index:o}=t;if(s!=="sha1"&&s!=="sha256")return i("format is not sha1 or sha256");if(t.home!==null&&!(0,exports.isGitHome)(t.home))return i("home is not null or { entity, path } naming worktrees/, modules/ or, with an entity, nothing, with no entity only for worktrees/");const r=t.home&&{entity:t.home.entity,path:t.home.path},c=new Set,n=Array.isArray(t.files)&&y(t.files),d=O(t.files,r,n,a=>f(a,r,n)&&!(0,exports.isGitIndexPath)(a),c);if(typeof d=="string")return i(`files: ${d}`);if(o===null)return(0,h.pass)({format:s,home:r,files:d,index:null});if((0,exports.gitSharesGitDir)(r))return i("a state that shares its owner's Git directory has an index");if(!(0,h.isRecord)(o)||Object.keys(o).length!==2||!p(o.meaning))return i("index is not null or { meaning, files }");const l=O(o.files,r,n,a=>f(a,r)&&(0,exports.isGitIndexPath)(a),c);if(typeof l=="string")return i(`index files: ${l}`);const P=(0,exports.gitSelfHeld)(r)?`${r.path}/index`:"index";return!l.some(a=>a.path===P)||l.some(a=>a.mode!=="100644")?i("index files are not plain files including index"):(0,h.pass)({format:s,home:r,files:d,index:{meaning:o.meaning,files:l}})}e(X,"checkGitState");function V(t){const i=e(s=>s.map(o=>({path:o.path,mode:o.mode,oid:o.oid})),"files");return{format:t.format,home:t.home&&{entity:t.home.entity,path:t.home.path},files:i(t.files),index:t.index&&{meaning:t.index.meaning,files:i(t.index.files)}}}e(V,"gitStateJson");const Z=e((t,i)=>i((0,G.utf8Encode)(`amalgm.git-state.v3
3
- ${JSON.stringify({format:t.format,home:t.home&&[t.home.entity,t.home.path],files:t.files.map(s=>[s.path,s.mode,s.oid]),index:t.index?.meaning??null})}`)),"gitStateId");exports.gitStateId=Z;
1
+ "use strict";var E=Object.defineProperty;var s=(t,i)=>E(t,"name",{value:i,configurable:!0});Object.defineProperty(exports,"__esModule",{value:!0}),exports.gitStateId=exports.isGitHome=exports.gitNamedObjects=exports.isGitNamingPath=exports.gitSharesObjects=exports.isGitStoragePath=exports.gitBytesForm=exports.isGitConfigurationPath=exports.isGitIndexPath=exports.isGitLockPath=exports.gitOwnPath=exports.gitSharesGitDir=exports.gitSelfHeld=exports.isGitOid=void 0,exports.isGitStatePath=f,exports.gitTreeOf=M,exports.gitBlobs=U,exports.checkGitState=V,exports.gitStateJson=Z;const _=require("@amalgm/core/identity"),d=require("../contracts/validate.js"),p=require("../entities/bytes.js"),k=require("../entities/types.js"),w=require("./alternates.js"),u=require("./text.js"),b=["040000","100644","100755","120000"],R={sha1:40,sha256:64},T=s((t,i)=>typeof i=="string"&&i.length===R[t]&&/^[0-9a-f]+$/.test(i),"isGitOid");exports.isGitOid=T;const G=s(t=>(0,exports.isGitOid)("sha256",t),"isDigest"),j=s(t=>t!==null&&t.entity===null,"gitSelfHeld");exports.gitSelfHeld=j;const A=s(t=>t!==null&&t.entity!==null&&t.path==="","gitSharesGitDir");exports.gitSharesGitDir=A;const H=s(t=>t.replace(/^worktrees\/[^/]+\//,""),"gitOwnPath");exports.gitOwnPath=H;const I=s(t=>t.split("/").some(i=>i.endsWith(".lock")),"isGitLockPath");exports.isGitLockPath=I;const $=s(t=>(i=>i==="index"||/^sharedindex\.[0-9a-f]+$/.test(i))((0,exports.gitOwnPath)(t)),"isGitIndexPath");exports.isGitIndexPath=$;const D=s(t=>["config","config.worktree"].includes((0,exports.gitOwnPath)(t)),"isGitConfigurationPath");exports.isGitConfigurationPath=D;const y=["worktrees","modules"],L=["objects",...y],g=s((t,i)=>t===w.GIT_ALTERNATES_PATH||t!=="gitdir"&&!(i?y:L).some(e=>t===e||t.startsWith(`${e}/`)),"isOwnStatePath");function f(t,i,e=!1){if((0,exports.gitSharesGitDir)(i)||(0,_.isLocalOnlyPath)(t)||(0,exports.isGitLockPath)(t))return!1;if(!(0,exports.gitSelfHeld)(i))return g(t,e);const n=i.path;return t==="worktrees"||t===n?!0:t.startsWith(`${n}/`)?g(t.slice(n.length+1),e):g(t,e)&&!(0,exports.isGitIndexPath)(t)}s(f,"isGitStatePath");const S=s(t=>t.some(i=>(0,d.isRecord)(i)&&i.path==="objects"&&i.mode==="040000"),"listsObjects"),N=s(t=>S(t.files),"gitBytesForm");exports.gitBytesForm=N;function M(t,i){const e=new Map;for(const n of t)e.set(n.path,n);for(const n of[...e.keys()])for(let r=n.indexOf("/");r>0;r=n.indexOf("/",r+1)){const a=n.slice(0,r);!e.has(a)&&f(a,i)&&e.set(a,{path:a,mode:"040000",oid:null})}return[...e.values()].sort((n,r)=>(0,u.compareGitText)(n.path,r.path))}s(M,"gitTreeOf");const q=s((t,i)=>f(t,i,!0)&&!f(t,i),"isGitStoragePath");exports.isGitStoragePath=q;const F=s(t=>!(0,exports.gitSelfHeld)(t.home)&&(t.home?.path.startsWith("worktrees/")??!1),"gitSharesObjects");exports.gitSharesObjects=F;const B=new Set(["AUTO_MERGE","BISECT_EXPECTED_REV","MERGE_AUTOSTASH","NOTES_MERGE_PARTIAL","NOTES_MERGE_REF"]),C=s(t=>(i=>/^[A-Z_-]+_HEAD$/.test(i)||B.has(i)||/^rebase-(apply|merge)\/(autostash|orig-head)$/.test(i))((0,exports.gitOwnPath)(t)),"isGitNamingPath");exports.isGitNamingPath=C;const W=s((t,i)=>(0,p.utf8Decode)(i).split(`
2
+ `).map(e=>e.split(/[\t ]/,1)[0]).filter(e=>(0,exports.isGitOid)(t,e)),"gitNamedObjects");exports.gitNamedObjects=W;const m=s(t=>typeof t=="string"&&t.length>0&&!t.includes("\0")&&t.split("/").every(i=>i!==""&&i!=="."&&i!==".."),"isPath");function U(t){const i=new Set;for(const e of[...t.files,...t.index?.files??[]])e.oid!==null&&i.add(e.oid);return i}s(U,"gitBlobs");const J='{ format: "sha1", home: { entity: <uuid>, path: "worktrees/<name>" | "modules/<name>" | "" } | { entity: null, path: "worktrees/<name>" } | null, files: [{ path: "HEAD", mode: "100644", oid: <sha256> }], index: { meaning: <sha256>, files: [...] } | null }',O=s(t=>typeof t=="string"&&/^worktrees\/[^/]+$/.test(t),"isWorktreeHome"),X=s(t=>(0,d.isRecord)(t)&&Object.keys(t).length===2&&(t.entity===null?m(t.path)&&O(t.path):typeof t.entity=="string"&&k.UUID_PATTERN.test(t.entity)&&t.entity===t.entity.toLowerCase()&&(t.path===""||m(t.path)&&(O(t.path)||t.path.startsWith("modules/")))),"isGitHome");exports.isGitHome=X;function P(t,i,e,n,r){if(!Array.isArray(t))return"not a list";for(const[a,o]of t.entries()){if((0,d.isRecord)(o)&&typeof o.path=="string"&&(0,exports.isGitLockPath)(o.path))return`${o.path} is a lock, a write in progress, never state`;if(!(0,d.isRecord)(o)||Object.keys(o).length!==3||!m(o.path)||!n(o.path))return`entry ${a} is not one { path, mode, oid } this list owns`;if(a>0&&(0,u.compareGitText)(t[a-1].path,o.path)>=0)return"paths are not sorted and unique";if(!b.includes(o.mode)||(o.mode==="040000"?o.oid!==null:!G(o.oid)))return`${o.path} is not a folder without a blob or a file, executable or link naming one`;const c=o.path.slice(0,Math.max(0,o.path.lastIndexOf("/")));if(c!==""&&f(c,i,e)&&!r.has(c))return`${o.path} stands in no listed folder`;o.mode==="040000"&&r.add(o.path)}return t}s(P,"checkFiles");function V(t){const i=s(h=>(0,d.failShape)(J,h),"bad");if(!(0,d.isRecord)(t)||Object.keys(t).length!==4)return i("the state is not { format, home, files, index }");const{format:e,index:n}=t;if(e!=="sha1"&&e!=="sha256")return i("format is not sha1 or sha256");if(t.home!==null&&!(0,exports.isGitHome)(t.home))return i("home is not null or { entity, path } naming worktrees/, modules/ or, with an entity, nothing, with no entity only for worktrees/");const r=t.home&&{entity:t.home.entity,path:t.home.path},a=new Set,o=Array.isArray(t.files)&&S(t.files),c=P(t.files,r,o,h=>f(h,r,o)&&!(0,exports.isGitIndexPath)(h),a);if(typeof c=="string")return i(`files: ${c}`);if(n===null)return(0,d.pass)({format:e,home:r,files:c,index:null});if((0,exports.gitSharesGitDir)(r))return i("a state that shares its owner's Git directory has an index");if(!(0,d.isRecord)(n)||Object.keys(n).length!==2||!G(n.meaning))return i("index is not null or { meaning, files }");const l=P(n.files,r,o,h=>f(h,r)&&(0,exports.isGitIndexPath)(h),a);if(typeof l=="string")return i(`index files: ${l}`);const x=(0,exports.gitSelfHeld)(r)?`${r.path}/index`:"index";return!l.some(h=>h.path===x)||l.some(h=>h.mode!=="100644")?i("index files are not plain files including index"):(0,d.pass)({format:e,home:r,files:c,index:{meaning:n.meaning,files:l}})}s(V,"checkGitState");function Z(t){const i=s(e=>e.map(n=>({path:n.path,mode:n.mode,oid:n.oid})),"files");return{format:t.format,home:t.home&&{entity:t.home.entity,path:t.home.path},files:i(t.files),index:t.index&&{meaning:t.index.meaning,files:i(t.index.files)}}}s(Z,"gitStateJson");const z=s((t,i)=>i((0,p.utf8Encode)(`amalgm.git-state.v3
3
+ ${JSON.stringify({format:t.format,home:t.home&&[t.home.entity,t.home.path],files:t.files.map(e=>[e.path,e.mode,e.oid]),index:t.index?.meaning??null})}`)),"gitStateId");exports.gitStateId=z;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amalgm/live",
3
- "version": "0.2.81-preview.46147035832",
3
+ "version": "0.2.81-preview.46155260343",
4
4
  "description": "Portable realtime SDK for Amalgm — wire contracts, mutation discipline, and delivery state machines behind host-injected adapters.",
5
5
  "type": "module",
6
6
  "main": "./dist-cjs/index.js",
@@ -131,13 +131,13 @@
131
131
  "esbuild@0.28.2": true
132
132
  },
133
133
  "dependencies": {
134
- "@amalgm/core": "0.5.1-preview.46146790288"
134
+ "@amalgm/core": "0.5.1-preview.46154682692"
135
135
  },
136
- "gitHead": "5eb24deac4d1289399a54c7ab528f8834a44e693",
136
+ "gitHead": "4463595667422a27dec873c2ff32f1e71c704f8a",
137
137
  "amalgmSource": {
138
138
  "repository": "amalgm-inc/amalgm-live",
139
139
  "branch": "preview",
140
- "commit": "5eb24deac4d1289399a54c7ab528f8834a44e693",
141
- "occurrence": "46147035832"
140
+ "commit": "4463595667422a27dec873c2ff32f1e71c704f8a",
141
+ "occurrence": "46155260343"
142
142
  }
143
143
  }