summary refs log tree commit diff
path: root/LibGitTest/Test1.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-06-05 03:25:53 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-06-05 03:25:53 +0200
commit51d820e22a4517dbb06d38a4f07f7c48522ef811 (patch)
tree4a7749cf77223dff2414fd4b73cb17df43d7449e /LibGitTest/Test1.cs
downloadGitTools-master.tar.xz
Initial commit HEAD master
Diffstat (limited to 'LibGitTest/Test1.cs')
-rw-r--r--LibGitTest/Test1.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/LibGitTest/Test1.cs b/LibGitTest/Test1.cs
new file mode 100644
index 0000000..ac88cf9
--- /dev/null
+++ b/LibGitTest/Test1.cs
@@ -0,0 +1,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);
+            }
+        }
+    }
+}
\ No newline at end of file