]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
change option of history, from after_current to rev_range.
authorAtsushi Odagiri <aodagx@gmail.com>
Sun, 14 Apr 2013 05:05:57 +0000 (14:05 +0900)
committerAtsushi Odagiri <aodagx@gmail.com>
Sun, 14 Apr 2013 05:05:57 +0000 (14:05 +0900)
alembic/command.py
alembic/config.py

index 731f36c0b5411e1be24ecac0e7734d5d2e9d6025..93a4381f5ce37d6b137c32eba21f088fa3ed5644 100644 (file)
@@ -149,31 +149,56 @@ def downgrade(config, revision, sql=False, tag=None):
     ):
         script.run_env()
 
-def history(config, after_current=False):
+def history(config, rev_range=""):
     """List changeset scripts in chronological order."""
 
     script = ScriptDirectory.from_config(config)
-    def display_history(current=None):
-        for sc in script.walk_revisions():
+    def display_history(start=None, end=None):
+        revs = iter(script.walk_revisions())
+        if end:
+            # skip to end
+            for sc in revs:
+                if sc == end:
+                    if sc.is_head:
+                        config.print_stdout("")
+                    config.print_stdout(sc)
+                    break
+        if (start or end) and end == start:
+            return
+
+        for sc in revs:
             if sc.is_head:
                 config.print_stdout("")
             config.print_stdout(sc)
-            if sc == current:
+            if sc == start:
                 break
 
-    def display_history_after_curreont(rev, context):
-        current = script.get_revision(rev)
-        display_history(current=current)
-        return []
-
-    if not after_current:
+    if not rev_range:
         return display_history()
 
+    if ":" not in rev_range:
+        raise ValueError("rev_range must be formatted in '[start]:[end]'")  # need a right message
+
+
+    def display_history_ragne(rev, context):
+        _start, _end = rev_range.split(":", 1)
+        _start = _start or "base"
+        _end = _end or "head"
+
+        if _start == 'current':
+            _start = rev
+        if _end == 'current':
+            _end = rev
+        
+        start = script.get_revision(_start)
+        end = script.get_revision(_end)
+        display_history(start=start, end=end)
+        return []
 
     with EnvironmentContext(
         config,
         script,
-        fn=display_history_after_curreont
+        fn=display_history_ragne
     ):
         script.run_env()
 
index 3fa8af7c3baef115956b52177fdec5e435dd7e3e..153439d959187b93f456798906898054dcba8906 100644 (file)
@@ -200,10 +200,15 @@ class CommandLine(object):
                                     help="Only show current version and "
                                     "whether or not this is the head revision.")
 
-            if 'after_current' in kwargs:
-                parser.add_argument("--after-current",
-                                    action="store_true",
-                                    help="Only show after current revisions and current revision.")
+            if 'rev_range' in kwargs:
+                parser.add_argument("-r", "--rev-range",
+                                    action="store",
+                                    help="Specify the range of display revisions. "
+                                    "range is formatted in [start]:[end] "
+                                    'accepting any rev number, "head", "base", '
+                                    'or "current". '
+                                    'the left side of : defaults to "base" '
+                                    'the right side defaults to "head"')
 
 
             positional_help = {