screw-up 1.31.0 → 1.33.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/dist/index.cjs +604 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/main.cjs +620 -195
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +6 -6
- package/dist/{metadata-file-BWd04LhD.js → metadata-file-Case8fsm.js} +603 -177
- package/dist/metadata-file-Case8fsm.js.map +1 -0
- package/dist/{packageMetadata-BsMXJpMH.js → packageMetadata-4rUlIBjt.js} +6 -6
- package/dist/{packageMetadata-BsMXJpMH.js.map → packageMetadata-4rUlIBjt.js.map} +1 -1
- package/dist/{packageMetadata-BDGBM3Fx.cjs → packageMetadata-CaaD3Ehh.cjs} +3 -3
- package/dist/{packageMetadata-ip0rBTwa.cjs → packageMetadata-k_QXJ2PH.cjs} +5 -5
- package/dist/{packageMetadata-ip0rBTwa.cjs.map → packageMetadata-k_QXJ2PH.cjs.map} +1 -1
- package/dist/src/analyzer.d.ts +2 -2
- package/dist/src/analyzer.d.ts.map +1 -1
- package/dist/src/cli-internal.d.ts +2 -2
- package/dist/src/cli.d.ts +2 -2
- package/dist/src/declaration-import-fix.d.ts +2 -2
- package/dist/src/default-import-fix.d.ts +2 -2
- package/dist/src/fast-tags.d.ts +2 -2
- package/dist/src/fast-tags.d.ts.map +1 -1
- package/dist/src/generated/packageMetadata.d.ts +4 -4
- package/dist/src/git-operations.d.ts +2 -2
- package/dist/src/git-operations.d.ts.map +1 -1
- package/dist/src/git-ref-utils.d.ts +46 -4
- package/dist/src/git-ref-utils.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/internal.d.ts +2 -2
- package/dist/src/main.d.ts +2 -2
- package/dist/src/metadata-file.d.ts +2 -2
- package/dist/src/text-edits.d.ts +2 -2
- package/dist/src/types.d.ts +2 -2
- package/dist/src/vite-plugin.d.ts +2 -2
- package/package.json +8 -8
- package/dist/metadata-file-BWd04LhD.js.map +0 -1
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: screw-up
|
|
3
|
-
* version: 1.
|
|
3
|
+
* version: 1.33.0
|
|
4
4
|
* description: Simply package metadata inserter on Vite plugin
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/screw-up.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: be56ff1901b5073e1b0238a28b80d0c4f3c1e894
|
|
9
9
|
*/
|
|
10
|
-
import fs, { mkdir, readFile, readdir, stat, writeFile } from "fs/promises";
|
|
10
|
+
import fs, { mkdir, open, readFile, readdir, stat, writeFile } from "fs/promises";
|
|
11
11
|
import { existsSync } from "fs";
|
|
12
12
|
import { basename, dirname, isAbsolute, join } from "path";
|
|
13
13
|
import { glob } from "glob";
|
|
14
14
|
import * as git from "isomorphic-git";
|
|
15
15
|
import __screwUpDefaultImportModule0 from "isomorphic-git";
|
|
16
|
+
import { createHash } from "crypto";
|
|
17
|
+
import { inflateSync } from "zlib";
|
|
16
18
|
//#region \0rolldown/runtime.js
|
|
17
19
|
var __create = Object.create;
|
|
18
20
|
var __defProp = Object.defineProperty;
|
|
@@ -1506,10 +1508,10 @@ var require_dayjs_min = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1506
1508
|
//#region src/internal.ts
|
|
1507
1509
|
var import_dist = /* @__PURE__ */ __toESM(require_dist(), 1);
|
|
1508
1510
|
var import_dayjs_min = /* @__PURE__ */ __toESM(require_dayjs_min(), 1);
|
|
1509
|
-
var JSON5 = __resolveDefaultExport$
|
|
1510
|
-
var dayjs$1 = __resolveDefaultExport$
|
|
1511
|
+
var JSON5 = __resolveDefaultExport$2(import_dist.default, false);
|
|
1512
|
+
var dayjs$1 = __resolveDefaultExport$2(import_dayjs_min.default, false);
|
|
1511
1513
|
globalThis.__screwUpIsInCJS_db7919f73ec9 = false;
|
|
1512
|
-
function __resolveDefaultExport$
|
|
1514
|
+
function __resolveDefaultExport$2(module, isESM) {
|
|
1513
1515
|
const __isInCJS = typeof globalThis !== "undefined" && globalThis.__screwUpIsInCJS_db7919f73ec9 === true;
|
|
1514
1516
|
const maybe = module;
|
|
1515
1517
|
const hasDefault = !!(maybe && typeof maybe === "object" && "default" in maybe);
|
|
@@ -1879,57 +1881,405 @@ var resolveRawPackageJsonObject = async (projectRoot, fetchGitMetadata, alwaysOv
|
|
|
1879
1881
|
};
|
|
1880
1882
|
//#endregion
|
|
1881
1883
|
//#region src/git-ref-utils.ts
|
|
1882
|
-
var
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
return value;
|
|
1893
|
-
};
|
|
1894
|
-
const resolvedDefault = hasDefault ? unwrapNamespaceDefault(maybe.default) : void 0;
|
|
1895
|
-
if (__isInCJS) return hasDefault ? resolvedDefault !== null && resolvedDefault !== void 0 ? resolvedDefault : module : module;
|
|
1896
|
-
if (isESM) {
|
|
1897
|
-
if (hasDefault) return resolvedDefault;
|
|
1898
|
-
throw new Error("Default export not found.");
|
|
1899
|
-
}
|
|
1900
|
-
return hasDefault ? resolvedDefault !== null && resolvedDefault !== void 0 ? resolvedDefault : module : module;
|
|
1901
|
-
}
|
|
1884
|
+
var PACK_TRAILER_SIZE = 20;
|
|
1885
|
+
var LOOSE_TAG_RESOLUTION_CONCURRENCY = 4;
|
|
1886
|
+
var PACKED_OBJECT_TYPE_BY_CODE = new Map([
|
|
1887
|
+
[1, "commit"],
|
|
1888
|
+
[2, "tree"],
|
|
1889
|
+
[3, "blob"],
|
|
1890
|
+
[4, "tag"],
|
|
1891
|
+
[6, "ofs-delta"],
|
|
1892
|
+
[7, "ref-delta"]
|
|
1893
|
+
]);
|
|
1902
1894
|
/**
|
|
1903
|
-
* Resolve
|
|
1895
|
+
* Resolve Git directory paths for repositories, worktrees, and submodules.
|
|
1904
1896
|
* @param repoPath - Repository path
|
|
1905
|
-
* @returns The resolved Git directory
|
|
1897
|
+
* @returns The resolved Git directory paths
|
|
1906
1898
|
*/
|
|
1907
|
-
var
|
|
1899
|
+
var resolveGitDirectoryPaths = async (repoPath) => {
|
|
1908
1900
|
const gitDir = join(repoPath, ".git");
|
|
1909
1901
|
const gitStat = await stat(gitDir).catch(() => null);
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1902
|
+
const resolvedGitDir = !(gitStat === null || gitStat === void 0 ? void 0 : gitStat.isFile()) ? gitDir : await (async () => {
|
|
1903
|
+
const match = (await readFile(gitDir, "utf-8")).match(/^gitdir:\s*(.+)$/m);
|
|
1904
|
+
if (!match) return gitDir;
|
|
1905
|
+
return isAbsolute(match[1]) ? match[1] : join(repoPath, match[1]);
|
|
1906
|
+
})();
|
|
1907
|
+
return {
|
|
1908
|
+
gitDir: resolvedGitDir,
|
|
1909
|
+
commonGitDir: await readFile(join(resolvedGitDir, "commondir"), "utf-8").then((content) => {
|
|
1910
|
+
const commondir = content.trim();
|
|
1911
|
+
if (!commondir) return resolvedGitDir;
|
|
1912
|
+
return isAbsolute(commondir) ? commondir : join(resolvedGitDir, commondir);
|
|
1913
|
+
}).catch((error) => {
|
|
1914
|
+
if ((error === null || error === void 0 ? void 0 : error.code) !== "ENOENT") throw error;
|
|
1915
|
+
return resolvedGitDir;
|
|
1916
|
+
})
|
|
1917
|
+
};
|
|
1918
|
+
};
|
|
1919
|
+
/**
|
|
1920
|
+
* Resolve the worktree-specific Git directory.
|
|
1921
|
+
* @param repoPath - Repository path
|
|
1922
|
+
* @returns The resolved worktree-specific Git directory path
|
|
1923
|
+
*/
|
|
1924
|
+
var getActualGitDir = async (repoPath) => {
|
|
1925
|
+
return (await resolveGitDirectoryPaths(repoPath)).gitDir;
|
|
1914
1926
|
};
|
|
1915
1927
|
/**
|
|
1916
|
-
* Resolve
|
|
1917
|
-
* Lightweight tags are returned unchanged.
|
|
1928
|
+
* Resolve the common Git directory used for refs and objects.
|
|
1918
1929
|
* @param repoPath - Repository path
|
|
1919
|
-
* @
|
|
1920
|
-
* @returns Commit hash this tag points to
|
|
1930
|
+
* @returns The resolved common Git directory path
|
|
1921
1931
|
*/
|
|
1922
|
-
var
|
|
1932
|
+
var getCommonGitDir = async (repoPath) => {
|
|
1933
|
+
return (await resolveGitDirectoryPaths(repoPath)).commonGitDir;
|
|
1934
|
+
};
|
|
1935
|
+
var readFixedRange = async (fileHandle, offset, length) => {
|
|
1936
|
+
const buffer = Buffer.alloc(length);
|
|
1937
|
+
const { bytesRead } = await fileHandle.read(buffer, 0, length, offset);
|
|
1938
|
+
if (bytesRead !== length) throw new Error(`Unexpected EOF while reading pack entry at offset ${offset} (expected ${length}, got ${bytesRead})`);
|
|
1939
|
+
return buffer;
|
|
1940
|
+
};
|
|
1941
|
+
var readLooseObject = async (gitDir, oid) => {
|
|
1923
1942
|
try {
|
|
1924
|
-
|
|
1925
|
-
const
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1943
|
+
const wrapped = inflateSync(await readFile(join(gitDir, "objects", oid.slice(0, 2), oid.slice(2))));
|
|
1944
|
+
const headerEnd = wrapped.indexOf(0);
|
|
1945
|
+
if (headerEnd < 0) throw new Error(`Invalid loose object header: ${oid}`);
|
|
1946
|
+
const header = wrapped.subarray(0, headerEnd).toString("utf-8");
|
|
1947
|
+
const match = header.match(/^(commit|tree|blob|tag) (\d+)$/);
|
|
1948
|
+
if (!match) throw new Error(`Unsupported loose object header: ${header}`);
|
|
1949
|
+
const content = wrapped.subarray(headerEnd + 1);
|
|
1950
|
+
const expectedSize = Number(match[2]);
|
|
1951
|
+
if (content.length !== expectedSize) throw new Error(`Loose object size mismatch: ${oid} (expected ${expectedSize}, got ${content.length})`);
|
|
1952
|
+
return {
|
|
1953
|
+
oid,
|
|
1954
|
+
type: match[1],
|
|
1955
|
+
content
|
|
1956
|
+
};
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
if (error.code === "ENOENT") return null;
|
|
1959
|
+
throw error;
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
var readLargePackOffset = (idxBuffer, largeOffsetsStart, largeOffsetIndex) => {
|
|
1963
|
+
const offset = Number(idxBuffer.readBigUInt64BE(largeOffsetsStart + largeOffsetIndex * 8));
|
|
1964
|
+
if (!Number.isSafeInteger(offset)) throw new Error(`Pack offset exceeds safe integer range: ${offset}`);
|
|
1965
|
+
return offset;
|
|
1966
|
+
};
|
|
1967
|
+
var loadPackIndex = async (idxPath) => {
|
|
1968
|
+
const packPath = idxPath.replace(/\.idx$/, ".pack");
|
|
1969
|
+
const [idxBuffer, packStat, fileHandle] = await Promise.all([
|
|
1970
|
+
readFile(idxPath),
|
|
1971
|
+
stat(packPath),
|
|
1972
|
+
open(packPath, "r")
|
|
1973
|
+
]);
|
|
1974
|
+
if (idxBuffer.readUInt32BE(0) !== 4285812579) throw new Error(`Unsupported pack index signature: ${idxPath}`);
|
|
1975
|
+
if (idxBuffer.readUInt32BE(4) !== 2) throw new Error(`Unsupported pack index version: ${idxPath}`);
|
|
1976
|
+
const objectCount = idxBuffer.readUInt32BE(1028);
|
|
1977
|
+
const oidStart = 1032;
|
|
1978
|
+
const offsetStart = oidStart + objectCount * 20 + objectCount * 4;
|
|
1979
|
+
const largeOffsetStart = offsetStart + objectCount * 4;
|
|
1980
|
+
const objectByOid = /* @__PURE__ */ new Map();
|
|
1981
|
+
const objectByOffset = /* @__PURE__ */ new Map();
|
|
1982
|
+
const sortedObjects = [];
|
|
1983
|
+
const packIndex = {
|
|
1984
|
+
fileHandle,
|
|
1985
|
+
objectByOid,
|
|
1986
|
+
objectByOffset
|
|
1987
|
+
};
|
|
1988
|
+
for (let index = 0; index < objectCount; index++) {
|
|
1989
|
+
const oidOffset = oidStart + index * 20;
|
|
1990
|
+
const oid = idxBuffer.subarray(oidOffset, oidOffset + 20).toString("hex");
|
|
1991
|
+
const rawOffset = idxBuffer.readUInt32BE(offsetStart + index * 4);
|
|
1992
|
+
const offset = (rawOffset & 2147483648) === 0 ? rawOffset : readLargePackOffset(idxBuffer, largeOffsetStart, rawOffset & 2147483647);
|
|
1993
|
+
sortedObjects.push({
|
|
1994
|
+
oid,
|
|
1995
|
+
offset
|
|
1996
|
+
});
|
|
1997
|
+
}
|
|
1998
|
+
sortedObjects.sort((left, right) => left.offset - right.offset);
|
|
1999
|
+
const packEndOffset = packStat.size - PACK_TRAILER_SIZE;
|
|
2000
|
+
for (let index = 0; index < sortedObjects.length; index++) {
|
|
2001
|
+
var _sortedObjects$offset, _sortedObjects;
|
|
2002
|
+
const currentObject = sortedObjects[index];
|
|
2003
|
+
const nextOffset = (_sortedObjects$offset = (_sortedObjects = sortedObjects[index + 1]) === null || _sortedObjects === void 0 ? void 0 : _sortedObjects.offset) !== null && _sortedObjects$offset !== void 0 ? _sortedObjects$offset : packEndOffset;
|
|
2004
|
+
const location = {
|
|
2005
|
+
oid: currentObject.oid,
|
|
2006
|
+
offset: currentObject.offset,
|
|
2007
|
+
nextOffset,
|
|
2008
|
+
packIndex
|
|
2009
|
+
};
|
|
2010
|
+
objectByOid.set(currentObject.oid, location);
|
|
2011
|
+
objectByOffset.set(currentObject.offset, location);
|
|
2012
|
+
}
|
|
2013
|
+
return packIndex;
|
|
2014
|
+
};
|
|
2015
|
+
var loadPackStore = async (gitDir) => {
|
|
2016
|
+
try {
|
|
2017
|
+
const packDir = join(gitDir, "objects", "pack");
|
|
2018
|
+
const idxPaths = (await readdir(packDir)).filter((entryName) => entryName.endsWith(".idx")).map((entryName) => join(packDir, entryName));
|
|
2019
|
+
const packs = await Promise.all(idxPaths.map(loadPackIndex));
|
|
2020
|
+
const objectByOid = /* @__PURE__ */ new Map();
|
|
2021
|
+
for (const pack of packs) for (const [oid, location] of pack.objectByOid.entries()) objectByOid.set(oid, location);
|
|
2022
|
+
return {
|
|
2023
|
+
packs,
|
|
2024
|
+
objectByOid
|
|
2025
|
+
};
|
|
2026
|
+
} catch (error) {
|
|
2027
|
+
if (error.code === "ENOENT") return {
|
|
2028
|
+
packs: [],
|
|
2029
|
+
objectByOid: /* @__PURE__ */ new Map()
|
|
2030
|
+
};
|
|
2031
|
+
throw error;
|
|
2032
|
+
}
|
|
2033
|
+
};
|
|
2034
|
+
var decodeOfsDeltaDistance = (buffer, startOffset) => {
|
|
2035
|
+
let cursor = startOffset;
|
|
2036
|
+
let byte = buffer[cursor++];
|
|
2037
|
+
let distance = byte & 127;
|
|
2038
|
+
while (byte & 128) {
|
|
2039
|
+
byte = buffer[cursor++];
|
|
2040
|
+
distance = distance + 1 << 7 | byte & 127;
|
|
2041
|
+
}
|
|
2042
|
+
return {
|
|
2043
|
+
distance,
|
|
2044
|
+
nextOffset: cursor
|
|
2045
|
+
};
|
|
2046
|
+
};
|
|
2047
|
+
var parsePackedEntryHeader = (entryBuffer, objectOffset) => {
|
|
2048
|
+
let cursor = 0;
|
|
2049
|
+
let byte = entryBuffer[cursor++];
|
|
2050
|
+
const packedType = PACKED_OBJECT_TYPE_BY_CODE.get(byte >> 4 & 7);
|
|
2051
|
+
if (!packedType) throw new Error(`Unsupported packed object type at offset ${objectOffset}`);
|
|
2052
|
+
let declaredSize = byte & 15;
|
|
2053
|
+
let shift = 4;
|
|
2054
|
+
while (byte & 128) {
|
|
2055
|
+
byte = entryBuffer[cursor++];
|
|
2056
|
+
declaredSize |= (byte & 127) << shift;
|
|
2057
|
+
shift += 7;
|
|
2058
|
+
}
|
|
2059
|
+
let baseOffset;
|
|
2060
|
+
let baseOid;
|
|
2061
|
+
if (packedType === "ofs-delta") {
|
|
2062
|
+
const decoded = decodeOfsDeltaDistance(entryBuffer, cursor);
|
|
2063
|
+
cursor = decoded.nextOffset;
|
|
2064
|
+
baseOffset = objectOffset - decoded.distance;
|
|
2065
|
+
} else if (packedType === "ref-delta") {
|
|
2066
|
+
baseOid = entryBuffer.subarray(cursor, cursor + 20).toString("hex");
|
|
2067
|
+
cursor += 20;
|
|
2068
|
+
}
|
|
2069
|
+
return {
|
|
2070
|
+
packedType,
|
|
2071
|
+
declaredSize,
|
|
2072
|
+
headerLength: cursor,
|
|
2073
|
+
baseOffset,
|
|
2074
|
+
baseOid
|
|
2075
|
+
};
|
|
2076
|
+
};
|
|
2077
|
+
var readDeltaSize = (buffer, startOffset) => {
|
|
2078
|
+
let cursor = startOffset;
|
|
2079
|
+
let size = 0;
|
|
2080
|
+
let shift = 0;
|
|
2081
|
+
while (cursor < buffer.length) {
|
|
2082
|
+
const byte = buffer[cursor++];
|
|
2083
|
+
size |= (byte & 127) << shift;
|
|
2084
|
+
if ((byte & 128) === 0) return {
|
|
2085
|
+
size,
|
|
2086
|
+
nextOffset: cursor
|
|
2087
|
+
};
|
|
2088
|
+
shift += 7;
|
|
2089
|
+
}
|
|
2090
|
+
throw new Error("Invalid git delta size encoding");
|
|
2091
|
+
};
|
|
2092
|
+
var applyGitDelta = (baseContent, deltaContent) => {
|
|
2093
|
+
const baseSizeInfo = readDeltaSize(deltaContent, 0);
|
|
2094
|
+
if (baseSizeInfo.size !== baseContent.length) throw new Error(`Git delta base size mismatch: expected ${baseSizeInfo.size}, got ${baseContent.length}`);
|
|
2095
|
+
const targetSizeInfo = readDeltaSize(deltaContent, baseSizeInfo.nextOffset);
|
|
2096
|
+
const result = Buffer.alloc(targetSizeInfo.size);
|
|
2097
|
+
let deltaOffset = targetSizeInfo.nextOffset;
|
|
2098
|
+
let resultOffset = 0;
|
|
2099
|
+
while (deltaOffset < deltaContent.length) {
|
|
2100
|
+
const opcode = deltaContent[deltaOffset++];
|
|
2101
|
+
if ((opcode & 128) !== 0) {
|
|
2102
|
+
let copyOffset = 0;
|
|
2103
|
+
let copySize = 0;
|
|
2104
|
+
if (opcode & 1) copyOffset |= deltaContent[deltaOffset++];
|
|
2105
|
+
if (opcode & 2) copyOffset |= deltaContent[deltaOffset++] << 8;
|
|
2106
|
+
if (opcode & 4) copyOffset |= deltaContent[deltaOffset++] << 16;
|
|
2107
|
+
if (opcode & 8) copyOffset |= deltaContent[deltaOffset++] << 24;
|
|
2108
|
+
if (opcode & 16) copySize |= deltaContent[deltaOffset++];
|
|
2109
|
+
if (opcode & 32) copySize |= deltaContent[deltaOffset++] << 8;
|
|
2110
|
+
if (opcode & 64) copySize |= deltaContent[deltaOffset++] << 16;
|
|
2111
|
+
if (copySize === 0) copySize = 65536;
|
|
2112
|
+
baseContent.copy(result, resultOffset, copyOffset, copyOffset + copySize);
|
|
2113
|
+
resultOffset += copySize;
|
|
2114
|
+
continue;
|
|
2115
|
+
}
|
|
2116
|
+
if (opcode === 0) throw new Error("Invalid git delta opcode");
|
|
2117
|
+
deltaContent.copy(result, resultOffset, deltaOffset, deltaOffset + opcode);
|
|
2118
|
+
deltaOffset += opcode;
|
|
2119
|
+
resultOffset += opcode;
|
|
2120
|
+
}
|
|
2121
|
+
if (resultOffset !== result.length) throw new Error(`Git delta size mismatch: expected ${result.length}, got ${resultOffset}`);
|
|
2122
|
+
return result;
|
|
2123
|
+
};
|
|
2124
|
+
var inflatePackedObject = (compressedContent) => Buffer.from(inflateSync(compressedContent));
|
|
2125
|
+
var parseTagTargetOid = (tagContent) => {
|
|
2126
|
+
const firstLineEnd = tagContent.indexOf(10);
|
|
2127
|
+
const firstLine = firstLineEnd >= 0 ? tagContent.subarray(0, firstLineEnd).toString("utf-8") : tagContent.toString("utf-8");
|
|
2128
|
+
const match = firstLine.match(/^object ([0-9a-f]{40})$/);
|
|
2129
|
+
if (!match) throw new Error(`Invalid annotated tag payload: ${firstLine}`);
|
|
2130
|
+
return match[1];
|
|
2131
|
+
};
|
|
2132
|
+
var parseTreeEntries = (treeContent) => {
|
|
2133
|
+
const entries = [];
|
|
2134
|
+
let offset = 0;
|
|
2135
|
+
while (offset < treeContent.length) {
|
|
2136
|
+
const modeEnd = treeContent.indexOf(32, offset);
|
|
2137
|
+
if (modeEnd < 0) throw new Error("Invalid tree entry mode");
|
|
2138
|
+
const nameEnd = treeContent.indexOf(0, modeEnd + 1);
|
|
2139
|
+
if (nameEnd < 0 || nameEnd + 21 > treeContent.length) throw new Error("Invalid tree entry name");
|
|
2140
|
+
entries.push({
|
|
2141
|
+
mode: treeContent.subarray(offset, modeEnd).toString("utf-8"),
|
|
2142
|
+
name: treeContent.subarray(modeEnd + 1, nameEnd).toString("utf-8"),
|
|
2143
|
+
oid: treeContent.subarray(nameEnd + 1, nameEnd + 21).toString("hex")
|
|
2144
|
+
});
|
|
2145
|
+
offset = nameEnd + 21;
|
|
2146
|
+
}
|
|
2147
|
+
return entries;
|
|
2148
|
+
};
|
|
2149
|
+
var createGitObjectResolver = async (repoPath) => {
|
|
2150
|
+
const commonGitDir = await getCommonGitDir(repoPath);
|
|
2151
|
+
const resolvedObjects = /* @__PURE__ */ new Map();
|
|
2152
|
+
let packStorePromise;
|
|
2153
|
+
const getPackStore = async () => {
|
|
2154
|
+
if (!packStorePromise) packStorePromise = loadPackStore(commonGitDir);
|
|
2155
|
+
return packStorePromise;
|
|
2156
|
+
};
|
|
2157
|
+
const readPackedObject = async (location) => {
|
|
2158
|
+
var _location$packIndex$o, _location$packIndex$o2, _header$baseOid;
|
|
2159
|
+
const entryLength = location.nextOffset - location.offset;
|
|
2160
|
+
const entryBuffer = await readFixedRange(location.packIndex.fileHandle, location.offset, entryLength);
|
|
2161
|
+
const header = parsePackedEntryHeader(entryBuffer, location.offset);
|
|
2162
|
+
const compressedContent = entryBuffer.subarray(header.headerLength);
|
|
2163
|
+
if (header.packedType === "commit" || header.packedType === "tree" || header.packedType === "blob" || header.packedType === "tag") {
|
|
2164
|
+
const content = inflatePackedObject(compressedContent);
|
|
2165
|
+
if (content.length !== header.declaredSize) throw new Error(`Packed object size mismatch: ${location.oid} (expected ${header.declaredSize}, got ${content.length})`);
|
|
2166
|
+
return {
|
|
2167
|
+
oid: location.oid,
|
|
2168
|
+
type: header.packedType,
|
|
2169
|
+
content
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
const deltaContent = inflatePackedObject(compressedContent);
|
|
2173
|
+
if (deltaContent.length !== header.declaredSize) throw new Error(`Packed delta size mismatch: ${location.oid} (expected ${header.declaredSize}, got ${deltaContent.length})`);
|
|
2174
|
+
const baseObject = header.packedType === "ofs-delta" ? await readObject((_location$packIndex$o = (_location$packIndex$o2 = location.packIndex.objectByOffset.get(header.baseOffset)) === null || _location$packIndex$o2 === void 0 ? void 0 : _location$packIndex$o2.oid) !== null && _location$packIndex$o !== void 0 ? _location$packIndex$o : (() => {
|
|
2175
|
+
throw new Error(`Missing ofs-delta base object at offset ${header.baseOffset}`);
|
|
2176
|
+
})()) : await readObject((_header$baseOid = header.baseOid) !== null && _header$baseOid !== void 0 ? _header$baseOid : (() => {
|
|
2177
|
+
throw new Error("Missing ref-delta base object id");
|
|
2178
|
+
})());
|
|
2179
|
+
const content = applyGitDelta(baseObject.content, deltaContent);
|
|
2180
|
+
return {
|
|
2181
|
+
oid: location.oid,
|
|
2182
|
+
type: baseObject.type,
|
|
2183
|
+
content
|
|
2184
|
+
};
|
|
2185
|
+
};
|
|
2186
|
+
const readObject = async (oid) => {
|
|
2187
|
+
const cachedObject = resolvedObjects.get(oid);
|
|
2188
|
+
if (cachedObject) return cachedObject;
|
|
2189
|
+
const objectPromise = (async () => {
|
|
2190
|
+
const looseObject = await readLooseObject(commonGitDir, oid);
|
|
2191
|
+
if (looseObject) return looseObject;
|
|
2192
|
+
const location = (await getPackStore()).objectByOid.get(oid);
|
|
2193
|
+
if (!location) throw new Error(`Git object not found: ${oid}`);
|
|
2194
|
+
return readPackedObject(location);
|
|
2195
|
+
})();
|
|
2196
|
+
resolvedObjects.set(oid, objectPromise);
|
|
2197
|
+
try {
|
|
2198
|
+
return await objectPromise;
|
|
2199
|
+
} catch (error) {
|
|
2200
|
+
resolvedObjects.delete(oid);
|
|
2201
|
+
throw error;
|
|
2202
|
+
}
|
|
2203
|
+
};
|
|
2204
|
+
return {
|
|
2205
|
+
close: async () => {
|
|
2206
|
+
if (!packStorePromise) return;
|
|
2207
|
+
const packStore = await packStorePromise;
|
|
2208
|
+
await Promise.allSettled(packStore.packs.map(async (pack) => {
|
|
2209
|
+
await pack.fileHandle.close();
|
|
2210
|
+
}));
|
|
2211
|
+
},
|
|
2212
|
+
readObject,
|
|
2213
|
+
resolveTagOidToCommit: async (tagOid) => {
|
|
2214
|
+
let currentOid = tagOid;
|
|
2215
|
+
const visitedOids = /* @__PURE__ */ new Set();
|
|
2216
|
+
while (true) {
|
|
2217
|
+
if (visitedOids.has(currentOid)) throw new Error(`Detected cyclic tag reference: ${currentOid}`);
|
|
2218
|
+
visitedOids.add(currentOid);
|
|
2219
|
+
const object = await readObject(currentOid);
|
|
2220
|
+
if (object.type !== "tag") return currentOid;
|
|
2221
|
+
currentOid = parseTagTargetOid(object.content);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
};
|
|
2225
|
+
};
|
|
2226
|
+
var runWithConcurrency = async (values, concurrency, worker) => {
|
|
2227
|
+
let nextIndex = 0;
|
|
2228
|
+
const runWorker = async () => {
|
|
2229
|
+
while (nextIndex < values.length) {
|
|
2230
|
+
const currentIndex = nextIndex;
|
|
2231
|
+
nextIndex += 1;
|
|
2232
|
+
await worker(values[currentIndex]);
|
|
2233
|
+
}
|
|
2234
|
+
};
|
|
2235
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, Math.max(values.length, 1)) }, () => runWorker()));
|
|
2236
|
+
};
|
|
2237
|
+
/**
|
|
2238
|
+
* Resolve multiple tag object OIDs to their peeled commit OIDs.
|
|
2239
|
+
* @param repoPath - Repository path
|
|
2240
|
+
* @param tagOids - Tag or commit OIDs
|
|
2241
|
+
* @returns Map of tag object OID to peeled commit OID
|
|
2242
|
+
*/
|
|
2243
|
+
var resolveTagOidsToCommits = async (repoPath, tagOids) => {
|
|
2244
|
+
const resolver = await createGitObjectResolver(repoPath);
|
|
2245
|
+
const result = /* @__PURE__ */ new Map();
|
|
2246
|
+
const uniqueTagOids = Array.from(new Set(tagOids));
|
|
2247
|
+
try {
|
|
2248
|
+
await runWithConcurrency(uniqueTagOids, LOOSE_TAG_RESOLUTION_CONCURRENCY, async (tagOid) => {
|
|
2249
|
+
result.set(tagOid, await resolver.resolveTagOidToCommit(tagOid));
|
|
1929
2250
|
});
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
2251
|
+
} finally {
|
|
2252
|
+
await resolver.close();
|
|
2253
|
+
}
|
|
2254
|
+
return result;
|
|
2255
|
+
};
|
|
2256
|
+
var collectTreeFiles = async (resolver, treeOid, prefix, files) => {
|
|
2257
|
+
const treeObject = await resolver.readObject(treeOid);
|
|
2258
|
+
if (treeObject.type !== "tree") throw new Error(`Expected tree object: ${treeOid}`);
|
|
2259
|
+
for (const entry of parseTreeEntries(treeObject.content)) {
|
|
2260
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
2261
|
+
if (entry.mode === "40000") {
|
|
2262
|
+
await collectTreeFiles(resolver, entry.oid, path, files);
|
|
2263
|
+
continue;
|
|
2264
|
+
}
|
|
2265
|
+
if (entry.mode !== "160000") files.set(path, entry.oid);
|
|
2266
|
+
}
|
|
2267
|
+
};
|
|
2268
|
+
/**
|
|
2269
|
+
* Collect all tracked file blob OIDs under the specified tree.
|
|
2270
|
+
* @param repoPath - Repository path
|
|
2271
|
+
* @param treeOid - Tree object OID
|
|
2272
|
+
* @returns Map of repository-relative file path to blob OID
|
|
2273
|
+
*/
|
|
2274
|
+
var listTreeFiles = async (repoPath, treeOid) => {
|
|
2275
|
+
const resolver = await createGitObjectResolver(repoPath);
|
|
2276
|
+
const files = /* @__PURE__ */ new Map();
|
|
2277
|
+
try {
|
|
2278
|
+
await collectTreeFiles(resolver, treeOid, "", files);
|
|
2279
|
+
} finally {
|
|
2280
|
+
await resolver.close();
|
|
2281
|
+
}
|
|
2282
|
+
return files;
|
|
1933
2283
|
};
|
|
1934
2284
|
//#endregion
|
|
1935
2285
|
//#region src/fast-tags.ts
|
|
@@ -1982,8 +2332,8 @@ var readLooseTags = async (refsTagsPath) => {
|
|
|
1982
2332
|
* @returns Array of all tag names
|
|
1983
2333
|
*/
|
|
1984
2334
|
var listTagsFast = async (repoPath) => {
|
|
1985
|
-
const
|
|
1986
|
-
const [packedTags, looseTags] = await Promise.all([parsePackedRefs(join(
|
|
2335
|
+
const commonGitDir = await getCommonGitDir(repoPath);
|
|
2336
|
+
const [packedTags, looseTags] = await Promise.all([parsePackedRefs(join(commonGitDir, "packed-refs")), readLooseTags(join(commonGitDir, "refs", "tags"))]);
|
|
1987
2337
|
const allTags = new Set([...packedTags, ...looseTags]);
|
|
1988
2338
|
return Array.from(allTags).sort();
|
|
1989
2339
|
};
|
|
@@ -1996,11 +2346,11 @@ var listTagsFast = async (repoPath) => {
|
|
|
1996
2346
|
var resolveTagsBatchWithCommit = async (repoPath, tagNames, logger) => {
|
|
1997
2347
|
const startTime = Date.now();
|
|
1998
2348
|
const result = /* @__PURE__ */ new Map();
|
|
1999
|
-
const
|
|
2349
|
+
const commonGitDir = await getCommonGitDir(repoPath);
|
|
2000
2350
|
const tagSet = new Set(tagNames);
|
|
2001
2351
|
const packedRefsStart = Date.now();
|
|
2002
2352
|
try {
|
|
2003
|
-
const lines = (await readFile(join(
|
|
2353
|
+
const lines = (await readFile(join(commonGitDir, "packed-refs"), "utf-8")).split("\n");
|
|
2004
2354
|
for (let i = 0; i < lines.length; i++) {
|
|
2005
2355
|
const line = lines[i];
|
|
2006
2356
|
if (line.startsWith("#") || !line.trim()) continue;
|
|
@@ -2023,19 +2373,28 @@ var resolveTagsBatchWithCommit = async (repoPath, tagNames, logger) => {
|
|
|
2023
2373
|
const remainingTags = tagNames.filter((tag) => !result.has(tag));
|
|
2024
2374
|
if (remainingTags.length > 0) {
|
|
2025
2375
|
const looseRefsStart = Date.now();
|
|
2026
|
-
await Promise.all(remainingTags.map(async (tagName) => {
|
|
2027
|
-
const looseRefPath = join(
|
|
2376
|
+
const looseTagEntries = (await Promise.all(remainingTags.map(async (tagName) => {
|
|
2377
|
+
const looseRefPath = join(commonGitDir, "refs", "tags", tagName);
|
|
2028
2378
|
try {
|
|
2029
|
-
|
|
2030
|
-
|
|
2379
|
+
return {
|
|
2380
|
+
tagName,
|
|
2381
|
+
oid: (await readFile(looseRefPath, "utf-8")).trim()
|
|
2382
|
+
};
|
|
2383
|
+
} catch (error) {
|
|
2384
|
+
if (error.code !== "ENOENT") throw error;
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
}))).filter((entry) => entry !== void 0);
|
|
2388
|
+
if (looseTagEntries.length > 0) {
|
|
2389
|
+
const commitOids = await resolveTagOidsToCommits(repoPath, looseTagEntries.map((entry) => entry.oid));
|
|
2390
|
+
for (const { tagName, oid } of looseTagEntries) {
|
|
2391
|
+
var _commitOids$get;
|
|
2031
2392
|
result.set(tagName, {
|
|
2032
2393
|
oid,
|
|
2033
|
-
commitOid
|
|
2394
|
+
commitOid: (_commitOids$get = commitOids.get(oid)) !== null && _commitOids$get !== void 0 ? _commitOids$get : oid
|
|
2034
2395
|
});
|
|
2035
|
-
} catch (error) {
|
|
2036
|
-
if (error.code !== "ENOENT") throw error;
|
|
2037
2396
|
}
|
|
2038
|
-
}
|
|
2397
|
+
}
|
|
2039
2398
|
logger.debug(`[fast-tags] read loose refs: ${Date.now() - looseRefsStart}ms`);
|
|
2040
2399
|
}
|
|
2041
2400
|
const totalTime = Date.now() - startTime;
|
|
@@ -2231,16 +2590,26 @@ var formatVersion = (version) => {
|
|
|
2231
2590
|
return result;
|
|
2232
2591
|
};
|
|
2233
2592
|
/**
|
|
2234
|
-
*
|
|
2593
|
+
* Build a Git read context that can operate correctly inside worktrees.
|
|
2235
2594
|
* @param repositoryPath - Local Git repository directory
|
|
2595
|
+
* @returns The resolved Git read context
|
|
2596
|
+
*/
|
|
2597
|
+
var createGitReadContext = async (repositoryPath) => ({
|
|
2598
|
+
dir: repositoryPath,
|
|
2599
|
+
gitdir: await getCommonGitDir(repositoryPath)
|
|
2600
|
+
});
|
|
2601
|
+
/**
|
|
2602
|
+
* Get a commit by hash
|
|
2603
|
+
* @param context - Git read context
|
|
2236
2604
|
* @param hash - The hash of the commit
|
|
2237
2605
|
* @returns The commit or undefined if the commit is not found
|
|
2238
2606
|
*/
|
|
2239
|
-
var getCommit = async (
|
|
2607
|
+
var getCommit = async (context, hash) => {
|
|
2240
2608
|
try {
|
|
2241
2609
|
const commit = await git.readCommit({
|
|
2242
2610
|
fs,
|
|
2243
|
-
dir:
|
|
2611
|
+
dir: context.dir,
|
|
2612
|
+
gitdir: context.gitdir,
|
|
2244
2613
|
oid: hash
|
|
2245
2614
|
});
|
|
2246
2615
|
return {
|
|
@@ -2248,7 +2617,8 @@ var getCommit = async (repositoryPath, hash) => {
|
|
|
2248
2617
|
shortHash: commit.oid.substring(0, 7),
|
|
2249
2618
|
date: (/* @__PURE__ */ new Date(commit.commit.author.timestamp * 1e3)).toISOString(),
|
|
2250
2619
|
message: commit.commit.message.trim(),
|
|
2251
|
-
parents: commit.commit.parent || []
|
|
2620
|
+
parents: commit.commit.parent || [],
|
|
2621
|
+
tree: commit.commit.tree
|
|
2252
2622
|
};
|
|
2253
2623
|
} catch (_unused) {
|
|
2254
2624
|
return;
|
|
@@ -2256,19 +2626,20 @@ var getCommit = async (repositoryPath, hash) => {
|
|
|
2256
2626
|
};
|
|
2257
2627
|
/**
|
|
2258
2628
|
* Get the current commit
|
|
2259
|
-
* @param
|
|
2629
|
+
* @param context - Git read context
|
|
2260
2630
|
* @returns The current commit or undefined if the current commit is not found
|
|
2261
2631
|
*/
|
|
2262
|
-
var getCurrentCommit = async (
|
|
2632
|
+
var getCurrentCommit = async (context) => {
|
|
2263
2633
|
try {
|
|
2264
2634
|
const currentOid = await git.resolveRef({
|
|
2265
2635
|
fs,
|
|
2266
|
-
dir:
|
|
2636
|
+
dir: context.dir,
|
|
2267
2637
|
ref: "HEAD"
|
|
2268
2638
|
});
|
|
2269
2639
|
const commit = await git.readCommit({
|
|
2270
2640
|
fs,
|
|
2271
|
-
dir:
|
|
2641
|
+
dir: context.dir,
|
|
2642
|
+
gitdir: context.gitdir,
|
|
2272
2643
|
oid: currentOid
|
|
2273
2644
|
});
|
|
2274
2645
|
return {
|
|
@@ -2276,7 +2647,8 @@ var getCurrentCommit = async (repositoryPath) => {
|
|
|
2276
2647
|
shortHash: commit.oid.substring(0, 7),
|
|
2277
2648
|
date: (/* @__PURE__ */ new Date(commit.commit.author.timestamp * 1e3)).toISOString(),
|
|
2278
2649
|
message: commit.commit.message.trim(),
|
|
2279
|
-
parents: commit.commit.parent || []
|
|
2650
|
+
parents: commit.commit.parent || [],
|
|
2651
|
+
tree: commit.commit.tree
|
|
2280
2652
|
};
|
|
2281
2653
|
} catch (_unused2) {
|
|
2282
2654
|
return;
|
|
@@ -2293,21 +2665,23 @@ var getRelatedTagsFromMap = (commitToTags, commitHash) => {
|
|
|
2293
2665
|
};
|
|
2294
2666
|
/**
|
|
2295
2667
|
* Get the commit related branch name.
|
|
2296
|
-
* @param
|
|
2668
|
+
* @param context - Git read context
|
|
2297
2669
|
* @param commitHash - The hash of the commit
|
|
2298
2670
|
* @returns The commit related branch name or undefined if not found
|
|
2299
2671
|
*/
|
|
2300
|
-
var getRelatedBranches = async (
|
|
2672
|
+
var getRelatedBranches = async (context, commitHash) => {
|
|
2301
2673
|
try {
|
|
2302
2674
|
const branches = await git.listBranches({
|
|
2303
2675
|
fs,
|
|
2304
|
-
dir:
|
|
2676
|
+
dir: context.dir,
|
|
2677
|
+
gitdir: context.gitdir
|
|
2305
2678
|
});
|
|
2306
2679
|
const relatedBranches = [];
|
|
2307
2680
|
for (const branch of branches) try {
|
|
2308
2681
|
if (await git.resolveRef({
|
|
2309
2682
|
fs,
|
|
2310
|
-
dir:
|
|
2683
|
+
dir: context.dir,
|
|
2684
|
+
gitdir: context.gitdir,
|
|
2311
2685
|
ref: branch
|
|
2312
2686
|
}) === commitHash) relatedBranches.push(branch);
|
|
2313
2687
|
} catch (_unused3) {}
|
|
@@ -2316,94 +2690,133 @@ var getRelatedBranches = async (repositoryPath, commitHash) => {
|
|
|
2316
2690
|
return [];
|
|
2317
2691
|
}
|
|
2318
2692
|
};
|
|
2319
|
-
|
|
2320
|
-
* Check if the repository has modified files (following RelaxVersioner logic).
|
|
2321
|
-
* Checks for staged files, unstaged files, and untracked files (respecting .gitignore).
|
|
2322
|
-
* @param repositoryPath - Local Git repository directory
|
|
2323
|
-
* @returns Modified files
|
|
2324
|
-
*/
|
|
2325
|
-
var isModifiedFile = ([, head, workdir, stage]) => {
|
|
2326
|
-
return workdir === 2 || stage === 2 || stage === 3 || head === 1 && workdir === 0 || head === 0 && workdir === 1;
|
|
2327
|
-
};
|
|
2328
|
-
var getStatusRow = async (filepath, entries) => {
|
|
2329
|
-
const [head, workdir, stage] = entries;
|
|
2330
|
-
const [headType, workdirType, stageType] = await Promise.all([
|
|
2331
|
-
head ? head.type() : void 0,
|
|
2332
|
-
workdir ? workdir.type() : void 0,
|
|
2333
|
-
stage ? stage.type() : void 0
|
|
2334
|
-
]);
|
|
2335
|
-
const isBlob = [
|
|
2336
|
-
headType,
|
|
2337
|
-
workdirType,
|
|
2338
|
-
stageType
|
|
2339
|
-
].includes("blob");
|
|
2340
|
-
if ((headType === "tree" || headType === "special") && !isBlob) return;
|
|
2341
|
-
if (headType === "commit") return;
|
|
2342
|
-
if ((workdirType === "tree" || workdirType === "special") && !isBlob) return;
|
|
2343
|
-
if (stageType === "commit") return;
|
|
2344
|
-
if ((stageType === "tree" || stageType === "special") && !isBlob) return;
|
|
2345
|
-
const headOid = headType === "blob" ? await head.oid() : void 0;
|
|
2346
|
-
const stageOid = stageType === "blob" ? await stage.oid() : void 0;
|
|
2347
|
-
let workdirOid;
|
|
2348
|
-
if (headType !== "blob" && workdirType === "blob" && stageType !== "blob") workdirOid = "42";
|
|
2349
|
-
else if (workdirType === "blob") workdirOid = await workdir.oid();
|
|
2350
|
-
const entry = [
|
|
2351
|
-
void 0,
|
|
2352
|
-
headOid,
|
|
2353
|
-
workdirOid,
|
|
2354
|
-
stageOid
|
|
2355
|
-
];
|
|
2356
|
-
const statusValues = entry.map((value) => entry.indexOf(value));
|
|
2357
|
-
return [
|
|
2358
|
-
filepath,
|
|
2359
|
-
statusValues[1],
|
|
2360
|
-
statusValues[2],
|
|
2361
|
-
statusValues[3]
|
|
2362
|
-
];
|
|
2363
|
-
};
|
|
2364
|
-
var reduceModifiedFiles = async (parent, children) => {
|
|
2365
|
-
const modifiedFiles = parent ? [parent] : [];
|
|
2366
|
-
for (const child of children) modifiedFiles.push(...child);
|
|
2367
|
-
return modifiedFiles;
|
|
2368
|
-
};
|
|
2369
|
-
var iterateSequentially = async (walk, children) => {
|
|
2370
|
-
const results = [];
|
|
2371
|
-
for (const child of children) results.push(await walk(child));
|
|
2372
|
-
return results;
|
|
2373
|
-
};
|
|
2374
|
-
var getModifiedFiles = async (repositoryPath) => {
|
|
2693
|
+
var parseGitIndex = async (gitDir) => {
|
|
2375
2694
|
try {
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2695
|
+
const buffer = await fs.readFile(join(gitDir, "index"));
|
|
2696
|
+
if (buffer.subarray(0, 4).toString("ascii") !== "DIRC") throw new Error("Unsupported git index signature");
|
|
2697
|
+
const version = buffer.readUInt32BE(4);
|
|
2698
|
+
if (version !== 2 && version !== 3) throw new Error(`Unsupported git index version: ${version}`);
|
|
2699
|
+
const entryCount = buffer.readUInt32BE(8);
|
|
2700
|
+
let offset = 12;
|
|
2701
|
+
const entries = /* @__PURE__ */ new Map();
|
|
2702
|
+
for (let index = 0; index < entryCount; index++) {
|
|
2703
|
+
const entryStart = offset;
|
|
2704
|
+
const size = buffer.readUInt32BE(entryStart + 36);
|
|
2705
|
+
const oid = buffer.subarray(entryStart + 40, entryStart + 60).toString("hex");
|
|
2706
|
+
const flags = buffer.readUInt16BE(entryStart + 60);
|
|
2707
|
+
const stage = flags >> 12 & 3;
|
|
2708
|
+
offset = entryStart + 62;
|
|
2709
|
+
if (version >= 3 && (flags & 16384) !== 0) offset += 2;
|
|
2710
|
+
const pathEnd = buffer.indexOf(0, offset);
|
|
2711
|
+
if (pathEnd < 0) throw new Error("Invalid git index path entry");
|
|
2712
|
+
const path = buffer.subarray(offset, pathEnd).toString("utf-8");
|
|
2713
|
+
offset = pathEnd + 1;
|
|
2714
|
+
while ((offset - entryStart) % 8 !== 0) offset += 1;
|
|
2715
|
+
entries.set(path, {
|
|
2716
|
+
path,
|
|
2717
|
+
oid,
|
|
2718
|
+
size,
|
|
2719
|
+
stage
|
|
2720
|
+
});
|
|
2721
|
+
}
|
|
2722
|
+
return entries;
|
|
2723
|
+
} catch (error) {
|
|
2724
|
+
if (error.code === "ENOENT") return /* @__PURE__ */ new Map();
|
|
2725
|
+
throw error;
|
|
2726
|
+
}
|
|
2727
|
+
};
|
|
2728
|
+
var listTrackedDirectories = (indexEntries) => {
|
|
2729
|
+
const directories = new Set([""]);
|
|
2730
|
+
for (const path of indexEntries.keys()) {
|
|
2731
|
+
const segments = path.split("/");
|
|
2732
|
+
let currentPath = "";
|
|
2733
|
+
for (let index = 0; index < segments.length - 1; index++) {
|
|
2734
|
+
currentPath = currentPath ? `${currentPath}/${segments[index]}` : segments[index];
|
|
2735
|
+
directories.add(currentPath);
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
return directories;
|
|
2739
|
+
};
|
|
2740
|
+
var listWorkingDirectoryFiles = async (repositoryPath, trackedDirectories, relativePath = "") => {
|
|
2741
|
+
const directoryPath = relativePath ? join(repositoryPath, relativePath) : repositoryPath;
|
|
2742
|
+
const entries = await fs.readdir(directoryPath, { withFileTypes: true });
|
|
2743
|
+
const files = [];
|
|
2744
|
+
for (const entry of entries) {
|
|
2745
|
+
if (entry.name === ".git") continue;
|
|
2746
|
+
const entryPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
2747
|
+
if (entry.isDirectory()) {
|
|
2748
|
+
if (!trackedDirectories.has(entryPath)) {
|
|
2749
|
+
if (await git.isIgnored({
|
|
2750
|
+
fs,
|
|
2751
|
+
dir: repositoryPath,
|
|
2752
|
+
filepath: entryPath
|
|
2753
|
+
})) continue;
|
|
2754
|
+
}
|
|
2755
|
+
files.push(...await listWorkingDirectoryFiles(repositoryPath, trackedDirectories, entryPath));
|
|
2756
|
+
continue;
|
|
2757
|
+
}
|
|
2758
|
+
if (entry.isFile() || entry.isSymbolicLink()) files.push(entryPath);
|
|
2759
|
+
}
|
|
2760
|
+
return files;
|
|
2761
|
+
};
|
|
2762
|
+
var calculateBlobOid = async (filePath) => {
|
|
2763
|
+
const content = await fs.readFile(filePath);
|
|
2764
|
+
return createHash("sha1").update(`blob ${content.length}\0`).update(content).digest("hex");
|
|
2765
|
+
};
|
|
2766
|
+
var getModifiedFiles = async (repositoryPath, headTreeOid) => {
|
|
2767
|
+
try {
|
|
2768
|
+
const gitDir = await getActualGitDir(repositoryPath);
|
|
2769
|
+
const [headFiles, indexEntries] = await Promise.all([listTreeFiles(repositoryPath, headTreeOid), parseGitIndex(gitDir)]);
|
|
2770
|
+
const workdirFiles = await listWorkingDirectoryFiles(repositoryPath, listTrackedDirectories(indexEntries));
|
|
2771
|
+
const modifiedFiles = /* @__PURE__ */ new Map();
|
|
2772
|
+
const rememberModifiedFile = (path, reason) => {
|
|
2773
|
+
if (!modifiedFiles.has(path)) modifiedFiles.set(path, {
|
|
2774
|
+
path,
|
|
2775
|
+
reason
|
|
2776
|
+
});
|
|
2777
|
+
};
|
|
2778
|
+
for (const [path, headOid] of headFiles.entries()) {
|
|
2779
|
+
const indexEntry = indexEntries.get(path);
|
|
2780
|
+
if (!indexEntry) rememberModifiedFile(path, "staged");
|
|
2781
|
+
else if (indexEntry.stage !== 0 || indexEntry.oid !== headOid) rememberModifiedFile(path, "staged");
|
|
2782
|
+
}
|
|
2783
|
+
for (const indexEntry of indexEntries.values()) {
|
|
2784
|
+
if (!headFiles.has(indexEntry.path)) rememberModifiedFile(indexEntry.path, "staged");
|
|
2785
|
+
const absolutePath = join(repositoryPath, indexEntry.path);
|
|
2786
|
+
try {
|
|
2787
|
+
const stats = await fs.lstat(absolutePath);
|
|
2788
|
+
if (!stats.isFile() && !stats.isSymbolicLink()) {
|
|
2789
|
+
rememberModifiedFile(indexEntry.path, "worktree");
|
|
2790
|
+
continue;
|
|
2392
2791
|
}
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2792
|
+
if (indexEntry.stage !== 0) {
|
|
2793
|
+
rememberModifiedFile(indexEntry.path, "staged");
|
|
2794
|
+
continue;
|
|
2795
|
+
}
|
|
2796
|
+
if (indexEntry.size !== stats.size || await calculateBlobOid(absolutePath) !== indexEntry.oid) rememberModifiedFile(indexEntry.path, "worktree");
|
|
2797
|
+
} catch (error) {
|
|
2798
|
+
if (error.code === "ENOENT") {
|
|
2799
|
+
rememberModifiedFile(indexEntry.path, "worktree");
|
|
2800
|
+
continue;
|
|
2801
|
+
}
|
|
2802
|
+
throw error;
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
const trackedPaths = new Set(indexEntries.keys());
|
|
2806
|
+
for (const filepath of workdirFiles) {
|
|
2807
|
+
if (trackedPaths.has(filepath)) continue;
|
|
2808
|
+
if (!await git.isIgnored({
|
|
2809
|
+
fs,
|
|
2810
|
+
dir: repositoryPath,
|
|
2811
|
+
filepath
|
|
2812
|
+
})) rememberModifiedFile(filepath, "untracked");
|
|
2813
|
+
}
|
|
2814
|
+
return Array.from(modifiedFiles.values());
|
|
2400
2815
|
} catch (_unused5) {
|
|
2401
2816
|
return [];
|
|
2402
2817
|
}
|
|
2403
2818
|
};
|
|
2404
|
-
var formatModifiedFile = (modifiedFile) => {
|
|
2405
|
-
return `'${modifiedFile[0]}':${modifiedFile[1]}:${modifiedFile[2]}:${modifiedFile[3]}`;
|
|
2406
|
-
};
|
|
2819
|
+
var formatModifiedFile = (modifiedFile) => `'${modifiedFile.path}':${modifiedFile.reason}`;
|
|
2407
2820
|
/**
|
|
2408
2821
|
* Lookup version label recursively core analyzer
|
|
2409
2822
|
* @param cwd - The directory to check
|
|
@@ -2412,7 +2825,7 @@ var formatModifiedFile = (modifiedFile) => {
|
|
|
2412
2825
|
* @param commitToTags - Map of commit hash to tags for performance
|
|
2413
2826
|
* @returns The version or undefined if no version is found
|
|
2414
2827
|
*/
|
|
2415
|
-
var lookupVersionLabelRecursive = async (
|
|
2828
|
+
var lookupVersionLabelRecursive = async (context, commit, reachedCommits, commitToTags) => {
|
|
2416
2829
|
const scheduledStack = [];
|
|
2417
2830
|
let version = {
|
|
2418
2831
|
major: 0,
|
|
@@ -2436,10 +2849,11 @@ var lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, commitToTa
|
|
|
2436
2849
|
try {
|
|
2437
2850
|
const parentHashes = (await git.readCommit({
|
|
2438
2851
|
fs,
|
|
2439
|
-
dir:
|
|
2852
|
+
dir: context.dir,
|
|
2853
|
+
gitdir: context.gitdir,
|
|
2440
2854
|
oid: currentCommit.hash
|
|
2441
2855
|
})).commit.parent || [];
|
|
2442
|
-
parentCommits = (await Promise.all(parentHashes.map((parentHash) => getCommit(
|
|
2856
|
+
parentCommits = (await Promise.all(parentHashes.map((parentHash) => getCommit(context, parentHash)))).filter((ci) => ci !== void 0);
|
|
2443
2857
|
} catch (_unused6) {}
|
|
2444
2858
|
if (parentCommits.length === 0) {
|
|
2445
2859
|
reachedCommits.set(currentCommit.hash, version);
|
|
@@ -2454,7 +2868,7 @@ var lookupVersionLabelRecursive = async (cwd, commit, reachedCommits, commitToTa
|
|
|
2454
2868
|
while (scheduledStack.length >= 1) {
|
|
2455
2869
|
const { commit: scheduledCommit, parents } = scheduledStack.pop();
|
|
2456
2870
|
if (parents.length >= 2) for (let index = 1; index < parents.length; index++) {
|
|
2457
|
-
const alternateParentVersion = await lookupVersionLabelRecursive(
|
|
2871
|
+
const alternateParentVersion = await lookupVersionLabelRecursive(context, parents[index], reachedCommits, commitToTags);
|
|
2458
2872
|
if (alternateParentVersion && compareVersions(alternateParentVersion, version) < 0) version = alternateParentVersion;
|
|
2459
2873
|
}
|
|
2460
2874
|
version = incrementLastVersionComponent(version);
|
|
@@ -2482,12 +2896,31 @@ var getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logger)
|
|
|
2482
2896
|
logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
|
|
2483
2897
|
return metadata;
|
|
2484
2898
|
}
|
|
2899
|
+
let gitContext;
|
|
2485
2900
|
try {
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2901
|
+
gitContext = await createGitReadContext(gitRootPath);
|
|
2902
|
+
} catch (error) {
|
|
2903
|
+
logger.warn(`Failed to resolve git metadata context: ${error}`);
|
|
2904
|
+
logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
|
|
2905
|
+
return metadata;
|
|
2906
|
+
}
|
|
2907
|
+
const currentCommit = await getCurrentCommit(gitContext);
|
|
2908
|
+
if (!currentCommit) {
|
|
2909
|
+
logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
|
|
2910
|
+
return metadata;
|
|
2911
|
+
}
|
|
2912
|
+
const gitMetadata = {
|
|
2913
|
+
tags: [],
|
|
2914
|
+
branches: [],
|
|
2915
|
+
commit: {
|
|
2916
|
+
hash: currentCommit.hash,
|
|
2917
|
+
shortHash: currentCommit.shortHash,
|
|
2918
|
+
date: dayjs(currentCommit.date).format("YYYY-MM-DDTHH:mm:ssZ"),
|
|
2919
|
+
message: currentCommit.message
|
|
2490
2920
|
}
|
|
2921
|
+
};
|
|
2922
|
+
metadata.git = gitMetadata;
|
|
2923
|
+
try {
|
|
2491
2924
|
const buildStart = Date.now();
|
|
2492
2925
|
const commitToTags = await buildCompleteTagCache(gitRootPath, (tagName) => {
|
|
2493
2926
|
const version = parseVersion(tagName);
|
|
@@ -2495,15 +2928,10 @@ var getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logger)
|
|
|
2495
2928
|
}, logger);
|
|
2496
2929
|
logger.debug(`[screw-up] buildCompleteTagCache: ${Date.now() - buildStart}ms`);
|
|
2497
2930
|
logger.debug(`Built tag map with ${commitToTags.size} commits`);
|
|
2498
|
-
let version = await lookupVersionLabelRecursive(
|
|
2499
|
-
const gitMetadata = {
|
|
2500
|
-
tags: [],
|
|
2501
|
-
branches: []
|
|
2502
|
-
};
|
|
2503
|
-
metadata.git = gitMetadata;
|
|
2931
|
+
let version = await lookupVersionLabelRecursive(gitContext, currentCommit, /* @__PURE__ */ new Map(), commitToTags);
|
|
2504
2932
|
if (version) {
|
|
2505
2933
|
if (checkWorkingDirectoryStatus) {
|
|
2506
|
-
const modifiedFiles = await getModifiedFiles(gitRootPath);
|
|
2934
|
+
const modifiedFiles = await getModifiedFiles(gitRootPath, currentCommit.tree);
|
|
2507
2935
|
if (modifiedFiles.length >= 1) {
|
|
2508
2936
|
const newVersion = incrementLastVersionComponent(version);
|
|
2509
2937
|
logger.debug(`Increased git version by detected modified items: ${formatVersion(version)} ---> ${formatVersion(newVersion)}, Files=[${modifiedFiles.map(formatModifiedFile).join(", ")}]`);
|
|
@@ -2514,16 +2942,14 @@ var getGitMetadata = async (repositoryPath, checkWorkingDirectoryStatus, logger)
|
|
|
2514
2942
|
gitMetadata.version = gitVersion;
|
|
2515
2943
|
metadata.version = gitVersion;
|
|
2516
2944
|
}
|
|
2517
|
-
gitMetadata.commit = {
|
|
2518
|
-
hash: currentCommit.hash,
|
|
2519
|
-
shortHash: currentCommit.shortHash,
|
|
2520
|
-
date: dayjs(currentCommit.date).format("YYYY-MM-DDTHH:mm:ssZ"),
|
|
2521
|
-
message: currentCommit.message
|
|
2522
|
-
};
|
|
2523
2945
|
gitMetadata.tags = getRelatedTagsFromMap(commitToTags, currentCommit.hash).map((tag) => tag.name);
|
|
2524
|
-
gitMetadata.branches = await getRelatedBranches(gitRootPath, currentCommit.hash);
|
|
2525
2946
|
} catch (error) {
|
|
2526
|
-
logger.warn(`Failed to
|
|
2947
|
+
logger.warn(`Failed to resolve git versioning metadata: ${error}`);
|
|
2948
|
+
}
|
|
2949
|
+
try {
|
|
2950
|
+
gitMetadata.branches = await getRelatedBranches(gitContext, currentCommit.hash);
|
|
2951
|
+
} catch (error) {
|
|
2952
|
+
logger.warn(`Failed to resolve git branch metadata: ${error}`);
|
|
2527
2953
|
}
|
|
2528
2954
|
logger.debug(`[screw-up] Total getGitMetadata: ${Date.now() - startTime}ms`);
|
|
2529
2955
|
return metadata;
|
|
@@ -2609,4 +3035,4 @@ var ensureMetadataGitignore = async (metadataSourcePath, logger) => {
|
|
|
2609
3035
|
//#endregion
|
|
2610
3036
|
export { collectWorkspaceSiblings as a, replacePeerDependenciesWildcards as c, require_dist as d, __exportAll as f, getFetchGitMetadata as i, resolvePackageMetadata as l, generateMetadataFileContent as n, createConsoleLogger as o, __toESM as p, writeFileIfChanged as r, findWorkspaceRoot as s, ensureMetadataGitignore as t, resolveRawPackageJsonObject as u };
|
|
2611
3037
|
|
|
2612
|
-
//# sourceMappingURL=metadata-file-
|
|
3038
|
+
//# sourceMappingURL=metadata-file-Case8fsm.js.map
|