# HG changeset patch
# User Dan Villiom Podlaski Christiansen  <danchr@gmail.com>
# Date 1352644279 -3600
# Node ID 82bbb3428684f1f899d62b8424cf1a527c9e830a
# Parent  641d0c41d1ea53df3036694b545415c8a86027e1
pull: save the last pulled revision *after* converting revisions

Otherwise, a KeyboardInterrupt may lead to an unpulled revision being
incorrectly saved as pulled in the lastpulled file. This will lead to
the interrupted revision being incorrectly skipped at the next pull,
leading to an incorrect conversion -- one might even say corrupt.

Due to it's nature of requiring a manual interrupt, this bug is
difficult to test.

diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -386,10 +386,10 @@ def pull(repo, source, heads=[], force=F
             # start converting revisions
             firstrun = True
             for r in svn.revisions(start=start, stop=stopat_rev):
-                lastpulled = r.revnum
                 if (r.revnum in skiprevs or
                     (r.author is None and
                      r.message == 'This is an empty revision for padding.')):
+                    lastpulled = r.revnum
                     continue
                 tbdelta = meta.update_branch_tag_map_for_rev(r)
                 # got a 502? Try more than once!
@@ -438,6 +438,9 @@ def pull(repo, source, heads=[], force=F
                         else:
                             ui.traceback()
                             raise hgutil.Abort(*e.args)
+
+                lastpulled = r.revnum
+
         except KeyboardInterrupt:
             ui.traceback()
     finally: