srctree

Gregory Mullen parent 0d44193f ea202096
drop unneeded alloc store from ini

this also adds repo config, but it's unused

inlinesplit
src/git.zig added: 20, removed: 17, total 3
@@ -181,7 +181,7 @@ pub const Repo = struct {
errdefer list.clearAndFree();
const config_data = try self.dir.readFileAlloc(a, "config", 0xffff);
const cfg = try Ini.Config(void).initOwned(a, config_data);
defer cfg.raze();
defer cfg.raze(a);
for (0..cfg.ns.len) |i| {
const ns = cfg.filter("remote", i) orelse break;
try list.append(.{
 
src/ini.zig added: 20, removed: 17, total 3
@@ -88,12 +88,12 @@ pub const Namespace = struct {
 
pub fn Config(Base: anytype) type {
return struct {
pub const Self = @This();
alloc: Allocator,
ns: []Namespace,
data: []const u8,
owned: ?[]const u8,
 
pub const Self = @This();
 
fn buildStruct(self: Self, T: type, name: []const u8) !?T {
var namespace: T = undefined;
const ns = self.get(name) orelse return null;
@@ -158,13 +158,13 @@ pub fn Config(Base: anytype) type {
return null;
}
 
pub fn raze(self: Self) void {
pub fn raze(self: Self, a: Allocator) void {
for (self.ns) |ns| {
ns.raze(self.alloc);
ns.raze(a);
}
self.alloc.free(self.ns);
a.free(self.ns);
if (self.owned) |owned| {
self.alloc.free(owned);
a.free(owned);
}
}
 
@@ -195,7 +195,6 @@ pub fn Config(Base: anytype) type {
}
 
return .{
.alloc = a,
.ns = try list.toOwnedSlice(),
.data = data,
.owned = null,
@@ -234,7 +233,6 @@ test "default" {
const a = std.testing.allocator;
 
const expected = Config(void){
.alloc = a,
.ns = @constCast(&[1]Namespace{
Namespace{
.name = @as([]u8, @constCast("one")),
@@ -252,7 +250,7 @@ test "default" {
};
 
const vtest = try Config(void).initDupe(a, "[one]\nleft = right");
defer vtest.raze();
defer vtest.raze(a);
 
try std.testing.expectEqualDeep(expected, vtest);
}
@@ -278,7 +276,7 @@ test "getBool" {
 
const a = std.testing.allocator;
const c = try Cfg.init(a, data);
defer c.raze();
defer c.raze(a);
const ns = c.get("test data").?;
 
try std.testing.expectEqual(true, ns.getBool("first").?);
@@ -306,7 +304,6 @@ test "commented" {
;
 
const expected = Config(void){
.alloc = a,
.ns = @constCast(&[1]Namespace{
Namespace{
.name = @as([]u8, @constCast("open")),
@@ -324,7 +321,7 @@ test "commented" {
};
 
const vtest = try Config(void).initDupe(a, vut);
defer vtest.raze();
defer vtest.raze(a);
 
try std.testing.expectEqualDeep(expected, vtest);
}
 
src/main.zig added: 20, removed: 17, total 3
@@ -75,6 +75,12 @@ pub const SrcConfig = struct {
sock: ?[]const u8,
remove_on_start: bool = false,
},
repos: ?struct {
/// Directory of public repos
repos: ?[]const u8,
/// Directory of private repos
private_repos: ?[]const u8,
},
};
 
// No, I don't like this
@@ -153,7 +159,7 @@ pub fn main() !void {
//error.FileNotFound => Ini.Config.empty(),
else => return e,
};
defer config.raze();
defer config.raze(a);
root_ini = config;
 
const src_conf = try config.config();