Example #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)
Example #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)
Example #3
0
def svndiff_main():
    """
    Main program for svn-diff script.
    """
    opts, args = parse_options()

    # Compute the location of the resilient directory for the comments and
    # history files (and maybe more stuff later on).
    resildir = xxdiff.resilient.resilient_for_paths(args)
    hist = xxdiff.history.History(opts, resildir)

    # Compute a list of files to ignore (e.g. if the comments or history file is
    # located in the checkout, we want to ignore them and then associated
    # swap/temp files).
    ignofiles = []
    if opts.commit and opts.comments_file:
        comfn = abspath(opts.comments_file)
        ignofiles.extend([comfn, '%s.swp' % comfn])
    if opts.history and opts.history_file:
        histfn = abspath(opts.history_file)
        ignofiles.extend([histfn, '%s.swp' % histfn])

    if opts.foreign:
        # Consider the unregistered files.
        if query_unregistered_svn_files(args,
                                        opts,
                                        sys.stdout,
                                        ignore=ignofiles) is not True:
            # The user has quit, don't continue.
            sys.exit(0)
        print()
        print()

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

    # Ignore the comments file from the svn status output.
    statii = [s for s in statii if abspath(s.filename) not in ignofiles]

    if not statii:
        print('(Nothing to do, exiting.)')
        hist.delete()
        return

    # First print out the status to a string.
    renstatus = os.linesep.join(x.parsed_line for x in statii)

    if opts.commit:
        # File to delete after a successful commit.
        if opts.comments_file:
            comfn = abspath(opts.comments_file)
        else:
            # Select a comments file and make sure that it exists.
            comfn = join(resildir, 'comments')

            makedirs(resildir, False)
            if not exists(comfn):
                open(comfn, 'w')

    # Spawn an editor if requested before starting the review.
    if opts.commit:
        m = {'date': datetime.datetime.now()}
        comments = None  # renstatus
        edit_waiter = xxdiff.editor.spawn_editor(comments, filename=comfn)

    # First print out the status to the user.
    print('Status Of Files To Be Diffed')
    print('----------------------------')
    print(renstatus)

    # Then we start printing each file and the associated decision.
    msgfmt = '  %-10s | %-10s | %s'
    print()
    print(msgfmt % ('Type', 'Action', 'Status'))
    print(msgfmt % ('-' * 10, '-' * 10, '-' * 40))

    # Main loop for graphical diffs, over each of the files reported by status.
    for s in statii:
        kind, action = 'unknown', 'exception'  # Initialize for in case of an
        # exception.
        try:
            # Skip directories.
            if isdir(s.filename):
                kind, action = 'directory', 'skip'
                continue
            elif islink(s.filename):
                kind, action = 'symlink', 'skip'
                continue

            # Compute unique string for history recorder.  We use the size, last
            # modification time, and status info to hash on this.
            if exists(s.filename):
                fstat = os.lstat(s.filename)
                sz, mtime = fstat.st_size, fstat.st_mtime
            else:
                # Deal with files that have been deleted.
                sz, mtime = 0, 0
            histitem = ' '.join((str(sz), str(mtime), s.parsed_line))

            # If the file has already been reviewed in the history, skip it.
            if hist.check(histitem):
                kind, action = 'seen', 'skip'
                continue

            # Review the file.
            (kind, action), waiter = review_file(s, opts)
        finally:
            print(msgfmt % (kind, action, s.parsed_line))

        if waiter is not None:
            waiter()

        # We have succesfully finished viewing the file, add it to the history.
        hist.append(histitem)

    # Commit the files if requested.
    if opts.commit:
        print("\nWaiting for editor '%s' to complete..." % edit_waiter.command,
              end='')
        sys.stdout.flush()
        comments = edit_waiter()
        print('Done.\n')
        print('Recorded Merge Comments: ', end='')
        if comments == '':
            print('(None)')
            comments = None
        else:
            print()
            print('-' * 70)
            print(comments)
            print('-' * 70)

        subversion.commit(args, comments=comments)

        # Delete temporary comments flie if we created it.
        if not opts.comments_file:
            xxdiff.resilient.resilient_remove(comfn)

    # The entire list of files has been reviewed (and possibly committed), clear
    # the history file.
    if opts.history:
        print()
        print('(Review complete, history cleared)')
        hist.delete()
