changeset 34:8708c75da2ac

Add export command
author mpm@selenic.com
date Sat, 07 May 2005 11:37:28 -0800
parents 98633e60067c
children 9197c26a414b
files hg
diffstat 1 files changed, 39 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/hg	Sat May 07 09:27:52 2005 -0800
+++ b/hg	Sat May 07 11:37:28 2005 -0800
@@ -46,6 +46,39 @@
         l += [ x for x in list if x.startswith(f) ]
     return l
 
+def diff(files = None, node1 = None, node2 = None):
+
+    if node2:
+        change = repo.changelog.read(node2)
+        mmap2 = repo.manifest.read(change[0])
+        (c, a, d) = repo.diffrevs(node1, node2)
+        def read(f): return repo.file(f).read(mmap2[f])
+    else:
+        if not node1:
+            node1 = repo.current
+        (c, a, d) = repo.diffdir(repo.root, node1)
+        def read(f): return file(f).read()
+
+    change = repo.changelog.read(node1)
+    mmap = repo.manifest.read(change[0])
+
+    if files:
+        (c, a, d) = map(lambda x: filterfiles(x, files), (c, a, d))
+
+    for f in c:
+        to = repo.file(f).read(mmap[f])
+        tn = read(f)
+        sys.stdout.write(mdiff.unidiff(to, tn, f))
+    for f in a:
+        to = ""
+        tn = read(f)
+        sys.stdout.write(mdiff.unidiff(to, tn, f))
+    for f in d:
+        to = repo.file(f).read(mmap[f])
+        tn = ""
+        sys.stdout.write(mdiff.unidiff(to, tn, f))
+    
+
 options = {}
 opts = [('v', 'verbose', None, 'verbose'),
         ('d', 'debug', None, 'debug')]
@@ -127,7 +160,7 @@
 
 elif cmd == "diff":
     doptions = {}
-    revs = [repo.current]
+    revs = []
 
     if args:
         opts = [('r', 'revision', [], 'revision')]
@@ -139,38 +172,13 @@
     if len(revs) > 2:
         print "too many revisions to diff"
         sys.exit(1)
-    elif len(revs) == 2:
-        change = repo.changelog.read(revs[1])
-        mmap2 = repo.manifest.read(change[0])
-        (c, a, d) = repo.diffrevs(revs[0], revs[1])
-        def read(f): return repo.file(f).read(mmap2[f])
     else:
-        if len(revs) < 1:
-            if not repo.current:
-                sys.exit(0)
-        (c, a, d) = repo.diffdir(repo.root, revs[0])
-        def read(f): return file(f).read()
-
-    change = repo.changelog.read(revs[0])
-    mmap = repo.manifest.read(change[0])
+        diff(args, *revs)
 
-    if args:
-        c = filterfiles(c, args)
-        a = filterfiles(a, args)
-        d = filterfiles(d, args)
-
-    for f in c:
-        to = repo.file(f).read(mmap[f])
-        tn = read(f)
-        sys.stdout.write(mdiff.unidiff(to, tn, f))
-    for f in a:
-        to = ""
-        tn = read(f)
-        sys.stdout.write(mdiff.unidiff(to, tn, f))
-    for f in d:
-        to = repo.file(f).read(mmap[f])
-        tn = ""
-        sys.stdout.write(mdiff.unidiff(to, tn, f))
+elif cmd == "export":
+    node = hg.bin(args[0])
+    prev = repo.changelog.parents(node)[0]
+    diff(None, prev, node)
 
 elif cmd == "addremove":
     (c, a, d) = repo.diffdir(repo.root, repo.current)