gent-cli 2.0.0 → 5.0.0
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/README.md +28 -42
- package/package.json +1 -1
- package/src/commands/add.js +102 -23
- package/src/commands/clone.js +137 -86
- package/src/commands/commit.js +89 -81
- package/src/commands/diff.js +257 -0
- package/src/commands/init.js +5 -36
- package/src/commands/log.js +57 -13
- package/src/commands/merge.js +245 -0
- package/src/commands/pull.js +176 -86
- package/src/commands/push.js +172 -79
- package/src/commands/remote.js +97 -113
- package/src/commands/reset.js +149 -0
- package/src/commands/rm.js +85 -0
- package/src/commands/show.js +167 -0
- package/src/commands/stash.js +255 -0
- package/src/commands/status.js +80 -46
- package/src/commands/tag.js +146 -0
- package/src/index.js +108 -57
- package/src/utils/constants.js +10 -26
- package/src/utils/diff-engine.js +236 -0
- package/src/utils/fileSystem.js +8 -60
- package/src/utils/hash-engine.js +337 -0
- package/src/utils/merge-engine.js +379 -0
- package/src/utils/object-store.js +54 -0
- package/src/commands/create.js +0 -121
- package/src/commands/list.js +0 -67
- package/src/services/repo-service.js +0 -284
- package/src/utils/cloud-sync.js +0 -323
- package/src/utils/diff.js +0 -121
package/src/utils/diff.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Myers Diff Algorithm Implementation
|
|
3
|
-
* Calculates the difference between two sequences of text
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Compare two strings and return the differences using Myers algorithm
|
|
8
|
-
* @param {String} oldText - The original text
|
|
9
|
-
* @param {String} newText - The new text
|
|
10
|
-
* @returns {Array} Array of changes [{ type: 'equal'|'insert'|'delete', value: string }]
|
|
11
|
-
*/
|
|
12
|
-
function computeDiff(oldText, newText) {
|
|
13
|
-
// Split into lines for line-by-line diff
|
|
14
|
-
const oldLines = oldText.split('\n');
|
|
15
|
-
const newLines = newText.split('\n');
|
|
16
|
-
|
|
17
|
-
// If both are empty or identical
|
|
18
|
-
if (oldText === newText) {
|
|
19
|
-
return oldLines.map(line => ({ type: 'equal', value: line }));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const path = exploreEditGraph(oldLines, newLines);
|
|
23
|
-
return backtrack(path, oldLines, newLines);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Explore the edit graph to find the shortest path (shortest edit script)
|
|
28
|
-
* @param {Array} oldLines
|
|
29
|
-
* @param {Array} newLines
|
|
30
|
-
* @returns {Array} Trace of the path
|
|
31
|
-
*/
|
|
32
|
-
function exploreEditGraph(oldLines, newLines) {
|
|
33
|
-
const n = oldLines.length;
|
|
34
|
-
const m = newLines.length;
|
|
35
|
-
const max = n + m;
|
|
36
|
-
|
|
37
|
-
// v array stores the x-coordinate of the furthest reaching D-path
|
|
38
|
-
// using object/map to handle negative indices (-max to +max)
|
|
39
|
-
const v = { 1: 0 };
|
|
40
|
-
const trace = [];
|
|
41
|
-
|
|
42
|
-
for (let d = 0; d <= max; d++) {
|
|
43
|
-
trace.push({ ...v });
|
|
44
|
-
|
|
45
|
-
for (let k = -d; k <= d; k += 2) {
|
|
46
|
-
let x;
|
|
47
|
-
|
|
48
|
-
// Choose move: down (insertion) or right (deletion)
|
|
49
|
-
if (k === -d || (k !== d && (v[k - 1] || 0) < (v[k + 1] || 0))) {
|
|
50
|
-
x = v[k + 1] || 0; // Move down
|
|
51
|
-
} else {
|
|
52
|
-
x = (v[k - 1] || 0) + 1; // Move right
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let y = x - k;
|
|
56
|
-
|
|
57
|
-
// Follow diagonal (equal lines)
|
|
58
|
-
while (x < n && y < m && oldLines[x] === newLines[y]) {
|
|
59
|
-
x++;
|
|
60
|
-
y++;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
v[k] = x;
|
|
64
|
-
|
|
65
|
-
if (x >= n && y >= m) {
|
|
66
|
-
return trace;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return trace;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Backtrack from the end to generate the diff
|
|
75
|
-
* @param {Array} trace
|
|
76
|
-
* @param {Array} oldLines
|
|
77
|
-
* @param {Array} newLines
|
|
78
|
-
* @returns {Array}
|
|
79
|
-
*/
|
|
80
|
-
function backtrack(trace, oldLines, newLines) {
|
|
81
|
-
let x = oldLines.length;
|
|
82
|
-
let y = newLines.length;
|
|
83
|
-
const diff = [];
|
|
84
|
-
|
|
85
|
-
for (let d = trace.length - 1; d >= 0; d--) {
|
|
86
|
-
const v = trace[d];
|
|
87
|
-
const k = x - y;
|
|
88
|
-
|
|
89
|
-
let prevK;
|
|
90
|
-
if (k === -d || (k !== d && (v[k - 1] || 0) < (v[k + 1] || 0))) {
|
|
91
|
-
prevK = k + 1;
|
|
92
|
-
} else {
|
|
93
|
-
prevK = k - 1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const prevX = v[prevK] || 0;
|
|
97
|
-
const prevY = prevX - prevK;
|
|
98
|
-
|
|
99
|
-
while (x > prevX && y > prevY) {
|
|
100
|
-
diff.unshift({ type: 'equal', value: oldLines[x - 1] });
|
|
101
|
-
x--;
|
|
102
|
-
y--;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (d > 0) {
|
|
106
|
-
if (x === prevX) {
|
|
107
|
-
diff.unshift({ type: 'insert', value: newLines[y - 1] });
|
|
108
|
-
y--;
|
|
109
|
-
} else {
|
|
110
|
-
diff.unshift({ type: 'delete', value: oldLines[x - 1] });
|
|
111
|
-
x--;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return diff;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
module.exports = {
|
|
120
|
-
computeDiff
|
|
121
|
-
};
|