merge with crew
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Sun, 09 Jul 2006 14:42:18 +0200
changeset 2584 1f4703115e28
parent 2583 6e5427447f4c (current diff)
parent 2582 276de216d2c5 (diff)
child 2585 5ec2dded1bda
merge with crew
mercurial/ui.py
--- a/mercurial/bdiff.c	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/bdiff.c	Sun Jul 09 14:42:18 2006 +0200
@@ -65,7 +65,7 @@
 
 int splitlines(const char *a, int len, struct line **lr)
 {
-	int h, i;
+	int g, h, i;
 	const char *p, *b = a;
 	struct line *l;
 
@@ -82,7 +82,16 @@
 	/* build the line array and calculate hashes */
 	h = 0;
 	for (p = a; p < a + len; p++) {
-		h = *p + rol32(h, 7); /* a simple hash from GNU diff */
+		/*
+		 * a simple hash from GNU diff, with better collision
+		 * resistance from hashpjw. this slows down common
+		 * case by 10%, but speeds up worst case by 100x.
+		 */
+		h = *p + rol32(h, 7);
+		if ((g = h & 0xf0000000)) {
+			h ^= g >> 24;
+			h ^= g;
+		}
 		if (*p == '\n' || p == a + len - 1) {
 			l->len = p - b + 1;
 			l->h = h * l->len;
--- a/mercurial/commands.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/commands.py	Sun Jul 09 14:42:18 2006 +0200
@@ -231,7 +231,7 @@
     """Yield revision as strings from a list of revision specifications."""
     seen = {}
     for spec in revs:
-        if spec.find(revrangesep) >= 0:
+        if revrangesep in spec:
             start, end = spec.split(revrangesep, 1)
             start = revfix(repo, start, 0)
             end = revfix(repo, end, repo.changelog.count() - 1)
@@ -405,23 +405,33 @@
     diffopts = ui.diffopts()
     showfunc = opts.get('show_function') or diffopts['showfunc']
     ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
+    ignorewsamount = opts.get('ignore_space_change') or \
+                     diffopts['ignorewsamount']
+    ignoreblanklines = opts.get('ignore_blank_lines') or \
+                     diffopts['ignoreblanklines']
     for f in modified:
         to = None
         if f in mmap:
             to = repo.file(f).read(mmap[f])
         tn = read(f)
         fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
-                               showfunc=showfunc, ignorews=ignorews))
+                               showfunc=showfunc, ignorews=ignorews,
+                               ignorewsamount=ignorewsamount,
+                               ignoreblanklines=ignoreblanklines))
     for f in added:
         to = None
         tn = read(f)
         fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
-                               showfunc=showfunc, ignorews=ignorews))
+                               showfunc=showfunc, ignorews=ignorews,
+                               ignorewsamount=ignorewsamount,
+                               ignoreblanklines=ignoreblanklines))
     for f in removed:
         to = repo.file(f).read(mmap[f])
         tn = None
         fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text,
-                               showfunc=showfunc, ignorews=ignorews))
+                               showfunc=showfunc, ignorews=ignorews,
+                               ignorewsamount=ignorewsamount,
+                               ignoreblanklines=ignoreblanklines))
 
 def trimuser(ui, name, rev, revcache):
     """trim the name of the user who committed a change"""
@@ -2742,7 +2752,7 @@
 
     disallowed = (revrangesep, '\r', '\n')
     for c in disallowed:
-        if name.find(c) >= 0:
+        if c in name:
             raise util.Abort(_("%s cannot be used in a tag name") % repr(c))
 
     repo.hook('pretag', throw=True, node=r, tag=name,
@@ -3018,6 +3028,10 @@
            _('show which function each change is in')),
           ('w', 'ignore-all-space', None,
            _('ignore white space when comparing lines')),
+          ('b', 'ignore-space-change', None,
+           _('ignore changes in the amount of white space')),
+          ('B', 'ignore-blank-lines', None,
+           _('ignore changes whose lines are all blank')),
           ('I', 'include', [], _('include names matching the given patterns')),
           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
          _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
--- a/mercurial/filelog.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/filelog.py	Sun Jul 09 14:42:18 2006 +0200
@@ -34,14 +34,14 @@
         t = self.revision(node)
         if not t.startswith('\1\n'):
             return t
-        s = t.find('\1\n', 2)
+        s = t.index('\1\n', 2)
         return t[s+2:]
 
     def readmeta(self, node):
         t = self.revision(node)
         if not t.startswith('\1\n'):
             return {}
-        s = t.find('\1\n', 2)
+        s = t.index('\1\n', 2)
         mt = t[2:s]
         m = {}
         for l in mt.splitlines():
--- a/mercurial/hg.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/hg.py	Sun Jul 09 14:42:18 2006 +0200
@@ -61,8 +61,7 @@
     if not path: path = ''
     scheme = path
     if scheme:
