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.") local_repository = Repository(repository_folder) remote_repository = Repository(File(args.target)) # This is a rather unintuitive way to do things, but we're just # going to iterate through all revisions in local_repository and check # to see if they're present in remote_repository, and if they're not, # add them. changes_pushed = 0 for number, hash, data in local_repository.revision_iterator(): if not remote_repository.has_revision(hash): changes_pushed += 1 # Revision is not present, so create it print "Pushing revision %s:%s" % (number, hash) new_hash = remote_repository.create_revision(data) # Sanity check to make sure we didn't get a different revision # hash; this shouldn't actually be needed unless there's a bug # in the revision encoding stuff somewhere if new_hash != hash: raise Exception("INTERNAL ERROR: Transferred hash " "mismatch: %s -> %s. One of the two repositories " "involved in the push is most likely corrupt." % (hash, new_hash)) if changes_pushed: print "Pushed %s change%s to %s." % (changes_pushed, "s" if changes_pushed > 1 else "", args.target) else: print "Remote repository is already up to date."
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