changeset 3099:09e8aecd8016

Merge with backout
author Matt Mackall <mpm@selenic.com>
date Fri, 15 Sep 2006 16:01:16 -0500
parents c27d1e1798a3 (current diff) fe9b13e35e46 (diff)
children ef4e5d05bac4
files doc/hgrc.5.txt mercurial/ui.py
diffstat 55 files changed, 998 insertions(+), 408 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contrib/churn.py	Fri Sep 15 16:01:16 2006 -0500
@@ -0,0 +1,179 @@
+# churn.py - create a graph showing who changed the most lines
+#
+# Copyright 2006 Josef "Jeff" Sipek <jeffpc@josefsipek.net>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+#
+#
+# Aliases map file format is simple one alias per line in the following
+# format:
+#
+# <alias email> <actual email>
+
+from mercurial.demandload import *
+from mercurial.i18n import gettext as _
+demandload(globals(), 'time sys signal os')
+demandload(globals(), 'mercurial:hg,mdiff,fancyopts,cmdutil,ui,util,templater,node')
+
+def __gather(ui, repo, node1, node2):
+    def dirtywork(f, mmap1, mmap2):
+        lines = 0
+
+        to = mmap1 and repo.file(f).read(mmap1[f]) or None
+        tn = mmap2 and repo.file(f).read(mmap2[f]) or None
+
+        diff = mdiff.unidiff(to, "", tn, "", f).split("\n")
+
+        for line in diff:
+            if not line:
+                continue # skip EOF
+            if line.startswith(" "):
+                continue # context line
+            if line.startswith("--- ") or line.startswith("+++ "):
+                continue # begining of diff
+            if line.startswith("@@ "):
+                continue # info line
+
+            # changed lines
+            lines += 1
+
+        return lines
+
+    ##
+
+    lines = 0
+
+    changes = repo.status(node1, node2, None, util.always)[:5]
+
+    modified, added, removed, deleted, unknown = changes
+
+    who = repo.changelog.read(node2)[1]
+    who = templater.email(who) # get the email of the person
+
+    mmap1 = repo.manifest.read(repo.changelog.read(node1)[0])
+    mmap2 = repo.manifest.read(repo.changelog.read(node2)[0])
+    for f in modified:
+        lines += dirtywork(f, mmap1, mmap2)
+
+    for f in added:
+        lines += dirtywork(f, None, mmap2)
+        
+    for f in removed:
+        lines += dirtywork(f, mmap1, None)
+
+    for f in deleted:
+        lines += dirtywork(f, mmap1, mmap2)
+
+    for f in unknown:
+        lines += dirtywork(f, mmap1, mmap2)
+
+    return (who, lines)
+
+def gather_stats(ui, repo, amap, revs=None, progress=False):
+    stats = {}
+    
+    cl    = repo.changelog
+
+    if not revs:
+        revs = range(0, cl.count())
+
+    nr_revs = len(revs)
+    cur_rev = 0
+
+    for rev in revs:
+        cur_rev += 1 # next revision
+
+        node2    = cl.node(rev)
+        node1    = cl.parents(node2)[0]
+
+        if cl.parents(node2)[1] != node.nullid:
+            ui.note(_('Revision %d is a merge, ignoring...\n') % (rev,))
+            continue
+
+        who, lines = __gather(ui, repo, node1, node2)
+
+        # remap the owner if possible
+        if amap.has_key(who):
+            ui.note("using '%s' alias for '%s'\n" % (amap[who], who))
+            who = amap[who]
+
+        if not stats.has_key(who):
+            stats[who] = 0
+        stats[who] += lines
+
+        ui.note("rev %d: %d lines by %s\n" % (rev, lines, who))
+
+        if progress:
+            if int(100.0*(cur_rev - 1)/nr_revs) < int(100.0*cur_rev/nr_revs):
+                ui.write("%d%%.." % (int(100.0*cur_rev/nr_revs),))
+                sys.stdout.flush()
+
+    if progress:
+        ui.write("done\n")
+        sys.stdout.flush()
+
+    return stats
+
+def churn(ui, repo, **opts):
+    "Graphs the number of lines changed"
+    
+    def pad(s, l):
+        if len(s) < l:
+            return s + " " * (l-len(s))
+        return s[0:l]
+
+    def graph(n, maximum, width, char):
+        n = int(n * width / float(maximum))
+        
+        return char * (n)
+
+    def get_aliases(f):
+        aliases = {}
+
+        for l in f.readlines():
+            l = l.strip()
+            alias, actual = l.split(" ")
+            aliases[alias] = actual
+
+        return aliases
+    
+    amap = {}
+    aliases = opts.get('aliases')
+    if aliases:
+        try:
+            f = open(aliases,"r")
+        except OSError, e:
+            print "Error: " + e
+            return
+
+        amap = get_aliases(f)
+        f.close()
+
+    revs = [int(r) for r in cmdutil.revrange(ui, repo, opts['rev'])]
+    revs.sort()
+    stats = gather_stats(ui, repo, amap, revs, opts.get('progress'))
+
+    # make a list of tuples (name, lines) and sort it in descending order
+    ordered = stats.items()
+    ordered.sort(lambda x, y: cmp(y[1], x[1]))
+
+    maximum = ordered[0][1]
+
+    ui.note("Assuming 80 character terminal\n")
+    width = 80 - 1
+
+    for i in ordered:
+        person = i[0]
+        lines = i[1]
+        print "%s %6d %s" % (pad(person, 20), lines,
+                graph(lines, maximum, width - 20 - 1 - 6 - 2 - 2, '*'))
+
+cmdtable = {
+    "churn":
+    (churn,
+     [('r', 'rev', [], _('limit statistics to the specified revisions')),
+      ('', 'aliases', '', _('file with email aliases')),
+      ('', 'progress', None, _('show progress'))],
+    'hg churn [-r revision range] [-a file] [--progress]'),
+}
--- a/contrib/hgk	Fri Sep 15 16:00:16 2006 -0500
+++ b/contrib/hgk	Fri Sep 15 16:01:16 2006 -0500
@@ -30,15 +30,29 @@
     set startmsecs [clock clicks -milliseconds]
     set nextupdate [expr $startmsecs + 100]
     set ncmupdate 1
+    set limit 0
+    set revargs {}
+    for {set i 0} {$i < [llength $rargs]} {incr i} {
+	set opt [lindex $rargs $i]
+	if {$opt == "--limit"} {
+	    incr i
+	    set limit [lindex $rargs $i]
+	} else {
+	    lappend revargs $opt
+	}
+    }
     if [catch {
-	set parse_args [concat --default HEAD $rargs]
+	set parse_args [concat --default HEAD $revargs]
 	set parsed_args [split [eval exec hg debug-rev-parse $parse_args] "\n"]
-    }] {
+    } err] {
 	# if git-rev-parse failed for some reason...
 	if {$rargs == {}} {
-	    set rargs HEAD
+	    set revargs HEAD
 	}
-	set parsed_args $rargs
+	set parsed_args $revargs
+    }
+    if {$limit > 0} {
+	set parsed_args [concat -n $limit $parsed_args]
     }
     if [catch {
 	set commfd [open "|hg debug-rev-list --header --topo-order --parents $parsed_args" r]
@@ -100,7 +114,7 @@
 	    set ids [string range $cmit 0 [expr {$j - 1}]]
 	    set ok 1
 	    foreach id $ids {
-		if {![regexp {^[0-9a-f]{40}$} $id]} {
+		if {![regexp {^[0-9a-f]{12}$} $id]} {
 		    set ok 0
 		    break
 		}
@@ -176,6 +190,7 @@
     set audate {}
     set comname {}
     set comdate {}
+    set rev {}
     if {![info exists nchildren($id)]} {
 	set children($id) {}
 	set nchildren($id) 0
@@ -209,6 +224,8 @@
 		    set x [expr {[llength $line] - 2}]
 		    set comdate [lindex $line $x]
 		    set comname [join [lrange $line 1 [expr {$x - 1}]]]
+		} elseif {$tag == "revision"} {
+		    set rev [lindex $line 1]
 		}
 	    }
 	} else {
@@ -233,7 +250,7 @@
 	set comdate [clock format $comdate -format "%Y-%m-%d %H:%M:%S"]
     }
     set commitinfo($id) [list $headline $auname $audate \
-			     $comname $comdate $comment]
+			     $comname $comdate $comment $rev]
 }
 
 proc readrefs {} {
@@ -261,7 +278,7 @@
 	catch {
 	    set fd [open $f r]
 	    set line [read $fd 40]
-	    if {[regexp {^[0-9a-f]{40}} $line id]} {
+	    if {[regexp {^[0-9a-f]{12}} $line id]} {
 		set name "$dname[file tail $f]"
 		set otherrefids($name) $id
 		lappend idotherrefs($id) $name
@@ -1743,7 +1760,7 @@
 	}
 	return
     }
-    if {![regexp {^[0-9a-f]{40}} $line id]} {
+    if {![regexp {^[0-9a-f]{12}} $line id]} {
 	error_popup "Can't parse git-diff-tree output: $line"
 	stopfindproc
 	return
@@ -1856,7 +1873,7 @@
 	}
 	return
     }
-    if {[regexp {^([0-9a-f]{40}) \(from ([0-9a-f]{40})\)} $line match id p]} {
+    if {[regexp {^([0-9a-f]{12}) \(from ([0-9a-f]{12})\)} $line match id p]} {
 	# start of a new string of diffs
 	donefilediff
 	set fdiffids [list $id $p]
@@ -2002,8 +2019,9 @@
     set l "..."
     if {[info exists commitinfo($p)]} {
 	set l [lindex $commitinfo($p) 0]
+	set r [lindex $commitinfo($p) 6]
     }
-    return "$p ($l)"
+    return "$r:$p ($l)"
 }
 
 # append some text to the ctext widget, and make any SHA1 ID
@@ -2014,7 +2032,7 @@
     set start [$ctext index "end - 1c"]
     $ctext insert end $text
     $ctext insert end "\n"
-    set links [regexp -indices -all -inline {[0-9a-f]{40}} $text]
+    set links [regexp -indices -all -inline {[0-9a-f]{12}} $text]
     foreach l $links {
 	set s [lindex $l 0]
 	set e [lindex $l 1]
@@ -2107,6 +2125,7 @@
     $ctext mark set fmark.0 0.0
     $ctext mark gravity fmark.0 left
     set info $commitinfo($id)
+    $ctext insert end "Revision: [lindex $info 6]\n"
     $ctext insert end "Author: [lindex $info 1]  [lindex $info 2]\n"
     $ctext insert end "Committer: [lindex $info 3]  [lindex $info 4]\n"
     if {[info exists idtags($id)]} {
--- a/doc/hg.1.txt	Fri Sep 15 16:00:16 2006 -0500
+++ b/doc/hg.1.txt	Fri Sep 15 16:01:16 2006 -0500
@@ -193,6 +193,10 @@
     global /etc/mercurial/hgrc configuration.  See hgrc(5) for details of
     the contents and format of these files.
 
+Some commands (e.g. revert) produce backup files ending in .orig, if
+the .orig file already exists and is not tracked by Mercurial, it
+will be overwritten.
+
 BUGS
 ----
 Probably lots, please post them to the mailing list (See Resources below)
--- a/doc/hgrc.5.txt	Fri Sep 15 16:00:16 2006 -0500
+++ b/doc/hgrc.5.txt	Fri Sep 15 16:01:16 2006 -0500
@@ -133,6 +133,21 @@
     # them to the working dir
     **.txt = tempfile: unix2dos -n INFILE OUTFILE
 
+defaults::
+  Use the [defaults] section to define command defaults, i.e. the 
+  default options/arguments to pass to the specified commands.
+  
+  The following example makes 'hg log' run in verbose mode, and
+  'hg status' show only the modified files, by default.
+  
+    [defaults]
+    log = -v
+    status = -m
+  
+  The actual commands, instead of their aliases, must be used when 
+  defining command defaults. The command defaults will also be
+  applied to the aliases of the commands defined.
+
 email::
   Settings for extensions that send email messages.
   from;;
--- a/hgeditor	Fri Sep 15 16:00:16 2006 -0500
+++ b/hgeditor	Fri Sep 15 16:01:16 2006 -0500
@@ -41,13 +41,15 @@
 
 cat "$1" > "$HGTMP/msg"
 
-CHECKSUM=`md5sum "$HGTMP/msg"`
+MD5=$(which md5sum 2>/dev/null) || \
+    MD5=$(which md5 2>/dev/null) 
+[ -x "${MD5}" ] && CHECKSUM=`${MD5} "$HGTMP/msg"`
 if [ -s "$HGTMP/diff" ]; then
     $EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $?
 else
     $EDITOR "$HGTMP/msg" || exit $?
 fi
-echo "$CHECKSUM" | md5sum -c >/dev/null 2>&1 && exit 13
+[ -x "${MD5}" ] && (echo "$CHECKSUM" | ${MD5} -c >/dev/null 2>&1 && exit 13)
 
 mv "$HGTMP/msg" "$1"
 
--- a/hgext/acl.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/hgext/acl.py	Fri Sep 15 16:01:16 2006 -0500
@@ -60,8 +60,8 @@
             return None, False
 
         thisuser = self.getuser()
-        pats = [pat for pat, user in self.ui.configitems(key)
-                if user == thisuser]
+        pats = [pat for pat, users in self.ui.configitems(key)
+                if thisuser in users.replace(',', ' ').split()]
         self.ui.debug(_('acl: %s enabled, %d entries for user %s\n') %
                       (key, len(pats), thisuser))
         if pats:
--- a/hgext/extdiff.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/hgext/extdiff.py	Fri Sep 15 16:01:16 2006 -0500
@@ -45,7 +45,7 @@
 from mercurial.demandload import demandload
 from mercurial.i18n import gettext as _
 from mercurial.node import *
-demandload(globals(), 'mercurial:commands,cmdutil,util os shutil tempfile')
+demandload(globals(), 'mercurial:cmdutil,util os shutil tempfile')
 
 def dodiff(ui, repo, diffcmd, diffopts, pats, opts):
     def snapshot_node(files, node):
@@ -90,7 +90,7 @@
                 fp.write(chunk)
         return dirname
 
-    node1, node2 = commands.revpair(ui, repo, opts['rev'])
+    node1, node2 = cmdutil.revpair(ui, repo, opts['rev'])
     files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
     modified, added, removed, deleted, unknown = repo.status(
         node1, node2, files, match=matchfn)[:5]
@@ -105,8 +105,7 @@
         else:
             dir2 = snapshot_wdir(modified + added)
         cmdline = ('%s %s %s %s' %
-                   (util.shellquote(diffcmd),
-                    ' '.join(map(util.shellquote, diffopts)),
+                   (util.shellquote(diffcmd), ' '.join(diffopts),
                     util.shellquote(dir1), util.shellquote(dir2)))
         ui.debug('running %r in %s\n' % (cmdline, tmproot))
         util.system(cmdline, cwd=tmproot)
--- a/hgext/hgk.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/hgext/hgk.py	Fri Sep 15 16:01:16 2006 -0500
@@ -7,92 +7,39 @@
 
 from mercurial.demandload import *
 demandload(globals(), 'time sys signal os')
-demandload(globals(), 'mercurial:hg,mdiff,fancyopts,commands,ui,util')
-
-def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
-           changes=None, text=False):
-    def date(c):
-        return time.asctime(time.gmtime(c[2][0]))
-
-    if not changes:
-        changes = repo.status(node1, node2, files, match=match)[:5]
-    modified, added, removed, deleted, unknown = changes
-    if files:
-        modified, added, removed = map(lambda x: filterfiles(files, x),
-                                       (modified, added, removed))
-
-    if not modified and not added and not removed:
-        return
-
-    if node2:
-        change = repo.changelog.read(node2)
-        mmap2 = repo.manifest.read(change[0])
-        date2 = date(change)
-        def read(f):
-            return repo.file(f).read(mmap2[f])
-    else:
-        date2 = time.asctime()
-        if not node1:
-            node1 = repo.dirstate.parents()[0]
-        def read(f):
-            return repo.wfile(f).read()
+demandload(globals(), 'mercurial:hg,fancyopts,commands,ui,util,patch,revlog')
 
-    change = repo.changelog.read(node1)
-    mmap = repo.manifest.read(change[0])
-    date1 = date(change)
-
-    for f in modified:
-        to = None
-        if f in mmap:
-            to = repo.file(f).read(mmap[f])
-        tn = read(f)
-        opts = mdiff.diffopts()
-        opts.text = text
-        fp.write("diff --git a/%s b/%s\n" % (f, f))
-        fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts))
-    for f in added:
-        to = None
-        tn = read(f)
-        fp.write("diff --git /dev/null b/%s\n" % (f))
-        fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts))
-    for f in removed:
-        to = repo.file(f).read(mmap[f])
-        tn = None
-        fp.write("diff --git a/%s /dev/null\n" % (f))
-        fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts))
-
-def difftree(ui, repo, node1=None, node2=None, **opts):
+def difftree(ui, repo, node1=None, node2=None, *files, **opts):
     """diff trees from two commits"""