-        c = scheme.find(':')
-        scheme = c >= 0 and scheme[:c]
+        scheme = scheme.split(":", 1)[0]
     ctor = schemes.get(scheme) or schemes['file']
     if create:
         try:
--- a/mercurial/hgweb/hgweb_mod.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/hgweb/hgweb_mod.py	Sun Jul 09 14:42:18 2006 +0200
@@ -133,21 +133,29 @@
         diffopts = self.repo.ui.diffopts()
         showfunc = diffopts['showfunc']
         ignorews = diffopts['ignorews']
+        ignorewsamount = diffopts['ignorewsamount']
+        ignoreblanklines = diffopts['ignoreblanklines']
         for f in modified:
             to = r.file(f).read(mmap1[f])
             tn = r.file(f).read(mmap2[f])
             yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
-                            showfunc=showfunc, ignorews=ignorews), f, tn)
+                            showfunc=showfunc, ignorews=ignorews,
+                            ignorewsamount=ignorewsamount,
+                            ignoreblanklines=ignoreblanklines), f, tn)
         for f in added:
             to = None
             tn = r.file(f).read(mmap2[f])
             yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
-                            showfunc=showfunc, ignorews=ignorews), f, tn)
+                            showfunc=showfunc, ignorews=ignorews,
+                            ignorewsamount=ignorewsamount,
+                            ignoreblanklines=ignoreblanklines), f, tn)
         for f in removed:
             to = r.file(f).read(mmap1[f])
             tn = None
             yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
-                            showfunc=showfunc, ignorews=ignorews), f, tn)
+                            showfunc=showfunc, ignorews=ignorews,
+                            ignorewsamount=ignorewsamount,
+                            ignoreblanklines=ignoreblanklines), f, tn)
 
     def changelog(self, pos):
         def changenav(**map):
@@ -462,7 +470,7 @@
                 continue
             remain = f[l:]
             if "/" in remain:
-                short = remain[:remain.find("/") + 1] # bleah
+                short = remain[:remain.index("/") + 1] # bleah
                 files[short] = (f, None)
             else:
                 short = os.path.basename(remain)
--- a/mercurial/hgweb/server.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/hgweb/server.py	Sun Jul 09 14:42:18 2006 +0200
@@ -127,6 +127,11 @@
             if h[0].lower() == 'content-length':
                 should_close = False
                 self.length = int(h[1])
+        # The value of the Connection header is a list of case-insensitive
+        # tokens separated by commas and optional whitespace.
+        if 'close' in [token.strip().lower() for token in 
+                       self.headers.get('connection', '').split(',')]:
+            should_close = True
         if should_close:
             self.send_header('Connection', 'close')
         self.close_connection = should_close
--- a/mercurial/localrepo.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/localrepo.py	Sun Jul 09 14:42:18 2006 +0200
@@ -74,8 +74,8 @@
         self.transhandle = None
 
         if create:
-	    if not os.path.exists(path):
-		os.mkdir(path)
+            if not os.path.exists(path):
+                os.mkdir(path)
             os.mkdir(self.path)
             os.mkdir(self.join("data"))
 
@@ -101,9 +101,13 @@
             try:
                 obj = __import__(modname)
             except ImportError:
-                raise util.Abort(_('%s hook is invalid '
-                                   '(import of "%s" failed)') %
-                                 (hname, modname))
+                try:
+                    # extensions are loaded with hgext_ prefix
+                    obj = __import__("hgext_%s" % modname)
+                except ImportError:
+                    raise util.Abort(_('%s hook is invalid '
+                                       '(import of "%s" failed)') %
+                                     (hname, modname))
             try:
                 for p in funcname.split('.')[1:]:
                     obj = getattr(obj, p)
--- a/mercurial/lock.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/lock.py	Sun Jul 09 14:42:18 2006 +0200
@@ -85,14 +85,14 @@
         # see if locker is alive.  if locker is on this machine but
         # not alive, we can safely break lock.
         locker = util.readlock(self.f)
-        c = locker.find(':')
-        if c == -1:
+        try:
+            host, pid = locker.split(":", 1)
+        except ValueError:
             return locker
-        host = locker[:c]
         if host != self.host:
             return locker
         try:
-            pid = int(locker[c+1:])
+            pid = int(pid)
         except:
             return locker
         if util.testpid(pid):
--- a/mercurial/mdiff.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/mdiff.py	Sun Jul 09 14:42:18 2006 +0200
@@ -20,7 +20,8 @@
     return lines
 
 def unidiff(a, ad, b, bd, fn, r=None, text=False,
-            showfunc=False, ignorews=False):
+            showfunc=False, ignorews=False, ignorewsamount=False,
+            ignoreblanklines=False):
 
     if not a and not b: return ""
     epoch = util.datestr((0, 0))
@@ -49,7 +50,9 @@
         al = splitnewlines(a)
         bl = splitnewlines(b)
         l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn,
