From: Atsushi Odagiri Date: Sun, 14 Apr 2013 05:05:57 +0000 (+0900) Subject: change option of history, from after_current to rev_range. X-Git-Tag: rel_0_6_0~19^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cda7661cf3e09e4372cbf6fe05e44497c77d738;p=thirdparty%2Fsqlalchemy%2Falembic.git change option of history, from after_current to rev_range. --- diff --git a/alembic/command.py b/alembic/command.py index 731f36c0..93a4381f 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -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() diff --git a/alembic/config.py b/alembic/config.py index 3fa8af7c..153439d9 100644 --- a/alembic/config.py +++ b/alembic/config.py @@ -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 = {