From: Eric S. Raymond Date: Sat, 8 Nov 2014 15:16:26 +0000 (-0500) Subject: Implemented and tested moveto. X-Git-Tag: 0.2~24 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=9003f1ff0bf11211e64995401ac5f8e80b8fd900;p=src.git Implemented and tested moveto. --- diff --git a/src b/src index 399939d..6e90d4f 100755 --- a/src +++ b/src @@ -299,6 +299,9 @@ 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 moveto 'directory' ['file'...] + Moves files and their histories to another directory. + 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. @@ -306,15 +309,19 @@ src fast-export ['file'...] def init_method(*args): "Create a repo directory if none already exists." - if not os.path.exists(repodir): + if args: + target = os.path.join(args[0], ".src") + else: + target = repodir + if not os.path.exists(target): try: - os.mkdir(repodir) + os.mkdir(target) except OSError: croak("creation failed, check directory permissions.") - elif os.path.isdir(repodir): - croak("%s already exists." % repodir) + elif os.path.isdir(target): + croak("%s already exists." % target) else: - croak("%s exists but is not a directory." % repodir) + croak("%s exists but is not a directory." % target) def preamble(cmd, args): "Common setup code." @@ -657,6 +664,31 @@ def fast_export_method(*args): if val in revrange: sys.stdout.write("reset refs/tags/%s\nfrom :%d\n\n" % (key, markmap[val])) +def moveto_method(*args): + "Register a file into src control." + (revspec, args) = preamble("moveto", args) + if revspec is not None: + croak("moveto doesn't take a revision spec") + if args: + target = args.pop(0) + else: + croak("moveto requires a sirectory argument") + if not os.path.exists(target): + croak("%s does not exist" % arg) + if not os.path.isdir(target): + croak("%s is not a directory" % arg) + init_method(target) + for arg in args: + if not os.path.exists(arg): + croak("I see no '%s' here." % arg) + elif not os.path.exists(master(arg)): + croak("%s is not registered, skipping." % arg) + else: + # Using mv(1) evades cross-filesystem issues + do_or_die("mv {0} {1} && mv {2} {3]/{4}".format(arg, target, master(arg), target, repodir)) + if not quiet and len(args) > 1: + announce("%s -> %s" % target) + dispatch = { "help": help_method, "init": init_method, @@ -671,6 +703,7 @@ dispatch = { "diff": diff_method, "tag": tag_method, "fast-export": fast_export_method, + "moveto": moveto_method, } if __name__ == "__main__": diff --git a/src.asc b/src.asc index 27debb8..febf04c 100644 --- a/src.asc +++ b/src.asc @@ -82,6 +82,9 @@ 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 moveto 'directory' ['file'...] + Moves files and their histories to another directory. + src fast-export ['file'...] Export one or more projects as a git fast-import stream. The committer identification is copied from your Git configuration. @@ -95,11 +98,11 @@ on, and the command is not a report generator (cat, log, list, fast-export, the listing modes of tag and branch) you will see a reply only if the operation failed. -Other commands (add, commit, checkout, tag creation and deletion) give -you a success message per file when operating on multiple files, so -you will not be in doubt about which operation succeeded. This -behavior can be suppressed with the -q option, placed 'before' the -subcommand word. +Other commands (add, commit, checkout, tag creation and deletion, +moveto) give you a success message per file when operating on multiple +files, so you will not be in doubt about which operation succeeded. +This behavior can be suppressed with the -q option, placed 'before' +the subcommand word. == DEBUGGING OPTIONS == @@ -117,9 +120,8 @@ It also attributes all commits to J. Random Hacker and sets a constant screen witch of 79. It's for regression testing. == DANGER! DANGER! == -This is a proof-of-concept alpha release. The 'branch' and -'fast-export' commands are not yet implemented; they are -described here to document the design. +This is a proof-of-concept alpha release. The 'branch' command is not +yet implemented; it is described here to document the design. == IMPLEMENTATION NOTE == SRC presently uses RCS for back-end storage. This may change in the future. diff --git a/srctest b/srctest index 2514af3..3220549 100755 --- a/srctest +++ b/srctest @@ -6,7 +6,7 @@ # Needs to not be a subdirectory of here, or git gets confused SANDBOX=/tmp/src-sandbox -trap "rm -f testfile* $SANDBOX/testfile*" 0 1 2 15 +trap "rm -fr $SANDBOX" 0 1 2 15 check() { case $? in @@ -167,4 +167,8 @@ 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" + # end