From: Eric S. Raymond Date: Sat, 8 Nov 2014 19:26:42 +0000 (-0500) Subject: move and copy implemented and documentedmn not yet in regression test. X-Git-Tag: 0.2~7 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=2df1a59d0671919ecb0a38152f645f7fdf70adf7;p=src.git move and copy implemented and documentedmn not yet in regression test. Regression test passes. --- diff --git a/TODO b/TODO index 62e1d34..ccf5a64 100644 --- a/TODO +++ b/TODO @@ -2,10 +2,6 @@ * src branch -* src rename/mv - -* src remove/rm - * src fast-import * vc.el diff --git a/src b/src index 99d99b9..c2befc3 100755 --- a/src +++ b/src @@ -299,6 +299,17 @@ src diff ['revision-spec'] ['file'...] the working copy against the last version checked in. With one revno, diffs the working copy against that stored revision; with a range, +src ls + List all registered files. + +src move 'old' 'new' + Rename a file and its master. Refuses to step on existing files or masters. + 'mv' and 'rename' are synonyms. + +src copy 'old' 'new' + Rename a file and its master. Refuses to step on existing files or masters. + 'cp' is a synonym. + src moveto 'directory' ['file'...] Moves files and their histories to another directory. @@ -309,8 +320,7 @@ src fast-export ['file'...] Export one or more projects to standard output as a git fast-import stream. The committer identification is copied from your Git configuration. -src ls - List all registered files. +The omission of 'src remove' is a deliberate speed bump. """ def init_method(*args): @@ -702,6 +712,31 @@ def copyto_method(*args): "Copy a file and its history to another directory." dircmd("copyto", backend.copyto, args) +def filecmd(legend, hook, args): + (revspec, args) = preamble(legend, args) + if revspec is not None: + croak("%s doesn't take a revision spec" % legend) + elif len(args) != 2: + croak("%s requires exactly two arguments" % legend) + (source, target) = args + if not os.path.exists(source): + croak("I see no '%s' here." % source) + elif not os.path.exists(backend.master(source)): + croak("%s is not registered, skipping." % source) + elif os.path.exists(backend.master(target)): + croak("%s is registered, I won't step on it") + elif os.path.exists(target): + croak("%s exists, please delete manually if you want it gone") + hook(src, target) + +def move_method(*args): + "Move a file and its history." + filecmd("move", backend.move, args) + +def copy_method(*args): + "Copy a file and its history." + filecmd("copy", backend.copy, args) + def ls_method(*args): "List registered files." if args: @@ -732,6 +767,11 @@ dispatch = { "moveto": moveto_method, "copyto": copyto_method, "ls": ls_method, + "move": move_method, + "mv": move_method, + "rename": move_method, + "copy": copy_method, + "cp": copy_method, } class RCS: @@ -771,6 +811,16 @@ class RCS: def set_tag(self, tagname, revision, arg): "Set a specified tag." do_or_die("rcs -N{0}:{1} {2}".format(tagname, revision, arg)) + def move(self, source, target): + "Move a file and its history." + do_or_die("mv {0} {1} && mv {2} {3]".format(source, target, + self.master(source), + self.master(target))) + def copy(self, source, target): + "Copy a file and its history." + do_or_die("cp {0} {1} && cp {2} {3]".format(source, target, + self.master(source), + self.master(target))) def moveto(self, arg, target): "Move a file and its history to a target directory." # Using mv(1) evades cross-filesystem issues diff --git a/src.asc b/src.asc index dbfb89b..8ad683a 100644 --- a/src.asc +++ b/src.asc @@ -49,52 +49,62 @@ src init:: src add ['file'...] Initialize new project histories for specified files. -src commit [- | -m commentstring | -f commentfile] ['file'...] +src commit [- | -m commentstring | -f commentfile] ['file'...]:: Enters a commit for specified files. Separately to each one. With '-', take comment text from stdin; with '-m' use the following string as the comment;with '-f' take from a file. ci is a synonym for commit. -src checkout [revision-spec] ['file'...] +src checkout [revision-spec] ['file'...]:: Refresh the working copy of the file(s) from their history files. co is a synonym for checkout. -src cat [revision-spec] ['file'...] +src cat [revision-spec] ['file'...]:: Send the specified revisions of the files to standard output. -src branch [delete|del|-d] ['branchname'] +src branch [delete|del|-d] ['branchname']:: Create, switch to, or delete a branch. With no arguments, list branches. -src tag [delete|del|-d] ['tagname'] ['revision-spec'] ['file'...] +src tag [delete|del|-d] ['tagname'] ['revision-spec'] ['file'...]:: Create, switch to, or delete a tag. With no arguments, list tags. -src list ['revision-spec'] ['file'...] +src list ['revision-spec'] ['file'...]:: Sends summary information about the specified commits to standard output. In each file listing, the summary line tagged with '*' is the state that checkout would return to. The default revision-spec is all commits on the current branch. -src log ['revision-spec'] ['file'...] +src log ['revision-spec'] ['file'...]:: Sends log information about the specified commits to standard output. The default revision-spec is all commits on the current branch. -src diff ['revision-spec'] ['file'...] +src diff ['revision-spec'] ['file'...]:: Sends a diff listing to standard output. With no revision spec, diffs the working copy against the last version checked in. With one revno, diffs the working copy against that stored revision; with a range, -src moveto 'directory' ['file'...] +src ls:: + List all registered files. + +src rename 'old' 'new':: + Rename a file and its master. Refuses to step on existing files or masters. + 'mv' and 'rename' are synonyms. + +src copy 'old' 'new':: + Rename a file and its master. Refuses to step on existing files or masters. + 'cp' is a synonym. + +src moveto 'directory' ['file'...]:: Moves files and their histories to another directory. -src copyto 'directory' ['file'...] +src copyto 'directory' ['file'...]:: Copies files and their histories to another directory. -src fast-export ['file'...] +src fast-export ['file'...]:: Export one or more projects as a git fast-import stream. The committer identification is copied from your Git configuration. -src ls - List all registered files. +The omission of 'src remove' is a deliberate speed bump. If no files are specified, all eligible files are operated on in sequence. diff --git a/srctest b/srctest index d9b4b0b..aa0528c 100755 --- a/srctest +++ b/srctest @@ -167,8 +167,9 @@ cat testfile14 | (cd $SANDBOX/foo >/dev/null; git init --quiet; git fast-import diff -u testfile14 testfile15 check "fast-export" -mkdir $SANDBOX/bar -src $TESTOPTS moveto $SANDBOX/bar -check "moveto" +src $TESTOPTS rename testfile1 newname +check "move" + +# untested: ls, moveto, copyto, copy # end