Exemple #1
0
    def run(self, args):
        if args.repository:
            repository_folder = File(args.repository)
        else:
            repository_folder = detect_repository(File())
            if not repository_folder:
                raise Exception("You're not in a repository (or a working "
                                "folder) right now and you didn't specify "
                                "--repository.")
        if args.working:
            working_file = File(args.working)
        else:
            working_file = detect_working(silent=True)
        repository = Repository(repository_folder)
        revisions = None
        if working_file and working_file.has_xattr(XATTR_BASE) and not args.all:
            # We have a working file and we're not displaying all revisions.
            # Only show revisions which are ancestors of the working file.
            # TODO: Figure out a way to do this without having to reconstruct
            # every revision; probably need to have some sort of cache in the
            # Repository class of parent-child revision relationships. Still
            # thinking a Neo4j database might be useful for this, or maybe some
            # sort of equivalent SQLite database.
            revisions = set()
            base = json.loads(working_file.get_xattr(XATTR_BASE))
            current = set(base)
            while current:
                # Find the revision with the highest number in current
                max_hash = max(current, key=lambda r: int(repository.number_for_rev(r)))
                revisions.add(max_hash)
                current.remove(max_hash)
                current |= set(repository.get_revision(max_hash)["parents"])
        print
        for number, hash, data in repository.revision_iterator():
            if revisions is not None and hash not in revisions:
                continue
            print u"Revision %s:%s:" % (number, hash)
            print u"    date:           %s" % time.ctime(data.get("info", {}).get("date", 0))
            print u"    type:           %s" % data["type"]
            if data.get("current_name"):
                print u"    committed as:   %s" % data["current_name"]
            for cparent in data["parents"]:
                print u"    change parent:  %s:%s" % (repository.number_for_rev(cparent), cparent)
#            for dparent in repository.get_dirparents(hash):
#                print "    dir parent:     %s:%s" % (repository.number_for_rev(dparent), dparent)
            try:
                print u"    message:        %s" % data.get("info", {}).get("message", "")
            except:
                print >>sys.stderr, data
                raise
            print
Exemple #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."