@ibgib/vcs-gib 0.0.30 → 0.0.32

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.
Files changed (151) hide show
  1. package/dist/AUTO-GENERATED-version.d.mts +1 -1
  2. package/dist/AUTO-GENERATED-version.mjs +1 -1
  3. package/dist/bootstrap/node-bootstrap.mjs +1 -1
  4. package/dist/bootstrap/node-bootstrap.mjs.map +1 -1
  5. package/dist/cli/commands/add-cmd.d.mts +2 -3
  6. package/dist/cli/commands/add-cmd.d.mts.map +1 -1
  7. package/dist/cli/commands/add-cmd.mjs +30 -283
  8. package/dist/cli/commands/add-cmd.mjs.map +1 -1
  9. package/dist/cli/commands/branch-cmd.d.mts +8 -8
  10. package/dist/cli/commands/branch-cmd.d.mts.map +1 -1
  11. package/dist/cli/commands/branch-cmd.mjs +45 -176
  12. package/dist/cli/commands/branch-cmd.mjs.map +1 -1
  13. package/dist/cli/commands/checkout-cmd.d.mts +2 -4
  14. package/dist/cli/commands/checkout-cmd.d.mts.map +1 -1
  15. package/dist/cli/commands/checkout-cmd.mjs +31 -110
  16. package/dist/cli/commands/checkout-cmd.mjs.map +1 -1
  17. package/dist/cli/commands/commit-cmd.d.mts +7 -8
  18. package/dist/cli/commands/commit-cmd.d.mts.map +1 -1
  19. package/dist/cli/commands/commit-cmd.mjs +40 -390
  20. package/dist/cli/commands/commit-cmd.mjs.map +1 -1
  21. package/dist/cli/commands/generate-comment-cmd.d.mts.map +1 -1
  22. package/dist/cli/commands/generate-comment-cmd.mjs +5 -2
  23. package/dist/cli/commands/generate-comment-cmd.mjs.map +1 -1
  24. package/dist/cli/commands/init-cmd.d.mts +2 -2
  25. package/dist/cli/commands/init-cmd.d.mts.map +1 -1
  26. package/dist/cli/commands/init-cmd.mjs +20 -70
  27. package/dist/cli/commands/init-cmd.mjs.map +1 -1
  28. package/dist/cli/commands/log-cmd.d.mts +2 -3
  29. package/dist/cli/commands/log-cmd.d.mts.map +1 -1
  30. package/dist/cli/commands/log-cmd.mjs +42 -271
  31. package/dist/cli/commands/log-cmd.mjs.map +1 -1
  32. package/dist/cli/commands/merge-cmd.d.mts +3 -17
  33. package/dist/cli/commands/merge-cmd.d.mts.map +1 -1
  34. package/dist/cli/commands/merge-cmd.mjs +32 -218
  35. package/dist/cli/commands/merge-cmd.mjs.map +1 -1
  36. package/dist/cli/commands/reset-cmd.d.mts +1 -1
  37. package/dist/cli/commands/reset-cmd.d.mts.map +1 -1
  38. package/dist/cli/commands/reset-cmd.mjs +17 -19
  39. package/dist/cli/commands/reset-cmd.mjs.map +1 -1
  40. package/dist/cli/commands/restore-cmd.d.mts +8 -7
  41. package/dist/cli/commands/restore-cmd.d.mts.map +1 -1
  42. package/dist/cli/commands/restore-cmd.mjs +44 -62
  43. package/dist/cli/commands/restore-cmd.mjs.map +1 -1
  44. package/dist/cli/commands/status-cmd.d.mts +2 -2
  45. package/dist/cli/commands/status-cmd.d.mts.map +1 -1
  46. package/dist/cli/commands/status-cmd.mjs +63 -62
  47. package/dist/cli/commands/status-cmd.mjs.map +1 -1
  48. package/dist/cli/vcs-projection-helper.d.mts +23 -0
  49. package/dist/cli/vcs-projection-helper.d.mts.map +1 -0
  50. package/dist/cli/vcs-projection-helper.mjs +91 -0
  51. package/dist/cli/vcs-projection-helper.mjs.map +1 -0
  52. package/dist/test/test-helpers.d.mts +2 -2
  53. package/dist/test/test-helpers.d.mts.map +1 -1
  54. package/package.json +3 -3
  55. package/src/AUTO-GENERATED-version.mts +1 -1
  56. package/src/bootstrap/node-bootstrap.mts +1 -1
  57. package/src/cli/cli-e2e.respec.mts +4 -4
  58. package/src/cli/commands/add-cmd.mts +32 -347
  59. package/src/cli/commands/branch-cmd.mts +56 -225
  60. package/src/cli/commands/checkout-cmd.mts +34 -138
  61. package/src/cli/commands/commit-cmd.mts +46 -473
  62. package/src/cli/commands/commit-log-cmd.respec.mts +11 -7
  63. package/src/cli/commands/generate-comment-cmd.mts +6 -2
  64. package/src/cli/commands/init-cmd.mts +20 -73
  65. package/src/cli/commands/log-cmd.mts +41 -331
  66. package/src/cli/commands/merge-cmd.mts +32 -252
  67. package/src/cli/commands/reset-cmd.mts +17 -19
  68. package/src/cli/commands/restore-cmd.mts +52 -72
  69. package/src/cli/commands/status-add-cmd.respec.mts +3 -3
  70. package/src/cli/commands/status-cmd.mts +68 -63
  71. package/src/cli/vcs-projection-helper.mts +112 -0
  72. package/src/engine/branch/branch-space.respec.mts +5 -5
  73. package/src/engine/merge/b2tfs-sync-comments.respec.mts +4 -4
  74. package/src/test/test-helpers.mts +2 -2
  75. package/src/vcs-gib.respec.mts +11 -8
  76. package/tsconfig.test.tsbuildinfo +1 -1
  77. package/tsconfig.tsbuildinfo +1 -1
  78. package/dist/engine/branch/branch-graph-helper.d.mts +0 -28
  79. package/dist/engine/branch/branch-graph-helper.d.mts.map +0 -1
  80. package/dist/engine/branch/branch-graph-helper.mjs +0 -81
  81. package/dist/engine/branch/branch-graph-helper.mjs.map +0 -1
  82. package/dist/engine/branch/branch-helper.d.mts +0 -40
  83. package/dist/engine/branch/branch-helper.d.mts.map +0 -1
  84. package/dist/engine/branch/branch-helper.mjs +0 -78
  85. package/dist/engine/branch/branch-helper.mjs.map +0 -1
  86. package/dist/engine/branch/branch-space-helper.d.mts +0 -23
  87. package/dist/engine/branch/branch-space-helper.d.mts.map +0 -1
  88. package/dist/engine/branch/branch-space-helper.mjs +0 -78
  89. package/dist/engine/branch/branch-space-helper.mjs.map +0 -1
  90. package/dist/engine/branch/branch-types.d.mts +0 -26
  91. package/dist/engine/branch/branch-types.d.mts.map +0 -1
  92. package/dist/engine/branch/branch-types.mjs +0 -7
  93. package/dist/engine/branch/branch-types.mjs.map +0 -1
  94. package/dist/engine/diff/line-diff-helper.d.mts +0 -76
  95. package/dist/engine/diff/line-diff-helper.d.mts.map +0 -1
  96. package/dist/engine/diff/line-diff-helper.mjs +0 -144
  97. package/dist/engine/diff/line-diff-helper.mjs.map +0 -1
  98. package/dist/engine/filter/glob-helper.d.mts +0 -51
  99. package/dist/engine/filter/glob-helper.d.mts.map +0 -1
  100. package/dist/engine/filter/glob-helper.mjs +0 -132
  101. package/dist/engine/filter/glob-helper.mjs.map +0 -1
  102. package/dist/engine/index/index-helper.d.mts +0 -113
  103. package/dist/engine/index/index-helper.d.mts.map +0 -1
  104. package/dist/engine/index/index-helper.mjs +0 -533
  105. package/dist/engine/index/index-helper.mjs.map +0 -1
  106. package/dist/engine/index/index-types.d.mts +0 -63
  107. package/dist/engine/index/index-types.d.mts.map +0 -1
  108. package/dist/engine/index/index-types.mjs +0 -7
  109. package/dist/engine/index/index-types.mjs.map +0 -1
  110. package/dist/engine/item/item-atom-helper.d.mts +0 -20
  111. package/dist/engine/item/item-atom-helper.d.mts.map +0 -1
  112. package/dist/engine/item/item-atom-helper.mjs +0 -30
  113. package/dist/engine/item/item-atom-helper.mjs.map +0 -1
  114. package/dist/engine/item/item-helper.d.mts +0 -94
  115. package/dist/engine/item/item-helper.d.mts.map +0 -1
  116. package/dist/engine/item/item-helper.mjs +0 -424
  117. package/dist/engine/item/item-helper.mjs.map +0 -1
  118. package/dist/engine/item/item-types.d.mts +0 -128
  119. package/dist/engine/item/item-types.d.mts.map +0 -1
  120. package/dist/engine/item/item-types.mjs +0 -16
  121. package/dist/engine/item/item-types.mjs.map +0 -1
  122. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts +0 -74
  123. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts.map +0 -1
  124. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs +0 -570
  125. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs.map +0 -1
  126. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts +0 -34
  127. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts.map +0 -1
  128. package/dist/engine/merge/b2tfs-3way-graft-types.mjs +0 -2
  129. package/dist/engine/merge/b2tfs-3way-graft-types.mjs.map +0 -1
  130. package/dist/engine/status/status-helper.d.mts +0 -90
  131. package/dist/engine/status/status-helper.d.mts.map +0 -1
  132. package/dist/engine/status/status-helper.mjs +0 -286
  133. package/dist/engine/status/status-helper.mjs.map +0 -1
  134. package/src/engine/branch/branch-graph-helper.mts +0 -117
  135. package/src/engine/branch/branch-helper.mts +0 -112
  136. package/src/engine/branch/branch-space-helper.mts +0 -110
  137. package/src/engine/branch/branch-types.mts +0 -29
  138. package/src/engine/diff/line-diff-helper.mts +0 -210
  139. package/src/engine/diff/line-diff-helper.respec.mts +0 -84
  140. package/src/engine/filter/glob-helper.mts +0 -165
  141. package/src/engine/filter/glob-helper.respec.mts +0 -94
  142. package/src/engine/index/index-helper.mts +0 -705
  143. package/src/engine/index/index-types.mts +0 -66
  144. package/src/engine/item/item-atom-helper.mts +0 -30
  145. package/src/engine/item/item-helper.mts +0 -544
  146. package/src/engine/item/item-types.mts +0 -137
  147. package/src/engine/item/item.respec.mts +0 -92
  148. package/src/engine/merge/b2tfs-3way-graft-strategy.mts +0 -630
  149. package/src/engine/merge/b2tfs-3way-graft-strategy.respec.mts +0 -346
  150. package/src/engine/merge/b2tfs-3way-graft-types.mts +0 -34
  151. package/src/engine/status/status-helper.mts +0 -383
@@ -1,25 +1,19 @@
1
1
  /**
2
2
  * @module init-cmd
3
3
  *
4
- * Command handler for `vcs init [targetDir]`.
5
- * Initializes local repository space, root B2tFS folder item, default branch, and in-band space index.
4
+ * CLI command handler for `vcs init [targetDir]`.
5
+ * Bootstraps Node environment, creates disk directories, and delegates to executeVcsInit.
6
6
  */
7
7
 
8
8
  import path from 'node:path';
9
9
  import fs from 'node:fs/promises';
10
10
 
11
- import { extractErrorMsg, getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
- import { Factory_V1 } from '@ibgib/ts-gib/dist/V1/factory.mjs';
13
- import { ROOT } from '@ibgib/ts-gib/dist/V1/constants.mjs';
14
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
15
- import { putInSpace, persistTransformResult } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
11
+ import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
+ import { executeVcsInit } from '@ibgib/core-gib/dist/vcs/commands/init-cmd.mjs';
16
13
 
17
14
  import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
18
- import { getB2tFSItemIb } from '../../engine/item/item-atom-helper.mjs';
19
- import { B2tFSItemIbGib_V1 } from '../../engine/item/item-types.mjs';
20
- import { createB2tFSBranchIbGib, getB2tFSBranchSpaceName } from '../../engine/branch/branch-helper.mjs';
21
- import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
22
- import { createB2tFSIndexIbGib, writeVcsIndexProjection } from '../../engine/index/index-helper.mjs';
15
+ import { getOrCreateBranchSpace } from '@ibgib/node-gib/dist/vcs/branch-space-helper.mjs';
16
+ import { writeVcsIndexProjectionToDisk } from '../vcs-projection-helper.mjs';
23
17
  import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
24
18
 
25
19
  const lcFile = `[init-cmd]`;
@@ -58,7 +52,7 @@ export async function executeInitCmd({
58
52
  await fs.mkdir(absTargetDir, { recursive: true });
59
53
 
60
54
  // Bootstrap Metaspace
61
- const { metaspace } = await bootstrapVcsMetaspace({
55
+ const { metaspace, localSpace } = await bootstrapVcsMetaspace({
62
56
  repoPath: absTargetDir,
63
57
  vcsFolderName,
64
58
  defaultSpaceName: `vcs_${path.basename(absTargetDir).replace(/[^a-zA-Z0-9_\-]/g, '_')}`,
@@ -72,81 +66,34 @@ export async function executeInitCmd({
72
66
  });
73
67
 
74
68
  const folderName = path.basename(absTargetDir) || 'root';
75
- const rootNameHash = await getUUID();
76
-
77
- // 1. Create root folder B2tFS item inside b2s_main space
78
- const rootItemRes = await Factory_V1.firstGen({
79
- parentIbGib: ROOT,
80
- ib: getB2tFSItemIb('folder', folderName, rootNameHash),
81
- data: {
82
- name: folderName,
83
- nameHash: rootNameHash,
84
- fsType: 'folder',
85
- diffTransactionId: await getUUID(),
86
- uuid: await getUUID(),
87
- classname: 'B2tFSItemIbGib_V1',
88
- },
89
- });
90
-
91
- const rootItem = rootItemRes.newIbGib as B2tFSItemIbGib_V1;
92
- await persistTransformResult({ resTransform: rootItemRes, space: branchSpace });
93
- await metaspace.registerNewIbGib({ ibGib: rootItem, space: branchSpace });
94
69
 
95
- // 2. Create default branch pointing to root folder inside b2s_main space
96
- const branchIbGib = await createB2tFSBranchIbGib({
97
- branchName: defaultBranchName,
98
- rootItem,
99
- space: branchSpace,
70
+ const initRes = await executeVcsInit({
100
71
  metaspace,
101
- });
102
- const branchAddr = getIbGibAddr({ ibGib: branchIbGib });
103
-
104
- // 3. Create space index meta object stored inside b2s_main space
105
- const indexIbGib = await createB2tFSIndexIbGib({
106
- spaceId,
107
- activeSpaceId: getB2tFSBranchSpaceName(defaultBranchName),
108
- activeBranch: defaultBranchName,
109
- space: branchSpace,
110
- metaspace,
111
- branchAddr,
112
- });
113
-
114
- // 4. Write read-only projection file in .vcsgib/
115
- await writeVcsIndexProjection({
116
- vcsPath,
117
- indexIbGib,
72
+ branchSpace,
73
+ localSpace,
74
+ rootFolderName: folderName,
75
+ defaultBranchName,
76
+ vcsFolderName,
118
77
  });
119
78
 
120
- // Clean up legacy out-of-band state files if present
121
- try {
122
- await fs.rm(path.join(vcsPath, 'vcs_state.json'), { force: true });
123
- } catch {
124
- // Ignore if missing
125
- }
126
- try {
127
- await fs.rm(path.join(vcsPath, 'staging.json'), { force: true });
128
- } catch {
129
- // Ignore if missing
130
- }
79
+ await writeVcsIndexProjectionToDisk({ vcsPath, indexIbGib: initRes.indexIbGib });
131
80
 
132
81
  if (!quiet) {
133
- console.log(`Initialized empty ibgib repository in ${vcsPath} (I: 6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f)`);
134
- console.log(` Branch: ${defaultBranchName}`);
135
- console.log(` Root Item: ${rootItem.ib}`);
82
+ console.log(`Initialized empty ibgib repository in ${vcsPath} (branch: ${defaultBranchName}) (I: 3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f)`);
136
83
  }
137
84
 
138
85
  return {
139
86
  vcsPath,
140
- spaceId,
141
- branchName: defaultBranchName,
142
- rootItemIb: rootItem.ib,
87
+ spaceId: initRes.spaceId,
88
+ branchName: initRes.branchName,
89
+ rootItemIb: initRes.rootItem.ib,
143
90
  };
144
91
  } catch (error) {
145
- console.error(`${lc} ${extractErrorMsg(error)} (E: 9b10c11d12e13f14a15b16c17d18e19f)`);
92
+ console.error(`${lc} ${extractErrorMsg(error)} (E: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d)`);
146
93
  throw error;
147
94
  } finally {
148
95
  if (logalot) {
149
- console.log(`${lc} complete. (I: 0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d)`);
96
+ console.log(`${lc} complete. (I: 2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e)`);
150
97
  }
151
98
  }
152
99
  }
@@ -1,25 +1,20 @@
1
1
  /**
2
2
  * @module log-cmd
3
3
  *
4
- * Command handler for `vcs log`.
5
- * Reads active branch timeline from B2tFSIndexIbGib_V1 in localSpace,
6
- * walks branch or item timeline history backward, and displays formatted commit and comment history.
4
+ * CLI command handler for `vcs log`.
5
+ * Delegates to executeVcsLog and formats console output.
7
6
  */
8
7
 
9
8
  import path from 'node:path';
10
9
  import fs from 'node:fs/promises';
11
10
 
12
11
  import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
13
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
14
- import { CommentIbGib_V1 } from '@ibgib/core-gib/dist/common/comment/comment-types.mjs';
12
+ import { executeVcsLog } from '@ibgib/core-gib/dist/vcs/commands/log-cmd.mjs';
13
+ import { resolveContextualBranchName } from '@ibgib/core-gib/dist/vcs/branch/branch-helper.mjs';
15
14
 
16
15
  import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
17
- import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
18
- import { resolveContextualBranchName } from '../../engine/branch/branch-helper.mjs';
19
- import { getIbGibWithMetaspaceFallback } from '../../engine/item/item-helper.mjs';
20
- import { B2tFSItemIbGib_V1, B2TFS_CHILD_ITEM_REL8N_NAME } from '../../engine/item/item-types.mjs';
21
- import { B2tFSBranchIbGib_V1 } from '../../engine/branch/branch-types.mjs';
22
- import { getB2tFSIndexIbGib, extractBranchNameFromAddr } from '../../engine/index/index-helper.mjs';
16
+ import { getOrCreateBranchSpace } from '@ibgib/node-gib/dist/vcs/branch-space-helper.mjs';
17
+ import { readVcsIndexProjectionFromDisk } from '../vcs-projection-helper.mjs';
23
18
  import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
24
19
 
25
20
  const lcFile = `[log-cmd]`;
@@ -80,7 +75,7 @@ export async function executeLogCmd({
80
75
  }
81
76
 
82
77
  // 1. Fetch authoritative B2tFSIndexIbGib_V1 directly from localSpace
83
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
78
+ const indexIbGib = await readVcsIndexProjectionFromDisk({ vcsPath, space: localSpace });
84
79
  if (!indexIbGib) {
85
80
  throw new Error(`Repository index B2tFSIndexIbGib_V1 not found in localSpace (E: 3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a)`);
86
81
  }
@@ -98,101 +93,22 @@ export async function executeLogCmd({
98
93
  branchName,
99
94
  });
100
95
 
101
- // 2. Fetch active branch node address matching active branchName
102
- const branchAddrs = indexIbGib.rel8ns?.branch || indexIbGib.rel8ns?.branch_tjp || [];
103
-
104
- let currBranchAddr: string | undefined;
105
- if (branchAddrs.length > 0) {
106
- let branchIbGibs: B2tFSBranchIbGib_V1[] = [];
107
- for (const bAddr of branchAddrs) {
108
- const bIbGib = await getIbGibWithMetaspaceFallback({
109
- addr: bAddr,
110
- space: activeSpace,
111
- metaspace,
112
- });
113
- if (bIbGib) {
114
- branchIbGibs.push(bIbGib as B2tFSBranchIbGib_V1);
115
- }
116
- }
117
-
118
- const matchingBranches = branchIbGibs.filter(b => b?.data?.name === branchName);
119
- const activeBranchIbGib = matchingBranches.sort((a, b) => (b.data?.n || 0) - (a.data?.n || 0))[0]
120
- || branchIbGibs.at(-1);
121
-
122
- if (activeBranchIbGib) {
123
- currBranchAddr = getIbGibAddr({ ibGib: activeBranchIbGib });
124
- }
125
- }
126
-
127
- const commits: VcsLogItem[] = [];
128
-
129
- // #region File-Specific Log Mode (vcs log <filePath>)
130
- if (filePath) {
131
- const normalizedRelPath = path.relative(repoRoot, path.resolve(absTargetDir, filePath)).replace(/\\/g, '/');
132
-
133
- // Find current root item
134
- const branchIbGib = currBranchAddr
135
- ? await getIbGibWithMetaspaceFallback({ addr: currBranchAddr, space: activeSpace, metaspace }) as B2tFSBranchIbGib_V1
136
- : undefined;
137
- const rootItemAddr = branchIbGib?.rel8ns?.b2tFS_item?.at(-1) || branchIbGib?.rel8ns?.b2tfs_item?.at(-1);
138
-
139
- if (!rootItemAddr) {
140
- throw new Error(`No root item found on branch ${branchName} (E: 4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b)`);
141
- }
142
-
143
- const targetItem = await logCmd_findItemByPath({
144
- rootItemAddr,
145
- targetRelPath: normalizedRelPath,
146
- space: activeSpace,
147
- metaspace,
148
- });
149
-
150
- if (!targetItem) {
151
- throw new Error(`Path '${normalizedRelPath}' not found in active branch snapshot (E: 5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c)`);
152
- }
153
-
154
- // Walk target item timeline history backward
155
- const visitedItemAddrs = new Set<string>();
156
- let currItem: B2tFSItemIbGib_V1 | undefined = targetItem;
157
-
158
- while (currItem) {
159
- const itemAddr = getIbGibAddr({ ibGib: currItem });
160
- if (visitedItemAddrs.has(itemAddr)) { break; }
161
- visitedItemAddrs.add(itemAddr);
162
-
163
- const commentAddrs = currItem.rel8ns?.comment || [];
164
- for (const cAddr of commentAddrs) {
165
- const commentIbGib = await getIbGibWithMetaspaceFallback({
166
- addr: cAddr,
167
- space: activeSpace,
168
- metaspace,
169
- }) as CommentIbGib_V1;
170
-
171
- if (commentIbGib) {
172
- commits.push({
173
- commitAddr: itemAddr,
174
- commentAddr: cAddr,
175
- message: commentIbGib.data?.text || '',
176
- timestamp: commentIbGib.data?.textTimestamp || commentIbGib.data?.timestamp || '',
177
- author: 'vcs-user',
178
- });
179
- }
180
- }
96
+ const logRes = await executeVcsLog({
97
+ metaspace,
98
+ localSpace,
99
+ activeBranchSpace: activeSpace,
100
+ indexIbGib,
101
+ filePath,
102
+ allComments,
103
+ repoRoot,
104
+ targetDir: absTargetDir,
105
+ });
181
106
 
182
- const pastAddr = currItem.rel8ns?.past?.at(0) || currItem.rel8ns?.ancestor?.at(0);
183
- if (pastAddr) {
184
- currItem = await getIbGibWithMetaspaceFallback({
185
- addr: pastAddr,
186
- space: activeSpace,
187
- metaspace,
188
- }) as B2tFSItemIbGib_V1;
189
- } else {
190
- currItem = undefined;
191
- }
192
- }
107
+ const commits: VcsLogItem[] = logRes.commits;
193
108
 
194
- if (!quiet) {
195
- console.log(`File: ${normalizedRelPath} (branch: ${branchName}) (I: 6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d)`);
109
+ if (!quiet) {
110
+ if (logRes.targetPath) {
111
+ console.log(`File: ${logRes.targetPath} (branch: ${logRes.branchName}) (I: 6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d)`);
196
112
  if (commits.length === 0) {
197
113
  console.log('No comments found for this file.');
198
114
  } else {
@@ -202,119 +118,25 @@ export async function executeLogCmd({
202
118
  console.log(`\n ${commit.message}\n`);
203
119
  }
204
120
  }
205
- }
206
-
207
- return {
208
- branchName,
209
- targetPath: normalizedRelPath,
210
- commits,
211
- };
212
- }
213
- // #endregion File-Specific Log Mode
214
-
215
- // #region Standard Branch Log Mode
216
- const visitedAddrs = new Set<string>();
217
-
218
- while (currBranchAddr && !visitedAddrs.has(currBranchAddr)) {
219
- visitedAddrs.add(currBranchAddr);
220
-
221
- const branchIbGib = await getIbGibWithMetaspaceFallback({
222
- addr: currBranchAddr,
223
- space: activeSpace,
224
- metaspace,
225
- }) as B2tFSBranchIbGib_V1;
226
-
227
- if (!branchIbGib) {
228
- break;
229
- }
230
-
231
- const rootItemAddr = branchIbGib.rel8ns?.b2tFS_item?.at(-1) || branchIbGib.rel8ns?.b2tfs_item?.at(-1);
232
-
233
- let rootItem: B2tFSItemIbGib_V1 | undefined;
234
- if (rootItemAddr) {
235
- rootItem = await getIbGibWithMetaspaceFallback({
236
- addr: rootItemAddr,
237
- space: activeSpace,
238
- metaspace,
239
- }) as B2tFSItemIbGib_V1;
240
- }
241
-
242
- let commentAddrs = [
243
- ...(branchIbGib.rel8ns?.comment || []),
244
- ...(rootItem?.rel8ns?.comment || []),
245
- ];
246
- // Deduplicate
247
- commentAddrs = Array.from(new Set(commentAddrs));
248
-
249
- let message = '';
250
- let timestamp = branchIbGib.data?.committedAt || '';
251
- // If branch has a direct comment, use that first, otherwise use the last added comment on root item
252
- let primaryCommentAddr = branchIbGib.rel8ns?.comment?.at(-1) || rootItem?.rel8ns?.comment?.at(-1) || commentAddrs.at(0);
253
-
254
- if (primaryCommentAddr) {
255
- const commentIbGib = await getIbGibWithMetaspaceFallback({
256
- addr: primaryCommentAddr,
257
- space: activeSpace,
258
- metaspace,
259
- }) as CommentIbGib_V1;
260
-
261
- if (commentIbGib?.data?.text) {
262
- message = commentIbGib.data.text;
263
- }
264
- if (commentIbGib?.data?.textTimestamp || commentIbGib?.data?.timestamp) {
265
- timestamp = commentIbGib.data.textTimestamp || commentIbGib.data.timestamp || timestamp;
266
- }
267
- }
268
-
269
- const committedPaths = branchIbGib.data?.committedPaths || [];
270
- const itemComments: Array<{ path: string; name?: string; message: string }> = [];
271
-
272
- if (allComments && rootItem) {
273
- await logCmd_collectAllItemComments({
274
- item: rootItem,
275
- space: activeSpace,
276
- metaspace,
277
- currentRelPath: '',
278
- outComments: itemComments,
279
- });
280
- }
281
-
282
- if (message || primaryCommentAddr || (committedPaths && committedPaths.length > 0)) {
283
- commits.push({
284
- branchAddr: currBranchAddr,
285
- commitAddr: currBranchAddr,
286
- commentAddr: primaryCommentAddr,
287
- message: message || '(no commit message)',
288
- timestamp,
289
- author: 'vcs-user',
290
- rootItemAddr,
291
- committedPaths,
292
- itemComments: itemComments.length > 0 ? itemComments : undefined,
293
- });
294
- }
295
-
296
- // Move to previous branch node in timeline
297
- currBranchAddr = branchIbGib.rel8ns?.past?.at(0) || branchIbGib.rel8ns?.ancestor?.at(0);
298
- }
299
-
300
- if (!quiet) {
301
- console.log(`Branch: ${branchName} (I: 4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b)`);
302
- if (commits.length === 0) {
303
- console.log('No commits yet.');
304
121
  } else {
305
- for (const commit of commits) {
306
- console.log(`\ncommit ${commit.commitAddr}`);
307
- console.log(`Author: ${commit.author}`);
308
- console.log(`Date: ${commit.timestamp}`);
309
- console.log(`\n ${commit.message}\n`);
310
- if (commit.committedPaths && commit.committedPaths.length > 0) {
311
- console.log(`Changed: ${commit.committedPaths.join(', ')}`);
312
- }
313
- if (commit.itemComments && commit.itemComments.length > 0) {
314
- console.log('Item Comments:');
315
- for (const ic of commit.itemComments) {
316
- const label = ic.name ? `${ic.path} (${ic.name})` : ic.path;
317
- console.log(` * [${label}]: ${ic.message}`);
122
+ console.log(`Branch: ${logRes.branchName} (I: 4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b)`);
123
+ if (commits.length === 0) {
124
+ console.log('No commits yet.');
125
+ } else {
126
+ for (const commit of commits) {
127
+ console.log(`\ncommit ${commit.commitAddr}`);
128
+ console.log(`Author: ${commit.author}`);
129
+ console.log(`Date: ${commit.timestamp}`);
130
+ console.log(`\n ${commit.message}\n`);
131
+ if (commit.committedPaths && commit.committedPaths.length > 0) {
132
+ console.log(`Changed: ${commit.committedPaths.join(', ')}`);
133
+ }
134
+ if (commit.itemComments && commit.itemComments.length > 0) {
135
+ console.log('Item Comments:');
136
+ for (const ic of commit.itemComments) {
137
+ const label = ic.name ? `${ic.path} (${ic.name})` : ic.path;
138
+ console.log(` * [${label}]: ${ic.message}`);
139
+ }
318
140
  }
319
141
  }
320
142
  }
@@ -322,10 +144,10 @@ export async function executeLogCmd({
322
144
  }
323
145
 
324
146
  return {
325
- branchName,
147
+ branchName: logRes.branchName,
148
+ targetPath: logRes.targetPath,
326
149
  commits,
327
150
  };
328
- // #endregion Standard Branch Log Mode
329
151
  } catch (error) {
330
152
  console.error(`${lc} ${extractErrorMsg(error)} (E: 5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c)`);
331
153
  throw error;
@@ -335,115 +157,3 @@ export async function executeLogCmd({
335
157
  }
336
158
  }
337
159
  }
338
-
339
- async function logCmd_findItemByPath({
340
- rootItemAddr,
341
- targetRelPath,
342
- space,
343
- metaspace,
344
- }: {
345
- rootItemAddr: string;
346
- targetRelPath: string;
347
- space: any;
348
- metaspace?: any;
349
- }): Promise<B2tFSItemIbGib_V1 | undefined> {
350
- const rootItem = await getIbGibWithMetaspaceFallback({
351
- addr: rootItemAddr,
352
- space,
353
- metaspace,
354
- }) as B2tFSItemIbGib_V1;
355
-
356
- if (!rootItem) { return undefined; }
357
- if (!targetRelPath || targetRelPath === '.' || targetRelPath === '') {
358
- return rootItem;
359
- }
360
-
361
- const segments = targetRelPath.split('/');
362
- let currentItem: B2tFSItemIbGib_V1 = rootItem;
363
-
364
- for (const segment of segments) {
365
- if (currentItem.data?.fsType !== 'folder') {
366
- return undefined;
367
- }
368
-
369
- const childAddrs = currentItem.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
370
- let nextItem: B2tFSItemIbGib_V1 | undefined;
371
-
372
- for (const cAddr of childAddrs) {
373
- const child = await getIbGibWithMetaspaceFallback({
374
- addr: cAddr,
375
- space,
376
- metaspace,
377
- }) as B2tFSItemIbGib_V1;
378
-
379
- if (child && child.data?.name === segment) {
380
- nextItem = child;
381
- break;
382
- }
383
- }
384
-
385
- if (!nextItem) {
386
- return undefined;
387
- }
388
- currentItem = nextItem;
389
- }
390
-
391
- return currentItem;
392
- }
393
-
394
- async function logCmd_collectAllItemComments({
395
- item,
396
- space,
397
- metaspace,
398
- currentRelPath,
399
- outComments,
400
- }: {
401
- item: B2tFSItemIbGib_V1;
402
- space: any;
403
- metaspace?: any;
404
- currentRelPath: string;
405
- outComments: Array<{ path: string; name?: string; message: string }>;
406
- }): Promise<void> {
407
- if (!item || !item.data) { return; }
408
-
409
- const itemComments = item.rel8ns?.comment || [];
410
- for (const cAddr of itemComments) {
411
- const commentIbGib = await getIbGibWithMetaspaceFallback({
412
- addr: cAddr,
413
- space,
414
- metaspace,
415
- }) as CommentIbGib_V1;
416
-
417
- if (commentIbGib && commentIbGib.data?.text) {
418
- outComments.push({
419
- path: currentRelPath || '(root)',
420
- name: (commentIbGib.data as any)?.name,
421
- message: commentIbGib.data.text,
422
- });
423
- }
424
- }
425
-
426
- if (item.data.fsType === 'folder') {
427
- const childAddrs = item.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
428
- for (const childAddr of childAddrs) {
429
- const childItem = await getIbGibWithMetaspaceFallback({
430
- addr: childAddr,
431
- space,
432
- metaspace,
433
- }) as B2tFSItemIbGib_V1;
434
-
435
- if (childItem && childItem.data) {
436
- const childRel = currentRelPath
437
- ? `${currentRelPath}/${childItem.data.name}`
438
- : childItem.data.name;
439
- await logCmd_collectAllItemComments({
440
- item: childItem,
441
- space,
442
- metaspace,
443
- currentRelPath: childRel,
444
- outComments,
445
- });
446
- }
447
- }
448
- }
449
- }