--- bzrpoller.orig.py	2008-03-10 19:07:44.000000000 +0300
+++ bzrpoller.py	2008-03-10 19:06:38.000000000 +0300
@@ -15,10 +15,10 @@
     implements(interfaces.IChangeSource)
 
     compare_attrs = ["location", "pollinterval"]
-                     
+
 
     parent = None # filled in when we're added
-    last_change = None
+    last_revno = None
     loop = None
     working = False
 
@@ -50,15 +50,23 @@
     def poll(self):
         log.msg("BzrPoller polling")
         # location="http://bazaar-vcs.org/bzr/bzr.dev"
-        b = Branch.open_containing(self.url)[0]
+        b = Branch.open_containing(self.location)[0]
         # this is subclass of bzrlib.branch.Branch
-        current_revision = b.revno()
+        current_revno = b.revno()
+        if self.last_revno is None:
+            self.last_revno = current_revno
+            log.msg('BzrPoller: starting at %s' % (self.last_revno))
+            return
+        if current_revno == self.last_revno:
+            log.msg('BzrPoller: no new revisions since %s' % (self.last_revno))
+            return
         # NOTE: b.revision_history() does network IO, and is blocking.
-        revisions = b.revision_history()[last_revno:] # each is an id string
+        revisions = b.revision_history()[self.last_revno:current_revno] # each is an id string
         changes = []
-        for r in revisions:
+        # any way in bzrlib to get revno from revision_id?
+        # revnos in a branch are sequential, without gaps
+        for r, revno in zip(revisions, xrange(self.last_revno+1, current_revno+1)):
             rev = b.repository.get_revision(r)
-            # bzrlib.revision.Revision
             who = rev.committer
             comments = rev.message
             when = rev.timestamp
@@ -72,14 +80,15 @@
                      [f[0] for f in d.modified]
                      )
 
-            # revision= ?
             # branch= ?
-            c = Change(who=rev.committer,
+            c = Change(who=who,
                        files=files,
-                       comments=rev.message,
-                       when=rev.timestamp,
+                       comments=comments,
+                       revision=revno,
+                       when=when,
                        )
             changes.append(c)
         for c in changes:
             self.parent.addChange(c)
+        self.last_revno = current_revno
         log.msg("BzrPoller finished polling, %d changes found" % len(changes))

