diff --git a/mercurial/bdiff.c b/mercurial/bdiff.c --- a/mercurial/bdiff.c +++ b/mercurial/bdiff.c @@ -65,7 +65,7 @@ static inline uint32_t rol32(uint32_t wo 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 @@ int splitlines(const char *a, int len, s /* 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; diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -231,7 +231,7 @@ def revrange(ui, repo, revs): """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 @@ def dodiff(fp, ui, repo, node1, node2, f 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 @@ def tag(ui, repo, name, rev_=None, **opt 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 @@ table = { _('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]...')), diff --git a/mercurial/filelog.py b/mercurial/filelog.py --- a/mercurial/filelog.py +++ b/mercurial/filelog.py @@ -34,14 +34,14 @@ class filelog(revlog): 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(): diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -61,8 +61,7 @@ def repository(ui, path=None, create=0): 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: diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -133,21 +133,29 @@ class hgweb(object): 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 @@ class hgweb(object): 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) diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py +++ b/mercurial/hgweb/server.py @@ -127,6 +127,11 @@ class _hgwebhandler(object, BaseHTTPServ 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 diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -74,8 +74,8 @@ class localrepository(object): 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 @@ class localrepository(object): 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) diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -85,14 +85,14 @@ class lock(object): # 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): diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -20,7 +20,8 @@ def splitnewlines(text): 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 @@ def unidiff(a, ad, b, bd, fn, r=None, te 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 @@ def unidiff(a, ad, b, bd, fn, r=None, te # 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 @@ def bunidiff(t1, t2, l1, l2, header1, he 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 @@ def bunidiff(t1, t2, l1, l2, header1, he 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)) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -76,7 +76,7 @@ class ui(object): 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 @@ class ui(object): 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 @@ class ui(object): 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) diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -620,7 +620,7 @@ else: 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 diff --git a/tests/test-help.out b/tests/test-help.out --- a/tests/test-help.out +++ b/tests/test-help.out @@ -173,12 +173,14 @@ diff repository (or selected files) 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