Skip to content

Commit

Permalink
Simplify updating repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoWilken committed Mar 6, 2024
1 parent 56d52f5 commit c4cc0a8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
22 changes: 7 additions & 15 deletions alibuild_helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,19 @@ def update_git_repos(args, specs, buildOrder):
def update_repo(package, git_prompt):
specs[package]["scm"] = Git()
if specs[package]["is_devel_pkg"]:
localCheckout = os.path.join(os.getcwd(), specs[package]["package"])
if exists("%s/.sl" % localCheckout):
specs[package]["scm"] = Sapling()
specs[package]["source"] = os.path.join(os.getcwd(), specs[package]["package"])
if exists(os.path.join(specs[package]["source"], ".sl")):
specs[package]["scm"] = Sapling()
updateReferenceRepoSpec(args.referenceSources, package, specs[package],
fetch=args.fetchRepos,
usePartialClone=not args.docker,
allowGitPrompt=git_prompt)

# Retrieve git heads
scm = specs[package]["scm"]
cmd = scm.listRefsCmd()
if specs[package]["is_devel_pkg"]:
specs[package]["source"] = \
os.path.join(os.getcwd(), specs[package]["package"])
cmd.append(specs[package]["source"])
else:
cmd.append(specs[package].get("reference", specs[package]["source"]))

output = logged_scm(scm, package, args.referenceSources,
cmd, ".", prompt=git_prompt, logOutput=False)
specs[package]["scm_refs"] = scm.parseRefs(output)
output = logged_scm(specs[package]["scm"], package, args.referenceSources,
specs[package]["scm"].listRefsCmd(specs[package].get("reference", specs[package]["source"])),
".", prompt=git_prompt, logOutput=False)
specs[package]["scm_refs"] = specs[package]["scm"].parseRefs(output)

progress = ProgressPrint("Updating repositories")
requires_auth = set()
Expand Down
4 changes: 2 additions & 2 deletions alibuild_helpers/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def parseRefs(self, output):
git_ref: git_hash for git_hash, sep, git_ref
in (line.partition("\t") for line in output.splitlines()) if sep
}
def listRefsCmd(self):
return ["ls-remote", "--heads", "--tags"]
def listRefsCmd(self, repository):
return ["ls-remote", "--heads", "--tags", repository]
def cloneCmd(self, source, referenceRepo, usePartialClone):
cmd = ["clone", "--bare", source, referenceRepo]
if usePartialClone:
Expand Down
2 changes: 1 addition & 1 deletion alibuild_helpers/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def branchOrRef(self, directory):
raise NotImplementedError
def lsRemote(self, remote):
raise NotImplementedError
def listRefsCmd(self):
def listRefsCmd(self, repository):
raise NotImplementedError
def parseRefs(self, output):
raise NotImplementedError
Expand Down
4 changes: 2 additions & 2 deletions alibuild_helpers/sl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def parseRefs(self, output):
sl_ref: sl_hash for sl_ref, sep, sl_hash
in (line.partition("\t") for line in output.splitlines()) if sep
}
def listRefsCmd(self):
return ["bookmark", "--list", "--remote", "-R"]
def listRefsCmd(self, repository):
return ["bookmark", "--list", "--remote", "-R", repository]
def diffCmd(self, directory):
return "cd %s && sl diff && sl status" % directory
def checkUntracked(self, line):
Expand Down
10 changes: 4 additions & 6 deletions alibuild_helpers/workarea.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ordereddict import OrderedDict

from alibuild_helpers.log import dieOnError, debug, error
from alibuild_helpers.utilities import call_ignoring_oserrors

FETCH_LOG_NAME = "fetch-log.txt"

Expand Down Expand Up @@ -92,18 +93,15 @@ def updateReferenceRepo(referenceSources, p, spec,
@fetch : whether to fetch updates: if False, only clone if not found
"""
assert isinstance(spec, OrderedDict)
if "source" not in spec:
return
if spec["is_devel_pkg"] or "source" not in spec:
return None

scm = spec["scm"]

debug("Updating references.")
referenceRepo = os.path.join(os.path.abspath(referenceSources), p.lower())

try:
os.makedirs(os.path.abspath(referenceSources))
except:
pass
call_ignoring_oserrors(os.makedirs, os.path.abspath(referenceSources), exist_ok=True)

if not is_writeable(referenceSources):
if os.path.exists(referenceRepo):
Expand Down
9 changes: 5 additions & 4 deletions tests/test_workarea.py