Esempio n. 1
0
def svnresolve_main():
    """
    Main program for svn-resolve script.
    """
    opts, args = parse_options()

    # Get the status of the working copy.
    statii = subversion.status(args)

    # First print out the list/status of the conflicting files to the user.
    for s in select_conflicts(statii):
        print(s.parsed_line)
    print()

    logs = sys.stdout

    # For each of the files reported by status
    for s in select_conflicts(statii):

        # Get the three files before the merge conflicts.
        info = subversion.getinfo(s.filename)
        dn = dirname(s.filename)
        ancestor, mine, yours = [join(dn, info[x]) for x in
                                 ('Conflict Previous Base File',
                                  'Conflict Previous Working File',
                                  'Conflict Current Base File')]

        # Spawn xxdiff in decision mode on the three files. We dispatch to the
        # encrypted version if necessary.
        if re.match('.*\.asc', s.filename):
            tmine = open(mine).read()
            tancestor = open(ancestor).read()
            tyours = open(yours).read()
            decision = diff_encrypted([tmine, tancestor, tyours], opts, outmerged=s.filename)
        else:
            decision = xxdiff.condrepl.cond_resolve(
                mine, ancestor, yours, s.filename, opts, logs, extra=('--merge',))

        # Backup all the other files that will get when the file gets resolved,
        # whether by this script or later by the user by hand.
        if decision in xxdiff.condrepl.proper_decisions:
            xxdiff.backup.backup_file(mine, opts, logs)
            xxdiff.backup.backup_file(ancestor, opts, logs)
            xxdiff.backup.backup_file(yours, opts, logs)
        else:
            # If no proper decision has been made, do not resolve.
            continue

        # Resolve the conflict with Subversion, if requested.
        if not opts.no_resolve:
            subversion.resolve(s.filename)
            print('(Resolved.)')

    xxdiff.backup.print_reminder(opts)
Esempio n. 2
0
def svnresolve_main():
    """
    Main program for svn-resolve script.
    """
    opts, args = parse_options()

    # Get the status of the working copy.
    statii = subversion.status(args)

    # First print out the list/status of the conflicting files to the user.
    for s in select_conflicts(statii):
        print s.parsed_line
    print

    logs = sys.stdout

    # For each of the files reported by status
    for s in select_conflicts(statii):

        # Get the three files before the merge conflicts.
        info = subversion.getinfo(s.filename)
        dn = dirname(s.filename)
        ancestor, mine, yours = [join(dn, info[x]) for x in
                                 ('Conflict Previous Base File',
                                  'Conflict Previous Working File',
                                  'Conflict Current Base File')]

        # Spawn xxdiff in decision mode on the three files. We dispatch to the
        # encrypted version if necessary.
        if re.match('.*\.asc', s.filename):
            tmine = open(mine).read()
            tancestor = open(ancestor).read()
            tyours = open(yours).read()
            decision = diff_encrypted([tmine, tancestor, tyours], opts, outmerged=s.filename)
        else:
            decision = xxdiff.condrepl.cond_resolve(
                mine, ancestor, yours, s.filename, opts, logs, extra=('--merge',))

        # Backup all the other files that will get when the file gets resolved,
        # whether by this script or later by the user by hand.
        if decision in xxdiff.condrepl.proper_decisions:
            xxdiff.backup.backup_file(mine, opts, logs)
            xxdiff.backup.backup_file(ancestor, opts, logs)
            xxdiff.backup.backup_file(yours, opts, logs)
        else:
            # If no proper decision has been made, do not resolve.
            continue

        # Resolve the conflict with Subversion, if requested.
        if not opts.no_resolve:
            subversion.resolve(s.filename)
            print '(Resolved.)'

    xxdiff.backup.print_reminder(opts)
