Skip to content

Commit 3bf6302

Browse files
committed
Pass all SCM commands+params to Repo than directly to Repo.scm
1 parent 0863d4f commit 3bf6302

File tree

1 file changed

+60
-61
lines changed

1 file changed

+60
-61
lines changed

mbed/mbed.py

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -315,21 +315,9 @@ def update(rev=None, clean=False, is_local=False):
315315
shutil.rmtree(fl)
316316
return Bld.checkout(rev)
317317

318-
def status():
319-
return False
320-
321-
def dirty():
322-
return False
323-
324318
def untracked():
325319
return ""
326320

327-
def outgoing():
328-
return False
329-
330-
def isdetached():
331-
return False
332-
333321
def seturl(url):
334322
if not os.path.exists('.'+Bld.name):
335323
os.mkdir('.'+Bld.name)
@@ -356,14 +344,6 @@ def getrev():
356344
def getbranch():
357345
return "default"
358346

359-
def ignores():
360-
return True
361-
362-
def ignore(dest):
363-
return True
364-
365-
def unignore(dest):
366-
return True
367347

368348
# pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use, unused-argument
369349
@scm('hg')
@@ -448,9 +428,6 @@ def outgoing():
448428
raise e
449429
return 0
450430

451-
def isdetached():
452-
return False
453-
454431
def geturl():
455432
tagpaths = '[paths]'
456433
default_url = ''
@@ -939,30 +916,53 @@ def getscm(self):
939916
if os.path.isdir(os.path.join(self.path, '.'+name)):
940917
return scm
941918

942-
def getrev(self):
943-
if self.scm:
919+
# Pass backend SCM commands and parameters if SCM exists
920+
def __scm_call(self, method, *args, **kwargs):
921+
if self.scm and hasattr(self.scm, method) and callable(getattr(self.scm, method)):
944922
with cd(self.path):
945-
return self.scm.getrev()
923+
return getattr(self.scm, method)(*args, **kwargs)
946924

947-
def geturl(self):
948-
if self.scm:
949-
with cd(self.path):
950-
return self.scm.geturl().strip().replace('\\', '/')
925+
def geturl(self, *args, **kwargs):
926+
return self.__scm_call('geturl', *args, **kwargs)
951927

952-
def ignores(self):
953-
if self.scm:
954-
with cd(self.path):
955-
return self.scm.ignores()
928+
def getrev(self, *args, **kwargs):
929+
return self.__scm_call('getrev', *args, **kwargs)
956930

957-
def ignore(self, dest):
958-
if self.scm:
959-
with cd(self.path):
960-
return self.scm.ignore(dest)
931+
def add(self, *args, **kwargs):
932+
return self.__scm_call('add', *args, **kwargs)
961933

962-
def unignore(self, dest):
963-
if self.scm:
964-
with cd(self.path):
965-
return self.scm.unignore(dest)
934+
def remove(self, *args, **kwargs):
935+
return self.__scm_call('remove', *args, **kwargs)
936+
937+
def ignores(self, *args, **kwargs):
938+
return self.__scm_call('ignores', *args, **kwargs)
939+
940+
def ignore(self, *args, **kwargs):
941+
return self.__scm_call('ignore', *args, **kwargs)
942+
943+
def unignore(self, *args, **kwargs):
944+
return self.__scm_call('unignore', *args, **kwargs)
945+
946+
def status(self, *args, **kwargs):
947+
return self.__scm_call('status', *args, **kwargs)
948+
949+
def dirty(self, *args, **kwargs):
950+
return self.__scm_call('dirty', *args, **kwargs)
951+
952+
def commit(self, *args, **kwargs):
953+
return self.__scm_call('commit', *args, **kwargs)
954+
955+
def outgoing(self, *args, **kwargs):
956+
return self.__scm_call('outgoing', *args, **kwargs)
957+
958+
def publish(self, *args, **kwargs):
959+
return self.__scm_call('publish', *args, **kwargs)
960+
961+
def update(self, *args, **kwargs):
962+
return self.__scm_call('update', *args, **kwargs)
963+
964+
def isdetached(self, *args, **kwargs):
965+
return self.__scm_call('isdetached', *args, **kwargs)
966966

967967
def getlibs(self):
968968
for root, dirs, files in os.walk(self.path):
@@ -1007,11 +1007,11 @@ def can_update(self, clean, force):
10071007
"Preserving local library \"%s\" in \"%s\".\nPlease publish this library to a remote URL to be able to restore it at any time."
10081008
"You can use --ignore switch to ignore all local libraries and update only the published ones.\n"
10091009
"You can also use --force switch to remove all local libraries. WARNING: This action cannot be undone." % (self.name, self.path))
1010-
elif not clean and self.scm.dirty():
1010+
elif not clean and self.dirty():
10111011
err = (
10121012
"Uncommitted changes in \"%s\" in \"%s\".\nPlease discard or stash them first and then retry update.\n"
10131013
"You can also use --clean switch to discard all uncommitted changes. WARNING: This action cannot be undone." % (self.name, self.path))
1014-
elif not force and self.scm.outgoing():
1014+
elif not force and self.outgoing():
10151015
err = (
10161016
"Unpublished changes in \"%s\" in \"%s\".\nPlease publish them first using the \"publish\" command.\n"
10171017
"You can also use --force to discard all local commits and replace the library with the one included in this revision. WARNING: This action cannot be undone." % (self.name, self.path))
@@ -1419,7 +1419,7 @@ def add(url, path=None, ignore=False, depth=None, protocol=None):
14191419
lib.sync()
14201420

