@catamorphic/git 0.1.0-alpha.37 → 0.1.0-alpha.39
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/index.js +107 -17
- package/dist/index.js.map +5 -5
- package/dist/native-project-repo.d.ts +1 -0
- package/dist/native-project-repo.d.ts.map +1 -1
- package/dist/project-manager.d.ts +1 -1
- package/dist/project-repo.d.ts +2 -0
- package/dist/project-repo.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/native-project-repo.ts +148 -16
- package/src/project-manager.ts +1 -1
- package/src/project-repo.ts +8 -2
package/dist/index.js
CHANGED
|
@@ -280,7 +280,7 @@ async function walkDirectory(dir, base, options) {
|
|
|
280
280
|
const entries = await fs3.readdir(dir, { withFileTypes: true });
|
|
281
281
|
const results = [];
|
|
282
282
|
for (const entry of entries) {
|
|
283
|
-
if (
|
|
283
|
+
if (WALK_SKIPPED_DIRS.has(entry.name))
|
|
284
284
|
continue;
|
|
285
285
|
if (!options?.includeHidden && entry.name.startsWith(".") && !ALLOWED_DOT_DIRS.has(entry.name) && !ALLOWED_DOT_FILES.has(entry.name))
|
|
286
286
|
continue;
|
|
@@ -830,12 +830,17 @@ async function commitSet(dir, ref) {
|
|
|
830
830
|
return new Set;
|
|
831
831
|
}
|
|
832
832
|
}
|
|
833
|
-
var
|
|
833
|
+
var WALK_SKIPPED_DIRS, STAGING_BATCH_SIZE = 128, ALLOWED_DOT_DIRS, ALLOWED_DOT_FILES;
|
|
834
834
|
var init_project_repo = __esm(() => {
|
|
835
835
|
init_file_reads();
|
|
836
836
|
init_personal_files();
|
|
837
837
|
init_ref_names();
|
|
838
|
-
|
|
838
|
+
WALK_SKIPPED_DIRS = new Set([
|
|
839
|
+
"node_modules",
|
|
840
|
+
".git",
|
|
841
|
+
"dist",
|
|
842
|
+
".turbo"
|
|
843
|
+
]);
|
|
839
844
|
ALLOWED_DOT_DIRS = new Set([".agents", PROJECT_WORKSPACE_ROOT]);
|
|
840
845
|
ALLOWED_DOT_FILES = new Set([".gitignore"]);
|
|
841
846
|
});
|
|
@@ -848,12 +853,99 @@ import {
|
|
|
848
853
|
PROJECT_PERSONAL_DIR as PROJECT_PERSONAL_DIR2,
|
|
849
854
|
publishedRef as publishedRef2
|
|
850
855
|
} from "@catamorphic/workflow/project-layout";
|
|
851
|
-
|
|
856
|
+
import ignore2 from "ignore";
|
|
857
|
+
function walkUnversioned(root, folder) {
|
|
858
|
+
const key = `${root}\x00${folder}`;
|
|
859
|
+
const current = unversionedWalks.get(key);
|
|
860
|
+
if (!current)
|
|
861
|
+
return startWalk(key, root, folder);
|
|
862
|
+
current.queued ??= current.running.catch(() => {}).then(() => startWalk(key, root, folder));
|
|
863
|
+
return current.queued;
|
|
864
|
+
}
|
|
865
|
+
function startWalk(key, root, folder) {
|
|
866
|
+
const entry = {
|
|
867
|
+
running: walkFolder(root, folder),
|
|
868
|
+
queued: null
|
|
869
|
+
};
|
|
870
|
+
unversionedWalks.set(key, entry);
|
|
871
|
+
entry.running.finally(() => {
|
|
872
|
+
if (unversionedWalks.get(key) === entry)
|
|
873
|
+
unversionedWalks.delete(key);
|
|
874
|
+
}).catch(() => {});
|
|
875
|
+
return entry.running;
|
|
876
|
+
}
|
|
877
|
+
async function walkFolder(root, folder) {
|
|
878
|
+
const rules = [];
|
|
879
|
+
const options = {
|
|
880
|
+
includeHidden: true,
|
|
881
|
+
excludeNestedRepositories: true,
|
|
882
|
+
tracked: new Set,
|
|
883
|
+
trackedDirectories: new Set,
|
|
884
|
+
rules
|
|
885
|
+
};
|
|
886
|
+
if (!folder || !(await fs4.stat(root)).isDirectory())
|
|
887
|
+
return walkDirectory(root, root, options);
|
|
888
|
+
let current = root;
|
|
889
|
+
for (const segment of folder.slice(0, -1).split("/")) {
|
|
890
|
+
if (!segment || segment === "." || segment === "..")
|
|
891
|
+
return [];
|
|
892
|
+
const content = await fs4.readFile(path4.join(current, ".gitignore"), "utf8").catch(() => "");
|
|
893
|
+
if (content)
|
|
894
|
+
rules.push({ base: current, matcher: ignore2().add(content) });
|
|
895
|
+
const next = path4.join(current, segment);
|
|
896
|
+
if (WALK_SKIPPED_DIRS.has(segment) || isPersonalFile(path4.relative(root, next)) || isIgnoredDirectory(rules, next))
|
|
897
|
+
return [];
|
|
898
|
+
const stat = await fs4.lstat(next).catch(() => {
|
|
899
|
+
return;
|
|
900
|
+
});
|
|
901
|
+
if (!stat?.isDirectory())
|
|
902
|
+
return [];
|
|
903
|
+
current = next;
|
|
904
|
+
if (await fs4.stat(path4.join(current, ".git")).then(() => true, () => false))
|
|
905
|
+
return [];
|
|
906
|
+
}
|
|
907
|
+
return walkDirectory(current, root, options);
|
|
908
|
+
}
|
|
909
|
+
function isIgnoredDirectory(rules, directory) {
|
|
910
|
+
let ignored = false;
|
|
911
|
+
for (const rule of rules) {
|
|
912
|
+
const result = rule.matcher.test(`${path4.relative(rule.base, directory)}/`);
|
|
913
|
+
if (result.ignored)
|
|
914
|
+
ignored = true;
|
|
915
|
+
if (result.unignored)
|
|
916
|
+
ignored = false;
|
|
917
|
+
}
|
|
918
|
+
return ignored;
|
|
919
|
+
}
|
|
920
|
+
function folderOf(prefix) {
|
|
921
|
+
const cut = prefix.lastIndexOf("/");
|
|
922
|
+
return cut < 0 ? "" : prefix.slice(0, cut + 1);
|
|
923
|
+
}
|
|
924
|
+
function literalFolder(globs) {
|
|
925
|
+
const folders = globs.map((glob) => {
|
|
926
|
+
const wild = glob.search(/[*?[{]/);
|
|
927
|
+
return folderOf(wild < 0 ? glob : glob.slice(0, wild));
|
|
928
|
+
});
|
|
929
|
+
if (folders.length === 0)
|
|
930
|
+
return "";
|
|
931
|
+
return folders.reduce((common, folder) => {
|
|
932
|
+
let end = 0;
|
|
933
|
+
for (let i = 0;i < Math.min(common.length, folder.length); i++) {
|
|
934
|
+
if (common[i] !== folder[i])
|
|
935
|
+
break;
|
|
936
|
+
if (common[i] === "/")
|
|
937
|
+
end = i + 1;
|
|
938
|
+
}
|
|
939
|
+
return common.slice(0, end);
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
var unversionedWalks, NativeProjectRepo;
|
|
852
943
|
var init_native_project_repo = __esm(() => {
|
|
853
944
|
init_file_reads();
|
|
854
945
|
init_native_git();
|
|
855
946
|
init_personal_files();
|
|
856
947
|
init_project_repo();
|
|
948
|
+
unversionedWalks = new Map;
|
|
857
949
|
NativeProjectRepo = class NativeProjectRepo extends ProjectRepoImpl {
|
|
858
950
|
followsSymlinks = true;
|
|
859
951
|
async readFileBytes(filePath) {
|
|
@@ -875,8 +967,11 @@ var init_native_project_repo = __esm(() => {
|
|
|
875
967
|
return this.readSnapshotBytes(filePath, 64 * 1024 * 1024);
|
|
876
968
|
}
|
|
877
969
|
async readAllFiles(options = {}) {
|
|
970
|
+
return this.readSnapshot(await this.listFiles(), options);
|
|
971
|
+
}
|
|
972
|
+
readSnapshot(paths, options) {
|
|
878
973
|
return readFileSnapshot({
|
|
879
|
-
paths
|
|
974
|
+
paths,
|
|
880
975
|
options: { maxFileBytes: 2 * 1024 * 1024, ...options },
|
|
881
976
|
read: async (file, maxBytes) => {
|
|
882
977
|
const stat = await fs4.lstat(path4.join(this.repoPath, file));
|
|
@@ -897,14 +992,9 @@ var init_native_project_repo = __esm(() => {
|
|
|
897
992
|
if (!await hasLocalGit({ path: this.repoPath })) {
|
|
898
993
|
if (opts?.prefix)
|
|
899
994
|
assertSafePath(opts.prefix);
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
tracked: new Set,
|
|
904
|
-
trackedDirectories: new Set,
|
|
905
|
-
rules: []
|
|
906
|
-
});
|
|
907
|
-
return files.filter((file) => !opts?.prefix || file.startsWith(opts.prefix)).sort();
|
|
995
|
+
const prefix = opts?.prefix ?? "";
|
|
996
|
+
const files = await walkUnversioned(this.repoPath, folderOf(prefix));
|
|
997
|
+
return files.filter((file) => file.startsWith(prefix)).sort();
|
|
908
998
|
}
|
|
909
999
|
const pathspec = opts?.prefix ? ["--", opts.prefix] : [];
|
|
910
1000
|
const [output, removed] = await Promise.all([
|
|
@@ -935,7 +1025,7 @@ var init_native_project_repo = __esm(() => {
|
|
|
935
1025
|
const matches = (file, glob) => path4.matchesGlob(file, glob) || !glob.includes("/") && path4.matchesGlob(path4.basename(file), glob);
|
|
936
1026
|
const includes = input.globs.filter((glob) => !glob.startsWith(":!"));
|
|
937
1027
|
const excludes = input.globs.filter((glob) => glob.startsWith(":!")).map((glob) => glob.slice(2));
|
|
938
|
-
const files = await this.
|
|
1028
|
+
const files = await this.readSnapshot(await this.listFiles({ prefix: literalFolder(includes) }), {
|
|
939
1029
|
filter: (file) => includes.some((glob) => matches(file, glob)) && !excludes.some((glob) => matches(file, glob))
|
|
940
1030
|
});
|
|
941
1031
|
return Object.entries(files).filter(([, content]) => content.includes(input.text)).map(([file]) => file);
|
|
@@ -1318,7 +1408,7 @@ var init_git_object_codec = __esm(() => {
|
|
|
1318
1408
|
|
|
1319
1409
|
// src/origin-objects.ts
|
|
1320
1410
|
import diff3Merge from "diff3";
|
|
1321
|
-
import
|
|
1411
|
+
import ignore3 from "ignore";
|
|
1322
1412
|
function isTreeMode(mode) {
|
|
1323
1413
|
return mode === "40000" || mode === "040000";
|
|
1324
1414
|
}
|
|
@@ -1551,7 +1641,7 @@ class OriginObjects {
|
|
|
1551
1641
|
let matcher = rules.get(directory);
|
|
1552
1642
|
if (matcher === undefined) {
|
|
1553
1643
|
const entry = await this.entry(treeOid, `${base}.gitignore`).catch(() => null);
|
|
1554
|
-
matcher = entry && !isTreeMode(entry.mode) ?
|
|
1644
|
+
matcher = entry && !isTreeMode(entry.mode) ? ignore3().add(new TextDecoder().decode(await this.blob(entry.oid))) : null;
|
|
1555
1645
|
rules.set(directory, matcher);
|
|
1556
1646
|
}
|
|
1557
1647
|
if (!matcher)
|
|
@@ -4742,5 +4832,5 @@ export {
|
|
|
4742
4832
|
unpinMirrorRef
|
|
4743
4833
|
};
|
|
4744
4834
|
|
|
4745
|
-
//# debugId=
|
|
4835
|
+
//# debugId=35CA7E4E5A973E9264756E2164756E21
|
|
4746
4836
|
//# sourceMappingURL=index.js.map
|