Patchwork [08,of,21,RFC] cmdutil: abort with localized error when `hg cat` encounters censored data

login
register
mail settings
Submitter michaeljedgar@gmail.com
Date Sept. 11, 2014, 12:26 a.m.
Message ID <f773537e5d12817f3523.1410395169@adgar-macbookpro3.roam.corp.google.com>
Download mbox | patch
Permalink /patch/5783/
State Changes Requested
Headers show

Comments

michaeljedgar@gmail.com - Sept. 11, 2014, 12:26 a.m.
# HG changeset patch
# User Mike Edgar <adgar@google.com>
# Date 1409528434 -7200
#      Mon Sep 01 01:40:34 2014 +0200
# Node ID f773537e5d12817f3523d86920c0df62062dd108
# Parent  96b547c542400ef1d75b7a2ed9a4731e7296a337
cmdutil: abort with localized error when `hg cat` encounters censored data
Matt Mackall - Sept. 11, 2014, 5:54 p.m.
On Wed, 2014-09-10 at 20:26 -0400, michaeljedgar@gmail.com wrote:
> # HG changeset patch
> # User Mike Edgar <adgar@google.com>
> # Date 1409528434 -7200
> #      Mon Sep 01 01:40:34 2014 +0200
> # Node ID f773537e5d12817f3523d86920c0df62062dd108
> # Parent  96b547c542400ef1d75b7a2ed9a4731e7296a337
> cmdutil: abort with localized error when `hg cat` encounters censored data
> 
> diff -r 96b547c54240 -r f773537e5d12 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py	Wed Sep 10 00:18:15 2014 -0400
> +++ b/mercurial/cmdutil.py	Mon Sep 01 01:40:34 2014 +0200
> @@ -1959,7 +1959,11 @@
>      def write(path):
>          fp = makefileobj(repo, opts.get('output'), ctx.node(),
>                           pathname=os.path.join(prefix, path))
> -        data = ctx[path].data()
> +        try:
> +            data = ctx[path].data()
> +        except revlog.CensoredNodeError, e:
> +            raise util.Abort(
> +                _('node %s in file %s is censored') % (short(e.node), path))

This pattern is too burdensome. There are way too many places we access
file data, we don't want to audit them all and add special handling. We
just need to let the exception pass through and get caught by the
dispatcher.

Patch

diff -r 96b547c54240 -r f773537e5d12 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Wed Sep 10 00:18:15 2014 -0400
+++ b/mercurial/cmdutil.py	Mon Sep 01 01:40:34 2014 +0200
@@ -1959,7 +1959,11 @@ 
     def write(path):
         fp = makefileobj(repo, opts.get('output'), ctx.node(),
                          pathname=os.path.join(prefix, path))
-        data = ctx[path].data()
+        try:
+            data = ctx[path].data()
+        except revlog.CensoredNodeError, e:
+            raise util.Abort(
+                _('node %s in file %s is censored') % (short(e.node), path))
         if opts.get('decode'):
             data = repo.wwritedata(path, data)
         fp.write(data)