def _get_revision(self, revision): """ Gets an ID revision given as str. This will always return a fill 40 char revision number :param revision: str or int or None """ if isinstance(revision, unicode): revision = safe_str(revision) if self._empty: raise EmptyRepositoryError("There are no changesets yet") if revision in [-1, 'tip', None]: revision = 'tip' try: revision = hex(self._repo.lookup(revision)) except (IndexError, ValueError, RepoLookupError, TypeError): msg = ("Revision %s does not exist for %s" % (revision, self)) raise ChangesetDoesNotExistError(msg) except (LookupError, ): msg = ("Ambiguous identifier `%s` for %s" % (revision, self)) raise ChangesetDoesNotExistError(msg) return revision
def get_ref_revision(self, ref_type, ref_name): """ Returns revision number for the given reference. """ if ref_type == 'rev' and not ref_name.strip('0'): return self.EMPTY_CHANGESET # lookup up the exact node id _revset_predicates = { 'branch': 'branch', 'book': 'bookmark', 'tag': 'tag', 'rev': 'id', } # avoid expensive branch(x) iteration over whole repo rev_spec = "%%s & %s(%%s)" % _revset_predicates[ref_type] try: revs = self._repo.revs(rev_spec, ref_name, ref_name) except LookupError: msg = "Ambiguous identifier %s:%s for %s" % (ref_type, ref_name, self.name) raise ChangesetDoesNotExistError(msg) except mercurial.error.RepoLookupError: msg = "Revision %s:%s does not exist for %s" % (ref_type, ref_name, self.name) raise ChangesetDoesNotExistError(msg) if revs: revision = revs.last() else: # TODO: just report 'not found'? revision = ref_name return self._get_revision(revision)
def _get_revision(self, revision): """ Given any revision identifier, returns a 40 char string with revision hash. :param revision: str or int or None """ if self._empty: raise EmptyRepositoryError("There are no changesets yet") if revision in [-1, None]: revision = b'tip' elif isinstance(revision, str): revision = safe_bytes(revision) try: if isinstance(revision, int): return ascii_str(self._repo[revision].hex()) return ascii_str( mercurial.scmutil.revsymbol(self._repo, revision).hex()) except (IndexError, ValueError, mercurial.error.RepoLookupError, TypeError): msg = "Revision %r does not exist for %s" % (safe_str(revision), self.name) raise ChangesetDoesNotExistError(msg) except (LookupError, ): msg = "Ambiguous identifier `%s` for %s" % (safe_str(revision), self.name) raise ChangesetDoesNotExistError(msg)
def _get_revision(self, revision): """ Given any revision identifier, returns a 40 char string with revision hash. """ if self._empty: raise EmptyRepositoryError("There are no changesets yet") if revision in (None, '', 'tip', 'HEAD', 'head', -1): revision = -1 if isinstance(revision, int): try: return self.revisions[revision] except IndexError: msg = "Revision %r does not exist for %s" % (revision, self.name) raise ChangesetDoesNotExistError(msg) if isinstance(revision, str): if revision.isdigit() and (len(revision) < 12 or len(revision) == revision.count('0')): try: return self.revisions[int(revision)] except IndexError: msg = "Revision %r does not exist for %s" % (revision, self) raise ChangesetDoesNotExistError(msg) # get by branch/tag name _ref_revision = self._parsed_refs.get(safe_bytes(revision)) if _ref_revision: # and _ref_revision[1] in [b'H', b'RH', b'T']: return ascii_str(_ref_revision[0]) if revision in self.revisions: return revision # maybe it's a tag ? we don't have them in self.revisions if revision in self.tags.values(): return revision if SHA_PATTERN.match(revision): msg = "Revision %r does not exist for %s" % (revision, self.name) raise ChangesetDoesNotExistError(msg) raise ChangesetDoesNotExistError("Given revision %r not recognized" % revision)
def _get_revision(self, revision): """ For git backend we always return integer here. This way we ensure that changeset's revision attribute would become integer. """ is_null = lambda o: len(o) == revision.count('0') if self._empty: raise EmptyRepositoryError("There are no changesets yet") if revision in (None, '', 'tip', 'HEAD', 'head', -1): return self.revisions[-1] is_bstr = isinstance(revision, (str, unicode)) if ((is_bstr and revision.isdigit() and len(revision) < 12) or isinstance(revision, int) or is_null(revision)): try: revision = self.revisions[int(revision)] except IndexError: msg = ("Revision %s does not exist for %s" % (revision, self)) raise ChangesetDoesNotExistError(msg) elif is_bstr: # get by branch/tag name _ref_revision = self._parsed_refs.get(revision) if _ref_revision: # and _ref_revision[1] in ['H', 'RH', 'T']: return _ref_revision[0] _tags_shas = self.tags.values() # maybe it's a tag ? we don't have them in self.revisions if revision in _tags_shas: return _tags_shas[_tags_shas.index(revision)] elif not SHA_PATTERN.match( revision) or revision not in self.revisions: msg = ("Revision %s does not exist for %s" % (revision, self)) raise ChangesetDoesNotExistError(msg) # Ensure we return full id if not SHA_PATTERN.match(str(revision)): raise ChangesetDoesNotExistError( "Given revision %s not recognized" % revision) return revision