From b1630354181cfa4d77b4c4e009fa44a76396c9a9 Mon Sep 17 00:00:00 2001 From: Vlad Temian Date: Thu, 18 Feb 2016 17:40:25 +0200 Subject: [PATCH 1/2] Improve logging in sync/fetch workers and accept mine strategy. --- gitfs/merges/accept_mine.py | 7 +++---- gitfs/worker/fetch.py | 2 ++ gitfs/worker/sync.py | 21 ++++++++++++++------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/gitfs/merges/accept_mine.py b/gitfs/merges/accept_mine.py index fb49e62a..912286f2 100644 --- a/gitfs/merges/accept_mine.py +++ b/gitfs/merges/accept_mine.py @@ -35,9 +35,7 @@ def _create_remote_copy(self, branch_name, upstream, new_branch): def _create_local_copy(self, branch_name, new_branch): branch = self.repository.lookup_branch(branch_name, pygit2.GIT_BRANCH_LOCAL) - branch_commit = branch.get_object() - return self.repository.create_branch(new_branch, branch_commit) def merge(self, local_branch, remote_branch, upstream): @@ -90,13 +88,14 @@ def merge(self, local_branch, remote_branch, upstream): force=True) def clean_up(self, local_branch): + log.debug("AcceptMine: Checkout force to branch %s", local_branch) self.repository.checkout("refs/heads/%s" % local_branch, strategy=pygit2.GIT_CHECKOUT_FORCE) refs = [(target, "refs/heads/" + target) for target in ["merging_local", "merging_remote"]] for branch, ref in refs: - log.debug("AcceptMine: Delete %s" % branch) + log.debug("AcceptMine: Delete %s", branch) self.repository.lookup_reference(ref).delete() def __call__(self, local_branch, remote_branch, upstream): @@ -110,7 +109,7 @@ def __call__(self, local_branch, remote_branch, upstream): def solve_conflicts(self, conflicts): if conflicts: - for common, theirs, ours in conflicts: + for _, theirs, ours in conflicts: if not ours and theirs: log.debug("AcceptMine: if we deleted the file and they " "didn't, remove the file") diff --git a/gitfs/worker/fetch.py b/gitfs/worker/fetch.py index 859d21dd..e8f73f17 100644 --- a/gitfs/worker/fetch.py +++ b/gitfs/worker/fetch.py @@ -28,6 +28,7 @@ def work(self): if idle.is_set(): timeout = self.idle_timeout + log.debug("Wait for %s" % timeout) fetch.wait(timeout) if shutting_down.is_set(): @@ -37,6 +38,7 @@ def work(self): self.fetch() def fetch(self): + log.debug("Lock fetching operation") with remote_operation: fetch.clear() diff --git a/gitfs/worker/sync.py b/gitfs/worker/sync.py index 3e5098f7..0887e3bc 100644 --- a/gitfs/worker/sync.py +++ b/gitfs/worker/sync.py @@ -90,17 +90,20 @@ def on_idle(self): self.commits = [] count = 0 - log.debug("Start syncing") - while not self.sync(): - if count < 5: - count += 1 - + log.debug("Start syncing, first attempt.") + while not self.sync() and count < 5: fuzz = random.randint(0, 1000) / 1000 wait = 2 ** count + fuzz - log.debug("Failed. Going to sleep for %d seconds", wait) + log.debug("Failed to sync. Going to sleep for %d seconds", wait) time.sleep(wait) - log.debug("Retry-ing") + + count += 1 + log.debug("Retry-ing to sync with remote. Attempt #%d", count) + + if count >= 5: + log.debug("Didn't manage to sync, I need some help") + def merge(self): log.debug("Start merging") @@ -122,7 +125,10 @@ def sync(self): try: log.debug("Start fetching") self.repository.fetch(self.upstream, self.branch) + log.debug("Done fetching") + log.debug("Start merging") self.merge() + log.debug("Merge done with success, ready to push") need_to_push = True except: log.exception("Merge failed") @@ -147,6 +153,7 @@ def sync(self): log.exception("Push failed") return False else: + log.debug("Sync done, clearing") sync_done.set() syncing.clear() From 61e650adc6bfafe35698b3dc4be9c880ec8fcf85 Mon Sep 17 00:00:00 2001 From: Vlad Temian Date: Thu, 18 Feb 2016 17:40:37 +0200 Subject: [PATCH 2/2] Ignore tests logging. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 838b090b..7f545b65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -log.txt +log.txt* *.log *.pot *.pyc