[PATCH] keyword: remove docstrings to ease translation

Christian Ebert blacktrash at gmx.net
Tue Feb 10 06:48:18 CST 2009


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1234270008 -3600
# Node ID a81f688a071bdd7883fead53a36c43651998912d
# Parent  5f7512f680cb9006f730eb851fa49f42237e9aaf
keyword: remove docstrings to ease translation

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -97,7 +97,7 @@
 restricted = 'merge record resolve qfold qimport qnew qpush qrefresh qrecord'
 
 def utcdate(date):
-    '''Returns hgdate in cvs-like UTC format.'''
+    # return hgdate in cvs-like UTC format
     return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
 
 # make keyword tools accessible
@@ -105,10 +105,7 @@
 
 
 class kwtemplater(object):
-    '''
-    Sets up keyword templates, corresponding keyword regex, and
-    provides keyword substitution functions.
-    '''
+
     templates = {
         'Revision': '{node|short}',
         'Author': '{author|user}',
@@ -140,7 +137,6 @@
                                               False, '', False)
 
     def substitute(self, data, path, ctx, subfunc):
-        '''Replaces keywords in data with expanded template.'''
         def kwsub(mobj):
             kw = mobj.group(1)
             self.ct.use_template(self.templates[kw])
@@ -151,20 +147,15 @@
         return subfunc(kwsub, data)
 
     def expand(self, path, node, data):
-        '''Returns data with keywords expanded.'''
         if not self.restrict and self.matcher(path) and not util.binary(data):
             ctx = self.repo.filectx(path, fileid=node).changectx()
             return self.substitute(data, path, ctx, self.re_kw.sub)
         return data
 
     def iskwfile(self, path, flagfunc):
-        '''Returns true if path matches [keyword] pattern
-        and is not a symbolic link.
-        Caveat: localrepository._link fails on Windows.'''
         return self.matcher(path) and not 'l' in flagfunc(path)
 
     def overwrite(self, node, expand, files):
-        '''Overwrites selected files expanding/shrinking keywords.'''
         ctx = self.repo[node]
         mf = ctx.manifest()
         if node is not None:     # commit
@@ -195,17 +186,14 @@
             self.restrict = False
 
     def shrinktext(self, text):
-        '''Unconditionally removes all keyword substitutions from text.'''
         return self.re_kw.sub(r'$\1$', text)
 
     def shrink(self, fname, text):
-        '''Returns text with all keyword substitutions removed.'''
         if self.matcher(fname) and not util.binary(text):
             return self.shrinktext(text)
         return text
 
     def shrinklines(self, fname, lines):
-        '''Returns lines with keyword substitutions removed.'''
         if self.matcher(fname):
             text = ''.join(lines)
             if not util.binary(text):
@@ -213,41 +201,38 @@
         return lines
 
     def wread(self, fname, data):
-        '''If in restricted mode returns data read from wdir with
-        keyword substitutions removed.'''
+        # in restricted mode return data from working dir with
+        # keyword substitions removed
         return self.restrict and self.shrink(fname, data) or data
 
+
 class kwfilelog(filelog.filelog):
-    '''
-    Subclass of filelog to hook into its read, add, cmp methods.
-    Keywords are "stored" unexpanded, and processed on reading.
-    '''
+
     def __init__(self, opener, kwt, path):
         super(kwfilelog, self).__init__(opener, path)
         self.kwt = kwt
         self.path = path
 
     def read(self, node):
-        '''Expands keywords when reading filelog.'''
+        # expand keywords when reading filelog
         data = super(kwfilelog, self).read(node)
         return self.kwt.expand(self.path, node, data)
 
     def add(self, text, meta, tr, link, p1=None, p2=None):
-        '''Removes keyword substitutions when adding to filelog.'''
+        # remove keyword substitutions when adding to filelog
         text = self.kwt.shrink(self.path, text)
         return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
 
     def cmp(self, node, text):
-        '''Removes keyword substitutions for comparison.'''
+        # remove keyword substitutions for comparison
         text = self.kwt.shrink(self.path, text)
         if self.renamed(node):
             t2 = super(kwfilelog, self).read(node)
             return t2 != text
         return revlog.revlog.cmp(self, node, text)
 
+
 def _status(ui, repo, kwt, unknown, *pats, **opts):
-    '''Bails out if [keyword] configuration is not active.
-    Returns status of working directory.'''
     if kwt:
         matcher = cmdutil.match(repo, pats, opts)
         return repo.status(match=matcher, unknown=unknown, clean=True)
@@ -256,7 +241,6 @@
     raise util.Abort(_('no [keyword] patterns configured'))
 
 def _kwfwrite(ui, repo, expand, *pats, **opts):
-    '''Selects files and passes them to kwtemplater.overwrite.'''
     if repo.dirstate.parents()[1] != nullid:
         raise util.Abort(_('outstanding uncommitted merge'))
     kwt = kwtools['templater']
@@ -399,8 +383,6 @@
 
 
 def uisetup(ui):
-    '''Collects [keyword] config in kwtools.
-    Monkeypatches dispatch._parse if needed.'''
 
     for pat, opt in ui.configitems('keyword'):
         if opt != 'ignore':
@@ -410,20 +392,14 @@
 
     if kwtools['inc']:
         def kwdispatch_parse(orig, ui, args):
-            '''Monkeypatch dispatch._parse to obtain running hg command.'''
             cmd, func, args, options, cmdoptions = orig(ui, args)
             kwtools['hgcmd'] = cmd
             return cmd, func, args, options, cmdoptions
 
         extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse)
 
+
 def reposetup(ui, repo):
-    '''Sets up repo as kwrepo for keyword substitution.
-    Overrides file method to return kwfilelog instead of filelog
-    if file matches user configuration.
-    Wraps commit to overwrite configured files with updated
-    keyword substitutions.
-    Monkeypatches patch and webcommands.'''
 
     if (not hasattr(repo, 'dirstate') or not kwtools['inc']
         or kwtools['hgcmd'] in nokwcommands.split()
@@ -484,16 +460,13 @@
 
     # monkeypatches
     def kwpatchfile_init(orig, self, ui, fname, opener, missing=False):
-        '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
-        rejects or conflicts due to expanded keywords in working dir.'''
         orig(self, ui, fname, opener, missing)
-        # shrink keywords read from working dir
+        # avoid bogus conflicts due to expanded keywords in working dir
         self.lines = kwt.shrinklines(self.fname, self.lines)
 
     def kw_diff(orig, repo, node1=None, node2=None, match=None, changes=None,
                 opts=None):
-        '''Monkeypatch patch.diff to avoid expansion except when
-        comparing against working dir.'''
+        # only expand when comparing against working dir
         if node2 is not None:
             kwt.matcher = util.never
         elif node1 is not None and node1 != repo['.'].node():
@@ -501,7 +474,7 @@
         return orig(repo, node1, node2, match, changes, opts)
 
     def kwweb_skip(orig, web, req, tmpl):
-        '''Wraps webcommands.x turning off keyword expansion.'''
+        # wrap webcommands.x turning off keyword expansion
         kwt.matcher = util.never
         return orig(web, req, tmpl)
 


More information about the Mercurial-devel mailing list