From cb2bb767db79f97d25be9da4a151592ff3297aaf Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Sun, 13 Sep 2020 21:55:24 +0200 Subject: [PATCH] Properly support symrefs in refs/ --- main.gd | 7 +++++-- main.tscn | 21 ++++++++++++++++----- node.gd | 6 ++---- repository.gd | 30 ++++++++++++++++++------------ 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/main.gd b/main.gd index bf5102e..8eb5804 100644 --- a/main.gd +++ b/main.gd @@ -85,6 +85,9 @@ func load_level(id): var dir = Directory.new() dir.copy(win_script, win_script_target) +func reload_level(): + load_level(current_level) + func load_next_level(): current_level = (current_level + 1) % list_levels().size() load_level(current_level) @@ -93,8 +96,8 @@ func construct_repo(script, path): # Becase in an exported game, all assets are in a .pck file, we need to put # the script somewhere in the filesystem. var content = "" - if ResourceLoader.exists(script): - content = game.read_file(script) + #if ResourceLoader.exists(script): + content = game.read_file(script) var script_path_outside = game.tmp_prefix+"/git-hydra-script" var script_path = "/tmp/git-hydra-script" game.write_file(script_path_outside, content) diff --git a/main.tscn b/main.tscn index 449d3e7..39c7f85 100644 --- a/main.tscn +++ b/main.tscn @@ -118,11 +118,10 @@ __meta__ = { } [node name="NextLevelButton" type="Button" parent="."] -visible = false -margin_left = 1403.0 -margin_top = 16.0 -margin_right = 1621.0 -margin_bottom = 47.0 +margin_left = 1688.03 +margin_top = 16.2615 +margin_right = 1906.03 +margin_bottom = 47.2615 custom_styles/hover = SubResource( 1 ) custom_styles/normal = ExtResource( 4 ) custom_fonts/font = ExtResource( 5 ) @@ -130,5 +129,17 @@ text = "Next Level" __meta__ = { "_edit_use_anchors_": false } + +[node name="ReloadButton" type="Button" parent="."] +margin_left = 1400.72 +margin_top = 16.2615 +margin_right = 1545.72 +margin_bottom = 47.2615 +custom_fonts/font = ExtResource( 5 ) +text = "Reload" +__meta__ = { +"_edit_use_anchors_": false +} [connection signal="pressed" from="TextEditor/SaveButton" to="." method="save_message"] [connection signal="pressed" from="NextLevelButton" to="." method="load_next_level"] +[connection signal="pressed" from="ReloadButton" to="." method="reload_level"] diff --git a/node.gd b/node.gd index 766ab8a..29e4022 100644 --- a/node.gd +++ b/node.gd @@ -39,9 +39,8 @@ func type_set(new_type): type = new_type if type != "ref": $ID.text = $ID.text.substr(0,8) - elif type == "ref": - var parts = $ID.text.split("/") - $ID.text = parts[parts.size()-1] + #elif type == "ref": + #$ID.text = $ID.text.replace("refs/", "") match new_type: "blob": $Rect.color = Color("#333333") @@ -51,7 +50,6 @@ func type_set(new_type): $Rect.color = Color.orange "tag": $Rect.color = Color.blue - id_always_visible = true "ref": $Rect.color = Color("#6680ff") id_always_visible = true diff --git a/repository.gd b/repository.gd index 5da5de7..ecb0081 100644 --- a/repository.gd +++ b/repository.gd @@ -78,6 +78,9 @@ func update_objects(): for p in commit_parents(o): c[p] = "" n.children = c + "tag": + print("tag") + n.children = tag_target(o) add_child(n) objects[o] = n @@ -93,7 +96,7 @@ func update_refs(): objects[r] = n add_child(n) var n = objects[r] - n.children = {ref_id(r): ""} + n.children = {ref_target(r): ""} func apply_forces(): for o in objects.values(): @@ -134,10 +137,10 @@ func update_head(): objects["HEAD"] = n add_child(n) var n = objects["HEAD"] - n.children = {symref_target("HEAD"): ""} - if not objects.has(symref_target("HEAD")): + n.children = {ref_target("HEAD"): ""} + if not objects.has(ref_target("HEAD")): var n2 = node.instance() - var r = symref_target("HEAD") + var r = ref_target("HEAD") n2.id = r n2.type = "ref" n2.content = "" @@ -182,6 +185,10 @@ func commit_parents(id): parents.push_back(ccc[1]) return parents +func tag_target(id): + var c = git("rev-parse %s^{}" % id) + return {c: ""} + func all_refs(): var refs = [] # If there are no refs, show-ref will have exit code 1. We don't care. @@ -192,11 +199,10 @@ func all_refs(): refs.push_back(name) return refs -func ref_id(ref): - return git("show-ref "+ref).split(" ")[0] - -func symref_target(symref): - var ret = git("symbolic-ref -q "+symref) - if ret != "": - return ret - return git("show-ref --head "+symref).split(" ")[0] +func ref_target(ref): + # Test whether this is a symbolic ref. + var ret = git("symbolic-ref -q "+ref+" || true") + # If it's not, it's probably a regular ref. + if ret == "": + ret = git("show-ref --head "+ref).split(" ")[0] + return ret