From 37093aebe62fd16a19ad642b882fb31e70e1d992 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 4 Feb 2020 19:01:31 -0800 Subject: [PATCH] Reduce number of unnecessary subprocesses with better conditions. The code is a little uglier with more ifs and elses but saving some subprocess calls is worth it. --- gitcheckup.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gitcheckup.py b/gitcheckup.py index 9935b71..3864bf2 100644 --- a/gitcheckup.py +++ b/gitcheckup.py @@ -50,16 +50,23 @@ def checkup_pushed(): output = check_output(command) (my_head, remote_head) = output.strip().decode().splitlines() - command = [GIT, 'merge-base', '@', '@{u}'] - merge_base = check_output(command) - merge_base = merge_base.strip().decode() - if my_head == remote_head: to_push = 0 to_pull = 0 else: - to_push = len(git_commits_between(merge_base, my_head)) - to_pull = len(git_commits_between(merge_base, remote_head)) + command = [GIT, 'merge-base', '@', '@{u}'] + merge_base = check_output(command) + merge_base = merge_base.strip().decode() + + if my_head == merge_base: + to_push = 0 + to_pull = len(git_commits_between(merge_base, remote_head)) + elif remote_head == merge_base: + to_push = len(git_commits_between(merge_base, my_head)) + to_pull = 0 + else: + to_push = len(git_commits_between(merge_base, my_head)) + to_pull = len(git_commits_between(merge_base, remote_head)) pushed = (to_push, to_pull) == (0, 0) details = types.SimpleNamespace(