-                          showfunc=showfunc, ignorews=ignorews))
+                          showfunc=showfunc, ignorews=ignorews,
+                          ignorewsamount=ignorewsamount,
+                          ignoreblanklines=ignoreblanklines))
         if not l: return ""
         # difflib uses a space, rather than a tab
         l[0] = "%s\t%s\n" % (l[0][:-2], ad)
@@ -72,8 +75,10 @@
 # context is the number of context lines
 # showfunc enables diff -p output
 # ignorews ignores all whitespace changes in the diff
+# ignorewsamount ignores changes in the amount of whitespace
+# ignoreblanklines ignores changes whose lines are all blank
 def bunidiff(t1, t2, l1, l2, header1, header2, context=3, showfunc=False,
-             ignorews=False):
+             ignorews=False, ignorewsamount=False, ignoreblanklines=False):
     def contextend(l, len):
         ret = l + context
         if ret > len:
@@ -116,6 +121,11 @@
 
     if showfunc:
         funcre = re.compile('\w')
+    if ignorewsamount:
+        wsamountre = re.compile('[ \t]+')
+        wsappendedre = re.compile(' \n')
+    if ignoreblanklines:
+        wsblanklinesre = re.compile('\n')
     if ignorews:
         wsre = re.compile('[ \t]')
 
@@ -149,6 +159,20 @@
         if not old and not new:
             continue
 
+        if ignoreblanklines:
+            wsold = wsblanklinesre.sub('', "".join(old))
+            wsnew = wsblanklinesre.sub('', "".join(new))
+            if wsold == wsnew:
+                continue
+
+        if ignorewsamount:
+            wsold = wsamountre.sub(' ', "".join(old))
+            wsold = wsappendedre.sub('\n', wsold)
+            wsnew = wsamountre.sub(' ', "".join(new))
+            wsnew = wsappendedre.sub('\n', wsnew)
+            if wsold == wsnew:
+                continue
+
         if ignorews:
             wsold = wsre.sub('', "".join(old))
             wsnew = wsre.sub('', "".join(new))
--- a/mercurial/ui.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/ui.py	Sun Jul 09 14:42:18 2006 +0200
@@ -76,7 +76,7 @@
         if root is None:
             root = os.path.expanduser('~')
         for name, path in self.configitems("paths"):
-            if path and path.find("://") == -1 and not os.path.isabs(path):
+            if path and "://" not in path and not os.path.isabs(path):
                 self.cdata.set("paths", name, os.path.join(root, path))
 
     def setconfig(self, section, name, val):
@@ -172,7 +172,8 @@
     def diffopts(self):
         if self.diffcache:
             return self.diffcache
-        result = {'showfunc': True, 'ignorews': False}
+        result = {'showfunc': True, 'ignorews': False,
+                  'ignorewsamount': False, 'ignoreblanklines': False}
         for key, value in self.configitems("diff"):
             if value:
                 result[key.lower()] = (value.lower() == 'true')
@@ -208,7 +209,7 @@
 
     def expandpath(self, loc, default=None):
         """Return repository location relative to cwd or from [paths]"""
-        if loc.find("://") != -1 or os.path.exists(loc):
+        if "://" in loc or os.path.exists(loc):
             return loc
 
         path = self.config("paths", loc)
--- a/mercurial/util.py	Sun Jul 09 14:12:19 2006 +0200
+++ b/mercurial/util.py	Sun Jul 09 14:42:18 2006 +0200
@@ -620,7 +620,7 @@
     def parse_patch_output(output_line):
         """parses the output produced by patch and returns the file name"""
         pf = output_line[14:]
-        if pf.startswith("'") and pf.endswith("'") and pf.find(" ") >= 0:
+        if pf.startswith("'") and pf.endswith("'") and " " in pf:
             pf = pf[1:-1] # Remove the quotes
         return pf
 
--- a/tests/test-help.out	Sun Jul 09 14:12:19 2006 +0200
+++ b/tests/test-help.out	Sun Jul 09 14:42:18 2006 +0200
@@ -173,12 +173,14 @@
 
 options:
 
- -r --rev               revision
- -a --text              treat all files as text
- -p --show-function     show which function each change is in
- -w --ignore-all-space  ignore white space when comparing lines
- -I --include           include names matching the given patterns
- -X --exclude           exclude names matching the given patterns
+ -r --rev                  revision
+ -a --text                 treat all files as text
+ -p --show-function        show which function each change is in
+ -w --ignore-all-space     ignore white space when comparing lines
+ -b --ignore-space-change  ignore changes in the amount of white space
+ -B --ignore-blank-lines   ignore changes whose lines are all blank
+ -I --include              include names matching the given patterns
+ -X --exclude              exclude names matching the given patterns
 hg status [OPTION]... [FILE]...
 
 show changed files in the working directory