Esempio n. 3
0
def review_file(sobj, opts):
    """
    Check the given status object and if necessary, spawn xxdiff on it.

    Return a pair of ((file type description, action) waiter-object).
    """
    msg = ('normal', 'display')
    dopts = []
    merged = sobj.filename
    try:
        # Ignore unmodified files if there are any.
        if sobj.status in (' ', '?'):
            msg = ('unmodified', 'ignored')
            return msg, None

        # Diff modified files
        if sobj.status in ('M', 'C'):
            tmpf = subversion.cat_revision_temp(sobj.filename, 'BASE')
            left, right = tmpf.name, sobj.filename

            dopts.extend(title_opts('%s (BASE)' % sobj.filename))

        # Diff added files
        elif sobj.status == 'A':
            # Check if it is a directory.
            if not isfile(sobj.filename):
                msg = ('directory', 'skip')
                return msg, None

            if sobj.withhist == '+':
                # Get the source filename from the history.
                info = subversion.getinfo(sobj.filename)
                from_url, from_rev = [
                    info.get('Copied From %s' % x, None)
                    for x in ['URL', 'Rev']
                ]

                tmpf = subversion.cat_revision_temp(sobj.filename, 'BASE')
                dopts.extend(title_opts('%s (%s)' % (from_url, from_rev)))
            else:
                tmpf = tempfile.NamedTemporaryFile(mode='w', prefix=tmpprefix)
                dopts.extend(title_opts('(NON-EXISTING)'))

            left, right = tmpf.name, sobj.filename

        # Diff deleted files
        elif sobj.status == 'D':
            tmpf = subversion.cat_revision_temp(sobj.filename, 'BASE')
            tmpf_empty = tempfile.NamedTemporaryFile(mode='w',
                                                     prefix=tmpprefix)

            dopts.extend(title_opts('%s (BASE)' % sobj.filename, '(DELETED)'))

            left, right = tmpf.name, tmpf_empty.name

        # We don't know what to do with the rest yet.
        else:
            msg = ('unknown', 'ignored')
            print(("Error: Action for status '%s' on file '%s' "
                   "is not implemented yet") % (sobj.status, sobj.filename),
                  file=sys.stderr)
            return msg, None
    finally:
        pass

    # Check for non-text files.
    if not xxdiff.utils.istextfile(left) or not xxdiff.utils.istextfile(right):
        return ('non-text', 'skip'), None

    # Run xxdiff on the files.
    if opts.review:
        dopts.extend(['--decision'])
        opts.no_confirm = False
        opts.dry_run = False
        decision = xxdiff.condrepl.cond_replace(left,
                                                right,
                                                opts,
                                                sys.stdout,
                                                False,
                                                replfn=right)
        waiter = None
    else:
        waiter = xxdiff.invoke.xxdiff_display(opts,
                                              left,
                                              right,
                                              nowait=1,
                                              *dopts)

    return msg, waiter
Esempio n. 4
0
def review_file(sobj, opts):
    """
    Check the given status object and if necessary, spawn xxdiff on it.

    Return a pair of ((file type description, action) waiter-object).
    """
    msg = ('normal', 'display')
    dopts = []
    merged = sobj.filename
    try:
        # Ignore unmodified files if there are any.
        if sobj.status in (' ', '?'):
            msg = ('unmodified', 'ignored')
            return msg, None

        # Diff modified files
        if sobj.status in ('M', 'C'):
            tmpf = subversion.cat_revision_temp(sobj.filename, 'BASE')
            left, right = tmpf.name, sobj.filename

            dopts.extend(title_opts('%s (BASE)' % sobj.filename))

        # Diff added files
        elif sobj.status == 'A':
            # Check if it is a directory.
            if not isfile(sobj.filename):
                msg = ('directory', 'skip')
                return msg, None

            if sobj.withhist == '+':
                # Get the source filename from the history.
                info = subversion.getinfo(sobj.filename)
                from_url, from_rev = [info.get('Copied From %s' % x, None)
                                      for x in 'URL', 'Rev']

                tmpf = subversion.cat_revision_temp(sobj.filename, 'BASE')
                dopts.extend(title_opts('%s (%s)' % (from_url, from_rev)))
            else:
                tmpf = tempfile.NamedTemporaryFile('w', prefix=tmpprefix)
                dopts.extend(title_opts('(NON-EXISTING)'))

            left, right = tmpf.name, sobj.filename

        # Diff deleted files
        elif sobj.status == 'D':
            tmpf = subversion.cat_revision_temp(sobj.filename, 'BASE')
            tmpf_empty = tempfile.NamedTemporaryFile('w', prefix=tmpprefix)

            dopts.extend(title_opts('%s (BASE)' % sobj.filename,
                                    '(DELETED)'))

            left, right = tmpf.name, tmpf_empty.name

        # We don't know what to do with the rest yet.
        else:
            msg = ('unknown', 'ignored')
            print >> sys.stderr, (
                "Error: Action for status '%s' on file '%s' "
                "is not implemented yet") % (sobj.status, sobj.filename)
            return msg, None
    finally:
        pass

    # Check for non-text files.
    if not xxdiff.utils.istextfile(left) or not xxdiff.utils.istextfile(right):
        return ('non-text', 'skip'), None

    # Run xxdiff on the files.
    if opts.review:
        dopts.extend(['--decision'])
        opts.no_confirm = False
        opts.dry_run = False
        decision = xxdiff.condrepl.cond_replace(left, right, opts, sys.stdout,
                                                False, replfn=right)
        waiter = None
    else:
        waiter = xxdiff.invoke.xxdiff_display(opts, left, right, nowait=1, *dopts)

    return msg, waiter