Пример #1
0
def check_max_diff(ctx, wfile):
    try:
        fctx = ctx.filectx(wfile)
        size = fctx.size()
        if not os.path.isfile(ctx._repo.wjoin(wfile)):
            return []
    except (EnvironmentError, error.LookupError):
        return []
    if size > hglib.getmaxdiffsize(ctx._repo.ui):
        # Fake patch that displays size warning
        lines = ['diff --git a/%s b/%s\n' % (wfile, wfile)]
        lines.append(_('File is larger than the specified max size.\n'))
        lines.append(_('Hunk selection is disabled for this file.\n'))
        lines.append('--- a/%s\n' % wfile)
        lines.append('+++ b/%s\n' % wfile)
        return lines
    try:
        contents = fctx.data()
    except (EnvironmentError, util.Abort):
        return []
    if '\0' in contents:
        # Fake patch that displays binary file warning
        lines = ['diff --git a/%s b/%s\n' % (wfile, wfile)]
        lines.append(_('File is binary.\n'))
        lines.append(_('Hunk selection is disabled for this file.\n'))
        lines.append('--- a/%s\n' % wfile)
        lines.append('+++ b/%s\n' % wfile)
        return lines
    return []
Пример #2
0
    def append_diff(self, wfile):
        if not wfile:
            return
        buf, rev = self._buffer, self.currev
        n1, n2 = self.curnodes

        eob = buf.get_end_iter()
        offset = eob.get_offset()

        size = 0
        try:
            ctx = self.repo[rev]
            if wfile in ctx:
                fctx = ctx.filectx(wfile)
                size = fctx._filelog.rawsize(fctx.filerev())
        except error.LookupError:
            pass
        if size > hglib.getmaxdiffsize(self.repo.ui):
            lines = ['diff',
                    _(' %s is larger than the specified max diff size') % wfile]
        else:
            lines = []
            M, A, R = self.changes
            if wfile in M:
                changes = [wfile], [], []
            elif wfile in A:
                changes = [], [wfile], []
            else:
                changes = [], [], [wfile]
            opts = mdiff.diffopts(git=True, nodates=True)
            try:
                for s in patch.diff(self.repo, n1, n2, changes=changes, opts=opts):
                    lines.extend(s.splitlines())
            except (error.RepoError, error.LookupError), e:
                err = _('Repository Error:  %s, refresh suggested') % str(e)
                lines = ['diff', '', err]