hg
changeset 31 642058291e74
parent 29 4d3a5dcb6972
child 33 98633e60067c
equal deleted inserted replaced
30:12f598340423 31:642058291e74
    36  dump <file> [rev]     dump the latest or given revision of a file
    36  dump <file> [rev]     dump the latest or given revision of a file
    37  dumpmanifest [rev]    dump the latest or given revision of the manifest
    37  dumpmanifest [rev]    dump the latest or given revision of the manifest
    38  diff [files...]       diff working directory (or selected files)
    38  diff [files...]       diff working directory (or selected files)
    39 """
    39 """
    40 
    40 
       
    41 def diffdir(node, files = None):
       
    42     (c, a, d) = repo.diffdir(repo.root, node)
       
    43 
       
    44     if args:
       
    45         nc = [ x for x in c if x in args ]
       
    46         na = [ x for x in a if x in args ]
       
    47         nd = [ x for x in d if x in args ]
       
    48         for arg in args:
       
    49             if not os.path.isdir(arg): continue
       
    50             if arg[-1] != os.sep: arg += os.sep
       
    51             nc += [ x for x in c if x.startswith(arg) ]
       
    52             na += [ x for x in a if x.startswith(arg) ]
       
    53             nd += [ x for x in d if x.startswith(arg) ]
       
    54         (c, a, d) = (nc, na, nd)
       
    55 
       
    56     return (c, a, d)
       
    57     
       
    58 
    41 options = {}
    59 options = {}
    42 opts = [('v', 'verbose', None, 'verbose'),
    60 opts = [('v', 'verbose', None, 'verbose'),
    43         ('d', 'debug', None, 'debug')]
    61         ('d', 'debug', None, 'debug')]
    44 
    62 
    45 args = fancyopts.fancyopts(sys.argv[1:], opts, options,
    63 args = fancyopts.fancyopts(sys.argv[1:], opts, options,
    86     repo.remove(args)
   104     repo.remove(args)
    87 
   105 
    88 elif cmd == "commit" or cmd == "checkin" or cmd == "ci":
   106 elif cmd == "commit" or cmd == "checkin" or cmd == "ci":
    89     if 1:
   107     if 1:
    90         if len(args) > 0:
   108         if len(args) > 0:
    91             repo.commit(args)
   109             repo.commit(repo.current, args)
    92         else:
   110         else:
    93             repo.commit()
   111             repo.commit(repo.current)
    94 
   112 
    95 elif cmd == "import" or cmd == "patch":
   113 elif cmd == "import" or cmd == "patch":
    96     ioptions = {}
   114     ioptions = {}
    97     opts = [('p', 'strip', 1, 'path strip'),
   115     opts = [('p', 'strip', 1, 'path strip'),
    98             ('b', 'base', "", 'base path')]
   116             ('b', 'base', "", 'base path')]
   110         files = f.read().splitlines()
   128         files = f.read().splitlines()
   111         f.close()
   129         f.close()
   112         repo.commit(files)
   130         repo.commit(files)
   113 
   131 
   114 elif cmd == "status":
   132 elif cmd == "status":
   115     (c, a, d) = repo.diffdir(repo.root, repo.current)
   133     (c, a, d) = diffdir(repo.current)
   116     for f in c: print "C", f
   134     for f in c: print "C", f
   117     for f in a: print "?", f
   135     for f in a: print "?", f
   118     for f in d: print "R", f
   136     for f in d: print "R", f
   119 
   137 
   120 elif cmd == "diff":
   138 elif cmd == "diff":
       
   139     (c, a, d) = diffdir(repo.current, args)
       
   140 
   121     mmap = {}
   141     mmap = {}
   122     if repo.current:
   142     if repo.current:
   123         change = repo.changelog.read(repo.current)
   143         change = repo.changelog.read(repo.current)
   124         mmap = repo.manifest.read(change[0])
   144         mmap = repo.manifest.read(change[0])
   125 
       
   126     (c, a, d) = repo.diffdir(repo.root, repo.current)
       
   127 
       
   128     if args:
       
   129         nc = [ x for x in c if x in args ]
       
   130         na = [ x for x in a if x in args ]
       
   131         nd = [ x for x in d if x in args ]
       
   132         for arg in args:
       
   133             if not os.path.isdir(arg): continue
       
   134             if arg[-1] != os.sep: arg += os.sep
       
   135             nc += [ x for x in c if x.startswith(arg) ]
       
   136             na += [ x for x in a if x.startswith(arg) ]
       
   137             nd += [ x for x in d if x.startswith(arg) ]
       
   138         (c, a, d) = (nc, na, nd)
       
   139 
   145 
   140     for f in c:
   146     for f in c:
   141         to = repo.file(f).read(mmap[f])
   147         to = repo.file(f).read(mmap[f])
   142         tn = file(f).read()
   148         tn = file(f).read()
   143         sys.stdout.write(mdiff.unidiff(to, tn, f))
   149         sys.stdout.write(mdiff.unidiff(to, tn, f))