Patchwork [1,of,3,V2] hardlink: extract topic text logic of copyfiles

login
register
mail settings
Submitter Jun Wu
Date March 29, 2017, 7:42 p.m.
Message ID <b1ef68e4196e01f723b7.1490816536@x1c>
Download mbox | patch
Permalink /patch/19825/
State Accepted
Headers show

Comments

Jun Wu - March 29, 2017, 7:42 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1490815275 25200
#      Wed Mar 29 12:21:15 2017 -0700
# Node ID b1ef68e4196e01f723b78746d752f60e46e33cc0
# Parent  cda83a1bfb3ac3a23cfa158c407be93755c1018e
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r b1ef68e4196e
hardlink: extract topic text logic of copyfiles

The topic text shows whether it's "linking" or "copying", based on
"hardlink" value. The function is extracted so a later patch can reuse it.
Yuya Nishihara - March 30, 2017, 2:33 p.m.
On Wed, 29 Mar 2017 12:42:16 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1490815275 25200
> #      Wed Mar 29 12:21:15 2017 -0700
> # Node ID b1ef68e4196e01f723b78746d752f60e46e33cc0
> # Parent  cda83a1bfb3ac3a23cfa158c407be93755c1018e
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r b1ef68e4196e
> hardlink: extract topic text logic of copyfiles

Looks good, queued, thanks.

> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1130,8 +1130,7 @@ def copyfiles(src, dst, hardlink=None, p
>          hardlink = (os.stat(src).st_dev ==
>                      os.stat(os.path.dirname(dst)).st_dev)
> -    if hardlink:
> -        topic = _('linking')
> -    else:
> -        topic = _('copying')
> +
> +    gettopic = lambda: hardlink and _('linking') or _('copying')
> +    topic = gettopic()

IIRC, we prefer not using and/or ternary. I would instead do:

  topicmap = [_('copying'), _('linking')]
  topicmap[hardlink]

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1130,8 +1130,7 @@  def copyfiles(src, dst, hardlink=None, p
         hardlink = (os.stat(src).st_dev ==
                     os.stat(os.path.dirname(dst)).st_dev)
-    if hardlink:
-        topic = _('linking')
-    else:
-        topic = _('copying')
+
+    gettopic = lambda: hardlink and _('linking') or _('copying')
+    topic = gettopic()
 
     if os.path.isdir(src):