summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2018-04-06 23:27:00 +1200
committerPaul Eggleton <paul.eggleton@linux.intel.com>2018-05-04 23:57:53 +1200
commit7343484695f264d68d5b5ed8900a0786d755a2ff (patch)
tree1ae54d2dfd5ff95f77e508f87c784b0a79aa48fc
parent009adcb8df8dabf5b459a98f35f3d1a829449a36 (diff)
downloadopenembedded-core-contrib-7343484695f264d68d5b5ed8900a0786d755a2ff.tar.gz
openembedded-core-contrib-7343484695f264d68d5b5ed8900a0786d755a2ff.tar.bz2
openembedded-core-contrib-7343484695f264d68d5b5ed8900a0786d755a2ff.zip
utils: add common function to check out a specific git revision
Checking out a revision in the bitbake/layer repositories is something we are doing in a few places, so add a checkout_repo() function that does this, ensuring that we don't get tripped up by any junk files, and avoids checking out if the repository is already at the desired revision (thus avoiding the clean operation and e.g. preserving any .pyc files that aren't stale and would speed things up a little). Note that we do the clean before checking out in case there are untracked files that are tracked in the commit we are checking out. In addition to adding this function, change the existing code that we use in the update script to check out a layer use the new function. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
-rw-r--r--layerindex/recipeparse.py6
-rw-r--r--layerindex/utils.py28
2 files changed, 26 insertions, 8 deletions
diff --git a/layerindex/recipeparse.py b/layerindex/recipeparse.py
index f211cfac4a..f1c1bd3246 100644
--- a/layerindex/recipeparse.py
+++ b/layerindex/recipeparse.py
@@ -31,8 +31,7 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
else:
# Branch name
bitbake_ref = 'origin/%s' % branch.bitbake_branch
- out = utils.runcmd("git checkout %s" % bitbake_ref, bitbakepath, logger=logger)
- out = utils.runcmd("git clean -f -x", bitbakepath, logger=logger)
+ utils.checkout_repo(bitbakepath, bitbake_ref, logger=logger)
# Skip sanity checks
os.environ['BB_ENV_EXTRAWHITE'] = 'DISABLE_SANITY_CHECKS'
@@ -57,8 +56,7 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout
core_repodir = os.path.join(fetchdir, core_urldir)
core_layerdir = os.path.join(core_repodir, core_subdir)
if not nocheckout:
- out = utils.runcmd("git checkout origin/%s" % core_branchname, core_repodir, logger=logger)
- out = utils.runcmd("git clean -f -x", core_repodir, logger=logger)
+ utils.checkout_repo(core_repodir, "origin/%s" % core_branchname, logger=logger)
if not os.path.exists(os.path.join(core_layerdir, 'conf/bitbake.conf')):
raise RecipeParseError("conf/bitbake.conf not found in core layer %s - is subdirectory set correctly?" % core_layer.name)
# The directory above where this script exists should contain our conf/layer.conf,
diff --git a/layerindex/utils.py b/layerindex/utils.py
index 14dbeb6e62..f8c5fd4560 100644
--- a/layerindex/utils.py
+++ b/layerindex/utils.py
@@ -206,14 +206,34 @@ def explode_dep_versions2(bitbakepath, deps):
import bb.utils
return bb.utils.explode_dep_versions2(deps)
-def checkout_layer_branch(layerbranch, repodir, logger=None):
+def checkout_repo(repodir, commit, logger, force=False):
+ """
+ Check out a revision in a repository, ensuring that untracked/uncommitted
+ files don't get in the way.
+ WARNING: this will throw away any untracked/uncommitted files in the repo,
+ so it is only suitable for use with repos where you don't care about such
+ things (which we don't for the layer repos that we use)
+ """
+ if force:
+ currentref = ''
+ else:
+ currentref = runcmd("git rev-parse HEAD", repodir, logger=logger).strip()
+ if currentref != commit:
+ # Reset in case there are added but uncommitted changes
+ runcmd("git reset --hard HEAD", repodir, logger=logger)
+ # Drop any untracked files in case these cause problems (either because
+ # they will exist in the revision we're checking out, or will otherwise
+ # interfere with operation, e.g. stale pyc files)
+ runcmd("git clean -qdfx", repodir, logger=logger)
+ # Now check out the revision
+ runcmd("git checkout %s" % commit,
+ repodir, logger=logger)
+def checkout_layer_branch(layerbranch, repodir, logger=None):
branchname = layerbranch.branch.name
if layerbranch.actual_branch:
branchname = layerbranch.actual_branch
-
- out = runcmd("git checkout origin/%s" % branchname, repodir, logger=logger)
- out = runcmd("git clean -f -x", repodir, logger=logger)
+ checkout_repo(repodir, 'origin/%s' % branchname, logger)
def is_layer_valid(layerdir):
conf_file = os.path.join(layerdir, "conf", "layer.conf")