Repository: airspeed-velocity/asv

Issue:
"asv profile" broken with existing environment
```
$ asv profile -E existing comm.Transfer.time_tcp_large_transfers_uncompressible
· An explicit revision may not be specified when using an existing environment.
```

Same with:
```
$ asv profile --python=same comm.Transfer.time_tcp_large_transfers_uncompressible
· An explicit revision may not be specified when using an existing environment.
```

I also tried with:
```
asv run --python=same --profile -b time_tcp_large_transfers_uncompressible
```
which doesn't seem to save a profile output anywhere.

This is with asv version 0.2.1.

Comments:

Patch:
diff --git a/asv/commands/profiling.py b/asv/commands/profiling.py
index afabf6c..8028862 100644
--- a/asv/commands/profiling.py
+++ b/asv/commands/profiling.py
@@ -13,7 +13,7 @@ import tempfile
 
 from . import Command
 from ..benchmarks import Benchmarks
-from ..console import log
+from ..console import log, color_print
 from ..environment import get_environments, is_existing_only
 from ..machine import Machine
 from ..profiling import ProfilerGui
@@ -123,8 +123,10 @@ class Profile(Command):
 
         machine_name = Machine.get_unique_machine_name()
         if revision is None:
-            revision = conf.branches[0]
-        commit_hash = repo.get_hash_from_name(revision)
+            rev = conf.branches[0]
+        else:
+            rev = revision
+        commit_hash = repo.get_hash_from_name(rev)
 
         profile_data = None
         checked_out = set()
@@ -192,6 +194,8 @@ class Profile(Command):
 
                 profile_data = results.get_profile(benchmark_name)
 
+        log.flush()
+
         if gui is not None:
             log.debug("Opening gui {0}".format(gui))
             with temp_profile(profile_data) as profile_path:
@@ -200,6 +204,7 @@ class Profile(Command):
             with io.open(output, 'wb') as fd:
                 fd.write(profile_data)
         else:
+            color_print('')
             with temp_profile(profile_data) as profile_path:
                 stats = pstats.Stats(profile_path)
                 stats.sort_stats('cumulative')
diff --git a/asv/console.py b/asv/console.py
index b573bd0..a7a6dac 100644
--- a/asv/console.py
+++ b/asv/console.py
@@ -274,9 +274,13 @@ class Log(object):
         else:
             rest = parts[1]
 
+        indent = self._indent + 1
+
         if self._total:
-            color_print('[{0:6.02f}%] '.format(
-                (float(self._count) / self._total) * 100.0), end='')
+            progress_msg = '[{0:6.02f}%] '.format(
+                (float(self._count) / self._total) * 100.0)
+            color_print(progress_msg, end='')
+            indent += len(progress_msg)
 
         color_print('·' * self._indent, end='')
         color_print(' ', end='')
@@ -299,7 +303,6 @@ class Log(object):
         else:
             color = 'red'
 
-        indent = self._indent + 11
         spaces = ' ' * indent
         color_print(first_line, color, end='')
         if rest is not None:


Test patch:
diff --git a/test/test_console.py b/test/test_console.py
index a0e141f..282a389 100644
--- a/test/test_console.py
+++ b/test/test_console.py
@@ -11,7 +11,7 @@ import sys
 import locale
 import itertools
 
-from asv.console import _write_with_fallback, color_print
+from asv.console import _write_with_fallback, color_print, log
 
 
 def test_write_with_fallback(tmpdir, capfd):
@@ -110,3 +110,19 @@ def test_color_print_nofail(capfd):
     assert 'indeed' in out
     assert 'really' in out
     assert 'not really' in out
+
+
+def test_log_indent(capsys):
+    log.set_nitems(0)
+    log.info("First\nSecond")
+
+    out, err = capsys.readouterr()
+    lines = out.lstrip().splitlines()
+    assert lines[0].index('First') == lines[1].index('Second')
+
+    log.set_nitems(1)
+    log.info("First\nSecond")
+
+    out, err = capsys.readouterr()
+    lines = out.lstrip().splitlines()
+    assert lines[0].index('First') == lines[1].index('Second')
diff --git a/test/test_dev.py b/test/test_dev.py
index 0d188d9..48453fe 100644
--- a/test/test_dev.py
+++ b/test/test_dev.py
@@ -42,6 +42,7 @@ def generate_basic_conf(tmpdir, repo_subdir=''):
         'html_dir': 'html',
         'repo': repo_path,
         'project': 'asv',
+        'branches': ['master'],
         'matrix': {
             "six": [None],
             "colorama": ["0.3.6", "0.3.7"],