mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
fetch: fix mutating unrelated fields when saving (#19816)
closes #19725
This commit is contained in:
parent
5e4da1ff30
commit
4d09fb491f
2 changed files with 21 additions and 1 deletions
|
|
@ -18,8 +18,10 @@ pub const MultiHashHexDigest = [multihash_hex_digest_len]u8;
|
||||||
pub const Dependency = struct {
|
pub const Dependency = struct {
|
||||||
location: Location,
|
location: Location,
|
||||||
location_tok: Ast.TokenIndex,
|
location_tok: Ast.TokenIndex,
|
||||||
|
location_node: Ast.Node.Index,
|
||||||
hash: ?[]const u8,
|
hash: ?[]const u8,
|
||||||
hash_tok: Ast.TokenIndex,
|
hash_tok: Ast.TokenIndex,
|
||||||
|
hash_node: Ast.Node.Index,
|
||||||
node: Ast.Node.Index,
|
node: Ast.Node.Index,
|
||||||
name_tok: Ast.TokenIndex,
|
name_tok: Ast.TokenIndex,
|
||||||
lazy: bool,
|
lazy: bool,
|
||||||
|
|
@ -293,8 +295,10 @@ const Parse = struct {
|
||||||
var dep: Dependency = .{
|
var dep: Dependency = .{
|
||||||
.location = undefined,
|
.location = undefined,
|
||||||
.location_tok = 0,
|
.location_tok = 0,
|
||||||
|
.location_node = undefined,
|
||||||
.hash = null,
|
.hash = null,
|
||||||
.hash_tok = 0,
|
.hash_tok = 0,
|
||||||
|
.hash_node = undefined,
|
||||||
.node = node,
|
.node = node,
|
||||||
.name_tok = 0,
|
.name_tok = 0,
|
||||||
.lazy = false,
|
.lazy = false,
|
||||||
|
|
@ -320,6 +324,7 @@ const Parse = struct {
|
||||||
};
|
};
|
||||||
has_location = true;
|
has_location = true;
|
||||||
dep.location_tok = main_tokens[field_init];
|
dep.location_tok = main_tokens[field_init];
|
||||||
|
dep.location_node = field_init;
|
||||||
} else if (mem.eql(u8, field_name, "path")) {
|
} else if (mem.eql(u8, field_name, "path")) {
|
||||||
if (has_location) {
|
if (has_location) {
|
||||||
return fail(p, main_tokens[field_init], "dependency should specify only one of 'url' and 'path' fields.", .{});
|
return fail(p, main_tokens[field_init], "dependency should specify only one of 'url' and 'path' fields.", .{});
|
||||||
|
|
@ -332,12 +337,14 @@ const Parse = struct {
|
||||||
};
|
};
|
||||||
has_location = true;
|
has_location = true;
|
||||||
dep.location_tok = main_tokens[field_init];
|
dep.location_tok = main_tokens[field_init];
|
||||||
|
dep.location_node = field_init;
|
||||||
} else if (mem.eql(u8, field_name, "hash")) {
|
} else if (mem.eql(u8, field_name, "hash")) {
|
||||||
dep.hash = parseHash(p, field_init) catch |err| switch (err) {
|
dep.hash = parseHash(p, field_init) catch |err| switch (err) {
|
||||||
error.ParseFailure => continue,
|
error.ParseFailure => continue,
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
};
|
};
|
||||||
dep.hash_tok = main_tokens[field_init];
|
dep.hash_tok = main_tokens[field_init];
|
||||||
|
dep.hash_node = field_init;
|
||||||
} else if (mem.eql(u8, field_name, "lazy")) {
|
} else if (mem.eql(u8, field_name, "lazy")) {
|
||||||
dep.lazy = parseBool(p, field_init) catch |err| switch (err) {
|
dep.lazy = parseBool(p, field_init) catch |err| switch (err) {
|
||||||
error.ParseFailure => continue,
|
error.ParseFailure => continue,
|
||||||
|
|
|
||||||
15
src/main.zig
15
src/main.zig
|
|
@ -7214,8 +7214,21 @@ fn cmdFetch(
|
||||||
.path => {},
|
.path => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const location_replace = try std.fmt.allocPrint(
|
||||||
|
arena,
|
||||||
|
"\"{}\"",
|
||||||
|
.{std.zig.fmtEscapes(path_or_url)},
|
||||||
|
);
|
||||||
|
const hash_replace = try std.fmt.allocPrint(
|
||||||
|
arena,
|
||||||
|
"\"{}\"",
|
||||||
|
.{std.zig.fmtEscapes(&hex_digest)},
|
||||||
|
);
|
||||||
|
|
||||||
warn("overwriting existing dependency named '{s}'", .{name});
|
warn("overwriting existing dependency named '{s}'", .{name});
|
||||||
try fixups.replace_nodes_with_string.put(gpa, dep.node, new_node_init);
|
try fixups.replace_nodes_with_string.put(gpa, dep.location_node, location_replace);
|
||||||
|
try fixups.replace_nodes_with_string.put(gpa, dep.hash_node, hash_replace);
|
||||||
} else if (manifest.dependencies.count() > 0) {
|
} else if (manifest.dependencies.count() > 0) {
|
||||||
// Add fixup for adding another dependency.
|
// Add fixup for adding another dependency.
|
||||||
const deps = manifest.dependencies.values();
|
const deps = manifest.dependencies.values();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue