From 6a803696d53a15e5106008e038336273311a4364 Mon Sep 17 00:00:00 2001 From: Shardul Chiplunkar Date: Thu, 29 Mar 2018 17:28:18 -0700 Subject: [PATCH 1/3] Initial attempt at #42 --- sync.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sync.py b/sync.py index 4847611..67b166b 100755 --- a/sync.py +++ b/sync.py @@ -60,6 +60,7 @@ DEFAULT_CLONE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'repos') DEFAULT_AUTHOR = 'Apertium Bot ' DEFAULT_SYNC_INTERVAL = 3 # seconds +DEFAULT_SYNC_DEPTH = 1 server = None @@ -154,11 +155,12 @@ def repos_for_topics(repos_by_topic, topics): class MetaRepoSyncer: - def __init__(self, clone_dir, name, submodules, author): + def __init__(self, clone_dir, name, submodules, author, sync_depth): self.clone_dir = clone_dir self.name = name self.submodules = submodules self.author = author + self.sync_depth = sync_depth self.dir = os.path.join(clone_dir, name) self.check_call = functools.partial(subprocess.check_call, cwd=self.dir) @@ -166,7 +168,7 @@ def __init__(self, clone_dir, name, submodules, author): def clone(self, init_submodules=True): if not os.path.isdir(os.path.join(self.clone_dir, self.name)): logging.info('Cloning meta repository %s', self.name) - subprocess.check_call(shlex.split('git clone --depth 1 git@github.com:{}/{}.git'.format(ORGANIZATION, self.name)), cwd=self.clone_dir) + subprocess.check_call(shlex.split('git clone --depth {} git@github.com:{}/{}.git'.format(self.sync_depth, ORGANIZATION, self.name)), cwd=self.clone_dir) if init_submodules and self._has_submodules(): self.check_call(shlex.split('git submodule update --depth 1 --init --jobs 8')) else: @@ -335,7 +337,7 @@ def handle_events(self): with concurrent.futures.ThreadPoolExecutor() as pool: for name, topics in metarepo_group.items(): submodules = repos_for_topics(repos_by_topic, topics) - pool.submit(MetaRepoSyncer(self.args.dir, name, submodules, self.args.author).sync) + pool.submit(MetaRepoSyncer(self.args.dir, name, submodules, self.args.author, self.args.sync_depth).sync) else: logging.debug('Ignoring events for meta repository group %d', i) except Exception as error: @@ -374,6 +376,7 @@ def main(): parser.add_argument('--port', '-p', type=int, help='server port (default: {})'.format(DEFAULT_PORT), default=DEFAULT_PORT) parser.add_argument('--token', '-t', help='GitHub OAuth token', required=(DEFAULT_OAUTH_TOKEN is None), default=DEFAULT_OAUTH_TOKEN) parser.add_argument('--sync-interval', '-i', help='min interval between syncs (default: {}s)'.format(DEFAULT_SYNC_INTERVAL), default=DEFAULT_SYNC_INTERVAL) + parser.add_argument('--sync-depth', '-n', help='clone depth for syncing (default: {})'.format(DEFAULT_SYNC_DEPTH), default=DEFAULT_SYNC_DEPTH) parser.add_argument('--author', '-a', help='commit author (default: {})'.format(DEFAULT_AUTHOR), default=DEFAULT_AUTHOR) args = parser.parse_args() @@ -393,12 +396,12 @@ def main(): if args.repo: topics = collections.ChainMap(*METAREPOS)[args.repo] submodules = repos_for_topics(repos_by_topic, topics) - MetaRepoSyncer(args.dir, args.repo, submodules, args.author).sync() + MetaRepoSyncer(args.dir, args.repo, submodules, args.author, args.sync_depth).sync() else: for metarepo_group in METAREPOS: for name, topics in metarepo_group.items(): submodules = repos_for_topics(repos_by_topic, topics) - MetaRepoSyncer(args.dir, name, submodules, args.author).sync() + MetaRepoSyncer(args.dir, name, submodules, args.author, args.sync_depth).sync() if __name__ == '__main__': From ce9383b8c667cfd0d3c461b2af7af6bef5815b46 Mon Sep 17 00:00:00 2001 From: Shardul Chiplunkar Date: Thu, 29 Mar 2018 17:42:11 -0700 Subject: [PATCH 2/3] Same depth for submodule init --- sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync.py b/sync.py index 67b166b..11cae6c 100755 --- a/sync.py +++ b/sync.py @@ -170,7 +170,7 @@ def clone(self, init_submodules=True): logging.info('Cloning meta repository %s', self.name) subprocess.check_call(shlex.split('git clone --depth {} git@github.com:{}/{}.git'.format(self.sync_depth, ORGANIZATION, self.name)), cwd=self.clone_dir) if init_submodules and self._has_submodules(): - self.check_call(shlex.split('git submodule update --depth 1 --init --jobs 8')) + self.check_call(shlex.split('git submodule update --depth {} --init --jobs 8'.format(self.sync_depth))) else: logging.debug('Meta repository %s already cloned', self.name) From 3107f6d9d81a9c64dadc764d3e3e1c0886da691c Mon Sep 17 00:00:00 2001 From: Shardul Chiplunkar Date: Thu, 29 Mar 2018 17:45:01 -0700 Subject: [PATCH 3/3] sync_depth -> depth inside Syncer class --- sync.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sync.py b/sync.py index 11cae6c..933114c 100755 --- a/sync.py +++ b/sync.py @@ -155,12 +155,12 @@ def repos_for_topics(repos_by_topic, topics): class MetaRepoSyncer: - def __init__(self, clone_dir, name, submodules, author, sync_depth): + def __init__(self, clone_dir, name, submodules, author, depth): self.clone_dir = clone_dir self.name = name self.submodules = submodules self.author = author - self.sync_depth = sync_depth + self.depth = depth self.dir = os.path.join(clone_dir, name) self.check_call = functools.partial(subprocess.check_call, cwd=self.dir) @@ -168,9 +168,9 @@ def __init__(self, clone_dir, name, submodules, author, sync_depth): def clone(self, init_submodules=True): if not os.path.isdir(os.path.join(self.clone_dir, self.name)): logging.info('Cloning meta repository %s', self.name) - subprocess.check_call(shlex.split('git clone --depth {} git@github.com:{}/{}.git'.format(self.sync_depth, ORGANIZATION, self.name)), cwd=self.clone_dir) + subprocess.check_call(shlex.split('git clone --depth {} git@github.com:{}/{}.git'.format(self.depth, ORGANIZATION, self.name)), cwd=self.clone_dir) if init_submodules and self._has_submodules(): - self.check_call(shlex.split('git submodule update --depth {} --init --jobs 8'.format(self.sync_depth))) + self.check_call(shlex.split('git submodule update --depth {} --init --jobs 8'.format(self.depth))) else: logging.debug('Meta repository %s already cloned', self.name)