Beispiel #1
0
    def _commit_phase_1(self, s, mid):
        request = self.socket[s][Response][mid]
        txn = request['txn']
        head = request['cur head']

        # if this change is already committed then we have nothing to do
        if self.branchmapdb.has_key(request['head']) and is_ancestor(
                self, request['head'], head, None):
            request['no phase 2'] = 1
            return

        sync_history(self, request['head'], txn, cache=request['changes'])

        if self.config.getboolean('control', 'backup'):
            if not is_ancestor(self, request['cur head'], request['head'],
                               txn):
                raise HistoryError, 'not an incremental backup'

            point = request['head']
            while point != rootnode:
                if point == request['cur head']:
                    break
                pinfo = bdecode(self.lcrepo.get(point, txn=txn))
                if not clean_merge_point(pinfo):
                    raise HistoryError, 'not an incremental backup'
                point = pinfo['precursors'][0]

        modified = handles_in_branch(self, [head], [request['head']], txn)[1]
        unlocked = self._lock_files(s, mid, modified)

        # bump the reference count by the locks we don't have
        request['count'] += len(unlocked)

        # mark all the diff requests which have to wait until we get the lock
        request['diff queue'] = {}
        for handle in unlocked:
            if request['diffs'].has_key(handle):
                request['diff queue'][handle] = 1

        # request all the related file diffs
        for handle, changes in request['diffs'].items():
            if request['diff queue'].has_key(handle):
                request['diff queue'][handle] = changes.keys()
                continue
            requested = 0
            for change in changes.keys():
                requested = 1
                self._queue_diff(s, change, handle, mid)
            request['count'] += requested
        self._get_diff(s, mid)

        # denote the merge checks we have to do later
        rmodified = request['modified'] = {}
        for handle in modified:
            rmodified[handle] = 0
Beispiel #2
0
    def _commit_phase_1(self, s, mid):
        request = self.socket[s][Response][mid]
        txn = request['txn']
        head = request['cur head']

        # if this change is already committed then we have nothing to do
        if self.branchmapdb.has_key(request['head']) and is_ancestor(self, request['head'], head, None):
            request['no phase 2'] = 1
            return

        sync_history(self, request['head'], txn, cache=request['changes'])

        if self.config.getboolean('control', 'backup'):
            if not is_ancestor(self, request['cur head'], request['head'], txn):
                raise HistoryError, 'not an incremental backup'

            point = request['head']
            while point != rootnode:
                if point == request['cur head']:
                    break
                pinfo = bdecode(self.lcrepo.get(point, txn=txn))
                if not clean_merge_point(pinfo):
                    raise HistoryError, 'not an incremental backup'
                point = pinfo['precursors'][0]

        modified = handles_in_branch(self, [head], [request['head']], txn)[1]
        unlocked = self._lock_files(s, mid, modified)

        # bump the reference count by the locks we don't have
        request['count'] += len(unlocked)

        # mark all the diff requests which have to wait until we get the lock
        request['diff queue'] = {}
        for handle in unlocked:
            if request['diffs'].has_key(handle):
                request['diff queue'][handle] = 1

        # request all the related file diffs
        for handle, changes in request['diffs'].items():
            if request['diff queue'].has_key(handle):
                request['diff queue'][handle] = changes.keys()
                continue
            requested = 0
            for change in changes.keys():
                requested = 1
                self._queue_diff(s, change, handle, mid)
            request['count'] += requested
        self._get_diff(s, mid)

        # denote the merge checks we have to do later
        rmodified = request['modified'] = {}
        for handle in modified:
            rmodified[handle] = 0
Beispiel #3
0
    def gen_file_points(prune):
        file_points, points = [], ['1']

        true_pre_heads = simplify_precursors(co, handle, co.contents,
                                             pre_heads, txn)[0]

        # don't use pre_heads which are ancestors of rhead
        for pre, index in true_pre_heads:
            if prune and is_ancestor(co, pre, rhead, txn):
                continue

            info = handle_contents_at_point(co, handle, pre, txn, dcache=dcache)
            if info is None:
                continue
            points = dmerge(points, info['points'])
            file_points.append((info['lines'], info['line points'], info['points']))
        return (file_points, points)
Beispiel #4
0
    def _response_get_diff(self, s, mid, msg, rstate):
        lstate = self.socket[s][Response][rstate['ref']]

        # send out the next one
        lstate['req-outstanding'] -= 1
        self._get_diff(s, rstate['ref'])

        handle = rstate['handle']

        diffs = lstate['diffs']
        diffs[handle][rstate['change']] = msg['diff']
        del self.socket[s][Request][mid]

        lstate['counts'][handle] -= 1
        if lstate['counts'][handle] == 0:
            lstate['count'] -= 1

            # write out the diffs
            WD = WriteDiff(self, handle, lstate['txn'])
            for change, diff in diffs[handle].items():
                WD.write(diff, change)
            WD.close()

            # XXX: suboptimal
            change = handle_last_modified(self, self.contents, handle,
                                          lstate['cur head'], lstate['txn'])
            if change is None or is_ancestor(self, change, lstate['head'],
                                             lstate['txn']):
                handle_contents_at_point(self,
                                         handle,
                                         lstate['head'],
                                         lstate['txn'],
                                         dcache=diffs[handle])
                assert lstate['modified'].has_key(handle)
                lstate['modified'][handle] = 1

            del diffs[handle]

        try:
            if lstate['count'] == 0:
                self._commit_phase_2(s, rstate['ref'])
        except HistoryError, msg:
            self._commit_fail(s, rstate['ref'], str(msg))
            return
Beispiel #5
0
    def gen_file_points(prune):
        file_points, points = [], ['1']

        true_pre_heads = simplify_precursors(co, handle, co.contents,
                                             pre_heads, txn)[0]

        # don't use pre_heads which are ancestors of rhead
        for pre, index in true_pre_heads:
            if prune and is_ancestor(co, pre, rhead, txn):
                continue

            info = handle_contents_at_point(co,
                                            handle,
                                            pre,
                                            txn,
                                            dcache=dcache)
            if info is None:
                continue
            points = dmerge(points, info['points'])
            file_points.append(
                (info['lines'], info['line points'], info['points']))
        return (file_points, points)
Beispiel #6
0
    def _response_get_diff(self, s, mid, msg, rstate):
        lstate = self.socket[s][Response][rstate['ref']]

        # send out the next one
        lstate['req-outstanding'] -= 1
        self._get_diff(s, rstate['ref'])

        handle = rstate['handle']

        diffs = lstate['diffs']
        diffs[handle][rstate['change']] = msg['diff']
        del self.socket[s][Request][mid]

        lstate['counts'][handle] -= 1
        if lstate['counts'][handle] == 0:
            lstate['count'] -= 1

            # write out the diffs
            WD = WriteDiff(self, handle, lstate['txn'])
            for change, diff in diffs[handle].items():
                WD.write(diff, change)
            WD.close()

            # XXX: suboptimal
            change = handle_last_modified(self, self.contents, handle, lstate['cur head'], lstate['txn'])
            if change is None or is_ancestor(self, change, lstate['head'], lstate['txn']):
                handle_contents_at_point(self, handle, lstate['head'], lstate['txn'], dcache=diffs[handle])
                assert lstate['modified'].has_key(handle)
                lstate['modified'][handle] = 1

            del diffs[handle]

        try:
            if lstate['count'] == 0:
                self._commit_phase_2(s, rstate['ref'])
        except HistoryError, msg:
            self._commit_fail(s, rstate['ref'], str(msg))
            return