Exemplo n.º 1
0
 def run(self, args):
     location = File(args.location)
     if args.plain:
         repository_folder = location
     else:
         location.mkdirs()
         repository_folder = location.child(".filer")
     init_repository(repository_folder)
     if not args.plain:
         repository = Repository(repository_folder)
         working = WorkingCopy(repository, location)
         working.create()
     print "Repository created at %r." % repository_folder.path
Exemplo n.º 2
0
 def run(self, args):
     # This is basically as simple as getting the working file and the
     # repository and committing a new revision on them.
     if args.repository:
         repository_folder = File(args.repository)
     else:
         repository_folder = detect_repository()
     repository = Repository(repository_folder)
     if args.working:
         working_file = File(args.working)
     else:
         working_file = detect_working()
     info = {"date": time.time(), "message": args.message}
     working = WorkingCopy(repository, working_file)
     # Keep track of the old base (which will be None if the working copy
     # is untracked) and compare it later on to see if anything changed
     if working_file.has_xattr(XATTR_BASE):
         base = json.loads(working_file.check_xattr(XATTR_BASE))
     else:
         base = None
     working.commit(info)
     if not working_file.has_xattr(XATTR_BASE):
         # This can happen when the working file itself isn't tracked, which
         # is rare but happens if the user checks out a new, blank working
         # copy but doesn't add it with the add command. In that case, we
         # print a friendly warning.
         print "The working copy isn't being tracked. You probably need to "
         print "`filer add %s` first." % working_file.path
     else:
         new_base = json.loads(working_file.check_xattr(XATTR_BASE))
         hash = new_base[0]
         if new_base != base:
             print "Committed revision %s:%s." % (repository.number_for_rev(hash), hash)
         else:
             print "No changes to be committed."
             print "If you copied new files into the working copy that you "
             print "expected to show up, make sure to `filer add` them first."
Exemplo n.º 3
0
 def run(self, args):
     # The checkout command does something different depending on how it's
     # run:
     # 
     # If the working copy (specified with --working or auto-detected)
     # exists and -r is specified, the working copy is updated to the
     # revision in question.
     # If the working copy exists but is not a working copy, it is turned
     # into one. Then, if -r is specified, it is updated to the specified
     # revision.
     # If the working copy does not exist, -r must be specified (so that we
     # know whether to create a file or a folder), and the working copy
     # will be created and updated to the revision in question.
     # 
     # So, if the working copy does not exist, we require -r and create it.
     # Then, if it's not a working copy, we make it one by setting
     # XATTR_REPO. Then we go update the working copy to the specified
     # revision.
     if args.repository:
         repository_folder = File(args.repository)
     else:
         repository_folder = detect_repository()
     repository = Repository(repository_folder)
     if args.working:
         working_file = File(args.working)
     else:
         working_file = detect_working()
     revision = args.revision
     # Check to see if the soon-to-be working copy already exists as a file
     # or folder
     if not working_file.exists:
         # It doesn't exist. Make sure we've got a --revision (and error out
         # if we don't, since then we don't know whether to create a file or
         # a folder).
         if revision is None:
             raise Exception("When using the checkout command on a working "
                     "copy that doesn't actually exist yet, --revision must "
                     "be specified. This is because Filer doesn't know "
                     "whether to create a folder or a file for it. If you "
                     "want to create a new, blank working copy without "
                     "checking one out from a revision, create a file or "
                     "folder at the relevant location, then use the "
                     "checkout command again. Then it'll work.")
         # We've got a revision, so look at whether it's a file or a folder,
         # and create a file or a folder accordingly.
         working_type = repository.get_revision(revision)["type"]
         if working_type == "file":
             # It's a file, so create a blank file for it.
             working_file.write("")
         else:
             # It's a folder, so create a blank folder for it.
             working_file.mkdir()
     # The working file exists. Now see if it's a working copy.
     working = WorkingCopy(repository, working_file)
     if not working.is_working():
         # It's not a working copy, so make it a working copy.
         working.create()
     # Now update it. TODO: We might want to keep track of whether it
     # already existed before now, and if it did, warn the user that they'll
     # be overwriting their changes.
     if revision:
         if working_file.has_xattr(XATTR_BASE):
             base = json.loads(working_file.get_xattr(XATTR_BASE))
         else:
             base = None
         # If we're already checked out, warn if we have multiple parents
         # as that'll likely steamroller over an impending merge. TODO:
         # might want to recursively walk down and make sure we don't have
         # any children that also have impending merges.
         if base and len(base) > 1:
             if not args.quiet and raw_input("The working copy has multiple parents; this "
                     "usually means a merge is in progress. Do you still "
                     "want to check out a new revision and overwrite "
                     "your changes (y or n)? ").lower()[0] != "y":
                 print "Stopping."
                 return
         # If we're checked out with one parent, see if the new revision is
         # an ancestor of the current revision or vice versa. If not, warn
         # that we're jumping history lines. TODO: Don't warn if they're on
         # the same changeline, even if they're on disjointed branches of
         # the changeline.
         elif base and len(base) == 1:
             base_rev = base[0]
             new_rev = repository.rev_for_number(revision)
             if not (repository.is_ancestor(base_rev, new_rev) or
                     repository.is_ancestor(new_rev, base_rev)):
                 if not args.quiet and raw_input("The revision you're updating to (%s) is not "
                         "an ancestor or a descendant of the working "
                         "copy's current revision (%s). Do you still want "
                         "to continue updating (y or n)? "
                         % (new_rev, base_rev)).lower()[0] != "y":
                     print "Stopping."
                     return
         working.update_to(revision)
         print "Checked out revision %r" % revision
     else:
         print "Resetting working copy to untracked"
         delete_tracked(working_file)