Patchwork [2,of,8] ignore: refactor syntax concatenation

login
register
mail settings
Submitter Durham Goode
Date May 13, 2015, 3:13 p.m.
Message ID <1236d101b01d25171501.1431529996@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9038/
State Accepted
Headers show

Comments

Durham Goode - May 13, 2015, 3:13 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1431057646 25200
#      Thu May 07 21:00:46 2015 -0700
# Node ID 1236d101b01d251715016df1b0ba53d3a37edfb8
# Parent  7bfb75835fb87a5e906007144b04b7d735ddfdfa
ignore: refactor syntax concatenation

This refactors the syntax+rule concatenation logic to be more separated. It
determines the syntax and the rule separately and then puts them back together.
This will help in a later patch when we want to process just the rule before it
gets concatenated.
Pierre-Yves David - May 14, 2015, 2:54 a.m.
On 05/13/2015 08:13 AM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1431057646 25200
> #      Thu May 07 21:00:46 2015 -0700
> # Node ID 1236d101b01d251715016df1b0ba53d3a37edfb8
> # Parent  7bfb75835fb87a5e906007144b04b7d735ddfdfa
> ignore: refactor syntax concatenation
>
> This refactors the syntax+rule concatenation logic to be more separated. It
> determines the syntax and the rule separately and then puts them back together.
> This will help in a later patch when we want to process just the rule before it
> gets concatenated.

These first two looks good to me and have been pushed to the clowncopter.

Patch

diff --git a/mercurial/ignore.py b/mercurial/ignore.py
--- a/mercurial/ignore.py
+++ b/mercurial/ignore.py
@@ -40,15 +40,18 @@  def ignorepats(lines):
             except KeyError:
                 warnings.append(_("ignoring invalid syntax '%s'") % s)
             continue
-        pat = syntax + line
+
+        linesyntax = syntax
         for s, rels in syntaxes.iteritems():
             if line.startswith(rels):
-                pat = line
+                linesyntax = rels
+                line = line[len(rels):]
                 break
             elif line.startswith(s+':'):
-                pat = rels + line[len(s) + 1:]
+                linesyntax = rels
+                line = line[len(s) + 1:]
                 break
-        patterns.append(pat)
+        patterns.append(linesyntax + line)
 
     return patterns, warnings