-    def __difftree(repo, node1, node2):
-        def date(c):
-            return time.asctime(time.gmtime(c[2][0]))
-
+    def __difftree(repo, node1, node2, files=[]):
         if node2:
             change = repo.changelog.read(node2)
             mmap2 = repo.manifest.read(change[0])
-            modified, added, removed, deleted, unknown = repo.status(node1, node2)[:5]
-            def read(f): return repo.file(f).read(mmap2[f])
-            date2 = date(change)
+            status = repo.status(node1, node2, files=files)[:5]
+            modified, added, removed, deleted, unknown = status
         else:
-            date2 = time.asctime()
-            modified, added, removed, deleted, unknown = repo.status(node1)[:5]
+            status = repo.status(node1, files=files)[:5]
+            modified, added, removed, deleted, unknown = status
             if not node1:
                 node1 = repo.dirstate.parents()[0]
-            def read(f): return file(os.path.join(repo.root, f)).read()
 
         change = repo.changelog.read(node1)
         mmap = repo.manifest.read(change[0])
-        date1 = date(change)
-        empty = "0" * 40;
+        empty = hg.short(hg.nullid)
 
         for f in modified:
             # TODO get file permissions
-            print ":100664 100664 %s %s M\t%s\t%s" % (hg.hex(mmap[f]),
-                                                      hg.hex(mmap2[f]), f, f)
+            print ":100664 100664 %s %s M\t%s\t%s" % (hg.short(mmap[f]),
+                                                      hg.short(mmap2[f]),
+                                                      f, f)
         for f in added:
-            print ":000000 100664 %s %s N\t%s\t%s" % (empty, hg.hex(mmap2[f]), f, f)
+            print ":000000 100664 %s %s N\t%s\t%s" % (empty,
+                                                      hg.short(mmap2[f]),
+                                                      f, f)
         for f in removed:
-            print ":100664 000000 %s %s D\t%s\t%s" % (hg.hex(mmap[f]), empty, f, f)
+            print ":100664 000000 %s %s D\t%s\t%s" % (hg.short(mmap[f]),
+                                                      empty,
+                                                      f, f)
     ##
 
     while True:
@@ -115,20 +62,22 @@
         if opts['patch']:
             if opts['pretty']:
                 catcommit(repo, node2, "")
-            dodiff(sys.stdout, ui, repo, node1, node2)
+            patch.diff(repo, node1, node2,
+                       files=files,
+                       opts=patch.diffopts(ui, {'git': True}))
         else:
-            __difftree(repo, node1, node2)
+            __difftree(repo, node1, node2, files=files)
         if not opts['stdin']:
             break
 
 def catcommit(repo, n, prefix, changes=None):
     nlprefix = '\n' + prefix;
     (p1, p2) = repo.changelog.parents(n)
-    (h, h1, h2) = map(hg.hex, (n, p1, p2))
+    (h, h1, h2) = map(hg.short, (n, p1, p2))
     (i1, i2) = map(repo.changelog.rev, (p1, p2))
     if not changes:
         changes = repo.changelog.read(n)
-    print "tree %s" % (hg.hex(changes[0]))
+    print "tree %s" % (hg.short(changes[0]))
     if i1 != -1: print "parent %s" % (h1)
     if i2 != -1: print "parent %s" % (h2)
     date_ar = changes[2]
@@ -141,6 +90,7 @@
 
     print "author %s %s %s" % (changes[1], date, date_ar[1])
     print "committer %s %s %s" % (committer, date, date_ar[1])
+    print "revision %d" % repo.changelog.rev(n)
     print ""
     if prefix != "":
         print "%s%s" % (prefix, changes[4].replace('\n', nlprefix).strip())
@@ -154,7 +104,7 @@
     node1 = repo.lookup(node1)
     node2 = repo.lookup(node2)
     n = repo.changelog.ancestor(node1, node2)
-    print hg.hex(n)
+    print hg.short(n)
 
 def catfile(ui, repo, type=None, r=None, **opts):
     """cat a specific revision"""
@@ -267,7 +217,6 @@
 
     # walk the repository looking for commits that are in our
     # reachability graph
-    #for i in range(repo.changelog.count()-1, -1, -1):
     for i, changes in chlogwalk():
         n = repo.changelog.node(i)
         mask = is_reachable(want_sha1, reachable, n)
@@ -276,17 +225,17 @@
             if parents:
                 pp = repo.changelog.parents(n)
                 if pp[0] != hg.nullid:
-                    parentstr += " " + hg.hex(pp[0])
+                    parentstr += " " + hg.short(pp[0])
                 if pp[1] != hg.nullid:
-                    parentstr += " " + hg.hex(pp[1])
+                    parentstr += " " + hg.short(pp[1])
             if not full:
-                print hg.hex(n) + parentstr
-            elif full is "commit":
-                print hg.hex(n) + parentstr
+                print hg.short(n) + parentstr
+            elif full == "commit":
+                print hg.short(n) + parentstr
                 catcommit(repo, n, '    ', changes)
             else:
                 (p1, p2) = repo.changelog.parents(n)
-                (h, h1, h2) = map(hg.hex, (n, p1, p2))
+                (h, h1, h2) = map(hg.short, (n, p1, p2))
                 (i1, i2) = map(repo.changelog.rev, (p1, p2))
 
                 date = changes[2][0]
@@ -302,6 +251,19 @@
                 break
             count += 1
 
+def revparse(ui, repo, *revs, **opts):
+    """Parse given revisions"""
+    def revstr(rev):
+        if rev == 'HEAD':
+            rev = 'tip'
+        return revlog.hex(repo.lookup(rev))
+
+    for r in revs:
+        revrange = r.split(':', 1)
+        ui.write('%s\n' % revstr(revrange[0]))
+        if len(revrange) == 2:
+            ui.write('^%s\n' % revstr(revrange[1]))
+
 # git rev-list tries to order things by date, and has the ability to stop
 # at a given commit without walking the whole repo.  TODO add the stop
 # parameter
@@ -314,23 +276,29 @@
     copy = [x for x in revs]
     revtree(copy, repo, full, opts['max_count'], opts['parents'])
 
-def view(ui, repo, *etc):
+def view(ui, repo, *etc, **opts):
     "start interactive history viewer"
     os.chdir(repo.root)
-    os.system(ui.config("hgk", "path", "hgk") + " " + " ".join(etc))
+    optstr = ' '.join(['--%s %s' % (k, v) for k, v in opts.iteritems()])
+    os.system(ui.config("hgk", "path", "hgk") + " %s %s" % (optstr, " ".join(etc)))
 
 cmdtable = {
-    "view": (view, [], 'hg view'),
+    "view": (view,
+             [('l', 'limit', '', 'limit number of changes displayed')],
+             'hg view [-l LIMIT] [REVRANGE]'),
     "debug-diff-tree": (difftree, [('p', 'patch', None, 'generate patch'),
                             ('r', 'recursive', None, 'recursive'),
                             ('P', 'pretty', None, 'pretty'),
                             ('s', 'stdin', None, 'stdin'),
                             ('C', 'copy', None, 'detect copies'),
                             ('S', 'search', "", 'search')],
-                            "hg git-diff-tree [options] node1 node2"),
+                            "hg git-diff-tree [options] node1 node2 [files...]"),
     "debug-cat-file": (catfile, [('s', 'stdin', None, 'stdin')],
                  "hg debug-cat-file [options] type file"),
     "debug-merge-base": (base, [], "hg debug-merge-base node node"),
