Patchwork [7,of,9,V2] largefiles: introduce "_lfstatuswriters" to customize status reporting

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Nov. 5, 2014, 2:34 p.m.
Message ID <94ac64bcf6fe91022a11.1415198056@feefifofum>
Download mbox | patch
Permalink /patch/6578/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Nov. 5, 2014, 2:34 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1415197487 -32400
#      Wed Nov 05 23:24:47 2014 +0900
# Node ID 94ac64bcf6fe91022a11a1709de8dbc671c12a4f
# Parent  f726b05ecfe682b2cf4d5baee73903bc2c889f87
largefiles: introduce "_lfstatuswriters" to customize status reporting

"lfutil.getstatuswriter" is the utility to get appropriate function to
write largefiles specific status out from "repo._lfstatuswriters".

This patch uses "stack" with an element instead of flag like
"_isXXXXing" or so, because:

  - the former works correctly even when customizations are nested, and
  - ensuring at least one element can ignore empty check

Patch

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -557,3 +557,20 @@ 
             return updatestandinsbymatch(repo, match)
         else:
             return match
+
+def getstatuswriter(ui, repo, forcibly=None):
+    '''Return the function to write largefiles specific status out
+
+    If ``forcibly`` is ``None``, this returns the last element of
+    ``repo._lfupdatereporters`` as "default" writer function.
+
+    Otherwise, this returns the function to always write out (or
+    ignore if ``not forcibly``) status.
+    '''
+    if forcibly is None:
+        return repo._lfstatuswriters[-1]
+    else:
+        if forcibly:
+            return ui.status # forcibly WRITE OUT
+        else:
+            return lambda *msg, **opts: None # forcibly IGNORE
diff --git a/hgext/largefiles/reposetup.py b/hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py
+++ b/hgext/largefiles/reposetup.py
@@ -343,6 +343,11 @@ 
     # only last element ("_lfcommithooks[-1]") is used for each committing.
     repo._lfcommithooks = [lfutil.updatestandinsbymatch]
 
+    # Stack of status writer functions taking "*msg, **opts" arguments
+    # like "ui.status()". Only last element ("_lfupdatereporters[-1]")
+    # is used to write status out.
+    repo._lfstatuswriters = [ui.status]
+
     def prepushoutgoinghook(local, remote, outgoing):
         if outgoing.missing:
             toupload = set()