Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging (fixes #219) #222

Merged
merged 2 commits into from
Feb 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
log.txt
log.txt*
*.log
*.pot
*.pyc
Expand Down
7 changes: 3 additions & 4 deletions gitfs/merges/accept_mine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions gitfs/worker/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -37,6 +38,7 @@ def work(self):
self.fetch()

def fetch(self):
log.debug("Lock fetching operation")
with remote_operation:
fetch.clear()

Expand Down
21 changes: 14 additions & 7 deletions gitfs/worker/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -147,6 +153,7 @@ def sync(self):
log.exception("Push failed")
return False
else:
log.debug("Sync done, clearing")
sync_done.set()
syncing.clear()

Expand Down