@feng0531/dsh-vcs 0.9.3 → 0.9.5

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/docs/RELEASING.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  每次改动完成并验证通过后,按授权渠道完成正式发布,不停留在本地修改或只推标签。默认 `both` 联合 npm/GitHub;明确仅 GitHub 的版本使用 `github-only`,不接触 npm token、registry 或 latest。渠道例外写入该版本说明,不能据 GitHub 版本号推断 npm 可用版本。版本使用 `vX.Y.Z`:X 为大版本,Y 为小版本/新增功能,Z 为 BUG 修复;递增前一位时后面的位归零。失败门禁必须先修复,不能为了发布跳过验证。发布不自动安装或重启宿主。
8
8
 
9
- 每个新版本必须有独立的中文发布说明,放在 `docs/releases/版本号.md`。按“本版变化、安装、限制、验证”组织,不把自动提交列表、开发轮次或内部恢复记录当作用户说明。没有新增功能时明确写出,不夸大改动。
9
+ 每个新版本必须有独立的中文发布说明,放在 `docs/releases/版本号.md`。按“本版变化、安装、限制、验证”组织,不把自动提交列表、开发轮次或内部恢复记录当作用户说明。没有新增功能时明确写出,不夸大改动。正文会直接用于 GitHub Release;仓库文档链接须用完整 GitHub URL,不使用相对路径。发布后打开 Release 页面确认链接可用。
10
10
 
11
11
  更新包版本和锁文件,在变更记录中填写同一版本。核查许可证、第三方声明及公开文件,排除凭据和私人数据。
12
12
 
@@ -68,7 +68,7 @@ node scripts/release-host-fixture.mjs pack <含node_modules和package-lock.json
68
68
 
69
69
  在 Actions 从 main 运行 **Publish GitHub and npm**,输入已验证的标签。
70
70
 
71
- 工作流检出该标签,验证同标签证据,直接使用已验证的候选 tgz,不重新生成另一份包。`both` 先上传 npm,再验证公开 npm 元数据与实际下载字节,最后公开 GitHub Release;`github-only` 跳过全部 npm 步骤,仅上传已验证候选及 SHA-256 校验文件。
71
+ 工作流检出该标签,验证同标签证据,直接使用已验证的候选 tgz,不重新生成另一份包。`both` 先上传 npm,再验证公开 npm 元数据与实际下载字节,最后公开 GitHub Release;`github-only` 跳过全部 npm 步骤。两种渠道均在 GitHub 上传候选 tgz、`SHA256SUMS.txt` 和 `release-evidence.json`。
72
72
 
73
73
  仅 `both` 渠道需配置 `NPM_AUTOMATION_TOKEN`,具有该包发布权限并符合 npm 2FA 策略;`github-only` 无需该凭据。凭据只用于上传步骤;不要写进源码、发布说明或聊天。
74
74
 