+    'debug-rev-parse': (revparse,
+                        [('', 'default', '', 'ignored')],
+                        "hg debug-rev-parse rev"),
     "debug-rev-list": (revlist, [('H', 'header', None, 'header'),
                            ('t', 'topo-order', None, 'topo-order'),
                            ('p', 'parents', None, 'parents'),
--- a/hgext/mq.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/hgext/mq.py	Fri Sep 15 16:01:16 2006 -0500
@@ -40,7 +40,7 @@
 class statusentry:
     def __init__(self, rev, name=None):
         if not name:
-            fields = rev.split(':')
+            fields = rev.split(':', 1)
             if len(fields) == 2:
                 self.rev, self.name = fields
             else:
@@ -483,24 +483,35 @@
         tr.close()
         return (err, n)
 
-    def delete(self, repo, patches, keep=False):
+    def delete(self, repo, patches, opts):
         realpatches = []
+        appliedbase = 0
+        forget = opts.get('forget')
         for patch in patches:
             patch = self.lookup(patch, strict=True)
             info = self.isapplied(patch)
-            if info:
+            if info and not forget:
                 raise util.Abort(_("cannot delete applied patch %s") % patch)
             if patch not in self.series:
                 raise util.Abort(_("patch %s not in series file") % patch)
+            if forget:
+                if not info:
+                    raise util.Abort(_("cannot forget unapplied patch %s") % patch)
+                if info[0] != appliedbase:
+                    raise util.Abort(_("patch %s not at base") % patch)
+                appliedbase += 1
             realpatches.append(patch)
 
-        if not keep:
+        if not opts.get('keep'):
             r = self.qrepo()
             if r:
                 r.remove(realpatches, True)
             else:
                 os.unlink(self.join(patch))
 
+        if forget:
+            del self.applied[:appliedbase]
+            self.applied_dirty = 1
         indices = [self.find_series(p) for p in realpatches]
         indices.sort()
         for i in indices[-1::-1]:
@@ -694,8 +705,8 @@
         stripall(rev, revnum)
 
         change = chlog.read(rev)
+        chlog.strip(revnum, revnum)
         repo.manifest.strip(repo.manifest.rev(change[0]), revnum)
-        chlog.strip(revnum, revnum)
         if saveheads:
             self.ui.status("adding branch\n")
             commands.unbundle(self.ui, repo, chgrpfile, update=False)
@@ -757,25 +768,25 @@
                 # return any partial match made above
                 if res:
                     return res
-                minus = patch.rsplit('-', 1)
-                if len(minus) > 1:
-                    res = partial_name(minus[0])
+                minus = patch.rfind('-')
+                if minus >= 0:
+                    res = partial_name(patch[:minus])
                     if res:
                         i = self.series.index(res)
                         try:
-                            off = int(minus[1] or 1)
+                            off = int(patch[minus+1:] or 1)
                         except(ValueError, OverflowError):
                             pass
                         else:
                             if i - off >= 0:
                                 return self.series[i - off]
-                plus = patch.rsplit('+', 1)
-                if len(plus) > 1:
-                    res = partial_name(plus[0])
+                plus = patch.rfind('+')
+                if plus >= 0:
+                    res = partial_name(patch[:plus])
                     if res:
                         i = self.series.index(res)
                         try:
-                            off = int(plus[1] or 1)
+                            off = int(patch[plus+1:] or 1)
                         except(ValueError, OverflowError):
                             pass
                         else:
@@ -919,13 +930,13 @@
             return 1
         wlock = repo.wlock()
         self.check_toppatch(repo)
-        (top, patch) = (self.applied[-1].rev, self.applied[-1].name)
+        (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name)
         top = revlog.bin(top)
         cparents = repo.changelog.parents(top)
         patchparent = self.qparents(repo, top)
-        message, comments, user, date, patchfound = self.readheaders(patch)
+        message, comments, user, date, patchfound = self.readheaders(patchfn)
 
-        patchf = self.opener(patch, "w")
+        patchf = self.opener(patchfn, "w")
         msg = opts.get('msg', '').rstrip()
         if msg:
             if comments:
@@ -995,8 +1006,11 @@
             r = list(util.unique(dd))
             a = list(util.unique(aa))
             filelist = filter(matchfn, util.unique(m + r + a))
-            self.printdiff(repo, patchparent, files=filelist,
-                           changes=(m, a, r, [], u), fp=patchf)
+            if opts.get('git'):
+                self.diffopts().git = True
+            patch.diff(repo, patchparent, files=filelist, match=matchfn,
+                       fp=patchf, changes=(m, a, r, [], u),
+                       opts=self.diffopts())
             patchf.close()
 
             changes = repo.changelog.read(tip)
@@ -1019,7 +1033,7 @@
 
             if not msg:
                 if not message:
-                    message = "patch queue: %s\n" % patch
+                    message = "patch queue: %s\n" % patchfn
                 else:
                     message = "\n".join(message)
             else:
@@ -1027,7 +1041,7 @@
 
             self.strip(repo, top, update=False, backup='strip', wlock=wlock)
             n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock)
-            self.applied[-1] = statusentry(revlog.hex(n), patch)
+            self.applied[-1] = statusentry(revlog.hex(n), patchfn)
             self.applied_dirty = 1
         else:
             self.printdiff(repo, patchparent, fp=patchf)
@@ -1303,10 +1317,15 @@
 def delete(ui, repo, patch, *patches, **opts):
     """remove patches from queue
 
-    The patches must not be applied.
-    With -k, the patch files are preserved in the patch directory."""
+    With --forget, mq will stop managing the named patches. The
+    patches must be applied and at the base of the stack. This option
+    is useful when the patches have been applied upstream.
+
+    Otherwise, the patches must not be applied.
+
+    With --keep, the patch files are preserved in the patch directory."""
     q = repo.mq
-    q.delete(repo, (patch,) + patches, keep=opts.get('keep'))
+    q.delete(repo, (patch,) + patches, opts)
     q.save_dirty()
     return 0
 
@@ -1478,7 +1497,7 @@
     if not files:
         raise util.Abort(_('qfold requires at least one patch name'))
     if not q.check_toppatch(repo):
-        raise util.Abort(_('No patches applied\n'))
+        raise util.Abort(_('No patches applied'))
 
     message = commands.logmessage(opts)
     if opts['edit']:
@@ -1650,13 +1669,6 @@
         name = patch
         patch = None
 
-    if name in q.series:
-        raise util.Abort(_('A patch named %s already exists in the series file') % name)
-
-    absdest = q.join(name)
-    if os.path.exists(absdest):
-        raise util.Abort(_('%s already exists') % absdest)
-    
     if patch:
         patch = q.lookup(patch)
     else:
@@ -1664,6 +1676,15 @@
             ui.write(_('No patches applied\n'))
             return
         patch = q.lookup('qtip')
+    absdest = q.join(name)
+    if os.path.isdir(absdest):
+        name = os.path.join(name, os.path.basename(patch))
+        absdest = q.join(name)
+    if os.path.exists(absdest):
+        raise util.Abort(_('%s already exists') % absdest)
+    
+    if name in q.series:
+        raise util.Abort(_('A patch named %s already exists in the series file') % name)
 
     if ui.verbose:
         ui.write('Renaming %s to %s\n' % (patch, name))
@@ -1735,7 +1756,8 @@
         backup = 'strip'
     elif opts['nobackup']:
         backup = 'none'
-    repo.mq.strip(repo, rev, backup=backup)
+    update = repo.dirstate.parents()[0] != revlog.nullid
+    repo.mq.strip(repo, rev, backup=backup, update=update)
     return 0
 
 def select(ui, repo, *args, **opts):
@@ -1911,8 +1933,9 @@
                'hg qdiff [-I] [-X] [FILE]...'),
     "qdelete|qremove|qrm":
         (delete,
-         [('k', 'keep', None, _('keep patch file'))],
-          'hg qdelete [-k] PATCH'),
+         [('f', 'forget', None, _('stop managing an applied patch')),
+          ('k', 'keep', None, _('keep patch file'))],
+          'hg qdelete [-f] [-k] PATCH'),
     'qfold':
         (fold,
          [('e', 'edit', None, _('edit patch header')),
@@ -1963,6 +1986,7 @@
          [('e', 'edit', None, _('edit commit message')),
           ('m', 'message', '', _('change commit message with <text>')),
           ('l', 'logfile', '', _('change commit message with <file> content')),
+          ('g', 'git', None, _('use git extended diff format')),
           ('s', 'short', None, 'short refresh'),
           ('I', 'include', [], _('include names matching the given patterns')),
           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
@@ -1994,7 +2018,7 @@
         (series,
          [('m', 'missing', None, 'print patches not in series'),
           ('s', 'summary', None, _('print first line of patch header'))],
-         'hg qseries [-m]'),
+         'hg qseries [-ms]'),
     "^strip":
         (strip,
          [('f', 'force', None, 'force multi-head removal'),
--- a/hgext/notify.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/hgext/notify.py	Fri Sep 15 16:01:16 2006 -0500
@@ -238,8 +238,11 @@
             return
         fp = templater.stringio()
         prev = self.repo.changelog.parents(node)[0]
-        patch.diff(self.repo, fp, prev, ref)
+        patch.diff(self.repo, prev, ref, fp=fp)
         difflines = fp.getvalue().splitlines(1)
+        if self.ui.configbool('notify', 'diffstat', True):
+            s = patch.diffstat(difflines)
+            self.sio.write('\ndiffstat:\n\n' + s)
         if maxdiff > 0 and len(difflines) > maxdiff:
             self.sio.write(_('\ndiffs (truncated from %d to %d lines):\n\n') %
                            (len(difflines), maxdiff))
--- a/hgext/patchbomb.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/hgext/patchbomb.py	Fri Sep 15 16:01:16 2006 -0500
@@ -65,7 +65,7 @@
 
 from mercurial.demandload import *
 demandload(globals(), '''email.MIMEMultipart email.MIMEText email.Utils
-                         mercurial:commands,hg,mail,ui
+                         mercurial:commands,hg,mail,ui,patch
                          os errno popen2 socket sys tempfile time''')
 from mercurial.i18n import gettext as _
 from mercurial.node import *
@@ -76,27 +76,6 @@
     import readline
 except ImportError: pass
 
-def diffstat(patch):
-    fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt")
-    try:
-        p = popen2.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name)
-        try:
-            for line in patch: print >> p.tochild, line
-            p.tochild.close()
-            if p.wait(): return
-            fp = os.fdopen(fd, 'r')
-            stat = []
-            for line in fp: stat.append(line.lstrip())
-            last = stat.pop()
-            stat.insert(0, last)
-            stat = ''.join(stat)
-            if stat.startswith('0 files'): raise ValueError
-            return stat
-        except: raise
-    finally:
-        try: os.unlink(name)
-        except: pass
-
 def patchbomb(ui, repo, *revs, **opts):
     '''send changesets as a series of patch emails
 
@@ -123,8 +102,8 @@
         if not prompt(s, default = 'y', rest = '? ').lower().startswith('y'):
             raise ValueError
 
-    def cdiffstat(summary, patch):
-        s = diffstat(patch)
+    def cdiffstat(summary, patchlines):
+        s = patch.diffstat(patchlines)
         if s:
             if summary:
                 ui.write(summary, '\n')
@@ -140,7 +119,9 @@
             if line.startswith('#'):
                 if line.startswith('# Node ID'): node = line.split()[-1]
                 continue
-            if line.startswith('diff -r'): break
+            if (line.startswith('diff -r')
+                or line.startswith('diff --git')):
+                break
             desc.append(line)
         if not node: raise ValueError
 
@@ -205,7 +186,8 @@
 
     commands.export(ui, repo, *revs, **{'output': exportee(patches),
                                         'switch_parent': False,
-                                        'text': None})
+                                        'text': None,
+                                        'git': opts.get('git')})
 
     jumbo = []
     msgs = []
@@ -322,6 +304,7 @@
       ('', 'bcc', [], 'email addresses of blind copy recipients'),
       ('c', 'cc', [], 'email addresses of copy recipients'),
       ('d', 'diffstat', None, 'add diffstat output to messages'),
+      ('g', 'git', None, _('use git extended diff format')),
       ('f', 'from', '', 'email address of sender'),
       ('', 'plain', None, 'omit hg patch header'),
       ('n', 'test', None, 'print messages that would be sent'),
--- a/mercurial/changelog.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/changelog.py	Fri Sep 15 16:01:16 2006 -0500
@@ -16,6 +16,14 @@
                         defversion)
 
     def extract(self, text):
+        """
+        format used:
+        nodeid\n  : manifest node in ascii
+        user\n    : user, no \n or \r allowed
+        time tz\n : date (time is int or float, timezone is int)
+        files\n\n : files modified by the cset, no \n or \r allowed
+        (.*)      : comment (free text, ideally utf-8)
+        """
         if not text:
             return (nullid, "", (0, 0), [], "")
         last = text.index("\n\n")
--- a/mercurial/cmdutil.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/cmdutil.py	Fri Sep 15 16:01:16 2006 -0500
@@ -11,6 +11,76 @@
 demandload(globals(), 'mdiff util')
 demandload(globals(), 'os sys')
 
+revrangesep = ':'
+
+def revfix(repo, val, defval):
+    '''turn user-level id of changeset into rev number.
+    user-level id can be tag, changeset, rev number, or negative rev
+    number relative to number of revs (-1 is tip, etc).'''
+    if not val:
+        return defval
+    try:
+        num = int(val)
+        if str(num) != val:
+            raise ValueError
+        if num < 0:
+            num += repo.changelog.count()
+        if num < 0:
+            num = 0
+        elif num >= repo.changelog.count():
+            raise ValueError
+    except ValueError:
+        try:
+            num = repo.changelog.rev(repo.lookup(val))
+        except KeyError:
+            raise util.Abort(_('invalid revision identifier %s') % val)
+    return num
+
+def revpair(ui, repo, revs):
+    '''return pair of nodes, given list of revisions. second item can
+    be None, meaning use working dir.'''
+    if not revs:
+        return repo.dirstate.parents()[0], None
+    end = None
+    if len(revs) == 1:
+        start = revs[0]
+        if revrangesep in start:
+            start, end = start.split(revrangesep, 1)
+            start = revfix(repo, start, 0)
+            end = revfix(repo, end, repo.changelog.count() - 1)
+        else:
+            start = revfix(repo, start, None)
+    elif len(revs) == 2:
+        if revrangesep in revs[0] or revrangesep in revs[1]:
+            raise util.Abort(_('too many revisions specified'))
+        start = revfix(repo, revs[0], None)
+        end = revfix(repo, revs[1], None)
+    else:
+        raise util.Abort(_('too many revisions specified'))
+    if end is not None: end = repo.lookup(str(end))
+    return repo.lookup(str(start)), end
+
+def revrange(ui, repo, revs):
+    """Yield revision as strings from a list of revision specifications."""
+    seen = {}
+    for spec in revs:
+        if revrangesep in spec:
+            start, end = spec.split(revrangesep, 1)
+            start = revfix(repo, start, 0)
+            end = revfix(repo, end, repo.changelog.count() - 1)
+            step = start > end and -1 or 1
+            for rev in xrange(start, end+step, step):
+                if rev in seen:
+                    continue
+                seen[rev] = 1
+                yield str(rev)
+        else:
+            rev = revfix(repo, spec, None)
+            if rev in seen:
+                continue
+            seen[rev] = 1
+            yield str(rev)
+
 def make_filename(repo, pat, node,
                   total=None, seqno=None, revwidth=None, pathname=None):
     node_expander = {
@@ -53,8 +123,8 @@
             i += 1
         return ''.join(newname)
     except KeyError, inst:
-        raise util.Abort(_("invalid format spec '%%%s' in output file name"),
-                    inst.args[0])
+        raise util.Abort(_("invalid format spec '%%%s' in output file name") %
+                         inst.args[0])
 
 def make_file(repo, pat, node=None,
               total=None, seqno=None, revwidth=None, mode='wb', pathname=None):
--- a/mercurial/commands.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/commands.py	Fri Sep 15 16:01:16 2006 -0500
@@ -8,7 +8,7 @@
 from demandload import demandload
 from node import *
 from i18n import gettext as _
-demandload(globals(), "os re sys signal shutil imp urllib pdb")
+demandload(globals(), "os re sys signal shutil imp urllib pdb shlex")
 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
 demandload(globals(), "fnmatch difflib patch random signal tempfile time")
 demandload(globals(), "traceback errno socket version struct atexit sets bz2")
@@ -50,6 +50,21 @@
                              (logfile, inst.strerror))
     return message
 
+def defaultrev(repo, rev=None, default='tip'):
+    """returns rev if it is specified, otherwise the working dir
+    parent if there is only one, or tip if there is no working
+    dir"""
+    if rev:
+        return rev
+
+    p1, p2 = repo.dirstate.parents()
+    if p2 != nullid:
+        raise util.Abort(_('uncommitted merge - please provide a '
+                           'specific revision'))
+    if p1 != nullid:
+        return hex(p1)
+    return default
+
 def walkchangerevs(ui, repo, pats, opts):
     '''Iterate over files and the revs they changed in.
 
@@ -99,16 +114,10 @@
         return [], False, matchfn
 
     if follow:
-        p = repo.dirstate.parents()[0]
-        if p == nullid:
-            ui.warn(_('No working directory revision; defaulting to tip\n'))
-            start = 'tip'
-        else:
-            start = repo.changelog.rev(p)
-        defrange = '%s:0' % start
+        defrange = '%s:0' % defaultrev(repo)
     else:
         defrange = 'tip:0'
-    revs = map(int, revrange(ui, repo, opts['rev'] or [defrange]))
+    revs = map(int, cmdutil.revrange(ui, repo, opts['rev'] or [defrange]))
     wanted = {}
     slowpath = anypats
     fncache = {}
@@ -252,76 +261,6 @@
                 yield 'iter', rev, None
     return iterate(), getchange, matchfn
 
-revrangesep = ':'
-
-def revfix(repo, val, defval):
-    '''turn user-level id of changeset into rev number.
-    user-level id can be tag, changeset, rev number, or negative rev
-    number relative to number of revs (-1 is tip, etc).'''
-    if not val:
-        return defval
-    try:
-        num = int(val)
-        if str(num) != val:
-            raise ValueError
-        if num < 0:
-            num += repo.changelog.count()
-        if num < 0:
-            num = 0
-        elif num >= repo.changelog.count():
-            raise ValueError
-    except ValueError:
-        try:
-            num = repo.changelog.rev(repo.lookup(val))
-        except KeyError:
-            raise util.Abort(_('invalid revision identifier %s'), val)
-    return num
-
-def revpair(ui, repo, revs):
-    '''return pair of nodes, given list of revisions. second item can
-    be None, meaning use working dir.'''
-    if not revs:
-        return repo.dirstate.parents()[0], None
-    end = None
-    if len(revs) == 1:
-        start = revs[0]
-        if revrangesep in start:
-            start, end = start.split(revrangesep, 1)
-            start = revfix(repo, start, 0)
-            end = revfix(repo, end, repo.changelog.count() - 1)
-        else:
-            start = revfix(repo, start, None)
-    elif len(revs) == 2:
-        if revrangesep in revs[0] or revrangesep in revs[1]:
-            raise util.Abort(_('too many revisions specified'))
-        start = revfix(repo, revs[0], None)
-        end = revfix(repo, revs[1], None)
-    else:
-        raise util.Abort(_('too many revisions specified'))
-    if end is not None: end = repo.lookup(str(end))
-    return repo.lookup(str(start)), end
-
-def revrange(ui, repo, revs):
-    """Yield revision as strings from a list of revision specifications."""
-    seen = {}
-    for spec in revs:
-        if revrangesep in spec:
-            start, end = spec.split(revrangesep, 1)
-            start = revfix(repo, start, 0)
-            end = revfix(repo, end, repo.changelog.count() - 1)
-            step = start > end and -1 or 1
-            for rev in xrange(start, end+step, step):
-                if rev in seen:
-                    continue
-                seen[rev] = 1
-                yield str(rev)
-        else:
-            rev = revfix(repo, spec, None)
-            if rev in seen:
-                continue
-            seen[rev] = 1
-            yield str(rev)
-
 def write_bundle(cg, filename=None, compress=True):
     """Write a bundle file and return its filename.
 
@@ -341,7 +280,7 @@
     try:
         if filename:
             if os.path.exists(filename):
-                raise util.Abort(_("file '%s' already exists"), filename)
+                raise util.Abort(_("file '%s' already exists") % filename)
             fh = open(filename, "wb")
         else:
             fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
@@ -707,7 +646,7 @@
     if not opts['user'] and not opts['changeset'] and not opts['date']:
         opts['number'] = 1
 
-    ctx = repo.changectx(opts['rev'] or repo.dirstate.parents()[0])
+    ctx = repo.changectx(defaultrev(repo, opts['rev']))
 
     for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
                                              node=ctx.node()):
