Skip to content

Commit 8536d5d

Browse files
committed
Optimizations related to checkout and cache logic
1 parent 979b8b1 commit 8536d5d

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

mbed/mbed.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,10 @@ def checkout(rev, clean=False):
653653
popen([git_cmd, 'checkout', rev] + (['-f'] if clean else []) + ([] if very_verbose else ['-q']))
654654

655655
def update(rev=None, clean=False, clean_files=False, is_local=False):
656-
if clean:
657-
Git.discard(clean_files)
658656
if not is_local:
659657
Git.fetch()
658+
if clean:
659+
Git.discard(clean_files)
660660
if rev:
661661
Git.checkout(rev, clean)
662662
else:
@@ -668,11 +668,11 @@ def update(rev=None, clean=False, clean_files=False, is_local=False):
668668
except ProcessException:
669669
pass
670670
else:
671-
err = "Unable to update \"%s\" in \"%s\".\n" % (os.path.basename(os.getcwd()), os.getcwd())
671+
err = "Unable to update \"%s\" in \"%s\"." % (os.path.basename(os.getcwd()), os.getcwd())
672672
if not remote:
673-
info(err+"The local repository is not associated with a remote one.")
673+
info(err+" The local repository is not associated with a remote one.")
674674
if not branch:
675-
info(err+"Working set is not on a branch.")
675+
info(err+" Working set is not on a branch.")
676676

677677
def status():
678678
return pquery([git_cmd, 'status', '-s'] + (['-v'] if very_verbose else []))
@@ -844,7 +844,7 @@ def fromurl(cls, url, path=None):
844844
repo.path = os.path.abspath(path or os.path.join(os.getcwd(), repo.name))
845845
repo.url = formaturl(m_repo_url.group(1))
846846
repo.rev = m_repo_url.group(3)
847-
if repo.rev and not re.match(r'^([a-fA-F0-9]{6,40})$', repo.rev):
847+
if repo.rev and repo.rev != 'latest' and not re.match(r'^([a-fA-F0-9]{6,40})$', repo.rev):
848848
error('Invalid revision (%s)' % repo.rev, -1)
849849
else:
850850
error('Invalid repository (%s)' % url.strip(), -1)
@@ -1634,15 +1634,11 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl
16341634
p.path = cwd_root
16351635
p.set_root()
16361636
if not create_only and not p.get_os_dir() and not p.get_mbedlib_dir():
1637-
url = mbed_lib_url if mbedlib else mbed_os_url
1637+
url = mbed_lib_url if mbedlib else mbed_os_url+'#latest'
16381638
d = 'mbed' if mbedlib else 'mbed-os'
16391639
try:
16401640
with cd(d_path):
16411641
add(url, depth=depth, protocol=protocol, top=False)
1642-
if not mbedlib:
1643-
with cd(d):
1644-
repo = Repo.fromrepo()
1645-
repo.checkout('latest')
16461642
except Exception as e:
16471643
if os.path.isdir(os.path.join(d_path, d)):
16481644
rmtree_readonly(os.path.join(d_path, d))
@@ -1694,7 +1690,7 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
16941690
with cd(repo.path):
16951691
Program(repo.path).set_root()
16961692
try:
1697-
if repo.getrev() != repo.rev:
1693+
if repo.rev and repo.getrev() != repo.rev:
16981694
repo.checkout(repo.rev, True)
16991695
except ProcessException as e:
17001696
err = "Unable to update \"%s\" to %s" % (repo.name, repo.revtype(repo.rev, True))

0 commit comments

Comments
 (0)