def get_changesets(self, start=None, end=None, start_date=None, end_date=None, branch_name=None, reverse=False): """ Returns iterator of ``MercurialChangeset`` objects from start to end (both are inclusive) :param start: None, str, int or mercurial lookup format :param end: None, str, int or mercurial lookup format :param start_date: :param end_date: :param branch_name: :param reversed: return changesets in reversed order """ start_raw_id = self._get_revision(start) start_pos = self.revisions.index(start_raw_id) if start else None end_raw_id = self._get_revision(end) end_pos = self.revisions.index(end_raw_id) if end else None if None not in [start, end] and start_pos > end_pos: raise RepositoryError("Start revision '%s' cannot be " "after end revision '%s'" % (start, end)) if branch_name and branch_name not in self.allbranches.keys(): raise BranchDoesNotExistError('Branch %s not found in' ' this repository' % branch_name) if end_pos is not None: end_pos += 1 #filter branches filter_ = [] if branch_name: filter_.append('branch("%s")' % (branch_name)) if start_date and not end_date: filter_.append('date(">%s")' % start_date) if end_date and not start_date: filter_.append('date("<%s")' % end_date) if start_date and end_date: filter_.append('date(">%s") and date("<%s")' % (start_date, end_date)) if filter_: revisions = scmutil.revrange(self._repo, filter_) else: revisions = self.revisions revs = revisions[start_pos:end_pos] if reverse: revs = reversed(revs) return CollectionGenerator(self, revs)
def _get_changesets(self, org_repo, org_ref, other_repo, other_ref, discovery_data): """ Returns a list of changesets that are incoming from org_repo@org_ref to other_repo@other_ref :param org_repo: :type org_repo: :param org_ref: :type org_ref: :param other_repo: :type other_repo: :param other_ref: :type other_ref: :param tmp: :type tmp: """ changesets = [] #case two independent repos common, incoming, rheads = discovery_data if org_repo != other_repo and incoming: obj = findcommonoutgoing(org_repo._repo, localrepo.locallegacypeer(other_repo._repo.local()), force=True) revs = obj.missing for cs in reversed(map(binascii.hexlify, revs)): changesets.append(org_repo.get_changeset(cs)) else: _revset_predicates = { 'branch': 'branch', 'book': 'bookmark', 'tag': 'tag', 'rev': 'id', } revs = [ "ancestors(%s('%s')) and not ancestors(%s('%s'))" % ( _revset_predicates[org_ref[0]], org_ref[1], _revset_predicates[other_ref[0]], other_ref[1] ) ] out = scmutil.revrange(org_repo._repo, revs) for cs in reversed(out): changesets.append(org_repo.get_changeset(cs)) return changesets
def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref, merge): """ Returns a list of changesets that can be merged from org_repo@org_ref to other_repo@other_ref ... and the ancestor that would be used for merge :param org_repo: :param org_ref: :param other_repo: :param other_ref: :param tmp: """ ancestor = None if alias == 'hg': # lookup up the exact node id _revset_predicates = { 'branch': 'branch', 'book': 'bookmark', 'tag': 'tag', 'rev': 'id', } org_rev_spec = "%s('%s')" % (_revset_predicates[org_ref[0]], safe_str(org_ref[1])) if org_ref[1] == EmptyChangeset().raw_id: org_rev = org_ref[1] else: org_rev = org_repo._repo[scmutil.revrange(org_repo._repo, [org_rev_spec])[-1]] other_rev_spec = "%s('%s')" % (_revset_predicates[other_ref[0]], safe_str(other_ref[1])) if other_ref[1] == EmptyChangeset().raw_id: other_rev = other_ref[1] else: other_rev = other_repo._repo[scmutil.revrange(other_repo._repo, [other_rev_spec])[-1]] #case two independent repos if org_repo != other_repo: hgrepo = unionrepo.unionrepository(other_repo.baseui, other_repo.path, org_repo.path) # all the changesets we are looking for will be in other_repo, # so rev numbers from hgrepo can be used in other_repo #no remote compare do it on the same repository else: hgrepo = other_repo._repo if merge: revs = ["ancestors(id('%s')) and not ancestors(id('%s')) and not id('%s')" % (other_rev, org_rev, org_rev)] ancestors = scmutil.revrange(hgrepo, ["ancestor(id('%s'), id('%s'))" % (org_rev, other_rev)]) if len(ancestors) == 1: ancestor = hgrepo[ancestors[0]].hex() else: # TODO: have both + and - changesets revs = ["id('%s') :: id('%s') - id('%s')" % (org_rev, other_rev, org_rev)] changesets = [other_repo.get_changeset(cs) for cs in scmutil.revrange(hgrepo, revs)] elif alias == 'git': assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos so, se = org_repo.run_git_command( 'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1], other_ref[1]) ) changesets = [org_repo.get_changeset(cs) for cs in re.findall(r'[0-9a-fA-F]{40}', so)] return changesets, ancestor
def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref, discovery_data): """ Returns a list of changesets that are incoming from org_repo@org_ref to other_repo@other_ref :param org_repo: :param org_ref: :param other_repo: :param other_ref: :param tmp: """ changesets = [] #case two independent repos common, incoming, rheads = discovery_data if org_repo != other_repo: revs = [ org_repo._repo.lookup(org_ref[1]), org_repo._repo.lookup(other_ref[1]), ] obj = findcommonoutgoing(org_repo._repo, localrepo.locallegacypeer(other_repo._repo.local()), revs, force=True) revs = obj.missing for cs in map(binascii.hexlify, revs): _cs = org_repo.get_changeset(cs) changesets.append(_cs) # in case we have revisions filter out the ones not in given range if org_ref[0] == 'rev' and other_ref[0] == 'rev': revs = [x.raw_id for x in changesets] start = org_ref[1] stop = other_ref[1] changesets = changesets[revs.index(start):revs.index(stop) + 1] else: #no remote compare do it on the same repository if alias == 'hg': _revset_predicates = { 'branch': 'branch', 'book': 'bookmark', 'tag': 'tag', 'rev': 'id', } revs = [ "ancestors(%s('%s')) and not ancestors(%s('%s'))" % ( _revset_predicates[other_ref[0]], other_ref[1], _revset_predicates[org_ref[0]], org_ref[1], ) ] out = scmutil.revrange(org_repo._repo, revs) for cs in (out): changesets.append(org_repo.get_changeset(cs)) elif alias == 'git': so, se = org_repo.run_git_command( 'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1], other_ref[1]) ) ids = re.findall(r'[0-9a-fA-F]{40}', so) for cs in (ids): changesets.append(org_repo.get_changeset(cs)) return changesets