aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-01-11 16:18:45 -0800
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-01-11 16:18:45 -0800
commitc03f7c998dd22689412658177e3a5736ce6b9034 (patch)
tree0d6e4e576b243d8c705d5896cc97e8f85fbd7b4e
parentbeb03c3c54c1fec4cdbec5440e0ab595351317f6 (diff)
downloadbun-c03f7c998dd22689412658177e3a5736ce6b9034.tar.gz
bun-c03f7c998dd22689412658177e3a5736ce6b9034.tar.zst
bun-c03f7c998dd22689412658177e3a5736ce6b9034.zip
git url parsing
-rw-r--r--src/install/install.zig14
-rw-r--r--src/install/repository.zig34
2 files changed, 42 insertions, 6 deletions
diff --git a/src/install/install.zig b/src/install/install.zig
index c4248aca7..3221605cd 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -2578,7 +2578,7 @@ pub const PackageManager = struct {
return &task.threadpool_task;
}
- fn enqueueCloneGitHubPackage(
+ fn enqueueCloneGitPackage(
this: *PackageManager,
task_id: u64,
repository: Repository,
@@ -2746,7 +2746,7 @@ pub const PackageManager = struct {
}
switch (dependency.version.tag) {
- .github => {
+ .github, .git => {
var resolve_result = this.getOrPutResolvedPackage(
name_hash,
name,
@@ -2765,13 +2765,19 @@ pub const PackageManager = struct {
if (resolve_result == null) {
const lockfile = this.lockfile;
- const repo = dependency.version.value.github;
+
+ const repo = if (version.tag == .github) version.value.github else version.value.git;
const task_id = Task.Id.forGitHubPackage(lockfile.str(repo.repo), lockfile.str(repo.owner));
const network_id = try this.network_dedupe_map.getOrPutContext(this.allocator, task_id, .{});
if (!network_id.found_existing) {
var batch = ThreadPool.Batch{};
- batch.push(ThreadPool.Batch.from(this.enqueueCloneGitHubPackage(task_id, version.value.github, id, dependency.version)));
+ batch.push(ThreadPool.Batch.from(this.enqueueCloneGitPackage(
+ task_id,
+ repo,
+ id,
+ dependency.version,
+ )));
const count = batch.len;
this.pending_tasks += @truncate(u32, count);
diff --git a/src/install/repository.zig b/src/install/repository.zig
index 264efe43e..d53fca8d5 100644
--- a/src/install/repository.zig
+++ b/src/install/repository.zig
@@ -61,7 +61,6 @@ pub const Repository = extern struct {
std.mem.copy(u8, buf[i..], github);
i += github.len;
- // might need to skip "github:"
std.mem.copy(u8, buf[i..], owner);
i += owner.len;
buf[i] = '/';
@@ -154,8 +153,37 @@ pub const Repository = extern struct {
return try std.fmt.bufPrint(buf, "{s}/{s}-{any}", .{ path, repo[0..@min(16, repo.len)], hex_fmt });
}
- pub fn parse(_: *const SlicedString) !Repository {
+ pub fn parse(input: *const SlicedString) !Repository {
var repo = Repository{};
+ const slice = input.slice;
+
+ // ignore "git+"
+ const i: usize = if (strings.indexOfChar(slice, '+')) |j| j + 1 else 0;
+ if (strings.indexOfChar(slice[i..], ':')) |_j| {
+ var j = i + _j + 1;
+ if (!strings.hasPrefixComptime(slice[j..], "//")) return error.InvalidGitURL;
+ j += 2;
+ if (strings.indexOfAny(slice[j..], ":/")) |k| {
+ j += k + 1;
+ if (strings.indexOfChar(slice[j..], '/')) |l| {
+ j += l;
+ repo.owner = String.init(input.buf, slice[i..j]);
+ } else return error.InvalidGitURL;
+ } else return error.InvalidGitURL;
+
+ if (strings.indexOfChar(slice[j..], '#')) |_k| {
+ var k = _k + j;
+ if (strings.endsWithComptime(slice[j + 1 .. k], ".git")) {
+ repo.repo = String.init(input.buf, slice[j + 1 .. k - ".git".len]);
+ } else {
+ repo.repo = String.init(input.buf, slice[j + 1 .. k]);
+ }
+ repo.committish = String.init(input.buf, slice[k + 1 ..]);
+ } else {
+ const end = if (strings.endsWithComptime(slice[j + 1 ..], ".git")) slice.len - ".git".len else slice.len;
+ repo.repo = String.init(input.buf, slice[j + 1 .. end]);
+ }
+ } else return error.InvalidGitURL;
return repo;
}
@@ -172,6 +200,8 @@ pub const Repository = extern struct {
} else {
repo.repo = String.init(input.buf, input.slice[j + 1 ..]);
}
+ } else {
+ return error.InvalidGitURL;
}
return repo;
}