@feng0531/dsh-vcs 0.9.2 → 0.9.4

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
@@ -24,7 +24,7 @@
24
24
 
25
25
  测试失败或跳过须调查;隔离安装只检查包和宿主注册,不是用户实际 DSH 验收。
26
26
 
27
- 新增宿主兼容声明时,还需对精确宿主执行隔离检查。rc.3 和 rc.5 官方宿主要求 Node.js ≥24.9.0,宿主准备与合同工作流固定使用 24.9.0;插件旧宿主的 Node 22/24 四矩阵测试不变。离线宿主总解压预算为 2 GiB,单文件 256 MiB、压缩归档 512 MiB、成员 20 万,路径与链接检查不变:
27
+ 新增宿主兼容声明时,还需对精确宿主执行隔离检查。DSH `0.2.3-alpha.2` 官方宿主要求 Node.js `^24.22.3 || >=26.13.1`,宿主准备与合同工作流固定使用 24.22.3;插件的 Node 22/24 四矩阵回归不变。离线宿主总解压预算为 2 GiB,单文件 256 MiB、压缩归档 512 MiB、成员 20 万,路径与链接检查不变:
28
28
 
29
29
  ```sh
30
30
  npm run test:host-compat -- "<installed @deepseek-ai/dsh/package.json>"
@@ -37,7 +37,7 @@ npm run test:host-compat -- "<installed @deepseek-ai/dsh/package.json>"
37
37
  1. 提交并推送版本修改,创建新标签 `vX.Y.Z`;不移动已有标签。
38
38
  2. 等待标签 CI 的 Windows/Ubuntu × Node 22/24 全部成功。
39
39
  3. 手动在同一标签运行 **Browser layout checks**,等待成功。
40
- 4. 在同一标签运行 **Controlled host compatibility**,提供受控离线宿主工件 run ID 和七个精确版本的 SHA-256。每个版本必须有自己的真实合同结果。
40
+ 4. 在同一标签运行 **Controlled host compatibility**,提供受控离线宿主工件 run ID 和八个精确版本的 SHA-256。每个版本必须有自己的真实合同结果。
41
41
  5. 发布预检自动下载四份候选包与浏览器/宿主证据,绑定完整 tag ref、提交 SHA、run ID 和 attempt;核对内嵌版本、零跳过测试摘要及四包字节一致。缺失或失败均阻断。
42
42
 
43
43
  分支检查不能代替同标签检查。失败后先定位;需要修改源码或测试时使用新的版本和标签。
@@ -46,15 +46,15 @@ npm run test:host-compat -- "<installed @deepseek-ai/dsh/package.json>"
46
46
 
47
47
  浏览器与宿主合同任务不重新构建插件:先以 `npm ci --include=dev --ignore-scripts` 安装测试依赖,再由[发布预检脚本](<https://github.com/f-e-n-g-0531/dsh-vcs/blob/main/scripts/release-preflight.mjs>)的 `select-ci` 选定同标签、同提交的成功 CI run/attempt,下载全部四矩阵候选;`consume` 校验版本、测试零失败/取消/跳过/待办及四包字节一致后,将候选包里的发行文件作为本次测试输入。
48
48
 
49
- 消费过程生成 `consumed-candidate.json` 收据,记录候选归档 SHA-256、CI run/attempt 和归档位置。生成 Chrome 或宿主成功报告前,再核对原归档及每个已消费发行文件的实际字节;变化即失败,不能用重新构建的文件替代。报告中的 `candidateSha256`、`ciRun`、`ciAttempt` 必须与最终发布预检选中的四份 CI 候选一致,同时仍核对各自的完整 tag ref、提交 SHA 和证据任务 run/attempt。仅“同一提交测试通过”而没有这条字节关联,不足以放行;CI 重跑后也必须重新取得对应候选的浏览器与七版本宿主证据。
49
+ 消费过程生成 `consumed-candidate.json` 收据,记录候选归档 SHA-256、CI run/attempt 和归档位置。生成 Chrome 或宿主成功报告前,再核对原归档及每个已消费发行文件的实际字节;变化即失败,不能用重新构建的文件替代。报告中的 `candidateSha256`、`ciRun`、`ciAttempt` 必须与最终发布预检选中的四份 CI 候选一致,同时仍核对各自的完整 tag ref、提交 SHA 和证据任务 run/attempt。仅“同一提交测试通过”而没有这条字节关联,不足以放行;CI 重跑后也必须重新取得对应候选的浏览器与八版本宿主证据。
50
50
 
51
51
  ## 受控宿主准备与离线合同
52
52
 
53
- [宿主工件工作流](<https://github.com/f-e-n-g-0531/dsh-vcs/blob/main/.github/workflows/host-fixtures.yml>)仅允许默认分支手动执行,在 GitHub 托管的 Ubuntu runner 上为七个精确版本分别准备真实宿主:`0.1.7-rc.2`、`0.2.0-rc.2`、`0.2.1-rc.2`、`0.2.1-rc.5`、`0.2.2-rc.1`、`0.2.2-rc.3`、`0.2.2-rc.5`。这是明确授权的**在线准备阶段**,不是离线安装,也不使用日常 DSH 的配置或依赖目录。
53
+ [宿主工件工作流](<https://github.com/f-e-n-g-0531/dsh-vcs/blob/main/.github/workflows/host-fixtures.yml>)仅允许默认分支手动执行,在 GitHub 托管的 Ubuntu runner 上为八个精确版本分别准备真实宿主:`0.1.7-rc.2`、`0.2.0-rc.2`、`0.2.1-rc.2`、`0.2.1-rc.5`、`0.2.2-rc.1`、`0.2.2-rc.3`、`0.2.2-rc.5`、`0.2.3-alpha.2`。这是明确授权的**在线准备阶段**,不是离线安装,也不使用日常 DSH 的配置或依赖目录。
54
54
 
55
55
  工作流通过[准备脚本](<https://github.com/f-e-n-g-0531/dsh-vcs/blob/main/scripts/prepare-host-fixture.mjs>)固定同版本的官方 DSH 与 ui-slots 包,仅从 `https://registry.npmjs.org` 解析依赖。先生成锁文件并校验精确版本、下载地址及 SHA-512 integrity,再按锁文件安装;两次 npm 操作均禁用安装脚本。工件同时保存锁文件及准备记录,包括锁文件 SHA-256、准备源码 SHA、run ID 和 attempt。不启动宿主,不安装插件,不接触运行中的 profile。
