Skip to content

Commit

Permalink
Merge pull request #13 from jderusse/feature/filter-ref
Browse files Browse the repository at this point in the history
Add an option to filter references
  • Loading branch information
jderusse authored May 14, 2018
2 parents 02cd302 + 1bfc814 commit e222df7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ install:
- git fetch --unshallow

script:
- docker run --rm -t -e GH_TOKEN -v /cache/gitsplit:/cache/gitsplit -v ${PWD}:/srv jderusse/gitsplit
- docker run --rm -t -e GH_TOKEN -v /cache/gitsplit:/cache/gitsplit -v ${PWD}:/srv jderusse/gitsplit --ref "${TRAVIS_BRANCH}"
```
# Sample with GitLab CI/CD
Expand Down Expand Up @@ -181,5 +181,5 @@ split:
- git config remote.origin.fetch "+refs/*:refs/*"
- git config remote.origin.mirror true
- git fetch
- gitsplit
- gitsplit --ref "${CI_COMMIT_REF_NAME}"
```
21 changes: 15 additions & 6 deletions gitsplit
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import tempfile
import subprocess
import re
import hashlib
import argparse
from multiprocessing.pool import ThreadPool
from multiprocessing import Lock

Expand Down Expand Up @@ -125,9 +126,9 @@ class Splitter:
self.utils = utils
self.logger = logger

def split(self):
def split(self, whitelist_references):
self._init_workspace()
self._split_project()
self._split_project(whitelist_references)

def _init_workspace(self):
# Init cache repo
Expand Down Expand Up @@ -160,19 +161,21 @@ class Splitter:
self.git.call(['fetch', '-p', 'origin'])
self.git.call(['fetch', '--tags', 'origin'])

def _split_project(self):
def _split_project(self, whitelist_references):
pool = ThreadPool(8)
pool.map(self._split_reference, self._get_split_references())
pool.map(self._split_reference, self._get_split_references(whitelist_references))
pool.close()
pool.join()

def _get_split_references(self):
def _get_split_references(self, whitelist_references):
for ref_pattern in self.config.origins:
re_pattern = re.compile(ref_pattern)
for (reference_ref, reference_sha1) in self._get_references('origin').items():
reference_name = self._get_reference_name(reference_ref)
if not reference_name:
continue
if whitelist_references and reference_name not in whitelist_references:
continue
if not re_pattern.match(reference_name):
continue

Expand Down Expand Up @@ -262,7 +265,13 @@ def main():
git = Git(config.cache_dir, process)

splitter = Splitter(config, process, git, utils, logger)
splitter.split()

parser = argparse.ArgumentParser(description='Split git repository.')
parser.add_argument('--ref', dest='references', metavar='BRANCH_OR_TAG', type=str, nargs='*',
help='git references (branch or tag) to process. When not set, process every references')

args = parser.parse_args()
splitter.split(args.references)

if __name__ == '__main__':
main()

0 comments on commit e222df7

Please sign in to comment.