From 05622c425f532dc3767105ff75c463483a7acf88 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sun, 8 Sep 2019 15:14:19 +0100 Subject: More bugfixes * backend : * make sync more reliable and future proof (in case we will have more branches) * while the bugfix commit 12c2d64d475552f7ccfb078613a8fbfcea1efaba fixed a long stading bug * it also slowed us down considerably triggering metadata refresh when it wasn't actually * needed. Rework the code to trigger metadata refresh only when absolutely needed * this will speed up things considerably, specially dependency resolution --- src/backend/libsisyphus.py | 78 ++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/src/backend/libsisyphus.py b/src/backend/libsisyphus.py index 8af5bf7..5ce9129 100644 --- a/src/backend/libsisyphus.py +++ b/src/backend/libsisyphus.py @@ -180,38 +180,59 @@ def syncLocalDatabase(): sisyphusdb.commit() sisyphusdb.close() +def checkPortageTree(): + os.chdir(gentooEbuildDir) + needsPortageTreeSync = int() + + localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + localHash = subprocess.check_output(['git', 'rev-parse', '@']) + remoteHash = subprocess.check_output(['git', 'rev-parse', '@{u}']) + + subprocess.call(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet']) + + if not localHash.decode().strip() == remoteHash.decode().strip(): + needsPortageTreeSync = int(1) + + return needsPortageTreeSync + +def checkOverlayTree(): + os.chdir(redcoreEbuildDir) + needsOverlayTreeSync = int() + + localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + localHash = subprocess.check_output(['git', 'rev-parse', '@']) + remoteHash = subprocess.check_output(['git', 'rev-parse', '@{u}']) + + subprocess.call(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet']) + + if not localHash.decode().strip() == remoteHash.decode().strip(): + needsOverlayTreeSync = int(1) + + return needsOverlayTreeSync + def syncPortageTree(): os.chdir(gentooEbuildDir) - currentBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) - if currentBranch.decode().strip() is 'master': - subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'master', '--quiet']) - subprocess.call(['git', 'reset', '--hard', 'origin/master', '--quiet']) - elif currentBranch.decode().strip() is 'next': - subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'next', '--quiet']) - subprocess.call(['git', 'reset', '--hard', 'origin/next', '--quiet']) + subprocess.call(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet']) + subprocess.call(['git', 'reset', '--hard'] + remoteBranch.decode().strip().replace('refs/remotes/','').split() + ['--quiet']) def syncOverlayTree(): os.chdir(redcoreEbuildDir) - currentBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) - if currentBranch.decode().strip() is 'master': - subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'master', '--quiet']) - subprocess.call(['git', 'reset', '--hard', 'origin/master', '--quiet']) - elif currentBranch.decode().strip() is 'next': - subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'next', '--quiet']) - subprocess.call(['git', 'reset', '--hard', 'origin/next', '--quiet']) + subprocess.call(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet']) + subprocess.call(['git', 'reset', '--hard'] + remoteBranch.decode().strip().replace('refs/remotes/','').split() + ['--quiet']) def syncPortageCfg(): os.chdir(portageConfigDir) - currentBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) - if currentBranch.decode().strip() is 'master': - subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'master', '--quiet']) - subprocess.call(['git', 'reset', '--hard', 'origin/master', '--quiet']) - elif currentBranch.decode().strip() is 'next': - subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'next', '--quiet']) - subprocess.call(['git', 'reset', '--hard', 'origin/next', '--quiet']) + subprocess.call(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet']) + subprocess.call(['git', 'reset', '--hard'] + remoteBranch.decode().strip().replace('refs/remotes/','').split() + ['--quiet']) def syncPortageMtd(): if os.path.isdir(portageMetadataDir): @@ -239,11 +260,16 @@ def cleanCacheDir(): def startUpdate(): checkRoot() cleanCacheDir() - syncPortageTree() - syncOverlayTree() - syncPortageCfg() - syncPortageMtd() - syncRemoteDatabase() + + needsPortageTreeSync = checkPortageTree() + needsOverlayTreeSync = checkOverlayTree() + + if (needsPortageTreeSync == 1) or (needsOverlayTreeSync == 1): + syncPortageTree() + syncOverlayTree() + syncPortageCfg() + syncPortageMtd() + syncRemoteDatabase() @animation.wait('syncing spm changes') def startSyncSPM(): -- cgit v1.2.3