⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svnmerge.py

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 PY
📖 第 1 页 / 共 5 页
字号:
        self.progname = NAME        self.version = version.replace("%prog", self.progname)        self.cwidth = console_width() - 2        self.ctable = command_table.copy()        self.gopts = global_opts[:]        self.copts = common_opts[:]        self._add_builtins()        for k in self.ctable.keys():            cmd = self.Cmd(k, *self.ctable[k])            opts = []            for o in cmd.opts:                if isinstance(o, types.StringType) or \                   isinstance(o, types.UnicodeType):                    o = self._find_common(o)                opts.append(o)            cmd.opts = opts            self.ctable[k] = cmd    def _add_builtins(self):        self.gopts.append(            Option("-h", "--help", help="show help for this command and exit"))        if self.version is not None:            self.gopts.append(                Option("-V", "--version", help="show version info and exit"))        self.ctable["help"] = (self._cmd_help,            "help [COMMAND]",            "Display help for a specific command. If COMMAND is omitted, "            "display brief command description.",            [])    def _cmd_help(self, cmd=None, *args):        if args:            self.error("wrong number of arguments", "help")        if cmd is not None:            cmd = self._command(cmd)            self.print_command_help(cmd)        else:            self.print_command_list()    def _paragraph(self, text, width=78):        chunks = re.split("\s+", text.strip())        chunks.reverse()        lines = []        while chunks:            L = chunks.pop()            while chunks and len(L) + len(chunks[-1]) + 1 <= width:                L += " " + chunks.pop()            lines.append(L)        return lines    def _paragraphs(self, text, *args, **kwargs):        pars = text.split("\n\n")        lines = self._paragraph(pars[0], *args, **kwargs)        for p in pars[1:]:            lines.append("")            lines.extend(self._paragraph(p, *args, **kwargs))        return lines    def _print_wrapped(self, text, indent=0):        text = self._paragraphs(text, self.cwidth - indent)        print text.pop(0)        for t in text:            print " " * indent + t    def _find_common(self, fl):        for o in self.copts:            if fl in o.lflags+o.sflags:                return o        assert False, fl    def _compute_flags(self, opts, check_conflicts=True):        back = {}        sfl = ""        lfl = []        for o in opts:            sapp = lapp = ""            if isinstance(o, OptionArg):                sapp, lapp = ":", "="            for s in o.sflags:                if check_conflicts and back.has_key(s):                    raise RuntimeError, "option conflict: %s" % s                back[s] = o                sfl += s[1:] + sapp            for l in o.lflags:                if check_conflicts and back.has_key(l):                    raise RuntimeError, "option conflict: %s" % l                back[l] = o                lfl.append(l[2:] + lapp)        return sfl, lfl, back    def _extract_command(self, args):        """        Try to extract the command name from the argument list. This is        non-trivial because we want to allow command-specific options even        before the command itself.        """        opts = self.gopts[:]        for cmd in self.ctable.values():            opts.extend(cmd.opts)        sfl, lfl, _ = self._compute_flags(opts, check_conflicts=False)        lopts,largs = getopt.getopt(args, sfl, lfl)        if not largs:            return None        return self._command(largs[0])    def _fancy_getopt(self, args, opts, state=None):        if state is None:            state= {}        for o in opts:            if not state.has_key(o.dest):                state[o.dest] = o.default        sfl, lfl, back = self._compute_flags(opts)        try:            lopts,args = getopt.gnu_getopt(args, sfl, lfl)        except AttributeError:            # Before Python 2.3, there was no gnu_getopt support.            # So we can't parse intermixed positional arguments            # and options.            lopts,args = getopt.getopt(args, sfl, lfl)        for o,v in lopts:            back[o].apply(state, v)        return state, args    def _command(self, cmd):        if not self.ctable.has_key(cmd):            self.error("unknown command: '%s'" % cmd)        return self.ctable[cmd]    def parse(self, args):        if not args:            self.print_small_help()            sys.exit(0)        cmd = None        try:            cmd = self._extract_command(args)            opts = self.gopts[:]            if cmd:                opts.extend(cmd.opts)                args.remove(cmd.name)            state, args = self._fancy_getopt(args, opts)        except getopt.GetoptError, e:            self.error(e, cmd)        # Handle builtins        if self.version is not None and state["version"]:            self.print_version()            sys.exit(0)        if state["help"]: # special case for --help            if cmd:                self.print_command_help(cmd)                sys.exit(0)            cmd = self.ctable["help"]        else:            if cmd is None:                self.error("command argument required")        if str(cmd) == "help":            cmd(*args)            sys.exit(0)        return cmd, args, state    def error(self, s, cmd=None):        print >>sys.stderr, "%s: %s" % (self.progname, s)        if cmd is not None:            self.print_command_help(cmd)        else:            self.print_small_help()        sys.exit(1)    def print_small_help(self):        print "Type '%s help' for usage" % self.progname    def print_usage_line(self):        print "usage: %s <subcommand> [options...] [args...]\n" % self.progname    def print_command_list(self):        print "Available commands (use '%s help COMMAND' for more details):\n" \              % self.progname        cmds = self.ctable.keys()        cmds.sort()        indent = max(map(len, cmds))        for c in cmds:            h = self.ctable[c].short_help()            print "  %-*s   " % (indent, c),            self._print_wrapped(h, indent+6)    def print_command_help(self, cmd):        cmd = self.ctable[str(cmd)]        print 'usage: %s %s\n' % (self.progname, cmd.usage)        self._print_wrapped(cmd.help)        def print_opts(opts, self=self):            if not opts: return            flags = [o.repr_flags() for o in opts]            indent = max(map(len, flags))            for f,o in zip(flags, opts):                print "  %-*s :" % (indent, f),                self._print_wrapped(o.help, indent+5)        print '\nCommand options:'        print_opts(cmd.opts)        print '\nGlobal options:'        print_opts(self.gopts)    def print_version(self):        print self.version################################################################################ Options and Commands description###############################################################################global_opts = [    Option("-F", "--force",           help="force operation even if the working copy is not clean, or "                "there are pending updates"),    Option("-n", "--dry-run",           help="don't actually change anything, just pretend; "                "implies --show-changes"),    Option("-s", "--show-changes",           help="show subversion commands that make changes"),    Option("-v", "--verbose",           help="verbose mode: output more information about progress"),    OptionArg("-u", "--username",              default=None,              help="invoke subversion commands with the supplied username"),    OptionArg("-p", "--password",              default=None,              help="invoke subversion commands with the supplied password"),]common_opts = [    Option("-b", "--bidirectional",           value=True,           default=False,           help="remove reflected revisions from merge candidates"),    OptionArg("-f", "--commit-file", metavar="FILE",              default="svnmerge-commit-message.txt",              help="set the name of the file where the suggested log message "                   "is written to"),    Option("-M", "--record-only",           value=True,           default=False,           help="do not perform an actual merge of the changes, yet record "                "that a merge happened"),    OptionArg("-r", "--revision",              metavar="REVLIST",              default="",              help="specify a revision list, consisting of revision numbers "                   'and ranges separated by commas, e.g., "534,537-539,540"'),    OptionArg("-S", "--head", "--source",              default=None,              help="specify the head for this branch. It can be either a path,"                   " a full URL, or an unambigous substring of one the paths "                   "for which merge tracking was already initialized. Needed "                   "only to disambiguate in case of multiple merge tracking "                   "(merging from multiple heads)"),]command_table = {    "init": (action_init,    "init [OPTION...] [HEAD]",    """Initialize merge tracking from HEAD on the current working    directory.    If HEAD is specified, all the revisions in HEAD are marked as already    merged; if this is not correct, you can use --revision to specify the    exact list of already-merged revisions.    If HEAD is omitted, then it is computed from the "svn cp" history of the    current working directory (searching back for the branch point); in this    case, %s assumes that no revision has been integrated yet since    the branch point (unless you teach it with --revision).""" % NAME,    [        "-f", "-r", # import common opts    ]),    "avail": (action_avail,    "avail [OPTION...] [PATH]",    """Show unmerged revisions available for PATH as a revision list.    If --revision is given, the revisions shown will be limited to those    also specified in the option.    When svnmerge is used to bidirectionally merge changes between a    branch and its head, it is necessary to not merge the same changes    forth and back: e.g., if you committed a merge of a certain    revision of the branch into the head, you do not want that commit    to appear as available to merged into the branch (as the code    originated in the branch itself!).  svnmerge can not show these    so-called "reflected" revisions if you specify the --bidirectional    or -b command line option.""",    [        Option("-A", "--all",               dest="avail-showwhat",               value=["blocked", "avail"],               default=["avail"],               help="show both available and blocked revisions (aka ignore "                    "blocked revisions)"),        "-b",        Option("-B", "--blocked",               dest="avail-showwhat",               value=["blocked"],               help="show the blocked revision list (see '%s block')" % NAME),        Option("-d", "--diff",               dest="avail-display",               value="diffs",               default="revisions",               help="show corresponding diff instead of revision list"),        Option("-l", "--log",               dest="avail-display",               value="logs",               help="show corresponding log history instead of revision list"),        "-r",        "-S",    ]),    "integrated": (action_integrated,    "integrated [OPTION...] [PATH]",    """Show merged revisions available for PATH as a revision list.    If --revision is given, the revisions shown will be limited to    those also specified in the option.""",    [        Option("-d", "--diff",               dest="integrated-display",               value="diffs",               default="revisions",               help="show corresponding diff instead of revision list"),        Option("-l", "--log",               dest="integrated-display",               value="logs",               help="show corresponding log history instead of revision list"),        "-r",        "-S",    ]),    "rollback": (action_rollback,    "rollback [OPTION...] [PATH]",    """Rollback previously merged in revisions from PATH.  The    --revision option is mandatory, and specifies which revisions    will be rolled back.  Only the previously integrated merges    will be rolled back.    When manually rolling back changes, --record-only can be used to    instruct %s that a manual rollback of a certain revision    already happened, so that it can record it and offer that    revision for merge henceforth.""" % (NAME),    [        "-f", "-r", "-S", "-M", # import common opts    ]),    "merge": (action_merge,    "merge [OPTION...] [PATH]",    """Merge in revisions into PATH from its head. If --revision is omitted,    all the available revisions will be merged. In any case, already merged-in    revisions will NOT be merged again.    When svnmerge is used to bidirectionally merge changes between a    branch and its head, it is necessary to not merge the same changes    forth and back: e.g., if you committed a merge of a certain    revision of the branch into

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -