authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-10 16:41:15-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-10 16:41:15-07:00
log6ca4ed5948d8eaab28fc5e3706aeb1b113a210af
tree3941236c60db642437683f492badae8209790ed0
parent7fa2357d0586cef742bf691d69a6cffdd353b496

Revert "Merge pull request #19349 from nolanderc/save-commit"

This reverts commit 7fa2357d0586cef742bf691d69a6cffdd353b496, reversing changes made to cb77bd672c3b398e3c5f6be80af03243bf8638e3.

2 files changed, 3 insertions(+), 51 deletions(-)

src/Package/Fetch.zig+1-9
......@@ -44,8 +44,6 @@ omit_missing_hash_error: bool,
4444/// which specifies inclusion rules. This is intended to be true for the first
4545/// fetch task and false for the recursive dependencies.
4646allow_missing_paths_field: bool,
47/// If true and URL points to a Git repository, will use the latest commit.
48use_latest_commit: bool,
4947
5048// Above this are fields provided as inputs to `run`.
5149// Below this are fields populated by `run`.
......@@ -61,8 +59,6 @@ actual_hash: Manifest.Digest,
6159has_build_zig: bool,
6260/// Indicates whether the task aborted due to an out-of-memory condition.
6361oom_flag: bool,
64/// If `use_latest_commit` was true, this will be the commit that was used.
65latest_commit: ?git.Oid,
6662
6763// This field is used by the CLI only, untouched by this file.
6864
......@@ -703,7 +699,6 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
703699 .job_queue = f.job_queue,
704700 .omit_missing_hash_error = false,
705701 .allow_missing_paths_field = true,
706 .use_latest_commit = false,
707702
708703 .package_root = undefined,
709704 .error_bundle = undefined,
......@@ -712,7 +707,6 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
712707 .actual_hash = undefined,
713708 .has_build_zig = false,
714709 .oom_flag = false,
715 .latest_commit = undefined,
716710
717711 .module = null,
718712 };
......@@ -1000,9 +994,7 @@ fn initResource(f: *Fetch, uri: std.Uri, server_header_buffer: []u8) RunError!Re
1000994 }
1001995 return f.fail(f.location_tok, try eb.printString("ref not found: {s}", .{want_ref}));
1002996 };
1003 if (f.use_latest_commit) {
1004 f.latest_commit = want_oid;
1005 } else if (uri.fragment == null) {
997 if (uri.fragment == null) {
1006998 const notes_len = 1;
1007999 try eb.addRootErrorMessage(.{
10081000 .msg = try eb.addString("url field is missing an explicit ref"),
src/main.zig+2-42
......@@ -5097,7 +5097,6 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
50975097 .job_queue = &job_queue,
50985098 .omit_missing_hash_error = true,
50995099 .allow_missing_paths_field = false,
5100 .use_latest_commit = false,
51015100
51025101 .package_root = undefined,
51035102 .error_bundle = undefined,
......@@ -5106,7 +5105,6 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
51065105 .actual_hash = undefined,
51075106 .has_build_zig = true,
51085107 .oom_flag = false,
5109 .latest_commit = undefined,
51105108
51115109 .module = build_mod,
51125110 };
......@@ -6896,7 +6894,6 @@ const usage_fetch =
68966894 \\ --debug-hash Print verbose hash information to stdout
68976895 \\ --save Add the fetched package to build.zig.zon
68986896 \\ --save=[name] Add the fetched package to build.zig.zon as name
6899 \\ --preserve-url Store a verbatim copy of the URL in build.zig.zon
69006897 \\
69016898;
69026899
......@@ -6912,7 +6909,6 @@ fn cmdFetch(
69126909 var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
69136910 var debug_hash: bool = false;
69146911 var save: union(enum) { no, yes, name: []const u8 } = .no;
6915 var preserve_url: bool = false;
69166912
69176913 {
69186914 var i: usize = 0;
......@@ -6933,8 +6929,6 @@ fn cmdFetch(
69336929 save = .yes;
69346930 } else if (mem.startsWith(u8, arg, "--save=")) {
69356931 save = .{ .name = arg["--save=".len..] };
6936 } else if (mem.startsWith(u8, arg, "--preserve-url")) {
6937 preserve_url = true;
69386932 } else {
69396933 fatal("unrecognized parameter: '{s}'", .{arg});
69406934 }
......@@ -6946,8 +6940,6 @@ fn cmdFetch(
69466940 }
69476941 }
69486942
6949 if (preserve_url and save == .no) fatal("use of '--preserve-url' requires '--save'", .{});
6950
69516943 const path_or_url = opt_path_or_url orelse fatal("missing url or path parameter", .{});
69526944
69536945 var thread_pool: ThreadPool = undefined;
......@@ -6996,7 +6988,6 @@ fn cmdFetch(
69966988 .job_queue = &job_queue,
69976989 .omit_missing_hash_error = true,
69986990 .allow_missing_paths_field = false,
6999 .use_latest_commit = true,
70006991
70016992 .package_root = undefined,
70026993 .error_bundle = undefined,
......@@ -7005,7 +6996,6 @@ fn cmdFetch(
70056996 .actual_hash = undefined,
70066997 .has_build_zig = false,
70076998 .oom_flag = false,
7008 .latest_commit = undefined,
70096999
70107000 .module = null,
70117001 };
......@@ -7062,43 +7052,13 @@ fn cmdFetch(
70627052 var fixups: Ast.Fixups = .{};
70637053 defer fixups.deinit(gpa);
70647054
7065 var saved_path_or_url = path_or_url;
7066
7067 if (fetch.latest_commit) |*latest_commit| {
7068 var uri = try std.Uri.parse(path_or_url);
7069 const target_ref = uri.fragment orelse "";
7070 if (!std.mem.eql(u8, target_ref, latest_commit)) {
7071 std.log.info("resolved ref '{s}' to commit {s}", .{
7072 target_ref,
7073 std.fmt.fmtSliceHexLower(latest_commit),
7074 });
7075
7076 if (!preserve_url) {
7077 if (target_ref.len != 0) {
7078 // include the target ref in a query parameter
7079 var query = try std.ArrayList(u8).initCapacity(arena, 4 + target_ref.len);
7080 try std.Uri.writeEscapedQuery(query.writer(), "ref=");
7081 try std.Uri.writeEscapedQuery(query.writer(), target_ref);
7082 uri.query = try query.toOwnedSlice();
7083 }
7084
7085 // replace the refspec with the resolved commit SHA
7086 uri.fragment = try std.fmt.allocPrint(arena, "{}", .{
7087 std.fmt.fmtSliceHexLower(latest_commit),
7088 });
7089
7090 saved_path_or_url = try std.fmt.allocPrint(arena, "{}", .{uri});
7091 }
7092 }
7093 }
7094
70957055 const new_node_init = try std.fmt.allocPrint(arena,
70967056 \\.{{
70977057 \\ .url = "{}",
70987058 \\ .hash = "{}",
70997059 \\ }}
71007060 , .{
7101 std.zig.fmtEscapes(saved_path_or_url),
7061 std.zig.fmtEscapes(path_or_url),
71027062 std.zig.fmtEscapes(&hex_digest),
71037063 });
71047064
......@@ -7118,7 +7078,7 @@ fn cmdFetch(
71187078 if (dep.hash) |h| {
71197079 switch (dep.location) {
71207080 .url => |u| {
7121 if (mem.eql(u8, h, &hex_digest) and mem.eql(u8, u, saved_path_or_url)) {
7081 if (mem.eql(u8, h, &hex_digest) and mem.eql(u8, u, path_or_url)) {
71227082 std.log.info("existing dependency named '{s}' is up-to-date", .{name});
71237083 process.exit(0);
71247084 }