-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
zig fetch: resolve branch/tag names to commit SHA
#19349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5098,6 +5098,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | |
| .job_queue = &job_queue, | ||
| .omit_missing_hash_error = true, | ||
| .allow_missing_paths_field = false, | ||
| .use_latest_commit = false, | ||
|
|
||
| .package_root = undefined, | ||
| .error_bundle = undefined, | ||
|
|
@@ -5106,6 +5107,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | |
| .actual_hash = undefined, | ||
| .has_build_zig = true, | ||
| .oom_flag = false, | ||
| .latest_commit = undefined, | ||
|
|
||
| .module = build_mod, | ||
| }; | ||
|
|
@@ -6757,6 +6759,7 @@ const usage_fetch = | |
| \\ --debug-hash Print verbose hash information to stdout | ||
| \\ --save Add the fetched package to build.zig.zon | ||
| \\ --save=[name] Add the fetched package to build.zig.zon as name | ||
| \\ --preserve-url Store a verbatim copy of the URL in build.zig.zon | ||
| \\ | ||
| ; | ||
|
|
||
|
|
@@ -6772,6 +6775,7 @@ fn cmdFetch( | |
| var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); | ||
| var debug_hash: bool = false; | ||
| var save: union(enum) { no, yes, name: []const u8 } = .no; | ||
| var preserve_url: bool = false; | ||
|
|
||
| { | ||
| var i: usize = 0; | ||
|
|
@@ -6792,6 +6796,8 @@ fn cmdFetch( | |
| save = .yes; | ||
| } else if (mem.startsWith(u8, arg, "--save=")) { | ||
| save = .{ .name = arg["--save=".len..] }; | ||
| } else if (mem.startsWith(u8, arg, "--preserve-url")) { | ||
| preserve_url = true; | ||
| } else { | ||
| fatal("unrecognized parameter: '{s}'", .{arg}); | ||
| } | ||
|
|
@@ -6803,6 +6809,8 @@ fn cmdFetch( | |
| } | ||
| } | ||
|
|
||
| if (preserve_url and save == .no) fatal("use of '--preserve-url' requires '--save'", .{}); | ||
|
|
||
| const path_or_url = opt_path_or_url orelse fatal("missing url or path parameter", .{}); | ||
|
|
||
| var thread_pool: ThreadPool = undefined; | ||
|
|
@@ -6851,6 +6859,7 @@ fn cmdFetch( | |
| .job_queue = &job_queue, | ||
| .omit_missing_hash_error = true, | ||
| .allow_missing_paths_field = false, | ||
| .use_latest_commit = true, | ||
|
|
||
| .package_root = undefined, | ||
| .error_bundle = undefined, | ||
|
|
@@ -6859,6 +6868,7 @@ fn cmdFetch( | |
| .actual_hash = undefined, | ||
| .has_build_zig = false, | ||
| .oom_flag = false, | ||
| .latest_commit = undefined, | ||
|
|
||
| .module = null, | ||
| }; | ||
|
|
@@ -6915,13 +6925,43 @@ fn cmdFetch( | |
| var fixups: Ast.Fixups = .{}; | ||
| defer fixups.deinit(gpa); | ||
|
|
||
| var saved_path_or_url = path_or_url; | ||
|
|
||
| if (fetch.latest_commit) |*latest_commit| { | ||
| var uri = try std.Uri.parse(path_or_url); | ||
| const target_ref = uri.fragment orelse ""; | ||
| if (!std.mem.eql(u8, target_ref, latest_commit)) { | ||
| std.log.info("resolved ref '{s}' to commit {s}", .{ | ||
| target_ref, | ||
| std.fmt.fmtSliceHexLower(latest_commit), | ||
| }); | ||
|
|
||
| if (!preserve_url) { | ||
| if (target_ref.len != 0) { | ||
|
Comment on lines
+6930
to
+6940
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too much nesting. Give the block a label and use break statements. Don't use string length 0 to mean null.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #19941 |
||
| // include the target ref in a query parameter | ||
| var query = try std.ArrayList(u8).initCapacity(arena, 4 + target_ref.len); | ||
| try std.Uri.writeEscapedQuery(query.writer(), "ref="); | ||
| try std.Uri.writeEscapedQuery(query.writer(), target_ref); | ||
| uri.query = try query.toOwnedSlice(); | ||
|
Comment on lines
+6942
to
+6945
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #19941 |
||
| } | ||
|
|
||
| // replace the refspec with the resolved commit SHA | ||
| uri.fragment = try std.fmt.allocPrint(arena, "{}", .{ | ||
| std.fmt.fmtSliceHexLower(latest_commit), | ||
| }); | ||
|
|
||
| saved_path_or_url = try std.fmt.allocPrint(arena, "{}", .{uri}); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const new_node_init = try std.fmt.allocPrint(arena, | ||
| \\.{{ | ||
| \\ .url = "{}", | ||
| \\ .hash = "{}", | ||
| \\ }} | ||
| , .{ | ||
| std.zig.fmtEscapes(path_or_url), | ||
| std.zig.fmtEscapes(saved_path_or_url), | ||
| std.zig.fmtEscapes(&hex_digest), | ||
| }); | ||
|
|
||
|
|
@@ -6941,7 +6981,7 @@ fn cmdFetch( | |
| if (dep.hash) |h| { | ||
| switch (dep.location) { | ||
| .url => |u| { | ||
| if (mem.eql(u8, h, &hex_digest) and mem.eql(u8, u, path_or_url)) { | ||
| if (mem.eql(u8, h, &hex_digest) and mem.eql(u8, u, saved_path_or_url)) { | ||
| std.log.info("existing dependency named '{s}' is up-to-date", .{name}); | ||
| process.exit(0); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be incorporated into the type of
save. I think a better set of flags would be--save-exactand--save-exact=[name].There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #19941