changeset 9:7e3d7dbe3386

Add __repr__() and __str__() to Command classes (for easier debugging).
author Greg Ward <greg-hg@gerg.ca>
date Tue, 31 Mar 2009 10:10:04 -0400
parents b2ee2f810f1e
children 18c1e7ac0012
files fastimport/commands.py
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/fastimport/commands.py	Wed Jul 16 13:04:41 2008 +0100
+++ b/fastimport/commands.py	Tue Mar 31 10:10:04 2009 -0400
@@ -35,6 +35,12 @@
         # List of field names not to display
         self._binary = []
 
+    def __repr__(self):
+        return "<%s at %x: %s>" % (self.__class__.__name__, id(self), self)
+
+    def __str__(self):
+        return self.name
+
     def dump_str(self, names=None, child_lists=None, verbose=False):
         """Dump fields as a string.
 
@@ -76,6 +82,9 @@
             self.id = ':' + mark
         self._binary = ['data']
 
+    def __str__(self):
+        return self.id
+
 
 class CheckpointCommand(ImportCommand):
 
@@ -104,6 +113,9 @@
         else:
             self.id = ':' + mark
 
+    def __str__(self):
+        return "ref %s, mark %s" % (self.ref, self.mark)
+
     def dump_str(self, names=None, child_lists=None, verbose=False):
         result = [ImportCommand.dump_str(self, names, verbose=verbose)]
         for f in self.file_iter():
@@ -141,6 +153,9 @@
         self.tagger = tagger
         self.message = message
 
+    def __str__(self):
+        return self.id
+
 
 class FileCommand(ImportCommand):
     """Base class for file commands."""
@@ -159,6 +174,9 @@
         self.data = data
         self._binary = ['data']
 
+    def __str__(self):
+        return self.path
+
 
 class FileDeleteCommand(FileCommand):
 
@@ -166,6 +184,9 @@
         FileCommand.__init__(self, 'filedelete')
         self.path = path
 
+    def __str__(self):
+        return self.path
+
 
 class FileCopyCommand(FileCommand):
 
@@ -174,6 +195,9 @@
         self.src_path = src_path
         self.dest_path = dest_path
 
+    def __str__(self):
+        return "%s -> %s" % (self.src_path, self.dest_path)
+
 
 class FileRenameCommand(FileCommand):
 
@@ -182,6 +206,9 @@
         self.old_path = old_path
         self.new_path = new_path
 
+    def __str__(self):
+        return "%s -> %s" % (self.old_path, self.new_path)
+
 
 class FileDeleteAllCommand(FileCommand):