Beispiel #1
0
 def close(self, rollback=False):
     if rollback:
         GitHgHelper.close(rollback)
         self._closed = True
     if self._closed:
         return
     super(PushStore, self).close()
Beispiel #2
0
 def close(self, rollback=False):
     if rollback:
         GitHgHelper.close(rollback)
         self._closed = True
     if self._closed:
         return
     super(PushStore, self).close()
Beispiel #3
0
 def tearDown(self):
     GitHgHelper.close(rollback=True)
     GitHgHelper._helper = False
     shutil.rmtree(os.environ['GIT_DIR'])
     if self.git_dir is None:
         del os.environ['GIT_DIR']
     else:
         os.environ['GIT_DIR'] = self.git_dir
Beispiel #4
0
 def tearDown(self):
     GitHgHelper.close(rollback=True)
     GitHgHelper._helper = False
     GitHgHelper.git2hg.invalidate()
     GitHgHelper.hg2git.invalidate()
     GitHgHelper._cat_commit.invalidate()
     shutil.rmtree(os.environ['GIT_DIR'])
     if self.git_dir is None:
         del os.environ['GIT_DIR']
     else:
         os.environ['GIT_DIR'] = self.git_dir
Beispiel #5
0
def do_rollback(ref):
    checked = Git.resolve_ref('refs/cinnabar/checked')
    if ref:
        sha1 = Git.resolve_ref(ref)
        if not sha1:
            logging.error('Invalid ref: %s', ref)
            return 1
        if sha1 != NULL_NODE_ID:
            # Validate that the sha1 is in the history of the current metadata
            metadata = Git.resolve_ref('refs/cinnabar/metadata')
            while metadata and metadata != sha1:
                previous_metadata = get_previous_metadata(metadata)
                if checked == metadata:
                    checked = previous_metadata
                metadata = previous_metadata
            if not metadata:
                logging.error('Cannot rollback to %s, it is not in the '
                              'history of the current metadata.', ref)
                return 1
    else:
        metadata = Git.resolve_ref('refs/cinnabar/metadata')
        if metadata:
            sha1 = get_previous_metadata(metadata) or NULL_NODE_ID
        else:
            sha1 = NULL_NODE_ID
        if checked and checked == metadata:
            checked = sha1

    refs = VersionedDict(
        (ref, commit)
        for commit, ref in Git.for_each_ref('refs/cinnabar',
                                            'refs/notes/cinnabar')
    )
    for ref in refs:
        if sha1 == NULL_NODE_ID or ref not in (b'refs/cinnabar/checked',
                                               b'refs/cinnabar/broken'):
            del refs[ref]
    if sha1 != NULL_NODE_ID:
        refs[b'refs/cinnabar/metadata'] = sha1
        if checked:
            refs[b'refs/cinnabar/checked'] = checked
        for line in Git.ls_tree(sha1):
            mode, typ, commit, path = line
            refs[b'refs/cinnabar/replace/%s' % path] = commit

    for status, ref, commit in refs.iterchanges():
        if status == VersionedDict.REMOVED:
            Git.delete_ref(ref)
        else:
            Git.update_ref(ref, commit)
    GitHgHelper.close(rollback=False)

    return 0
Beispiel #6
0
def do_rollback(ref):
    checked = Git.resolve_ref('refs/cinnabar/checked')
    if ref:
        sha1 = Git.resolve_ref(ref)
        if not sha1:
            logging.error('Invalid ref: %s', ref)
            return 1
        if sha1 != NULL_NODE_ID:
            # Validate that the sha1 is in the history of the current metadata
            metadata = Git.resolve_ref('refs/cinnabar/metadata')
            while metadata and metadata != sha1:
                previous_metadata = get_previous_metadata(metadata)
                if checked == metadata:
                    checked = previous_metadata
                metadata = previous_metadata
            if not metadata:
                logging.error('Cannot rollback to %s, it is not in the '
                              'history of the current metadata.', ref)
                return 1
    else:
        metadata = Git.resolve_ref('refs/cinnabar/metadata')
        if metadata:
            sha1 = get_previous_metadata(metadata) or NULL_NODE_ID
        else:
            sha1 = NULL_NODE_ID
        if checked and checked == metadata:
            checked = sha1

    refs = VersionedDict(
        (ref, commit)
        for commit, ref in Git.for_each_ref('refs/cinnabar',
                                            'refs/notes/cinnabar')
    )
    for ref in refs:
        if ref not in ('refs/cinnabar/checked', 'refs/cinnabar/broken'):
            del refs[ref]
    if sha1 != NULL_NODE_ID:
        refs['refs/cinnabar/metadata'] = sha1
        if checked:
            refs['refs/cinnabar/checked'] = checked
        for line in Git.ls_tree(sha1):
            mode, typ, commit, path = line
            refs['refs/cinnabar/replace/%s' % path] = commit

    for status, ref, commit in refs.iterchanges():
        if status == VersionedDict.REMOVED:
            Git.delete_ref(ref)
        else:
            Git.update_ref(ref, commit)
    GitHgHelper.close(rollback=False)

    return 0
Beispiel #7
0
 def tearDown(self):
     GitHgHelper.close(rollback=True)
     GitHgHelper._helper = False