Skip to contentSkip to conversation

combo-tool: simply branch/commit validation logic

PATCH In review Ross Burton 2 participants 3 messages Nov 18, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 combo-tool: simply branch/commit validation logic

Simply the branch/revision logic by using git-merge-base.

---
 scripts/combo-layer |   13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
scripts/combo-layer +2 -11
index ae97471..2c8ba07 100755
@@ -283,23 +283,14 @@ def drop_to_shell(workdir=None):
 
 def check_rev_branch(component, repodir, rev, branch):
     try:
-        actualbranch = runcmd("git branch --contains %s" % rev, repodir, printerr=False)
+        mergepoint = runcmd("git merge-base %s %s" % (rev, branch), repodir, printerr=False).rstrip()
     except subprocess.CalledProcessError as e:
         if e.returncode == 129:
             actualbranch = ""
         else:
             raise
 
-    if not actualbranch:
-        logger.error("%s: specified revision %s is invalid!" % (component, rev))
-        return False
-
-    branches = []
-    branchlist = actualbranch.split("\n")
-    for b in branchlist:
-        branches.append(b.strip().split(' ')[-1])
-
-    if branch not in branches:
+    if mergepoint != rev:
         logger.error("%s: specified revision %s is not on specified branch %s!" % (component, rev, branch))
         return False
     return True
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 1 line · Ross Burton

Simply the branch/revision logic by using git-merge-base.

Did you mean 'simplify'?

Quoted 37 lines
---
  scripts/combo-layer |   13 ++-----------
  1 file changed, 2 insertions(+), 11 deletions(-)
scripts/combo-layer +2 -11
index ae97471..2c8ba07 100755
@@ -283,23 +283,14 @@ def drop_to_shell(workdir=None):
 
  def check_rev_branch(component, repodir, rev, branch):
      try:
-        actualbranch = runcmd("git branch --contains %s" % rev, repodir, printerr=False)
+        mergepoint = runcmd("git merge-base %s %s" % (rev, branch), repodir, printerr=False).rstrip()
      except subprocess.CalledProcessError as e:
          if e.returncode == 129:
              actualbranch = ""
          else:
              raise
 
-    if not actualbranch:
-        logger.error("%s: specified revision %s is invalid!" % (component, rev))
-        return False
-
-    branches = []
-    branchlist = actualbranch.split("\n")
-    for b in branchlist:
-        branches.append(b.strip().split(' ')[-1])
-
-    if branch not in branches:
+    if mergepoint != rev:
          logger.error("%s: specified revision %s is not on specified branch %s!" % (component, rev, branch))
          return False
      return True
Signature · 4 lines
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
#2 lore raw
Quoted 5 lines · Gary Thomas
Quoted 2 lines · Ross Burton

Simply the branch/revision logic by using git-merge-base.

Did you mean 'simplify'?

Yes. :)

Ross