hgext/hgk.py
changeset 3061 fe5c92529d1c
parent 3060 aa1cee5b8afb
child 3062 32fd512ca7c0
equal deleted inserted replaced
3060:aa1cee5b8afb 3061:fe5c92529d1c
     7 
     7 
     8 from mercurial.demandload import *
     8 from mercurial.demandload import *
     9 demandload(globals(), 'time sys signal os')
     9 demandload(globals(), 'time sys signal os')
    10 demandload(globals(), 'mercurial:hg,mdiff,fancyopts,commands,ui,util')
    10 demandload(globals(), 'mercurial:hg,mdiff,fancyopts,commands,ui,util')
    11 
    11 
       
    12 def filterfiles(files, filters):
       
    13     l = [x for x in filters if x in files]
       
    14 
       
    15     for t in files:
       
    16         if not t.endswith("/"):
       
    17             t += "/"
       
    18         l += [x for x in filters if x.startswith(t)]
       
    19     return l
       
    20 
    12 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
    21 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
    13            changes=None, text=False):
    22            changes=None, text=False):
    14     def date(c):
    23     def date(c):
    15         return time.asctime(time.gmtime(c[2][0]))
    24         return time.asctime(time.gmtime(c[2][0]))
    16 
    25 
    39 
    48 
    40     change = repo.changelog.read(node1)
    49     change = repo.changelog.read(node1)
    41     mmap = repo.manifest.read(change[0])
    50     mmap = repo.manifest.read(change[0])
    42     date1 = date(change)
    51     date1 = date(change)
    43 
    52 
       
    53     opts = mdiff.diffopts()
       
    54     opts.text = text
    44     for f in modified:
    55     for f in modified:
    45         to = None
    56         to = None
    46         if f in mmap:
    57         if f in mmap:
    47             to = repo.file(f).read(mmap[f])
    58             to = repo.file(f).read(mmap[f])
    48         tn = read(f)
    59         tn = read(f)
    49         opts = mdiff.diffopts()
       
    50         opts.text = text
       
    51         fp.write("diff --git a/%s b/%s\n" % (f, f))
    60         fp.write("diff --git a/%s b/%s\n" % (f, f))
    52         fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts))
    61         fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts))
    53     for f in added:
    62     for f in added:
    54         to = None
    63         to = None
    55         tn = read(f)
    64         tn = read(f)
    62         fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts))
    71         fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts))
    63 
    72 
    64 def difftree(ui, repo, node1=None, node2=None, *files, **opts):
    73 def difftree(ui, repo, node1=None, node2=None, *files, **opts):
    65     """diff trees from two commits"""
    74     """diff trees from two commits"""
    66     def __difftree(repo, node1, node2, files=[]):
    75     def __difftree(repo, node1, node2, files=[]):
    67         def date(c):
       
    68             return time.asctime(time.gmtime(c[2][0]))
       
    69 
       
    70         if node2:
    76         if node2:
    71             change = repo.changelog.read(node2)
    77             change = repo.changelog.read(node2)
    72             mmap2 = repo.manifest.read(change[0])
    78             mmap2 = repo.manifest.read(change[0])
    73             status = repo.status(node1, node2, files=files)[:5]
    79             status = repo.status(node1, node2, files=files)[:5]
    74             modified, added, removed, deleted, unknown = status
    80             modified, added, removed, deleted, unknown = status
    75             def read(f): return repo.file(f).read(mmap2[f])
       
    76             date2 = date(change)
       
    77         else:
    81         else:
    78             date2 = time.asctime()
       
    79             status = repo.status(node1, files=files)[:5]
    82             status = repo.status(node1, files=files)[:5]
    80             modified, added, removed, deleted, unknown = status
    83             modified, added, removed, deleted, unknown = status
    81             if not node1:
    84             if not node1:
    82                 node1 = repo.dirstate.parents()[0]
    85                 node1 = repo.dirstate.parents()[0]
    83             def read(f): return file(os.path.join(repo.root, f)).read()
       
    84 
    86 
    85         change = repo.changelog.read(node1)
    87         change = repo.changelog.read(node1)
    86         mmap = repo.manifest.read(change[0])
    88         mmap = repo.manifest.read(change[0])
    87         date1 = date(change)
       
    88         empty = "0" * 40;
    89         empty = "0" * 40;
    89 
    90 
    90         for f in modified:
    91         for f in modified:
    91             # TODO get file permissions
    92             # TODO get file permissions
    92             print ":100664 100664 %s %s M\t%s\t%s" % (hg.short(mmap[f]),
    93             print ":100664 100664 %s %s M\t%s\t%s" % (hg.short(mmap[f]),
   286                     parentstr += " " + hg.short(pp[0])
   287                     parentstr += " " + hg.short(pp[0])
   287                 if pp[1] != hg.nullid:
   288                 if pp[1] != hg.nullid:
   288                     parentstr += " " + hg.short(pp[1])
   289                     parentstr += " " + hg.short(pp[1])
   289             if not full:
   290             if not full:
   290                 print hg.short(n) + parentstr
   291                 print hg.short(n) + parentstr
   291             elif full is "commit":
   292             elif full == "commit":
   292                 print hg.short(n) + parentstr
   293                 print hg.short(n) + parentstr
   293                 catcommit(repo, n, '    ', changes)
   294                 catcommit(repo, n, '    ', changes)
   294             else:
   295             else:
   295                 (p1, p2) = repo.changelog.parents(n)
   296                 (p1, p2) = repo.changelog.parents(n)
   296                 (h, h1, h2) = map(hg.short, (n, p1, p2))
   297                 (h, h1, h2) = map(hg.short, (n, p1, p2))