From patchwork Fri May 24 22:06:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Mostafa X-Patchwork-Id: 246295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id E7A192C0174 for ; Sat, 25 May 2013 08:07:06 +1000 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1Ug08a-0006ct-L3; Fri, 24 May 2013 22:07:00 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1Ug08U-0006cB-Rl for kernel-team@lists.ubuntu.com; Fri, 24 May 2013 22:06:54 +0000 Received: from c-67-160-231-42.hsd1.ca.comcast.net ([67.160.231.42] helo=fourier) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1Ug08U-0004d1-LX; Fri, 24 May 2013 22:06:54 +0000 Received: from kamal by fourier with local (Exim 4.80) (envelope-from ) id 1Ug08S-0004Wn-BS; Fri, 24 May 2013 15:06:52 -0700 From: Kamal Mostafa To: kernel-team@lists.ubuntu.com Subject: [kteam-tools][PATCH] ktl: Git.current_branch() optimization Date: Fri, 24 May 2013 15:06:48 -0700 Message-Id: <1369433208-17373-1-git-send-email-kamal@canonical.com> X-Mailer: git-send-email 1.8.1.2 Cc: Kamal Mostafa X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com Query 'git symbolic-ref HEAD' instead of iterating the 'git branch' list. Also changed behavior if current_branch() is called in a detached HEAD state: before: returned the string "(no branch)" now: throws an exception ktl.git.GetError GitError("no current branch") No existing caller depends on the old "(no branch)" behavior. Signed-off-by: Kamal Mostafa --- ktl/git.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/ktl/git.py b/ktl/git.py index 9483ad4..7b18275 100644 --- a/ktl/git.py +++ b/ktl/git.py @@ -94,17 +94,10 @@ class Git: # @classmethod def current_branch(cls): - retval = "" - status, result = run_command("git branch", cls.debug) - if status == 0: - for line in result: - if line != '' and line[0] == '*': - retval = line[1:].strip() - break - else: - raise GitError(result) - - return retval + status, result = run_command("git symbolic-ref --short HEAD", cls.debug) + if status != 0: + raise GitError("no current branch") + return result[0] # show #