@@ -754,14 +693,7 @@
     The default is the basename of the archive, with suffixes removed.
     '''
 
-    if opts['rev']:
-        node = repo.lookup(opts['rev'])
-    else:
-        node, p2 = repo.dirstate.parents()
-        if p2 != nullid:
-            raise util.Abort(_('uncommitted merge - please provide a '
-                               'specific revision'))
-
+    node = repo.lookup(defaultrev(repo, opts['rev']))
     dest = cmdutil.make_filename(repo, dest, node)
     if os.path.realpath(dest) == repo.root:
         raise util.Abort(_('repository root cannot be destination'))
@@ -867,7 +799,8 @@
     """output the latest or given revisions of files
 
     Print the specified files as they were at the given revision.
-    If no revision is given then the tip is used.
+    If no revision is given then working dir parent is used, or tip
+    if no revision is checked out.
 
     Output may be to a file, in which case the name of the file is
     given using a format string.  The formatting rules are the same as
@@ -877,7 +810,7 @@
     %d   dirname of file being printed, or '.' if in repo root
     %p   root-relative path name of file being printed
     """
-    ctx = repo.changectx(opts['rev'] or "-1")
+    ctx = repo.changectx(defaultrev(repo, opts['rev']))
     for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts,
                                              ctx.node()):
         fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
@@ -1269,7 +1202,7 @@
     try:
         ui.write(r.revision(r.lookup(rev)))
     except KeyError:
-        raise util.Abort(_('invalid revision identifier %s'), rev)
+        raise util.Abort(_('invalid revision identifier %s') % rev)
 
 def debugindex(ui, file_):
     """dump the contents of an index file"""
@@ -1344,7 +1277,7 @@
     it detects as binary. With -a, diff will generate a diff anyway,
     probably with undesirable results.
     """
-    node1, node2 = revpair(ui, repo, opts['rev'])
+    node1, node2 = cmdutil.revpair(ui, repo, opts['rev'])
 
     fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
 
@@ -1380,7 +1313,7 @@
     """
     if not changesets:
         raise util.Abort(_("export requires at least one changeset"))
-    revs = list(revrange(ui, repo, changesets))
+    revs = list(cmdutil.revrange(ui, repo, changesets))
     if len(revs) > 1:
         ui.note(_('exporting patches:\n'))
     else:
@@ -1940,7 +1873,7 @@
     revision to merge with must be provided.
     """
 
-    if node:
+    if node or branch:
         node = _lookup(repo, node, branch)
     else:
         heads = repo.heads()
@@ -2272,8 +2205,8 @@
     Modified files are saved with a .orig suffix before reverting.
     To disable these backups, use --no-backup.
 
-    Using the -r option, revert the given files or directories to
-    their contents as of a specific revision.  This can be helpful to"roll
+    Using the -r option, revert the given files or directories to their
+    contents as of a specific revision. This can be helpful to "roll
     back" some or all of a change that should not have been committed.
 
     Revert modifies the working directory.  It does not commit any
@@ -2291,16 +2224,11 @@
     """
 
     if not pats and not opts['all']:
-        raise util.Abort(_('no files or directories specified'))
+        raise util.Abort(_('no files or directories specified; '
+                           'use --all to revert the whole repo'))
 
     parent, p2 = repo.dirstate.parents()
-    if opts['rev']:
-        node = repo.lookup(opts['rev'])
-    elif p2 != nullid:
-        raise util.Abort(_('working dir has two parents; '
-                           'you must specify the revision to revert to'))
-    else:
-        node = parent
+    node = repo.lookup(defaultrev(repo, opts['rev']))
     mf = repo.manifest.read(repo.changelog.read(node)[0])
     if node == parent:
         pmf = mf
@@ -2457,7 +2385,8 @@
 
     if opts["stdio"]:
         if repo is None:
-            raise hg.RepoError(_('no repo found'))
+            raise hg.RepoError(_("There is no Mercurial repository here"
+                                 " (.hg not found)"))
         s = sshserver.sshserver(ui, repo)
         s.serve_forever()
 
@@ -2468,7 +2397,8 @@
             ui.setconfig("web", o, opts[o])
 
     if repo is None and not ui.config("web", "webdir_conf"):
-        raise hg.RepoError(_('no repo found'))
+        raise hg.RepoError(_("There is no Mercurial repository here"
+                             " (.hg not found)"))
 
     if opts['daemon'] and not opts['daemon_pipefds']:
         rfd, wfd = os.pipe()
@@ -2483,7 +2413,7 @@
     try:
         httpd = hgweb.server.create_server(ui, repo)
     except socket.error, inst:
-        raise util.Abort(_('cannot start server: ') + inst.args[1])
+        raise util.Abort(_('cannot start server: %s') % inst.args[1])
 
     if ui.verbose:
         addr, port = httpd.socket.getsockname()
@@ -2598,15 +2528,10 @@
             raise util.Abort(_("use only one form to specify the revision"))
     if opts['rev']:
         rev_ = opts['rev']
-    if rev_:
-        r = repo.lookup(rev_)
-    else:
-        p1, p2 = repo.dirstate.parents()
-        if p1 == nullid:
-            raise util.Abort(_('no revision to tag'))
-        if p2 != nullid:
-            raise util.Abort(_('outstanding uncommitted merges'))
-        r = p1
+    r = defaultrev(repo, rev_, nullid)
+    if r == nullid:
+        raise util.Abort(_('no revision to tag'))
+    r = repo.lookup(r)
 
     message = opts['message']
     if not message:
@@ -2733,7 +2658,7 @@
             repo.ui.warn(_("Using head %s for branch %s\n")
                          % (short(node), branch))
         else:
-            raise util.Abort(_("branch %s not found\n") % (branch))
+            raise util.Abort(_("branch %s not found") % branch)
     else:
         node = node and repo.lookup(node) or repo.changelog.tip()
     return node
@@ -2886,6 +2811,7 @@
         (export,
          [('o', 'output', '', _('print output to file with formatted name')),
           ('a', 'text', None, _('treat all files as text')),
+          ('g', 'git', None, _('use git extended diff format')),
           ('', 'switch-parent', None, _('diff against the second parent'))],
          _('hg export [-a] [-o OUTFILESPEC] REV...')),
     "debugforget|forget":
@@ -3221,7 +3147,7 @@
         cmd = aliases[0]
         defaults = ui.config("defaults", cmd)
         if defaults:
-            args = defaults.split() + args
+            args = shlex.split(defaults) + args
         c = list(i[1])
     else:
         cmd = None
@@ -3305,12 +3231,14 @@
         if num: signal.signal(num, catchterm)
 
     try:
-        u = ui.ui(traceback='--traceback' in sys.argv[1:],
-                  readhooks=[load_extensions])
+        u = ui.ui(traceback='--traceback' in sys.argv[1:])
     except util.Abort, inst:
         sys.stderr.write(_("abort: %s\n") % inst)
         return -1
 
+    load_extensions(u)
+    u.addreadhook(load_extensions)
+
     try:
         cmd, func, args, options, cmdoptions = parse(u, args)
         if options["time"]:
@@ -3445,7 +3373,7 @@
         u.warn(_("abort: could not lock %s: %s\n") %
                (inst.desc or inst.filename, inst.strerror))
     except revlog.RevlogError, inst:
-        u.warn(_("abort: "), inst, "!\n")
+        u.warn(_("abort: %s!\n") % inst)
     except util.SignalInterrupt:
         u.warn(_("killed!\n"))
     except KeyboardInterrupt:
@@ -3467,18 +3395,18 @@
                 u.warn(_("broken pipe\n"))
         elif getattr(inst, "strerror", None):
             if getattr(inst, "filename", None):
-                u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename))
+                u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
             else:
                 u.warn(_("abort: %s\n") % inst.strerror)
         else:
             raise
     except OSError, inst:
-        if hasattr(inst, "filename"):
+        if getattr(inst, "filename", None):
             u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
         else:
             u.warn(_("abort: %s\n") % inst.strerror)
     except util.Abort, inst:
-        u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n')
+        u.warn(_("abort: %s\n") % inst)
     except TypeError, inst:
         # was this an argument error?
         tb = traceback.extract_tb(sys.exc_info()[2])
--- a/mercurial/hg.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/hg.py	Fri Sep 15 16:01:16 2006 -0500
@@ -115,7 +115,7 @@
     source = localpath(source)
 
     if os.path.exists(dest):
-        raise util.Abort(_("destination '%s' already exists"), dest)
+        raise util.Abort(_("destination '%s' already exists") % dest)
 
     class DirCleanup(object):
         def __init__(self, dir_):
@@ -127,12 +127,7 @@
             if self.dir_:
                 self.rmtree(self.dir_, True)
 
-    dest_repo = None
-    try:
-        dest_repo = repository(ui, dest)
-        raise util.Abort(_("destination '%s' already exists." % dest))
-    except RepoError:
-        dest_repo = repository(ui, dest, create=True)
+    dest_repo = repository(ui, dest, create=True)
 
     dest_path = None
     dir_cleanup = None
--- a/mercurial/hgweb/server.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/hgweb/server.py	Fri Sep 15 16:01:16 2006 -0500
@@ -207,7 +207,8 @@
                 hgwebobj = self.repoviewmaker(repo.__class__(repo.ui,
                                                              repo.origroot))
             else:
-                raise hg.RepoError(_('no repo found'))
+                raise hg.RepoError(_("There is no Mercurial repository here"
+                                     " (.hg not found)"))
             return hgwebobj
 
     class IPv6HTTPServer(MercurialHTTPServer):
--- a/mercurial/httprepo.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/httprepo.py	Fri Sep 15 16:01:16 2006 -0500
@@ -325,7 +325,7 @@
                     rfp.close()
             except socket.error, err:
                 if err[0] in (errno.ECONNRESET, errno.EPIPE):
-                    raise util.Abort(_('push failed: %s'), err[1])
+                    raise util.Abort(_('push failed: %s') % err[1])
                 raise util.Abort(err[1])
         finally:
             fp.close()
--- a/mercurial/localrepo.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/localrepo.py	Fri Sep 15 16:01:16 2006 -0500
@@ -27,12 +27,21 @@
                 oldp = p
                 p = os.path.dirname(p)
                 if p == oldp:
-                    raise repo.RepoError(_("no repo found"))
+                    raise repo.RepoError(_("There is no Mercurial repository"
+                                           " here (.hg not found)"))
             path = p
         self.path = os.path.join(path, ".hg")
 
-        if not create and not os.path.isdir(self.path):
-            raise repo.RepoError(_("repository %s not found") % path)
+        if not os.path.isdir(self.path):
+            if create:
+                if not os.path.exists(path):
+                    os.mkdir(path)
+                os.mkdir(self.path)
+                os.mkdir(self.join("data"))
+            else:
+                raise repo.RepoError(_("repository %s not found") % path)
+        elif create:
+            raise repo.RepoError(_("repository %s already exists") % path)
 
         self.root = os.path.abspath(path)
         self.origroot = path
@@ -75,12 +84,6 @@
         self.decodepats = None
         self.transhandle = None
 
-        if create:
-            if not os.path.exists(path):
-                os.mkdir(path)
-            os.mkdir(self.path)
-            os.mkdir(self.join("data"))
-
         self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
 
     def url(self):
@@ -131,7 +134,7 @@
             except Exception, exc:
                 if isinstance(exc, util.Abort):
                     self.ui.warn(_('error: %s hook failed: %s\n') %
-                                 (hname, exc.args[0] % exc.args[1:]))
+                                 (hname, exc.args[0]))
                 else:
                     self.ui.warn(_('error: %s hook raised an exception: '
                                    '%s\n') % (hname, exc))
@@ -641,7 +644,11 @@
         if node:
             fdict = dict.fromkeys(files)
             for fn in self.manifest.read(self.changelog.read(node)[0]):
-                fdict.pop(fn, None)
+                for ffn in fdict:
+                    # match if the file is the exact name or a directory
+                    if ffn == fn or fn.startswith("%s/" % ffn):
+                        del fdict[ffn]
+                        break
                 if match(fn):
                     yield 'm', fn
             for fn in fdict:
--- a/mercurial/mdiff.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/mdiff.py	Fri Sep 15 16:01:16 2006 -0500
@@ -50,6 +50,9 @@
 defaultopts = diffopts()
 
 def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts):
+    def datetag(date):
+        return opts.git and '\n' or '\t%s\n' % date
+
     if not a and not b: return ""
     epoch = util.datestr((0, 0))
 
@@ -58,19 +61,19 @@
     elif not a:
         b = splitnewlines(b)
         if a is None:
-            l1 = "--- %s\t%s\n" % ("/dev/null", epoch)
+            l1 = '--- /dev/null%s' % datetag(epoch)
         else:
-            l1 = "--- %s\t%s\n" % ("a/" + fn, ad)
-        l2 = "+++ %s\t%s\n" % ("b/" + fn, bd)
+            l1 = "--- %s%s" % ("a/" + fn, datetag(ad))
+        l2 = "+++ %s%s" % ("b/" + fn, datetag(bd))
         l3 = "@@ -0,0 +1,%d @@\n" % len(b)
         l = [l1, l2, l3] + ["+" + e for e in b]
     elif not b:
         a = splitnewlines(a)
-        l1 = "--- %s\t%s\n" % ("a/" + fn, ad)
+        l1 = "--- %s%s" % ("a/" + fn, datetag(ad))
         if b is None:
-            l2 = "+++ %s\t%s\n" % ("/dev/null", epoch)
+            l2 = '+++ /dev/null%s' % datetag(epoch)
         else:
-            l2 = "+++ %s\t%s\n" % ("b/" + fn, bd)
+            l2 = "+++ %s%s" % ("b/" + fn, datetag(bd))
         l3 = "@@ -1,%d +0,0 @@\n" % len(a)
         l = [l1, l2, l3] + ["-" + e for e in a]
     else:
@@ -79,8 +82,8 @@
         l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn, opts=opts))
         if not l: return ""
         # difflib uses a space, rather than a tab
-        l[0] = "%s\t%s\n" % (l[0][:-2], ad)
-        l[1] = "%s\t%s\n" % (l[1][:-2], bd)
+        l[0] = "%s%s" % (l[0][:-2], datetag(ad))
+        l[1] = "%s%s" % (l[1][:-2], datetag(bd))
 
     for ln in xrange(len(l)):
         if l[ln][-1] != '\n':
--- a/mercurial/merge.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/merge.py	Fri Sep 15 16:01:16 2006 -0500
@@ -8,7 +8,7 @@
 from node import *
 from i18n import gettext as _
 from demandload import *
-demandload(globals(), "util os tempfile")
+demandload(globals(), "errno util os tempfile")
 
 def fmerge(f, local, other, ancestor):
     """merge executable flags"""
@@ -88,12 +88,9 @@
         if modified or added or removed:
             raise util.Abort(_("outstanding uncommitted changes"))
 
-    m1n = repo.changelog.read(p1)[0]
-    m2n = repo.changelog.read(p2)[0]
-    man = repo.manifest.ancestor(m1n, m2n)
-    m1 = repo.manifest.read(m1n).copy()
-    m2 = repo.manifest.read(m2n).copy()
-    ma = repo.manifest.read(man)
+    m1 = repo.changectx(p1).manifest().copy()
+    m2 = repo.changectx(p2).manifest().copy()
+    ma = repo.changectx(pa).manifest()
 
     if not force:
         for f in unknown:
@@ -108,7 +105,7 @@
     repo.ui.debug(_(" overwrite %s branchmerge %s partial %s linear %s\n") %
                   (overwrite, branchmerge, bool(partial), linear_path))
     repo.ui.debug(_(" ancestor %s local %s remote %s\n") %
-                  (short(man), short(m1n), short(m2n)))
+                  (short(p1), short(p2), short(pa)))
 
     action = {}
     forget = []
@@ -116,9 +113,10 @@
     # update m1 from working dir
     umap = dict.fromkeys(unknown)
 
-    for f in added + modified + unknown:
-        m1[f] = m1.get(f, nullid) + "+"
-        m1.set(f, util.is_exec(repo.wjoin(f), m1.execf(f)))
+    for i,l in (("a", added), ("m", modified), ("u", unknown)):
+        for f in l:
+            m1[f] = m1.get(f, nullid) + i
+            m1.set(f, util.is_exec(repo.wjoin(f), m1.execf(f)))
 
     for f in deleted + removed:
         del m1[f]
@@ -157,7 +155,7 @@
                     repo.ui.debug(_(" remote %s is newer, get\n") % f)
                     action[f] = (m2.execf(f), m2[f], None)
                     queued = 1
-            elif f in umap or f in added:
+            elif n[20:] in ("u","a"):
                 # this unknown file is the same as the checkout
                 # we need to reset the dirstate if the file was added
                 action[f] = (m2.execf(f), m2[f], None)
@@ -168,7 +166,8 @@
                     repo.ui.debug(_(" updating permissions for %s\n") % f)
                     util.set_exec(repo.wjoin(f), m2.execf(f))
                 else:
-                    if fmerge(f, m1, m2, ma) != m1.execf(f):
+                    mode = fmerge(f, m1, m2, ma)
+                    if mode != m1.execf(f):
                         repo.ui.debug(_(" updating permissions for %s\n")
                                       % f)
                         util.set_exec(repo.wjoin(f), mode)
@@ -187,7 +186,7 @@
                 action[f] = (None, None, None)
         else:
             # file is created on branch or in working directory
-            if overwrite and f not in umap:
+            if overwrite and n[20:] != "u":
                 repo.ui.debug(_("remote deleted %s, clobbering\n") % f)
                 action[f] = (None, None, None)
             elif not n[20:]: # same as parent
@@ -236,8 +235,7 @@
     repo.hook('preupdate', throw=True, parent1=xp1, parent2=xxp2)
 
     # update files
-    unresolved = []
-    updated, merged, removed = 0, 0, 0
+    updated, merged, removed, unresolved = 0, 0, 0, 0
     files = action.keys()
     files.sort()
     for f in files:
@@ -257,7 +255,7 @@
         elif other:
             repo.ui.status(_("merging %s\n") % f)
             if merge3(repo, f, my, other, xp1, xp2):
-                unresolved.append(f)
+                unresolved += 1
             util.set_exec(repo.wjoin(f), flag)
             merged += 1
         else:
@@ -302,9 +300,9 @@
 
     if show_stats:
         stats = ((updated, _("updated")),
-                 (merged - len(unresolved), _("merged")),
+                 (merged - unresolved, _("merged")),
                  (removed, _("removed")),
-                 (len(unresolved), _("unresolved")))
+                 (unresolved, _("unresolved")))
         note = ", ".join([_("%d files %s") % s for s in stats])
         repo.ui.status("%s\n" % note)
     if not partial:
@@ -322,6 +320,6 @@
             repo.ui.status(_("There are unresolved merges with"
                              " locally modified files.\n"))
 
-    repo.hook('update', parent1=xp1, parent2=xxp2, error=len(unresolved))
-    return len(unresolved)
+    repo.hook('update', parent1=xp1, parent2=xxp2, error=unresolved)
+    return unresolved
 
--- a/mercurial/patch.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/patch.py	Fri Sep 15 16:01:16 2006 -0500
@@ -9,7 +9,8 @@
 from i18n import gettext as _
 from node import *
 demandload(globals(), "cmdutil mdiff util")
-demandload(globals(), "cStringIO email.Parser errno os re shutil sys tempfile")
+demandload(globals(), '''cStringIO email.Parser errno os re shutil sys tempfile
+                         popen2''')
 
 # helper functions
 
@@ -182,7 +183,7 @@
 
     return (dopatch, gitpatches)
 
-def dogitpatch(patchname, gitpatches):
+def dogitpatch(patchname, gitpatches, cwd=None):
     """Preprocess git patch so that vanilla patch can handle it"""
     pf = file(patchname)
     pfline = 1
@@ -196,7 +197,7 @@
             if not p.copymod:
                 continue
 
-            copyfile(p.oldpath, p.path)
+            copyfile(p.oldpath, p.path, basedir=cwd)
 
             # rewrite patch hunk
             while pfline < p.lineno:
@@ -227,23 +228,20 @@
     """apply the patch <patchname> to the working directory.
     a list of patched files is returned"""
 
-    (dopatch, gitpatches) = readgitpatch(patchname)
+    # helper function
+    def __patch(patchname):
+        """patch and updates the files and fuzz variables"""
+        files = {}
+        fuzz = False
 
-    files = {}
-    fuzz = False
-    if dopatch:
-        if dopatch == 'filter':
-            patchname = dogitpatch(patchname, gitpatches)
-        patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
+        patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''),
+                                    'patch')
         args = []
         if cwd:
             args.append('-d %s' % util.shellquote(cwd))
         fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip,
                                            util.shellquote(patchname)))
 
-        if dopatch == 'filter':
-            False and os.unlink(patchname)
-
         for line in fp:
             line = line.rstrip()
             ui.note(line + '\n')
@@ -264,11 +262,24 @@
                     ui.warn(pf + '\n')
                     printed_file = True
                 ui.warn(line + '\n')
-            
         code = fp.close()
         if code:
             raise util.Abort(_("patch command failed: %s") %
                              util.explain_exit(code)[0])
+        return files, fuzz
+
+    (dopatch, gitpatches) = readgitpatch(patchname)
+
+    if dopatch:
+        if dopatch == 'filter':
+            patchname = dogitpatch(patchname, gitpatches, cwd=cwd)
+        try:
+            files, fuzz = __patch(patchname)
+        finally:
+            if dopatch == 'filter':
+                os.unlink(patchname)
+    else:
+        files, fuzz = {}, False
 
     for gp in gitpatches:
         files[gp.path] = (gp.op, gp)
@@ -492,7 +503,10 @@
                     header.append('deleted file mode %s\n' % mode)
             else:
                 omode = gitmode(mmap.execf(f))
-                nmode = gitmode(util.is_exec(repo.wjoin(f), mmap.execf(f)))
+                if node2:
+                    nmode = gitmode(mmap2.execf(f))
+                else:
+                    nmode = gitmode(util.is_exec(repo.wjoin(f), mmap.execf(f)))
                 addmodehdr(header, omode, nmode)
             r = None
             if dodiff:
@@ -537,3 +551,24 @@
 
     for seqno, cset in enumerate(revs):
         single(cset, seqno, fp)
+
+def diffstat(patchlines):
+    fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt")
+    try:
+        p = popen2.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name)
+        try:
+            for line in patchlines: print >> p.tochild, line
+            p.tochild.close()
+            if p.wait(): return
+            fp = os.fdopen(fd, 'r')
+            stat = []
+            for line in fp: stat.append(line.lstrip())
+            last = stat.pop()
+            stat.insert(0, last)
+            stat = ''.join(stat)
+            if stat.startswith('0 files'): raise ValueError
+            return stat
+        except: raise
+    finally:
+        try: os.unlink(name)
+        except: pass
--- a/mercurial/revlog.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/revlog.py	Fri Sep 15 16:01:16 2006 -0500
@@ -139,6 +139,11 @@
         if self.all: return
         if data is None:
             self.dataf.seek(blockstart)
+            if blockstart + blocksize > self.datasize:
+                # the revlog may have grown since we've started running,
+                # but we don't have space in self.index for more entries.
+                # limit blocksize so that we don't get too much data.
+                blocksize = max(self.datasize - blockstart, 0)
             data = self.dataf.read(blocksize)
         lend = len(data) / self.s
         i = blockstart / self.s
--- a/mercurial/sshrepo.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/sshrepo.py	Fri Sep 15 16:01:16 2006 -0500
@@ -32,12 +32,6 @@
         remotecmd = self.ui.config("ui", "remotecmd", "hg")
 
         if create:
-            try:
-                self.validate_repo(ui, sshcmd, args, remotecmd)
-                return # the repo is good, nothing more to do
-            except hg.RepoError:
-                pass
-
             cmd = '%s %s "%s init %s"'
             cmd = cmd % (sshcmd, args, remotecmd, self.path)
 
@@ -52,6 +46,9 @@
         return self._url
 
     def validate_repo(self, ui, sshcmd, args, remotecmd):
+        # cleanup up previous run
+        self.cleanup()
+
         cmd = '%s %s "%s -R %s serve --stdio"'
         cmd = cmd % (sshcmd, args, remotecmd, self.path)
 
@@ -90,7 +87,7 @@
             if not l: break
             self.ui.status(_("remote: "), l)
 
-    def __del__(self):
+    def cleanup(self):
         try:
             self.pipeo.close()
             self.pipei.close()
@@ -101,6 +98,8 @@
         except:
             pass
 
+    __del__ = cleanup
+
     def do_cmd(self, cmd, **args):
         self.ui.debug(_("sending %s command\n") % cmd)
         self.pipeo.write("%s\n" % cmd)
--- a/mercurial/ui.py	Fri Sep 15 16:00:16 2006 -0500
+++ b/mercurial/ui.py	Fri Sep 15 16:01:16 2006 -0500
@@ -12,13 +12,12 @@
 
 class ui(object):
     def __init__(self, verbose=False, debug=False, quiet=False,
-                 interactive=True, traceback=False, parentui=None,
-                 readhooks=[]):
+                 interactive=True, traceback=False, parentui=None):
         self.overlay = {}
         if parentui is None:
             # this is the parent of all ui children
             self.parentui = None
-            self.readhooks = list(readhooks)
+            self.readhooks = []
             self.cdata = ConfigParser.SafeConfigParser()
             self.readconfig(util.rcpath())
 
@@ -36,7 +35,7 @@
         else:
             # parentui may point to an ui object which is already a child
             self.parentui = parentui.parentui or parentui
-            self.readhooks = list(parentui.readhooks or readhooks)
+            self.readhooks = parentui.readhooks[:]
             parent_cdata = self.parentui.cdata
             self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults())
             # make interpolation work
@@ -51,7 +50,7 @@
     def updateopts(self, verbose=False, debug=False, quiet=False,
                    interactive=True, traceback=False, config=[]):
         self.quiet = (self.quiet or quiet) and not verbose and not debug
-        self.verbose = (self.verbose or verbose) or debug
+        self.verbose = ((self.verbose or verbose) or debug) and not self.quiet
         self.debugflag = (self.debugflag or debug)
         self.interactive = (self.interactive and interactive)
         self.traceback = self.traceback or traceback
@@ -84,6 +83,9 @@
         for hook in self.readhooks:
             hook(self)
 
+    def addreadhook(self, hook):
+        self.readhooks.append(hook)
+
     def setconfig(self, section, name, val):
         self.overlay[(section, name)] = val
 
@@ -94,7 +96,9 @@
             try:
                 return self.cdata.get(section, name)
             except ConfigParser.InterpolationError, inst:
-                raise util.Abort(_("Error in configuration:\n%s") % inst)
+                raise util.Abort(_("Error in configuration section [%s] "
+                                   "parameter '%s':\n%s")
+                                 % (section, name, inst))
         if self.parentui is None:
             return default
         else:
@@ -116,7 +120,9 @@
             try:
                 return self.cdata.getboolean(section, name)
             except ConfigParser.InterpolationError, inst:
-                raise util.Abort(_("Error in configuration:\n%s") % inst)
+                raise util.Abort(_("Error in configuration section [%s] "
+                                   "parameter '%s':\n%s")
+                                 % (section, name, inst))
         if self.parentui is None:
             return default
         else:
@@ -134,7 +140,8 @@
             try:
                 items.update(dict(self.cdata.items(section)))
             except ConfigParser.InterpolationError, inst:
-                raise util.Abort(_("Error in configuration:\n%s") % inst)
+                raise util.Abort(_("Error in configuration section [%s]:\n%s")
+                                 % (section, inst))
         x = items.items()
         x.sort()
         return x
@@ -146,10 +153,14 @@
             yield section, name, value
             seen[section, name] = 1
         for section in self.cdata.sections():
-            for name, value in self.cdata.items(section):
-                if (section, name) in seen: continue
-                yield section, name, value.replace('\n', '\\n')
-                seen[section, name] = 1
+            try:
+                for name, value in self.cdata.items(section):
+                    if (section, name) in seen: continue
+                    yield section, name, value.replace('\n', '\\n')
+                    seen[section, name] = 1
+            except ConfigParser.InterpolationError, inst:
+                raise util.Abort(_("Error in configuration section [%s]:\n%s")
+                                 % (section, inst))
         if self.parentui is not None:
             for parent in self.parentui.walkconfig(seen):
                 yield parent
--- a/templates/map-gitweb	Fri Sep 15 16:00:16 2006 -0500
+++ b/templates/map-gitweb	Fri Sep 15 16:01:16 2006 -0500
@@ -8,7 +8,7 @@
 naventry = '<a href="?cmd=changelog;rev=#rev#;style=gitweb">#label|escape#</a> '
 navshortentry = '<a href="?cmd=shortlog;rev=#rev#;style=gitweb">#label|escape#</a> '
 filedifflink = '<a href="?cmd=filediff;node=#node#;file=#file|urlescape#;style=gitweb">#file|escape#</a> '
-filenodelink = '<tr class="light"><td><a class="list" href="">#file|escape#</a></td><td></td><td class="link"><a href="?cmd=file;filenode=#filenode#;file=#file|urlescape#;style=gitweb">file</a> | <!-- FIXME: <a href="?fd=#filenode|short#;file=#file|urlescape#;style=gitweb">diff</a> | --> <a href="?cmd=filelog;filenode=#filenode|short#;file=#file|urlescape#;style=gitweb">revisions</a></td></tr>'
+filenodelink = '<tr class="light"><td><a class="list" href="">#file|escape#</a></td><td></td><td class="link"><a href="?cmd=file;filenode=#filenode#;file=#file|urlescape#;style=gitweb">file</a> | <a href="?fa=#filenode|short#;file=#file|urlescape#;style=gitweb">annotate</a> | <!-- FIXME: <a href="?fd=#filenode|short#;file=#file|urlescape#;style=gitweb">diff</a> | --> <a href="?cmd=filelog;filenode=#filenode|short#;file=#file|urlescape#;style=gitweb">revisions</a></td></tr>'
 fileellipses = '...'
 changelogentry = changelogentry-gitweb.tmpl
 searchentry = changelogentry-gitweb.tmpl
@@ -19,12 +19,12 @@
 filerevision = filerevision-gitweb.tmpl
 fileannotate = fileannotate-gitweb.tmpl
 filelog = filelog-gitweb.tmpl
-fileline = '<div style="font-family:monospace; white-space: pre;" class="parity#parity#"><span class="linenr">   #linenumber#</span> #line|escape#</div>'
-annotateline = '<tr style="font-family:monospace; white-space: pre;" class="parity#parity#"><td class="linenr" style="text-align: right;"><a href="?cs=#node|short#;style=gitweb">#author|obfuscate#@#rev#</a></td><td>#line|escape#</td></tr>'
-difflineplus = '<div class="pre" style="color:#008800;">#line|escape#</div>'
-difflineminus = '<div class="pre" style="color:#cc0000;">#line|escape#</div>'
-difflineat = '<div class="pre" style="color:#990099;">#line|escape#</div>'
-diffline = '<div class="pre">#line|escape#</div>'
+fileline = '<div style="font-family:monospace" class="parity#parity#"><pre><span class="linenr">   #linenumber#</span> #line|escape#</pre></div>'
+annotateline = '<tr style="font-family:monospace" class="parity#parity#"><td class="linenr" style="text-align: right;"><a href="?cs=#node|short#;style=gitweb">#author|obfuscate#@#rev#</a></td><td><pre>#line|escape#</pre></td></tr>'
+difflineplus = '<div style="color:#008800;">#line|escape#</div>'
+difflineminus = '<div style="color:#cc0000;">#line|escape#</div>'
+difflineat = '<div style="color:#990099;">#line|escape#</div>'
+diffline = '<div>#line|escape#</div>'
 changelogparent = '<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="?cmd=changeset;node=#node#;style=gitweb">#node|short#</a></td></tr>'
 changesetparent = '<tr><td>parent</td><td style="font-family:monospace"><a class="list" href="?cmd=changeset;node=#node|short#;style=gitweb">#node|short#</a></td></tr>'
 filerevparent = '<tr><td class="metatag">parent:</td><td><a href="?cmd=file;file=#file|urlescape#;filenode=#node#;style=gitweb">#node|short#</a></td></tr>'
@@ -37,7 +37,7 @@
 fileannotatechild = '<tr><td class="metatag">child:</td><td><a href="?cmd=annotate;file=#file|urlescape#;filenode=#node#;style=gitweb">#node|short#</a></td></tr>'
 tags = tags-gitweb.tmpl
 tagentry = '<tr class="parity#parity#"><td class="age"><i>#date|age# ago</i></td><td><a class="list" href="?cmd=changeset;node=#node|short#;style=gitweb"><b>#tag|escape#</b></a></td><td class="link"><a href="?cmd=changeset;node=#node|short#;style=gitweb">changeset</a> | <a href="?cmd=changelog;rev=#node|short#;style=gitweb">changelog</a> |  <a href="?mf=#tagmanifest|short#;path=/;style=gitweb">manifest</a></td></tr>'
-diffblock = '#lines#'
+diffblock = '<pre>#lines#</pre>'
 changelogtag = '<tr><th class="tag">tag:</th><td class="tag">#tag|escape#</td></tr>'
 changesettag = '<tr><td>tag</td><td>#tag|escape#</td></tr>'
 filediffparent = '<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="?cmd=changeset;node=#node#;style=gitweb">#node|short#</a></td></tr>'
@@ -46,5 +46,5 @@
 filelogchild = '<tr><td align="right">child #rev#:&nbsp;</td><td><a href="?cmd=file;file=#file|urlescape#;filenode=#node#;style=gitweb">#node|short#</a></td></tr>'
 shortlog = shortlog-gitweb.tmpl
 shortlogentry = '<tr class="parity#parity#"><td class="age"><i>#date|age# ago</i></td><td><i>#author#</i></td><td><a class="list" href="?cmd=changeset;node=#node|short#;style=gitweb"><b>#desc|strip|firstline|escape#</b></a></td><td class="link"><a href="?cmd=changeset;node=#node|short#;style=gitweb">changeset</a> |  <a href="?cmd=manifest;manifest=#manifest|short#;path=/;style=gitweb">manifest</a></td></tr>'
-filelogentry = '<tr class="parity#parity#"><td class="age"><i>#date|age# ago</i></td><td><a class="list" href="?cmd=changeset;node=#node|short#;style=gitweb"><b>#desc|strip|firstline|escape#</b></a></td><td class="link"><!-- FIXME: <a href="?fd=#node|short#;file=#file|urlescape#;style=gitweb">diff</a> | --> <a href="?fa=#filenode|short#;file=#file|urlescape#;style=gitweb">annotate</a> #rename%filelogrename#</td></tr>'
+filelogentry = '<tr class="parity#parity#"><td class="age"><i>#date|age# ago</i></td><td><a class="list" href="?cmd=changeset;node=#node|short#;style=gitweb"><b>#desc|strip|firstline|escape#</b></a></td><td class="link"><a href="?f=#node|short#;file=#file|urlescape#;style=gitweb">file</a> | <!-- FIXME: <a href="?fd=#node|short#;file=#file|urlescape#;style=gitweb">diff</a> | --> <a href="?fa=#filenode|short#;file=#file|urlescape#;style=gitweb">annotate</a> #rename%filelogrename#</td></tr>'
 archiveentry = ' | <a href="?ca=#node|short#;type=#type|urlescape#">#type|escape#</a> '
--- a/templates/static/style-gitweb.css	Fri Sep 15 16:00:16 2006 -0500
+++ b/templates/static/style-gitweb.css	Fri Sep 15 16:01:16 2006 -0500
@@ -47,3 +47,4 @@
 	text-align:center; text-decoration:none;
 }
 a.rss_logo:hover { background-color:#ee5500; }
+pre { margin: 0; }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-bad-extension	Fri Sep 15 16:01:16 2006 -0500
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+echo 'syntax error' > badext.py
+abspath=`pwd`/badext.py
+
+echo '[extensions]' >> $HGRCPATH
+echo "badext = $abspath" >> $HGRCPATH
+
+hg -q help help
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-bad-extension.out	Fri Sep 15 16:01:16 2006 -0500
@@ -0,0 +1,4 @@
+*** failed to import extension badext: invalid syntax (badext.py, line 1)
+hg help [COMMAND]
+
+show help for a command, extension, or list of commands
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-branch	Fri Sep 15 16:01:16 2006 -0500
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# test for branch handling
+#
+# XXX: need more tests
+
+hg init
+echo a > a
+echo b > b
+hg ci -A -m 0 -d "1000000 0"
+echo aa > a
+echo bb > b
+hg ci -m 1 -d "1000000 0"
+hg tag -l foo
+hg update 0
+hg parents -b 
+
+# test update
+hg update -b foo
+hg parents
+
+# test merge
+hg update 0
+echo c > c
+hg ci -A -m 0.0 -d "1000000 0"
+hg merge -b foo
+hg parents -b 
+
+# re-test with more branches
+hg update -C 0
+echo d > d
+hg ci -A -m 0.0 -d "1000000 0"
+hg merge -b foo
+hg parents -b 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-branch.out	Fri Sep 15 16:01:16 2006 -0500
@@ -0,0 +1,55 @@
+adding a
+adding b
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+changeset:   0:b544c4ac4389
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     0
+
+Using head f4ac749470f2 for branch foo
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+changeset:   1:f4ac749470f2
+tag:         foo
+tag:         tip
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     1
+
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+adding c
+Using head f4ac749470f2 for branch foo
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+changeset:   2:1505d56ee00e
+tag:         tip
+parent:      0:b544c4ac4389
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     0.0
+
+changeset:   1:f4ac749470f2
+tag:         foo
+branch:      foo
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     1
+
+2 files updated, 0 files merged, 1 files removed, 0 files unresolved
+adding d
+Using head f4ac749470f2 for branch foo
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+changeset:   3:53b72df12ae5
+tag:         tip
+parent:      0:b544c4ac4389
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     0.0
+
+changeset:   1:f4ac749470f2
+tag:         foo
+branch:      foo
+user:        test
+date:        Mon Jan 12 13:46:40 1970 +0000
+summary:     1
+
--- a/tests/test-command-template.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-command-template.out	Fri Sep 15 16:01:16 2006 -0500
@@ -59,9 +59,9 @@
   line 1
 
 # error if style not readable
-abort: Permission denied - ./q
+abort: Permission denied: ./q
 # error if no style
-abort: No such file or directory - notexist
+abort: No such file or directory: notexist
 # error if style missing key
 abort: ./t: no key named 'changeset'
 # error if include fails
--- a/tests/test-confused-revert.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-confused-revert.out	Fri Sep 15 16:01:16 2006 -0500
@@ -17,7 +17,7 @@
 A b
 R a
 %%% revert should fail
-abort: working dir has two parents; you must specify the revision to revert to
+abort: uncommitted merge - please provide a specific revision
 %%% revert should be ok now
 undeleting a
 forgetting b
--- a/tests/test-git-export	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-git-export	Fri Sep 15 16:01:16 2006 -0500
@@ -50,3 +50,7 @@
 echo '% rename+mod+chmod'
 hg diff --git -r 6:tip | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
     -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/"
+
+echo '% nonexistent in tip+chmod'
+hg diff --git -r 5:6 | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
+    -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/"
--- a/tests/test-git-export.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-git-export.out	Fri Sep 15 16:01:16 2006 -0500
@@ -40,3 +40,7 @@
  4
  5
 +a
+% nonexistent in tip+chmod
+diff --git a/src b/src
+old mode 100644
+new mode 100755
--- a/tests/test-http	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-http	Fri Sep 15 16:01:16 2006 -0500
@@ -11,7 +11,7 @@
 
 echo % clone via stream
 http_proxy= hg clone --uncompressed http://localhost:20059/ copy 2>&1 | \
-  sed -e 's/[0-9][0-9.]*/XXX/g' -e 's/.\(B\/sec\)/X\1/'
+  sed -e 's/[0-9][0-9.]*/XXX/g' -e 's/[KM]\(B\/sec\)/X\1/'
 hg verify -R copy
 
 echo % try to clone via stream, should use pull instead
--- a/tests/test-http-proxy	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-http-proxy	Fri Sep 15 16:01:16 2006 -0500
@@ -15,7 +15,7 @@
 
 echo %% url for proxy, stream
 http_proxy=http://localhost:20060/ hg --config http_proxy.always=True clone --uncompressed http://localhost:20059/ b | \
-  sed -e 's/[0-9][0-9.]*/XXX/g'
+  sed -e 's/[0-9][0-9.]*/XXX/g' -e 's/[KM]\(B\/sec\)/X\1/'
 cd b
 hg verify
 cd ..
--- a/tests/test-http-proxy.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-http-proxy.out	Fri Sep 15 16:01:16 2006 -0500
@@ -2,7 +2,7 @@
 %% url for proxy, stream
 streaming all changes
 XXX files to transfer, XXX bytes of data
-transferred XXX bytes in XXX seconds (XXX KB/sec)
+transferred XXX bytes in XXX seconds (XXX XB/sec)
 XXX files updated, XXX files merged, XXX files removed, XXX files unresolved
 checking changesets
 checking manifests
--- a/tests/test-init	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-init	Fri Sep 15 16:01:16 2006 -0500
@@ -27,6 +27,9 @@
 echo this > local/foo
 hg ci --cwd local -A -m "init" -d "1000000 0"
 
+echo "#test failure"
+hg init local
+
 echo "# init+push to remote2"
 hg init -e ./dummyssh ssh://user@dummy/remote2
 hg incoming -R remote2 local
@@ -35,6 +38,12 @@
 echo "# clone to remote1"
 hg clone -e ./dummyssh local ssh://user@dummy/remote1
 
+echo "# init to existing repo"
+hg init -e ./dummyssh ssh://user@dummy/remote1
+
+echo "# clone to existing repo"
+hg clone -e ./dummyssh local ssh://user@dummy/remote1
+
 echo "# output of dummyssh"
 cat dummylog
 
--- a/tests/test-init.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-init.out	Fri Sep 15 16:01:16 2006 -0500
@@ -1,5 +1,7 @@
 # creating 'local'
 adding foo
+#test failure
+abort: repository local already exists!
 # init+push to remote2
 changeset:   0:c4e059d443be
 tag:         tip
@@ -15,20 +17,24 @@
 remote: added 1 changesets with 1 changes to 1 files
 # clone to remote1
 searching for changes
-remote: abort: repository remote1 not found!
 remote: adding changesets
 remote: adding manifests
 remote: adding file changes
 remote: added 1 changesets with 1 changes to 1 files
+# init to existing repo
+abort: repository remote1 already exists!
+abort: could not create remote repo!
+# clone to existing repo
+abort: repository remote1 already exists!
+abort: could not create remote repo!
 # output of dummyssh
-Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio 3: 4: 5:
 Got arguments 1:user@dummy 2:hg init remote2 3: 4: 5:
 Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio 3: 4: 5:
 Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio 3: 4: 5:
-Got arguments 1:user@dummy 2:hg -R remote1 serve --stdio 3: 4: 5:
+Got arguments 1:user@dummy 2:hg init remote1 3: 4: 5:
 Got arguments 1:user@dummy 2:hg -R remote1 serve --stdio 3: 4: 5:
 Got arguments 1:user@dummy 2:hg init remote1 3: 4: 5:
-Got arguments 1:user@dummy 2:hg -R remote1 serve --stdio 3: 4: 5:
+Got arguments 1:user@dummy 2:hg init remote1 3: 4: 5:
 # comparing repositories
 0:c4e059d443be
 0:c4e059d443be
--- a/tests/test-merge7.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-merge7.out	Fri Sep 15 16:01:16 2006 -0500
@@ -23,7 +23,7 @@
 merge: warning: conflicts during merge
 resolving manifests
  overwrite None branchmerge True partial False linear False
- ancestor 055d847dd401 local 2eded9ab0a5c remote 84cf5750dd20
+ ancestor 451c744aabcc local a070d41e8360 remote faaea63e63a9
  test.txt versions differ, resolve
 merging test.txt
 resolving test.txt
--- a/tests/test-mq	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-mq	Fri Sep 15 16:01:16 2006 -0500
@@ -115,6 +115,19 @@
 echo % qunapplied
 hg qunapplied
 
+echo % qpush/qpop with index
+hg qnew test1b.patch
+echo 1b > 1b
+hg add 1b
+hg qrefresh
+hg qpush 2
+hg qpop 0
+hg qpush test.patch+1
+hg qpush test.patch+2
+hg qpop test2.patch-1
+hg qpop test2.patch-2
+hg qpush test1b.patch+1
+
 echo % push should succeed
 hg qpop -a
 hg push ../../k
@@ -126,6 +139,27 @@
 hg strip tip 2>&1 | sed 's/\(saving bundle to \).*/\1/'
 hg unbundle .hg/strip-backup/*
 
+echo '% cd b; hg qrefresh'
+hg init refresh
+cd refresh
+echo a > a
+hg ci -Ama -d'0 0'
+hg qnew -mfoo foo
+echo a >> a
+hg qrefresh
+mkdir b
+cd b
+echo f > f
+hg add f
+hg qrefresh
+sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
+    -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" ../.hg/patches/foo
+echo % hg qrefresh .
+hg qrefresh .
+sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
+    -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" ../.hg/patches/foo
+hg status
+
 cat >>$HGRCPATH <<EOF
 [diff]
 git = True
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-qdelete	Fri Sep 15 16:01:16 2006 -0500
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
+
+hg init a
+cd a
+
+echo 'base' > base
+hg ci -Ambase -d '1 0'
+
+hg qnew a
+hg qnew b
+hg qnew c
+
+hg qdel c
+hg qpop
+hg qdel c
+hg qseries
+ls .hg/patches
+hg qpop
+hg qdel -k b
+ls .hg/patches
+hg qdel -f a
+hg qapplied
+hg log --template '{rev} {desc}\n'
+
+hg qnew d
+hg qnew e
+hg qnew f
+
+hg qdel -f e
+hg qdel -f d e
+hg qapplied
+hg log --template '{rev} {desc}\n'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-qdelete.out	Fri Sep 15 16:01:16 2006 -0500
@@ -0,0 +1,23 @@
+adding base
+abort: cannot delete applied patch c
+Now at: b
+a
+b
+a
+b
+series
+status
+Now at: a
+a
+b
+series
+status
+1 New patch: a
+0 base
+abort: patch e not at base
+f
+4 New patch: f
+3 New patch: e
+2 New patch: d
+1 New patch: a
+0 base
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-qrename	Fri Sep 15 16:01:16 2006 -0500
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
+
+hg init a
+cd a
+
+echo 'base' > base
+hg ci -Ambase -d '1 0'
+
+hg qnew -mmqbase mqbase
+hg qrename mqbase renamed
+mkdir .hg/patches/foo
+hg qrename renamed foo
+hg qseries
+ls .hg/patches/foo
+mkdir .hg/patches/bar
+hg qrename foo/renamed bar
+hg qseries
+ls .hg/patches/bar
+hg qrename bar/renamed baz
+hg qseries
+ls .hg/patches/baz
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-qrename.out	Fri Sep 15 16:01:16 2006 -0500
@@ -0,0 +1,7 @@
+adding base
+foo/renamed
+renamed
+bar/renamed
+renamed
+baz
+.hg/patches/baz
--- a/tests/test-mq.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-mq.out	Fri Sep 15 16:01:16 2006 -0500
@@ -110,6 +110,19 @@
 abort: source has mq patches applied
 % qunapplied
 test2.patch
+% qpush/qpop with index
+applying test2.patch
+Now at: test2.patch
+Now at: test.patch
+applying test1b.patch
+Now at: test1b.patch
+applying test2.patch
+Now at: test2.patch
+Now at: test1b.patch
+Now at: test.patch
+applying test1b.patch
+applying test2.patch
+Now at: test2.patch
 % push should succeed
 Patch queue now empty
 pushing to ../../k
@@ -127,6 +140,30 @@
 adding file changes
 added 1 changesets with 1 changes to 1 files
 (run 'hg update' to get a working copy)
+% cd b; hg qrefresh
+adding a
+foo
+
+diff -r cb9a9f314b8b a
+--- a/a
++++ b/a
+@@ -1,1 +1,2 @@ a
+ a
++a
+diff -r cb9a9f314b8b b/f
+--- /dev/null
++++ b/b/f
+@@ -0,0 +1,1 @@
++f
+% hg qrefresh .
+foo
+
+diff -r cb9a9f314b8b b/f
+--- /dev/null
++++ b/b/f
+@@ -0,0 +1,1 @@
++f
+M a
 new file
 
 diff --git a/new b/new
--- a/tests/test-revert	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-revert	Fri Sep 15 16:01:16 2006 -0500
@@ -85,4 +85,8 @@
 echo % should succeed
 hg revert --all -rtip
 
+echo %% issue332
+hg ci -A -m b -d '1000001 0'
+echo foobar > b/b
+hg revert b
 true
--- a/tests/test-revert.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-revert.out	Fri Sep 15 16:01:16 2006 -0500
@@ -55,6 +55,9 @@
 adding a
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 % should fail - no arguments
-abort: no files or directories specified
+abort: no files or directories specified; use --all to revert the whole repo
 % should succeed
 reverting a
+%% issue332
+adding b/b
+reverting b/b
--- a/tests/test-ro-message.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-ro-message.out	Fri Sep 15 16:01:16 2006 -0500
@@ -1,3 +1,3 @@
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-abort: Permission denied - test-ro-message/b/vehicle
+abort: Permission denied: test-ro-message/b/vehicle
--- a/tests/test-ssh	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-ssh	Fri Sep 15 16:01:16 2006 -0500
@@ -38,7 +38,7 @@
 
 echo "# clone remote via stream"
 hg clone -e ./dummyssh --uncompressed ssh://user@dummy/remote local-stream 2>&1 | \
-  sed -e 's/[0-9][0-9.]*/XXX/g'
+  sed -e 's/[0-9][0-9.]*/XXX/g' -e 's/[KM]\(B\/sec\)/X\1/'
 cd local-stream
 hg verify
 cd ..
@@ -80,7 +80,7 @@
 echo "# check remote tip"
 hg tip
 hg verify
-hg cat foo
+hg cat -r tip foo
 
 echo z > z
 hg ci -A -m z -d '1000001 0' z
--- a/tests/test-ssh.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-ssh.out	Fri Sep 15 16:01:16 2006 -0500
@@ -2,7 +2,7 @@
 # clone remote via stream
 streaming all changes
 XXX files to transfer, XXX bytes of data
-transferred XXX bytes in XXX seconds (XXX KB/sec)
+transferred XXX bytes in XXX seconds (XXX XB/sec)
 XXX files updated, XXX files merged, XXX files removed, XXX files unresolved
 checking changesets
 checking manifests
--- a/tests/test-ui-config	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-ui-config	Fri Sep 15 16:01:16 2006 -0500
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-from mercurial import ui
+from mercurial import ui, util
 
 testui = ui.ui()
 testui.updateopts(config=[
@@ -11,10 +11,19 @@
     'lists.list2=foo bar baz',
     'lists.list3=alice, bob',
     'lists.list4=foo bar baz alice, bob',
+    'interpolation.value1=hallo',
+    'interpolation.value2=%(value1)s world',
+    'interpolation.value3=%(novalue)s',
+    'interpolation.value4=%(bad)1',
+    'interpolation.value5=%bad2',
 ])
 
 print repr(testui.configitems('values'))
 print repr(testui.configitems('lists'))
+try:
+    print repr(testui.configitems('interpolation'))
+except util.Abort, inst:
+    print inst
 print "---"
 print repr(testui.config('values', 'string'))
 print repr(testui.config('values', 'bool1'))
@@ -45,3 +54,18 @@
 print repr(testui.configlist('lists', 'unknown', ['foo bar']))
 print repr(testui.configlist('lists', 'unknown', ['foo', 'bar']))
 print "---"
+print repr(testui.config('interpolation', 'value1'))
+print repr(testui.config('interpolation', 'value2'))
+try:
+    print repr(testui.config('interpolation', 'value3'))
+except util.Abort, inst:
+    print inst
+try:
+    print repr(testui.config('interpolation', 'value4'))
+except util.Abort, inst:
+    print inst
+try:
+    print repr(testui.config('interpolation', 'value5'))
+except util.Abort, inst:
+    print inst
+print "---"
--- a/tests/test-ui-config.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-ui-config.out	Fri Sep 15 16:01:16 2006 -0500
@@ -1,5 +1,7 @@
 [('bool1', 'true'), ('bool2', 'false'), ('string', 'string value')]
 [('list1', 'foo'), ('list2', 'foo bar baz'), ('list3', 'alice, bob'), ('list4', 'foo bar baz alice, bob')]
+Error in configuration section [interpolation]:
+'%' must be followed by '%' or '(', found: '%bad2'
 ---
 'string value'
 'true'
@@ -27,3 +29,17 @@
 ['foo bar']
 ['foo', 'bar']
 ---
+'hallo'
+'hallo world'
+Error in configuration section [interpolation] parameter 'value3':
+Bad value substitution:
+	section: [interpolation]
+	option : value3
+	key    : novalue
+	rawval : 
+
+Error in configuration section [interpolation] parameter 'value4':
+bad interpolation variable reference '%(bad)1'
+Error in configuration section [interpolation] parameter 'value5':
+'%' must be followed by '%' or '(', found: '%bad2'
+---
--- a/tests/test-up-local-change.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-up-local-change.out	Fri Sep 15 16:01:16 2006 -0500
@@ -16,7 +16,7 @@
 
 resolving manifests
  overwrite False branchmerge False partial False linear True
- ancestor a0c8bcbbb45c local a0c8bcbbb45c remote 1165e8bd193e
+ ancestor 33aaa84a386b local 802f095af299 remote 33aaa84a386b
  a versions differ, resolve
 remote created b
 merging a
@@ -32,7 +32,7 @@
 
 resolving manifests
  overwrite False branchmerge False partial False linear True
- ancestor a0c8bcbbb45c local 1165e8bd193e remote a0c8bcbbb45c
+ ancestor 802f095af299 local 33aaa84a386b remote 33aaa84a386b
 remote deleted b
 removing b
 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
@@ -50,7 +50,7 @@
 
 resolving manifests
  overwrite False branchmerge False partial False linear True
- ancestor a0c8bcbbb45c local a0c8bcbbb45c remote 1165e8bd193e
+ ancestor 33aaa84a386b local 802f095af299 remote 33aaa84a386b
  a versions differ, resolve
 remote created b
 merging a
@@ -101,7 +101,7 @@
 failed
 resolving manifests
  overwrite False branchmerge True partial False linear False
- ancestor a0c8bcbbb45c local 1165e8bd193e remote 4096f2872392
+ ancestor 802f095af299 local 030602aee63d remote 33aaa84a386b
  a versions differ, resolve
  b versions differ, resolve
 merging a
--- a/tests/test-update-reverse.out	Fri Sep 15 16:00:16 2006 -0500
+++ b/tests/test-update-reverse.out	Fri Sep 15 16:01:16 2006 -0500
@@ -41,7 +41,7 @@
 side2
 resolving manifests
  overwrite True branchmerge False partial False linear False
- ancestor 8515d4bfda76 local 1c0f48f8ece6 remote 0594b9004bae
+ ancestor ded32b0db104 local 221226fb2bd8 remote 537353581d3d
 remote deleted side2, clobbering
 remote deleted side1, clobbering
 remote created main