aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/git/Git.js
blob: 008fefc5913e011513874db8c9bca66858f56e6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

.pragma library

// Pure helpers for the git page, tested by test_git.js under node.

// `gitcfg list` (git config -z --list) into [{name, section, key, value}],
// in file order. The key is after the last dot, so a subsection stays in the
// section: color.branch.remote is section color.branch.
function parse(text) {
    return text.split("\0").filter(e => e !== "").map(e => {
        const nl = e.indexOf("\n");
        const name = nl < 0 ? e : e.slice(0, nl);
        const dot = name.lastIndexOf(".");
        return { name, section: name.slice(0, dot), key: name.slice(dot + 1),
                 value: nl < 0 ? "" : e.slice(nl + 1) };
    });
}