def checkout_packages(options): if options.checkout is None: options.checkout = "/".join([REMOTE_NAME, options.branch[0]]) fetch_packages(options) refs = getrefs(options.branch, options.repopattern) for pkgdir in sorted(refs.heads): repo = GitRepo(os.path.join(options.packagesdir, pkgdir)) try: repo.checkout(options.checkout) except GitRepoError as e: print('Problem with checking branch {} in repo {}: {}'.format(options.checkout, repo.gdir, e), file=sys.stderr)
def fetch_packages(options, return_all=False): fetch_queue = queue.Queue() updated_repos = Store() for i in range(options.jobs): t = ThreadFetch(fetch_queue, updated_repos, options.packagesdir, options.depth) t.setDaemon(True) t.start() signal.signal(signal.SIGINT, signal.SIG_DFL) refs = getrefs(options.branch, options.repopattern) print('Read remotes data') for pkgdir in sorted(refs.heads): gitdir = os.path.join(options.packagesdir, pkgdir, '.git') if not os.path.isdir(gitdir): if options.newpkgs: gitrepo = initpackage(pkgdir, options) else: continue elif options.omitexisting: continue else: gitrepo = GitRepo(os.path.join(options.packagesdir, pkgdir)) ref2fetch = [] for ref in refs.heads[pkgdir]: if gitrepo.check_remote(ref) != refs.heads[pkgdir][ref]: ref2fetch.append('+{}:{}/{}'.format(ref, REMOTEREFS, ref[len('refs/heads/'):])) if ref2fetch: ref2fetch.append('refs/notes/*:refs/notes/*') fetch_queue.put((gitrepo, ref2fetch)) fetch_queue.join() if options.prune: refs = getrefs('*') for pattern in options.repopattern: for fulldir in glob.iglob(os.path.join(options.packagesdir, pattern)): pkgdir = os.path.basename(fulldir) if len(refs.heads[pkgdir]) == 0 and os.path.isdir(os.path.join(fulldir, '.git')): print('Removing', fulldir) shutil.rmtree(fulldir) if return_all: return refs.heads else: return updated_repos.items
def initpackage(name, options): repo = GitRepo(os.path.join(options.packagesdir, name)) remotepush = os.path.join(GIT_REPO_PUSH, name) repo.init(os.path.join(GIT_REPO, name), remotepush) return repo