56
56
 
57
- 准备完成后,在待发布标签运行[宿主兼容工作流](<https://github.com/f-e-n-g-0531/dsh-vcs/blob/main/.github/workflows/host-compat.yml>),提供成功准备任务的 `fixture_run` 和七个版本各自 `host.tar.gz` 的 SHA-256 映射 `fixture_hashes`。工作流只接受本仓库默认分支的受控准备工作流结果,拒绝其他工作流、fork/PR 以及不匹配的摘要;验证归档路径后提取真实依赖树。**宿主合同使用已准备的离线依赖树**,不再在线安装宿主、不启动 profile,也不能用 mock 或一个版本的结果冒充七版本通过。工作流下载证据及安装插件项目的测试依赖仍需要网络,不表示整项 CI 在断网环境运行。
57
+ 准备完成后,在待发布标签运行[宿主兼容工作流](<https://github.com/f-e-n-g-0531/dsh-vcs/blob/main/.github/workflows/host-compat.yml>),提供成功准备任务的 `fixture_run` 和八个版本各自 `host.tar.gz` 的 SHA-256 映射 `fixture_hashes`。工作流只接受本仓库默认分支的受控准备工作流结果,拒绝其他工作流、fork/PR 以及不匹配的摘要;验证归档路径后提取真实依赖树。**宿主合同使用已准备的离线依赖树**,不再在线安装宿主、不启动 profile,也不能用 mock 或一个版本的结果冒充八版本通过。工作流下载证据及安装插件项目的测试依赖仍需要网络,不表示整项 CI 在断网环境运行。
58
58
 
59
59
  若维护者已有完整可信依赖树,也可本地生成相同宿主归档:
60
60
 
@@ -62,7 +62,7 @@ npm run test:host-compat -- "<installed @deepseek-ai/dsh/package.json>"
62
62
  node scripts/release-host-fixture.mjs pack <含node_modules和package-lock.json的根目录> <精确版本> <新的输出目录>
63
63
  ```
64
64
 
65
- 归档来源必须包含完整依赖与锁文件;根目录内合法依赖链接可物化为普通文件,指向根目录外的链接或外部依赖 store 会被拒绝,须先将依赖完整准备在根目录内。归档本身不得保留链接或越界项。本地生成归档不绕过发布工作流的受控来源检查;七版本工件或真实合同不完整时发布仍会阻断。
65
+ 归档来源必须包含完整依赖与锁文件;根目录内合法依赖链接可物化为普通文件,指向根目录外的链接或外部依赖 store 会被拒绝,须先将依赖完整准备在根目录内。归档本身不得保留链接或越界项。本地生成归档不绕过发布工作流的受控来源检查;八版本工件或真实合同不完整时发布仍会阻断。
66
66
 
67
67
  ## 3. 按渠道发布
68
68
 
@@ -1,9 +1,14 @@
1
1
  import {readFile} from 'node:fs/promises';
2
2
  import {createHash} from 'node:crypto';
3
3
  const digest=bytes=>createHash('sha256').update(bytes).digest('hex');
4
+ // New WebServer versions pass the admitted Peer; older routes authenticate the request locally.
5
+ export function assetRejection(ctx,req,peer){
6
+ if(peer!==undefined)return peer.principal?.kind==='owner'?undefined:403;
7
+ return ctx.connection.admit(req).rejection;
8
+ }
4
9
  export function registerFrontendAssets(ctx,{running,load=name=>readFile(new URL('./dist/'+name,import.meta.url))}={}){
5
- for(const name of ['frontend.json','interface.js'])ctx.effect(()=>ctx.webServer.register({kind:'exact',path:'/vcs-assets/'+name,async handler(req,res){
6
- const admission=ctx.connection.admit(req);if('rejection' in admission){res.writeHead(admission.rejection);res.end();return;}
10
+ for(const name of ['frontend.json','interface.js'])ctx.effect(()=>ctx.webServer.register({kind:'exact',path:'/vcs-assets/'+name,auth:'required',async handler(req,res,peer){
11
+ const rejection=assetRejection(ctx,req,peer);if(rejection!==undefined){res.writeHead(rejection);res.end();return;}
7
12
  if(!['GET','HEAD'].includes(req.method)){res.writeHead(405,{Allow:'GET, HEAD'});res.end();return;}
8
13
  try{
9
14
  let bytes=await load(name);
package/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import {readFileSync} from 'node:fs';
3
- import {registerFrontendAssets} from './frontend-assets.mjs';
3
+ import {assetRejection,registerFrontendAssets} from './frontend-assets.mjs';
4
4
  const runningFrontend=JSON.parse(readFileSync(new URL('./dist/frontend.json',import.meta.url),'utf8'));
5
5
  import * as adapter from './vcs.mjs';
6
6
  import {createIndexUnstageCoordinator} from './index-change-host.mjs';
@@ -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
 
@@ -756,10 +776,10 @@ export function registerAssets(ctx, load = filename => readFile(new URL('./dist/
756
776
  /** Dedicated static routes avoid dependence on the shared /api dispatcher. */
757
777
  export function registerDirectAssets(ctx, load = filename => readFile(new URL('./dist/' + filename, import.meta.url))) {
758
778
  for (const filename of ASSETS) ctx.effect(() => ctx.webServer.register({
759
- kind: 'exact', path: '/vcs-assets/' + filename,
760
- async handler(req, res) {
761
- const admission = ctx.connection.admit(req);
762
- if ('rejection' in admission) { res.writeHead(admission.rejection); res.end(admission.rejection === 401 ? 'unauthorized' : 'forbidden'); return; }
779
+ kind: 'exact', path: '/vcs-assets/' + filename, auth: 'required',
780
+ async handler(req, res, peer) {
781
+ const rejection = assetRejection(ctx,req,peer);
782
+ if (rejection !== undefined) { res.writeHead(rejection); res.end(rejection === 401 ? 'unauthorized' : 'forbidden'); return; }
763
783
  if (!['GET', 'HEAD'].includes(req.method)) { res.writeHead(405, {Allow:'GET, HEAD'}); res.end(); return; }
764
784
  try {
765
785
  const bytes = await load(filename);
@@ -771,11 +791,17 @@ export function registerDirectAssets(ctx, load = filename => readFile(new URL('.
771
791
  }
772
792
 
773
793
  export function apply(ctx) {
774
- // Pass the plugin owner explicitly: the nested rpc getter can retain the
775
- // connection service context, which does not inject webServer.
776
794
  const host=createSvnHttpsHost(ctx,adapter);
777
795
  ctx.effect(()=>()=>{ host.dispose(); adapter.clearHistoricalCache?.(); });
778
- ctx.connection.register(ctx, RPC_CHANNEL, host.handle);
796
+ const connection=ctx.connection;
797
+ if(!('browserPeer' in connection)){
798
+ // Older hosts expose explicit owner registration.
799
+ connection.register(ctx,RPC_CHANNEL,host.handle);
800
+ }else{
801
+ // The new carrier admits a Peer before dispatch. VCS is local-owner only.
802
+ connection.rpc.handle(RPC_CHANNEL,(endpoint,payload,signal,peer)=>
803
+ peer?.principal?.kind==='owner'?host.handle(endpoint,payload,signal):failure('vcs/forbidden','VCS requires the local owner.'));
804
+ }
779
805
  registerAssets(ctx);
780
806
  registerDirectAssets(ctx);
781
807
  registerFrontendAssets(ctx,{running:runningFrontend});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feng0531/dsh-vcs",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "private": false,
5
5
  "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
6
6
  "type": "module",
@@ -102,7 +102,7 @@
102
102
  "test:performance": "node scripts/performance-baseline.mjs"
103
103
  },
104
104
  "peerDependencies": {
105
- "@deepseek-ai/dsh": "0.1.7-rc.2 || 0.2.0-rc.2 || 0.2.1-rc.2 || 0.2.1-rc.5 || 0.2.2-rc.1 || 0.2.2-rc.3 || 0.2.2-rc.5"
105
+ "@deepseek-ai/dsh": "0.1.7-rc.2 || 0.2.0-rc.2 || 0.2.1-rc.2 || 0.2.1-rc.5 || 0.2.2-rc.1 || 0.2.2-rc.3 || 0.2.2-rc.5 || 0.2.3-alpha.2"
106
106
  },
107
107
  "peerDependenciesMeta": {
108
108
  "@deepseek-ai/dsh": { "optional": true }
@@ -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();