def parse_branches(self, data): """ Parse output of git branch -a, eg: develop master * release/2.0.0 rtd-jonas remotes/origin/2.0.X remotes/origin/HEAD -> origin/master remotes/origin/develop remotes/origin/master remotes/origin/release/2.0.0 remotes/origin/release/2.1.0 """ clean_branches = [] raw_branches = csv.reader(StringIO(data), delimiter=' ') for branch in raw_branches: branch = filter(lambda f: f != '' and f != '*', branch) branch = branch[0] if branch.startswith('remotes/origin/'): slug = branch[15:].replace('/', '-') if slug in ['HEAD', self.fallback_branch]: continue clean_branches.append(VCSVersion(self, branch, slug)) else: slug = branch.replace('/', '-') clean_branches.append(VCSVersion(self, branch, slug)) return clean_branches
def parse_branches(self, data): """ Parse output of git branch -r e.g.: origin/2.0.X origin/HEAD -> origin/master origin/develop origin/master origin/release/2.0.0 origin/release/2.1.0 """ clean_branches = [] raw_branches = csv.reader(StringIO(data), delimiter=' ') for branch in raw_branches: branch = filter(lambda f: f != '' and f != '*', branch) # Handle empty branches if len(branch): branch = branch[0] if branch.startswith('origin/'): cut_len = len('origin/') slug = branch[cut_len:].replace('/', '-') if slug in ['HEAD']: continue clean_branches.append(VCSVersion(self, branch, slug)) else: # Believe this is dead code. slug = branch.replace('/', '-') clean_branches.append(VCSVersion(self, branch, slug)) return clean_branches
def lsremote(self): """ Use ``git ls-remote`` to list branches and tags without clonning the repository. :returns: tuple containing a list of branch and tags """ cmd = ['git', 'ls-remote', self.repo_url] self.check_working_dir() code, stdout, stderr = self.run(*cmd) if code != 0: raise RepositoryError tags = [] branches = [] for line in stdout.splitlines()[1:]: # skip HEAD commit, ref = line.split() if ref.startswith('refs/heads/'): branch = ref.replace('refs/heads/', '') branches.append(VCSVersion(self, branch, branch)) if ref.startswith('refs/tags/'): tag = ref.replace('refs/tags/', '') if tag.endswith('^{}'): # skip annotated tags since they are duplicated continue tags.append(VCSVersion(self, commit, tag)) return branches, tags
def parse_branches(self, data): """ Parse output of git branch -r. e.g.: origin/2.0.X origin/HEAD -> origin/master origin/develop origin/master origin/release/2.0.0 origin/release/2.1.0 """ clean_branches = [] # StringIO below is expecting Unicode data, so ensure that it gets it. if not isinstance(data, str): data = str(data) delimiter = str(' ').encode('utf-8') if PY2 else str(' ') raw_branches = csv.reader(StringIO(data), delimiter=delimiter) for branch in raw_branches: branch = [f for f in branch if f not in ('', '*')] # Handle empty branches if branch: branch = branch[0] if branch.startswith('origin/'): verbose_name = branch.replace('origin/', '') if verbose_name in ['HEAD']: continue clean_branches.append( VCSVersion(self, branch, verbose_name)) else: clean_branches.append(VCSVersion(self, branch, branch)) return clean_branches
def parse_branches(self, data): """ Parse output of git branch -r e.g.: origin/2.0.X origin/HEAD -> origin/master origin/develop origin/master origin/release/2.0.0 origin/release/2.1.0 """ clean_branches = [] # StringIO below is expecting Unicode data, so ensure that it gets it. if not isinstance(data, str): data = str(data) raw_branches = csv.reader(StringIO(data), delimiter=' ') for branch in raw_branches: branch = [f for f in branch if f != '' and f != '*'] # Handle empty branches if branch: branch = branch[0] if branch.startswith('origin/'): cut_len = len('origin/') slug = branch[cut_len:].replace('/', '-') if slug in ['HEAD']: continue clean_branches.append(VCSVersion(self, branch, slug)) else: # Believe this is dead code. slug = branch.replace('/', '-') clean_branches.append(VCSVersion(self, branch, slug)) return clean_branches
def parse_tags(self, data): """ Parses output of `hg tags`, eg: tip 278:c4b2d21db51a 0.2.2 152:6b0364d98837 0.2.1 117:a14b7b6ffa03 0.1 50:30c2c6b3a055 maintenance release 1 10:f83c32fe8126 Into VCSVersion objects with the tag name as verbose_name and the commit hash as identifier. """ vcs_tags = [] tag_lines = [line.strip() for line in data.splitlines()] # starting from the rhs of each line, split a single value (changeset) # off at whitespace; the tag name is the string to the left of that tag_pairs = [line.rsplit(None, 1) for line in tag_lines] for row in tag_pairs: if len(row) != 2: continue name, commit = row if name == 'tip': continue _, commit_hash = commit.split(':') vcs_tags.append(VCSVersion(self, commit_hash, name)) return vcs_tags
def tags(self): versions = [] repo = self._repo # Build a cache of tag -> commit # GitPython is not very optimized for reading large numbers of tags ref_cache = {} # 'ref/tags/<tag>' -> hexsha # This code is the same that is executed for each tag in gitpython, # we excute it only once for all tags. for hexsha, ref in git.TagReference._iter_packed_refs(repo): gitobject = git.Object.new_from_sha(repo, hex_to_bin(hexsha)) if gitobject.type == 'commit': ref_cache[ref] = str(gitobject) elif gitobject.type == 'tag' and gitobject.object.type == 'commit': ref_cache[ref] = str(gitobject.object) for tag in repo.tags: if tag.path in ref_cache: hexsha = ref_cache[tag.path] else: try: hexsha = str(tag.commit) except ValueError: # ValueError: Cannot resolve commit as tag TAGNAME points to a # blob object - use the `.object` property instead to access it # This is not a real tag for us, so we skip it # https://github.com/rtfd/readthedocs.org/issues/4440 log.warning('Git tag skipped: %s', tag, exc_info=True) continue versions.append(VCSVersion(self, hexsha, str(tag))) return versions
def tags(self): versions = [] repo = git.Repo(self.working_dir) # Build a cache of tag -> commit # GitPython is not very optimized for reading large numbers of tags ref_cache = {} # 'ref/tags/<tag>' -> hexsha for hexsha, ref in git.TagReference._iter_packed_refs(repo): ref_cache[ref] = hexsha for tag in repo.tags: if tag.path in ref_cache: hexsha = ref_cache[tag.path] else: try: hexsha = str(tag.commit) except ValueError: # ValueError: Cannot resolve commit as tag TAGNAME points to a # blob object - use the `.object` property instead to access it # This is not a real tag for us, so we skip it # https://github.com/rtfd/readthedocs.org/issues/4440 log.warning('Git tag skipped: %s', tag, exc_info=True) continue versions.append(VCSVersion(self, hexsha, str(tag))) return versions
def parse_tags(self, data): """ Parses output of bzr tags, eg: 0.1.0 171 0.1.1 173 0.1.2 174 0.2.0-pre-alpha 177 Can't forget about poorly formatted tags or tags that lack revisions, such as: 3.3.0-rc1 ? tag with spaces 123 """ # parse the lines into a list of tuples (commit-hash, tag ref name) # StringIO below is expecting Unicode data, so ensure that it gets it. if not isinstance(data, str): data = str(data) squashed_data = re.sub(r' +', ' ', data) raw_tags = csv.reader(StringIO(squashed_data), delimiter=' ') vcs_tags = [] for row in raw_tags: name = ' '.join(row[:-1]) commit = row[-1] if commit != '?': vcs_tags.append(VCSVersion(self, commit, name)) return vcs_tags
def parse_tags(self, data): """ Parses output of show-ref --tags, eg: 3b32886c8d3cb815df3793b3937b2e91d0fb00f1 refs/tags/2.0.0 bd533a768ff661991a689d3758fcfe72f455435d refs/tags/2.0.1 c0288a17899b2c6818f74e3a90b77e2a1779f96a refs/tags/2.0.2 a63a2de628a3ce89034b7d1a5ca5e8159534eef0 refs/tags/2.1.0.beta2 c7fc3d16ed9dc0b19f0d27583ca661a64562d21e refs/tags/2.1.0.rc1 edc0a2d02a0cc8eae8b67a3a275f65cd126c05b1 refs/tags/2.1.0.rc2 Into VCSTag objects with the tag name as verbose_name and the commit hash as identifier. """ # parse the lines into a list of tuples (commit-hash, tag ref name) # StringIO below is expecting Unicode data, so ensure that it gets it. if not isinstance(data, str): data = str(data) raw_tags = csv.reader(StringIO(data), delimiter=' ') vcs_tags = [] for row in raw_tags: row = [f for f in row if f != ''] if row == []: continue commit_hash, name = row clean_name = name.split('/')[-1] vcs_tags.append(VCSVersion(self, commit_hash, clean_name)) return vcs_tags
def parse_branches(self, data): """ stable default """ names = [name.lstrip() for name in data.splitlines()] return [VCSVersion(self, name, name) for name in names if name]
def branches(self): branches = [] proj = self.get_project() for series in proj.series: branches.append( VCSVersion(self, series.branch.bzr_identity, series.name)) return branches
def parse_branches(self, data): """ Parses output of `hg branches --quiet`, eg: default 0.2 0.1 Into VCSVersion objects with branch name as verbose_name and identifier. """ names = [name.lstrip() for name in data.splitlines()] return [VCSVersion(self, name, name) for name in names if name]
def tags(self): versions = [] repo = git.Repo(self.working_dir) for tag in repo.tags: try: versions.append(VCSVersion(self, str(tag.commit), str(tag))) except ValueError: # ValueError: Cannot resolve commit as tag TAGNAME points to a # blob object - use the `.object` property instead to access it # This is not a real tag for us, so we skip it # https://github.com/rtfd/readthedocs.org/issues/4440 log.warning('Git tag skipped: %s', tag, exc_info=True) continue return versions
def parse_branches(self, data): """ stable 13575:8e94a1b4e9a4 default 13572:1bb2a56a9d73 """ raw_branches = csv.reader(StringIO(data), delimiter=' ') clean_branches = [] for branch in raw_branches: branch = filter(lambda f: f != '', branch) if branch == []: continue name, rev = branch clean_branches.append(VCSVersion(self, name, name)) return clean_branches
def parse_tags(self, data): """ Parses output of show-ref --tags, eg: 0.1.0 171 0.1.1 173 0.1.2 174 0.2.0-pre-alpha 177 """ # parse the lines into a list of tuples (commit-hash, tag ref name) raw_tags = csv.reader(StringIO(data), delimiter=' ') vcs_tags = [] for name, commit in raw_tags: vcs_tags.append(VCSVersion(self, commit, name)) return vcs_tags
def branches(self): repo = git.Repo(self.working_dir) versions = [] branches = [] # ``repo.remotes.origin.refs`` returns remote branches if repo.remotes: branches += repo.remotes.origin.refs for branch in branches: verbose_name = branch.name if verbose_name.startswith('origin/'): verbose_name = verbose_name.replace('origin/', '') if verbose_name == 'HEAD': continue versions.append(VCSVersion(self, str(branch), verbose_name)) return versions
def parse_tags(self, data): """ Parses output of svn list, eg: release-1.1/ release-1.2/ release-1.3/ release-1.4/ release-1.4.1/ release-1.5/ """ # parse the lines into a list of tuples (commit-hash, tag ref name) raw_tags = csv.reader(StringIO(data), delimiter='/') vcs_tags = [] for name, _ in raw_tags: vcs_tags.append(VCSVersion(self, '/tags/%s/' % name, name)) return vcs_tags
def parse_tags(self, data): """ Parses output of svn list, eg: release-1.1/ release-1.2/ release-1.3/ release-1.4/ release-1.4.1/ release-1.5/ """ # parse the lines into a list of tuples (commit-hash, tag ref name) # StringIO below is expecting Unicode data, so ensure that it gets it. if not isinstance(data, str): data = str(data) raw_tags = csv.reader(StringIO(data), delimiter='/') vcs_tags = [] for name, _ in raw_tags: vcs_tags.append(VCSVersion(self, '/tags/%s/' % name, name)) return vcs_tags
def parse_tags(self, data): """ Parses output of show-ref --tags, eg: tip 278:c4b2d21db51a 0.2.2 152:6b0364d98837 0.2.1 117:a14b7b6ffa03 0.1 50:30c2c6b3a055 """ # parse the lines into a list of tuples (commit-hash, tag ref name) raw_tags = csv.reader(StringIO(data), delimiter=' ') vcs_tags = [] for row in raw_tags: row = filter(lambda f: f != '', row) if row == []: continue name, commit = row if name == 'tip': continue revision, commit_hash = commit.split(':') vcs_tags.append(VCSVersion(self, commit_hash, name)) return vcs_tags
def tags(self): repo = git.Repo(self.working_dir) versions = [ VCSVersion(self, str(tag.commit), str(tag)) for tag in repo.tags ] return versions