

def _linearise(self, branch, sequence, previous_import):
    counter = (len(sequence) - 1)
    ancestors = set()
    self._set_branch(branch, previous_import, checkout=True, force=True)
    root = previous_import.hexsha
    while (counter > 0):
        ancestors.add(root)
        for idx in xrange((counter - 1), (- 1), (- 1)):
            commit = sequence[idx]
            if (len(commit.parents) < 2):
                ancestors.add(commit.hexsha)
            elif any(((p.hexsha not in ancestors) for p in commit.parents)):
                self.log.debug('Rebase upto commit SHA1: %s', commit.hexsha)
                idx = (idx + 1)
                break
            else:
                ancestors.add(commit.hexsha)
        tip = sequence[idx].hexsha
        self.log.info('Rebasing from %s to %s', root, tip)
        previous = self.git.rev_parse(branch)
        self.log.info("Rebasing onto '%s'", previous)
        if ((root == previous) and (idx == 0)):
            self.log.info('Already in a linear layout')
            return
        self._set_branch(branch, tip, force=True)
        try:
            self.log.debug('\n                        git rebase -p --onto=%s \\\n                            %s %s\n                    ', previous, root, branch)
            self.git.rebase(root, branch, onto=previous, p=True)
        except Exception:
            self.git.rebase(abort=True, with_exceptions=False)
            raise
        counter = (idx - 1)
        root = sequence[branch].hexsha

dataset/ETHPy150Open openstack/git-upstream/git_upstream/lib/importupstream.py ImportUpstream._linearise/VarMisuse@349/470 `counter`->`branch`