From 1d6fdb9b8a17e6629a19bff1c93f32f6526af27d Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Wed, 18 Mar 2020 15:23:38 +0100 Subject: [PATCH] Basic Git object functionality --- main.gd | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.tscn | 4 +++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 main.gd diff --git a/main.gd b/main.gd new file mode 100644 index 0000000..f436dfc --- /dev/null +++ b/main.gd @@ -0,0 +1,72 @@ +extends Node2D + +func _ready(): + for o in all_objects(): + print(" ") + print(o) + var type = object_type(o) + print(type) + #print(object_content(o)) + match type: + "blob": + pass + "tree": + print("Children:") + print(tree_children(o)) + "commit": + print("Tree:") + print(commit_tree(o)) + + print("Parents:") + print(commit_parents(o)) + +func git(args, splitlines = false): + var output = [] + var a = args.split(" ") + a.insert(0, "-C") + a.insert(1, "/home/seb/tmp/godotgit") + #print ("Running: ", a) + OS.execute("git", a, true, output, true) + var o = output[0] + if splitlines: + o = o.split("\n") + o.remove(len(o)-1) + else: + o = o.substr(0,len(o)-1) + return o + +func all_objects(): + return git("cat-file --batch-check=%(objectname) --batch-all-objects", true) + +func object_type(id): + return git("cat-file -t "+id) + +func object_content(id): + return git("cat-file -p "+id) + +func tree_children(id): + var children = git("cat-file -p "+id, true) + var ids = [] + for c in children: + var a = c.split(" ") + ids.push_back(a[2].split("\t")[0]) + return ids + +func commit_tree(id): + var c = git("cat-file -p "+id, true) + for cc in c: + var ccc = cc.split(" ", 2) + match ccc[0]: + "tree": + return ccc[1] + return null + +func commit_parents(id): + var parents = [] + var c = git("cat-file -p "+id, true) + for cc in c: + var ccc = cc.split(" ", 2) + match ccc[0]: + "parent": + parents.push_back(ccc[1]) + return parents diff --git a/main.tscn b/main.tscn index f0ecde4..dda2ed6 100644 --- a/main.tscn +++ b/main.tscn @@ -1,8 +1,10 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://player.tscn" type="PackedScene" id=1] +[ext_resource path="res://main.gd" type="Script" id=2] [node name="Main" type="Node2D"] +script = ExtResource( 2 ) [node name="Player" parent="." instance=ExtResource( 1 )] position = Vector2( 960, 540 )