Show index, show refs and symrefs

This commit is contained in:
Sebastian Morr 2020-03-18 20:03:17 +01:00
parent 0059b7b196
commit 4e45330ad0
7 changed files with 183 additions and 36 deletions

View file

@ -7,9 +7,12 @@ func _ready():
pass
func _process(delta):
var t = get_node("../..").objects[target]
var t = get_node("/root/Main").objects[target]
#print(t)
$Line.points[1] = t.position - global_position
$Label.position = ($Line.points[0] + $Line.points[1])/2
$Tip.position = ($Line.points[0] + $Line.points[1])/2
$Tip.rotation = PI+$Line.points[0].angle_to($Line.points[1])
func label_set(new_label):
label = new_label

View file

@ -7,7 +7,17 @@ script = ExtResource( 1 )
[node name="Line" type="Line2D" parent="."]
z_index = -1
points = PoolVector2Array( -0.480499, -0.11055, 205.769, 94.6112 )
points = PoolVector2Array( -0.480499, -0.11055, 158.301, 0.581757 )
default_color = Color( 0.447059, 0.447059, 0.447059, 1 )
[node name="Tip" type="Node2D" parent="."]
position = Vector2( 149.835, 0.290878 )
[node name="Polygon" type="Polygon2D" parent="Tip"]
position = Vector2( -9.66138, -2.89842 )
z_index = -1
color = Color( 0.447059, 0.447059, 0.447059, 1 )
polygon = PoolVector2Array( -19.8744, 17.0372, 47.7551, 11.8845, -10.5351, -21.2861 )
[node name="Label" type="Node2D" parent="."]
position = Vector2( 102, 46 )

147
main.gd
View file

@ -4,43 +4,102 @@ var node = preload("res://node.tscn")
var objects = {}
var dragged = null
var viewport_size
func _ready():
viewport_size = get_viewport_rect().size
func _process(delta):
if Input.is_action_just_pressed("click"):
var mindist = 9999999
for o in objects.values():
var d = o.position.distance_to(get_global_mouse_position())
if d < mindist:
mindist = d
dragged = o
if Input.is_action_just_released("click"):
dragged = null
if dragged:
dragged.position = get_global_mouse_position()
update_head()
update_refs()
update_index()
update_objects()
apply_forces()
func update_index():
$Index.text = git("ls-files")
func update_objects():
for o in all_objects():
if objects.has(o):
continue
var n = node.instance()
n.id = o
n.type = object_type(o)
n.content = object_content(o)
var viewport_size = get_viewport_rect().size
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
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))
n.children = tree_children(o)
"commit":
print("Tree:")
print(commit_tree(o))
print("Parents:")
print(commit_parents(o))
n.children = [commit_tree(o)] + commit_parents(o)
if true:
#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))
n.children = tree_children(o)
"commit":
#print("Tree:")
#print(commit_tree(o))
#print("Parents:")
#print(commit_parents(o))
var c = {}
c[commit_tree(o)] = ""
for p in commit_parents(o):
c[p] = ""
n.children = c
add_child(n)
objects[o] = n
func update_refs():
for r in all_refs():
if not objects.has(r):
var n = node.instance()
n.id = r
n.type = "ref"
n.content = ""
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
objects[r] = n
add_child(n)
var n = objects[r]
n.children = {ref_id(r): ""}
func apply_forces():
for o in objects.values():
for o2 in objects.values():
if o == o2:
continue
var d = o.position.distance_to(o2.position)
var dir = (o.global_position - o2.global_position).normalized()
var f = 3000/pow(d+0.00001,1.5)
o.position += dir*f
o2.position -= dir*f
func git(args, splitlines = false):
var output = []
var a = args.split(" ")
a.insert(0, "-C")
a.insert(1, "/home/seb/wip/wurst-day-ever")
a.insert(1, "/home/seb/tmp/godotgit")
#print ("Running: ", a)
OS.execute("git", a, true, output, true)
var o = output[0]
@ -51,6 +110,26 @@ func git(args, splitlines = false):
o = o.substr(0,len(o)-1)
return o
func update_head():
if not objects.has("HEAD"):
var n = node.instance()
n.id = "HEAD"
n.type = "head"
n.content = ""
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
objects["HEAD"] = n
add_child(n)
n = node.instance()
n.id = "refs/heads/master"
n.type = "ref"
n.content = ""
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
objects[n.id] = n
add_child(n)
var n = objects["HEAD"]
n.children = {symref_target("HEAD"): ""}
func all_objects():
return git("cat-file --batch-check=%(objectname) --batch-all-objects", true)
@ -62,10 +141,10 @@ func object_content(id):
func tree_children(id):
var children = git("cat-file -p "+id, true)
var ids = []
var ids = {}
for c in children:
var a = c.split(" ")
ids.push_back(a[2].split("\t")[0])
ids[a[2].split("\t")[0]] = a[2].split("\t")[1]
return ids
func commit_tree(id):
@ -86,3 +165,21 @@ func commit_parents(id):
"parent":
parents.push_back(ccc[1])
return parents
func all_refs():
var refs = []
for line in git("show-ref", true):
line = line.split(" ")
var id = line[0]
var name = line[1]
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]

View file

@ -4,3 +4,24 @@
[node name="Main" type="Node2D"]
script = ExtResource( 2 )
[node name="Index" type="Label" parent="."]
margin_left = 35.0
margin_top = 120.0
margin_right = 374.0
margin_bottom = 1044.0
text = "file1
file2"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="IndexLabel" type="Label" parent="."]
margin_left = 38.0
margin_top = 69.0
margin_right = 377.0
margin_bottom = 108.0
text = "Index:"
__meta__ = {
"_edit_use_anchors_": false
}

27
node.gd
View file

@ -4,7 +4,7 @@ var id setget id_set
var content setget content_set
var type setget type_set
var children = [] setget children_set
var children = {} setget children_set
var arrow = preload("res://arrow.tscn")
@ -12,11 +12,11 @@ func _ready():
pass
func _process(delta):
for c in children:
for c in children.keys():
var other = get_node("..").objects[c]
var d = other.position.distance_to(position)
var dir = (other.position - position).normalized()
var f = ((d-400)*0.01)
var f = (d*0.05)
position += dir*f
other.position -= dir*f
@ -30,7 +30,8 @@ func content_set(new_content):
func type_set(new_type):
type = new_type
$ID.text = new_type + " " + $ID.text.substr(0,8)
if type != "ref":
$ID.text = $ID.text.substr(0,8)
match new_type:
"blob":
$Rect.color = Color.gray
@ -40,14 +41,22 @@ func type_set(new_type):
$Rect.color = Color.orange
"tag":
$Rect.color = Color.blue
"ref":
$Rect.color = Color("#6680ff")
"head":
$Rect.color = Color.red
func children_set(new_children):
for c in $Arrows.get_children():
if not new_children.has(c.target):
c.queue_free()
for c in new_children:
if not children.has(c):
var a = arrow.instance()
a.label = new_children[c]
a.target = c
$Arrows.add_child(a)
children = new_children
for c in children:
var a = arrow.instance()
a.label = "test"
a.target = c
add_child(a)
func _on_hover():
$Content.visible = true

View file

@ -46,5 +46,7 @@ __meta__ = {
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area"]
shape = SubResource( 1 )
[node name="Arrows" type="Node2D" parent="."]
[connection signal="mouse_entered" from="Area" to="." method="_on_hover"]
[connection signal="mouse_exited" from="Area" to="." method="_on_unhover"]

View file

@ -55,3 +55,8 @@ down={
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
]
}
click={
"deadzone": 0.5,
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
]
}