summary refs log tree commit diff
path: root/LibGitTest/Test1.cs
blob: ac88cf9fd77d87d9cbdabdb312f70c06ae4382e4 (plain) (blame)
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
28
29
30
31
32
33
34
35
36
using LibGit;

namespace LibGitTest;

public class Test1
{
    public static async Task Run()
    {
        var repo = new GitRepo(new FileRepoSource(@"/home/root@Rory/tmpgit/MatrixRoomUtils.git"));
// var repo = new GitRepo(new WebRepoSource("https://git.rory.gay/MatrixRoomUtils.git/"));
        var commit = await repo.GetCommit("HEAD");

        while (commit.ParentIds.Count > 0)
        {
            Console.WriteLine($"{commit.CommitId[..7]} | {commit.AuthorName.PadRight(16)} | {commit.Message.PadRight(32)[..32]} | {commit.TreeId}");
            var tree = await commit.GetTreeAsync();
            await PrintTreeRecursive(tree);

            commit = await repo.GetCommit(commit.ParentIds.First());
        }

        async Task PrintTreeRecursive(TreeObject tree, int indent = 0)
        {
            foreach (var (key, value) in tree.Entries.Where(x => x.Value.Mode.StartsWith("1")))
            {
                Console.WriteLine($"{value.Mode.PadLeft(6)} {value.Hash}{"".PadRight(indent)} {key}");
            }

            foreach (var (key, value) in tree.Entries.Where(x => !x.Value.Mode.StartsWith("1")))
            {
                Console.WriteLine($"{value.Mode.PadLeft(6)}{"".PadRight(indent + 41)} {key + "/"}");
                await PrintTreeRecursive(new TreeObject(tree.RepoSource, value.Hash).ReadFromZlibCompressedObjFile(await tree.RepoSource.GetObjectStreamById(value.Hash)), indent + 2);
            }
        }
    }
}