Example #4
0
def svndiff_main():
    """
    Main program for svn-diff script.
    """
    opts, args = parse_options()

    # Compute the location of the resilient directory for the comments and
    # history files (and maybe more stuff later on).
    resildir = xxdiff.resilient.resilient_for_paths(args)
    hist = xxdiff.history.History(opts, resildir)

    # Compute a list of files to ignore (e.g. if the comments or history file is
    # located in the checkout, we want to ignore them and then associated
    # swap/temp files).
    ignofiles = []
    if opts.commit and opts.comments_file:
        comfn = abspath(opts.comments_file)
        ignofiles.extend([comfn, '%s.swp' % comfn])
    if opts.history and opts.history_file:
        histfn = abspath(opts.history_file)
        ignofiles.extend([histfn, '%s.swp' % histfn])

    if opts.foreign:
        # Consider the unregistered files.
        if query_unregistered_svn_files(
            args, opts, sys.stdout, ignore=ignofiles) is not True:
            # The user has quit, don't continue.
            sys.exit(0)
        print
        print

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

    # Ignore the comments file from the svn status output.
    statii = [s for s in statii if abspath(s.filename) not in ignofiles]

    if not statii:
        print '(Nothing to do, exiting.)'
        hist.delete()
        return

    # First print out the status to a string.
    renstatus = os.linesep.join(x.parsed_line for x in statii)

    if opts.commit:
        # File to delete after a successful commit.
        if opts.comments_file:
            comfn = abspath(opts.comments_file)
        else:
            # Select a comments file and make sure that it exists.
            comfn = join(resildir, 'comments')

            makedirs(resildir, False)
            if not exists(comfn):
                open(comfn, 'w')

    # Spawn an editor if requested before starting the review.
    if opts.commit:
        m = {'date': datetime.datetime.now()}
        comments = None # renstatus
        edit_waiter = xxdiff.editor.spawn_editor(comments, filename=comfn)

    # First print out the status to the user.
    print 'Status Of Files To Be Diffed'
    print '----------------------------'
    print renstatus

    # Then we start printing each file and the associated decision.
    msgfmt = '  %-10s | %-10s | %s'
    print
    print msgfmt % ('Type', 'Action', 'Status')
    print msgfmt % ('-'*10, '-'*10, '-'*40)

    # Main loop for graphical diffs, over each of the files reported by status.
    for s in statii:
        kind, action = 'unknown', 'exception' # Initialize for in case of an
                                              # exception.
        try:
            # Skip directories.
            if isdir(s.filename):
                kind, action = 'directory', 'skip'
                continue
            elif islink(s.filename):
                kind, action = 'symlink', 'skip'
                continue

            # Compute unique string for history recorder.  We use the size, last
            # modification time, and status info to hash on this.
            if exists(s.filename):
                fstat = os.lstat(s.filename)
                sz, mtime = fstat.st_size, fstat.st_mtime
            else:
                # Deal with files that have been deleted.
                sz, mtime = 0, 0
            histitem = ' '.join((str(sz), str(mtime), s.parsed_line))

            # If the file has already been reviewed in the history, skip it.
            if hist.check(histitem):
                kind, action = 'seen', 'skip'
                continue

            # Review the file.
            (kind, action), waiter = review_file(s, opts)
        finally:
            print msgfmt % (kind, action, s.parsed_line)

        if waiter is not None:
            waiter()

        # We have succesfully finished viewing the file, add it to the history.
        hist.append(histitem)

    # Commit the files if requested.
    if opts.commit:
        print "\nWaiting for editor '%s' to complete..." % edit_waiter.command,
        sys.stdout.flush()
        comments = edit_waiter()
        print 'Done.\n'
        print 'Recorded Merge Comments: ',
        if comments == '':
            print '(None)'
            comments = None
        else:
            print
            print '-' * 70
            print comments
            print '-' * 70

        subversion.commit(args, comments=comments)

        # Delete temporary comments flie if we created it.
        if not opts.comments_file:
            xxdiff.resilient.resilient_remove(comfn)

    # The entire list of files has been reviewed (and possibly committed), clear
    # the history file.
    if opts.history:
        print
        print '(Review complete, history cleared)'
        hist.delete()