aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Spiers <git@adamspiers.org>2015-01-20 11:08:00 +0000
committerAdam Spiers <git@adamspiers.org>2015-01-20 11:20:37 +0000
commita2044bc1c6524248f2a67664c9b272c12f704296 (patch)
treefff21559cba54458cea7acf03db34fa9d7e10f87
parent474e2d6ac034801c79b9345e8ad4c6e2747e4a0c (diff)
downloadgit-deps-a2044bc1c6524248f2a67664c9b272c12f704296.tar.gz
track reverse dependencies (#16, #32, #35)
-rw-r--r--html/js/git-deps-data.coffee28
1 files changed, 24 insertions, 4 deletions
diff --git a/html/js/git-deps-data.coffee b/html/js/git-deps-data.coffee
index ae3816f..9034b18 100644
--- a/html/js/git-deps-data.coffee
+++ b/html/js/git-deps-data.coffee
@@ -10,12 +10,20 @@ links = []
# same node twice.
node_index = {}
-# Constraints will be added to try to keep siblings at the same y
-# position. For this we need to track siblings, which we do by
-# mapping each parent to an array of its siblings in this hash.
-# It also enables us to deduplicate links across multiple XHRs.
+# Track dependencies in a hash of hashes which maps parents to
+# children to booleans. Constraints will be added to try to keep
+# siblings at the same y position. For this we need to track
+# siblings, which we do by mapping each parent to an array of its
+# siblings in this hash. It also enables us to deduplicate links
+# across multiple XHRs.
deps = {}
+# Track dependences in reverse in a hash of hashes which maps children
+# to parents to booleans. This allows us to highlight parents when
+# the mouse hovers over a child, and know when we can safely remove
+# a commit due to its sole parent being deleted.
+rdeps = {}
+
# Returns 1 iff a node was added, otherwise 0.
add_node = (commit) ->
if commit.sha1 of node_index
@@ -38,6 +46,16 @@ add_dependency = (parent_sha1, child_sha1) ->
add_link parent_sha1, child_sha1
return 1
+# Returns 1 iff a reverse dependency was added, otherwise 0.
+add_rev_dependency = (child_sha1, parent_sha1) ->
+ rdeps[child_sha1] = {} unless child_sha1 of rdeps
+
+ # We've already got this link, presumably
+ # from a previous XHR.
+ return 0 if parent_sha1 of rdeps[child_sha1]
+ rdeps[child_sha1][parent_sha1] = true
+ return 1
+
add_link = (parent_sha1, child_sha1) ->
pi = node_index[parent_sha1]
ci = node_index[child_sha1]
@@ -58,6 +76,7 @@ add_data = (data) ->
for dep in data.dependencies
new_deps += add_dependency(dep.parent, dep.child)
+ add_rev_dependency(dep.child, dep.parent)
if new_nodes > 0 or new_deps > 0
return [
@@ -82,6 +101,7 @@ module.exports =
links: links
node_index: node_index
deps: deps
+ rdeps: rdeps
# Functions
add: add_data