diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-14 18:47:09 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-14 18:47:09 -0400 |
commit | 7f1fe62c0827099a433e9a7df3378f6eb6b7bd62 (patch) | |
tree | 9f913a262018bb66cf439901f9312f429d533c11 /alembic/command.py | |
parent | c27e9ef22c56ad6608e661fcc63e32452eaa6e64 (diff) | |
download | alembic-7f1fe62c0827099a433e9a7df3378f6eb6b7bd62.tar.gz |
- rework the -r flag on history to make use of existing walk_revisions();
this way we get at relative revisions, error handling, etc.
- don't run environment for history command unless "current" was requested;
running the environment modifies output with logging, might access multiple
dbs, etc., so don't get into it if not needed
- add test suite for commands, start with history output
- document/changelog for history -r feature
- fix sys.stdout writing for py3k
- one more with_statement future not needed
Diffstat (limited to 'alembic/command.py')
-rw-r--r-- | alembic/command.py | 76 |
1 files changed, 33 insertions, 43 deletions
diff --git a/alembic/command.py b/alembic/command.py index 93a4381..898f4c9 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -149,58 +149,48 @@ def downgrade(config, revision, sql=False, tag=None): ): script.run_env() -def history(config, rev_range=""): +def history(config, rev_range=None): """List changeset scripts in chronological order.""" script = ScriptDirectory.from_config(config) - 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 rev_range is not None: + if ":" not in rev_range: + raise util.CommandError( + "History range requires [start]:[end], " + "[start]:, or :[end]") + base, head = rev_range.strip().split(":") + else: + base = head = None + + def _display_history(config, script, base, head): + for sc in script.walk_revisions( + base=base or "base", + head=head or "head"): if sc.is_head: config.print_stdout("") config.print_stdout(sc) - if sc == start: - break - 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" + def _display_history_w_current(config, script, base=None, head=None): + def _display_current_history(rev, context): + if head is None: + _display_history(config, script, base, rev) + elif base is None: + _display_history(config, script, rev, head) + return [] - 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_current_history + ): + script.run_env() - with EnvironmentContext( - config, - script, - fn=display_history_ragne - ): - script.run_env() + if base == "current": + _display_history_w_current(config, script, head=head) + elif head == "current": + _display_history_w_current(config, script, base=base) + else: + _display_history(config, script, base, head) def branches(config): |