Patchwork [STABLE,V2] keyword: avoid traceback when kwdemo is run outside a repo

login
register
mail settings
Submitter Christian Ebert
Date July 27, 2016, 9:37 p.m.
Message ID <591ba25e00ddcb93e20a.1469655438@1.0.0.127.in-addr.arpa>
Download mbox | patch
Permalink /patch/15993/
State Accepted
Headers show

Comments

Christian Ebert - July 27, 2016, 9:37 p.m.
# HG changeset patch
# User Christian Ebert <blacktrash@gmx.net>
# Date 1469624271 -3600
#      Wed Jul 27 13:57:51 2016 +0100
# Branch stable
# Node ID 591ba25e00ddcb93e20a7bdb3fc7091183522709
# Parent  6217180f9ab8c61320ea3826591960415779282e
keyword: avoid traceback when kwdemo is run outside a repo

f0564402d059 causes a fatal AttributeError if kwdemo is run outside a repo
because in the temporary repo creation repo is None and therefore cannot have a
baseui attribute.
In this case fall back to using ui.

Add test case.
Augie Fackler - July 27, 2016, 9:44 p.m.
> On Jul 27, 2016, at 5:37 PM, Christian Ebert <blacktrash@gmx.net> wrote:
> 
> # HG changeset patch
> # User Christian Ebert <blacktrash@gmx.net>
> # Date 1469624271 -3600
> #      Wed Jul 27 13:57:51 2016 +0100
> # Branch stable
> # Node ID 591ba25e00ddcb93e20a7bdb3fc7091183522709
> # Parent  6217180f9ab8c61320ea3826591960415779282e
> keyword: avoid traceback when kwdemo is run outside a repo

Queued for stable, thanks

> 
> f0564402d059 causes a fatal AttributeError if kwdemo is run outside a repo
> because in the temporary repo creation repo is None and therefore cannot have a
> baseui attribute.
> In this case fall back to using ui.
> 
> Add test case.
> 
> diff --git a/hgext/keyword.py b/hgext/keyword.py
> --- a/hgext/keyword.py
> +++ b/hgext/keyword.py
> @@ -412,7 +412,11 @@ def demo(ui, repo, *args, **opts):
>     fn = 'demo.txt'
>     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
>     ui.note(_('creating temporary repository at %s\n') % tmpdir)
> -    repo = localrepo.localrepository(repo.baseui, tmpdir, True)
> +    if repo == None:
> +        baseui = ui
> +    else:
> +        baseui = repo.baseui
> +    repo = localrepo.localrepository(baseui, tmpdir, True)
>     ui.setconfig('keyword', fn, '', 'keyword')
>     svn = ui.configbool('keywordset', 'svn')
>     # explicitly set keywordset for demo output
> diff --git a/tests/test-keyword.t b/tests/test-keyword.t
> --- a/tests/test-keyword.t
> +++ b/tests/test-keyword.t
> @@ -1,3 +1,15 @@
> +Run kwdemo outside a repo
> +  $ hg -q --config extensions.keyword= --config keywordmaps.Foo="{author|user}" kwdemo
> +  [extensions]
> +  keyword =
> +  [keyword]
> +  demo.txt =
> +  [keywordset]
> +  svn = False
> +  [keywordmaps]
> +  Foo = {author|user}
> +  $Foo: test $
> +
>   $ cat <<EOF >> $HGRCPATH
>> [extensions]
>> keyword =
Augie Fackler - July 27, 2016, 11:37 p.m.
> On Jul 27, 2016, at 5:44 PM, Augie Fackler <raf@durin42.com> wrote:
> 
>> diff --git a/hgext/keyword.py b/hgext/keyword.py
>> --- a/hgext/keyword.py
>> +++ b/hgext/keyword.py
>> @@ -412,7 +412,11 @@ def demo(ui, repo, *args, **opts):
>>    fn = 'demo.txt'
>>    tmpdir = tempfile.mkdtemp('', 'kwdemo.')
>>    ui.note(_('creating temporary repository at %s\n') % tmpdir)
>> -    repo = localrepo.localrepository(repo.baseui, tmpdir, True)
>> +    if repo == None:

I fixed this in flight. check-code sends its regards.
Christian Ebert - July 28, 2016, 8:10 a.m.
* Augie Fackler on Wednesday, July 27, 2016 at 19:37:47 -0400
>> On Jul 27, 2016, at 5:44 PM, Augie Fackler <raf@durin42.com> wrote:
>>> +    if repo == None:
> 
> I fixed this in flight. check-code sends its regards.

Sorry, and thanks. Clearly not in Python land atm.

Patch

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -412,7 +412,11 @@  def demo(ui, repo, *args, **opts):
     fn = 'demo.txt'
     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
     ui.note(_('creating temporary repository at %s\n') % tmpdir)
-    repo = localrepo.localrepository(repo.baseui, tmpdir, True)
+    if repo == None:
+        baseui = ui
+    else:
+        baseui = repo.baseui
+    repo = localrepo.localrepository(baseui, tmpdir, True)
     ui.setconfig('keyword', fn, '', 'keyword')
     svn = ui.configbool('keywordset', 'svn')
     # explicitly set keywordset for demo output
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -1,3 +1,15 @@ 
+Run kwdemo outside a repo
+  $ hg -q --config extensions.keyword= --config keywordmaps.Foo="{author|user}" kwdemo
+  [extensions]
+  keyword =
+  [keyword]
+  demo.txt = 
+  [keywordset]
+  svn = False
+  [keywordmaps]
+  Foo = {author|user}
+  $Foo: test $
+
   $ cat <<EOF >> $HGRCPATH
   > [extensions]
   > keyword =