Skip to contentSkip to conversation

devtool: upgrade: enable branch checking when revision is provided

PATCH New [email protected] 1 participant 2 messages Aug 17, 2017

lore
Share & tools
lore
#0 lore raw

cover devtool: upgrade: enable branch checking when revision is provided

From: Chang Rebecca Swee Fun <[email protected]>

This work has been similar to [YOCTO #11389] but this is mainly on devtool 'upgrade' subcommand. This feature is important for devtool as this will surely improve the usability of devtool and improve the quality of the recipe being changed.

Users might have input a revision/ commit hash to 'devtool upgrade' and the revision might not be on master branch. This will caused bitbake to fail in source fetching.

Regards,
Rebecca

The following changes since commit 55bf88603927469de9aa9f6fd4d449230d2e61e3:

poky: Add nios2 to list of qemu targets (2017-08-17 00:21:35 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib rebeccas/11484-wip
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=rebeccas/11484-wip

Chang Rebecca Swee Fun (1):
devtool: upgrade: enable branch checking when revision is provided

 scripts/lib/devtool/upgrade.py | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 devtool: upgrade: enable branch checking when revision is provided

From: Chang Rebecca Swee Fun <[email protected]>

When devtool upgrade is run on a recipe with revision specified that is not on master branch, and branch isn't set by --srcbranch or -B, then we should get the correct branch and append the branch to the URL.

If the revision was found on multiple branches, we will display error to inform user to provide a correct branch and exit.

[YOCTO #11484]

---
 scripts/lib/devtool/upgrade.py | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
scripts/lib/devtool/upgrade.py +23 -5
index f077f37..7adeab5 100644
@@ -180,7 +180,7 @@ def _get_uri(rd):
             srcuri = rev_re.sub('', srcuri)
     return srcuri, srcrev
 
-def _extract_new_source(newpv, srctree, no_patch, srcrev, branch, keep_temp, tinfoil, rd):
+def _extract_new_source(newpv, srctree, no_patch, srcrev, srcbranch, branch, keep_temp, tinfoil, rd):
     """Extract sources of a recipe with a new version"""
 
     def __run(cmd):
@@ -202,6 +202,24 @@ def _extract_new_source(newpv, srctree, no_patch, srcrev, branch, keep_temp, tin
         __run('git tag -f devtool-base-new')
         md5 = None
         sha256 = None
+        if not srcbranch:
+            check_branch, check_branch_err = __run('git branch -r --contains %s' % srcrev)
+            get_branch = [x.strip() for x in check_branch.splitlines()]
+            # Remove HEAD reference point and drop remote prefix
+            get_branch = [x.split('/', 1)[1] for x in get_branch if not x.startswith('origin/HEAD')]
+            if 'master' in get_branch:
+                # If it is master, we do not need to append 'branch=master' as this is default.
+                # Even with the case where get_branch has multiple objects, if 'master' is one
+                # of them, we should default take from 'master'
+                srcbranch = ''
+            elif len(get_branch) == 1:
+                # If 'master' isn't in get_branch and get_branch contains only ONE object, then store result into 'srcbranch'
+                srcbranch = get_branch[0]
+            else:
+                # If get_branch contains more than one objects, then display error and exit.
+                mbrch = '\n  ' + '\n  '.join(get_branch)
+                raise DevtoolError('Revision %s was found on multiple branches: %s\nPlease provide the correct branch in the devtool command with "--srcbranch" or "-B" option.' % (srcrev, mbrch))
+                sys.exit(1)
     else:
         __run('git checkout devtool-base -b devtool-%s' % newpv)
 
@@ -275,7 +293,7 @@ def _extract_new_source(newpv, srctree, no_patch, srcrev, branch, keep_temp, tin
         else:
             shutil.rmtree(tmpsrctree)
 
-    return (rev, md5, sha256)
+    return (rev, md5, sha256, srcbranch)
 
 def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, workspace, tinfoil, rd):
     """Creates the new recipe under workspace"""
@@ -374,10 +392,10 @@ def upgrade(args, config, basepath, workspace):
         rf = None
         try:
             rev1 = standard._extract_source(srctree, False, 'devtool-orig', False, rd, tinfoil)
-            rev2, md5, sha256 = _extract_new_source(args.version, srctree, args.no_patch,
-                                                    args.srcrev, args.branch, args.keep_temp,
+            rev2, md5, sha256, srcbranch = _extract_new_source(args.version, srctree, args.no_patch,
+                                                    args.srcrev, args.srcbranch, args.branch, args.keep_temp,
                                                     tinfoil, rd)
-            rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, args.srcbranch, config.workspace_path, tinfoil, rd)
+            rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, srcbranch, config.workspace_path, tinfoil, rd)
         except bb.process.CmdError as e:
             _upgrade_error(e, rf, srctree)
         except DevtoolError as e:
Signature · 1 line
2.7.4