authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-27 13:38:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-27 13:38:19-04:00
log41e17106cdcb0bc19f26ef67ebe2d98d920ee21b
tree5097dd7ccdadda390fca0e43c03ab0b504a9ef24
parentfdff381a5644d5e12519ca53012d7b00a33a33c4

zig fmt: still print the relative path

The previous commit made zig fmt print absolute paths; this commit keeps the absolute path resolution but still prints the relative paths to stdout.

2 files changed, 9 insertions(+), 5 deletions(-)

lib/std/io/buffered_atomic_file.zig+7-3
......@@ -15,8 +15,12 @@ pub const BufferedAtomicFile = struct {
1515
1616 /// TODO when https://github.com/ziglang/zig/issues/2761 is solved
1717 /// this API will not need an allocator
18 /// TODO integrate this with Dir API
19 pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile {
18 pub fn create(
19 allocator: *mem.Allocator,
20 dir: fs.Dir,
21 dest_path: []const u8,
22 atomic_file_options: fs.Dir.AtomicFileOptions,
23 ) !*BufferedAtomicFile {
2024 var self = try allocator.create(BufferedAtomicFile);
2125 self.* = BufferedAtomicFile{
2226 .atomic_file = undefined,
......@@ -26,7 +30,7 @@ pub const BufferedAtomicFile = struct {
2630 };
2731 errdefer allocator.destroy(self);
2832
29 self.atomic_file = try fs.cwd().atomicFile(dest_path, .{});
33 self.atomic_file = try dir.atomicFile(dest_path, atomic_file_options);
3034 errdefer self.atomic_file.deinit();
3135
3236 self.file_stream = self.atomic_file.file.outStream();
src-self-hosted/stage2.zig+2-2
......@@ -339,7 +339,7 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
339339
340340 while (try dir_it.next()) |entry| {
341341 if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) {
342 const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ real_path, entry.name });
342 const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ file_path, entry.name });
343343 try fmtPath(fmt, full_path, check_mode);
344344 }
345345 }
......@@ -377,7 +377,7 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
377377 fmt.any_error = true;
378378 }
379379 } else {
380 const baf = try io.BufferedAtomicFile.create(fmt.allocator, real_path);
380 const baf = try io.BufferedAtomicFile.create(fmt.allocator, fs.cwd(), real_path, .{});
381381 defer baf.destroy();
382382
383383 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);