14211421
lib.write()
1422-
repo.scm.add(lib.lib)
1422+
repo.add(lib.lib)
14231423

14241424

14251425
# Remove library
@@ -1432,9 +1432,8 @@ def remove(path):
14321432
error("Could not find library in path (%s)" % path, 1)
14331433

14341434
lib = Repo.fromrepo(path)
1435-
1436-
repo.scm.remove(lib.lib)
14371435
rmtree_readonly(lib.path)
1436+
repo.remove(lib.lib)
14381437
repo.unignore(relpath(repo.path, lib.path))
14391438

14401439

@@ -1460,16 +1459,16 @@ def publish(all=None, top=True):
14601459

14611460
sync(recursive=False)
14621461

1463-
if repo.scm.dirty():
1462+
if repo.dirty():
14641463
action("Uncommitted changes in %s \"%s\" in \"%s\"" % (repo.pathtype(repo.path), repo.name, repo.path))
14651464
raw_input('Press enter to commit and publish: ')
1466-
repo.scm.commit()
1465+
repo.commit()
14671466

14681467
try:
1469-
outgoing = repo.scm.outgoing()
1468+
outgoing = repo.outgoing()
14701469
if outgoing > 0:
14711470
action("Pushing local repository \"%s\" to remote \"%s\"" % (repo.name, repo.url))
1472-
repo.scm.publish(all)
1471+
repo.publish(all)
14731472
except ProcessException as e:
14741473
if e[0] != 1:
14751474
raise e
@@ -1490,7 +1489,7 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
14901489

14911490
repo = Repo.fromrepo()
14921491

1493-
if top and not rev and repo.scm.isdetached():
1492+
if top and not rev and repo.isdetached():
14941493
error(
14951494
"This %s is in detached HEAD state, and you won't be able to receive updates from the remote repository until you either checkout a branch or create a new one.\n"
14961495
"You can checkout a branch using \"%s checkout <branch_name>\" command before running \"mbed update\"." % (cwd_type, repo.scm.name), 1)
@@ -1507,7 +1506,7 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
15071506
repo.revtype(rev, True)))
15081507

15091508
try:
1510-
repo.scm.update(rev, clean, repo.is_local)
1509+
repo.update(rev, clean, repo.is_local)
15111510
except ProcessException as e:
15121511
err = "Unable to update \"%s\" to %s" % (repo.name, repo.revtype(rev, True))
15131512
if depth:
@@ -1594,7 +1593,7 @@ def sync(recursive=True, keep_refs=False, top=True):
15941593
else:
15951594
if not keep_refs:
15961595
action("Removing reference \"%s\" -> \"%s\"" % (lib.name, lib.fullurl))
1597-
repo.scm.remove(lib.lib)
1596+
repo.remove(lib.lib)
15981597
repo.unignore(relpath(repo.path, lib.path))
15991598

16001599
for root, dirs, files in os.walk(repo.path):
@@ -1613,7 +1612,7 @@ def sync(recursive=True, keep_refs=False, top=True):
16131612
dirs.remove(d)
16141613
lib.write()
16151614
repo.ignore(relpath(repo.path, lib.path))
1616-
repo.scm.add(lib.lib)
1615+
repo.add(lib.lib)
16171616
progress()
16181617

16191618
repo.sync()
@@ -1657,9 +1656,9 @@ def list_(all=False, prefix='', p_path=None, ignore=False):
16571656
help='Show status of the current %s and its dependencies.' % cwd_type)
16581657
def status_(ignore=False):
16591658
repo = Repo.fromrepo()
1660-
if repo.scm.dirty():
1659+
if repo.dirty():
16611660
action("Status for \"%s\":" % repo.name)
1662-
print repo.scm.status()
1661+
print repo.status()
16631662

16641663
for lib in repo.libs:
16651664
if lib.check_repo(ignore):
@@ -1890,14 +1889,14 @@ def config(toolchain=None, mcu=None, source=False, prefix=None):
18901889
parser.print_help()
18911890
sys.exit(1)
18921891

1893-
args, remainder = parser.parse_known_args()
1892+
pargs, remainder = parser.parse_known_args()
18941893
status = 1
18951894

18961895
try:
1897-
very_verbose = args.very_verbose
1898-
verbose = very_verbose or args.verbose
1896+
very_verbose = pargs.very_verbose
1897+
verbose = very_verbose or pargs.verbose
18991898
log('Working path \"%s\" (%s)' % (os.getcwd(), cwd_type))
1900-
status = args.command(args)
1899+
status = pargs.command(pargs)
19011900
except ProcessException as e:
19021901
error(
19031902
"\"%s\" returned error code %d.\n"

0 commit comments

Comments
 (0)