From 237de3f58ee118221a5609e56fa0e1714d401920 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sun, 3 Sep 2017 15:23:11 -0700 Subject: [PATCH] Refactoring: exctract _redirect_edges() --- dvc/workflow.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dvc/workflow.py b/dvc/workflow.py index 349fd34d7..93098d06d 100644 --- a/dvc/workflow.py +++ b/dvc/workflow.py @@ -129,13 +129,8 @@ class Workflow(object): self._commits[hash].remove_parent(commit.hash) pass - for hash in parent_commit_hashes: - self._edges[hash].remove(commit.hash) - self._edges[hash] |= child_commit_hashes - - for hash in child_commit_hashes: - self._back_edges[hash].remove(commit.hash) - self._back_edges[hash] |= parent_commit_hashes + self._redirect_edges(self._edges, child_commit_hashes, commit.hash, parent_commit_hashes) + self._redirect_edges(self._back_edges, parent_commit_hashes, commit.hash, child_commit_hashes) hashes_to_remove.append(commit.hash) else: @@ -146,3 +141,9 @@ class Workflow(object): del self._edges[hash] del self._back_edges[hash] pass + + @staticmethod + def _redirect_edges(edges, child_commit_hashes, hash, commit_hashes): + for h in commit_hashes: + edges[h].remove(hash) + edges[h] |= child_commit_hashes