| ... | ... | @@ -5097,7 +5097,6 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 5097 | 5097 | .job_queue = &job_queue, |
| 5098 | 5098 | .omit_missing_hash_error = true, |
| 5099 | 5099 | .allow_missing_paths_field = false, |
| 5100 | | .use_latest_commit = false, |
| 5101 | 5100 | |
| 5102 | 5101 | .package_root = undefined, |
| 5103 | 5102 | .error_bundle = undefined, |
| ... | ... | @@ -5106,7 +5105,6 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 5106 | 5105 | .actual_hash = undefined, |
| 5107 | 5106 | .has_build_zig = true, |
| 5108 | 5107 | .oom_flag = false, |
| 5109 | | .latest_commit = undefined, |
| 5110 | 5108 | |
| 5111 | 5109 | .module = build_mod, |
| 5112 | 5110 | }; |
| ... | ... | @@ -6896,7 +6894,6 @@ const usage_fetch = |
| 6896 | 6894 | \\ --debug-hash Print verbose hash information to stdout |
| 6897 | 6895 | \\ --save Add the fetched package to build.zig.zon |
| 6898 | 6896 | \\ --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 |
| 6900 | 6897 | \\ |
| 6901 | 6898 | ; |
| 6902 | 6899 | |
| ... | ... | @@ -6912,7 +6909,6 @@ fn cmdFetch( |
| 6912 | 6909 | var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); |
| 6913 | 6910 | var debug_hash: bool = false; |
| 6914 | 6911 | var save: union(enum) { no, yes, name: []const u8 } = .no; |
| 6915 | | var preserve_url: bool = false; |
| 6916 | 6912 | |
| 6917 | 6913 | { |
| 6918 | 6914 | var i: usize = 0; |
| ... | ... | @@ -6933,8 +6929,6 @@ fn cmdFetch( |
| 6933 | 6929 | save = .yes; |
| 6934 | 6930 | } else if (mem.startsWith(u8, arg, "--save=")) { |
| 6935 | 6931 | save = .{ .name = arg["--save=".len..] }; |
| 6936 | | } else if (mem.startsWith(u8, arg, "--preserve-url")) { |
| 6937 | | preserve_url = true; |
| 6938 | 6932 | } else { |
| 6939 | 6933 | fatal("unrecognized parameter: '{s}'", .{arg}); |
| 6940 | 6934 | } |
| ... | ... | @@ -6946,8 +6940,6 @@ fn cmdFetch( |
| 6946 | 6940 | } |
| 6947 | 6941 | } |
| 6948 | 6942 | |
| 6949 | | if (preserve_url and save == .no) fatal("use of '--preserve-url' requires '--save'", .{}); |
| 6950 | | |
| 6951 | 6943 | const path_or_url = opt_path_or_url orelse fatal("missing url or path parameter", .{}); |
| 6952 | 6944 | |
| 6953 | 6945 | var thread_pool: ThreadPool = undefined; |
| ... | ... | @@ -6996,7 +6988,6 @@ fn cmdFetch( |
| 6996 | 6988 | .job_queue = &job_queue, |
| 6997 | 6989 | .omit_missing_hash_error = true, |
| 6998 | 6990 | .allow_missing_paths_field = false, |
| 6999 | | .use_latest_commit = true, |
| 7000 | 6991 | |
| 7001 | 6992 | .package_root = undefined, |
| 7002 | 6993 | .error_bundle = undefined, |
| ... | ... | @@ -7005,7 +6996,6 @@ fn cmdFetch( |
| 7005 | 6996 | .actual_hash = undefined, |
| 7006 | 6997 | .has_build_zig = false, |
| 7007 | 6998 | .oom_flag = false, |
| 7008 | | .latest_commit = undefined, |
| 7009 | 6999 | |
| 7010 | 7000 | .module = null, |
| 7011 | 7001 | }; |
| ... | ... | @@ -7062,43 +7052,13 @@ fn cmdFetch( |
| 7062 | 7052 | var fixups: Ast.Fixups = .{}; |
| 7063 | 7053 | defer fixups.deinit(gpa); |
| 7064 | 7054 | |
| 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 | | |
| 7095 | 7055 | const new_node_init = try std.fmt.allocPrint(arena, |
| 7096 | 7056 | \\.{{ |
| 7097 | 7057 | \\ .url = "{}", |
| 7098 | 7058 | \\ .hash = "{}", |
| 7099 | 7059 | \\ }} |
| 7100 | 7060 | , .{ |
| 7101 | | std.zig.fmtEscapes(saved_path_or_url), |
| 7061 | std.zig.fmtEscapes(path_or_url), |
| 7102 | 7062 | std.zig.fmtEscapes(&hex_digest), |
| 7103 | 7063 | }); |
| 7104 | 7064 | |
| ... | ... | @@ -7118,7 +7078,7 @@ fn cmdFetch( |
| 7118 | 7078 | if (dep.hash) |h| { |
| 7119 | 7079 | switch (dep.location) { |
| 7120 | 7080 | .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)) { |
| 7122 | 7082 | std.log.info("existing dependency named '{s}' is up-to-date", .{name}); |
| 7123 | 7083 | process.exit(0); |
| 7124 | 7084 | } |