Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/filelog.py @ 1109:ee817c5e3ece
Merge with TAH
author | mpm@selenic.com |
---|---|
date | Sat, 27 Aug 2005 17:26:26 -0700 |
parents | 142b5d5ec9cc |
children | 0cdd73b0767c |
rev | line source |
---|---|
1089 | 1 # filelog.py - file history class for mercurial |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 # |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
4 # |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
1089 | 8 import os |
262 | 9 from revlog import * |
10 from demandload import * | |
1089 | 11 demandload(globals(), "bdiff") |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
12 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
13 class filelog(revlog): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
14 def __init__(self, opener, path): |
144
ea9188538222
Fix transaction handling bug by reverting fileopener change
mpm@selenic.com
parents:
140
diff
changeset
|
15 revlog.__init__(self, opener, |
786
902b12d55751
Fix the directory and revlog collision problem
mpm@selenic.com
parents:
785
diff
changeset
|
16 os.path.join("data", self.encodedir(path + ".i")), |
902b12d55751
Fix the directory and revlog collision problem
mpm@selenic.com
parents:
785
diff
changeset
|
17 os.path.join("data", self.encodedir(path + ".d"))) |
902b12d55751
Fix the directory and revlog collision problem
mpm@selenic.com
parents:
785
diff
changeset
|
18 |
902b12d55751
Fix the directory and revlog collision problem
mpm@selenic.com
parents:
785
diff
changeset
|
19 # This avoids a collision between a file named foo and a dir named |
902b12d55751
Fix the directory and revlog collision problem
mpm@selenic.com
parents:
785
diff
changeset
|
20 # foo.i or foo.d |
902b12d55751
Fix the directory and revlog collision problem
mpm@selenic.com
parents:
785
diff
changeset
|
21 def encodedir(self, path): |
856
fbe964ae7325
Fixed encoding of directories ending in .d or .i:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
839
diff
changeset
|
22 return (path |
fbe964ae7325
Fixed encoding of directories ending in .d or .i:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
839
diff
changeset
|
23 .replace(".hg/", ".hg.hg/") |
fbe964ae7325
Fixed encoding of directories ending in .d or .i:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
839
diff
changeset
|
24 .replace(".i/", ".i.hg/") |
fbe964ae7325
Fixed encoding of directories ending in .d or .i:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
839
diff
changeset
|
25 .replace(".d/", ".d.hg/")) |
786
902b12d55751
Fix the directory and revlog collision problem
mpm@selenic.com
parents:
785
diff
changeset
|
26 |
902b12d55751
Fix the directory and revlog collision problem
mpm@selenic.com
parents:
785
diff
changeset
|
27 def decodedir(self, path): |
856
fbe964ae7325
Fixed encoding of directories ending in .d or .i:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
839
diff
changeset
|
28 return (path |
fbe964ae7325
Fixed encoding of directories ending in .d or .i:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
839
diff
changeset
|
29 .replace(".d.hg/", ".d/") |
fbe964ae7325
Fixed encoding of directories ending in .d or .i:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
839
diff
changeset
|
30 .replace(".i.hg/", ".i/") |
fbe964ae7325
Fixed encoding of directories ending in .d or .i:
Thomas Arendsen Hein <thomas@intevation.de>
parents:
839
diff
changeset
|
31 .replace(".hg.hg/", ".hg/")) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
32 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
33 def read(self, node): |
360 | 34 t = self.revision(node) |
686
d7d68d27ebe5
Reapply startswith() changes that got lost with stale edit
Matt Mackall <mpm@selenic.com>
parents:
681
diff
changeset
|
35 if not t.startswith('\1\n'): |
360 | 36 return t |
37 s = t.find('\1\n', 2) | |
38 return t[s+2:] | |
39 | |
40 def readmeta(self, node): | |
41 t = self.revision(node) | |
686
d7d68d27ebe5
Reapply startswith() changes that got lost with stale edit
Matt Mackall <mpm@selenic.com>
parents:
681
diff
changeset
|
42 if not t.startswith('\1\n'): |
360 | 43 return t |
44 s = t.find('\1\n', 2) | |
45 mt = t[2:s] | |
46 for l in mt.splitlines(): | |
47 k, v = l.split(": ", 1) | |
48 m[k] = v | |
49 return m | |
50 | |
51 def add(self, text, meta, transaction, link, p1=None, p2=None): | |
686
d7d68d27ebe5
Reapply startswith() changes that got lost with stale edit
Matt Mackall <mpm@selenic.com>
parents:
681
diff
changeset
|
52 if meta or text.startswith('\1\n'): |
360 | 53 mt = "" |
54 if meta: | |
55 mt = [ "%s: %s\n" % (k, v) for k,v in meta.items() ] | |
56 text = "\1\n" + "".join(mt) + "\1\n" + text | |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
57 return self.addrevision(text, transaction, link, p1, p2) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
58 |
79 | 59 def annotate(self, node): |
199 | 60 |
61 def decorate(text, rev): | |
436 | 62 return ([rev] * len(text.splitlines()), text) |
199 | 63 |
64 def pair(parent, child): | |
436 | 65 for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): |
471 | 66 child[0][b1:b2] = parent[0][a1:a2] |
67 return child | |
199 | 68 |
200 | 69 # find all ancestors |
216
201115f2859b
hg annotate: actually annotate the given version
mpm@selenic.com
parents:
210
diff
changeset
|
70 needed = {node:1} |
199 | 71 visit = [node] |
72 while visit: | |
73 n = visit.pop(0) | |
74 for p in self.parents(n): | |
75 if p not in needed: | |
76 needed[p] = 1 | |
77 visit.append(p) | |
200 | 78 else: |
79 # count how many times we'll use this | |
80 needed[p] += 1 | |
199 | 81 |
200 | 82 # sort by revision which is a topological order |
471 | 83 visit = [ (self.rev(n), n) for n in needed.keys() ] |
199 | 84 visit.sort() |
85 hist = {} | |
86 | |
471 | 87 for r,n in visit: |
199 | 88 curr = decorate(self.read(n), self.linkrev(n)) |
89 for p in self.parents(n): | |
90 if p != nullid: | |
91 curr = pair(hist[p], curr) | |
200 | 92 # trim the history of unneeded revs |
93 needed[p] -= 1 | |
94 if not needed[p]: | |
95 del hist[p] | |
199 | 96 hist[n] = curr |
97 | |
436 | 98 return zip(hist[n][0], hist[n][1].splitlines(1)) |