package/index.mjs CHANGED
@@ -377,7 +377,7 @@ function latestCommitPayload(payload) {
377
377
  const optionalField = (key, value) => value === undefined ? {} : {[key]: value};
378
378
 
379
379
  /** Dispatch only after grants and capacity have been checked by createHandler. */
380
- async function readRepository(api, endpoint, repository, payload, {cwd, mode, signal}) {
380
+ async function readRepository(api, endpoint, repository, payload, {cwd, mode, signal, svnModifiedPath}) {
381
381
  switch (endpoint) {
382
382
  case 'vcs/tree-page':
383
383
  return api.getHistoricalTreePage({...repository}, {commit: payload.commit, path: payload.path ?? '', offset: payload.offset ?? 0, limit: payload.limit ?? 100, ...optionalField('query', payload.query), signal});
@@ -445,7 +445,7 @@ async function readRepository(api, endpoint, repository, payload, {cwd, mode, si
445
445
  case 'vcs/conflict-stages':
446
446
  return api.getConflictStages({...repository}, {mode, id: payload.id, signal});
447
447
  case 'vcs/compare':
448
- return api.getComparison({...repository}, {mode, id: payload.id, ...optionalField('signal', signal), ...optionalField('large', payload.large)});
448
+ return api.getComparison({...repository}, {mode, id: payload.id, ...optionalField('signal', signal), ...optionalField('large', payload.large), ...optionalField('svnModifiedPath', svnModifiedPath)});
449
449
  }
450
450
  }
451
451
 
@@ -453,6 +453,10 @@ async function readRepository(api, endpoint, repository, payload, {cwd, mode, si
453
453
  export function createHandler(ctx, api = adapter, maxActive = 4, { now = Date.now, ttlMs = 5 * 60_000, maxSessions = 32, maxRepositories = 512, operationTimeoutMs = 15000, bindSvnIdentityResolver } = {}) {
454
454
  let active = 0, activeImages = 0, activeSegments = 0;
455
455
  const sessions = new Map();
456
+ // Only the most recent SVN status list per Session supplies optional path hints.
457
+ const svnSelections = new WeakMap();
458
+ const MAX_SVN_HINTS = 10000;
459
+ let svnStatusSequence = 0;
456
460
  const commit=createCommitCoordinator({api,now});
457
461
  const amend=createAmendCoordinator({api,now});
458
462
  const branchCreate=createBranchCreateCoordinator({api,now});
@@ -477,6 +481,7 @@ export function createHandler(ctx, api = adapter, maxActive = 4, { now = Date.no
477
481
  const lineUnstage=createLineUnstageCoordinator({api,now});
478
482
 
479
483
  const clearGrantCache = entry => {
484
+ svnSelections.delete(entry);
480
485
  branchCreate.invalidate(entry);
481
486
  tagCreate.invalidate(entry);
482
487
  lightweightTag.invalidate(entry);
@@ -589,8 +594,23 @@ export function createHandler(ctx, api = adapter, maxActive = 4, { now = Date.no
589
594
 
590
595
  /** Read through the adapter, then require both the cwd grant and the selected repository to be current. */
591
596
  async function readGrantedRepository(endpoint, repository, payload, cwd, mode, entry, signal) {
592
- const value = await readRepository(api, endpoint, repository, payload, {cwd, mode, signal});
597
+ const svnStatus = repository.type === 'svn' && endpoint === 'vcs/status';
598
+ const sequence = svnStatus ? ++svnStatusSequence : 0;
599
+ const previous = svnSelections.get(entry);
600
+ if (svnStatus) svnSelections.set(entry, {sequence, repository});
601
+ const svnModifiedPath = endpoint === 'vcs/compare' && previous?.repository === repository
602
+ ? previous.paths?.get(payload.id) : undefined;
603
+ const value = await readRepository(api, endpoint, repository, payload, {cwd, mode, signal, svnModifiedPath});
593
604
  await assertCurrentGrant(payload.sessionId, cwd, entry, payload.repositoryId, repository, signal);
605
+ const snapshot = svnSelections.get(entry);
606
+ if (svnStatus && snapshot?.sequence === sequence) {
607
+ const hints = new Map();
608
+ for (const row of value.changes) {
609
+ if (hints.size === MAX_SVN_HINTS) break;
610
+ if (row.status === 'modified' && typeof row.path === 'string' && row.path.length <= 4096 && row.path !== '.') hints.set(row.id, row.path);
611
+ }
612
+ snapshot.paths = hints;
613
+ }
594
614
  return value;
595
615
  }
596
616
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feng0531/dsh-vcs",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "private": false,
5
5
  "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
6
6
  "type": "module",
@@ -1,5 +1,7 @@
1
1
  // Start independent reads together, drain ALL siblings, then consume errors in input order.
2
- export async function settledReads(reads){
2
+ export async function settledReads(reads,signal){
3
3
  const settled=await Promise.allSettled(reads.map(read=>Promise.resolve().then(read)));
4
+ // Prefer caller cancellation after every sibling has settled.
5
+ signal?.throwIfAborted();
4
6
  const values=[];for(const row of settled){if(row.status==='rejected')throw row.reason;values.push(row.value);}return values;
5
7
  }
package/vcs.mjs CHANGED
@@ -24,6 +24,7 @@ import {createHistoricalAccess,validateHistoricalPath} from './src/historical-ac
24
24
  import {withComparisonPreview} from './src/preview-capabilities.mjs';
25
25
  import {searchContentPage} from './src/content-search.mjs';
26
26
  import {withOperationBudget} from './src/operation-budget.mjs';
27
+ import {settledReads} from './src/settled-reads.mjs';
27
28
  import {parseReflog, REFLOG_FORMAT, REFLOG_MAX_OUTPUT} from './src/reflog.mjs';
28
29
 
29
30
  const historicalAccess = createHistoricalAccess({run:git});
@@ -240,9 +241,10 @@ async function resolveHeadCommit(run) {
240
241
  }
241
242
  }
242
243
  export async function getSvnIdentity(repo,{signal}={}){
243
- repo=await checkedRepo(repo,signal);if(repo.type!=='svn')throw Error('SVN working copy required');
244
+ signal?.throwIfAborted();
245
+ if(repo?.type!=='svn'||typeof repo.root!=='string')throw Error('SVN working copy required');
244
246
  const result=parseSvnIdentity((await svn(repo.root,['info','--xml','--', '.'],MAX_TEXT,{signal})).toString('utf8'));
245
- if(await fs.realpath(result.wcRoot)!==repo.root)throw Error('SVN working copy root changed');signal?.throwIfAborted();return result;
247
+ if(path.resolve(await fs.realpath(result.wcRoot))!==path.resolve(repo.root))throw Error('SVN working copy root changed');signal?.throwIfAborted();return result;
246
248
  }
247
249
  export async function listHistory(repo, {snapshot,offset=0,limit=50,search,signal} = {}) {
248
250
  const query=historySearchArgs(search);
@@ -577,7 +579,8 @@ async function annotateSubmodules(repo, entries, options) {
577
579
  const pointers = new Map();
578
580
  const deadline=Date.now()+(options?.timeoutMs??TIMEOUT);
579
581
  const check=()=>{options?.signal?.throwIfAborted();if(Date.now()>=deadline)throw Object.assign(Error('Index metadata timed out'),{code:'TIMEOUT'});};
580
- const files=entries.filter(entry=>entry.status!=='conflicted').map(entry=>entry.path);
582
+ // Porcelain ?? rows have no stage-0 entry. Never send them through batched index lookups.
583
+ const files=entries.filter(entry=>entry.status!=='conflicted'&&entry.indexStatus!=='?').map(entry=>entry.path);
581
584
  for(let from=0;from<files.length;){
582
585
  check();const batch=[];let bytes=0;
583
586
  while(from<files.length&&batch.length<METADATA_BATCH_SIZE){const file=files[from],size=Buffer.byteLength(file,'utf8')+1;if(size>METADATA_BATCH_BYTES)throw Error('Selected path exceeds metadata budget');if(bytes+size>METADATA_BATCH_BYTES)break;batch.push(file);bytes+=size;from++;}
@@ -623,7 +626,7 @@ async function annotateSubmodules(repo, entries, options) {
623
626
  }
624
627
  }
625
628
  const statuses = { M: 'modified', A: 'added', D: 'deleted', R: 'renamed', C: 'copied', U: 'conflicted', T: 'typechanged', '?': 'untracked' };
626
- async function changes(repo, mode, options) {
629
+ async function changes(repo, mode, options, selectedPath) {
627
630
  let entries;
628
631
  if (repo.type === 'git') {
629
632
  const fields = (await git(repo.root, ['status', '--porcelain=v1', '-z', '--untracked-files=all', '--ignore-submodules=none'],undefined,options)).toString('utf8').split('\0');
@@ -639,7 +642,8 @@ async function changes(repo, mode, options) {
639
642
  }
640
643
  await annotateSubmodules(repo, entries, options);
641
644
  } else {
642
- const document = parseXML(await svn(repo.root, ['status', '--xml', '--ignore-externals', '--', '.'], undefined, options));
645
+ const targets = selectedPath === undefined ? ['--', '.'] : ['--depth', 'empty', '--', selectedPath + '@'];
646
+ const document = parseXML(await svn(repo.root, ['status', '--xml', '--ignore-externals', ...targets], undefined, options));
643
647
  entries = [];
644
648
  for (const target of document.status?.target || []) for (const item of target.entry || []) {
645
649
  const state = item['wc-status'];
@@ -649,7 +653,7 @@ async function changes(repo, mode, options) {
649
653
  entries.push({ path: file, status: state['tree-conflicted'] === 'true' || state.props === 'conflicted' ? 'conflicted' : state.item === 'normal' ? 'modified' : state.item, propertyStatus: state.props, treeConflict: state['tree-conflicted'] === 'true' });
650
654
  }
651
655
  }
652
- return entries.map(entry => ({ ...entry, id: identity(entry, mode) }));
656
+ return entries.filter(entry => selectedPath === undefined || entry.path === selectedPath).map(entry => ({ ...entry, id: identity(entry, mode) }));
653
657
  }
654
658
  /** Changes have opaque IDs, status words, and repo-relative paths. */
655
659
  export async function listChanges(repo, mode = 'all', {signal} = {}) { repo = await checkedRepo(repo,signal); modeFor(repo, mode); const result=await changes(repo, mode,{signal});signal?.throwIfAborted();return result; }
@@ -730,8 +734,10 @@ export async function getCommitComparison(repo,{commit,parentIndex=0,id,signal,l
730
734
  const details=await commitDetails(repo,{commit,parentIndex,signal});
731
735
  const entry=details.changes.find(row=>row.id===id);
732
736
  if(!entry)throw new Error('Historical change is not part of selected commit and parent');
733
- const left=details.parent&&entry.status!=='added'?await historicalBlob(repo.root,details.parent,entry.oldPath||entry.path,signal,large):{text:''};
734
- const right=entry.status!=='deleted'?await historicalBlob(repo.root,commit,entry.path,signal,large):{text:''};
737
+ const [left,right]=await settledReads([
738
+ ()=>details.parent&&entry.status!=='added'?historicalBlob(repo.root,details.parent,entry.oldPath||entry.path,signal,large):{text:''},
739
+ ()=>entry.status!=='deleted'?historicalBlob(repo.root,commit,entry.path,signal,large):{text:''},
740
+ ]);
735
741
  return withComparisonPreview({...entry,large,left:{...left,label:details.parent||'Empty tree'},right:{...right,label:commit},binary:!!(left.binary||right.binary),notice:[left.notice,right.notice].filter(Boolean).join(' ')},{allowLarge:true});
736
742
  }
737
743
  export async function getRevisionComparison(repo,{base,target,id,signal,large=false}={}){
@@ -740,8 +746,10 @@ export async function getRevisionComparison(repo,{base,target,id,signal,large=fa
740
746
  const details=await getRevisionChanges(repo,{base,target,signal});
741
747
  const entry=details.changes.find(row=>row.id===id);
742
748
  if(!entry)throw new Error('Change is not part of selected revision pair');
743
- const left=entry.status!=='added'?await historicalBlob(repo.root,base,entry.oldPath||entry.path,signal,large):{text:''};
744
- const right=entry.status!=='deleted'?await historicalBlob(repo.root,target,entry.path,signal,large):{text:''};
749
+ const [left,right]=await settledReads([
750
+ ()=>entry.status!=='added'?historicalBlob(repo.root,base,entry.oldPath||entry.path,signal,large):{text:''},
751
+ ()=>entry.status!=='deleted'?historicalBlob(repo.root,target,entry.path,signal,large):{text:''},
752
+ ]);
745
753
  return withComparisonPreview({...entry,base,target,large,left:{...left,label:base},right:{...right,label:target},binary:!!(left.binary||right.binary),notice:[left.notice,right.notice].filter(Boolean).join(' ')},{allowLarge:true});
746
754
  }
747
755
  async function properties(root, file, base, signal) {
@@ -820,13 +828,16 @@ async function workingIdentity(root, file) {
820
828
  }
821
829
 
822
830
  /** Bind mutable HEAD/Index to immutable objects, then reject any changed selection. */
823
- export async function getComparison(repo, {mode = 'all',id,large = false,signal} = {}) {
831
+ export async function getComparison(repo, {mode = 'all',id,large = false,signal,svnModifiedPath} = {}) {
824
832
  if(typeof large !== 'boolean') throw Error('Invalid large comparison mode');
825
833
  if(large) return getWorkspaceLargeComparison(repo,{mode,id,signal});
826
834
  signal?.throwIfAborted();
827
- repo = await checkedRepo(repo,signal);modeFor(repo,mode);
828
- const status = () => changes(repo,mode,{signal});
829
- const entry = (await status()).find(item => item.id === id);
835
+ repo = await checkedRepo(repo,signal,undefined,false);modeFor(repo,mode);
836
+ // A server-owned path from status is only a hint. Re-check current SVN membership and ID.
837
+ const selectedPath = repo.type === 'svn' ? svnModifiedPath : undefined;
838
+ if(selectedPath !== undefined) await confined(repo.root,selectedPath);
839
+ const status = () => changes(repo,mode,{signal},selectedPath);
840
+ const entry = (await status()).find(item => item.id === id && (selectedPath === undefined || item.status === 'modified'));
830
841
  if(!entry) throw selectionChanged('Change no longer exists; refresh repository status.');
831
842
  await confined(repo.root,entry.path);
832
843
  if(entry.oldPath) await confined(repo.root,entry.oldPath);
@@ -836,37 +847,51 @@ export async function getComparison(repo, {mode = 'all',id,large = false,signal}
836
847
  if(repo.type === 'git') {
837
848
  const run = args => git(repo.root,args,MAX_TEXT,{signal});
838
849
  const head = () => resolveHeadCommit(run);
839
- const revision = await head();
840
850
  const indexArgs = ['ls-files','--stage','-z','--',entry.path];
841
- const index = await run(indexArgs);
851
+ const readSnapshot = () => settledReads([head,()=>run(indexArgs)],signal);
852
+ const [revision,index] = await readSnapshot();
842
853
  verify = async () => {
843
- if(revision !== await head() || !index.equals(await run(indexArgs))) throw selectionChanged();
854
+ const [currentHead,currentIndex] = await readSnapshot();
855
+ if(revision !== currentHead || !index.equals(currentIndex)) throw selectionChanged();
844
856
  };
845
857
  leftLabel = mode === 'unstaged' ? 'Index' : 'HEAD';
846
858
  rightLabel = mode === 'staged' ? 'Index' : 'Working tree';
847
859
  if(entry.status === 'conflicted') {
848
860
  notice = 'Unmerged conflict: showing HEAD versus working tree (index has conflict stages).';
849
861
  leftLabel = 'HEAD';rightLabel = 'Working tree';
850
- if(revision) left = await gitBlob(repo.root,revision,entry.oldPath || entry.path,{signal});
851
- right = await working(repo.root,entry.path,false,signal);
862
+ [left,right] = await settledReads([
863
+ ()=>revision ? gitBlob(repo.root,revision,entry.oldPath || entry.path,{signal}) : left,
864
+ ()=>working(repo.root,entry.path,false,signal),
865
+ ],signal);
852
866
  } else {
853
867
  const untracked = entry.indexStatus === '?';
854
868
  const addedToHead = entry.indexStatus === 'A' || entry.indexStatus === 'C';
855
- if(!untracked && (mode === 'unstaged' ? entry.indexStatus !== 'D' : revision && !addedToHead)) {
856
- left = await gitBlob(repo.root,mode === 'unstaged' ? '' : revision,mode === 'unstaged' ? entry.path : entry.oldPath || entry.path,{signal},index);
857
- }
858
- if(mode === 'staged') {if(entry.indexStatus !== 'D') right = await gitBlob(repo.root,'',entry.path,{signal},index);}
859
- else right = await working(repo.root,entry.path,false,signal);
869
+ const readLeft = !untracked && (mode === 'unstaged' ? entry.indexStatus !== 'D' : revision && !addedToHead);
870
+ [left,right] = await settledReads([
871
+ ()=>readLeft ? gitBlob(repo.root,mode === 'unstaged' ? '' : revision,mode === 'unstaged' ? entry.path : entry.oldPath || entry.path,{signal},index) : left,
872
+ ()=>mode !== 'staged' ? working(repo.root,entry.path,false,signal) : entry.indexStatus !== 'D' ? gitBlob(repo.root,'',entry.path,{signal},index) : right,
873
+ ],signal);
860
874
  }
861
875
  } else {
862
876
  leftLabel = 'BASE';rightLabel = 'Working copy';
863
877
  const added = ['added','unversioned','replaced'].includes(entry.status);
864
878
  const info = () => svn(repo.root,['info','--xml','--',entry.path + '@'],undefined,{signal});
865
879
  const before = entry.status === 'unversioned' ? null : await info();
880
+ const beforeEntry = before && parseXML(before).info.entry[0];
881
+ if(selectedPath !== undefined) {
882
+ const selectedRoot = beforeEntry?.['wc-info']?.['wcroot-abspath'];
883
+ if(!selectedRoot || path.resolve(await fs.realpath(selectedRoot)) !== path.resolve(repo.root)) throw selectionChanged();
884
+ }
885
+ const readProperties = async () => {
886
+ const base = () => added ? {} : properties(repo.root,entry.path,true,signal);
887
+ const work = () => ['deleted','missing'].includes(entry.status) ? {} : properties(repo.root,entry.path,false,signal);
888
+ const [left,right] = selectedPath === undefined ? [await base(),await work()] : await settledReads([base,work]);
889
+ return {left,right};
890
+ };
866
891
  verify = async () => {
867
892
  if(before && svnInfoSnapshot(before) !== svnInfoSnapshot(await info())) throw selectionChanged('SVN BASE selection changed; refresh repository status');
868
893
  if(props) {
869
- const after = {left:added ? {} : await properties(repo.root,entry.path,true,signal),right:['deleted','missing'].includes(entry.status) ? {} : await properties(repo.root,entry.path,false,signal)};
894
+ const after = await readProperties();
870
895
  if(stableSnapshot(after) !== stableSnapshot(props)) throw selectionChanged('SVN properties changed; refresh repository status');
871
896
  }
872
897
  };
@@ -874,12 +899,12 @@ export async function getComparison(repo, {mode = 'all',id,large = false,signal}
874
899
  let directory = false;
875
900
  try {directory = (await fs.lstat(await confined(repo.root,entry.path))).isDirectory();} catch(error) {if(error.code !== 'ENOENT') throw error;}
876
901
  if(!added && !directory) {
877
- directory = parseXML(before).info.entry[0].kind === 'dir';
902
+ directory = beforeEntry.kind === 'dir';
878
903
  if(!directory) left = await content(() => svn(repo.root,['cat','--revision','BASE','--',entry.path + '@'],MAX_TEXT,{signal}));
879
904
  }
880
905
  if(directory) {notice = 'Directory change; property differences are shown separately.';right = {text:'',previewReason:'unsupported-type',largeEligible:false};}
881
906
  else right = await working(repo.root,entry.path,true,signal);
882
- if(entry.status !== 'unversioned') props = {left:added ? {} : await properties(repo.root,entry.path,true,signal),right:['deleted','missing'].includes(entry.status) ? {} : await properties(repo.root,entry.path,false,signal)};
907
+ if(entry.status !== 'unversioned') props = await readProperties();
883
908
  if(entry.status === 'conflicted') notice = 'Conflicted working copy: showing BASE versus working content.';
884
909
  }
885
910
  await verify();