mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-20 16:20:18 +01:00
Cache various shell commands in the repo
This commit is contained in:
parent
fe97283ddb
commit
80c50bdc81
2 changed files with 18 additions and 13 deletions
|
@ -55,7 +55,7 @@ func update():
|
||||||
var head_files
|
var head_files
|
||||||
var index_files
|
var index_files
|
||||||
|
|
||||||
if repository.there_is_a_git():
|
if repository.there_is_a_git_cache:
|
||||||
# Files in the HEAD commit.
|
# Files in the HEAD commit.
|
||||||
head_files = Array(repository.shell.run("git ls-tree --name-only -r HEAD 2> /dev/null || true").split("\n"))
|
head_files = Array(repository.shell.run("git ls-tree --name-only -r HEAD 2> /dev/null || true").split("\n"))
|
||||||
# The last entry is an empty string, remove it.
|
# The last entry is an empty string, remove it.
|
||||||
|
@ -116,7 +116,7 @@ func update():
|
||||||
grid.add_child(item)
|
grid.add_child(item)
|
||||||
FileBrowserMode.INDEX:
|
FileBrowserMode.INDEX:
|
||||||
#var is_visible = false
|
#var is_visible = false
|
||||||
if repository and repository.there_is_a_git():
|
if repository and repository.there_is_a_git_cache:
|
||||||
|
|
||||||
var deleted_files = Array(repository.shell.run("git status -s | grep '^D' | sed 's/^...//'").split("\n"))
|
var deleted_files = Array(repository.shell.run("git status -s | grep '^D' | sed 's/^...//'").split("\n"))
|
||||||
# The last entries are empty strings, remove them.
|
# The last entries are empty strings, remove them.
|
||||||
|
|
|
@ -18,6 +18,11 @@ var shell = Shell.new()
|
||||||
var objects = {}
|
var objects = {}
|
||||||
var mouse_inside = false
|
var mouse_inside = false
|
||||||
|
|
||||||
|
# Used for caching.
|
||||||
|
var all_objects_cache
|
||||||
|
var all_refs_cache
|
||||||
|
var there_is_a_git_cache
|
||||||
|
|
||||||
# We use this for a heuristic of when to hide trees and blobs.
|
# We use this for a heuristic of when to hide trees and blobs.
|
||||||
var _commit_count = 0
|
var _commit_count = 0
|
||||||
|
|
||||||
|
@ -46,8 +51,8 @@ func there_is_a_git():
|
||||||
return shell.run("test -d .git && echo yes || echo no") == "yes\n"
|
return shell.run("test -d .git && echo yes || echo no") == "yes\n"
|
||||||
|
|
||||||
func update_everything():
|
func update_everything():
|
||||||
print("update_everything()")
|
there_is_a_git_cache = there_is_a_git()
|
||||||
if there_is_a_git():
|
if there_is_a_git_cache:
|
||||||
update_head()
|
update_head()
|
||||||
update_refs()
|
update_refs()
|
||||||
update_objects()
|
update_objects()
|
||||||
|
@ -84,10 +89,10 @@ func random_position():
|
||||||
return Vector2(rand_range(0, rect_size.x), rand_range(0, rect_size.y))
|
return Vector2(rand_range(0, rect_size.x), rand_range(0, rect_size.y))
|
||||||
|
|
||||||
func update_objects():
|
func update_objects():
|
||||||
var all = all_objects()
|
all_objects_cache = all_objects()
|
||||||
|
|
||||||
# Create new objects, if necessary.
|
# Create new objects, if necessary.
|
||||||
for o in all:
|
for o in all_objects_cache:
|
||||||
if objects.has(o):
|
if objects.has(o):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -127,7 +132,7 @@ func update_objects():
|
||||||
objects[o] = n
|
objects[o] = n
|
||||||
|
|
||||||
func update_node_positions():
|
func update_node_positions():
|
||||||
if there_is_a_git():
|
if there_is_a_git_cache:
|
||||||
var graph_text = shell.run("git log --graph --oneline --all --no-abbrev")
|
var graph_text = shell.run("git log --graph --oneline --all --no-abbrev")
|
||||||
var graph_lines = Array(graph_text.split("\n"))
|
var graph_lines = Array(graph_text.split("\n"))
|
||||||
graph_lines.pop_back()
|
graph_lines.pop_back()
|
||||||
|
@ -141,7 +146,7 @@ func update_node_positions():
|
||||||
var regex_match = hash_regex.search(line)
|
var regex_match = hash_regex.search(line)
|
||||||
objects[regex_match.get_string()].position = Vector2((graph_lines.size()-line_count) * 100 + 500, star_idx * 100 + 500)
|
objects[regex_match.get_string()].position = Vector2((graph_lines.size()-line_count) * 100 + 500, star_idx * 100 + 500)
|
||||||
|
|
||||||
for ref in all_refs():
|
for ref in all_refs_cache:
|
||||||
var target_reference = objects[ref].children.keys()[0]
|
var target_reference = objects[ref].children.keys()[0]
|
||||||
var target = objects[target_reference]
|
var target = objects[target_reference]
|
||||||
objects[ref].position = Vector2(target.position.x ,target.position.y - 100)
|
objects[ref].position = Vector2(target.position.x ,target.position.y - 100)
|
||||||
|
@ -152,7 +157,8 @@ func update_node_positions():
|
||||||
objects["HEAD"].position = Vector2(target.position.x ,target.position.y - 100)
|
objects["HEAD"].position = Vector2(target.position.x ,target.position.y - 100)
|
||||||
|
|
||||||
func update_refs():
|
func update_refs():
|
||||||
for r in all_refs():
|
all_refs_cache = all_refs()
|
||||||
|
for r in all_refs_cache:
|
||||||
if not objects.has(r):
|
if not objects.has(r):
|
||||||
var n = node.instance()
|
var n = node.instance()
|
||||||
n.id = r
|
n.id = r
|
||||||
|
@ -311,11 +317,10 @@ func set_editable_path(editable):
|
||||||
path_node.visible = editable
|
path_node.visible = editable
|
||||||
|
|
||||||
func remove_gone_stuff():
|
func remove_gone_stuff():
|
||||||
# FIXME: Cache the result of all_objects.
|
|
||||||
var all = {}
|
var all = {}
|
||||||
for o in all_objects():
|
for o in all_objects_cache:
|
||||||
all[o] = ""
|
all[o] = ""
|
||||||
for o in all_refs():
|
for o in all_refs_cache:
|
||||||
all[o] = ""
|
all[o] = ""
|
||||||
all["HEAD"] = ""
|
all["HEAD"] = ""
|
||||||
# Delete objects, if they disappeared.
|
# Delete objects, if they disappeared.
|
||||||
|
|
Loading…
Reference in a new issue