Properly support symrefs in refs/

This commit is contained in:
Sebastian Morr 2020-09-13 21:55:24 +02:00
parent 8a6f957c61
commit cb2bb767db
4 changed files with 41 additions and 23 deletions

View file

@ -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)

View file

@ -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"]

View file

@ -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

View file

@ -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