Show More
@@ -1,153 +1,152 | |||||
1 | # perf.py - performance test routines |
|
1 | # perf.py - performance test routines | |
2 | '''helper extension to measure performance''' |
|
2 | '''helper extension to measure performance''' | |
3 |
|
3 | |||
4 | from mercurial import cmdutil, match, commands |
|
4 | from mercurial import cmdutil, match, commands | |
5 | import time, os, sys |
|
5 | import time, os, sys | |
6 |
|
6 | |||
7 | def timer(func, title=None): |
|
7 | def timer(func, title=None): | |
8 | results = [] |
|
8 | results = [] | |
9 | begin = time.time() |
|
9 | begin = time.time() | |
10 | count = 0 |
|
10 | count = 0 | |
11 | while 1: |
|
11 | while 1: | |
12 | ostart = os.times() |
|
12 | ostart = os.times() | |
13 | cstart = time.time() |
|
13 | cstart = time.time() | |
14 | r = func() |
|
14 | r = func() | |
15 | cstop = time.time() |
|
15 | cstop = time.time() | |
16 | ostop = os.times() |
|
16 | ostop = os.times() | |
17 | count += 1 |
|
17 | count += 1 | |
18 | a, b = ostart, ostop |
|
18 | a, b = ostart, ostop | |
19 | results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
|
19 | results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) | |
20 | if cstop - begin > 3 and count >= 100: |
|
20 | if cstop - begin > 3 and count >= 100: | |
21 | break |
|
21 | break | |
22 | if cstop - begin > 10 and count >= 3: |
|
22 | if cstop - begin > 10 and count >= 3: | |
23 | break |
|
23 | break | |
24 | if title: |
|
24 | if title: | |
25 | sys.stderr.write("! %s\n" % title) |
|
25 | sys.stderr.write("! %s\n" % title) | |
26 | if r: |
|
26 | if r: | |
27 | sys.stderr.write("! result: %s\n" % r) |
|
27 | sys.stderr.write("! result: %s\n" % r) | |
28 | m = min(results) |
|
28 | m = min(results) | |
29 | sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" |
|
29 | sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" | |
30 | % (m[0], m[1] + m[2], m[1], m[2], count)) |
|
30 | % (m[0], m[1] + m[2], m[1], m[2], count)) | |
31 |
|
31 | |||
32 | def perfwalk(ui, repo, *pats): |
|
32 | def perfwalk(ui, repo, *pats): | |
33 | try: |
|
33 | try: | |
34 | m = cmdutil.match(repo, pats, {}) |
|
34 | m = cmdutil.match(repo, pats, {}) | |
35 | timer(lambda: len(list(repo.dirstate.walk(m, True, False)))) |
|
35 | timer(lambda: len(list(repo.dirstate.walk(m, [], True, False)))) | |
36 | except: |
|
36 | except: | |
37 | try: |
|
37 | try: | |
38 | m = cmdutil.match(repo, pats, {}) |
|
38 | m = cmdutil.match(repo, pats, {}) | |
39 | timer(lambda: len([b for a,b,c in repo.dirstate.statwalk([], m)])) |
|
39 | timer(lambda: len([b for a,b,c in repo.dirstate.statwalk([], m)])) | |
40 | except: |
|
40 | except: | |
41 | timer(lambda: len(list(cmdutil.walk(repo, pats, {})))) |
|
41 | timer(lambda: len(list(cmdutil.walk(repo, pats, {})))) | |
42 |
|
42 | |||
43 | def perfstatus(ui, repo, *pats): |
|
43 | def perfstatus(ui, repo, *pats): | |
44 | #m = match.always(repo.root, repo.getcwd()) |
|
44 | #m = match.always(repo.root, repo.getcwd()) | |
45 | #timer(lambda: sum(map(len, repo.dirstate.status(m, False, False, False)))) |
|
45 | #timer(lambda: sum(map(len, repo.dirstate.status(m, False, False, False)))) | |
46 | timer(lambda: sum(map(len, repo.status()))) |
|
46 | timer(lambda: sum(map(len, repo.status()))) | |
47 |
|
47 | |||
48 | def perfheads(ui, repo): |
|
48 | def perfheads(ui, repo): | |
49 | timer(lambda: len(repo.changelog.heads())) |
|
49 | timer(lambda: len(repo.changelog.heads())) | |
50 |
|
50 | |||
51 | def perftags(ui, repo): |
|
51 | def perftags(ui, repo): | |
52 | import mercurial.changelog, mercurial.manifest |
|
52 | import mercurial.changelog, mercurial.manifest | |
53 | def t(): |
|
53 | def t(): | |
54 | repo.changelog = mercurial.changelog.changelog(repo.sopener) |
|
54 | repo.changelog = mercurial.changelog.changelog(repo.sopener) | |
55 | repo.manifest = mercurial.manifest.manifest(repo.sopener) |
|
55 | repo.manifest = mercurial.manifest.manifest(repo.sopener) | |
56 | repo._tags = None |
|
56 | repo._tags = None | |
57 | return len(repo.tags()) |
|
57 | return len(repo.tags()) | |
58 | timer(t) |
|
58 | timer(t) | |
59 |
|
59 | |||
60 | def perfdirstate(ui, repo): |
|
60 | def perfdirstate(ui, repo): | |
61 | "a" in repo.dirstate |
|
61 | "a" in repo.dirstate | |
62 | def d(): |
|
62 | def d(): | |
63 | repo.dirstate.invalidate() |
|
63 | repo.dirstate.invalidate() | |
64 | "a" in repo.dirstate |
|
64 | "a" in repo.dirstate | |
65 | timer(d) |
|
65 | timer(d) | |
66 |
|
66 | |||
67 | def perfdirstatedirs(ui, repo): |
|
67 | def perfdirstatedirs(ui, repo): | |
68 | "a" in repo.dirstate |
|
68 | "a" in repo.dirstate | |
69 | def d(): |
|
69 | def d(): | |
70 | "a" in repo.dirstate._dirs |
|
70 | "a" in repo.dirstate._dirs | |
71 | del repo.dirstate._dirs |
|
71 | del repo.dirstate._dirs | |
72 | timer(d) |
|
72 | timer(d) | |
73 |
|
73 | |||
74 | def perfmanifest(ui, repo): |
|
74 | def perfmanifest(ui, repo): | |
75 | def d(): |
|
75 | def d(): | |
76 | t = repo.manifest.tip() |
|
76 | t = repo.manifest.tip() | |
77 | m = repo.manifest.read(t) |
|
77 | m = repo.manifest.read(t) | |
78 | repo.manifest.mapcache = None |
|
78 | repo.manifest.mapcache = None | |
79 | repo.manifest._cache = None |
|
79 | repo.manifest._cache = None | |
80 | timer(d) |
|
80 | timer(d) | |
81 |
|
81 | |||
82 | def perfindex(ui, repo): |
|
82 | def perfindex(ui, repo): | |
83 | import mercurial.changelog |
|
83 | import mercurial.changelog | |
84 | def d(): |
|
84 | def d(): | |
85 | t = repo.changelog.tip() |
|
85 | t = repo.changelog.tip() | |
86 | repo.changelog = mercurial.changelog.changelog(repo.sopener) |
|
86 | repo.changelog = mercurial.changelog.changelog(repo.sopener) | |
87 | repo.changelog._loadindexmap() |
|
87 | repo.changelog._loadindexmap() | |
88 | timer(d) |
|
88 | timer(d) | |
89 |
|
89 | |||
90 | def perfstartup(ui, repo): |
|
90 | def perfstartup(ui, repo): | |
91 | cmd = sys.argv[0] |
|
91 | cmd = sys.argv[0] | |
92 | def d(): |
|
92 | def d(): | |
93 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) |
|
93 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) | |
94 | timer(d) |
|
94 | timer(d) | |
95 |
|
95 | |||
96 | def perfparents(ui, repo): |
|
96 | def perfparents(ui, repo): | |
97 | nl = [repo.changelog.node(i) for i in xrange(1000)] |
|
97 | nl = [repo.changelog.node(i) for i in xrange(1000)] | |
98 | def d(): |
|
98 | def d(): | |
99 | for n in nl: |
|
99 | for n in nl: | |
100 | repo.changelog.parents(n) |
|
100 | repo.changelog.parents(n) | |
101 | timer(d) |
|
101 | timer(d) | |
102 |
|
102 | |||
103 | def perflookup(ui, repo, rev): |
|
103 | def perflookup(ui, repo, rev): | |
104 | timer(lambda: len(repo.lookup(rev))) |
|
104 | timer(lambda: len(repo.lookup(rev))) | |
105 |
|
105 | |||
106 | def perflog(ui, repo, **opts): |
|
106 | def perflog(ui, repo, **opts): | |
107 | ui.pushbuffer() |
|
107 | ui.pushbuffer() | |
108 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
|
108 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', | |
109 | copies=opts.get('rename'))) |
|
109 | copies=opts.get('rename'))) | |
110 | ui.popbuffer() |
|
110 | ui.popbuffer() | |
111 |
|
111 | |||
112 | def perftemplating(ui, repo): |
|
112 | def perftemplating(ui, repo): | |
113 | ui.pushbuffer() |
|
113 | ui.pushbuffer() | |
114 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
|
114 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', | |
115 | template='{date|shortdate} [{rev}:{node|short}]' |
|
115 | template='{date|shortdate} [{rev}:{node|short}]' | |
116 | ' {author|person}: {desc|firstline}\n')) |
|
116 | ' {author|person}: {desc|firstline}\n')) | |
117 | ui.popbuffer() |
|
117 | ui.popbuffer() | |
118 |
|
118 | |||
119 | def perfdiffwd(ui, repo): |
|
119 | def perfdiffwd(ui, repo): | |
120 | """Profile diff of working directory changes""" |
|
120 | """Profile diff of working directory changes""" | |
121 | options = { |
|
121 | options = { | |
122 | 'w': 'ignore_all_space', |
|
122 | 'w': 'ignore_all_space', | |
123 | 'b': 'ignore_space_change', |
|
123 | 'b': 'ignore_space_change', | |
124 | 'B': 'ignore_blank_lines', |
|
124 | 'B': 'ignore_blank_lines', | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | for diffopt in ('', 'w', 'b', 'B', 'wB'): |
|
127 | for diffopt in ('', 'w', 'b', 'B', 'wB'): | |
128 | opts = dict((options[c], '1') for c in diffopt) |
|
128 | opts = dict((options[c], '1') for c in diffopt) | |
129 | def d(): |
|
129 | def d(): | |
130 | ui.pushbuffer() |
|
130 | ui.pushbuffer() | |
131 | commands.diff(ui, repo, **opts) |
|
131 | commands.diff(ui, repo, **opts) | |
132 | ui.popbuffer() |
|
132 | ui.popbuffer() | |
133 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') |
|
133 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') | |
134 | timer(d, title) |
|
134 | timer(d, title) | |
135 |
|
135 | |||
136 | cmdtable = { |
|
136 | cmdtable = { | |
137 | 'perflookup': (perflookup, []), |
|
137 | 'perflookup': (perflookup, []), | |
138 | 'perfparents': (perfparents, []), |
|
138 | 'perfparents': (perfparents, []), | |
139 | 'perfstartup': (perfstartup, []), |
|
139 | 'perfstartup': (perfstartup, []), | |
140 | 'perfstatus': (perfstatus, []), |
|
140 | 'perfstatus': (perfstatus, []), | |
141 | 'perfwalk': (perfwalk, []), |
|
141 | 'perfwalk': (perfwalk, []), | |
142 | 'perfmanifest': (perfmanifest, []), |
|
142 | 'perfmanifest': (perfmanifest, []), | |
143 | 'perfindex': (perfindex, []), |
|
143 | 'perfindex': (perfindex, []), | |
144 | 'perfheads': (perfheads, []), |
|
144 | 'perfheads': (perfheads, []), | |
145 | 'perftags': (perftags, []), |
|
145 | 'perftags': (perftags, []), | |
146 | 'perfdirstate': (perfdirstate, []), |
|
146 | 'perfdirstate': (perfdirstate, []), | |
147 | 'perfdirstatedirs': (perfdirstate, []), |
|
147 | 'perfdirstatedirs': (perfdirstate, []), | |
148 | 'perflog': (perflog, |
|
148 | 'perflog': (perflog, | |
149 | [('', 'rename', False, 'ask log to follow renames')]), |
|
149 | [('', 'rename', False, 'ask log to follow renames')]), | |
150 | 'perftemplating': (perftemplating, []), |
|
150 | 'perftemplating': (perftemplating, []), | |
151 | 'perfdiffwd': (perfdiffwd, []), |
|
151 | 'perfdiffwd': (perfdiffwd, []), | |
152 | } |
|
152 | } | |
153 |
|
@@ -1,87 +1,87 | |||||
1 | # __init__.py - inotify-based status acceleration for Linux |
|
1 | # __init__.py - inotify-based status acceleration for Linux | |
2 | # |
|
2 | # | |
3 | # Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> |
|
3 | # Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> | |
4 | # Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> |
|
4 | # Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | # GNU General Public License version 2, incorporated herein by reference. | |
8 |
|
8 | |||
9 | '''accelerate status report using Linux's inotify service''' |
|
9 | '''accelerate status report using Linux's inotify service''' | |
10 |
|
10 | |||
11 | # todo: socket permissions |
|
11 | # todo: socket permissions | |
12 |
|
12 | |||
13 | from mercurial.i18n import _ |
|
13 | from mercurial.i18n import _ | |
14 | from mercurial import cmdutil, util |
|
14 | from mercurial import cmdutil, util | |
15 | import server |
|
15 | import server | |
16 | from client import client, QueryFailed |
|
16 | from client import client, QueryFailed | |
17 |
|
17 | |||
18 | def serve(ui, repo, **opts): |
|
18 | def serve(ui, repo, **opts): | |
19 | '''start an inotify server for this repository''' |
|
19 | '''start an inotify server for this repository''' | |
20 | server.start(ui, repo.dirstate, repo.root, opts) |
|
20 | server.start(ui, repo.dirstate, repo.root, opts) | |
21 |
|
21 | |||
22 | def debuginotify(ui, repo, **opts): |
|
22 | def debuginotify(ui, repo, **opts): | |
23 | '''debugging information for inotify extension |
|
23 | '''debugging information for inotify extension | |
24 |
|
24 | |||
25 | Prints the list of directories being watched by the inotify server. |
|
25 | Prints the list of directories being watched by the inotify server. | |
26 | ''' |
|
26 | ''' | |
27 | cli = client(ui, repo) |
|
27 | cli = client(ui, repo) | |
28 | response = cli.debugquery() |
|
28 | response = cli.debugquery() | |
29 |
|
29 | |||
30 | ui.write(_('directories being watched:\n')) |
|
30 | ui.write(_('directories being watched:\n')) | |
31 | for path in response: |
|
31 | for path in response: | |
32 | ui.write((' %s/\n') % path) |
|
32 | ui.write((' %s/\n') % path) | |
33 |
|
33 | |||
34 | def reposetup(ui, repo): |
|
34 | def reposetup(ui, repo): | |
35 | if not hasattr(repo, 'dirstate'): |
|
35 | if not hasattr(repo, 'dirstate'): | |
36 | return |
|
36 | return | |
37 |
|
37 | |||
38 | class inotifydirstate(repo.dirstate.__class__): |
|
38 | class inotifydirstate(repo.dirstate.__class__): | |
39 |
|
39 | |||
40 | # We'll set this to false after an unsuccessful attempt so that |
|
40 | # We'll set this to false after an unsuccessful attempt so that | |
41 | # next calls of status() within the same instance don't try again |
|
41 | # next calls of status() within the same instance don't try again | |
42 | # to start an inotify server if it won't start. |
|
42 | # to start an inotify server if it won't start. | |
43 | _inotifyon = True |
|
43 | _inotifyon = True | |
44 |
|
44 | |||
45 | def status(self, match, ignored, clean, unknown=True): |
|
45 | def status(self, match, subrepos, ignored, clean, unknown=True): | |
46 | files = match.files() |
|
46 | files = match.files() | |
47 | if '.' in files: |
|
47 | if '.' in files: | |
48 | files = [] |
|
48 | files = [] | |
49 | if self._inotifyon and not ignored and not self._dirty: |
|
49 | if self._inotifyon and not ignored and not subrepos and not self._dirty: | |
50 | cli = client(ui, repo) |
|
50 | cli = client(ui, repo) | |
51 | try: |
|
51 | try: | |
52 | result = cli.statusquery(files, match, False, |
|
52 | result = cli.statusquery(files, match, False, | |
53 | clean, unknown) |
|
53 | clean, unknown) | |
54 | except QueryFailed, instr: |
|
54 | except QueryFailed, instr: | |
55 | ui.debug(str(instr)) |
|
55 | ui.debug(str(instr)) | |
56 | # don't retry within the same hg instance |
|
56 | # don't retry within the same hg instance | |
57 | inotifydirstate._inotifyon = False |
|
57 | inotifydirstate._inotifyon = False | |
58 | pass |
|
58 | pass | |
59 | else: |
|
59 | else: | |
60 | if ui.config('inotify', 'debug'): |
|
60 | if ui.config('inotify', 'debug'): | |
61 | r2 = super(inotifydirstate, self).status( |
|
61 | r2 = super(inotifydirstate, self).status( | |
62 | match, False, clean, unknown) |
|
62 | match, False, clean, unknown) | |
63 | for c,a,b in zip('LMARDUIC', result, r2): |
|
63 | for c,a,b in zip('LMARDUIC', result, r2): | |
64 | for f in a: |
|
64 | for f in a: | |
65 | if f not in b: |
|
65 | if f not in b: | |
66 | ui.warn('*** inotify: %s +%s\n' % (c, f)) |
|
66 | ui.warn('*** inotify: %s +%s\n' % (c, f)) | |
67 | for f in b: |
|
67 | for f in b: | |
68 | if f not in a: |
|
68 | if f not in a: | |
69 | ui.warn('*** inotify: %s -%s\n' % (c, f)) |
|
69 | ui.warn('*** inotify: %s -%s\n' % (c, f)) | |
70 | result = r2 |
|
70 | result = r2 | |
71 | return result |
|
71 | return result | |
72 | return super(inotifydirstate, self).status( |
|
72 | return super(inotifydirstate, self).status( | |
73 | match, ignored, clean, unknown) |
|
73 | match, subrepos, ignored, clean, unknown) | |
74 |
|
74 | |||
75 | repo.dirstate.__class__ = inotifydirstate |
|
75 | repo.dirstate.__class__ = inotifydirstate | |
76 |
|
76 | |||
77 | cmdtable = { |
|
77 | cmdtable = { | |
78 | 'debuginotify': |
|
78 | 'debuginotify': | |
79 | (debuginotify, [], ('hg debuginotify')), |
|
79 | (debuginotify, [], ('hg debuginotify')), | |
80 | '^inserve': |
|
80 | '^inserve': | |
81 | (serve, |
|
81 | (serve, | |
82 | [('d', 'daemon', None, _('run server in background')), |
|
82 | [('d', 'daemon', None, _('run server in background')), | |
83 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
83 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
84 | ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), |
|
84 | ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), | |
85 | ('', 'pid-file', '', _('name of file to write process ID to'))], |
|
85 | ('', 'pid-file', '', _('name of file to write process ID to'))], | |
86 | _('hg inserve [OPTION]...')), |
|
86 | _('hg inserve [OPTION]...')), | |
87 | } |
|
87 | } |
@@ -1,830 +1,831 | |||||
1 | # context.py - changeset and file context objects for mercurial |
|
1 | # context.py - changeset and file context objects for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2, incorporated herein by reference. |
|
6 | # GNU General Public License version 2, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from node import nullid, nullrev, short, hex |
|
8 | from node import nullid, nullrev, short, hex | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import ancestor, bdiff, error, util, subrepo |
|
10 | import ancestor, bdiff, error, util, subrepo | |
11 | import os, errno |
|
11 | import os, errno | |
12 |
|
12 | |||
13 | propertycache = util.propertycache |
|
13 | propertycache = util.propertycache | |
14 |
|
14 | |||
15 | class changectx(object): |
|
15 | class changectx(object): | |
16 | """A changecontext object makes access to data related to a particular |
|
16 | """A changecontext object makes access to data related to a particular | |
17 | changeset convenient.""" |
|
17 | changeset convenient.""" | |
18 | def __init__(self, repo, changeid=''): |
|
18 | def __init__(self, repo, changeid=''): | |
19 | """changeid is a revision number, node, or tag""" |
|
19 | """changeid is a revision number, node, or tag""" | |
20 | if changeid == '': |
|
20 | if changeid == '': | |
21 | changeid = '.' |
|
21 | changeid = '.' | |
22 | self._repo = repo |
|
22 | self._repo = repo | |
23 | if isinstance(changeid, (long, int)): |
|
23 | if isinstance(changeid, (long, int)): | |
24 | self._rev = changeid |
|
24 | self._rev = changeid | |
25 | self._node = self._repo.changelog.node(changeid) |
|
25 | self._node = self._repo.changelog.node(changeid) | |
26 | else: |
|
26 | else: | |
27 | self._node = self._repo.lookup(changeid) |
|
27 | self._node = self._repo.lookup(changeid) | |
28 | self._rev = self._repo.changelog.rev(self._node) |
|
28 | self._rev = self._repo.changelog.rev(self._node) | |
29 |
|
29 | |||
30 | def __str__(self): |
|
30 | def __str__(self): | |
31 | return short(self.node()) |
|
31 | return short(self.node()) | |
32 |
|
32 | |||
33 | def __int__(self): |
|
33 | def __int__(self): | |
34 | return self.rev() |
|
34 | return self.rev() | |
35 |
|
35 | |||
36 | def __repr__(self): |
|
36 | def __repr__(self): | |
37 | return "<changectx %s>" % str(self) |
|
37 | return "<changectx %s>" % str(self) | |
38 |
|
38 | |||
39 | def __hash__(self): |
|
39 | def __hash__(self): | |
40 | try: |
|
40 | try: | |
41 | return hash(self._rev) |
|
41 | return hash(self._rev) | |
42 | except AttributeError: |
|
42 | except AttributeError: | |
43 | return id(self) |
|
43 | return id(self) | |
44 |
|
44 | |||
45 | def __eq__(self, other): |
|
45 | def __eq__(self, other): | |
46 | try: |
|
46 | try: | |
47 | return self._rev == other._rev |
|
47 | return self._rev == other._rev | |
48 | except AttributeError: |
|
48 | except AttributeError: | |
49 | return False |
|
49 | return False | |
50 |
|
50 | |||
51 | def __ne__(self, other): |
|
51 | def __ne__(self, other): | |
52 | return not (self == other) |
|
52 | return not (self == other) | |
53 |
|
53 | |||
54 | def __nonzero__(self): |
|
54 | def __nonzero__(self): | |
55 | return self._rev != nullrev |
|
55 | return self._rev != nullrev | |
56 |
|
56 | |||
57 | @propertycache |
|
57 | @propertycache | |
58 | def _changeset(self): |
|
58 | def _changeset(self): | |
59 | return self._repo.changelog.read(self.node()) |
|
59 | return self._repo.changelog.read(self.node()) | |
60 |
|
60 | |||
61 | @propertycache |
|
61 | @propertycache | |
62 | def _manifest(self): |
|
62 | def _manifest(self): | |
63 | return self._repo.manifest.read(self._changeset[0]) |
|
63 | return self._repo.manifest.read(self._changeset[0]) | |
64 |
|
64 | |||
65 | @propertycache |
|
65 | @propertycache | |
66 | def _manifestdelta(self): |
|
66 | def _manifestdelta(self): | |
67 | return self._repo.manifest.readdelta(self._changeset[0]) |
|
67 | return self._repo.manifest.readdelta(self._changeset[0]) | |
68 |
|
68 | |||
69 | @propertycache |
|
69 | @propertycache | |
70 | def _parents(self): |
|
70 | def _parents(self): | |
71 | p = self._repo.changelog.parentrevs(self._rev) |
|
71 | p = self._repo.changelog.parentrevs(self._rev) | |
72 | if p[1] == nullrev: |
|
72 | if p[1] == nullrev: | |
73 | p = p[:-1] |
|
73 | p = p[:-1] | |
74 | return [changectx(self._repo, x) for x in p] |
|
74 | return [changectx(self._repo, x) for x in p] | |
75 |
|
75 | |||
76 | @propertycache |
|
76 | @propertycache | |
77 | def substate(self): |
|
77 | def substate(self): | |
78 | return subrepo.state(self) |
|
78 | return subrepo.state(self) | |
79 |
|
79 | |||
80 | def __contains__(self, key): |
|
80 | def __contains__(self, key): | |
81 | return key in self._manifest |
|
81 | return key in self._manifest | |
82 |
|
82 | |||
83 | def __getitem__(self, key): |
|
83 | def __getitem__(self, key): | |
84 | return self.filectx(key) |
|
84 | return self.filectx(key) | |
85 |
|
85 | |||
86 | def __iter__(self): |
|
86 | def __iter__(self): | |
87 | for f in sorted(self._manifest): |
|
87 | for f in sorted(self._manifest): | |
88 | yield f |
|
88 | yield f | |
89 |
|
89 | |||
90 | def changeset(self): return self._changeset |
|
90 | def changeset(self): return self._changeset | |
91 | def manifest(self): return self._manifest |
|
91 | def manifest(self): return self._manifest | |
92 | def manifestnode(self): return self._changeset[0] |
|
92 | def manifestnode(self): return self._changeset[0] | |
93 |
|
93 | |||
94 | def rev(self): return self._rev |
|
94 | def rev(self): return self._rev | |
95 | def node(self): return self._node |
|
95 | def node(self): return self._node | |
96 | def hex(self): return hex(self._node) |
|
96 | def hex(self): return hex(self._node) | |
97 | def user(self): return self._changeset[1] |
|
97 | def user(self): return self._changeset[1] | |
98 | def date(self): return self._changeset[2] |
|
98 | def date(self): return self._changeset[2] | |
99 | def files(self): return self._changeset[3] |
|
99 | def files(self): return self._changeset[3] | |
100 | def description(self): return self._changeset[4] |
|
100 | def description(self): return self._changeset[4] | |
101 | def branch(self): return self._changeset[5].get("branch") |
|
101 | def branch(self): return self._changeset[5].get("branch") | |
102 | def extra(self): return self._changeset[5] |
|
102 | def extra(self): return self._changeset[5] | |
103 | def tags(self): return self._repo.nodetags(self._node) |
|
103 | def tags(self): return self._repo.nodetags(self._node) | |
104 |
|
104 | |||
105 | def parents(self): |
|
105 | def parents(self): | |
106 | """return contexts for each parent changeset""" |
|
106 | """return contexts for each parent changeset""" | |
107 | return self._parents |
|
107 | return self._parents | |
108 |
|
108 | |||
109 | def p1(self): |
|
109 | def p1(self): | |
110 | return self._parents[0] |
|
110 | return self._parents[0] | |
111 |
|
111 | |||
112 | def p2(self): |
|
112 | def p2(self): | |
113 | if len(self._parents) == 2: |
|
113 | if len(self._parents) == 2: | |
114 | return self._parents[1] |
|
114 | return self._parents[1] | |
115 | return changectx(self._repo, -1) |
|
115 | return changectx(self._repo, -1) | |
116 |
|
116 | |||
117 | def children(self): |
|
117 | def children(self): | |
118 | """return contexts for each child changeset""" |
|
118 | """return contexts for each child changeset""" | |
119 | c = self._repo.changelog.children(self._node) |
|
119 | c = self._repo.changelog.children(self._node) | |
120 | return [changectx(self._repo, x) for x in c] |
|
120 | return [changectx(self._repo, x) for x in c] | |
121 |
|
121 | |||
122 | def ancestors(self): |
|
122 | def ancestors(self): | |
123 | for a in self._repo.changelog.ancestors(self._rev): |
|
123 | for a in self._repo.changelog.ancestors(self._rev): | |
124 | yield changectx(self._repo, a) |
|
124 | yield changectx(self._repo, a) | |
125 |
|
125 | |||
126 | def descendants(self): |
|
126 | def descendants(self): | |
127 | for d in self._repo.changelog.descendants(self._rev): |
|
127 | for d in self._repo.changelog.descendants(self._rev): | |
128 | yield changectx(self._repo, d) |
|
128 | yield changectx(self._repo, d) | |
129 |
|
129 | |||
130 | def _fileinfo(self, path): |
|
130 | def _fileinfo(self, path): | |
131 | if '_manifest' in self.__dict__: |
|
131 | if '_manifest' in self.__dict__: | |
132 | try: |
|
132 | try: | |
133 | return self._manifest[path], self._manifest.flags(path) |
|
133 | return self._manifest[path], self._manifest.flags(path) | |
134 | except KeyError: |
|
134 | except KeyError: | |
135 | raise error.LookupError(self._node, path, |
|
135 | raise error.LookupError(self._node, path, | |
136 | _('not found in manifest')) |
|
136 | _('not found in manifest')) | |
137 | if '_manifestdelta' in self.__dict__ or path in self.files(): |
|
137 | if '_manifestdelta' in self.__dict__ or path in self.files(): | |
138 | if path in self._manifestdelta: |
|
138 | if path in self._manifestdelta: | |
139 | return self._manifestdelta[path], self._manifestdelta.flags(path) |
|
139 | return self._manifestdelta[path], self._manifestdelta.flags(path) | |
140 | node, flag = self._repo.manifest.find(self._changeset[0], path) |
|
140 | node, flag = self._repo.manifest.find(self._changeset[0], path) | |
141 | if not node: |
|
141 | if not node: | |
142 | raise error.LookupError(self._node, path, |
|
142 | raise error.LookupError(self._node, path, | |
143 | _('not found in manifest')) |
|
143 | _('not found in manifest')) | |
144 |
|
144 | |||
145 | return node, flag |
|
145 | return node, flag | |
146 |
|
146 | |||
147 | def filenode(self, path): |
|
147 | def filenode(self, path): | |
148 | return self._fileinfo(path)[0] |
|
148 | return self._fileinfo(path)[0] | |
149 |
|
149 | |||
150 | def flags(self, path): |
|
150 | def flags(self, path): | |
151 | try: |
|
151 | try: | |
152 | return self._fileinfo(path)[1] |
|
152 | return self._fileinfo(path)[1] | |
153 | except error.LookupError: |
|
153 | except error.LookupError: | |
154 | return '' |
|
154 | return '' | |
155 |
|
155 | |||
156 | def filectx(self, path, fileid=None, filelog=None): |
|
156 | def filectx(self, path, fileid=None, filelog=None): | |
157 | """get a file context from this changeset""" |
|
157 | """get a file context from this changeset""" | |
158 | if fileid is None: |
|
158 | if fileid is None: | |
159 | fileid = self.filenode(path) |
|
159 | fileid = self.filenode(path) | |
160 | return filectx(self._repo, path, fileid=fileid, |
|
160 | return filectx(self._repo, path, fileid=fileid, | |
161 | changectx=self, filelog=filelog) |
|
161 | changectx=self, filelog=filelog) | |
162 |
|
162 | |||
163 | def ancestor(self, c2): |
|
163 | def ancestor(self, c2): | |
164 | """ |
|
164 | """ | |
165 | return the ancestor context of self and c2 |
|
165 | return the ancestor context of self and c2 | |
166 | """ |
|
166 | """ | |
167 | # deal with workingctxs |
|
167 | # deal with workingctxs | |
168 | n2 = c2._node |
|
168 | n2 = c2._node | |
169 | if n2 == None: |
|
169 | if n2 == None: | |
170 | n2 = c2._parents[0]._node |
|
170 | n2 = c2._parents[0]._node | |
171 | n = self._repo.changelog.ancestor(self._node, n2) |
|
171 | n = self._repo.changelog.ancestor(self._node, n2) | |
172 | return changectx(self._repo, n) |
|
172 | return changectx(self._repo, n) | |
173 |
|
173 | |||
174 | def walk(self, match): |
|
174 | def walk(self, match): | |
175 | fset = set(match.files()) |
|
175 | fset = set(match.files()) | |
176 | # for dirstate.walk, files=['.'] means "walk the whole tree". |
|
176 | # for dirstate.walk, files=['.'] means "walk the whole tree". | |
177 | # follow that here, too |
|
177 | # follow that here, too | |
178 | fset.discard('.') |
|
178 | fset.discard('.') | |
179 | for fn in self: |
|
179 | for fn in self: | |
180 | for ffn in fset: |
|
180 | for ffn in fset: | |
181 | # match if the file is the exact name or a directory |
|
181 | # match if the file is the exact name or a directory | |
182 | if ffn == fn or fn.startswith("%s/" % ffn): |
|
182 | if ffn == fn or fn.startswith("%s/" % ffn): | |
183 | fset.remove(ffn) |
|
183 | fset.remove(ffn) | |
184 | break |
|
184 | break | |
185 | if match(fn): |
|
185 | if match(fn): | |
186 | yield fn |
|
186 | yield fn | |
187 | for fn in sorted(fset): |
|
187 | for fn in sorted(fset): | |
188 | if match.bad(fn, 'No such file in rev ' + str(self)) and match(fn): |
|
188 | if match.bad(fn, 'No such file in rev ' + str(self)) and match(fn): | |
189 | yield fn |
|
189 | yield fn | |
190 |
|
190 | |||
191 | def sub(self, path): |
|
191 | def sub(self, path): | |
192 | return subrepo.subrepo(self, path) |
|
192 | return subrepo.subrepo(self, path) | |
193 |
|
193 | |||
194 | class filectx(object): |
|
194 | class filectx(object): | |
195 | """A filecontext object makes access to data related to a particular |
|
195 | """A filecontext object makes access to data related to a particular | |
196 | filerevision convenient.""" |
|
196 | filerevision convenient.""" | |
197 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
197 | def __init__(self, repo, path, changeid=None, fileid=None, | |
198 | filelog=None, changectx=None): |
|
198 | filelog=None, changectx=None): | |
199 | """changeid can be a changeset revision, node, or tag. |
|
199 | """changeid can be a changeset revision, node, or tag. | |
200 | fileid can be a file revision or node.""" |
|
200 | fileid can be a file revision or node.""" | |
201 | self._repo = repo |
|
201 | self._repo = repo | |
202 | self._path = path |
|
202 | self._path = path | |
203 |
|
203 | |||
204 | assert (changeid is not None |
|
204 | assert (changeid is not None | |
205 | or fileid is not None |
|
205 | or fileid is not None | |
206 | or changectx is not None), \ |
|
206 | or changectx is not None), \ | |
207 | ("bad args: changeid=%r, fileid=%r, changectx=%r" |
|
207 | ("bad args: changeid=%r, fileid=%r, changectx=%r" | |
208 | % (changeid, fileid, changectx)) |
|
208 | % (changeid, fileid, changectx)) | |
209 |
|
209 | |||
210 | if filelog: |
|
210 | if filelog: | |
211 | self._filelog = filelog |
|
211 | self._filelog = filelog | |
212 |
|
212 | |||
213 | if changeid is not None: |
|
213 | if changeid is not None: | |
214 | self._changeid = changeid |
|
214 | self._changeid = changeid | |
215 | if changectx is not None: |
|
215 | if changectx is not None: | |
216 | self._changectx = changectx |
|
216 | self._changectx = changectx | |
217 | if fileid is not None: |
|
217 | if fileid is not None: | |
218 | self._fileid = fileid |
|
218 | self._fileid = fileid | |
219 |
|
219 | |||
220 | @propertycache |
|
220 | @propertycache | |
221 | def _changectx(self): |
|
221 | def _changectx(self): | |
222 | return changectx(self._repo, self._changeid) |
|
222 | return changectx(self._repo, self._changeid) | |
223 |
|
223 | |||
224 | @propertycache |
|
224 | @propertycache | |
225 | def _filelog(self): |
|
225 | def _filelog(self): | |
226 | return self._repo.file(self._path) |
|
226 | return self._repo.file(self._path) | |
227 |
|
227 | |||
228 | @propertycache |
|
228 | @propertycache | |
229 | def _changeid(self): |
|
229 | def _changeid(self): | |
230 | if '_changectx' in self.__dict__: |
|
230 | if '_changectx' in self.__dict__: | |
231 | return self._changectx.rev() |
|
231 | return self._changectx.rev() | |
232 | else: |
|
232 | else: | |
233 | return self._filelog.linkrev(self._filerev) |
|
233 | return self._filelog.linkrev(self._filerev) | |
234 |
|
234 | |||
235 | @propertycache |
|
235 | @propertycache | |
236 | def _filenode(self): |
|
236 | def _filenode(self): | |
237 | if '_fileid' in self.__dict__: |
|
237 | if '_fileid' in self.__dict__: | |
238 | return self._filelog.lookup(self._fileid) |
|
238 | return self._filelog.lookup(self._fileid) | |
239 | else: |
|
239 | else: | |
240 | return self._changectx.filenode(self._path) |
|
240 | return self._changectx.filenode(self._path) | |
241 |
|
241 | |||
242 | @propertycache |
|
242 | @propertycache | |
243 | def _filerev(self): |
|
243 | def _filerev(self): | |
244 | return self._filelog.rev(self._filenode) |
|
244 | return self._filelog.rev(self._filenode) | |
245 |
|
245 | |||
246 | @propertycache |
|
246 | @propertycache | |
247 | def _repopath(self): |
|
247 | def _repopath(self): | |
248 | return self._path |
|
248 | return self._path | |
249 |
|
249 | |||
250 | def __nonzero__(self): |
|
250 | def __nonzero__(self): | |
251 | try: |
|
251 | try: | |
252 | self._filenode |
|
252 | self._filenode | |
253 | return True |
|
253 | return True | |
254 | except error.LookupError: |
|
254 | except error.LookupError: | |
255 | # file is missing |
|
255 | # file is missing | |
256 | return False |
|
256 | return False | |
257 |
|
257 | |||
258 | def __str__(self): |
|
258 | def __str__(self): | |
259 | return "%s@%s" % (self.path(), short(self.node())) |
|
259 | return "%s@%s" % (self.path(), short(self.node())) | |
260 |
|
260 | |||
261 | def __repr__(self): |
|
261 | def __repr__(self): | |
262 | return "<filectx %s>" % str(self) |
|
262 | return "<filectx %s>" % str(self) | |
263 |
|
263 | |||
264 | def __hash__(self): |
|
264 | def __hash__(self): | |
265 | try: |
|
265 | try: | |
266 | return hash((self._path, self._fileid)) |
|
266 | return hash((self._path, self._fileid)) | |
267 | except AttributeError: |
|
267 | except AttributeError: | |
268 | return id(self) |
|
268 | return id(self) | |
269 |
|
269 | |||
270 | def __eq__(self, other): |
|
270 | def __eq__(self, other): | |
271 | try: |
|
271 | try: | |
272 | return (self._path == other._path |
|
272 | return (self._path == other._path | |
273 | and self._fileid == other._fileid) |
|
273 | and self._fileid == other._fileid) | |
274 | except AttributeError: |
|
274 | except AttributeError: | |
275 | return False |
|
275 | return False | |
276 |
|
276 | |||
277 | def __ne__(self, other): |
|
277 | def __ne__(self, other): | |
278 | return not (self == other) |
|
278 | return not (self == other) | |
279 |
|
279 | |||
280 | def filectx(self, fileid): |
|
280 | def filectx(self, fileid): | |
281 | '''opens an arbitrary revision of the file without |
|
281 | '''opens an arbitrary revision of the file without | |
282 | opening a new filelog''' |
|
282 | opening a new filelog''' | |
283 | return filectx(self._repo, self._path, fileid=fileid, |
|
283 | return filectx(self._repo, self._path, fileid=fileid, | |
284 | filelog=self._filelog) |
|
284 | filelog=self._filelog) | |
285 |
|
285 | |||
286 | def filerev(self): return self._filerev |
|
286 | def filerev(self): return self._filerev | |
287 | def filenode(self): return self._filenode |
|
287 | def filenode(self): return self._filenode | |
288 | def flags(self): return self._changectx.flags(self._path) |
|
288 | def flags(self): return self._changectx.flags(self._path) | |
289 | def filelog(self): return self._filelog |
|
289 | def filelog(self): return self._filelog | |
290 |
|
290 | |||
291 | def rev(self): |
|
291 | def rev(self): | |
292 | if '_changectx' in self.__dict__: |
|
292 | if '_changectx' in self.__dict__: | |
293 | return self._changectx.rev() |
|
293 | return self._changectx.rev() | |
294 | if '_changeid' in self.__dict__: |
|
294 | if '_changeid' in self.__dict__: | |
295 | return self._changectx.rev() |
|
295 | return self._changectx.rev() | |
296 | return self._filelog.linkrev(self._filerev) |
|
296 | return self._filelog.linkrev(self._filerev) | |
297 |
|
297 | |||
298 | def linkrev(self): return self._filelog.linkrev(self._filerev) |
|
298 | def linkrev(self): return self._filelog.linkrev(self._filerev) | |
299 | def node(self): return self._changectx.node() |
|
299 | def node(self): return self._changectx.node() | |
300 | def hex(self): return hex(self.node()) |
|
300 | def hex(self): return hex(self.node()) | |
301 | def user(self): return self._changectx.user() |
|
301 | def user(self): return self._changectx.user() | |
302 | def date(self): return self._changectx.date() |
|
302 | def date(self): return self._changectx.date() | |
303 | def files(self): return self._changectx.files() |
|
303 | def files(self): return self._changectx.files() | |
304 | def description(self): return self._changectx.description() |
|
304 | def description(self): return self._changectx.description() | |
305 | def branch(self): return self._changectx.branch() |
|
305 | def branch(self): return self._changectx.branch() | |
306 | def extra(self): return self._changectx.extra() |
|
306 | def extra(self): return self._changectx.extra() | |
307 | def manifest(self): return self._changectx.manifest() |
|
307 | def manifest(self): return self._changectx.manifest() | |
308 | def changectx(self): return self._changectx |
|
308 | def changectx(self): return self._changectx | |
309 |
|
309 | |||
310 | def data(self): return self._filelog.read(self._filenode) |
|
310 | def data(self): return self._filelog.read(self._filenode) | |
311 | def path(self): return self._path |
|
311 | def path(self): return self._path | |
312 | def size(self): return self._filelog.size(self._filerev) |
|
312 | def size(self): return self._filelog.size(self._filerev) | |
313 |
|
313 | |||
314 | def cmp(self, text): return self._filelog.cmp(self._filenode, text) |
|
314 | def cmp(self, text): return self._filelog.cmp(self._filenode, text) | |
315 |
|
315 | |||
316 | def renamed(self): |
|
316 | def renamed(self): | |
317 | """check if file was actually renamed in this changeset revision |
|
317 | """check if file was actually renamed in this changeset revision | |
318 |
|
318 | |||
319 | If rename logged in file revision, we report copy for changeset only |
|
319 | If rename logged in file revision, we report copy for changeset only | |
320 | if file revisions linkrev points back to the changeset in question |
|
320 | if file revisions linkrev points back to the changeset in question | |
321 | or both changeset parents contain different file revisions. |
|
321 | or both changeset parents contain different file revisions. | |
322 | """ |
|
322 | """ | |
323 |
|
323 | |||
324 | renamed = self._filelog.renamed(self._filenode) |
|
324 | renamed = self._filelog.renamed(self._filenode) | |
325 | if not renamed: |
|
325 | if not renamed: | |
326 | return renamed |
|
326 | return renamed | |
327 |
|
327 | |||
328 | if self.rev() == self.linkrev(): |
|
328 | if self.rev() == self.linkrev(): | |
329 | return renamed |
|
329 | return renamed | |
330 |
|
330 | |||
331 | name = self.path() |
|
331 | name = self.path() | |
332 | fnode = self._filenode |
|
332 | fnode = self._filenode | |
333 | for p in self._changectx.parents(): |
|
333 | for p in self._changectx.parents(): | |
334 | try: |
|
334 | try: | |
335 | if fnode == p.filenode(name): |
|
335 | if fnode == p.filenode(name): | |
336 | return None |
|
336 | return None | |
337 | except error.LookupError: |
|
337 | except error.LookupError: | |
338 | pass |
|
338 | pass | |
339 | return renamed |
|
339 | return renamed | |
340 |
|
340 | |||
341 | def parents(self): |
|
341 | def parents(self): | |
342 | p = self._path |
|
342 | p = self._path | |
343 | fl = self._filelog |
|
343 | fl = self._filelog | |
344 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] |
|
344 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] | |
345 |
|
345 | |||
346 | r = self._filelog.renamed(self._filenode) |
|
346 | r = self._filelog.renamed(self._filenode) | |
347 | if r: |
|
347 | if r: | |
348 | pl[0] = (r[0], r[1], None) |
|
348 | pl[0] = (r[0], r[1], None) | |
349 |
|
349 | |||
350 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
350 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
351 | for p,n,l in pl if n != nullid] |
|
351 | for p,n,l in pl if n != nullid] | |
352 |
|
352 | |||
353 | def children(self): |
|
353 | def children(self): | |
354 | # hard for renames |
|
354 | # hard for renames | |
355 | c = self._filelog.children(self._filenode) |
|
355 | c = self._filelog.children(self._filenode) | |
356 | return [filectx(self._repo, self._path, fileid=x, |
|
356 | return [filectx(self._repo, self._path, fileid=x, | |
357 | filelog=self._filelog) for x in c] |
|
357 | filelog=self._filelog) for x in c] | |
358 |
|
358 | |||
359 | def annotate(self, follow=False, linenumber=None): |
|
359 | def annotate(self, follow=False, linenumber=None): | |
360 | '''returns a list of tuples of (ctx, line) for each line |
|
360 | '''returns a list of tuples of (ctx, line) for each line | |
361 | in the file, where ctx is the filectx of the node where |
|
361 | in the file, where ctx is the filectx of the node where | |
362 | that line was last changed. |
|
362 | that line was last changed. | |
363 | This returns tuples of ((ctx, linenumber), line) for each line, |
|
363 | This returns tuples of ((ctx, linenumber), line) for each line, | |
364 | if "linenumber" parameter is NOT "None". |
|
364 | if "linenumber" parameter is NOT "None". | |
365 | In such tuples, linenumber means one at the first appearance |
|
365 | In such tuples, linenumber means one at the first appearance | |
366 | in the managed file. |
|
366 | in the managed file. | |
367 | To reduce annotation cost, |
|
367 | To reduce annotation cost, | |
368 | this returns fixed value(False is used) as linenumber, |
|
368 | this returns fixed value(False is used) as linenumber, | |
369 | if "linenumber" parameter is "False".''' |
|
369 | if "linenumber" parameter is "False".''' | |
370 |
|
370 | |||
371 | def decorate_compat(text, rev): |
|
371 | def decorate_compat(text, rev): | |
372 | return ([rev] * len(text.splitlines()), text) |
|
372 | return ([rev] * len(text.splitlines()), text) | |
373 |
|
373 | |||
374 | def without_linenumber(text, rev): |
|
374 | def without_linenumber(text, rev): | |
375 | return ([(rev, False)] * len(text.splitlines()), text) |
|
375 | return ([(rev, False)] * len(text.splitlines()), text) | |
376 |
|
376 | |||
377 | def with_linenumber(text, rev): |
|
377 | def with_linenumber(text, rev): | |
378 | size = len(text.splitlines()) |
|
378 | size = len(text.splitlines()) | |
379 | return ([(rev, i) for i in xrange(1, size + 1)], text) |
|
379 | return ([(rev, i) for i in xrange(1, size + 1)], text) | |
380 |
|
380 | |||
381 | decorate = (((linenumber is None) and decorate_compat) or |
|
381 | decorate = (((linenumber is None) and decorate_compat) or | |
382 | (linenumber and with_linenumber) or |
|
382 | (linenumber and with_linenumber) or | |
383 | without_linenumber) |
|
383 | without_linenumber) | |
384 |
|
384 | |||
385 | def pair(parent, child): |
|
385 | def pair(parent, child): | |
386 | for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): |
|
386 | for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): | |
387 | child[0][b1:b2] = parent[0][a1:a2] |
|
387 | child[0][b1:b2] = parent[0][a1:a2] | |
388 | return child |
|
388 | return child | |
389 |
|
389 | |||
390 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
|
390 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) | |
391 | def getctx(path, fileid): |
|
391 | def getctx(path, fileid): | |
392 | log = path == self._path and self._filelog or getlog(path) |
|
392 | log = path == self._path and self._filelog or getlog(path) | |
393 | return filectx(self._repo, path, fileid=fileid, filelog=log) |
|
393 | return filectx(self._repo, path, fileid=fileid, filelog=log) | |
394 | getctx = util.lrucachefunc(getctx) |
|
394 | getctx = util.lrucachefunc(getctx) | |
395 |
|
395 | |||
396 | def parents(f): |
|
396 | def parents(f): | |
397 | # we want to reuse filectx objects as much as possible |
|
397 | # we want to reuse filectx objects as much as possible | |
398 | p = f._path |
|
398 | p = f._path | |
399 | if f._filerev is None: # working dir |
|
399 | if f._filerev is None: # working dir | |
400 | pl = [(n.path(), n.filerev()) for n in f.parents()] |
|
400 | pl = [(n.path(), n.filerev()) for n in f.parents()] | |
401 | else: |
|
401 | else: | |
402 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] |
|
402 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] | |
403 |
|
403 | |||
404 | if follow: |
|
404 | if follow: | |
405 | r = f.renamed() |
|
405 | r = f.renamed() | |
406 | if r: |
|
406 | if r: | |
407 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) |
|
407 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) | |
408 |
|
408 | |||
409 | return [getctx(p, n) for p, n in pl if n != nullrev] |
|
409 | return [getctx(p, n) for p, n in pl if n != nullrev] | |
410 |
|
410 | |||
411 | # use linkrev to find the first changeset where self appeared |
|
411 | # use linkrev to find the first changeset where self appeared | |
412 | if self.rev() != self.linkrev(): |
|
412 | if self.rev() != self.linkrev(): | |
413 | base = self.filectx(self.filerev()) |
|
413 | base = self.filectx(self.filerev()) | |
414 | else: |
|
414 | else: | |
415 | base = self |
|
415 | base = self | |
416 |
|
416 | |||
417 | # find all ancestors |
|
417 | # find all ancestors | |
418 | needed = {base: 1} |
|
418 | needed = {base: 1} | |
419 | visit = [base] |
|
419 | visit = [base] | |
420 | files = [base._path] |
|
420 | files = [base._path] | |
421 | while visit: |
|
421 | while visit: | |
422 | f = visit.pop(0) |
|
422 | f = visit.pop(0) | |
423 | for p in parents(f): |
|
423 | for p in parents(f): | |
424 | if p not in needed: |
|
424 | if p not in needed: | |
425 | needed[p] = 1 |
|
425 | needed[p] = 1 | |
426 | visit.append(p) |
|
426 | visit.append(p) | |
427 | if p._path not in files: |
|
427 | if p._path not in files: | |
428 | files.append(p._path) |
|
428 | files.append(p._path) | |
429 | else: |
|
429 | else: | |
430 | # count how many times we'll use this |
|
430 | # count how many times we'll use this | |
431 | needed[p] += 1 |
|
431 | needed[p] += 1 | |
432 |
|
432 | |||
433 | # sort by revision (per file) which is a topological order |
|
433 | # sort by revision (per file) which is a topological order | |
434 | visit = [] |
|
434 | visit = [] | |
435 | for f in files: |
|
435 | for f in files: | |
436 | visit.extend(n for n in needed if n._path == f) |
|
436 | visit.extend(n for n in needed if n._path == f) | |
437 |
|
437 | |||
438 | hist = {} |
|
438 | hist = {} | |
439 | for f in sorted(visit, key=lambda x: x.rev()): |
|
439 | for f in sorted(visit, key=lambda x: x.rev()): | |
440 | curr = decorate(f.data(), f) |
|
440 | curr = decorate(f.data(), f) | |
441 | for p in parents(f): |
|
441 | for p in parents(f): | |
442 | curr = pair(hist[p], curr) |
|
442 | curr = pair(hist[p], curr) | |
443 | # trim the history of unneeded revs |
|
443 | # trim the history of unneeded revs | |
444 | needed[p] -= 1 |
|
444 | needed[p] -= 1 | |
445 | if not needed[p]: |
|
445 | if not needed[p]: | |
446 | del hist[p] |
|
446 | del hist[p] | |
447 | hist[f] = curr |
|
447 | hist[f] = curr | |
448 |
|
448 | |||
449 | return zip(hist[f][0], hist[f][1].splitlines(True)) |
|
449 | return zip(hist[f][0], hist[f][1].splitlines(True)) | |
450 |
|
450 | |||
451 | def ancestor(self, fc2): |
|
451 | def ancestor(self, fc2): | |
452 | """ |
|
452 | """ | |
453 | find the common ancestor file context, if any, of self, and fc2 |
|
453 | find the common ancestor file context, if any, of self, and fc2 | |
454 | """ |
|
454 | """ | |
455 |
|
455 | |||
456 | actx = self.changectx().ancestor(fc2.changectx()) |
|
456 | actx = self.changectx().ancestor(fc2.changectx()) | |
457 |
|
457 | |||
458 | # the trivial case: changesets are unrelated, files must be too |
|
458 | # the trivial case: changesets are unrelated, files must be too | |
459 | if not actx: |
|
459 | if not actx: | |
460 | return None |
|
460 | return None | |
461 |
|
461 | |||
462 | # the easy case: no (relevant) renames |
|
462 | # the easy case: no (relevant) renames | |
463 | if fc2.path() == self.path() and self.path() in actx: |
|
463 | if fc2.path() == self.path() and self.path() in actx: | |
464 | return actx[self.path()] |
|
464 | return actx[self.path()] | |
465 | acache = {} |
|
465 | acache = {} | |
466 |
|
466 | |||
467 | # prime the ancestor cache for the working directory |
|
467 | # prime the ancestor cache for the working directory | |
468 | for c in (self, fc2): |
|
468 | for c in (self, fc2): | |
469 | if c._filerev is None: |
|
469 | if c._filerev is None: | |
470 | pl = [(n.path(), n.filenode()) for n in c.parents()] |
|
470 | pl = [(n.path(), n.filenode()) for n in c.parents()] | |
471 | acache[(c._path, None)] = pl |
|
471 | acache[(c._path, None)] = pl | |
472 |
|
472 | |||
473 | flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} |
|
473 | flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} | |
474 | def parents(vertex): |
|
474 | def parents(vertex): | |
475 | if vertex in acache: |
|
475 | if vertex in acache: | |
476 | return acache[vertex] |
|
476 | return acache[vertex] | |
477 | f, n = vertex |
|
477 | f, n = vertex | |
478 | if f not in flcache: |
|
478 | if f not in flcache: | |
479 | flcache[f] = self._repo.file(f) |
|
479 | flcache[f] = self._repo.file(f) | |
480 | fl = flcache[f] |
|
480 | fl = flcache[f] | |
481 | pl = [(f, p) for p in fl.parents(n) if p != nullid] |
|
481 | pl = [(f, p) for p in fl.parents(n) if p != nullid] | |
482 | re = fl.renamed(n) |
|
482 | re = fl.renamed(n) | |
483 | if re: |
|
483 | if re: | |
484 | pl.append(re) |
|
484 | pl.append(re) | |
485 | acache[vertex] = pl |
|
485 | acache[vertex] = pl | |
486 | return pl |
|
486 | return pl | |
487 |
|
487 | |||
488 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) |
|
488 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) | |
489 | v = ancestor.ancestor(a, b, parents) |
|
489 | v = ancestor.ancestor(a, b, parents) | |
490 | if v: |
|
490 | if v: | |
491 | f, n = v |
|
491 | f, n = v | |
492 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) |
|
492 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) | |
493 |
|
493 | |||
494 | return None |
|
494 | return None | |
495 |
|
495 | |||
496 | class workingctx(changectx): |
|
496 | class workingctx(changectx): | |
497 | """A workingctx object makes access to data related to |
|
497 | """A workingctx object makes access to data related to | |
498 | the current working directory convenient. |
|
498 | the current working directory convenient. | |
499 | parents - a pair of parent nodeids, or None to use the dirstate. |
|
499 | parents - a pair of parent nodeids, or None to use the dirstate. | |
500 | date - any valid date string or (unixtime, offset), or None. |
|
500 | date - any valid date string or (unixtime, offset), or None. | |
501 | user - username string, or None. |
|
501 | user - username string, or None. | |
502 | extra - a dictionary of extra values, or None. |
|
502 | extra - a dictionary of extra values, or None. | |
503 | changes - a list of file lists as returned by localrepo.status() |
|
503 | changes - a list of file lists as returned by localrepo.status() | |
504 | or None to use the repository status. |
|
504 | or None to use the repository status. | |
505 | """ |
|
505 | """ | |
506 | def __init__(self, repo, parents=None, text="", user=None, date=None, |
|
506 | def __init__(self, repo, parents=None, text="", user=None, date=None, | |
507 | extra=None, changes=None): |
|
507 | extra=None, changes=None): | |
508 | self._repo = repo |
|
508 | self._repo = repo | |
509 | self._rev = None |
|
509 | self._rev = None | |
510 | self._node = None |
|
510 | self._node = None | |
511 | self._text = text |
|
511 | self._text = text | |
512 | if date: |
|
512 | if date: | |
513 | self._date = util.parsedate(date) |
|
513 | self._date = util.parsedate(date) | |
514 | if user: |
|
514 | if user: | |
515 | self._user = user |
|
515 | self._user = user | |
516 | if parents: |
|
516 | if parents: | |
517 | self._parents = [changectx(self._repo, p) for p in parents] |
|
517 | self._parents = [changectx(self._repo, p) for p in parents] | |
518 | if changes: |
|
518 | if changes: | |
519 | self._status = list(changes) |
|
519 | self._status = list(changes) | |
520 |
|
520 | |||
521 | self._extra = {} |
|
521 | self._extra = {} | |
522 | if extra: |
|
522 | if extra: | |
523 | self._extra = extra.copy() |
|
523 | self._extra = extra.copy() | |
524 | if 'branch' not in self._extra: |
|
524 | if 'branch' not in self._extra: | |
525 | branch = self._repo.dirstate.branch() |
|
525 | branch = self._repo.dirstate.branch() | |
526 | try: |
|
526 | try: | |
527 | branch = branch.decode('UTF-8').encode('UTF-8') |
|
527 | branch = branch.decode('UTF-8').encode('UTF-8') | |
528 | except UnicodeDecodeError: |
|
528 | except UnicodeDecodeError: | |
529 | raise util.Abort(_('branch name not in UTF-8!')) |
|
529 | raise util.Abort(_('branch name not in UTF-8!')) | |
530 | self._extra['branch'] = branch |
|
530 | self._extra['branch'] = branch | |
531 | if self._extra['branch'] == '': |
|
531 | if self._extra['branch'] == '': | |
532 | self._extra['branch'] = 'default' |
|
532 | self._extra['branch'] = 'default' | |
533 |
|
533 | |||
534 | def __str__(self): |
|
534 | def __str__(self): | |
535 | return str(self._parents[0]) + "+" |
|
535 | return str(self._parents[0]) + "+" | |
536 |
|
536 | |||
537 | def __nonzero__(self): |
|
537 | def __nonzero__(self): | |
538 | return True |
|
538 | return True | |
539 |
|
539 | |||
540 | def __contains__(self, key): |
|
540 | def __contains__(self, key): | |
541 | return self._repo.dirstate[key] not in "?r" |
|
541 | return self._repo.dirstate[key] not in "?r" | |
542 |
|
542 | |||
543 | @propertycache |
|
543 | @propertycache | |
544 | def _manifest(self): |
|
544 | def _manifest(self): | |
545 | """generate a manifest corresponding to the working directory""" |
|
545 | """generate a manifest corresponding to the working directory""" | |
546 |
|
546 | |||
547 | man = self._parents[0].manifest().copy() |
|
547 | man = self._parents[0].manifest().copy() | |
548 | copied = self._repo.dirstate.copies() |
|
548 | copied = self._repo.dirstate.copies() | |
549 | cf = lambda x: man.flags(copied.get(x, x)) |
|
549 | cf = lambda x: man.flags(copied.get(x, x)) | |
550 | ff = self._repo.dirstate.flagfunc(cf) |
|
550 | ff = self._repo.dirstate.flagfunc(cf) | |
551 | modified, added, removed, deleted, unknown = self._status[:5] |
|
551 | modified, added, removed, deleted, unknown = self._status[:5] | |
552 | for i, l in (("a", added), ("m", modified), ("u", unknown)): |
|
552 | for i, l in (("a", added), ("m", modified), ("u", unknown)): | |
553 | for f in l: |
|
553 | for f in l: | |
554 | man[f] = man.get(copied.get(f, f), nullid) + i |
|
554 | man[f] = man.get(copied.get(f, f), nullid) + i | |
555 | try: |
|
555 | try: | |
556 | man.set(f, ff(f)) |
|
556 | man.set(f, ff(f)) | |
557 | except OSError: |
|
557 | except OSError: | |
558 | pass |
|
558 | pass | |
559 |
|
559 | |||
560 | for f in deleted + removed: |
|
560 | for f in deleted + removed: | |
561 | if f in man: |
|
561 | if f in man: | |
562 | del man[f] |
|
562 | del man[f] | |
563 |
|
563 | |||
564 | return man |
|
564 | return man | |
565 |
|
565 | |||
566 | @propertycache |
|
566 | @propertycache | |
567 | def _status(self): |
|
567 | def _status(self): | |
568 | return self._repo.status(unknown=True) |
|
568 | return self._repo.status(unknown=True) | |
569 |
|
569 | |||
570 | @propertycache |
|
570 | @propertycache | |
571 | def _user(self): |
|
571 | def _user(self): | |
572 | return self._repo.ui.username() |
|
572 | return self._repo.ui.username() | |
573 |
|
573 | |||
574 | @propertycache |
|
574 | @propertycache | |
575 | def _date(self): |
|
575 | def _date(self): | |
576 | return util.makedate() |
|
576 | return util.makedate() | |
577 |
|
577 | |||
578 | @propertycache |
|
578 | @propertycache | |
579 | def _parents(self): |
|
579 | def _parents(self): | |
580 | p = self._repo.dirstate.parents() |
|
580 | p = self._repo.dirstate.parents() | |
581 | if p[1] == nullid: |
|
581 | if p[1] == nullid: | |
582 | p = p[:-1] |
|
582 | p = p[:-1] | |
583 | self._parents = [changectx(self._repo, x) for x in p] |
|
583 | self._parents = [changectx(self._repo, x) for x in p] | |
584 | return self._parents |
|
584 | return self._parents | |
585 |
|
585 | |||
586 | def manifest(self): return self._manifest |
|
586 | def manifest(self): return self._manifest | |
587 |
|
587 | |||
588 | def user(self): return self._user or self._repo.ui.username() |
|
588 | def user(self): return self._user or self._repo.ui.username() | |
589 | def date(self): return self._date |
|
589 | def date(self): return self._date | |
590 | def description(self): return self._text |
|
590 | def description(self): return self._text | |
591 | def files(self): |
|
591 | def files(self): | |
592 | return sorted(self._status[0] + self._status[1] + self._status[2]) |
|
592 | return sorted(self._status[0] + self._status[1] + self._status[2]) | |
593 |
|
593 | |||
594 | def modified(self): return self._status[0] |
|
594 | def modified(self): return self._status[0] | |
595 | def added(self): return self._status[1] |
|
595 | def added(self): return self._status[1] | |
596 | def removed(self): return self._status[2] |
|
596 | def removed(self): return self._status[2] | |
597 | def deleted(self): return self._status[3] |
|
597 | def deleted(self): return self._status[3] | |
598 | def unknown(self): return self._status[4] |
|
598 | def unknown(self): return self._status[4] | |
599 | def clean(self): return self._status[5] |
|
599 | def clean(self): return self._status[5] | |
600 | def branch(self): return self._extra['branch'] |
|
600 | def branch(self): return self._extra['branch'] | |
601 | def extra(self): return self._extra |
|
601 | def extra(self): return self._extra | |
602 |
|
602 | |||
603 | def tags(self): |
|
603 | def tags(self): | |
604 | t = [] |
|
604 | t = [] | |
605 | [t.extend(p.tags()) for p in self.parents()] |
|
605 | [t.extend(p.tags()) for p in self.parents()] | |
606 | return t |
|
606 | return t | |
607 |
|
607 | |||
608 | def children(self): |
|
608 | def children(self): | |
609 | return [] |
|
609 | return [] | |
610 |
|
610 | |||
611 | def flags(self, path): |
|
611 | def flags(self, path): | |
612 | if '_manifest' in self.__dict__: |
|
612 | if '_manifest' in self.__dict__: | |
613 | try: |
|
613 | try: | |
614 | return self._manifest.flags(path) |
|
614 | return self._manifest.flags(path) | |
615 | except KeyError: |
|
615 | except KeyError: | |
616 | return '' |
|
616 | return '' | |
617 |
|
617 | |||
618 | pnode = self._parents[0].changeset()[0] |
|
618 | pnode = self._parents[0].changeset()[0] | |
619 | orig = self._repo.dirstate.copies().get(path, path) |
|
619 | orig = self._repo.dirstate.copies().get(path, path) | |
620 | node, flag = self._repo.manifest.find(pnode, orig) |
|
620 | node, flag = self._repo.manifest.find(pnode, orig) | |
621 | try: |
|
621 | try: | |
622 | ff = self._repo.dirstate.flagfunc(lambda x: flag or '') |
|
622 | ff = self._repo.dirstate.flagfunc(lambda x: flag or '') | |
623 | return ff(path) |
|
623 | return ff(path) | |
624 | except OSError: |
|
624 | except OSError: | |
625 | pass |
|
625 | pass | |
626 |
|
626 | |||
627 | if not node or path in self.deleted() or path in self.removed(): |
|
627 | if not node or path in self.deleted() or path in self.removed(): | |
628 | return '' |
|
628 | return '' | |
629 | return flag |
|
629 | return flag | |
630 |
|
630 | |||
631 | def filectx(self, path, filelog=None): |
|
631 | def filectx(self, path, filelog=None): | |
632 | """get a file context from the working directory""" |
|
632 | """get a file context from the working directory""" | |
633 | return workingfilectx(self._repo, path, workingctx=self, |
|
633 | return workingfilectx(self._repo, path, workingctx=self, | |
634 | filelog=filelog) |
|
634 | filelog=filelog) | |
635 |
|
635 | |||
636 | def ancestor(self, c2): |
|
636 | def ancestor(self, c2): | |
637 | """return the ancestor context of self and c2""" |
|
637 | """return the ancestor context of self and c2""" | |
638 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
638 | return self._parents[0].ancestor(c2) # punt on two parents for now | |
639 |
|
639 | |||
640 | def walk(self, match): |
|
640 | def walk(self, match): | |
641 |
return sorted(self._repo.dirstate.walk(match, |
|
641 | return sorted(self._repo.dirstate.walk(match, self.substate.keys(), | |
|
642 | True, False)) | |||
642 |
|
643 | |||
643 | def dirty(self, missing=False): |
|
644 | def dirty(self, missing=False): | |
644 | "check whether a working directory is modified" |
|
645 | "check whether a working directory is modified" | |
645 |
|
646 | |||
646 | return (self.p2() or self.branch() != self.p1().branch() or |
|
647 | return (self.p2() or self.branch() != self.p1().branch() or | |
647 | self.modified() or self.added() or self.removed() or |
|
648 | self.modified() or self.added() or self.removed() or | |
648 | (missing and self.deleted())) |
|
649 | (missing and self.deleted())) | |
649 |
|
650 | |||
650 | class workingfilectx(filectx): |
|
651 | class workingfilectx(filectx): | |
651 | """A workingfilectx object makes access to data related to a particular |
|
652 | """A workingfilectx object makes access to data related to a particular | |
652 | file in the working directory convenient.""" |
|
653 | file in the working directory convenient.""" | |
653 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
654 | def __init__(self, repo, path, filelog=None, workingctx=None): | |
654 | """changeid can be a changeset revision, node, or tag. |
|
655 | """changeid can be a changeset revision, node, or tag. | |
655 | fileid can be a file revision or node.""" |
|
656 | fileid can be a file revision or node.""" | |
656 | self._repo = repo |
|
657 | self._repo = repo | |
657 | self._path = path |
|
658 | self._path = path | |
658 | self._changeid = None |
|
659 | self._changeid = None | |
659 | self._filerev = self._filenode = None |
|
660 | self._filerev = self._filenode = None | |
660 |
|
661 | |||
661 | if filelog: |
|
662 | if filelog: | |
662 | self._filelog = filelog |
|
663 | self._filelog = filelog | |
663 | if workingctx: |
|
664 | if workingctx: | |
664 | self._changectx = workingctx |
|
665 | self._changectx = workingctx | |
665 |
|
666 | |||
666 | @propertycache |
|
667 | @propertycache | |
667 | def _changectx(self): |
|
668 | def _changectx(self): | |
668 | return workingctx(self._repo) |
|
669 | return workingctx(self._repo) | |
669 |
|
670 | |||
670 | def __nonzero__(self): |
|
671 | def __nonzero__(self): | |
671 | return True |
|
672 | return True | |
672 |
|
673 | |||
673 | def __str__(self): |
|
674 | def __str__(self): | |
674 | return "%s@%s" % (self.path(), self._changectx) |
|
675 | return "%s@%s" % (self.path(), self._changectx) | |
675 |
|
676 | |||
676 | def data(self): return self._repo.wread(self._path) |
|
677 | def data(self): return self._repo.wread(self._path) | |
677 | def renamed(self): |
|
678 | def renamed(self): | |
678 | rp = self._repo.dirstate.copied(self._path) |
|
679 | rp = self._repo.dirstate.copied(self._path) | |
679 | if not rp: |
|
680 | if not rp: | |
680 | return None |
|
681 | return None | |
681 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
682 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) | |
682 |
|
683 | |||
683 | def parents(self): |
|
684 | def parents(self): | |
684 | '''return parent filectxs, following copies if necessary''' |
|
685 | '''return parent filectxs, following copies if necessary''' | |
685 | def filenode(ctx, path): |
|
686 | def filenode(ctx, path): | |
686 | return ctx._manifest.get(path, nullid) |
|
687 | return ctx._manifest.get(path, nullid) | |
687 |
|
688 | |||
688 | path = self._path |
|
689 | path = self._path | |
689 | fl = self._filelog |
|
690 | fl = self._filelog | |
690 | pcl = self._changectx._parents |
|
691 | pcl = self._changectx._parents | |
691 | renamed = self.renamed() |
|
692 | renamed = self.renamed() | |
692 |
|
693 | |||
693 | if renamed: |
|
694 | if renamed: | |
694 | pl = [renamed + (None,)] |
|
695 | pl = [renamed + (None,)] | |
695 | else: |
|
696 | else: | |
696 | pl = [(path, filenode(pcl[0], path), fl)] |
|
697 | pl = [(path, filenode(pcl[0], path), fl)] | |
697 |
|
698 | |||
698 | for pc in pcl[1:]: |
|
699 | for pc in pcl[1:]: | |
699 | pl.append((path, filenode(pc, path), fl)) |
|
700 | pl.append((path, filenode(pc, path), fl)) | |
700 |
|
701 | |||
701 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
702 | return [filectx(self._repo, p, fileid=n, filelog=l) | |
702 | for p,n,l in pl if n != nullid] |
|
703 | for p,n,l in pl if n != nullid] | |
703 |
|
704 | |||
704 | def children(self): |
|
705 | def children(self): | |
705 | return [] |
|
706 | return [] | |
706 |
|
707 | |||
707 | def size(self): return os.stat(self._repo.wjoin(self._path)).st_size |
|
708 | def size(self): return os.stat(self._repo.wjoin(self._path)).st_size | |
708 | def date(self): |
|
709 | def date(self): | |
709 | t, tz = self._changectx.date() |
|
710 | t, tz = self._changectx.date() | |
710 | try: |
|
711 | try: | |
711 | return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) |
|
712 | return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) | |
712 | except OSError, err: |
|
713 | except OSError, err: | |
713 | if err.errno != errno.ENOENT: raise |
|
714 | if err.errno != errno.ENOENT: raise | |
714 | return (t, tz) |
|
715 | return (t, tz) | |
715 |
|
716 | |||
716 | def cmp(self, text): return self._repo.wread(self._path) == text |
|
717 | def cmp(self, text): return self._repo.wread(self._path) == text | |
717 |
|
718 | |||
718 | class memctx(object): |
|
719 | class memctx(object): | |
719 | """Use memctx to perform in-memory commits via localrepo.commitctx(). |
|
720 | """Use memctx to perform in-memory commits via localrepo.commitctx(). | |
720 |
|
721 | |||
721 | Revision information is supplied at initialization time while |
|
722 | Revision information is supplied at initialization time while | |
722 | related files data and is made available through a callback |
|
723 | related files data and is made available through a callback | |
723 | mechanism. 'repo' is the current localrepo, 'parents' is a |
|
724 | mechanism. 'repo' is the current localrepo, 'parents' is a | |
724 | sequence of two parent revisions identifiers (pass None for every |
|
725 | sequence of two parent revisions identifiers (pass None for every | |
725 | missing parent), 'text' is the commit message and 'files' lists |
|
726 | missing parent), 'text' is the commit message and 'files' lists | |
726 | names of files touched by the revision (normalized and relative to |
|
727 | names of files touched by the revision (normalized and relative to | |
727 | repository root). |
|
728 | repository root). | |
728 |
|
729 | |||
729 | filectxfn(repo, memctx, path) is a callable receiving the |
|
730 | filectxfn(repo, memctx, path) is a callable receiving the | |
730 | repository, the current memctx object and the normalized path of |
|
731 | repository, the current memctx object and the normalized path of | |
731 | requested file, relative to repository root. It is fired by the |
|
732 | requested file, relative to repository root. It is fired by the | |
732 | commit function for every file in 'files', but calls order is |
|
733 | commit function for every file in 'files', but calls order is | |
733 | undefined. If the file is available in the revision being |
|
734 | undefined. If the file is available in the revision being | |
734 | committed (updated or added), filectxfn returns a memfilectx |
|
735 | committed (updated or added), filectxfn returns a memfilectx | |
735 | object. If the file was removed, filectxfn raises an |
|
736 | object. If the file was removed, filectxfn raises an | |
736 | IOError. Moved files are represented by marking the source file |
|
737 | IOError. Moved files are represented by marking the source file | |
737 | removed and the new file added with copy information (see |
|
738 | removed and the new file added with copy information (see | |
738 | memfilectx). |
|
739 | memfilectx). | |
739 |
|
740 | |||
740 | user receives the committer name and defaults to current |
|
741 | user receives the committer name and defaults to current | |
741 | repository username, date is the commit date in any format |
|
742 | repository username, date is the commit date in any format | |
742 | supported by util.parsedate() and defaults to current date, extra |
|
743 | supported by util.parsedate() and defaults to current date, extra | |
743 | is a dictionary of metadata or is left empty. |
|
744 | is a dictionary of metadata or is left empty. | |
744 | """ |
|
745 | """ | |
745 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
746 | def __init__(self, repo, parents, text, files, filectxfn, user=None, | |
746 | date=None, extra=None): |
|
747 | date=None, extra=None): | |
747 | self._repo = repo |
|
748 | self._repo = repo | |
748 | self._rev = None |
|
749 | self._rev = None | |
749 | self._node = None |
|
750 | self._node = None | |
750 | self._text = text |
|
751 | self._text = text | |
751 | self._date = date and util.parsedate(date) or util.makedate() |
|
752 | self._date = date and util.parsedate(date) or util.makedate() | |
752 | self._user = user |
|
753 | self._user = user | |
753 | parents = [(p or nullid) for p in parents] |
|
754 | parents = [(p or nullid) for p in parents] | |
754 | p1, p2 = parents |
|
755 | p1, p2 = parents | |
755 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
|
756 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] | |
756 | files = sorted(set(files)) |
|
757 | files = sorted(set(files)) | |
757 | self._status = [files, [], [], [], []] |
|
758 | self._status = [files, [], [], [], []] | |
758 | self._filectxfn = filectxfn |
|
759 | self._filectxfn = filectxfn | |
759 |
|
760 | |||
760 | self._extra = extra and extra.copy() or {} |
|
761 | self._extra = extra and extra.copy() or {} | |
761 | if 'branch' not in self._extra: |
|
762 | if 'branch' not in self._extra: | |
762 | self._extra['branch'] = 'default' |
|
763 | self._extra['branch'] = 'default' | |
763 | elif self._extra.get('branch') == '': |
|
764 | elif self._extra.get('branch') == '': | |
764 | self._extra['branch'] = 'default' |
|
765 | self._extra['branch'] = 'default' | |
765 |
|
766 | |||
766 | def __str__(self): |
|
767 | def __str__(self): | |
767 | return str(self._parents[0]) + "+" |
|
768 | return str(self._parents[0]) + "+" | |
768 |
|
769 | |||
769 | def __int__(self): |
|
770 | def __int__(self): | |
770 | return self._rev |
|
771 | return self._rev | |
771 |
|
772 | |||
772 | def __nonzero__(self): |
|
773 | def __nonzero__(self): | |
773 | return True |
|
774 | return True | |
774 |
|
775 | |||
775 | def __getitem__(self, key): |
|
776 | def __getitem__(self, key): | |
776 | return self.filectx(key) |
|
777 | return self.filectx(key) | |
777 |
|
778 | |||
778 | def p1(self): return self._parents[0] |
|
779 | def p1(self): return self._parents[0] | |
779 | def p2(self): return self._parents[1] |
|
780 | def p2(self): return self._parents[1] | |
780 |
|
781 | |||
781 | def user(self): return self._user or self._repo.ui.username() |
|
782 | def user(self): return self._user or self._repo.ui.username() | |
782 | def date(self): return self._date |
|
783 | def date(self): return self._date | |
783 | def description(self): return self._text |
|
784 | def description(self): return self._text | |
784 | def files(self): return self.modified() |
|
785 | def files(self): return self.modified() | |
785 | def modified(self): return self._status[0] |
|
786 | def modified(self): return self._status[0] | |
786 | def added(self): return self._status[1] |
|
787 | def added(self): return self._status[1] | |
787 | def removed(self): return self._status[2] |
|
788 | def removed(self): return self._status[2] | |
788 | def deleted(self): return self._status[3] |
|
789 | def deleted(self): return self._status[3] | |
789 | def unknown(self): return self._status[4] |
|
790 | def unknown(self): return self._status[4] | |
790 | def clean(self): return self._status[5] |
|
791 | def clean(self): return self._status[5] | |
791 | def branch(self): return self._extra['branch'] |
|
792 | def branch(self): return self._extra['branch'] | |
792 | def extra(self): return self._extra |
|
793 | def extra(self): return self._extra | |
793 | def flags(self, f): return self[f].flags() |
|
794 | def flags(self, f): return self[f].flags() | |
794 |
|
795 | |||
795 | def parents(self): |
|
796 | def parents(self): | |
796 | """return contexts for each parent changeset""" |
|
797 | """return contexts for each parent changeset""" | |
797 | return self._parents |
|
798 | return self._parents | |
798 |
|
799 | |||
799 | def filectx(self, path, filelog=None): |
|
800 | def filectx(self, path, filelog=None): | |
800 | """get a file context from the working directory""" |
|
801 | """get a file context from the working directory""" | |
801 | return self._filectxfn(self._repo, self, path) |
|
802 | return self._filectxfn(self._repo, self, path) | |
802 |
|
803 | |||
803 | class memfilectx(object): |
|
804 | class memfilectx(object): | |
804 | """memfilectx represents an in-memory file to commit. |
|
805 | """memfilectx represents an in-memory file to commit. | |
805 |
|
806 | |||
806 | See memctx for more details. |
|
807 | See memctx for more details. | |
807 | """ |
|
808 | """ | |
808 | def __init__(self, path, data, islink, isexec, copied): |
|
809 | def __init__(self, path, data, islink, isexec, copied): | |
809 | """ |
|
810 | """ | |
810 | path is the normalized file path relative to repository root. |
|
811 | path is the normalized file path relative to repository root. | |
811 | data is the file content as a string. |
|
812 | data is the file content as a string. | |
812 | islink is True if the file is a symbolic link. |
|
813 | islink is True if the file is a symbolic link. | |
813 | isexec is True if the file is executable. |
|
814 | isexec is True if the file is executable. | |
814 | copied is the source file path if current file was copied in the |
|
815 | copied is the source file path if current file was copied in the | |
815 | revision being committed, or None.""" |
|
816 | revision being committed, or None.""" | |
816 | self._path = path |
|
817 | self._path = path | |
817 | self._data = data |
|
818 | self._data = data | |
818 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
|
819 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') | |
819 | self._copied = None |
|
820 | self._copied = None | |
820 | if copied: |
|
821 | if copied: | |
821 | self._copied = (copied, nullid) |
|
822 | self._copied = (copied, nullid) | |
822 |
|
823 | |||
823 | def __nonzero__(self): return True |
|
824 | def __nonzero__(self): return True | |
824 | def __str__(self): return "%s@%s" % (self.path(), self._changectx) |
|
825 | def __str__(self): return "%s@%s" % (self.path(), self._changectx) | |
825 | def path(self): return self._path |
|
826 | def path(self): return self._path | |
826 | def data(self): return self._data |
|
827 | def data(self): return self._data | |
827 | def flags(self): return self._flags |
|
828 | def flags(self): return self._flags | |
828 | def isexec(self): return 'x' in self._flags |
|
829 | def isexec(self): return 'x' in self._flags | |
829 | def islink(self): return 'l' in self._flags |
|
830 | def islink(self): return 'l' in self._flags | |
830 | def renamed(self): return self._copied |
|
831 | def renamed(self): return self._copied |
@@ -1,644 +1,647 | |||||
1 | # dirstate.py - working directory tracking for mercurial |
|
1 | # dirstate.py - working directory tracking for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2, incorporated herein by reference. |
|
6 | # GNU General Public License version 2, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from node import nullid |
|
8 | from node import nullid | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import util, ignore, osutil, parsers |
|
10 | import util, ignore, osutil, parsers | |
11 | import struct, os, stat, errno |
|
11 | import struct, os, stat, errno | |
12 | import cStringIO |
|
12 | import cStringIO | |
13 |
|
13 | |||
14 | _unknown = ('?', 0, 0, 0) |
|
14 | _unknown = ('?', 0, 0, 0) | |
15 | _format = ">cllll" |
|
15 | _format = ">cllll" | |
16 | propertycache = util.propertycache |
|
16 | propertycache = util.propertycache | |
17 |
|
17 | |||
18 | def _finddirs(path): |
|
18 | def _finddirs(path): | |
19 | pos = path.rfind('/') |
|
19 | pos = path.rfind('/') | |
20 | while pos != -1: |
|
20 | while pos != -1: | |
21 | yield path[:pos] |
|
21 | yield path[:pos] | |
22 | pos = path.rfind('/', 0, pos) |
|
22 | pos = path.rfind('/', 0, pos) | |
23 |
|
23 | |||
24 | def _incdirs(dirs, path): |
|
24 | def _incdirs(dirs, path): | |
25 | for base in _finddirs(path): |
|
25 | for base in _finddirs(path): | |
26 | if base in dirs: |
|
26 | if base in dirs: | |
27 | dirs[base] += 1 |
|
27 | dirs[base] += 1 | |
28 | return |
|
28 | return | |
29 | dirs[base] = 1 |
|
29 | dirs[base] = 1 | |
30 |
|
30 | |||
31 | def _decdirs(dirs, path): |
|
31 | def _decdirs(dirs, path): | |
32 | for base in _finddirs(path): |
|
32 | for base in _finddirs(path): | |
33 | if dirs[base] > 1: |
|
33 | if dirs[base] > 1: | |
34 | dirs[base] -= 1 |
|
34 | dirs[base] -= 1 | |
35 | return |
|
35 | return | |
36 | del dirs[base] |
|
36 | del dirs[base] | |
37 |
|
37 | |||
38 | class dirstate(object): |
|
38 | class dirstate(object): | |
39 |
|
39 | |||
40 | def __init__(self, opener, ui, root): |
|
40 | def __init__(self, opener, ui, root): | |
41 | '''Create a new dirstate object. |
|
41 | '''Create a new dirstate object. | |
42 |
|
42 | |||
43 | opener is an open()-like callable that can be used to open the |
|
43 | opener is an open()-like callable that can be used to open the | |
44 | dirstate file; root is the root of the directory tracked by |
|
44 | dirstate file; root is the root of the directory tracked by | |
45 | the dirstate. |
|
45 | the dirstate. | |
46 | ''' |
|
46 | ''' | |
47 | self._opener = opener |
|
47 | self._opener = opener | |
48 | self._root = root |
|
48 | self._root = root | |
49 | self._rootdir = os.path.join(root, '') |
|
49 | self._rootdir = os.path.join(root, '') | |
50 | self._dirty = False |
|
50 | self._dirty = False | |
51 | self._dirtypl = False |
|
51 | self._dirtypl = False | |
52 | self._ui = ui |
|
52 | self._ui = ui | |
53 |
|
53 | |||
54 | @propertycache |
|
54 | @propertycache | |
55 | def _map(self): |
|
55 | def _map(self): | |
56 | '''Return the dirstate contents as a map from filename to |
|
56 | '''Return the dirstate contents as a map from filename to | |
57 | (state, mode, size, time).''' |
|
57 | (state, mode, size, time).''' | |
58 | self._read() |
|
58 | self._read() | |
59 | return self._map |
|
59 | return self._map | |
60 |
|
60 | |||
61 | @propertycache |
|
61 | @propertycache | |
62 | def _copymap(self): |
|
62 | def _copymap(self): | |
63 | self._read() |
|
63 | self._read() | |
64 | return self._copymap |
|
64 | return self._copymap | |
65 |
|
65 | |||
66 | @propertycache |
|
66 | @propertycache | |
67 | def _foldmap(self): |
|
67 | def _foldmap(self): | |
68 | f = {} |
|
68 | f = {} | |
69 | for name in self._map: |
|
69 | for name in self._map: | |
70 | f[os.path.normcase(name)] = name |
|
70 | f[os.path.normcase(name)] = name | |
71 | return f |
|
71 | return f | |
72 |
|
72 | |||
73 | @propertycache |
|
73 | @propertycache | |
74 | def _branch(self): |
|
74 | def _branch(self): | |
75 | try: |
|
75 | try: | |
76 | return self._opener("branch").read().strip() or "default" |
|
76 | return self._opener("branch").read().strip() or "default" | |
77 | except IOError: |
|
77 | except IOError: | |
78 | return "default" |
|
78 | return "default" | |
79 |
|
79 | |||
80 | @propertycache |
|
80 | @propertycache | |
81 | def _pl(self): |
|
81 | def _pl(self): | |
82 | try: |
|
82 | try: | |
83 | st = self._opener("dirstate").read(40) |
|
83 | st = self._opener("dirstate").read(40) | |
84 | l = len(st) |
|
84 | l = len(st) | |
85 | if l == 40: |
|
85 | if l == 40: | |
86 | return st[:20], st[20:40] |
|
86 | return st[:20], st[20:40] | |
87 | elif l > 0 and l < 40: |
|
87 | elif l > 0 and l < 40: | |
88 | raise util.Abort(_('working directory state appears damaged!')) |
|
88 | raise util.Abort(_('working directory state appears damaged!')) | |
89 | except IOError, err: |
|
89 | except IOError, err: | |
90 | if err.errno != errno.ENOENT: raise |
|
90 | if err.errno != errno.ENOENT: raise | |
91 | return [nullid, nullid] |
|
91 | return [nullid, nullid] | |
92 |
|
92 | |||
93 | @propertycache |
|
93 | @propertycache | |
94 | def _dirs(self): |
|
94 | def _dirs(self): | |
95 | dirs = {} |
|
95 | dirs = {} | |
96 | for f,s in self._map.iteritems(): |
|
96 | for f,s in self._map.iteritems(): | |
97 | if s[0] != 'r': |
|
97 | if s[0] != 'r': | |
98 | _incdirs(dirs, f) |
|
98 | _incdirs(dirs, f) | |
99 | return dirs |
|
99 | return dirs | |
100 |
|
100 | |||
101 | @propertycache |
|
101 | @propertycache | |
102 | def _ignore(self): |
|
102 | def _ignore(self): | |
103 | files = [self._join('.hgignore')] |
|
103 | files = [self._join('.hgignore')] | |
104 | for name, path in self._ui.configitems("ui"): |
|
104 | for name, path in self._ui.configitems("ui"): | |
105 | if name == 'ignore' or name.startswith('ignore.'): |
|
105 | if name == 'ignore' or name.startswith('ignore.'): | |
106 | files.append(util.expandpath(path)) |
|
106 | files.append(util.expandpath(path)) | |
107 | return ignore.ignore(self._root, files, self._ui.warn) |
|
107 | return ignore.ignore(self._root, files, self._ui.warn) | |
108 |
|
108 | |||
109 | @propertycache |
|
109 | @propertycache | |
110 | def _slash(self): |
|
110 | def _slash(self): | |
111 | return self._ui.configbool('ui', 'slash') and os.sep != '/' |
|
111 | return self._ui.configbool('ui', 'slash') and os.sep != '/' | |
112 |
|
112 | |||
113 | @propertycache |
|
113 | @propertycache | |
114 | def _checklink(self): |
|
114 | def _checklink(self): | |
115 | return util.checklink(self._root) |
|
115 | return util.checklink(self._root) | |
116 |
|
116 | |||
117 | @propertycache |
|
117 | @propertycache | |
118 | def _checkexec(self): |
|
118 | def _checkexec(self): | |
119 | return util.checkexec(self._root) |
|
119 | return util.checkexec(self._root) | |
120 |
|
120 | |||
121 | @propertycache |
|
121 | @propertycache | |
122 | def _checkcase(self): |
|
122 | def _checkcase(self): | |
123 | return not util.checkcase(self._join('.hg')) |
|
123 | return not util.checkcase(self._join('.hg')) | |
124 |
|
124 | |||
125 | def _join(self, f): |
|
125 | def _join(self, f): | |
126 | # much faster than os.path.join() |
|
126 | # much faster than os.path.join() | |
127 | # it's safe because f is always a relative path |
|
127 | # it's safe because f is always a relative path | |
128 | return self._rootdir + f |
|
128 | return self._rootdir + f | |
129 |
|
129 | |||
130 | def flagfunc(self, fallback): |
|
130 | def flagfunc(self, fallback): | |
131 | if self._checklink: |
|
131 | if self._checklink: | |
132 | if self._checkexec: |
|
132 | if self._checkexec: | |
133 | def f(x): |
|
133 | def f(x): | |
134 | p = self._join(x) |
|
134 | p = self._join(x) | |
135 | if os.path.islink(p): |
|
135 | if os.path.islink(p): | |
136 | return 'l' |
|
136 | return 'l' | |
137 | if util.is_exec(p): |
|
137 | if util.is_exec(p): | |
138 | return 'x' |
|
138 | return 'x' | |
139 | return '' |
|
139 | return '' | |
140 | return f |
|
140 | return f | |
141 | def f(x): |
|
141 | def f(x): | |
142 | if os.path.islink(self._join(x)): |
|
142 | if os.path.islink(self._join(x)): | |
143 | return 'l' |
|
143 | return 'l' | |
144 | if 'x' in fallback(x): |
|
144 | if 'x' in fallback(x): | |
145 | return 'x' |
|
145 | return 'x' | |
146 | return '' |
|
146 | return '' | |
147 | return f |
|
147 | return f | |
148 | if self._checkexec: |
|
148 | if self._checkexec: | |
149 | def f(x): |
|
149 | def f(x): | |
150 | if 'l' in fallback(x): |
|
150 | if 'l' in fallback(x): | |
151 | return 'l' |
|
151 | return 'l' | |
152 | if util.is_exec(self._join(x)): |
|
152 | if util.is_exec(self._join(x)): | |
153 | return 'x' |
|
153 | return 'x' | |
154 | return '' |
|
154 | return '' | |
155 | return f |
|
155 | return f | |
156 | return fallback |
|
156 | return fallback | |
157 |
|
157 | |||
158 | def getcwd(self): |
|
158 | def getcwd(self): | |
159 | cwd = os.getcwd() |
|
159 | cwd = os.getcwd() | |
160 | if cwd == self._root: return '' |
|
160 | if cwd == self._root: return '' | |
161 | # self._root ends with a path separator if self._root is '/' or 'C:\' |
|
161 | # self._root ends with a path separator if self._root is '/' or 'C:\' | |
162 | rootsep = self._root |
|
162 | rootsep = self._root | |
163 | if not util.endswithsep(rootsep): |
|
163 | if not util.endswithsep(rootsep): | |
164 | rootsep += os.sep |
|
164 | rootsep += os.sep | |
165 | if cwd.startswith(rootsep): |
|
165 | if cwd.startswith(rootsep): | |
166 | return cwd[len(rootsep):] |
|
166 | return cwd[len(rootsep):] | |
167 | else: |
|
167 | else: | |
168 | # we're outside the repo. return an absolute path. |
|
168 | # we're outside the repo. return an absolute path. | |
169 | return cwd |
|
169 | return cwd | |
170 |
|
170 | |||
171 | def pathto(self, f, cwd=None): |
|
171 | def pathto(self, f, cwd=None): | |
172 | if cwd is None: |
|
172 | if cwd is None: | |
173 | cwd = self.getcwd() |
|
173 | cwd = self.getcwd() | |
174 | path = util.pathto(self._root, cwd, f) |
|
174 | path = util.pathto(self._root, cwd, f) | |
175 | if self._slash: |
|
175 | if self._slash: | |
176 | return util.normpath(path) |
|
176 | return util.normpath(path) | |
177 | return path |
|
177 | return path | |
178 |
|
178 | |||
179 | def __getitem__(self, key): |
|
179 | def __getitem__(self, key): | |
180 | '''Return the current state of key (a filename) in the dirstate. |
|
180 | '''Return the current state of key (a filename) in the dirstate. | |
181 |
|
181 | |||
182 | States are: |
|
182 | States are: | |
183 | n normal |
|
183 | n normal | |
184 | m needs merging |
|
184 | m needs merging | |
185 | r marked for removal |
|
185 | r marked for removal | |
186 | a marked for addition |
|
186 | a marked for addition | |
187 | ? not tracked |
|
187 | ? not tracked | |
188 | ''' |
|
188 | ''' | |
189 | return self._map.get(key, ("?",))[0] |
|
189 | return self._map.get(key, ("?",))[0] | |
190 |
|
190 | |||
191 | def __contains__(self, key): |
|
191 | def __contains__(self, key): | |
192 | return key in self._map |
|
192 | return key in self._map | |
193 |
|
193 | |||
194 | def __iter__(self): |
|
194 | def __iter__(self): | |
195 | for x in sorted(self._map): |
|
195 | for x in sorted(self._map): | |
196 | yield x |
|
196 | yield x | |
197 |
|
197 | |||
198 | def parents(self): |
|
198 | def parents(self): | |
199 | return self._pl |
|
199 | return self._pl | |
200 |
|
200 | |||
201 | def branch(self): |
|
201 | def branch(self): | |
202 | return self._branch |
|
202 | return self._branch | |
203 |
|
203 | |||
204 | def setparents(self, p1, p2=nullid): |
|
204 | def setparents(self, p1, p2=nullid): | |
205 | self._dirty = self._dirtypl = True |
|
205 | self._dirty = self._dirtypl = True | |
206 | self._pl = p1, p2 |
|
206 | self._pl = p1, p2 | |
207 |
|
207 | |||
208 | def setbranch(self, branch): |
|
208 | def setbranch(self, branch): | |
209 | self._branch = branch |
|
209 | self._branch = branch | |
210 | self._opener("branch", "w").write(branch + '\n') |
|
210 | self._opener("branch", "w").write(branch + '\n') | |
211 |
|
211 | |||
212 | def _read(self): |
|
212 | def _read(self): | |
213 | self._map = {} |
|
213 | self._map = {} | |
214 | self._copymap = {} |
|
214 | self._copymap = {} | |
215 | try: |
|
215 | try: | |
216 | st = self._opener("dirstate").read() |
|
216 | st = self._opener("dirstate").read() | |
217 | except IOError, err: |
|
217 | except IOError, err: | |
218 | if err.errno != errno.ENOENT: raise |
|
218 | if err.errno != errno.ENOENT: raise | |
219 | return |
|
219 | return | |
220 | if not st: |
|
220 | if not st: | |
221 | return |
|
221 | return | |
222 |
|
222 | |||
223 | p = parsers.parse_dirstate(self._map, self._copymap, st) |
|
223 | p = parsers.parse_dirstate(self._map, self._copymap, st) | |
224 | if not self._dirtypl: |
|
224 | if not self._dirtypl: | |
225 | self._pl = p |
|
225 | self._pl = p | |
226 |
|
226 | |||
227 | def invalidate(self): |
|
227 | def invalidate(self): | |
228 | for a in "_map _copymap _foldmap _branch _pl _dirs _ignore".split(): |
|
228 | for a in "_map _copymap _foldmap _branch _pl _dirs _ignore".split(): | |
229 | if a in self.__dict__: |
|
229 | if a in self.__dict__: | |
230 | delattr(self, a) |
|
230 | delattr(self, a) | |
231 | self._dirty = False |
|
231 | self._dirty = False | |
232 |
|
232 | |||
233 | def copy(self, source, dest): |
|
233 | def copy(self, source, dest): | |
234 | """Mark dest as a copy of source. Unmark dest if source is None.""" |
|
234 | """Mark dest as a copy of source. Unmark dest if source is None.""" | |
235 | if source == dest: |
|
235 | if source == dest: | |
236 | return |
|
236 | return | |
237 | self._dirty = True |
|
237 | self._dirty = True | |
238 | if source is not None: |
|
238 | if source is not None: | |
239 | self._copymap[dest] = source |
|
239 | self._copymap[dest] = source | |
240 | elif dest in self._copymap: |
|
240 | elif dest in self._copymap: | |
241 | del self._copymap[dest] |
|
241 | del self._copymap[dest] | |
242 |
|
242 | |||
243 | def copied(self, file): |
|
243 | def copied(self, file): | |
244 | return self._copymap.get(file, None) |
|
244 | return self._copymap.get(file, None) | |
245 |
|
245 | |||
246 | def copies(self): |
|
246 | def copies(self): | |
247 | return self._copymap |
|
247 | return self._copymap | |
248 |
|
248 | |||
249 | def _droppath(self, f): |
|
249 | def _droppath(self, f): | |
250 | if self[f] not in "?r" and "_dirs" in self.__dict__: |
|
250 | if self[f] not in "?r" and "_dirs" in self.__dict__: | |
251 | _decdirs(self._dirs, f) |
|
251 | _decdirs(self._dirs, f) | |
252 |
|
252 | |||
253 | def _addpath(self, f, check=False): |
|
253 | def _addpath(self, f, check=False): | |
254 | oldstate = self[f] |
|
254 | oldstate = self[f] | |
255 | if check or oldstate == "r": |
|
255 | if check or oldstate == "r": | |
256 | if '\r' in f or '\n' in f: |
|
256 | if '\r' in f or '\n' in f: | |
257 | raise util.Abort( |
|
257 | raise util.Abort( | |
258 | _("'\\n' and '\\r' disallowed in filenames: %r") % f) |
|
258 | _("'\\n' and '\\r' disallowed in filenames: %r") % f) | |
259 | if f in self._dirs: |
|
259 | if f in self._dirs: | |
260 | raise util.Abort(_('directory %r already in dirstate') % f) |
|
260 | raise util.Abort(_('directory %r already in dirstate') % f) | |
261 | # shadows |
|
261 | # shadows | |
262 | for d in _finddirs(f): |
|
262 | for d in _finddirs(f): | |
263 | if d in self._dirs: |
|
263 | if d in self._dirs: | |
264 | break |
|
264 | break | |
265 | if d in self._map and self[d] != 'r': |
|
265 | if d in self._map and self[d] != 'r': | |
266 | raise util.Abort( |
|
266 | raise util.Abort( | |
267 | _('file %r in dirstate clashes with %r') % (d, f)) |
|
267 | _('file %r in dirstate clashes with %r') % (d, f)) | |
268 | if oldstate in "?r" and "_dirs" in self.__dict__: |
|
268 | if oldstate in "?r" and "_dirs" in self.__dict__: | |
269 | _incdirs(self._dirs, f) |
|
269 | _incdirs(self._dirs, f) | |
270 |
|
270 | |||
271 | def normal(self, f): |
|
271 | def normal(self, f): | |
272 | '''Mark a file normal and clean.''' |
|
272 | '''Mark a file normal and clean.''' | |
273 | self._dirty = True |
|
273 | self._dirty = True | |
274 | self._addpath(f) |
|
274 | self._addpath(f) | |
275 | s = os.lstat(self._join(f)) |
|
275 | s = os.lstat(self._join(f)) | |
276 | self._map[f] = ('n', s.st_mode, s.st_size, int(s.st_mtime)) |
|
276 | self._map[f] = ('n', s.st_mode, s.st_size, int(s.st_mtime)) | |
277 | if f in self._copymap: |
|
277 | if f in self._copymap: | |
278 | del self._copymap[f] |
|
278 | del self._copymap[f] | |
279 |
|
279 | |||
280 | def normallookup(self, f): |
|
280 | def normallookup(self, f): | |
281 | '''Mark a file normal, but possibly dirty.''' |
|
281 | '''Mark a file normal, but possibly dirty.''' | |
282 | if self._pl[1] != nullid and f in self._map: |
|
282 | if self._pl[1] != nullid and f in self._map: | |
283 | # if there is a merge going on and the file was either |
|
283 | # if there is a merge going on and the file was either | |
284 | # in state 'm' or dirty before being removed, restore that state. |
|
284 | # in state 'm' or dirty before being removed, restore that state. | |
285 | entry = self._map[f] |
|
285 | entry = self._map[f] | |
286 | if entry[0] == 'r' and entry[2] in (-1, -2): |
|
286 | if entry[0] == 'r' and entry[2] in (-1, -2): | |
287 | source = self._copymap.get(f) |
|
287 | source = self._copymap.get(f) | |
288 | if entry[2] == -1: |
|
288 | if entry[2] == -1: | |
289 | self.merge(f) |
|
289 | self.merge(f) | |
290 | elif entry[2] == -2: |
|
290 | elif entry[2] == -2: | |
291 | self.normaldirty(f) |
|
291 | self.normaldirty(f) | |
292 | if source: |
|
292 | if source: | |
293 | self.copy(source, f) |
|
293 | self.copy(source, f) | |
294 | return |
|
294 | return | |
295 | if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2: |
|
295 | if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2: | |
296 | return |
|
296 | return | |
297 | self._dirty = True |
|
297 | self._dirty = True | |
298 | self._addpath(f) |
|
298 | self._addpath(f) | |
299 | self._map[f] = ('n', 0, -1, -1) |
|
299 | self._map[f] = ('n', 0, -1, -1) | |
300 | if f in self._copymap: |
|
300 | if f in self._copymap: | |
301 | del self._copymap[f] |
|
301 | del self._copymap[f] | |
302 |
|
302 | |||
303 | def normaldirty(self, f): |
|
303 | def normaldirty(self, f): | |
304 | '''Mark a file normal, but dirty.''' |
|
304 | '''Mark a file normal, but dirty.''' | |
305 | self._dirty = True |
|
305 | self._dirty = True | |
306 | self._addpath(f) |
|
306 | self._addpath(f) | |
307 | self._map[f] = ('n', 0, -2, -1) |
|
307 | self._map[f] = ('n', 0, -2, -1) | |
308 | if f in self._copymap: |
|
308 | if f in self._copymap: | |
309 | del self._copymap[f] |
|
309 | del self._copymap[f] | |
310 |
|
310 | |||
311 | def add(self, f): |
|
311 | def add(self, f): | |
312 | '''Mark a file added.''' |
|
312 | '''Mark a file added.''' | |
313 | self._dirty = True |
|
313 | self._dirty = True | |
314 | self._addpath(f, True) |
|
314 | self._addpath(f, True) | |
315 | self._map[f] = ('a', 0, -1, -1) |
|
315 | self._map[f] = ('a', 0, -1, -1) | |
316 | if f in self._copymap: |
|
316 | if f in self._copymap: | |
317 | del self._copymap[f] |
|
317 | del self._copymap[f] | |
318 |
|
318 | |||
319 | def remove(self, f): |
|
319 | def remove(self, f): | |
320 | '''Mark a file removed.''' |
|
320 | '''Mark a file removed.''' | |
321 | self._dirty = True |
|
321 | self._dirty = True | |
322 | self._droppath(f) |
|
322 | self._droppath(f) | |
323 | size = 0 |
|
323 | size = 0 | |
324 | if self._pl[1] != nullid and f in self._map: |
|
324 | if self._pl[1] != nullid and f in self._map: | |
325 | entry = self._map[f] |
|
325 | entry = self._map[f] | |
326 | if entry[0] == 'm': |
|
326 | if entry[0] == 'm': | |
327 | size = -1 |
|
327 | size = -1 | |
328 | elif entry[0] == 'n' and entry[2] == -2: |
|
328 | elif entry[0] == 'n' and entry[2] == -2: | |
329 | size = -2 |
|
329 | size = -2 | |
330 | self._map[f] = ('r', 0, size, 0) |
|
330 | self._map[f] = ('r', 0, size, 0) | |
331 | if size == 0 and f in self._copymap: |
|
331 | if size == 0 and f in self._copymap: | |
332 | del self._copymap[f] |
|
332 | del self._copymap[f] | |
333 |
|
333 | |||
334 | def merge(self, f): |
|
334 | def merge(self, f): | |
335 | '''Mark a file merged.''' |
|
335 | '''Mark a file merged.''' | |
336 | self._dirty = True |
|
336 | self._dirty = True | |
337 | s = os.lstat(self._join(f)) |
|
337 | s = os.lstat(self._join(f)) | |
338 | self._addpath(f) |
|
338 | self._addpath(f) | |
339 | self._map[f] = ('m', s.st_mode, s.st_size, int(s.st_mtime)) |
|
339 | self._map[f] = ('m', s.st_mode, s.st_size, int(s.st_mtime)) | |
340 | if f in self._copymap: |
|
340 | if f in self._copymap: | |
341 | del self._copymap[f] |
|
341 | del self._copymap[f] | |
342 |
|
342 | |||
343 | def forget(self, f): |
|
343 | def forget(self, f): | |
344 | '''Forget a file.''' |
|
344 | '''Forget a file.''' | |
345 | self._dirty = True |
|
345 | self._dirty = True | |
346 | try: |
|
346 | try: | |
347 | self._droppath(f) |
|
347 | self._droppath(f) | |
348 | del self._map[f] |
|
348 | del self._map[f] | |
349 | except KeyError: |
|
349 | except KeyError: | |
350 | self._ui.warn(_("not in dirstate: %s\n") % f) |
|
350 | self._ui.warn(_("not in dirstate: %s\n") % f) | |
351 |
|
351 | |||
352 | def _normalize(self, path, knownpath): |
|
352 | def _normalize(self, path, knownpath): | |
353 | norm_path = os.path.normcase(path) |
|
353 | norm_path = os.path.normcase(path) | |
354 | fold_path = self._foldmap.get(norm_path, None) |
|
354 | fold_path = self._foldmap.get(norm_path, None) | |
355 | if fold_path is None: |
|
355 | if fold_path is None: | |
356 | if knownpath or not os.path.exists(os.path.join(self._root, path)): |
|
356 | if knownpath or not os.path.exists(os.path.join(self._root, path)): | |
357 | fold_path = path |
|
357 | fold_path = path | |
358 | else: |
|
358 | else: | |
359 | fold_path = self._foldmap.setdefault(norm_path, |
|
359 | fold_path = self._foldmap.setdefault(norm_path, | |
360 | util.fspath(path, self._root)) |
|
360 | util.fspath(path, self._root)) | |
361 | return fold_path |
|
361 | return fold_path | |
362 |
|
362 | |||
363 | def clear(self): |
|
363 | def clear(self): | |
364 | self._map = {} |
|
364 | self._map = {} | |
365 | if "_dirs" in self.__dict__: |
|
365 | if "_dirs" in self.__dict__: | |
366 | delattr(self, "_dirs"); |
|
366 | delattr(self, "_dirs"); | |
367 | self._copymap = {} |
|
367 | self._copymap = {} | |
368 | self._pl = [nullid, nullid] |
|
368 | self._pl = [nullid, nullid] | |
369 | self._dirty = True |
|
369 | self._dirty = True | |
370 |
|
370 | |||
371 | def rebuild(self, parent, files): |
|
371 | def rebuild(self, parent, files): | |
372 | self.clear() |
|
372 | self.clear() | |
373 | for f in files: |
|
373 | for f in files: | |
374 | if 'x' in files.flags(f): |
|
374 | if 'x' in files.flags(f): | |
375 | self._map[f] = ('n', 0777, -1, 0) |
|
375 | self._map[f] = ('n', 0777, -1, 0) | |
376 | else: |
|
376 | else: | |
377 | self._map[f] = ('n', 0666, -1, 0) |
|
377 | self._map[f] = ('n', 0666, -1, 0) | |
378 | self._pl = (parent, nullid) |
|
378 | self._pl = (parent, nullid) | |
379 | self._dirty = True |
|
379 | self._dirty = True | |
380 |
|
380 | |||
381 | def write(self): |
|
381 | def write(self): | |
382 | if not self._dirty: |
|
382 | if not self._dirty: | |
383 | return |
|
383 | return | |
384 | st = self._opener("dirstate", "w", atomictemp=True) |
|
384 | st = self._opener("dirstate", "w", atomictemp=True) | |
385 |
|
385 | |||
386 | # use the modification time of the newly created temporary file as the |
|
386 | # use the modification time of the newly created temporary file as the | |
387 | # filesystem's notion of 'now' |
|
387 | # filesystem's notion of 'now' | |
388 | now = int(util.fstat(st).st_mtime) |
|
388 | now = int(util.fstat(st).st_mtime) | |
389 |
|
389 | |||
390 | cs = cStringIO.StringIO() |
|
390 | cs = cStringIO.StringIO() | |
391 | copymap = self._copymap |
|
391 | copymap = self._copymap | |
392 | pack = struct.pack |
|
392 | pack = struct.pack | |
393 | write = cs.write |
|
393 | write = cs.write | |
394 | write("".join(self._pl)) |
|
394 | write("".join(self._pl)) | |
395 | for f, e in self._map.iteritems(): |
|
395 | for f, e in self._map.iteritems(): | |
396 | if f in copymap: |
|
396 | if f in copymap: | |
397 | f = "%s\0%s" % (f, copymap[f]) |
|
397 | f = "%s\0%s" % (f, copymap[f]) | |
398 |
|
398 | |||
399 | if e[0] == 'n' and e[3] == now: |
|
399 | if e[0] == 'n' and e[3] == now: | |
400 | # The file was last modified "simultaneously" with the current |
|
400 | # The file was last modified "simultaneously" with the current | |
401 | # write to dirstate (i.e. within the same second for file- |
|
401 | # write to dirstate (i.e. within the same second for file- | |
402 | # systems with a granularity of 1 sec). This commonly happens |
|
402 | # systems with a granularity of 1 sec). This commonly happens | |
403 | # for at least a couple of files on 'update'. |
|
403 | # for at least a couple of files on 'update'. | |
404 | # The user could change the file without changing its size |
|
404 | # The user could change the file without changing its size | |
405 | # within the same second. Invalidate the file's stat data in |
|
405 | # within the same second. Invalidate the file's stat data in | |
406 | # dirstate, forcing future 'status' calls to compare the |
|
406 | # dirstate, forcing future 'status' calls to compare the | |
407 | # contents of the file. This prevents mistakenly treating such |
|
407 | # contents of the file. This prevents mistakenly treating such | |
408 | # files as clean. |
|
408 | # files as clean. | |
409 | e = (e[0], 0, -1, -1) # mark entry as 'unset' |
|
409 | e = (e[0], 0, -1, -1) # mark entry as 'unset' | |
410 |
|
410 | |||
411 | e = pack(_format, e[0], e[1], e[2], e[3], len(f)) |
|
411 | e = pack(_format, e[0], e[1], e[2], e[3], len(f)) | |
412 | write(e) |
|
412 | write(e) | |
413 | write(f) |
|
413 | write(f) | |
414 | st.write(cs.getvalue()) |
|
414 | st.write(cs.getvalue()) | |
415 | st.rename() |
|
415 | st.rename() | |
416 | self._dirty = self._dirtypl = False |
|
416 | self._dirty = self._dirtypl = False | |
417 |
|
417 | |||
418 | def _dirignore(self, f): |
|
418 | def _dirignore(self, f): | |
419 | if f == '.': |
|
419 | if f == '.': | |
420 | return False |
|
420 | return False | |
421 | if self._ignore(f): |
|
421 | if self._ignore(f): | |
422 | return True |
|
422 | return True | |
423 | for p in _finddirs(f): |
|
423 | for p in _finddirs(f): | |
424 | if self._ignore(p): |
|
424 | if self._ignore(p): | |
425 | return True |
|
425 | return True | |
426 | return False |
|
426 | return False | |
427 |
|
427 | |||
428 | def walk(self, match, unknown, ignored): |
|
428 | def walk(self, match, subrepos, unknown, ignored): | |
429 | ''' |
|
429 | ''' | |
430 | Walk recursively through the directory tree, finding all files |
|
430 | Walk recursively through the directory tree, finding all files | |
431 | matched by match. |
|
431 | matched by match. | |
432 |
|
432 | |||
433 | Return a dict mapping filename to stat-like object (either |
|
433 | Return a dict mapping filename to stat-like object (either | |
434 | mercurial.osutil.stat instance or return value of os.stat()). |
|
434 | mercurial.osutil.stat instance or return value of os.stat()). | |
435 | ''' |
|
435 | ''' | |
436 |
|
436 | |||
437 | def fwarn(f, msg): |
|
437 | def fwarn(f, msg): | |
438 | self._ui.warn('%s: %s\n' % (self.pathto(f), msg)) |
|
438 | self._ui.warn('%s: %s\n' % (self.pathto(f), msg)) | |
439 | return False |
|
439 | return False | |
440 |
|
440 | |||
441 | def badtype(mode): |
|
441 | def badtype(mode): | |
442 | kind = _('unknown') |
|
442 | kind = _('unknown') | |
443 | if stat.S_ISCHR(mode): kind = _('character device') |
|
443 | if stat.S_ISCHR(mode): kind = _('character device') | |
444 | elif stat.S_ISBLK(mode): kind = _('block device') |
|
444 | elif stat.S_ISBLK(mode): kind = _('block device') | |
445 | elif stat.S_ISFIFO(mode): kind = _('fifo') |
|
445 | elif stat.S_ISFIFO(mode): kind = _('fifo') | |
446 | elif stat.S_ISSOCK(mode): kind = _('socket') |
|
446 | elif stat.S_ISSOCK(mode): kind = _('socket') | |
447 | elif stat.S_ISDIR(mode): kind = _('directory') |
|
447 | elif stat.S_ISDIR(mode): kind = _('directory') | |
448 | return _('unsupported file type (type is %s)') % kind |
|
448 | return _('unsupported file type (type is %s)') % kind | |
449 |
|
449 | |||
450 | ignore = self._ignore |
|
450 | ignore = self._ignore | |
451 | dirignore = self._dirignore |
|
451 | dirignore = self._dirignore | |
452 | if ignored: |
|
452 | if ignored: | |
453 | ignore = util.never |
|
453 | ignore = util.never | |
454 | dirignore = util.never |
|
454 | dirignore = util.never | |
455 | elif not unknown: |
|
455 | elif not unknown: | |
456 | # if unknown and ignored are False, skip step 2 |
|
456 | # if unknown and ignored are False, skip step 2 | |
457 | ignore = util.always |
|
457 | ignore = util.always | |
458 | dirignore = util.always |
|
458 | dirignore = util.always | |
459 |
|
459 | |||
460 | matchfn = match.matchfn |
|
460 | matchfn = match.matchfn | |
461 | badfn = match.bad |
|
461 | badfn = match.bad | |
462 | dmap = self._map |
|
462 | dmap = self._map | |
463 | normpath = util.normpath |
|
463 | normpath = util.normpath | |
464 | listdir = osutil.listdir |
|
464 | listdir = osutil.listdir | |
465 | lstat = os.lstat |
|
465 | lstat = os.lstat | |
466 | getkind = stat.S_IFMT |
|
466 | getkind = stat.S_IFMT | |
467 | dirkind = stat.S_IFDIR |
|
467 | dirkind = stat.S_IFDIR | |
468 | regkind = stat.S_IFREG |
|
468 | regkind = stat.S_IFREG | |
469 | lnkkind = stat.S_IFLNK |
|
469 | lnkkind = stat.S_IFLNK | |
470 | join = self._join |
|
470 | join = self._join | |
471 | work = [] |
|
471 | work = [] | |
472 | wadd = work.append |
|
472 | wadd = work.append | |
473 |
|
473 | |||
474 | if self._checkcase: |
|
474 | if self._checkcase: | |
475 | normalize = self._normalize |
|
475 | normalize = self._normalize | |
476 | else: |
|
476 | else: | |
477 | normalize = lambda x, y: x |
|
477 | normalize = lambda x, y: x | |
478 |
|
478 | |||
479 | exact = skipstep3 = False |
|
479 | exact = skipstep3 = False | |
480 | if matchfn == match.exact: # match.exact |
|
480 | if matchfn == match.exact: # match.exact | |
481 | exact = True |
|
481 | exact = True | |
482 | dirignore = util.always # skip step 2 |
|
482 | dirignore = util.always # skip step 2 | |
483 | elif match.files() and not match.anypats(): # match.match, no patterns |
|
483 | elif match.files() and not match.anypats(): # match.match, no patterns | |
484 | skipstep3 = True |
|
484 | skipstep3 = True | |
485 |
|
485 | |||
486 | files = set(match.files()) |
|
486 | files = set(match.files()) | |
487 | if not files or '.' in files: |
|
487 | if not files or '.' in files: | |
488 | files = [''] |
|
488 | files = [''] | |
489 | results = {'.hg': None} |
|
489 | results = dict.fromkeys(subrepos) | |
|
490 | results['.hg'] = None | |||
490 |
|
491 | |||
491 | # step 1: find all explicit files |
|
492 | # step 1: find all explicit files | |
492 | for ff in sorted(files): |
|
493 | for ff in sorted(files): | |
493 | nf = normalize(normpath(ff), False) |
|
494 | nf = normalize(normpath(ff), False) | |
494 | if nf in results: |
|
495 | if nf in results: | |
495 | continue |
|
496 | continue | |
496 |
|
497 | |||
497 | try: |
|
498 | try: | |
498 | st = lstat(join(nf)) |
|
499 | st = lstat(join(nf)) | |
499 | kind = getkind(st.st_mode) |
|
500 | kind = getkind(st.st_mode) | |
500 | if kind == dirkind: |
|
501 | if kind == dirkind: | |
501 | skipstep3 = False |
|
502 | skipstep3 = False | |
502 | if nf in dmap: |
|
503 | if nf in dmap: | |
503 | #file deleted on disk but still in dirstate |
|
504 | #file deleted on disk but still in dirstate | |
504 | results[nf] = None |
|
505 | results[nf] = None | |
505 | match.dir(nf) |
|
506 | match.dir(nf) | |
506 | if not dirignore(nf): |
|
507 | if not dirignore(nf): | |
507 | wadd(nf) |
|
508 | wadd(nf) | |
508 | elif kind == regkind or kind == lnkkind: |
|
509 | elif kind == regkind or kind == lnkkind: | |
509 | results[nf] = st |
|
510 | results[nf] = st | |
510 | else: |
|
511 | else: | |
511 | badfn(ff, badtype(kind)) |
|
512 | badfn(ff, badtype(kind)) | |
512 | if nf in dmap: |
|
513 | if nf in dmap: | |
513 | results[nf] = None |
|
514 | results[nf] = None | |
514 | except OSError, inst: |
|
515 | except OSError, inst: | |
515 | if nf in dmap: # does it exactly match a file? |
|
516 | if nf in dmap: # does it exactly match a file? | |
516 | results[nf] = None |
|
517 | results[nf] = None | |
517 | else: # does it match a directory? |
|
518 | else: # does it match a directory? | |
518 | prefix = nf + "/" |
|
519 | prefix = nf + "/" | |
519 | for fn in dmap: |
|
520 | for fn in dmap: | |
520 | if fn.startswith(prefix): |
|
521 | if fn.startswith(prefix): | |
521 | match.dir(nf) |
|
522 | match.dir(nf) | |
522 | skipstep3 = False |
|
523 | skipstep3 = False | |
523 | break |
|
524 | break | |
524 | else: |
|
525 | else: | |
525 | badfn(ff, inst.strerror) |
|
526 | badfn(ff, inst.strerror) | |
526 |
|
527 | |||
527 | # step 2: visit subdirectories |
|
528 | # step 2: visit subdirectories | |
528 | while work: |
|
529 | while work: | |
529 | nd = work.pop() |
|
530 | nd = work.pop() | |
530 | skip = None |
|
531 | skip = None | |
531 | if nd == '.': |
|
532 | if nd == '.': | |
532 | nd = '' |
|
533 | nd = '' | |
533 | else: |
|
534 | else: | |
534 | skip = '.hg' |
|
535 | skip = '.hg' | |
535 | try: |
|
536 | try: | |
536 | entries = listdir(join(nd), stat=True, skip=skip) |
|
537 | entries = listdir(join(nd), stat=True, skip=skip) | |
537 | except OSError, inst: |
|
538 | except OSError, inst: | |
538 | if inst.errno == errno.EACCES: |
|
539 | if inst.errno == errno.EACCES: | |
539 | fwarn(nd, inst.strerror) |
|
540 | fwarn(nd, inst.strerror) | |
540 | continue |
|
541 | continue | |
541 | raise |
|
542 | raise | |
542 | for f, kind, st in entries: |
|
543 | for f, kind, st in entries: | |
543 | nf = normalize(nd and (nd + "/" + f) or f, True) |
|
544 | nf = normalize(nd and (nd + "/" + f) or f, True) | |
544 | if nf not in results: |
|
545 | if nf not in results: | |
545 | if kind == dirkind: |
|
546 | if kind == dirkind: | |
546 | if not ignore(nf): |
|
547 | if not ignore(nf): | |
547 | match.dir(nf) |
|
548 | match.dir(nf) | |
548 | wadd(nf) |
|
549 | wadd(nf) | |
549 | if nf in dmap and matchfn(nf): |
|
550 | if nf in dmap and matchfn(nf): | |
550 | results[nf] = None |
|
551 | results[nf] = None | |
551 | elif kind == regkind or kind == lnkkind: |
|
552 | elif kind == regkind or kind == lnkkind: | |
552 | if nf in dmap: |
|
553 | if nf in dmap: | |
553 | if matchfn(nf): |
|
554 | if matchfn(nf): | |
554 | results[nf] = st |
|
555 | results[nf] = st | |
555 | elif matchfn(nf) and not ignore(nf): |
|
556 | elif matchfn(nf) and not ignore(nf): | |
556 | results[nf] = st |
|
557 | results[nf] = st | |
557 | elif nf in dmap and matchfn(nf): |
|
558 | elif nf in dmap and matchfn(nf): | |
558 | results[nf] = None |
|
559 | results[nf] = None | |
559 |
|
560 | |||
560 | # step 3: report unseen items in the dmap hash |
|
561 | # step 3: report unseen items in the dmap hash | |
561 | if not skipstep3 and not exact: |
|
562 | if not skipstep3 and not exact: | |
562 | visit = sorted([f for f in dmap if f not in results and matchfn(f)]) |
|
563 | visit = sorted([f for f in dmap if f not in results and matchfn(f)]) | |
563 | for nf, st in zip(visit, util.statfiles([join(i) for i in visit])): |
|
564 | for nf, st in zip(visit, util.statfiles([join(i) for i in visit])): | |
564 | if not st is None and not getkind(st.st_mode) in (regkind, lnkkind): |
|
565 | if not st is None and not getkind(st.st_mode) in (regkind, lnkkind): | |
565 | st = None |
|
566 | st = None | |
566 | results[nf] = st |
|
567 | results[nf] = st | |
567 |
|
568 | for s in subrepos: | ||
|
569 | del results[s] | |||
568 | del results['.hg'] |
|
570 | del results['.hg'] | |
569 | return results |
|
571 | return results | |
570 |
|
572 | |||
571 | def status(self, match, ignored, clean, unknown): |
|
573 | def status(self, match, subrepos, ignored, clean, unknown): | |
572 | '''Determine the status of the working copy relative to the |
|
574 | '''Determine the status of the working copy relative to the | |
573 | dirstate and return a tuple of lists (unsure, modified, added, |
|
575 | dirstate and return a tuple of lists (unsure, modified, added, | |
574 | removed, deleted, unknown, ignored, clean), where: |
|
576 | removed, deleted, unknown, ignored, clean), where: | |
575 |
|
577 | |||
576 | unsure: |
|
578 | unsure: | |
577 | files that might have been modified since the dirstate was |
|
579 | files that might have been modified since the dirstate was | |
578 | written, but need to be read to be sure (size is the same |
|
580 | written, but need to be read to be sure (size is the same | |
579 | but mtime differs) |
|
581 | but mtime differs) | |
580 | modified: |
|
582 | modified: | |
581 | files that have definitely been modified since the dirstate |
|
583 | files that have definitely been modified since the dirstate | |
582 | was written (different size or mode) |
|
584 | was written (different size or mode) | |
583 | added: |
|
585 | added: | |
584 | files that have been explicitly added with hg add |
|
586 | files that have been explicitly added with hg add | |
585 | removed: |
|
587 | removed: | |
586 | files that have been explicitly removed with hg remove |
|
588 | files that have been explicitly removed with hg remove | |
587 | deleted: |
|
589 | deleted: | |
588 | files that have been deleted through other means ("missing") |
|
590 | files that have been deleted through other means ("missing") | |
589 | unknown: |
|
591 | unknown: | |
590 | files not in the dirstate that are not ignored |
|
592 | files not in the dirstate that are not ignored | |
591 | ignored: |
|
593 | ignored: | |
592 | files not in the dirstate that are ignored |
|
594 | files not in the dirstate that are ignored | |
593 | (by _dirignore()) |
|
595 | (by _dirignore()) | |
594 | clean: |
|
596 | clean: | |
595 | files that have definitely not been modified since the |
|
597 | files that have definitely not been modified since the | |
596 | dirstate was written |
|
598 | dirstate was written | |
597 | ''' |
|
599 | ''' | |
598 | listignored, listclean, listunknown = ignored, clean, unknown |
|
600 | listignored, listclean, listunknown = ignored, clean, unknown | |
599 | lookup, modified, added, unknown, ignored = [], [], [], [], [] |
|
601 | lookup, modified, added, unknown, ignored = [], [], [], [], [] | |
600 | removed, deleted, clean = [], [], [] |
|
602 | removed, deleted, clean = [], [], [] | |
601 |
|
603 | |||
602 | dmap = self._map |
|
604 | dmap = self._map | |
603 | ladd = lookup.append # aka "unsure" |
|
605 | ladd = lookup.append # aka "unsure" | |
604 | madd = modified.append |
|
606 | madd = modified.append | |
605 | aadd = added.append |
|
607 | aadd = added.append | |
606 | uadd = unknown.append |
|
608 | uadd = unknown.append | |
607 | iadd = ignored.append |
|
609 | iadd = ignored.append | |
608 | radd = removed.append |
|
610 | radd = removed.append | |
609 | dadd = deleted.append |
|
611 | dadd = deleted.append | |
610 | cadd = clean.append |
|
612 | cadd = clean.append | |
611 |
|
613 | |||
612 |
for fn, st in self.walk(match, listunknown, |
|
614 | for fn, st in self.walk(match, subrepos, listunknown, | |
|
615 | listignored).iteritems(): | |||
613 | if fn not in dmap: |
|
616 | if fn not in dmap: | |
614 | if (listignored or match.exact(fn)) and self._dirignore(fn): |
|
617 | if (listignored or match.exact(fn)) and self._dirignore(fn): | |
615 | if listignored: |
|
618 | if listignored: | |
616 | iadd(fn) |
|
619 | iadd(fn) | |
617 | elif listunknown: |
|
620 | elif listunknown: | |
618 | uadd(fn) |
|
621 | uadd(fn) | |
619 | continue |
|
622 | continue | |
620 |
|
623 | |||
621 | state, mode, size, time = dmap[fn] |
|
624 | state, mode, size, time = dmap[fn] | |
622 |
|
625 | |||
623 | if not st and state in "nma": |
|
626 | if not st and state in "nma": | |
624 | dadd(fn) |
|
627 | dadd(fn) | |
625 | elif state == 'n': |
|
628 | elif state == 'n': | |
626 | if (size >= 0 and |
|
629 | if (size >= 0 and | |
627 | (size != st.st_size |
|
630 | (size != st.st_size | |
628 | or ((mode ^ st.st_mode) & 0100 and self._checkexec)) |
|
631 | or ((mode ^ st.st_mode) & 0100 and self._checkexec)) | |
629 | or size == -2 |
|
632 | or size == -2 | |
630 | or fn in self._copymap): |
|
633 | or fn in self._copymap): | |
631 | madd(fn) |
|
634 | madd(fn) | |
632 | elif time != int(st.st_mtime): |
|
635 | elif time != int(st.st_mtime): | |
633 | ladd(fn) |
|
636 | ladd(fn) | |
634 | elif listclean: |
|
637 | elif listclean: | |
635 | cadd(fn) |
|
638 | cadd(fn) | |
636 | elif state == 'm': |
|
639 | elif state == 'm': | |
637 | madd(fn) |
|
640 | madd(fn) | |
638 | elif state == 'a': |
|
641 | elif state == 'a': | |
639 | aadd(fn) |
|
642 | aadd(fn) | |
640 | elif state == 'r': |
|
643 | elif state == 'r': | |
641 | radd(fn) |
|
644 | radd(fn) | |
642 |
|
645 | |||
643 | return (lookup, modified, added, removed, deleted, unknown, ignored, |
|
646 | return (lookup, modified, added, removed, deleted, unknown, ignored, | |
644 | clean) |
|
647 | clean) |
@@ -1,2162 +1,2164 | |||||
1 | # localrepo.py - read/write repository class for mercurial |
|
1 | # localrepo.py - read/write repository class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2, incorporated herein by reference. |
|
6 | # GNU General Public License version 2, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from node import bin, hex, nullid, nullrev, short |
|
8 | from node import bin, hex, nullid, nullrev, short | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import repo, changegroup, subrepo |
|
10 | import repo, changegroup, subrepo | |
11 | import changelog, dirstate, filelog, manifest, context |
|
11 | import changelog, dirstate, filelog, manifest, context | |
12 | import lock, transaction, store, encoding |
|
12 | import lock, transaction, store, encoding | |
13 | import util, extensions, hook, error |
|
13 | import util, extensions, hook, error | |
14 | import match as match_ |
|
14 | import match as match_ | |
15 | import merge as merge_ |
|
15 | import merge as merge_ | |
16 | import tags as tags_ |
|
16 | import tags as tags_ | |
17 | from lock import release |
|
17 | from lock import release | |
18 | import weakref, stat, errno, os, time, inspect |
|
18 | import weakref, stat, errno, os, time, inspect | |
19 | propertycache = util.propertycache |
|
19 | propertycache = util.propertycache | |
20 |
|
20 | |||
21 | class localrepository(repo.repository): |
|
21 | class localrepository(repo.repository): | |
22 | capabilities = set(('lookup', 'changegroupsubset', 'branchmap')) |
|
22 | capabilities = set(('lookup', 'changegroupsubset', 'branchmap')) | |
23 | supported = set('revlogv1 store fncache shared'.split()) |
|
23 | supported = set('revlogv1 store fncache shared'.split()) | |
24 |
|
24 | |||
25 | def __init__(self, baseui, path=None, create=0): |
|
25 | def __init__(self, baseui, path=None, create=0): | |
26 | repo.repository.__init__(self) |
|
26 | repo.repository.__init__(self) | |
27 | self.root = os.path.realpath(path) |
|
27 | self.root = os.path.realpath(path) | |
28 | self.path = os.path.join(self.root, ".hg") |
|
28 | self.path = os.path.join(self.root, ".hg") | |
29 | self.origroot = path |
|
29 | self.origroot = path | |
30 | self.opener = util.opener(self.path) |
|
30 | self.opener = util.opener(self.path) | |
31 | self.wopener = util.opener(self.root) |
|
31 | self.wopener = util.opener(self.root) | |
32 | self.baseui = baseui |
|
32 | self.baseui = baseui | |
33 | self.ui = baseui.copy() |
|
33 | self.ui = baseui.copy() | |
34 |
|
34 | |||
35 | try: |
|
35 | try: | |
36 | self.ui.readconfig(self.join("hgrc"), self.root) |
|
36 | self.ui.readconfig(self.join("hgrc"), self.root) | |
37 | extensions.loadall(self.ui) |
|
37 | extensions.loadall(self.ui) | |
38 | except IOError: |
|
38 | except IOError: | |
39 | pass |
|
39 | pass | |
40 |
|
40 | |||
41 | if not os.path.isdir(self.path): |
|
41 | if not os.path.isdir(self.path): | |
42 | if create: |
|
42 | if create: | |
43 | if not os.path.exists(path): |
|
43 | if not os.path.exists(path): | |
44 | os.mkdir(path) |
|
44 | os.mkdir(path) | |
45 | os.mkdir(self.path) |
|
45 | os.mkdir(self.path) | |
46 | requirements = ["revlogv1"] |
|
46 | requirements = ["revlogv1"] | |
47 | if self.ui.configbool('format', 'usestore', True): |
|
47 | if self.ui.configbool('format', 'usestore', True): | |
48 | os.mkdir(os.path.join(self.path, "store")) |
|
48 | os.mkdir(os.path.join(self.path, "store")) | |
49 | requirements.append("store") |
|
49 | requirements.append("store") | |
50 | if self.ui.configbool('format', 'usefncache', True): |
|
50 | if self.ui.configbool('format', 'usefncache', True): | |
51 | requirements.append("fncache") |
|
51 | requirements.append("fncache") | |
52 | # create an invalid changelog |
|
52 | # create an invalid changelog | |
53 | self.opener("00changelog.i", "a").write( |
|
53 | self.opener("00changelog.i", "a").write( | |
54 | '\0\0\0\2' # represents revlogv2 |
|
54 | '\0\0\0\2' # represents revlogv2 | |
55 | ' dummy changelog to prevent using the old repo layout' |
|
55 | ' dummy changelog to prevent using the old repo layout' | |
56 | ) |
|
56 | ) | |
57 | reqfile = self.opener("requires", "w") |
|
57 | reqfile = self.opener("requires", "w") | |
58 | for r in requirements: |
|
58 | for r in requirements: | |
59 | reqfile.write("%s\n" % r) |
|
59 | reqfile.write("%s\n" % r) | |
60 | reqfile.close() |
|
60 | reqfile.close() | |
61 | else: |
|
61 | else: | |
62 | raise error.RepoError(_("repository %s not found") % path) |
|
62 | raise error.RepoError(_("repository %s not found") % path) | |
63 | elif create: |
|
63 | elif create: | |
64 | raise error.RepoError(_("repository %s already exists") % path) |
|
64 | raise error.RepoError(_("repository %s already exists") % path) | |
65 | else: |
|
65 | else: | |
66 | # find requirements |
|
66 | # find requirements | |
67 | requirements = set() |
|
67 | requirements = set() | |
68 | try: |
|
68 | try: | |
69 | requirements = set(self.opener("requires").read().splitlines()) |
|
69 | requirements = set(self.opener("requires").read().splitlines()) | |
70 | except IOError, inst: |
|
70 | except IOError, inst: | |
71 | if inst.errno != errno.ENOENT: |
|
71 | if inst.errno != errno.ENOENT: | |
72 | raise |
|
72 | raise | |
73 | for r in requirements - self.supported: |
|
73 | for r in requirements - self.supported: | |
74 | raise error.RepoError(_("requirement '%s' not supported") % r) |
|
74 | raise error.RepoError(_("requirement '%s' not supported") % r) | |
75 |
|
75 | |||
76 | self.sharedpath = self.path |
|
76 | self.sharedpath = self.path | |
77 | try: |
|
77 | try: | |
78 | s = os.path.realpath(self.opener("sharedpath").read()) |
|
78 | s = os.path.realpath(self.opener("sharedpath").read()) | |
79 | if not os.path.exists(s): |
|
79 | if not os.path.exists(s): | |
80 | raise error.RepoError( |
|
80 | raise error.RepoError( | |
81 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
81 | _('.hg/sharedpath points to nonexistent directory %s') % s) | |
82 | self.sharedpath = s |
|
82 | self.sharedpath = s | |
83 | except IOError, inst: |
|
83 | except IOError, inst: | |
84 | if inst.errno != errno.ENOENT: |
|
84 | if inst.errno != errno.ENOENT: | |
85 | raise |
|
85 | raise | |
86 |
|
86 | |||
87 | self.store = store.store(requirements, self.sharedpath, util.opener) |
|
87 | self.store = store.store(requirements, self.sharedpath, util.opener) | |
88 | self.spath = self.store.path |
|
88 | self.spath = self.store.path | |
89 | self.sopener = self.store.opener |
|
89 | self.sopener = self.store.opener | |
90 | self.sjoin = self.store.join |
|
90 | self.sjoin = self.store.join | |
91 | self.opener.createmode = self.store.createmode |
|
91 | self.opener.createmode = self.store.createmode | |
92 |
|
92 | |||
93 | # These two define the set of tags for this repository. _tags |
|
93 | # These two define the set of tags for this repository. _tags | |
94 | # maps tag name to node; _tagtypes maps tag name to 'global' or |
|
94 | # maps tag name to node; _tagtypes maps tag name to 'global' or | |
95 | # 'local'. (Global tags are defined by .hgtags across all |
|
95 | # 'local'. (Global tags are defined by .hgtags across all | |
96 | # heads, and local tags are defined in .hg/localtags.) They |
|
96 | # heads, and local tags are defined in .hg/localtags.) They | |
97 | # constitute the in-memory cache of tags. |
|
97 | # constitute the in-memory cache of tags. | |
98 | self._tags = None |
|
98 | self._tags = None | |
99 | self._tagtypes = None |
|
99 | self._tagtypes = None | |
100 |
|
100 | |||
101 | self._branchcache = None # in UTF-8 |
|
101 | self._branchcache = None # in UTF-8 | |
102 | self._branchcachetip = None |
|
102 | self._branchcachetip = None | |
103 | self.nodetagscache = None |
|
103 | self.nodetagscache = None | |
104 | self.filterpats = {} |
|
104 | self.filterpats = {} | |
105 | self._datafilters = {} |
|
105 | self._datafilters = {} | |
106 | self._transref = self._lockref = self._wlockref = None |
|
106 | self._transref = self._lockref = self._wlockref = None | |
107 |
|
107 | |||
108 | @propertycache |
|
108 | @propertycache | |
109 | def changelog(self): |
|
109 | def changelog(self): | |
110 | c = changelog.changelog(self.sopener) |
|
110 | c = changelog.changelog(self.sopener) | |
111 | if 'HG_PENDING' in os.environ: |
|
111 | if 'HG_PENDING' in os.environ: | |
112 | p = os.environ['HG_PENDING'] |
|
112 | p = os.environ['HG_PENDING'] | |
113 | if p.startswith(self.root): |
|
113 | if p.startswith(self.root): | |
114 | c.readpending('00changelog.i.a') |
|
114 | c.readpending('00changelog.i.a') | |
115 | self.sopener.defversion = c.version |
|
115 | self.sopener.defversion = c.version | |
116 | return c |
|
116 | return c | |
117 |
|
117 | |||
118 | @propertycache |
|
118 | @propertycache | |
119 | def manifest(self): |
|
119 | def manifest(self): | |
120 | return manifest.manifest(self.sopener) |
|
120 | return manifest.manifest(self.sopener) | |
121 |
|
121 | |||
122 | @propertycache |
|
122 | @propertycache | |
123 | def dirstate(self): |
|
123 | def dirstate(self): | |
124 | return dirstate.dirstate(self.opener, self.ui, self.root) |
|
124 | return dirstate.dirstate(self.opener, self.ui, self.root) | |
125 |
|
125 | |||
126 | def __getitem__(self, changeid): |
|
126 | def __getitem__(self, changeid): | |
127 | if changeid is None: |
|
127 | if changeid is None: | |
128 | return context.workingctx(self) |
|
128 | return context.workingctx(self) | |
129 | return context.changectx(self, changeid) |
|
129 | return context.changectx(self, changeid) | |
130 |
|
130 | |||
131 | def __contains__(self, changeid): |
|
131 | def __contains__(self, changeid): | |
132 | try: |
|
132 | try: | |
133 | return bool(self.lookup(changeid)) |
|
133 | return bool(self.lookup(changeid)) | |
134 | except error.RepoLookupError: |
|
134 | except error.RepoLookupError: | |
135 | return False |
|
135 | return False | |
136 |
|
136 | |||
137 | def __nonzero__(self): |
|
137 | def __nonzero__(self): | |
138 | return True |
|
138 | return True | |
139 |
|
139 | |||
140 | def __len__(self): |
|
140 | def __len__(self): | |
141 | return len(self.changelog) |
|
141 | return len(self.changelog) | |
142 |
|
142 | |||
143 | def __iter__(self): |
|
143 | def __iter__(self): | |
144 | for i in xrange(len(self)): |
|
144 | for i in xrange(len(self)): | |
145 | yield i |
|
145 | yield i | |
146 |
|
146 | |||
147 | def url(self): |
|
147 | def url(self): | |
148 | return 'file:' + self.root |
|
148 | return 'file:' + self.root | |
149 |
|
149 | |||
150 | def hook(self, name, throw=False, **args): |
|
150 | def hook(self, name, throw=False, **args): | |
151 | return hook.hook(self.ui, self, name, throw, **args) |
|
151 | return hook.hook(self.ui, self, name, throw, **args) | |
152 |
|
152 | |||
153 | tag_disallowed = ':\r\n' |
|
153 | tag_disallowed = ':\r\n' | |
154 |
|
154 | |||
155 | def _tag(self, names, node, message, local, user, date, extra={}): |
|
155 | def _tag(self, names, node, message, local, user, date, extra={}): | |
156 | if isinstance(names, str): |
|
156 | if isinstance(names, str): | |
157 | allchars = names |
|
157 | allchars = names | |
158 | names = (names,) |
|
158 | names = (names,) | |
159 | else: |
|
159 | else: | |
160 | allchars = ''.join(names) |
|
160 | allchars = ''.join(names) | |
161 | for c in self.tag_disallowed: |
|
161 | for c in self.tag_disallowed: | |
162 | if c in allchars: |
|
162 | if c in allchars: | |
163 | raise util.Abort(_('%r cannot be used in a tag name') % c) |
|
163 | raise util.Abort(_('%r cannot be used in a tag name') % c) | |
164 |
|
164 | |||
165 | for name in names: |
|
165 | for name in names: | |
166 | self.hook('pretag', throw=True, node=hex(node), tag=name, |
|
166 | self.hook('pretag', throw=True, node=hex(node), tag=name, | |
167 | local=local) |
|
167 | local=local) | |
168 |
|
168 | |||
169 | def writetags(fp, names, munge, prevtags): |
|
169 | def writetags(fp, names, munge, prevtags): | |
170 | fp.seek(0, 2) |
|
170 | fp.seek(0, 2) | |
171 | if prevtags and prevtags[-1] != '\n': |
|
171 | if prevtags and prevtags[-1] != '\n': | |
172 | fp.write('\n') |
|
172 | fp.write('\n') | |
173 | for name in names: |
|
173 | for name in names: | |
174 | m = munge and munge(name) or name |
|
174 | m = munge and munge(name) or name | |
175 | if self._tagtypes and name in self._tagtypes: |
|
175 | if self._tagtypes and name in self._tagtypes: | |
176 | old = self._tags.get(name, nullid) |
|
176 | old = self._tags.get(name, nullid) | |
177 | fp.write('%s %s\n' % (hex(old), m)) |
|
177 | fp.write('%s %s\n' % (hex(old), m)) | |
178 | fp.write('%s %s\n' % (hex(node), m)) |
|
178 | fp.write('%s %s\n' % (hex(node), m)) | |
179 | fp.close() |
|
179 | fp.close() | |
180 |
|
180 | |||
181 | prevtags = '' |
|
181 | prevtags = '' | |
182 | if local: |
|
182 | if local: | |
183 | try: |
|
183 | try: | |
184 | fp = self.opener('localtags', 'r+') |
|
184 | fp = self.opener('localtags', 'r+') | |
185 | except IOError: |
|
185 | except IOError: | |
186 | fp = self.opener('localtags', 'a') |
|
186 | fp = self.opener('localtags', 'a') | |
187 | else: |
|
187 | else: | |
188 | prevtags = fp.read() |
|
188 | prevtags = fp.read() | |
189 |
|
189 | |||
190 | # local tags are stored in the current charset |
|
190 | # local tags are stored in the current charset | |
191 | writetags(fp, names, None, prevtags) |
|
191 | writetags(fp, names, None, prevtags) | |
192 | for name in names: |
|
192 | for name in names: | |
193 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
193 | self.hook('tag', node=hex(node), tag=name, local=local) | |
194 | return |
|
194 | return | |
195 |
|
195 | |||
196 | try: |
|
196 | try: | |
197 | fp = self.wfile('.hgtags', 'rb+') |
|
197 | fp = self.wfile('.hgtags', 'rb+') | |
198 | except IOError: |
|
198 | except IOError: | |
199 | fp = self.wfile('.hgtags', 'ab') |
|
199 | fp = self.wfile('.hgtags', 'ab') | |
200 | else: |
|
200 | else: | |
201 | prevtags = fp.read() |
|
201 | prevtags = fp.read() | |
202 |
|
202 | |||
203 | # committed tags are stored in UTF-8 |
|
203 | # committed tags are stored in UTF-8 | |
204 | writetags(fp, names, encoding.fromlocal, prevtags) |
|
204 | writetags(fp, names, encoding.fromlocal, prevtags) | |
205 |
|
205 | |||
206 | if '.hgtags' not in self.dirstate: |
|
206 | if '.hgtags' not in self.dirstate: | |
207 | self.add(['.hgtags']) |
|
207 | self.add(['.hgtags']) | |
208 |
|
208 | |||
209 | m = match_.exact(self.root, '', ['.hgtags']) |
|
209 | m = match_.exact(self.root, '', ['.hgtags']) | |
210 | tagnode = self.commit(message, user, date, extra=extra, match=m) |
|
210 | tagnode = self.commit(message, user, date, extra=extra, match=m) | |
211 |
|
211 | |||
212 | for name in names: |
|
212 | for name in names: | |
213 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
213 | self.hook('tag', node=hex(node), tag=name, local=local) | |
214 |
|
214 | |||
215 | return tagnode |
|
215 | return tagnode | |
216 |
|
216 | |||
217 | def tag(self, names, node, message, local, user, date): |
|
217 | def tag(self, names, node, message, local, user, date): | |
218 | '''tag a revision with one or more symbolic names. |
|
218 | '''tag a revision with one or more symbolic names. | |
219 |
|
219 | |||
220 | names is a list of strings or, when adding a single tag, names may be a |
|
220 | names is a list of strings or, when adding a single tag, names may be a | |
221 | string. |
|
221 | string. | |
222 |
|
222 | |||
223 | if local is True, the tags are stored in a per-repository file. |
|
223 | if local is True, the tags are stored in a per-repository file. | |
224 | otherwise, they are stored in the .hgtags file, and a new |
|
224 | otherwise, they are stored in the .hgtags file, and a new | |
225 | changeset is committed with the change. |
|
225 | changeset is committed with the change. | |
226 |
|
226 | |||
227 | keyword arguments: |
|
227 | keyword arguments: | |
228 |
|
228 | |||
229 | local: whether to store tags in non-version-controlled file |
|
229 | local: whether to store tags in non-version-controlled file | |
230 | (default False) |
|
230 | (default False) | |
231 |
|
231 | |||
232 | message: commit message to use if committing |
|
232 | message: commit message to use if committing | |
233 |
|
233 | |||
234 | user: name of user to use if committing |
|
234 | user: name of user to use if committing | |
235 |
|
235 | |||
236 | date: date tuple to use if committing''' |
|
236 | date: date tuple to use if committing''' | |
237 |
|
237 | |||
238 | for x in self.status()[:5]: |
|
238 | for x in self.status()[:5]: | |
239 | if '.hgtags' in x: |
|
239 | if '.hgtags' in x: | |
240 | raise util.Abort(_('working copy of .hgtags is changed ' |
|
240 | raise util.Abort(_('working copy of .hgtags is changed ' | |
241 | '(please commit .hgtags manually)')) |
|
241 | '(please commit .hgtags manually)')) | |
242 |
|
242 | |||
243 | self.tags() # instantiate the cache |
|
243 | self.tags() # instantiate the cache | |
244 | self._tag(names, node, message, local, user, date) |
|
244 | self._tag(names, node, message, local, user, date) | |
245 |
|
245 | |||
246 | def tags(self): |
|
246 | def tags(self): | |
247 | '''return a mapping of tag to node''' |
|
247 | '''return a mapping of tag to node''' | |
248 | if self._tags is None: |
|
248 | if self._tags is None: | |
249 | (self._tags, self._tagtypes) = self._findtags() |
|
249 | (self._tags, self._tagtypes) = self._findtags() | |
250 |
|
250 | |||
251 | return self._tags |
|
251 | return self._tags | |
252 |
|
252 | |||
253 | def _findtags(self): |
|
253 | def _findtags(self): | |
254 | '''Do the hard work of finding tags. Return a pair of dicts |
|
254 | '''Do the hard work of finding tags. Return a pair of dicts | |
255 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
255 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
256 | maps tag name to a string like \'global\' or \'local\'. |
|
256 | maps tag name to a string like \'global\' or \'local\'. | |
257 | Subclasses or extensions are free to add their own tags, but |
|
257 | Subclasses or extensions are free to add their own tags, but | |
258 | should be aware that the returned dicts will be retained for the |
|
258 | should be aware that the returned dicts will be retained for the | |
259 | duration of the localrepo object.''' |
|
259 | duration of the localrepo object.''' | |
260 |
|
260 | |||
261 | # XXX what tagtype should subclasses/extensions use? Currently |
|
261 | # XXX what tagtype should subclasses/extensions use? Currently | |
262 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
262 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
263 | # Should each extension invent its own tag type? Should there |
|
263 | # Should each extension invent its own tag type? Should there | |
264 | # be one tagtype for all such "virtual" tags? Or is the status |
|
264 | # be one tagtype for all such "virtual" tags? Or is the status | |
265 | # quo fine? |
|
265 | # quo fine? | |
266 |
|
266 | |||
267 | alltags = {} # map tag name to (node, hist) |
|
267 | alltags = {} # map tag name to (node, hist) | |
268 | tagtypes = {} |
|
268 | tagtypes = {} | |
269 |
|
269 | |||
270 | tags_.findglobaltags(self.ui, self, alltags, tagtypes) |
|
270 | tags_.findglobaltags(self.ui, self, alltags, tagtypes) | |
271 | tags_.readlocaltags(self.ui, self, alltags, tagtypes) |
|
271 | tags_.readlocaltags(self.ui, self, alltags, tagtypes) | |
272 |
|
272 | |||
273 | # Build the return dicts. Have to re-encode tag names because |
|
273 | # Build the return dicts. Have to re-encode tag names because | |
274 | # the tags module always uses UTF-8 (in order not to lose info |
|
274 | # the tags module always uses UTF-8 (in order not to lose info | |
275 | # writing to the cache), but the rest of Mercurial wants them in |
|
275 | # writing to the cache), but the rest of Mercurial wants them in | |
276 | # local encoding. |
|
276 | # local encoding. | |
277 | tags = {} |
|
277 | tags = {} | |
278 | for (name, (node, hist)) in alltags.iteritems(): |
|
278 | for (name, (node, hist)) in alltags.iteritems(): | |
279 | if node != nullid: |
|
279 | if node != nullid: | |
280 | tags[encoding.tolocal(name)] = node |
|
280 | tags[encoding.tolocal(name)] = node | |
281 | tags['tip'] = self.changelog.tip() |
|
281 | tags['tip'] = self.changelog.tip() | |
282 | tagtypes = dict([(encoding.tolocal(name), value) |
|
282 | tagtypes = dict([(encoding.tolocal(name), value) | |
283 | for (name, value) in tagtypes.iteritems()]) |
|
283 | for (name, value) in tagtypes.iteritems()]) | |
284 | return (tags, tagtypes) |
|
284 | return (tags, tagtypes) | |
285 |
|
285 | |||
286 | def tagtype(self, tagname): |
|
286 | def tagtype(self, tagname): | |
287 | ''' |
|
287 | ''' | |
288 | return the type of the given tag. result can be: |
|
288 | return the type of the given tag. result can be: | |
289 |
|
289 | |||
290 | 'local' : a local tag |
|
290 | 'local' : a local tag | |
291 | 'global' : a global tag |
|
291 | 'global' : a global tag | |
292 | None : tag does not exist |
|
292 | None : tag does not exist | |
293 | ''' |
|
293 | ''' | |
294 |
|
294 | |||
295 | self.tags() |
|
295 | self.tags() | |
296 |
|
296 | |||
297 | return self._tagtypes.get(tagname) |
|
297 | return self._tagtypes.get(tagname) | |
298 |
|
298 | |||
299 | def tagslist(self): |
|
299 | def tagslist(self): | |
300 | '''return a list of tags ordered by revision''' |
|
300 | '''return a list of tags ordered by revision''' | |
301 | l = [] |
|
301 | l = [] | |
302 | for t, n in self.tags().iteritems(): |
|
302 | for t, n in self.tags().iteritems(): | |
303 | try: |
|
303 | try: | |
304 | r = self.changelog.rev(n) |
|
304 | r = self.changelog.rev(n) | |
305 | except: |
|
305 | except: | |
306 | r = -2 # sort to the beginning of the list if unknown |
|
306 | r = -2 # sort to the beginning of the list if unknown | |
307 | l.append((r, t, n)) |
|
307 | l.append((r, t, n)) | |
308 | return [(t, n) for r, t, n in sorted(l)] |
|
308 | return [(t, n) for r, t, n in sorted(l)] | |
309 |
|
309 | |||
310 | def nodetags(self, node): |
|
310 | def nodetags(self, node): | |
311 | '''return the tags associated with a node''' |
|
311 | '''return the tags associated with a node''' | |
312 | if not self.nodetagscache: |
|
312 | if not self.nodetagscache: | |
313 | self.nodetagscache = {} |
|
313 | self.nodetagscache = {} | |
314 | for t, n in self.tags().iteritems(): |
|
314 | for t, n in self.tags().iteritems(): | |
315 | self.nodetagscache.setdefault(n, []).append(t) |
|
315 | self.nodetagscache.setdefault(n, []).append(t) | |
316 | return self.nodetagscache.get(node, []) |
|
316 | return self.nodetagscache.get(node, []) | |
317 |
|
317 | |||
318 | def _branchtags(self, partial, lrev): |
|
318 | def _branchtags(self, partial, lrev): | |
319 | # TODO: rename this function? |
|
319 | # TODO: rename this function? | |
320 | tiprev = len(self) - 1 |
|
320 | tiprev = len(self) - 1 | |
321 | if lrev != tiprev: |
|
321 | if lrev != tiprev: | |
322 | self._updatebranchcache(partial, lrev+1, tiprev+1) |
|
322 | self._updatebranchcache(partial, lrev+1, tiprev+1) | |
323 | self._writebranchcache(partial, self.changelog.tip(), tiprev) |
|
323 | self._writebranchcache(partial, self.changelog.tip(), tiprev) | |
324 |
|
324 | |||
325 | return partial |
|
325 | return partial | |
326 |
|
326 | |||
327 | def branchmap(self): |
|
327 | def branchmap(self): | |
328 | tip = self.changelog.tip() |
|
328 | tip = self.changelog.tip() | |
329 | if self._branchcache is not None and self._branchcachetip == tip: |
|
329 | if self._branchcache is not None and self._branchcachetip == tip: | |
330 | return self._branchcache |
|
330 | return self._branchcache | |
331 |
|
331 | |||
332 | oldtip = self._branchcachetip |
|
332 | oldtip = self._branchcachetip | |
333 | self._branchcachetip = tip |
|
333 | self._branchcachetip = tip | |
334 | if oldtip is None or oldtip not in self.changelog.nodemap: |
|
334 | if oldtip is None or oldtip not in self.changelog.nodemap: | |
335 | partial, last, lrev = self._readbranchcache() |
|
335 | partial, last, lrev = self._readbranchcache() | |
336 | else: |
|
336 | else: | |
337 | lrev = self.changelog.rev(oldtip) |
|
337 | lrev = self.changelog.rev(oldtip) | |
338 | partial = self._branchcache |
|
338 | partial = self._branchcache | |
339 |
|
339 | |||
340 | self._branchtags(partial, lrev) |
|
340 | self._branchtags(partial, lrev) | |
341 | # this private cache holds all heads (not just tips) |
|
341 | # this private cache holds all heads (not just tips) | |
342 | self._branchcache = partial |
|
342 | self._branchcache = partial | |
343 |
|
343 | |||
344 | return self._branchcache |
|
344 | return self._branchcache | |
345 |
|
345 | |||
346 | def branchtags(self): |
|
346 | def branchtags(self): | |
347 | '''return a dict where branch names map to the tipmost head of |
|
347 | '''return a dict where branch names map to the tipmost head of | |
348 | the branch, open heads come before closed''' |
|
348 | the branch, open heads come before closed''' | |
349 | bt = {} |
|
349 | bt = {} | |
350 | for bn, heads in self.branchmap().iteritems(): |
|
350 | for bn, heads in self.branchmap().iteritems(): | |
351 | head = None |
|
351 | head = None | |
352 | for i in range(len(heads)-1, -1, -1): |
|
352 | for i in range(len(heads)-1, -1, -1): | |
353 | h = heads[i] |
|
353 | h = heads[i] | |
354 | if 'close' not in self.changelog.read(h)[5]: |
|
354 | if 'close' not in self.changelog.read(h)[5]: | |
355 | head = h |
|
355 | head = h | |
356 | break |
|
356 | break | |
357 | # no open heads were found |
|
357 | # no open heads were found | |
358 | if head is None: |
|
358 | if head is None: | |
359 | head = heads[-1] |
|
359 | head = heads[-1] | |
360 | bt[bn] = head |
|
360 | bt[bn] = head | |
361 | return bt |
|
361 | return bt | |
362 |
|
362 | |||
363 |
|
363 | |||
364 | def _readbranchcache(self): |
|
364 | def _readbranchcache(self): | |
365 | partial = {} |
|
365 | partial = {} | |
366 | try: |
|
366 | try: | |
367 | f = self.opener("branchheads.cache") |
|
367 | f = self.opener("branchheads.cache") | |
368 | lines = f.read().split('\n') |
|
368 | lines = f.read().split('\n') | |
369 | f.close() |
|
369 | f.close() | |
370 | except (IOError, OSError): |
|
370 | except (IOError, OSError): | |
371 | return {}, nullid, nullrev |
|
371 | return {}, nullid, nullrev | |
372 |
|
372 | |||
373 | try: |
|
373 | try: | |
374 | last, lrev = lines.pop(0).split(" ", 1) |
|
374 | last, lrev = lines.pop(0).split(" ", 1) | |
375 | last, lrev = bin(last), int(lrev) |
|
375 | last, lrev = bin(last), int(lrev) | |
376 | if lrev >= len(self) or self[lrev].node() != last: |
|
376 | if lrev >= len(self) or self[lrev].node() != last: | |
377 | # invalidate the cache |
|
377 | # invalidate the cache | |
378 | raise ValueError('invalidating branch cache (tip differs)') |
|
378 | raise ValueError('invalidating branch cache (tip differs)') | |
379 | for l in lines: |
|
379 | for l in lines: | |
380 | if not l: continue |
|
380 | if not l: continue | |
381 | node, label = l.split(" ", 1) |
|
381 | node, label = l.split(" ", 1) | |
382 | partial.setdefault(label.strip(), []).append(bin(node)) |
|
382 | partial.setdefault(label.strip(), []).append(bin(node)) | |
383 | except KeyboardInterrupt: |
|
383 | except KeyboardInterrupt: | |
384 | raise |
|
384 | raise | |
385 | except Exception, inst: |
|
385 | except Exception, inst: | |
386 | if self.ui.debugflag: |
|
386 | if self.ui.debugflag: | |
387 | self.ui.warn(str(inst), '\n') |
|
387 | self.ui.warn(str(inst), '\n') | |
388 | partial, last, lrev = {}, nullid, nullrev |
|
388 | partial, last, lrev = {}, nullid, nullrev | |
389 | return partial, last, lrev |
|
389 | return partial, last, lrev | |
390 |
|
390 | |||
391 | def _writebranchcache(self, branches, tip, tiprev): |
|
391 | def _writebranchcache(self, branches, tip, tiprev): | |
392 | try: |
|
392 | try: | |
393 | f = self.opener("branchheads.cache", "w", atomictemp=True) |
|
393 | f = self.opener("branchheads.cache", "w", atomictemp=True) | |
394 | f.write("%s %s\n" % (hex(tip), tiprev)) |
|
394 | f.write("%s %s\n" % (hex(tip), tiprev)) | |
395 | for label, nodes in branches.iteritems(): |
|
395 | for label, nodes in branches.iteritems(): | |
396 | for node in nodes: |
|
396 | for node in nodes: | |
397 | f.write("%s %s\n" % (hex(node), label)) |
|
397 | f.write("%s %s\n" % (hex(node), label)) | |
398 | f.rename() |
|
398 | f.rename() | |
399 | except (IOError, OSError): |
|
399 | except (IOError, OSError): | |
400 | pass |
|
400 | pass | |
401 |
|
401 | |||
402 | def _updatebranchcache(self, partial, start, end): |
|
402 | def _updatebranchcache(self, partial, start, end): | |
403 | # collect new branch entries |
|
403 | # collect new branch entries | |
404 | newbranches = {} |
|
404 | newbranches = {} | |
405 | for r in xrange(start, end): |
|
405 | for r in xrange(start, end): | |
406 | c = self[r] |
|
406 | c = self[r] | |
407 | newbranches.setdefault(c.branch(), []).append(c.node()) |
|
407 | newbranches.setdefault(c.branch(), []).append(c.node()) | |
408 | # if older branchheads are reachable from new ones, they aren't |
|
408 | # if older branchheads are reachable from new ones, they aren't | |
409 | # really branchheads. Note checking parents is insufficient: |
|
409 | # really branchheads. Note checking parents is insufficient: | |
410 | # 1 (branch a) -> 2 (branch b) -> 3 (branch a) |
|
410 | # 1 (branch a) -> 2 (branch b) -> 3 (branch a) | |
411 | for branch, newnodes in newbranches.iteritems(): |
|
411 | for branch, newnodes in newbranches.iteritems(): | |
412 | bheads = partial.setdefault(branch, []) |
|
412 | bheads = partial.setdefault(branch, []) | |
413 | bheads.extend(newnodes) |
|
413 | bheads.extend(newnodes) | |
414 | if len(bheads) < 2: |
|
414 | if len(bheads) < 2: | |
415 | continue |
|
415 | continue | |
416 | newbheads = [] |
|
416 | newbheads = [] | |
417 | # starting from tip means fewer passes over reachable |
|
417 | # starting from tip means fewer passes over reachable | |
418 | while newnodes: |
|
418 | while newnodes: | |
419 | latest = newnodes.pop() |
|
419 | latest = newnodes.pop() | |
420 | if latest not in bheads: |
|
420 | if latest not in bheads: | |
421 | continue |
|
421 | continue | |
422 | minbhrev = self[min([self[bh].rev() for bh in bheads])].node() |
|
422 | minbhrev = self[min([self[bh].rev() for bh in bheads])].node() | |
423 | reachable = self.changelog.reachable(latest, minbhrev) |
|
423 | reachable = self.changelog.reachable(latest, minbhrev) | |
424 | bheads = [b for b in bheads if b not in reachable] |
|
424 | bheads = [b for b in bheads if b not in reachable] | |
425 | newbheads.insert(0, latest) |
|
425 | newbheads.insert(0, latest) | |
426 | bheads.extend(newbheads) |
|
426 | bheads.extend(newbheads) | |
427 | partial[branch] = bheads |
|
427 | partial[branch] = bheads | |
428 |
|
428 | |||
429 | def lookup(self, key): |
|
429 | def lookup(self, key): | |
430 | if isinstance(key, int): |
|
430 | if isinstance(key, int): | |
431 | return self.changelog.node(key) |
|
431 | return self.changelog.node(key) | |
432 | elif key == '.': |
|
432 | elif key == '.': | |
433 | return self.dirstate.parents()[0] |
|
433 | return self.dirstate.parents()[0] | |
434 | elif key == 'null': |
|
434 | elif key == 'null': | |
435 | return nullid |
|
435 | return nullid | |
436 | elif key == 'tip': |
|
436 | elif key == 'tip': | |
437 | return self.changelog.tip() |
|
437 | return self.changelog.tip() | |
438 | n = self.changelog._match(key) |
|
438 | n = self.changelog._match(key) | |
439 | if n: |
|
439 | if n: | |
440 | return n |
|
440 | return n | |
441 | if key in self.tags(): |
|
441 | if key in self.tags(): | |
442 | return self.tags()[key] |
|
442 | return self.tags()[key] | |
443 | if key in self.branchtags(): |
|
443 | if key in self.branchtags(): | |
444 | return self.branchtags()[key] |
|
444 | return self.branchtags()[key] | |
445 | n = self.changelog._partialmatch(key) |
|
445 | n = self.changelog._partialmatch(key) | |
446 | if n: |
|
446 | if n: | |
447 | return n |
|
447 | return n | |
448 |
|
448 | |||
449 | # can't find key, check if it might have come from damaged dirstate |
|
449 | # can't find key, check if it might have come from damaged dirstate | |
450 | if key in self.dirstate.parents(): |
|
450 | if key in self.dirstate.parents(): | |
451 | raise error.Abort(_("working directory has unknown parent '%s'!") |
|
451 | raise error.Abort(_("working directory has unknown parent '%s'!") | |
452 | % short(key)) |
|
452 | % short(key)) | |
453 | try: |
|
453 | try: | |
454 | if len(key) == 20: |
|
454 | if len(key) == 20: | |
455 | key = hex(key) |
|
455 | key = hex(key) | |
456 | except: |
|
456 | except: | |
457 | pass |
|
457 | pass | |
458 | raise error.RepoLookupError(_("unknown revision '%s'") % key) |
|
458 | raise error.RepoLookupError(_("unknown revision '%s'") % key) | |
459 |
|
459 | |||
460 | def local(self): |
|
460 | def local(self): | |
461 | return True |
|
461 | return True | |
462 |
|
462 | |||
463 | def join(self, f): |
|
463 | def join(self, f): | |
464 | return os.path.join(self.path, f) |
|
464 | return os.path.join(self.path, f) | |
465 |
|
465 | |||
466 | def wjoin(self, f): |
|
466 | def wjoin(self, f): | |
467 | return os.path.join(self.root, f) |
|
467 | return os.path.join(self.root, f) | |
468 |
|
468 | |||
469 | def rjoin(self, f): |
|
469 | def rjoin(self, f): | |
470 | return os.path.join(self.root, util.pconvert(f)) |
|
470 | return os.path.join(self.root, util.pconvert(f)) | |
471 |
|
471 | |||
472 | def file(self, f): |
|
472 | def file(self, f): | |
473 | if f[0] == '/': |
|
473 | if f[0] == '/': | |
474 | f = f[1:] |
|
474 | f = f[1:] | |
475 | return filelog.filelog(self.sopener, f) |
|
475 | return filelog.filelog(self.sopener, f) | |
476 |
|
476 | |||
477 | def changectx(self, changeid): |
|
477 | def changectx(self, changeid): | |
478 | return self[changeid] |
|
478 | return self[changeid] | |
479 |
|
479 | |||
480 | def parents(self, changeid=None): |
|
480 | def parents(self, changeid=None): | |
481 | '''get list of changectxs for parents of changeid''' |
|
481 | '''get list of changectxs for parents of changeid''' | |
482 | return self[changeid].parents() |
|
482 | return self[changeid].parents() | |
483 |
|
483 | |||
484 | def filectx(self, path, changeid=None, fileid=None): |
|
484 | def filectx(self, path, changeid=None, fileid=None): | |
485 | """changeid can be a changeset revision, node, or tag. |
|
485 | """changeid can be a changeset revision, node, or tag. | |
486 | fileid can be a file revision or node.""" |
|
486 | fileid can be a file revision or node.""" | |
487 | return context.filectx(self, path, changeid, fileid) |
|
487 | return context.filectx(self, path, changeid, fileid) | |
488 |
|
488 | |||
489 | def getcwd(self): |
|
489 | def getcwd(self): | |
490 | return self.dirstate.getcwd() |
|
490 | return self.dirstate.getcwd() | |
491 |
|
491 | |||
492 | def pathto(self, f, cwd=None): |
|
492 | def pathto(self, f, cwd=None): | |
493 | return self.dirstate.pathto(f, cwd) |
|
493 | return self.dirstate.pathto(f, cwd) | |
494 |
|
494 | |||
495 | def wfile(self, f, mode='r'): |
|
495 | def wfile(self, f, mode='r'): | |
496 | return self.wopener(f, mode) |
|
496 | return self.wopener(f, mode) | |
497 |
|
497 | |||
498 | def _link(self, f): |
|
498 | def _link(self, f): | |
499 | return os.path.islink(self.wjoin(f)) |
|
499 | return os.path.islink(self.wjoin(f)) | |
500 |
|
500 | |||
501 | def _filter(self, filter, filename, data): |
|
501 | def _filter(self, filter, filename, data): | |
502 | if filter not in self.filterpats: |
|
502 | if filter not in self.filterpats: | |
503 | l = [] |
|
503 | l = [] | |
504 | for pat, cmd in self.ui.configitems(filter): |
|
504 | for pat, cmd in self.ui.configitems(filter): | |
505 | if cmd == '!': |
|
505 | if cmd == '!': | |
506 | continue |
|
506 | continue | |
507 | mf = match_.match(self.root, '', [pat]) |
|
507 | mf = match_.match(self.root, '', [pat]) | |
508 | fn = None |
|
508 | fn = None | |
509 | params = cmd |
|
509 | params = cmd | |
510 | for name, filterfn in self._datafilters.iteritems(): |
|
510 | for name, filterfn in self._datafilters.iteritems(): | |
511 | if cmd.startswith(name): |
|
511 | if cmd.startswith(name): | |
512 | fn = filterfn |
|
512 | fn = filterfn | |
513 | params = cmd[len(name):].lstrip() |
|
513 | params = cmd[len(name):].lstrip() | |
514 | break |
|
514 | break | |
515 | if not fn: |
|
515 | if not fn: | |
516 | fn = lambda s, c, **kwargs: util.filter(s, c) |
|
516 | fn = lambda s, c, **kwargs: util.filter(s, c) | |
517 | # Wrap old filters not supporting keyword arguments |
|
517 | # Wrap old filters not supporting keyword arguments | |
518 | if not inspect.getargspec(fn)[2]: |
|
518 | if not inspect.getargspec(fn)[2]: | |
519 | oldfn = fn |
|
519 | oldfn = fn | |
520 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
520 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
521 | l.append((mf, fn, params)) |
|
521 | l.append((mf, fn, params)) | |
522 | self.filterpats[filter] = l |
|
522 | self.filterpats[filter] = l | |
523 |
|
523 | |||
524 | for mf, fn, cmd in self.filterpats[filter]: |
|
524 | for mf, fn, cmd in self.filterpats[filter]: | |
525 | if mf(filename): |
|
525 | if mf(filename): | |
526 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
526 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
527 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
527 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
528 | break |
|
528 | break | |
529 |
|
529 | |||
530 | return data |
|
530 | return data | |
531 |
|
531 | |||
532 | def adddatafilter(self, name, filter): |
|
532 | def adddatafilter(self, name, filter): | |
533 | self._datafilters[name] = filter |
|
533 | self._datafilters[name] = filter | |
534 |
|
534 | |||
535 | def wread(self, filename): |
|
535 | def wread(self, filename): | |
536 | if self._link(filename): |
|
536 | if self._link(filename): | |
537 | data = os.readlink(self.wjoin(filename)) |
|
537 | data = os.readlink(self.wjoin(filename)) | |
538 | else: |
|
538 | else: | |
539 | data = self.wopener(filename, 'r').read() |
|
539 | data = self.wopener(filename, 'r').read() | |
540 | return self._filter("encode", filename, data) |
|
540 | return self._filter("encode", filename, data) | |
541 |
|
541 | |||
542 | def wwrite(self, filename, data, flags): |
|
542 | def wwrite(self, filename, data, flags): | |
543 | data = self._filter("decode", filename, data) |
|
543 | data = self._filter("decode", filename, data) | |
544 | try: |
|
544 | try: | |
545 | os.unlink(self.wjoin(filename)) |
|
545 | os.unlink(self.wjoin(filename)) | |
546 | except OSError: |
|
546 | except OSError: | |
547 | pass |
|
547 | pass | |
548 | if 'l' in flags: |
|
548 | if 'l' in flags: | |
549 | self.wopener.symlink(data, filename) |
|
549 | self.wopener.symlink(data, filename) | |
550 | else: |
|
550 | else: | |
551 | self.wopener(filename, 'w').write(data) |
|
551 | self.wopener(filename, 'w').write(data) | |
552 | if 'x' in flags: |
|
552 | if 'x' in flags: | |
553 | util.set_flags(self.wjoin(filename), False, True) |
|
553 | util.set_flags(self.wjoin(filename), False, True) | |
554 |
|
554 | |||
555 | def wwritedata(self, filename, data): |
|
555 | def wwritedata(self, filename, data): | |
556 | return self._filter("decode", filename, data) |
|
556 | return self._filter("decode", filename, data) | |
557 |
|
557 | |||
558 | def transaction(self): |
|
558 | def transaction(self): | |
559 | tr = self._transref and self._transref() or None |
|
559 | tr = self._transref and self._transref() or None | |
560 | if tr and tr.running(): |
|
560 | if tr and tr.running(): | |
561 | return tr.nest() |
|
561 | return tr.nest() | |
562 |
|
562 | |||
563 | # abort here if the journal already exists |
|
563 | # abort here if the journal already exists | |
564 | if os.path.exists(self.sjoin("journal")): |
|
564 | if os.path.exists(self.sjoin("journal")): | |
565 | raise error.RepoError(_("abandoned transaction found - run hg recover")) |
|
565 | raise error.RepoError(_("abandoned transaction found - run hg recover")) | |
566 |
|
566 | |||
567 | # save dirstate for rollback |
|
567 | # save dirstate for rollback | |
568 | try: |
|
568 | try: | |
569 | ds = self.opener("dirstate").read() |
|
569 | ds = self.opener("dirstate").read() | |
570 | except IOError: |
|
570 | except IOError: | |
571 | ds = "" |
|
571 | ds = "" | |
572 | self.opener("journal.dirstate", "w").write(ds) |
|
572 | self.opener("journal.dirstate", "w").write(ds) | |
573 | self.opener("journal.branch", "w").write(self.dirstate.branch()) |
|
573 | self.opener("journal.branch", "w").write(self.dirstate.branch()) | |
574 |
|
574 | |||
575 | renames = [(self.sjoin("journal"), self.sjoin("undo")), |
|
575 | renames = [(self.sjoin("journal"), self.sjoin("undo")), | |
576 | (self.join("journal.dirstate"), self.join("undo.dirstate")), |
|
576 | (self.join("journal.dirstate"), self.join("undo.dirstate")), | |
577 | (self.join("journal.branch"), self.join("undo.branch"))] |
|
577 | (self.join("journal.branch"), self.join("undo.branch"))] | |
578 | tr = transaction.transaction(self.ui.warn, self.sopener, |
|
578 | tr = transaction.transaction(self.ui.warn, self.sopener, | |
579 | self.sjoin("journal"), |
|
579 | self.sjoin("journal"), | |
580 | aftertrans(renames), |
|
580 | aftertrans(renames), | |
581 | self.store.createmode) |
|
581 | self.store.createmode) | |
582 | self._transref = weakref.ref(tr) |
|
582 | self._transref = weakref.ref(tr) | |
583 | return tr |
|
583 | return tr | |
584 |
|
584 | |||
585 | def recover(self): |
|
585 | def recover(self): | |
586 | lock = self.lock() |
|
586 | lock = self.lock() | |
587 | try: |
|
587 | try: | |
588 | if os.path.exists(self.sjoin("journal")): |
|
588 | if os.path.exists(self.sjoin("journal")): | |
589 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
589 | self.ui.status(_("rolling back interrupted transaction\n")) | |
590 | transaction.rollback(self.sopener, self.sjoin("journal"), self.ui.warn) |
|
590 | transaction.rollback(self.sopener, self.sjoin("journal"), self.ui.warn) | |
591 | self.invalidate() |
|
591 | self.invalidate() | |
592 | return True |
|
592 | return True | |
593 | else: |
|
593 | else: | |
594 | self.ui.warn(_("no interrupted transaction available\n")) |
|
594 | self.ui.warn(_("no interrupted transaction available\n")) | |
595 | return False |
|
595 | return False | |
596 | finally: |
|
596 | finally: | |
597 | lock.release() |
|
597 | lock.release() | |
598 |
|
598 | |||
599 | def rollback(self): |
|
599 | def rollback(self): | |
600 | wlock = lock = None |
|
600 | wlock = lock = None | |
601 | try: |
|
601 | try: | |
602 | wlock = self.wlock() |
|
602 | wlock = self.wlock() | |
603 | lock = self.lock() |
|
603 | lock = self.lock() | |
604 | if os.path.exists(self.sjoin("undo")): |
|
604 | if os.path.exists(self.sjoin("undo")): | |
605 | self.ui.status(_("rolling back last transaction\n")) |
|
605 | self.ui.status(_("rolling back last transaction\n")) | |
606 | transaction.rollback(self.sopener, self.sjoin("undo"), self.ui.warn) |
|
606 | transaction.rollback(self.sopener, self.sjoin("undo"), self.ui.warn) | |
607 | util.rename(self.join("undo.dirstate"), self.join("dirstate")) |
|
607 | util.rename(self.join("undo.dirstate"), self.join("dirstate")) | |
608 | try: |
|
608 | try: | |
609 | branch = self.opener("undo.branch").read() |
|
609 | branch = self.opener("undo.branch").read() | |
610 | self.dirstate.setbranch(branch) |
|
610 | self.dirstate.setbranch(branch) | |
611 | except IOError: |
|
611 | except IOError: | |
612 | self.ui.warn(_("Named branch could not be reset, " |
|
612 | self.ui.warn(_("Named branch could not be reset, " | |
613 | "current branch still is: %s\n") |
|
613 | "current branch still is: %s\n") | |
614 | % encoding.tolocal(self.dirstate.branch())) |
|
614 | % encoding.tolocal(self.dirstate.branch())) | |
615 | self.invalidate() |
|
615 | self.invalidate() | |
616 | self.dirstate.invalidate() |
|
616 | self.dirstate.invalidate() | |
617 | self.destroyed() |
|
617 | self.destroyed() | |
618 | else: |
|
618 | else: | |
619 | self.ui.warn(_("no rollback information available\n")) |
|
619 | self.ui.warn(_("no rollback information available\n")) | |
620 | finally: |
|
620 | finally: | |
621 | release(lock, wlock) |
|
621 | release(lock, wlock) | |
622 |
|
622 | |||
623 | def invalidate(self): |
|
623 | def invalidate(self): | |
624 | for a in "changelog manifest".split(): |
|
624 | for a in "changelog manifest".split(): | |
625 | if a in self.__dict__: |
|
625 | if a in self.__dict__: | |
626 | delattr(self, a) |
|
626 | delattr(self, a) | |
627 | self._tags = None |
|
627 | self._tags = None | |
628 | self._tagtypes = None |
|
628 | self._tagtypes = None | |
629 | self.nodetagscache = None |
|
629 | self.nodetagscache = None | |
630 | self._branchcache = None # in UTF-8 |
|
630 | self._branchcache = None # in UTF-8 | |
631 | self._branchcachetip = None |
|
631 | self._branchcachetip = None | |
632 |
|
632 | |||
633 | def _lock(self, lockname, wait, releasefn, acquirefn, desc): |
|
633 | def _lock(self, lockname, wait, releasefn, acquirefn, desc): | |
634 | try: |
|
634 | try: | |
635 | l = lock.lock(lockname, 0, releasefn, desc=desc) |
|
635 | l = lock.lock(lockname, 0, releasefn, desc=desc) | |
636 | except error.LockHeld, inst: |
|
636 | except error.LockHeld, inst: | |
637 | if not wait: |
|
637 | if not wait: | |
638 | raise |
|
638 | raise | |
639 | self.ui.warn(_("waiting for lock on %s held by %r\n") % |
|
639 | self.ui.warn(_("waiting for lock on %s held by %r\n") % | |
640 | (desc, inst.locker)) |
|
640 | (desc, inst.locker)) | |
641 | # default to 600 seconds timeout |
|
641 | # default to 600 seconds timeout | |
642 | l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")), |
|
642 | l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")), | |
643 | releasefn, desc=desc) |
|
643 | releasefn, desc=desc) | |
644 | if acquirefn: |
|
644 | if acquirefn: | |
645 | acquirefn() |
|
645 | acquirefn() | |
646 | return l |
|
646 | return l | |
647 |
|
647 | |||
648 | def lock(self, wait=True): |
|
648 | def lock(self, wait=True): | |
649 | '''Lock the repository store (.hg/store) and return a weak reference |
|
649 | '''Lock the repository store (.hg/store) and return a weak reference | |
650 | to the lock. Use this before modifying the store (e.g. committing or |
|
650 | to the lock. Use this before modifying the store (e.g. committing or | |
651 | stripping). If you are opening a transaction, get a lock as well.)''' |
|
651 | stripping). If you are opening a transaction, get a lock as well.)''' | |
652 | l = self._lockref and self._lockref() |
|
652 | l = self._lockref and self._lockref() | |
653 | if l is not None and l.held: |
|
653 | if l is not None and l.held: | |
654 | l.lock() |
|
654 | l.lock() | |
655 | return l |
|
655 | return l | |
656 |
|
656 | |||
657 | l = self._lock(self.sjoin("lock"), wait, None, self.invalidate, |
|
657 | l = self._lock(self.sjoin("lock"), wait, None, self.invalidate, | |
658 | _('repository %s') % self.origroot) |
|
658 | _('repository %s') % self.origroot) | |
659 | self._lockref = weakref.ref(l) |
|
659 | self._lockref = weakref.ref(l) | |
660 | return l |
|
660 | return l | |
661 |
|
661 | |||
662 | def wlock(self, wait=True): |
|
662 | def wlock(self, wait=True): | |
663 | '''Lock the non-store parts of the repository (everything under |
|
663 | '''Lock the non-store parts of the repository (everything under | |
664 | .hg except .hg/store) and return a weak reference to the lock. |
|
664 | .hg except .hg/store) and return a weak reference to the lock. | |
665 | Use this before modifying files in .hg.''' |
|
665 | Use this before modifying files in .hg.''' | |
666 | l = self._wlockref and self._wlockref() |
|
666 | l = self._wlockref and self._wlockref() | |
667 | if l is not None and l.held: |
|
667 | if l is not None and l.held: | |
668 | l.lock() |
|
668 | l.lock() | |
669 | return l |
|
669 | return l | |
670 |
|
670 | |||
671 | l = self._lock(self.join("wlock"), wait, self.dirstate.write, |
|
671 | l = self._lock(self.join("wlock"), wait, self.dirstate.write, | |
672 | self.dirstate.invalidate, _('working directory of %s') % |
|
672 | self.dirstate.invalidate, _('working directory of %s') % | |
673 | self.origroot) |
|
673 | self.origroot) | |
674 | self._wlockref = weakref.ref(l) |
|
674 | self._wlockref = weakref.ref(l) | |
675 | return l |
|
675 | return l | |
676 |
|
676 | |||
677 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
677 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
678 | """ |
|
678 | """ | |
679 | commit an individual file as part of a larger transaction |
|
679 | commit an individual file as part of a larger transaction | |
680 | """ |
|
680 | """ | |
681 |
|
681 | |||
682 | fname = fctx.path() |
|
682 | fname = fctx.path() | |
683 | text = fctx.data() |
|
683 | text = fctx.data() | |
684 | flog = self.file(fname) |
|
684 | flog = self.file(fname) | |
685 | fparent1 = manifest1.get(fname, nullid) |
|
685 | fparent1 = manifest1.get(fname, nullid) | |
686 | fparent2 = fparent2o = manifest2.get(fname, nullid) |
|
686 | fparent2 = fparent2o = manifest2.get(fname, nullid) | |
687 |
|
687 | |||
688 | meta = {} |
|
688 | meta = {} | |
689 | copy = fctx.renamed() |
|
689 | copy = fctx.renamed() | |
690 | if copy and copy[0] != fname: |
|
690 | if copy and copy[0] != fname: | |
691 | # Mark the new revision of this file as a copy of another |
|
691 | # Mark the new revision of this file as a copy of another | |
692 | # file. This copy data will effectively act as a parent |
|
692 | # file. This copy data will effectively act as a parent | |
693 | # of this new revision. If this is a merge, the first |
|
693 | # of this new revision. If this is a merge, the first | |
694 | # parent will be the nullid (meaning "look up the copy data") |
|
694 | # parent will be the nullid (meaning "look up the copy data") | |
695 | # and the second one will be the other parent. For example: |
|
695 | # and the second one will be the other parent. For example: | |
696 | # |
|
696 | # | |
697 | # 0 --- 1 --- 3 rev1 changes file foo |
|
697 | # 0 --- 1 --- 3 rev1 changes file foo | |
698 | # \ / rev2 renames foo to bar and changes it |
|
698 | # \ / rev2 renames foo to bar and changes it | |
699 | # \- 2 -/ rev3 should have bar with all changes and |
|
699 | # \- 2 -/ rev3 should have bar with all changes and | |
700 | # should record that bar descends from |
|
700 | # should record that bar descends from | |
701 | # bar in rev2 and foo in rev1 |
|
701 | # bar in rev2 and foo in rev1 | |
702 | # |
|
702 | # | |
703 | # this allows this merge to succeed: |
|
703 | # this allows this merge to succeed: | |
704 | # |
|
704 | # | |
705 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
705 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
706 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
706 | # \ / merging rev3 and rev4 should use bar@rev2 | |
707 | # \- 2 --- 4 as the merge base |
|
707 | # \- 2 --- 4 as the merge base | |
708 | # |
|
708 | # | |
709 |
|
709 | |||
710 | cfname = copy[0] |
|
710 | cfname = copy[0] | |
711 | crev = manifest1.get(cfname) |
|
711 | crev = manifest1.get(cfname) | |
712 | newfparent = fparent2 |
|
712 | newfparent = fparent2 | |
713 |
|
713 | |||
714 | if manifest2: # branch merge |
|
714 | if manifest2: # branch merge | |
715 | if fparent2 == nullid or crev is None: # copied on remote side |
|
715 | if fparent2 == nullid or crev is None: # copied on remote side | |
716 | if cfname in manifest2: |
|
716 | if cfname in manifest2: | |
717 | crev = manifest2[cfname] |
|
717 | crev = manifest2[cfname] | |
718 | newfparent = fparent1 |
|
718 | newfparent = fparent1 | |
719 |
|
719 | |||
720 | # find source in nearest ancestor if we've lost track |
|
720 | # find source in nearest ancestor if we've lost track | |
721 | if not crev: |
|
721 | if not crev: | |
722 | self.ui.debug(" %s: searching for copy revision for %s\n" % |
|
722 | self.ui.debug(" %s: searching for copy revision for %s\n" % | |
723 | (fname, cfname)) |
|
723 | (fname, cfname)) | |
724 | for ancestor in self['.'].ancestors(): |
|
724 | for ancestor in self['.'].ancestors(): | |
725 | if cfname in ancestor: |
|
725 | if cfname in ancestor: | |
726 | crev = ancestor[cfname].filenode() |
|
726 | crev = ancestor[cfname].filenode() | |
727 | break |
|
727 | break | |
728 |
|
728 | |||
729 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
729 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) | |
730 | meta["copy"] = cfname |
|
730 | meta["copy"] = cfname | |
731 | meta["copyrev"] = hex(crev) |
|
731 | meta["copyrev"] = hex(crev) | |
732 | fparent1, fparent2 = nullid, newfparent |
|
732 | fparent1, fparent2 = nullid, newfparent | |
733 | elif fparent2 != nullid: |
|
733 | elif fparent2 != nullid: | |
734 | # is one parent an ancestor of the other? |
|
734 | # is one parent an ancestor of the other? | |
735 | fparentancestor = flog.ancestor(fparent1, fparent2) |
|
735 | fparentancestor = flog.ancestor(fparent1, fparent2) | |
736 | if fparentancestor == fparent1: |
|
736 | if fparentancestor == fparent1: | |
737 | fparent1, fparent2 = fparent2, nullid |
|
737 | fparent1, fparent2 = fparent2, nullid | |
738 | elif fparentancestor == fparent2: |
|
738 | elif fparentancestor == fparent2: | |
739 | fparent2 = nullid |
|
739 | fparent2 = nullid | |
740 |
|
740 | |||
741 | # is the file changed? |
|
741 | # is the file changed? | |
742 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
742 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
743 | changelist.append(fname) |
|
743 | changelist.append(fname) | |
744 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
744 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
745 |
|
745 | |||
746 | # are just the flags changed during merge? |
|
746 | # are just the flags changed during merge? | |
747 | if fparent1 != fparent2o and manifest1.flags(fname) != fctx.flags(): |
|
747 | if fparent1 != fparent2o and manifest1.flags(fname) != fctx.flags(): | |
748 | changelist.append(fname) |
|
748 | changelist.append(fname) | |
749 |
|
749 | |||
750 | return fparent1 |
|
750 | return fparent1 | |
751 |
|
751 | |||
752 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
752 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
753 | editor=False, extra={}): |
|
753 | editor=False, extra={}): | |
754 | """Add a new revision to current repository. |
|
754 | """Add a new revision to current repository. | |
755 |
|
755 | |||
756 | Revision information is gathered from the working directory, |
|
756 | Revision information is gathered from the working directory, | |
757 | match can be used to filter the committed files. If editor is |
|
757 | match can be used to filter the committed files. If editor is | |
758 | supplied, it is called to get a commit message. |
|
758 | supplied, it is called to get a commit message. | |
759 | """ |
|
759 | """ | |
760 |
|
760 | |||
761 | def fail(f, msg): |
|
761 | def fail(f, msg): | |
762 | raise util.Abort('%s: %s' % (f, msg)) |
|
762 | raise util.Abort('%s: %s' % (f, msg)) | |
763 |
|
763 | |||
764 | if not match: |
|
764 | if not match: | |
765 | match = match_.always(self.root, '') |
|
765 | match = match_.always(self.root, '') | |
766 |
|
766 | |||
767 | if not force: |
|
767 | if not force: | |
768 | vdirs = [] |
|
768 | vdirs = [] | |
769 | match.dir = vdirs.append |
|
769 | match.dir = vdirs.append | |
770 | match.bad = fail |
|
770 | match.bad = fail | |
771 |
|
771 | |||
772 | wlock = self.wlock() |
|
772 | wlock = self.wlock() | |
773 | try: |
|
773 | try: | |
774 | p1, p2 = self.dirstate.parents() |
|
774 | p1, p2 = self.dirstate.parents() | |
775 | wctx = self[None] |
|
775 | wctx = self[None] | |
776 |
|
776 | |||
777 | if (not force and p2 != nullid and match and |
|
777 | if (not force and p2 != nullid and match and | |
778 | (match.files() or match.anypats())): |
|
778 | (match.files() or match.anypats())): | |
779 | raise util.Abort(_('cannot partially commit a merge ' |
|
779 | raise util.Abort(_('cannot partially commit a merge ' | |
780 | '(do not specify files or patterns)')) |
|
780 | '(do not specify files or patterns)')) | |
781 |
|
781 | |||
782 | changes = self.status(match=match, clean=force) |
|
782 | changes = self.status(match=match, clean=force) | |
783 | if force: |
|
783 | if force: | |
784 | changes[0].extend(changes[6]) # mq may commit unchanged files |
|
784 | changes[0].extend(changes[6]) # mq may commit unchanged files | |
785 |
|
785 | |||
786 | # check subrepos |
|
786 | # check subrepos | |
787 | subs = [] |
|
787 | subs = [] | |
788 | for s in wctx.substate: |
|
788 | for s in wctx.substate: | |
789 | if match(s) and wctx.sub(s).dirty(): |
|
789 | if match(s) and wctx.sub(s).dirty(): | |
790 | subs.append(s) |
|
790 | subs.append(s) | |
791 | if subs and '.hgsubstate' not in changes[0]: |
|
791 | if subs and '.hgsubstate' not in changes[0]: | |
792 | changes[0].insert(0, '.hgsubstate') |
|
792 | changes[0].insert(0, '.hgsubstate') | |
793 |
|
793 | |||
794 | # make sure all explicit patterns are matched |
|
794 | # make sure all explicit patterns are matched | |
795 | if not force and match.files(): |
|
795 | if not force and match.files(): | |
796 | matched = set(changes[0] + changes[1] + changes[2]) |
|
796 | matched = set(changes[0] + changes[1] + changes[2]) | |
797 |
|
797 | |||
798 | for f in match.files(): |
|
798 | for f in match.files(): | |
799 | if f == '.' or f in matched or f in wctx.substate: |
|
799 | if f == '.' or f in matched or f in wctx.substate: | |
800 | continue |
|
800 | continue | |
801 | if f in changes[3]: # missing |
|
801 | if f in changes[3]: # missing | |
802 | fail(f, _('file not found!')) |
|
802 | fail(f, _('file not found!')) | |
803 | if f in vdirs: # visited directory |
|
803 | if f in vdirs: # visited directory | |
804 | d = f + '/' |
|
804 | d = f + '/' | |
805 | for mf in matched: |
|
805 | for mf in matched: | |
806 | if mf.startswith(d): |
|
806 | if mf.startswith(d): | |
807 | break |
|
807 | break | |
808 | else: |
|
808 | else: | |
809 | fail(f, _("no match under directory!")) |
|
809 | fail(f, _("no match under directory!")) | |
810 | elif f not in self.dirstate: |
|
810 | elif f not in self.dirstate: | |
811 | fail(f, _("file not tracked!")) |
|
811 | fail(f, _("file not tracked!")) | |
812 |
|
812 | |||
813 | if (not force and not extra.get("close") and p2 == nullid |
|
813 | if (not force and not extra.get("close") and p2 == nullid | |
814 | and not (changes[0] or changes[1] or changes[2]) |
|
814 | and not (changes[0] or changes[1] or changes[2]) | |
815 | and self[None].branch() == self['.'].branch()): |
|
815 | and self[None].branch() == self['.'].branch()): | |
816 | return None |
|
816 | return None | |
817 |
|
817 | |||
818 | ms = merge_.mergestate(self) |
|
818 | ms = merge_.mergestate(self) | |
819 | for f in changes[0]: |
|
819 | for f in changes[0]: | |
820 | if f in ms and ms[f] == 'u': |
|
820 | if f in ms and ms[f] == 'u': | |
821 | raise util.Abort(_("unresolved merge conflicts " |
|
821 | raise util.Abort(_("unresolved merge conflicts " | |
822 | "(see hg resolve)")) |
|
822 | "(see hg resolve)")) | |
823 |
|
823 | |||
824 | cctx = context.workingctx(self, (p1, p2), text, user, date, |
|
824 | cctx = context.workingctx(self, (p1, p2), text, user, date, | |
825 | extra, changes) |
|
825 | extra, changes) | |
826 | if editor: |
|
826 | if editor: | |
827 | cctx._text = editor(self, cctx, subs) |
|
827 | cctx._text = editor(self, cctx, subs) | |
828 | edited = (text != cctx._text) |
|
828 | edited = (text != cctx._text) | |
829 |
|
829 | |||
830 | # commit subs |
|
830 | # commit subs | |
831 | if subs: |
|
831 | if subs: | |
832 | state = wctx.substate.copy() |
|
832 | state = wctx.substate.copy() | |
833 | for s in subs: |
|
833 | for s in subs: | |
834 | self.ui.status(_('committing subrepository %s\n') % s) |
|
834 | self.ui.status(_('committing subrepository %s\n') % s) | |
835 | sr = wctx.sub(s).commit(cctx._text, user, date) |
|
835 | sr = wctx.sub(s).commit(cctx._text, user, date) | |
836 | state[s] = (state[s][0], sr) |
|
836 | state[s] = (state[s][0], sr) | |
837 | subrepo.writestate(self, state) |
|
837 | subrepo.writestate(self, state) | |
838 |
|
838 | |||
839 | # Save commit message in case this transaction gets rolled back |
|
839 | # Save commit message in case this transaction gets rolled back | |
840 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
840 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
841 | # the assumption that the user will use the same editor again. |
|
841 | # the assumption that the user will use the same editor again. | |
842 | msgfile = self.opener('last-message.txt', 'wb') |
|
842 | msgfile = self.opener('last-message.txt', 'wb') | |
843 | msgfile.write(cctx._text) |
|
843 | msgfile.write(cctx._text) | |
844 | msgfile.close() |
|
844 | msgfile.close() | |
845 |
|
845 | |||
846 | try: |
|
846 | try: | |
847 | ret = self.commitctx(cctx, True) |
|
847 | ret = self.commitctx(cctx, True) | |
848 | except: |
|
848 | except: | |
849 | if edited: |
|
849 | if edited: | |
850 | msgfn = self.pathto(msgfile.name[len(self.root)+1:]) |
|
850 | msgfn = self.pathto(msgfile.name[len(self.root)+1:]) | |
851 | self.ui.write( |
|
851 | self.ui.write( | |
852 | _('note: commit message saved in %s\n') % msgfn) |
|
852 | _('note: commit message saved in %s\n') % msgfn) | |
853 | raise |
|
853 | raise | |
854 |
|
854 | |||
855 | # update dirstate and mergestate |
|
855 | # update dirstate and mergestate | |
856 | for f in changes[0] + changes[1]: |
|
856 | for f in changes[0] + changes[1]: | |
857 | self.dirstate.normal(f) |
|
857 | self.dirstate.normal(f) | |
858 | for f in changes[2]: |
|
858 | for f in changes[2]: | |
859 | self.dirstate.forget(f) |
|
859 | self.dirstate.forget(f) | |
860 | self.dirstate.setparents(ret) |
|
860 | self.dirstate.setparents(ret) | |
861 | ms.reset() |
|
861 | ms.reset() | |
862 |
|
862 | |||
863 | return ret |
|
863 | return ret | |
864 |
|
864 | |||
865 | finally: |
|
865 | finally: | |
866 | wlock.release() |
|
866 | wlock.release() | |
867 |
|
867 | |||
868 | def commitctx(self, ctx, error=False): |
|
868 | def commitctx(self, ctx, error=False): | |
869 | """Add a new revision to current repository. |
|
869 | """Add a new revision to current repository. | |
870 |
|
870 | |||
871 | Revision information is passed via the context argument. |
|
871 | Revision information is passed via the context argument. | |
872 | """ |
|
872 | """ | |
873 |
|
873 | |||
874 | tr = lock = None |
|
874 | tr = lock = None | |
875 | removed = ctx.removed() |
|
875 | removed = ctx.removed() | |
876 | p1, p2 = ctx.p1(), ctx.p2() |
|
876 | p1, p2 = ctx.p1(), ctx.p2() | |
877 | m1 = p1.manifest().copy() |
|
877 | m1 = p1.manifest().copy() | |
878 | m2 = p2.manifest() |
|
878 | m2 = p2.manifest() | |
879 | user = ctx.user() |
|
879 | user = ctx.user() | |
880 |
|
880 | |||
881 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
881 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
882 | self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) |
|
882 | self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) | |
883 |
|
883 | |||
884 | lock = self.lock() |
|
884 | lock = self.lock() | |
885 | try: |
|
885 | try: | |
886 | tr = self.transaction() |
|
886 | tr = self.transaction() | |
887 | trp = weakref.proxy(tr) |
|
887 | trp = weakref.proxy(tr) | |
888 |
|
888 | |||
889 | # check in files |
|
889 | # check in files | |
890 | new = {} |
|
890 | new = {} | |
891 | changed = [] |
|
891 | changed = [] | |
892 | linkrev = len(self) |
|
892 | linkrev = len(self) | |
893 | for f in sorted(ctx.modified() + ctx.added()): |
|
893 | for f in sorted(ctx.modified() + ctx.added()): | |
894 | self.ui.note(f + "\n") |
|
894 | self.ui.note(f + "\n") | |
895 | try: |
|
895 | try: | |
896 | fctx = ctx[f] |
|
896 | fctx = ctx[f] | |
897 | new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, |
|
897 | new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, | |
898 | changed) |
|
898 | changed) | |
899 | m1.set(f, fctx.flags()) |
|
899 | m1.set(f, fctx.flags()) | |
900 | except (OSError, IOError): |
|
900 | except (OSError, IOError): | |
901 | if error: |
|
901 | if error: | |
902 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
902 | self.ui.warn(_("trouble committing %s!\n") % f) | |
903 | raise |
|
903 | raise | |
904 | else: |
|
904 | else: | |
905 | removed.append(f) |
|
905 | removed.append(f) | |
906 |
|
906 | |||
907 | # update manifest |
|
907 | # update manifest | |
908 | m1.update(new) |
|
908 | m1.update(new) | |
909 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
909 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
910 | drop = [f for f in removed if f in m1] |
|
910 | drop = [f for f in removed if f in m1] | |
911 | for f in drop: |
|
911 | for f in drop: | |
912 | del m1[f] |
|
912 | del m1[f] | |
913 | mn = self.manifest.add(m1, trp, linkrev, p1.manifestnode(), |
|
913 | mn = self.manifest.add(m1, trp, linkrev, p1.manifestnode(), | |
914 | p2.manifestnode(), (new, drop)) |
|
914 | p2.manifestnode(), (new, drop)) | |
915 |
|
915 | |||
916 | # update changelog |
|
916 | # update changelog | |
917 | self.changelog.delayupdate() |
|
917 | self.changelog.delayupdate() | |
918 | n = self.changelog.add(mn, changed + removed, ctx.description(), |
|
918 | n = self.changelog.add(mn, changed + removed, ctx.description(), | |
919 | trp, p1.node(), p2.node(), |
|
919 | trp, p1.node(), p2.node(), | |
920 | user, ctx.date(), ctx.extra().copy()) |
|
920 | user, ctx.date(), ctx.extra().copy()) | |
921 | p = lambda: self.changelog.writepending() and self.root or "" |
|
921 | p = lambda: self.changelog.writepending() and self.root or "" | |
922 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
922 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
923 | parent2=xp2, pending=p) |
|
923 | parent2=xp2, pending=p) | |
924 | self.changelog.finalize(trp) |
|
924 | self.changelog.finalize(trp) | |
925 | tr.close() |
|
925 | tr.close() | |
926 |
|
926 | |||
927 | if self._branchcache: |
|
927 | if self._branchcache: | |
928 | self.branchtags() |
|
928 | self.branchtags() | |
929 |
|
929 | |||
930 | self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2) |
|
930 | self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2) | |
931 | return n |
|
931 | return n | |
932 | finally: |
|
932 | finally: | |
933 | del tr |
|
933 | del tr | |
934 | lock.release() |
|
934 | lock.release() | |
935 |
|
935 | |||
936 | def destroyed(self): |
|
936 | def destroyed(self): | |
937 | '''Inform the repository that nodes have been destroyed. |
|
937 | '''Inform the repository that nodes have been destroyed. | |
938 | Intended for use by strip and rollback, so there's a common |
|
938 | Intended for use by strip and rollback, so there's a common | |
939 | place for anything that has to be done after destroying history.''' |
|
939 | place for anything that has to be done after destroying history.''' | |
940 | # XXX it might be nice if we could take the list of destroyed |
|
940 | # XXX it might be nice if we could take the list of destroyed | |
941 | # nodes, but I don't see an easy way for rollback() to do that |
|
941 | # nodes, but I don't see an easy way for rollback() to do that | |
942 |
|
942 | |||
943 | # Ensure the persistent tag cache is updated. Doing it now |
|
943 | # Ensure the persistent tag cache is updated. Doing it now | |
944 | # means that the tag cache only has to worry about destroyed |
|
944 | # means that the tag cache only has to worry about destroyed | |
945 | # heads immediately after a strip/rollback. That in turn |
|
945 | # heads immediately after a strip/rollback. That in turn | |
946 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
946 | # guarantees that "cachetip == currenttip" (comparing both rev | |
947 | # and node) always means no nodes have been added or destroyed. |
|
947 | # and node) always means no nodes have been added or destroyed. | |
948 |
|
948 | |||
949 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
949 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
950 | # head, refresh the tag cache, then immediately add a new head. |
|
950 | # head, refresh the tag cache, then immediately add a new head. | |
951 | # But I think doing it this way is necessary for the "instant |
|
951 | # But I think doing it this way is necessary for the "instant | |
952 | # tag cache retrieval" case to work. |
|
952 | # tag cache retrieval" case to work. | |
953 | tags_.findglobaltags(self.ui, self, {}, {}) |
|
953 | tags_.findglobaltags(self.ui, self, {}, {}) | |
954 |
|
954 | |||
955 | def walk(self, match, node=None): |
|
955 | def walk(self, match, node=None): | |
956 | ''' |
|
956 | ''' | |
957 | walk recursively through the directory tree or a given |
|
957 | walk recursively through the directory tree or a given | |
958 | changeset, finding all files matched by the match |
|
958 | changeset, finding all files matched by the match | |
959 | function |
|
959 | function | |
960 | ''' |
|
960 | ''' | |
961 | return self[node].walk(match) |
|
961 | return self[node].walk(match) | |
962 |
|
962 | |||
963 | def status(self, node1='.', node2=None, match=None, |
|
963 | def status(self, node1='.', node2=None, match=None, | |
964 | ignored=False, clean=False, unknown=False): |
|
964 | ignored=False, clean=False, unknown=False): | |
965 | """return status of files between two nodes or node and working directory |
|
965 | """return status of files between two nodes or node and working directory | |
966 |
|
966 | |||
967 | If node1 is None, use the first dirstate parent instead. |
|
967 | If node1 is None, use the first dirstate parent instead. | |
968 | If node2 is None, compare node1 with working directory. |
|
968 | If node2 is None, compare node1 with working directory. | |
969 | """ |
|
969 | """ | |
970 |
|
970 | |||
971 | def mfmatches(ctx): |
|
971 | def mfmatches(ctx): | |
972 | mf = ctx.manifest().copy() |
|
972 | mf = ctx.manifest().copy() | |
973 | for fn in mf.keys(): |
|
973 | for fn in mf.keys(): | |
974 | if not match(fn): |
|
974 | if not match(fn): | |
975 | del mf[fn] |
|
975 | del mf[fn] | |
976 | return mf |
|
976 | return mf | |
977 |
|
977 | |||
978 | if isinstance(node1, context.changectx): |
|
978 | if isinstance(node1, context.changectx): | |
979 | ctx1 = node1 |
|
979 | ctx1 = node1 | |
980 | else: |
|
980 | else: | |
981 | ctx1 = self[node1] |
|
981 | ctx1 = self[node1] | |
982 | if isinstance(node2, context.changectx): |
|
982 | if isinstance(node2, context.changectx): | |
983 | ctx2 = node2 |
|
983 | ctx2 = node2 | |
984 | else: |
|
984 | else: | |
985 | ctx2 = self[node2] |
|
985 | ctx2 = self[node2] | |
986 |
|
986 | |||
987 | working = ctx2.rev() is None |
|
987 | working = ctx2.rev() is None | |
988 | parentworking = working and ctx1 == self['.'] |
|
988 | parentworking = working and ctx1 == self['.'] | |
989 | match = match or match_.always(self.root, self.getcwd()) |
|
989 | match = match or match_.always(self.root, self.getcwd()) | |
990 | listignored, listclean, listunknown = ignored, clean, unknown |
|
990 | listignored, listclean, listunknown = ignored, clean, unknown | |
991 |
|
991 | |||
992 | # load earliest manifest first for caching reasons |
|
992 | # load earliest manifest first for caching reasons | |
993 | if not working and ctx2.rev() < ctx1.rev(): |
|
993 | if not working and ctx2.rev() < ctx1.rev(): | |
994 | ctx2.manifest() |
|
994 | ctx2.manifest() | |
995 |
|
995 | |||
996 | if not parentworking: |
|
996 | if not parentworking: | |
997 | def bad(f, msg): |
|
997 | def bad(f, msg): | |
998 | if f not in ctx1: |
|
998 | if f not in ctx1: | |
999 | self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg)) |
|
999 | self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg)) | |
1000 | match.bad = bad |
|
1000 | match.bad = bad | |
1001 |
|
1001 | |||
1002 | if working: # we need to scan the working dir |
|
1002 | if working: # we need to scan the working dir | |
1003 | s = self.dirstate.status(match, listignored, listclean, listunknown) |
|
1003 | subrepos = ctx1.substate.keys() | |
|
1004 | s = self.dirstate.status(match, subrepos, listignored, | |||
|
1005 | listclean, listunknown) | |||
1004 | cmp, modified, added, removed, deleted, unknown, ignored, clean = s |
|
1006 | cmp, modified, added, removed, deleted, unknown, ignored, clean = s | |
1005 |
|
1007 | |||
1006 | # check for any possibly clean files |
|
1008 | # check for any possibly clean files | |
1007 | if parentworking and cmp: |
|
1009 | if parentworking and cmp: | |
1008 | fixup = [] |
|
1010 | fixup = [] | |
1009 | # do a full compare of any files that might have changed |
|
1011 | # do a full compare of any files that might have changed | |
1010 | for f in sorted(cmp): |
|
1012 | for f in sorted(cmp): | |
1011 | if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f) |
|
1013 | if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f) | |
1012 | or ctx1[f].cmp(ctx2[f].data())): |
|
1014 | or ctx1[f].cmp(ctx2[f].data())): | |
1013 | modified.append(f) |
|
1015 | modified.append(f) | |
1014 | else: |
|
1016 | else: | |
1015 | fixup.append(f) |
|
1017 | fixup.append(f) | |
1016 |
|
1018 | |||
1017 | if listclean: |
|
1019 | if listclean: | |
1018 | clean += fixup |
|
1020 | clean += fixup | |
1019 |
|
1021 | |||
1020 | # update dirstate for files that are actually clean |
|
1022 | # update dirstate for files that are actually clean | |
1021 | if fixup: |
|
1023 | if fixup: | |
1022 | try: |
|
1024 | try: | |
1023 | # updating the dirstate is optional |
|
1025 | # updating the dirstate is optional | |
1024 | # so we don't wait on the lock |
|
1026 | # so we don't wait on the lock | |
1025 | wlock = self.wlock(False) |
|
1027 | wlock = self.wlock(False) | |
1026 | try: |
|
1028 | try: | |
1027 | for f in fixup: |
|
1029 | for f in fixup: | |
1028 | self.dirstate.normal(f) |
|
1030 | self.dirstate.normal(f) | |
1029 | finally: |
|
1031 | finally: | |
1030 | wlock.release() |
|
1032 | wlock.release() | |
1031 | except error.LockError: |
|
1033 | except error.LockError: | |
1032 | pass |
|
1034 | pass | |
1033 |
|
1035 | |||
1034 | if not parentworking: |
|
1036 | if not parentworking: | |
1035 | mf1 = mfmatches(ctx1) |
|
1037 | mf1 = mfmatches(ctx1) | |
1036 | if working: |
|
1038 | if working: | |
1037 | # we are comparing working dir against non-parent |
|
1039 | # we are comparing working dir against non-parent | |
1038 | # generate a pseudo-manifest for the working dir |
|
1040 | # generate a pseudo-manifest for the working dir | |
1039 | mf2 = mfmatches(self['.']) |
|
1041 | mf2 = mfmatches(self['.']) | |
1040 | for f in cmp + modified + added: |
|
1042 | for f in cmp + modified + added: | |
1041 | mf2[f] = None |
|
1043 | mf2[f] = None | |
1042 | mf2.set(f, ctx2.flags(f)) |
|
1044 | mf2.set(f, ctx2.flags(f)) | |
1043 | for f in removed: |
|
1045 | for f in removed: | |
1044 | if f in mf2: |
|
1046 | if f in mf2: | |
1045 | del mf2[f] |
|
1047 | del mf2[f] | |
1046 | else: |
|
1048 | else: | |
1047 | # we are comparing two revisions |
|
1049 | # we are comparing two revisions | |
1048 | deleted, unknown, ignored = [], [], [] |
|
1050 | deleted, unknown, ignored = [], [], [] | |
1049 | mf2 = mfmatches(ctx2) |
|
1051 | mf2 = mfmatches(ctx2) | |
1050 |
|
1052 | |||
1051 | modified, added, clean = [], [], [] |
|
1053 | modified, added, clean = [], [], [] | |
1052 | for fn in mf2: |
|
1054 | for fn in mf2: | |
1053 | if fn in mf1: |
|
1055 | if fn in mf1: | |
1054 | if (mf1.flags(fn) != mf2.flags(fn) or |
|
1056 | if (mf1.flags(fn) != mf2.flags(fn) or | |
1055 | (mf1[fn] != mf2[fn] and |
|
1057 | (mf1[fn] != mf2[fn] and | |
1056 | (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))): |
|
1058 | (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))): | |
1057 | modified.append(fn) |
|
1059 | modified.append(fn) | |
1058 | elif listclean: |
|
1060 | elif listclean: | |
1059 | clean.append(fn) |
|
1061 | clean.append(fn) | |
1060 | del mf1[fn] |
|
1062 | del mf1[fn] | |
1061 | else: |
|
1063 | else: | |
1062 | added.append(fn) |
|
1064 | added.append(fn) | |
1063 | removed = mf1.keys() |
|
1065 | removed = mf1.keys() | |
1064 |
|
1066 | |||
1065 | r = modified, added, removed, deleted, unknown, ignored, clean |
|
1067 | r = modified, added, removed, deleted, unknown, ignored, clean | |
1066 | [l.sort() for l in r] |
|
1068 | [l.sort() for l in r] | |
1067 | return r |
|
1069 | return r | |
1068 |
|
1070 | |||
1069 | def add(self, list): |
|
1071 | def add(self, list): | |
1070 | wlock = self.wlock() |
|
1072 | wlock = self.wlock() | |
1071 | try: |
|
1073 | try: | |
1072 | rejected = [] |
|
1074 | rejected = [] | |
1073 | for f in list: |
|
1075 | for f in list: | |
1074 | p = self.wjoin(f) |
|
1076 | p = self.wjoin(f) | |
1075 | try: |
|
1077 | try: | |
1076 | st = os.lstat(p) |
|
1078 | st = os.lstat(p) | |
1077 | except: |
|
1079 | except: | |
1078 | self.ui.warn(_("%s does not exist!\n") % f) |
|
1080 | self.ui.warn(_("%s does not exist!\n") % f) | |
1079 | rejected.append(f) |
|
1081 | rejected.append(f) | |
1080 | continue |
|
1082 | continue | |
1081 | if st.st_size > 10000000: |
|
1083 | if st.st_size > 10000000: | |
1082 | self.ui.warn(_("%s: files over 10MB may cause memory and" |
|
1084 | self.ui.warn(_("%s: files over 10MB may cause memory and" | |
1083 | " performance problems\n" |
|
1085 | " performance problems\n" | |
1084 | "(use 'hg revert %s' to unadd the file)\n") |
|
1086 | "(use 'hg revert %s' to unadd the file)\n") | |
1085 | % (f, f)) |
|
1087 | % (f, f)) | |
1086 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1088 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1087 | self.ui.warn(_("%s not added: only files and symlinks " |
|
1089 | self.ui.warn(_("%s not added: only files and symlinks " | |
1088 | "supported currently\n") % f) |
|
1090 | "supported currently\n") % f) | |
1089 | rejected.append(p) |
|
1091 | rejected.append(p) | |
1090 | elif self.dirstate[f] in 'amn': |
|
1092 | elif self.dirstate[f] in 'amn': | |
1091 | self.ui.warn(_("%s already tracked!\n") % f) |
|
1093 | self.ui.warn(_("%s already tracked!\n") % f) | |
1092 | elif self.dirstate[f] == 'r': |
|
1094 | elif self.dirstate[f] == 'r': | |
1093 | self.dirstate.normallookup(f) |
|
1095 | self.dirstate.normallookup(f) | |
1094 | else: |
|
1096 | else: | |
1095 | self.dirstate.add(f) |
|
1097 | self.dirstate.add(f) | |
1096 | return rejected |
|
1098 | return rejected | |
1097 | finally: |
|
1099 | finally: | |
1098 | wlock.release() |
|
1100 | wlock.release() | |
1099 |
|
1101 | |||
1100 | def forget(self, list): |
|
1102 | def forget(self, list): | |
1101 | wlock = self.wlock() |
|
1103 | wlock = self.wlock() | |
1102 | try: |
|
1104 | try: | |
1103 | for f in list: |
|
1105 | for f in list: | |
1104 | if self.dirstate[f] != 'a': |
|
1106 | if self.dirstate[f] != 'a': | |
1105 | self.ui.warn(_("%s not added!\n") % f) |
|
1107 | self.ui.warn(_("%s not added!\n") % f) | |
1106 | else: |
|
1108 | else: | |
1107 | self.dirstate.forget(f) |
|
1109 | self.dirstate.forget(f) | |
1108 | finally: |
|
1110 | finally: | |
1109 | wlock.release() |
|
1111 | wlock.release() | |
1110 |
|
1112 | |||
1111 | def remove(self, list, unlink=False): |
|
1113 | def remove(self, list, unlink=False): | |
1112 | if unlink: |
|
1114 | if unlink: | |
1113 | for f in list: |
|
1115 | for f in list: | |
1114 | try: |
|
1116 | try: | |
1115 | util.unlink(self.wjoin(f)) |
|
1117 | util.unlink(self.wjoin(f)) | |
1116 | except OSError, inst: |
|
1118 | except OSError, inst: | |
1117 | if inst.errno != errno.ENOENT: |
|
1119 | if inst.errno != errno.ENOENT: | |
1118 | raise |
|
1120 | raise | |
1119 | wlock = self.wlock() |
|
1121 | wlock = self.wlock() | |
1120 | try: |
|
1122 | try: | |
1121 | for f in list: |
|
1123 | for f in list: | |
1122 | if unlink and os.path.exists(self.wjoin(f)): |
|
1124 | if unlink and os.path.exists(self.wjoin(f)): | |
1123 | self.ui.warn(_("%s still exists!\n") % f) |
|
1125 | self.ui.warn(_("%s still exists!\n") % f) | |
1124 | elif self.dirstate[f] == 'a': |
|
1126 | elif self.dirstate[f] == 'a': | |
1125 | self.dirstate.forget(f) |
|
1127 | self.dirstate.forget(f) | |
1126 | elif f not in self.dirstate: |
|
1128 | elif f not in self.dirstate: | |
1127 | self.ui.warn(_("%s not tracked!\n") % f) |
|
1129 | self.ui.warn(_("%s not tracked!\n") % f) | |
1128 | else: |
|
1130 | else: | |
1129 | self.dirstate.remove(f) |
|
1131 | self.dirstate.remove(f) | |
1130 | finally: |
|
1132 | finally: | |
1131 | wlock.release() |
|
1133 | wlock.release() | |
1132 |
|
1134 | |||
1133 | def undelete(self, list): |
|
1135 | def undelete(self, list): | |
1134 | manifests = [self.manifest.read(self.changelog.read(p)[0]) |
|
1136 | manifests = [self.manifest.read(self.changelog.read(p)[0]) | |
1135 | for p in self.dirstate.parents() if p != nullid] |
|
1137 | for p in self.dirstate.parents() if p != nullid] | |
1136 | wlock = self.wlock() |
|
1138 | wlock = self.wlock() | |
1137 | try: |
|
1139 | try: | |
1138 | for f in list: |
|
1140 | for f in list: | |
1139 | if self.dirstate[f] != 'r': |
|
1141 | if self.dirstate[f] != 'r': | |
1140 | self.ui.warn(_("%s not removed!\n") % f) |
|
1142 | self.ui.warn(_("%s not removed!\n") % f) | |
1141 | else: |
|
1143 | else: | |
1142 | m = f in manifests[0] and manifests[0] or manifests[1] |
|
1144 | m = f in manifests[0] and manifests[0] or manifests[1] | |
1143 | t = self.file(f).read(m[f]) |
|
1145 | t = self.file(f).read(m[f]) | |
1144 | self.wwrite(f, t, m.flags(f)) |
|
1146 | self.wwrite(f, t, m.flags(f)) | |
1145 | self.dirstate.normal(f) |
|
1147 | self.dirstate.normal(f) | |
1146 | finally: |
|
1148 | finally: | |
1147 | wlock.release() |
|
1149 | wlock.release() | |
1148 |
|
1150 | |||
1149 | def copy(self, source, dest): |
|
1151 | def copy(self, source, dest): | |
1150 | p = self.wjoin(dest) |
|
1152 | p = self.wjoin(dest) | |
1151 | if not (os.path.exists(p) or os.path.islink(p)): |
|
1153 | if not (os.path.exists(p) or os.path.islink(p)): | |
1152 | self.ui.warn(_("%s does not exist!\n") % dest) |
|
1154 | self.ui.warn(_("%s does not exist!\n") % dest) | |
1153 | elif not (os.path.isfile(p) or os.path.islink(p)): |
|
1155 | elif not (os.path.isfile(p) or os.path.islink(p)): | |
1154 | self.ui.warn(_("copy failed: %s is not a file or a " |
|
1156 | self.ui.warn(_("copy failed: %s is not a file or a " | |
1155 | "symbolic link\n") % dest) |
|
1157 | "symbolic link\n") % dest) | |
1156 | else: |
|
1158 | else: | |
1157 | wlock = self.wlock() |
|
1159 | wlock = self.wlock() | |
1158 | try: |
|
1160 | try: | |
1159 | if self.dirstate[dest] in '?r': |
|
1161 | if self.dirstate[dest] in '?r': | |
1160 | self.dirstate.add(dest) |
|
1162 | self.dirstate.add(dest) | |
1161 | self.dirstate.copy(source, dest) |
|
1163 | self.dirstate.copy(source, dest) | |
1162 | finally: |
|
1164 | finally: | |
1163 | wlock.release() |
|
1165 | wlock.release() | |
1164 |
|
1166 | |||
1165 | def heads(self, start=None): |
|
1167 | def heads(self, start=None): | |
1166 | heads = self.changelog.heads(start) |
|
1168 | heads = self.changelog.heads(start) | |
1167 | # sort the output in rev descending order |
|
1169 | # sort the output in rev descending order | |
1168 | heads = [(-self.changelog.rev(h), h) for h in heads] |
|
1170 | heads = [(-self.changelog.rev(h), h) for h in heads] | |
1169 | return [n for (r, n) in sorted(heads)] |
|
1171 | return [n for (r, n) in sorted(heads)] | |
1170 |
|
1172 | |||
1171 | def branchheads(self, branch=None, start=None, closed=False): |
|
1173 | def branchheads(self, branch=None, start=None, closed=False): | |
1172 | '''return a (possibly filtered) list of heads for the given branch |
|
1174 | '''return a (possibly filtered) list of heads for the given branch | |
1173 |
|
1175 | |||
1174 | Heads are returned in topological order, from newest to oldest. |
|
1176 | Heads are returned in topological order, from newest to oldest. | |
1175 | If branch is None, use the dirstate branch. |
|
1177 | If branch is None, use the dirstate branch. | |
1176 | If start is not None, return only heads reachable from start. |
|
1178 | If start is not None, return only heads reachable from start. | |
1177 | If closed is True, return heads that are marked as closed as well. |
|
1179 | If closed is True, return heads that are marked as closed as well. | |
1178 | ''' |
|
1180 | ''' | |
1179 | if branch is None: |
|
1181 | if branch is None: | |
1180 | branch = self[None].branch() |
|
1182 | branch = self[None].branch() | |
1181 | branches = self.branchmap() |
|
1183 | branches = self.branchmap() | |
1182 | if branch not in branches: |
|
1184 | if branch not in branches: | |
1183 | return [] |
|
1185 | return [] | |
1184 | # the cache returns heads ordered lowest to highest |
|
1186 | # the cache returns heads ordered lowest to highest | |
1185 | bheads = list(reversed(branches[branch])) |
|
1187 | bheads = list(reversed(branches[branch])) | |
1186 | if start is not None: |
|
1188 | if start is not None: | |
1187 | # filter out the heads that cannot be reached from startrev |
|
1189 | # filter out the heads that cannot be reached from startrev | |
1188 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
1190 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
1189 | bheads = [h for h in bheads if h in fbheads] |
|
1191 | bheads = [h for h in bheads if h in fbheads] | |
1190 | if not closed: |
|
1192 | if not closed: | |
1191 | bheads = [h for h in bheads if |
|
1193 | bheads = [h for h in bheads if | |
1192 | ('close' not in self.changelog.read(h)[5])] |
|
1194 | ('close' not in self.changelog.read(h)[5])] | |
1193 | return bheads |
|
1195 | return bheads | |
1194 |
|
1196 | |||
1195 | def branches(self, nodes): |
|
1197 | def branches(self, nodes): | |
1196 | if not nodes: |
|
1198 | if not nodes: | |
1197 | nodes = [self.changelog.tip()] |
|
1199 | nodes = [self.changelog.tip()] | |
1198 | b = [] |
|
1200 | b = [] | |
1199 | for n in nodes: |
|
1201 | for n in nodes: | |
1200 | t = n |
|
1202 | t = n | |
1201 | while 1: |
|
1203 | while 1: | |
1202 | p = self.changelog.parents(n) |
|
1204 | p = self.changelog.parents(n) | |
1203 | if p[1] != nullid or p[0] == nullid: |
|
1205 | if p[1] != nullid or p[0] == nullid: | |
1204 | b.append((t, n, p[0], p[1])) |
|
1206 | b.append((t, n, p[0], p[1])) | |
1205 | break |
|
1207 | break | |
1206 | n = p[0] |
|
1208 | n = p[0] | |
1207 | return b |
|
1209 | return b | |
1208 |
|
1210 | |||
1209 | def between(self, pairs): |
|
1211 | def between(self, pairs): | |
1210 | r = [] |
|
1212 | r = [] | |
1211 |
|
1213 | |||
1212 | for top, bottom in pairs: |
|
1214 | for top, bottom in pairs: | |
1213 | n, l, i = top, [], 0 |
|
1215 | n, l, i = top, [], 0 | |
1214 | f = 1 |
|
1216 | f = 1 | |
1215 |
|
1217 | |||
1216 | while n != bottom and n != nullid: |
|
1218 | while n != bottom and n != nullid: | |
1217 | p = self.changelog.parents(n)[0] |
|
1219 | p = self.changelog.parents(n)[0] | |
1218 | if i == f: |
|
1220 | if i == f: | |
1219 | l.append(n) |
|
1221 | l.append(n) | |
1220 | f = f * 2 |
|
1222 | f = f * 2 | |
1221 | n = p |
|
1223 | n = p | |
1222 | i += 1 |
|
1224 | i += 1 | |
1223 |
|
1225 | |||
1224 | r.append(l) |
|
1226 | r.append(l) | |
1225 |
|
1227 | |||
1226 | return r |
|
1228 | return r | |
1227 |
|
1229 | |||
1228 | def findincoming(self, remote, base=None, heads=None, force=False): |
|
1230 | def findincoming(self, remote, base=None, heads=None, force=False): | |
1229 | """Return list of roots of the subsets of missing nodes from remote |
|
1231 | """Return list of roots of the subsets of missing nodes from remote | |
1230 |
|
1232 | |||
1231 | If base dict is specified, assume that these nodes and their parents |
|
1233 | If base dict is specified, assume that these nodes and their parents | |
1232 | exist on the remote side and that no child of a node of base exists |
|
1234 | exist on the remote side and that no child of a node of base exists | |
1233 | in both remote and self. |
|
1235 | in both remote and self. | |
1234 | Furthermore base will be updated to include the nodes that exists |
|
1236 | Furthermore base will be updated to include the nodes that exists | |
1235 | in self and remote but no children exists in self and remote. |
|
1237 | in self and remote but no children exists in self and remote. | |
1236 | If a list of heads is specified, return only nodes which are heads |
|
1238 | If a list of heads is specified, return only nodes which are heads | |
1237 | or ancestors of these heads. |
|
1239 | or ancestors of these heads. | |
1238 |
|
1240 | |||
1239 | All the ancestors of base are in self and in remote. |
|
1241 | All the ancestors of base are in self and in remote. | |
1240 | All the descendants of the list returned are missing in self. |
|
1242 | All the descendants of the list returned are missing in self. | |
1241 | (and so we know that the rest of the nodes are missing in remote, see |
|
1243 | (and so we know that the rest of the nodes are missing in remote, see | |
1242 | outgoing) |
|
1244 | outgoing) | |
1243 | """ |
|
1245 | """ | |
1244 | return self.findcommonincoming(remote, base, heads, force)[1] |
|
1246 | return self.findcommonincoming(remote, base, heads, force)[1] | |
1245 |
|
1247 | |||
1246 | def findcommonincoming(self, remote, base=None, heads=None, force=False): |
|
1248 | def findcommonincoming(self, remote, base=None, heads=None, force=False): | |
1247 | """Return a tuple (common, missing roots, heads) used to identify |
|
1249 | """Return a tuple (common, missing roots, heads) used to identify | |
1248 | missing nodes from remote. |
|
1250 | missing nodes from remote. | |
1249 |
|
1251 | |||
1250 | If base dict is specified, assume that these nodes and their parents |
|
1252 | If base dict is specified, assume that these nodes and their parents | |
1251 | exist on the remote side and that no child of a node of base exists |
|
1253 | exist on the remote side and that no child of a node of base exists | |
1252 | in both remote and self. |
|
1254 | in both remote and self. | |
1253 | Furthermore base will be updated to include the nodes that exists |
|
1255 | Furthermore base will be updated to include the nodes that exists | |
1254 | in self and remote but no children exists in self and remote. |
|
1256 | in self and remote but no children exists in self and remote. | |
1255 | If a list of heads is specified, return only nodes which are heads |
|
1257 | If a list of heads is specified, return only nodes which are heads | |
1256 | or ancestors of these heads. |
|
1258 | or ancestors of these heads. | |
1257 |
|
1259 | |||
1258 | All the ancestors of base are in self and in remote. |
|
1260 | All the ancestors of base are in self and in remote. | |
1259 | """ |
|
1261 | """ | |
1260 | m = self.changelog.nodemap |
|
1262 | m = self.changelog.nodemap | |
1261 | search = [] |
|
1263 | search = [] | |
1262 | fetch = set() |
|
1264 | fetch = set() | |
1263 | seen = set() |
|
1265 | seen = set() | |
1264 | seenbranch = set() |
|
1266 | seenbranch = set() | |
1265 | if base is None: |
|
1267 | if base is None: | |
1266 | base = {} |
|
1268 | base = {} | |
1267 |
|
1269 | |||
1268 | if not heads: |
|
1270 | if not heads: | |
1269 | heads = remote.heads() |
|
1271 | heads = remote.heads() | |
1270 |
|
1272 | |||
1271 | if self.changelog.tip() == nullid: |
|
1273 | if self.changelog.tip() == nullid: | |
1272 | base[nullid] = 1 |
|
1274 | base[nullid] = 1 | |
1273 | if heads != [nullid]: |
|
1275 | if heads != [nullid]: | |
1274 | return [nullid], [nullid], list(heads) |
|
1276 | return [nullid], [nullid], list(heads) | |
1275 | return [nullid], [], [] |
|
1277 | return [nullid], [], [] | |
1276 |
|
1278 | |||
1277 | # assume we're closer to the tip than the root |
|
1279 | # assume we're closer to the tip than the root | |
1278 | # and start by examining the heads |
|
1280 | # and start by examining the heads | |
1279 | self.ui.status(_("searching for changes\n")) |
|
1281 | self.ui.status(_("searching for changes\n")) | |
1280 |
|
1282 | |||
1281 | unknown = [] |
|
1283 | unknown = [] | |
1282 | for h in heads: |
|
1284 | for h in heads: | |
1283 | if h not in m: |
|
1285 | if h not in m: | |
1284 | unknown.append(h) |
|
1286 | unknown.append(h) | |
1285 | else: |
|
1287 | else: | |
1286 | base[h] = 1 |
|
1288 | base[h] = 1 | |
1287 |
|
1289 | |||
1288 | heads = unknown |
|
1290 | heads = unknown | |
1289 | if not unknown: |
|
1291 | if not unknown: | |
1290 | return base.keys(), [], [] |
|
1292 | return base.keys(), [], [] | |
1291 |
|
1293 | |||
1292 | req = set(unknown) |
|
1294 | req = set(unknown) | |
1293 | reqcnt = 0 |
|
1295 | reqcnt = 0 | |
1294 |
|
1296 | |||
1295 | # search through remote branches |
|
1297 | # search through remote branches | |
1296 | # a 'branch' here is a linear segment of history, with four parts: |
|
1298 | # a 'branch' here is a linear segment of history, with four parts: | |
1297 | # head, root, first parent, second parent |
|
1299 | # head, root, first parent, second parent | |
1298 | # (a branch always has two parents (or none) by definition) |
|
1300 | # (a branch always has two parents (or none) by definition) | |
1299 | unknown = remote.branches(unknown) |
|
1301 | unknown = remote.branches(unknown) | |
1300 | while unknown: |
|
1302 | while unknown: | |
1301 | r = [] |
|
1303 | r = [] | |
1302 | while unknown: |
|
1304 | while unknown: | |
1303 | n = unknown.pop(0) |
|
1305 | n = unknown.pop(0) | |
1304 | if n[0] in seen: |
|
1306 | if n[0] in seen: | |
1305 | continue |
|
1307 | continue | |
1306 |
|
1308 | |||
1307 | self.ui.debug("examining %s:%s\n" |
|
1309 | self.ui.debug("examining %s:%s\n" | |
1308 | % (short(n[0]), short(n[1]))) |
|
1310 | % (short(n[0]), short(n[1]))) | |
1309 | if n[0] == nullid: # found the end of the branch |
|
1311 | if n[0] == nullid: # found the end of the branch | |
1310 | pass |
|
1312 | pass | |
1311 | elif n in seenbranch: |
|
1313 | elif n in seenbranch: | |
1312 | self.ui.debug("branch already found\n") |
|
1314 | self.ui.debug("branch already found\n") | |
1313 | continue |
|
1315 | continue | |
1314 | elif n[1] and n[1] in m: # do we know the base? |
|
1316 | elif n[1] and n[1] in m: # do we know the base? | |
1315 | self.ui.debug("found incomplete branch %s:%s\n" |
|
1317 | self.ui.debug("found incomplete branch %s:%s\n" | |
1316 | % (short(n[0]), short(n[1]))) |
|
1318 | % (short(n[0]), short(n[1]))) | |
1317 | search.append(n[0:2]) # schedule branch range for scanning |
|
1319 | search.append(n[0:2]) # schedule branch range for scanning | |
1318 | seenbranch.add(n) |
|
1320 | seenbranch.add(n) | |
1319 | else: |
|
1321 | else: | |
1320 | if n[1] not in seen and n[1] not in fetch: |
|
1322 | if n[1] not in seen and n[1] not in fetch: | |
1321 | if n[2] in m and n[3] in m: |
|
1323 | if n[2] in m and n[3] in m: | |
1322 | self.ui.debug("found new changeset %s\n" % |
|
1324 | self.ui.debug("found new changeset %s\n" % | |
1323 | short(n[1])) |
|
1325 | short(n[1])) | |
1324 | fetch.add(n[1]) # earliest unknown |
|
1326 | fetch.add(n[1]) # earliest unknown | |
1325 | for p in n[2:4]: |
|
1327 | for p in n[2:4]: | |
1326 | if p in m: |
|
1328 | if p in m: | |
1327 | base[p] = 1 # latest known |
|
1329 | base[p] = 1 # latest known | |
1328 |
|
1330 | |||
1329 | for p in n[2:4]: |
|
1331 | for p in n[2:4]: | |
1330 | if p not in req and p not in m: |
|
1332 | if p not in req and p not in m: | |
1331 | r.append(p) |
|
1333 | r.append(p) | |
1332 | req.add(p) |
|
1334 | req.add(p) | |
1333 | seen.add(n[0]) |
|
1335 | seen.add(n[0]) | |
1334 |
|
1336 | |||
1335 | if r: |
|
1337 | if r: | |
1336 | reqcnt += 1 |
|
1338 | reqcnt += 1 | |
1337 | self.ui.debug("request %d: %s\n" % |
|
1339 | self.ui.debug("request %d: %s\n" % | |
1338 | (reqcnt, " ".join(map(short, r)))) |
|
1340 | (reqcnt, " ".join(map(short, r)))) | |
1339 | for p in xrange(0, len(r), 10): |
|
1341 | for p in xrange(0, len(r), 10): | |
1340 | for b in remote.branches(r[p:p+10]): |
|
1342 | for b in remote.branches(r[p:p+10]): | |
1341 | self.ui.debug("received %s:%s\n" % |
|
1343 | self.ui.debug("received %s:%s\n" % | |
1342 | (short(b[0]), short(b[1]))) |
|
1344 | (short(b[0]), short(b[1]))) | |
1343 | unknown.append(b) |
|
1345 | unknown.append(b) | |
1344 |
|
1346 | |||
1345 | # do binary search on the branches we found |
|
1347 | # do binary search on the branches we found | |
1346 | while search: |
|
1348 | while search: | |
1347 | newsearch = [] |
|
1349 | newsearch = [] | |
1348 | reqcnt += 1 |
|
1350 | reqcnt += 1 | |
1349 | for n, l in zip(search, remote.between(search)): |
|
1351 | for n, l in zip(search, remote.between(search)): | |
1350 | l.append(n[1]) |
|
1352 | l.append(n[1]) | |
1351 | p = n[0] |
|
1353 | p = n[0] | |
1352 | f = 1 |
|
1354 | f = 1 | |
1353 | for i in l: |
|
1355 | for i in l: | |
1354 | self.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i))) |
|
1356 | self.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i))) | |
1355 | if i in m: |
|
1357 | if i in m: | |
1356 | if f <= 2: |
|
1358 | if f <= 2: | |
1357 | self.ui.debug("found new branch changeset %s\n" % |
|
1359 | self.ui.debug("found new branch changeset %s\n" % | |
1358 | short(p)) |
|
1360 | short(p)) | |
1359 | fetch.add(p) |
|
1361 | fetch.add(p) | |
1360 | base[i] = 1 |
|
1362 | base[i] = 1 | |
1361 | else: |
|
1363 | else: | |
1362 | self.ui.debug("narrowed branch search to %s:%s\n" |
|
1364 | self.ui.debug("narrowed branch search to %s:%s\n" | |
1363 | % (short(p), short(i))) |
|
1365 | % (short(p), short(i))) | |
1364 | newsearch.append((p, i)) |
|
1366 | newsearch.append((p, i)) | |
1365 | break |
|
1367 | break | |
1366 | p, f = i, f * 2 |
|
1368 | p, f = i, f * 2 | |
1367 | search = newsearch |
|
1369 | search = newsearch | |
1368 |
|
1370 | |||
1369 | # sanity check our fetch list |
|
1371 | # sanity check our fetch list | |
1370 | for f in fetch: |
|
1372 | for f in fetch: | |
1371 | if f in m: |
|
1373 | if f in m: | |
1372 | raise error.RepoError(_("already have changeset ") |
|
1374 | raise error.RepoError(_("already have changeset ") | |
1373 | + short(f[:4])) |
|
1375 | + short(f[:4])) | |
1374 |
|
1376 | |||
1375 | if base.keys() == [nullid]: |
|
1377 | if base.keys() == [nullid]: | |
1376 | if force: |
|
1378 | if force: | |
1377 | self.ui.warn(_("warning: repository is unrelated\n")) |
|
1379 | self.ui.warn(_("warning: repository is unrelated\n")) | |
1378 | else: |
|
1380 | else: | |
1379 | raise util.Abort(_("repository is unrelated")) |
|
1381 | raise util.Abort(_("repository is unrelated")) | |
1380 |
|
1382 | |||
1381 | self.ui.debug("found new changesets starting at " + |
|
1383 | self.ui.debug("found new changesets starting at " + | |
1382 | " ".join([short(f) for f in fetch]) + "\n") |
|
1384 | " ".join([short(f) for f in fetch]) + "\n") | |
1383 |
|
1385 | |||
1384 | self.ui.debug("%d total queries\n" % reqcnt) |
|
1386 | self.ui.debug("%d total queries\n" % reqcnt) | |
1385 |
|
1387 | |||
1386 | return base.keys(), list(fetch), heads |
|
1388 | return base.keys(), list(fetch), heads | |
1387 |
|
1389 | |||
1388 | def findoutgoing(self, remote, base=None, heads=None, force=False): |
|
1390 | def findoutgoing(self, remote, base=None, heads=None, force=False): | |
1389 | """Return list of nodes that are roots of subsets not in remote |
|
1391 | """Return list of nodes that are roots of subsets not in remote | |
1390 |
|
1392 | |||
1391 | If base dict is specified, assume that these nodes and their parents |
|
1393 | If base dict is specified, assume that these nodes and their parents | |
1392 | exist on the remote side. |
|
1394 | exist on the remote side. | |
1393 | If a list of heads is specified, return only nodes which are heads |
|
1395 | If a list of heads is specified, return only nodes which are heads | |
1394 | or ancestors of these heads, and return a second element which |
|
1396 | or ancestors of these heads, and return a second element which | |
1395 | contains all remote heads which get new children. |
|
1397 | contains all remote heads which get new children. | |
1396 | """ |
|
1398 | """ | |
1397 | if base is None: |
|
1399 | if base is None: | |
1398 | base = {} |
|
1400 | base = {} | |
1399 | self.findincoming(remote, base, heads, force=force) |
|
1401 | self.findincoming(remote, base, heads, force=force) | |
1400 |
|
1402 | |||
1401 | self.ui.debug("common changesets up to " |
|
1403 | self.ui.debug("common changesets up to " | |
1402 | + " ".join(map(short, base.keys())) + "\n") |
|
1404 | + " ".join(map(short, base.keys())) + "\n") | |
1403 |
|
1405 | |||
1404 | remain = set(self.changelog.nodemap) |
|
1406 | remain = set(self.changelog.nodemap) | |
1405 |
|
1407 | |||
1406 | # prune everything remote has from the tree |
|
1408 | # prune everything remote has from the tree | |
1407 | remain.remove(nullid) |
|
1409 | remain.remove(nullid) | |
1408 | remove = base.keys() |
|
1410 | remove = base.keys() | |
1409 | while remove: |
|
1411 | while remove: | |
1410 | n = remove.pop(0) |
|
1412 | n = remove.pop(0) | |
1411 | if n in remain: |
|
1413 | if n in remain: | |
1412 | remain.remove(n) |
|
1414 | remain.remove(n) | |
1413 | for p in self.changelog.parents(n): |
|
1415 | for p in self.changelog.parents(n): | |
1414 | remove.append(p) |
|
1416 | remove.append(p) | |
1415 |
|
1417 | |||
1416 | # find every node whose parents have been pruned |
|
1418 | # find every node whose parents have been pruned | |
1417 | subset = [] |
|
1419 | subset = [] | |
1418 | # find every remote head that will get new children |
|
1420 | # find every remote head that will get new children | |
1419 | updated_heads = set() |
|
1421 | updated_heads = set() | |
1420 | for n in remain: |
|
1422 | for n in remain: | |
1421 | p1, p2 = self.changelog.parents(n) |
|
1423 | p1, p2 = self.changelog.parents(n) | |
1422 | if p1 not in remain and p2 not in remain: |
|
1424 | if p1 not in remain and p2 not in remain: | |
1423 | subset.append(n) |
|
1425 | subset.append(n) | |
1424 | if heads: |
|
1426 | if heads: | |
1425 | if p1 in heads: |
|
1427 | if p1 in heads: | |
1426 | updated_heads.add(p1) |
|
1428 | updated_heads.add(p1) | |
1427 | if p2 in heads: |
|
1429 | if p2 in heads: | |
1428 | updated_heads.add(p2) |
|
1430 | updated_heads.add(p2) | |
1429 |
|
1431 | |||
1430 | # this is the set of all roots we have to push |
|
1432 | # this is the set of all roots we have to push | |
1431 | if heads: |
|
1433 | if heads: | |
1432 | return subset, list(updated_heads) |
|
1434 | return subset, list(updated_heads) | |
1433 | else: |
|
1435 | else: | |
1434 | return subset |
|
1436 | return subset | |
1435 |
|
1437 | |||
1436 | def pull(self, remote, heads=None, force=False): |
|
1438 | def pull(self, remote, heads=None, force=False): | |
1437 | lock = self.lock() |
|
1439 | lock = self.lock() | |
1438 | try: |
|
1440 | try: | |
1439 | common, fetch, rheads = self.findcommonincoming(remote, heads=heads, |
|
1441 | common, fetch, rheads = self.findcommonincoming(remote, heads=heads, | |
1440 | force=force) |
|
1442 | force=force) | |
1441 | if fetch == [nullid]: |
|
1443 | if fetch == [nullid]: | |
1442 | self.ui.status(_("requesting all changes\n")) |
|
1444 | self.ui.status(_("requesting all changes\n")) | |
1443 |
|
1445 | |||
1444 | if not fetch: |
|
1446 | if not fetch: | |
1445 | self.ui.status(_("no changes found\n")) |
|
1447 | self.ui.status(_("no changes found\n")) | |
1446 | return 0 |
|
1448 | return 0 | |
1447 |
|
1449 | |||
1448 | if heads is None and remote.capable('changegroupsubset'): |
|
1450 | if heads is None and remote.capable('changegroupsubset'): | |
1449 | heads = rheads |
|
1451 | heads = rheads | |
1450 |
|
1452 | |||
1451 | if heads is None: |
|
1453 | if heads is None: | |
1452 | cg = remote.changegroup(fetch, 'pull') |
|
1454 | cg = remote.changegroup(fetch, 'pull') | |
1453 | else: |
|
1455 | else: | |
1454 | if not remote.capable('changegroupsubset'): |
|
1456 | if not remote.capable('changegroupsubset'): | |
1455 | raise util.Abort(_("Partial pull cannot be done because " |
|
1457 | raise util.Abort(_("Partial pull cannot be done because " | |
1456 | "other repository doesn't support " |
|
1458 | "other repository doesn't support " | |
1457 | "changegroupsubset.")) |
|
1459 | "changegroupsubset.")) | |
1458 | cg = remote.changegroupsubset(fetch, heads, 'pull') |
|
1460 | cg = remote.changegroupsubset(fetch, heads, 'pull') | |
1459 | return self.addchangegroup(cg, 'pull', remote.url()) |
|
1461 | return self.addchangegroup(cg, 'pull', remote.url()) | |
1460 | finally: |
|
1462 | finally: | |
1461 | lock.release() |
|
1463 | lock.release() | |
1462 |
|
1464 | |||
1463 | def push(self, remote, force=False, revs=None): |
|
1465 | def push(self, remote, force=False, revs=None): | |
1464 | # there are two ways to push to remote repo: |
|
1466 | # there are two ways to push to remote repo: | |
1465 | # |
|
1467 | # | |
1466 | # addchangegroup assumes local user can lock remote |
|
1468 | # addchangegroup assumes local user can lock remote | |
1467 | # repo (local filesystem, old ssh servers). |
|
1469 | # repo (local filesystem, old ssh servers). | |
1468 | # |
|
1470 | # | |
1469 | # unbundle assumes local user cannot lock remote repo (new ssh |
|
1471 | # unbundle assumes local user cannot lock remote repo (new ssh | |
1470 | # servers, http servers). |
|
1472 | # servers, http servers). | |
1471 |
|
1473 | |||
1472 | if remote.capable('unbundle'): |
|
1474 | if remote.capable('unbundle'): | |
1473 | return self.push_unbundle(remote, force, revs) |
|
1475 | return self.push_unbundle(remote, force, revs) | |
1474 | return self.push_addchangegroup(remote, force, revs) |
|
1476 | return self.push_addchangegroup(remote, force, revs) | |
1475 |
|
1477 | |||
1476 | def prepush(self, remote, force, revs): |
|
1478 | def prepush(self, remote, force, revs): | |
1477 | '''Analyze the local and remote repositories and determine which |
|
1479 | '''Analyze the local and remote repositories and determine which | |
1478 | changesets need to be pushed to the remote. Return a tuple |
|
1480 | changesets need to be pushed to the remote. Return a tuple | |
1479 | (changegroup, remoteheads). changegroup is a readable file-like |
|
1481 | (changegroup, remoteheads). changegroup is a readable file-like | |
1480 | object whose read() returns successive changegroup chunks ready to |
|
1482 | object whose read() returns successive changegroup chunks ready to | |
1481 | be sent over the wire. remoteheads is the list of remote heads. |
|
1483 | be sent over the wire. remoteheads is the list of remote heads. | |
1482 | ''' |
|
1484 | ''' | |
1483 | common = {} |
|
1485 | common = {} | |
1484 | remote_heads = remote.heads() |
|
1486 | remote_heads = remote.heads() | |
1485 | inc = self.findincoming(remote, common, remote_heads, force=force) |
|
1487 | inc = self.findincoming(remote, common, remote_heads, force=force) | |
1486 |
|
1488 | |||
1487 | update, updated_heads = self.findoutgoing(remote, common, remote_heads) |
|
1489 | update, updated_heads = self.findoutgoing(remote, common, remote_heads) | |
1488 | msng_cl, bases, heads = self.changelog.nodesbetween(update, revs) |
|
1490 | msng_cl, bases, heads = self.changelog.nodesbetween(update, revs) | |
1489 |
|
1491 | |||
1490 | def checkbranch(lheads, rheads, updatelb): |
|
1492 | def checkbranch(lheads, rheads, updatelb): | |
1491 | ''' |
|
1493 | ''' | |
1492 | check whether there are more local heads than remote heads on |
|
1494 | check whether there are more local heads than remote heads on | |
1493 | a specific branch. |
|
1495 | a specific branch. | |
1494 |
|
1496 | |||
1495 | lheads: local branch heads |
|
1497 | lheads: local branch heads | |
1496 | rheads: remote branch heads |
|
1498 | rheads: remote branch heads | |
1497 | updatelb: outgoing local branch bases |
|
1499 | updatelb: outgoing local branch bases | |
1498 | ''' |
|
1500 | ''' | |
1499 |
|
1501 | |||
1500 | warn = 0 |
|
1502 | warn = 0 | |
1501 |
|
1503 | |||
1502 | if not revs and len(lheads) > len(rheads): |
|
1504 | if not revs and len(lheads) > len(rheads): | |
1503 | warn = 1 |
|
1505 | warn = 1 | |
1504 | else: |
|
1506 | else: | |
1505 | # add local heads involved in the push |
|
1507 | # add local heads involved in the push | |
1506 | updatelheads = [self.changelog.heads(x, lheads) |
|
1508 | updatelheads = [self.changelog.heads(x, lheads) | |
1507 | for x in updatelb] |
|
1509 | for x in updatelb] | |
1508 | newheads = set(sum(updatelheads, [])) & set(lheads) |
|
1510 | newheads = set(sum(updatelheads, [])) & set(lheads) | |
1509 |
|
1511 | |||
1510 | if not newheads: |
|
1512 | if not newheads: | |
1511 | return True |
|
1513 | return True | |
1512 |
|
1514 | |||
1513 | # add heads we don't have or that are not involved in the push |
|
1515 | # add heads we don't have or that are not involved in the push | |
1514 | for r in rheads: |
|
1516 | for r in rheads: | |
1515 | if r in self.changelog.nodemap: |
|
1517 | if r in self.changelog.nodemap: | |
1516 | desc = self.changelog.heads(r, heads) |
|
1518 | desc = self.changelog.heads(r, heads) | |
1517 | l = [h for h in heads if h in desc] |
|
1519 | l = [h for h in heads if h in desc] | |
1518 | if not l: |
|
1520 | if not l: | |
1519 | newheads.add(r) |
|
1521 | newheads.add(r) | |
1520 | else: |
|
1522 | else: | |
1521 | newheads.add(r) |
|
1523 | newheads.add(r) | |
1522 | if len(newheads) > len(rheads): |
|
1524 | if len(newheads) > len(rheads): | |
1523 | warn = 1 |
|
1525 | warn = 1 | |
1524 |
|
1526 | |||
1525 | if warn: |
|
1527 | if warn: | |
1526 | if not rheads: # new branch requires --force |
|
1528 | if not rheads: # new branch requires --force | |
1527 | self.ui.warn(_("abort: push creates new" |
|
1529 | self.ui.warn(_("abort: push creates new" | |
1528 | " remote branch '%s'!\n") % |
|
1530 | " remote branch '%s'!\n") % | |
1529 | self[lheads[0]].branch()) |
|
1531 | self[lheads[0]].branch()) | |
1530 | else: |
|
1532 | else: | |
1531 | self.ui.warn(_("abort: push creates new remote heads!\n")) |
|
1533 | self.ui.warn(_("abort: push creates new remote heads!\n")) | |
1532 |
|
1534 | |||
1533 | self.ui.status(_("(did you forget to merge?" |
|
1535 | self.ui.status(_("(did you forget to merge?" | |
1534 | " use push -f to force)\n")) |
|
1536 | " use push -f to force)\n")) | |
1535 | return False |
|
1537 | return False | |
1536 | return True |
|
1538 | return True | |
1537 |
|
1539 | |||
1538 | if not bases: |
|
1540 | if not bases: | |
1539 | self.ui.status(_("no changes found\n")) |
|
1541 | self.ui.status(_("no changes found\n")) | |
1540 | return None, 1 |
|
1542 | return None, 1 | |
1541 | elif not force: |
|
1543 | elif not force: | |
1542 | # Check for each named branch if we're creating new remote heads. |
|
1544 | # Check for each named branch if we're creating new remote heads. | |
1543 | # To be a remote head after push, node must be either: |
|
1545 | # To be a remote head after push, node must be either: | |
1544 | # - unknown locally |
|
1546 | # - unknown locally | |
1545 | # - a local outgoing head descended from update |
|
1547 | # - a local outgoing head descended from update | |
1546 | # - a remote head that's known locally and not |
|
1548 | # - a remote head that's known locally and not | |
1547 | # ancestral to an outgoing head |
|
1549 | # ancestral to an outgoing head | |
1548 | # |
|
1550 | # | |
1549 | # New named branches cannot be created without --force. |
|
1551 | # New named branches cannot be created without --force. | |
1550 |
|
1552 | |||
1551 | if remote_heads != [nullid]: |
|
1553 | if remote_heads != [nullid]: | |
1552 | if remote.capable('branchmap'): |
|
1554 | if remote.capable('branchmap'): | |
1553 | localhds = {} |
|
1555 | localhds = {} | |
1554 | if not revs: |
|
1556 | if not revs: | |
1555 | localhds = self.branchmap() |
|
1557 | localhds = self.branchmap() | |
1556 | else: |
|
1558 | else: | |
1557 | for n in heads: |
|
1559 | for n in heads: | |
1558 | branch = self[n].branch() |
|
1560 | branch = self[n].branch() | |
1559 | if branch in localhds: |
|
1561 | if branch in localhds: | |
1560 | localhds[branch].append(n) |
|
1562 | localhds[branch].append(n) | |
1561 | else: |
|
1563 | else: | |
1562 | localhds[branch] = [n] |
|
1564 | localhds[branch] = [n] | |
1563 |
|
1565 | |||
1564 | remotehds = remote.branchmap() |
|
1566 | remotehds = remote.branchmap() | |
1565 |
|
1567 | |||
1566 | for lh in localhds: |
|
1568 | for lh in localhds: | |
1567 | if lh in remotehds: |
|
1569 | if lh in remotehds: | |
1568 | rheads = remotehds[lh] |
|
1570 | rheads = remotehds[lh] | |
1569 | else: |
|
1571 | else: | |
1570 | rheads = [] |
|
1572 | rheads = [] | |
1571 | lheads = localhds[lh] |
|
1573 | lheads = localhds[lh] | |
1572 | if not checkbranch(lheads, rheads, update): |
|
1574 | if not checkbranch(lheads, rheads, update): | |
1573 | return None, 0 |
|
1575 | return None, 0 | |
1574 | else: |
|
1576 | else: | |
1575 | if not checkbranch(heads, remote_heads, update): |
|
1577 | if not checkbranch(heads, remote_heads, update): | |
1576 | return None, 0 |
|
1578 | return None, 0 | |
1577 |
|
1579 | |||
1578 | if inc: |
|
1580 | if inc: | |
1579 | self.ui.warn(_("note: unsynced remote changes!\n")) |
|
1581 | self.ui.warn(_("note: unsynced remote changes!\n")) | |
1580 |
|
1582 | |||
1581 |
|
1583 | |||
1582 | if revs is None: |
|
1584 | if revs is None: | |
1583 | # use the fast path, no race possible on push |
|
1585 | # use the fast path, no race possible on push | |
1584 | nodes = self.changelog.findmissing(common.keys()) |
|
1586 | nodes = self.changelog.findmissing(common.keys()) | |
1585 | cg = self._changegroup(nodes, 'push') |
|
1587 | cg = self._changegroup(nodes, 'push') | |
1586 | else: |
|
1588 | else: | |
1587 | cg = self.changegroupsubset(update, revs, 'push') |
|
1589 | cg = self.changegroupsubset(update, revs, 'push') | |
1588 | return cg, remote_heads |
|
1590 | return cg, remote_heads | |
1589 |
|
1591 | |||
1590 | def push_addchangegroup(self, remote, force, revs): |
|
1592 | def push_addchangegroup(self, remote, force, revs): | |
1591 | lock = remote.lock() |
|
1593 | lock = remote.lock() | |
1592 | try: |
|
1594 | try: | |
1593 | ret = self.prepush(remote, force, revs) |
|
1595 | ret = self.prepush(remote, force, revs) | |
1594 | if ret[0] is not None: |
|
1596 | if ret[0] is not None: | |
1595 | cg, remote_heads = ret |
|
1597 | cg, remote_heads = ret | |
1596 | return remote.addchangegroup(cg, 'push', self.url()) |
|
1598 | return remote.addchangegroup(cg, 'push', self.url()) | |
1597 | return ret[1] |
|
1599 | return ret[1] | |
1598 | finally: |
|
1600 | finally: | |
1599 | lock.release() |
|
1601 | lock.release() | |
1600 |
|
1602 | |||
1601 | def push_unbundle(self, remote, force, revs): |
|
1603 | def push_unbundle(self, remote, force, revs): | |
1602 | # local repo finds heads on server, finds out what revs it |
|
1604 | # local repo finds heads on server, finds out what revs it | |
1603 | # must push. once revs transferred, if server finds it has |
|
1605 | # must push. once revs transferred, if server finds it has | |
1604 | # different heads (someone else won commit/push race), server |
|
1606 | # different heads (someone else won commit/push race), server | |
1605 | # aborts. |
|
1607 | # aborts. | |
1606 |
|
1608 | |||
1607 | ret = self.prepush(remote, force, revs) |
|
1609 | ret = self.prepush(remote, force, revs) | |
1608 | if ret[0] is not None: |
|
1610 | if ret[0] is not None: | |
1609 | cg, remote_heads = ret |
|
1611 | cg, remote_heads = ret | |
1610 | if force: remote_heads = ['force'] |
|
1612 | if force: remote_heads = ['force'] | |
1611 | return remote.unbundle(cg, remote_heads, 'push') |
|
1613 | return remote.unbundle(cg, remote_heads, 'push') | |
1612 | return ret[1] |
|
1614 | return ret[1] | |
1613 |
|
1615 | |||
1614 | def changegroupinfo(self, nodes, source): |
|
1616 | def changegroupinfo(self, nodes, source): | |
1615 | if self.ui.verbose or source == 'bundle': |
|
1617 | if self.ui.verbose or source == 'bundle': | |
1616 | self.ui.status(_("%d changesets found\n") % len(nodes)) |
|
1618 | self.ui.status(_("%d changesets found\n") % len(nodes)) | |
1617 | if self.ui.debugflag: |
|
1619 | if self.ui.debugflag: | |
1618 | self.ui.debug("list of changesets:\n") |
|
1620 | self.ui.debug("list of changesets:\n") | |
1619 | for node in nodes: |
|
1621 | for node in nodes: | |
1620 | self.ui.debug("%s\n" % hex(node)) |
|
1622 | self.ui.debug("%s\n" % hex(node)) | |
1621 |
|
1623 | |||
1622 | def changegroupsubset(self, bases, heads, source, extranodes=None): |
|
1624 | def changegroupsubset(self, bases, heads, source, extranodes=None): | |
1623 | """Compute a changegroup consisting of all the nodes that are |
|
1625 | """Compute a changegroup consisting of all the nodes that are | |
1624 | descendents of any of the bases and ancestors of any of the heads. |
|
1626 | descendents of any of the bases and ancestors of any of the heads. | |
1625 | Return a chunkbuffer object whose read() method will return |
|
1627 | Return a chunkbuffer object whose read() method will return | |
1626 | successive changegroup chunks. |
|
1628 | successive changegroup chunks. | |
1627 |
|
1629 | |||
1628 | It is fairly complex as determining which filenodes and which |
|
1630 | It is fairly complex as determining which filenodes and which | |
1629 | manifest nodes need to be included for the changeset to be complete |
|
1631 | manifest nodes need to be included for the changeset to be complete | |
1630 | is non-trivial. |
|
1632 | is non-trivial. | |
1631 |
|
1633 | |||
1632 | Another wrinkle is doing the reverse, figuring out which changeset in |
|
1634 | Another wrinkle is doing the reverse, figuring out which changeset in | |
1633 | the changegroup a particular filenode or manifestnode belongs to. |
|
1635 | the changegroup a particular filenode or manifestnode belongs to. | |
1634 |
|
1636 | |||
1635 | The caller can specify some nodes that must be included in the |
|
1637 | The caller can specify some nodes that must be included in the | |
1636 | changegroup using the extranodes argument. It should be a dict |
|
1638 | changegroup using the extranodes argument. It should be a dict | |
1637 | where the keys are the filenames (or 1 for the manifest), and the |
|
1639 | where the keys are the filenames (or 1 for the manifest), and the | |
1638 | values are lists of (node, linknode) tuples, where node is a wanted |
|
1640 | values are lists of (node, linknode) tuples, where node is a wanted | |
1639 | node and linknode is the changelog node that should be transmitted as |
|
1641 | node and linknode is the changelog node that should be transmitted as | |
1640 | the linkrev. |
|
1642 | the linkrev. | |
1641 | """ |
|
1643 | """ | |
1642 |
|
1644 | |||
1643 | # Set up some initial variables |
|
1645 | # Set up some initial variables | |
1644 | # Make it easy to refer to self.changelog |
|
1646 | # Make it easy to refer to self.changelog | |
1645 | cl = self.changelog |
|
1647 | cl = self.changelog | |
1646 | # msng is short for missing - compute the list of changesets in this |
|
1648 | # msng is short for missing - compute the list of changesets in this | |
1647 | # changegroup. |
|
1649 | # changegroup. | |
1648 | if not bases: |
|
1650 | if not bases: | |
1649 | bases = [nullid] |
|
1651 | bases = [nullid] | |
1650 | msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads) |
|
1652 | msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads) | |
1651 |
|
1653 | |||
1652 | if extranodes is None: |
|
1654 | if extranodes is None: | |
1653 | # can we go through the fast path ? |
|
1655 | # can we go through the fast path ? | |
1654 | heads.sort() |
|
1656 | heads.sort() | |
1655 | allheads = self.heads() |
|
1657 | allheads = self.heads() | |
1656 | allheads.sort() |
|
1658 | allheads.sort() | |
1657 | if heads == allheads: |
|
1659 | if heads == allheads: | |
1658 | return self._changegroup(msng_cl_lst, source) |
|
1660 | return self._changegroup(msng_cl_lst, source) | |
1659 |
|
1661 | |||
1660 | # slow path |
|
1662 | # slow path | |
1661 | self.hook('preoutgoing', throw=True, source=source) |
|
1663 | self.hook('preoutgoing', throw=True, source=source) | |
1662 |
|
1664 | |||
1663 | self.changegroupinfo(msng_cl_lst, source) |
|
1665 | self.changegroupinfo(msng_cl_lst, source) | |
1664 | # Some bases may turn out to be superfluous, and some heads may be |
|
1666 | # Some bases may turn out to be superfluous, and some heads may be | |
1665 | # too. nodesbetween will return the minimal set of bases and heads |
|
1667 | # too. nodesbetween will return the minimal set of bases and heads | |
1666 | # necessary to re-create the changegroup. |
|
1668 | # necessary to re-create the changegroup. | |
1667 |
|
1669 | |||
1668 | # Known heads are the list of heads that it is assumed the recipient |
|
1670 | # Known heads are the list of heads that it is assumed the recipient | |
1669 | # of this changegroup will know about. |
|
1671 | # of this changegroup will know about. | |
1670 | knownheads = set() |
|
1672 | knownheads = set() | |
1671 | # We assume that all parents of bases are known heads. |
|
1673 | # We assume that all parents of bases are known heads. | |
1672 | for n in bases: |
|
1674 | for n in bases: | |
1673 | knownheads.update(cl.parents(n)) |
|
1675 | knownheads.update(cl.parents(n)) | |
1674 | knownheads.discard(nullid) |
|
1676 | knownheads.discard(nullid) | |
1675 | knownheads = list(knownheads) |
|
1677 | knownheads = list(knownheads) | |
1676 | if knownheads: |
|
1678 | if knownheads: | |
1677 | # Now that we know what heads are known, we can compute which |
|
1679 | # Now that we know what heads are known, we can compute which | |
1678 | # changesets are known. The recipient must know about all |
|
1680 | # changesets are known. The recipient must know about all | |
1679 | # changesets required to reach the known heads from the null |
|
1681 | # changesets required to reach the known heads from the null | |
1680 | # changeset. |
|
1682 | # changeset. | |
1681 | has_cl_set, junk, junk = cl.nodesbetween(None, knownheads) |
|
1683 | has_cl_set, junk, junk = cl.nodesbetween(None, knownheads) | |
1682 | junk = None |
|
1684 | junk = None | |
1683 | # Transform the list into a set. |
|
1685 | # Transform the list into a set. | |
1684 | has_cl_set = set(has_cl_set) |
|
1686 | has_cl_set = set(has_cl_set) | |
1685 | else: |
|
1687 | else: | |
1686 | # If there were no known heads, the recipient cannot be assumed to |
|
1688 | # If there were no known heads, the recipient cannot be assumed to | |
1687 | # know about any changesets. |
|
1689 | # know about any changesets. | |
1688 | has_cl_set = set() |
|
1690 | has_cl_set = set() | |
1689 |
|
1691 | |||
1690 | # Make it easy to refer to self.manifest |
|
1692 | # Make it easy to refer to self.manifest | |
1691 | mnfst = self.manifest |
|
1693 | mnfst = self.manifest | |
1692 | # We don't know which manifests are missing yet |
|
1694 | # We don't know which manifests are missing yet | |
1693 | msng_mnfst_set = {} |
|
1695 | msng_mnfst_set = {} | |
1694 | # Nor do we know which filenodes are missing. |
|
1696 | # Nor do we know which filenodes are missing. | |
1695 | msng_filenode_set = {} |
|
1697 | msng_filenode_set = {} | |
1696 |
|
1698 | |||
1697 | junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex |
|
1699 | junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex | |
1698 | junk = None |
|
1700 | junk = None | |
1699 |
|
1701 | |||
1700 | # A changeset always belongs to itself, so the changenode lookup |
|
1702 | # A changeset always belongs to itself, so the changenode lookup | |
1701 | # function for a changenode is identity. |
|
1703 | # function for a changenode is identity. | |
1702 | def identity(x): |
|
1704 | def identity(x): | |
1703 | return x |
|
1705 | return x | |
1704 |
|
1706 | |||
1705 | # If we determine that a particular file or manifest node must be a |
|
1707 | # If we determine that a particular file or manifest node must be a | |
1706 | # node that the recipient of the changegroup will already have, we can |
|
1708 | # node that the recipient of the changegroup will already have, we can | |
1707 | # also assume the recipient will have all the parents. This function |
|
1709 | # also assume the recipient will have all the parents. This function | |
1708 | # prunes them from the set of missing nodes. |
|
1710 | # prunes them from the set of missing nodes. | |
1709 | def prune_parents(revlog, hasset, msngset): |
|
1711 | def prune_parents(revlog, hasset, msngset): | |
1710 | for r in revlog.ancestors(*[revlog.rev(n) for n in hasset]): |
|
1712 | for r in revlog.ancestors(*[revlog.rev(n) for n in hasset]): | |
1711 | msngset.pop(revlog.node(r), None) |
|
1713 | msngset.pop(revlog.node(r), None) | |
1712 |
|
1714 | |||
1713 | # This is a function generating function used to set up an environment |
|
1715 | # This is a function generating function used to set up an environment | |
1714 | # for the inner function to execute in. |
|
1716 | # for the inner function to execute in. | |
1715 | def manifest_and_file_collector(changedfileset): |
|
1717 | def manifest_and_file_collector(changedfileset): | |
1716 | # This is an information gathering function that gathers |
|
1718 | # This is an information gathering function that gathers | |
1717 | # information from each changeset node that goes out as part of |
|
1719 | # information from each changeset node that goes out as part of | |
1718 | # the changegroup. The information gathered is a list of which |
|
1720 | # the changegroup. The information gathered is a list of which | |
1719 | # manifest nodes are potentially required (the recipient may |
|
1721 | # manifest nodes are potentially required (the recipient may | |
1720 | # already have them) and total list of all files which were |
|
1722 | # already have them) and total list of all files which were | |
1721 | # changed in any changeset in the changegroup. |
|
1723 | # changed in any changeset in the changegroup. | |
1722 | # |
|
1724 | # | |
1723 | # We also remember the first changenode we saw any manifest |
|
1725 | # We also remember the first changenode we saw any manifest | |
1724 | # referenced by so we can later determine which changenode 'owns' |
|
1726 | # referenced by so we can later determine which changenode 'owns' | |
1725 | # the manifest. |
|
1727 | # the manifest. | |
1726 | def collect_manifests_and_files(clnode): |
|
1728 | def collect_manifests_and_files(clnode): | |
1727 | c = cl.read(clnode) |
|
1729 | c = cl.read(clnode) | |
1728 | for f in c[3]: |
|
1730 | for f in c[3]: | |
1729 | # This is to make sure we only have one instance of each |
|
1731 | # This is to make sure we only have one instance of each | |
1730 | # filename string for each filename. |
|
1732 | # filename string for each filename. | |
1731 | changedfileset.setdefault(f, f) |
|
1733 | changedfileset.setdefault(f, f) | |
1732 | msng_mnfst_set.setdefault(c[0], clnode) |
|
1734 | msng_mnfst_set.setdefault(c[0], clnode) | |
1733 | return collect_manifests_and_files |
|
1735 | return collect_manifests_and_files | |
1734 |
|
1736 | |||
1735 | # Figure out which manifest nodes (of the ones we think might be part |
|
1737 | # Figure out which manifest nodes (of the ones we think might be part | |
1736 | # of the changegroup) the recipient must know about and remove them |
|
1738 | # of the changegroup) the recipient must know about and remove them | |
1737 | # from the changegroup. |
|
1739 | # from the changegroup. | |
1738 | def prune_manifests(): |
|
1740 | def prune_manifests(): | |
1739 | has_mnfst_set = set() |
|
1741 | has_mnfst_set = set() | |
1740 | for n in msng_mnfst_set: |
|
1742 | for n in msng_mnfst_set: | |
1741 | # If a 'missing' manifest thinks it belongs to a changenode |
|
1743 | # If a 'missing' manifest thinks it belongs to a changenode | |
1742 | # the recipient is assumed to have, obviously the recipient |
|
1744 | # the recipient is assumed to have, obviously the recipient | |
1743 | # must have that manifest. |
|
1745 | # must have that manifest. | |
1744 | linknode = cl.node(mnfst.linkrev(mnfst.rev(n))) |
|
1746 | linknode = cl.node(mnfst.linkrev(mnfst.rev(n))) | |
1745 | if linknode in has_cl_set: |
|
1747 | if linknode in has_cl_set: | |
1746 | has_mnfst_set.add(n) |
|
1748 | has_mnfst_set.add(n) | |
1747 | prune_parents(mnfst, has_mnfst_set, msng_mnfst_set) |
|
1749 | prune_parents(mnfst, has_mnfst_set, msng_mnfst_set) | |
1748 |
|
1750 | |||
1749 | # Use the information collected in collect_manifests_and_files to say |
|
1751 | # Use the information collected in collect_manifests_and_files to say | |
1750 | # which changenode any manifestnode belongs to. |
|
1752 | # which changenode any manifestnode belongs to. | |
1751 | def lookup_manifest_link(mnfstnode): |
|
1753 | def lookup_manifest_link(mnfstnode): | |
1752 | return msng_mnfst_set[mnfstnode] |
|
1754 | return msng_mnfst_set[mnfstnode] | |
1753 |
|
1755 | |||
1754 | # A function generating function that sets up the initial environment |
|
1756 | # A function generating function that sets up the initial environment | |
1755 | # the inner function. |
|
1757 | # the inner function. | |
1756 | def filenode_collector(changedfiles): |
|
1758 | def filenode_collector(changedfiles): | |
1757 | # This gathers information from each manifestnode included in the |
|
1759 | # This gathers information from each manifestnode included in the | |
1758 | # changegroup about which filenodes the manifest node references |
|
1760 | # changegroup about which filenodes the manifest node references | |
1759 | # so we can include those in the changegroup too. |
|
1761 | # so we can include those in the changegroup too. | |
1760 | # |
|
1762 | # | |
1761 | # It also remembers which changenode each filenode belongs to. It |
|
1763 | # It also remembers which changenode each filenode belongs to. It | |
1762 | # does this by assuming the a filenode belongs to the changenode |
|
1764 | # does this by assuming the a filenode belongs to the changenode | |
1763 | # the first manifest that references it belongs to. |
|
1765 | # the first manifest that references it belongs to. | |
1764 | def collect_msng_filenodes(mnfstnode): |
|
1766 | def collect_msng_filenodes(mnfstnode): | |
1765 | r = mnfst.rev(mnfstnode) |
|
1767 | r = mnfst.rev(mnfstnode) | |
1766 | if r - 1 in mnfst.parentrevs(r): |
|
1768 | if r - 1 in mnfst.parentrevs(r): | |
1767 | # If the previous rev is one of the parents, |
|
1769 | # If the previous rev is one of the parents, | |
1768 | # we only need to see a diff. |
|
1770 | # we only need to see a diff. | |
1769 | deltamf = mnfst.readdelta(mnfstnode) |
|
1771 | deltamf = mnfst.readdelta(mnfstnode) | |
1770 | # For each line in the delta |
|
1772 | # For each line in the delta | |
1771 | for f, fnode in deltamf.iteritems(): |
|
1773 | for f, fnode in deltamf.iteritems(): | |
1772 | f = changedfiles.get(f, None) |
|
1774 | f = changedfiles.get(f, None) | |
1773 | # And if the file is in the list of files we care |
|
1775 | # And if the file is in the list of files we care | |
1774 | # about. |
|
1776 | # about. | |
1775 | if f is not None: |
|
1777 | if f is not None: | |
1776 | # Get the changenode this manifest belongs to |
|
1778 | # Get the changenode this manifest belongs to | |
1777 | clnode = msng_mnfst_set[mnfstnode] |
|
1779 | clnode = msng_mnfst_set[mnfstnode] | |
1778 | # Create the set of filenodes for the file if |
|
1780 | # Create the set of filenodes for the file if | |
1779 | # there isn't one already. |
|
1781 | # there isn't one already. | |
1780 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1782 | ndset = msng_filenode_set.setdefault(f, {}) | |
1781 | # And set the filenode's changelog node to the |
|
1783 | # And set the filenode's changelog node to the | |
1782 | # manifest's if it hasn't been set already. |
|
1784 | # manifest's if it hasn't been set already. | |
1783 | ndset.setdefault(fnode, clnode) |
|
1785 | ndset.setdefault(fnode, clnode) | |
1784 | else: |
|
1786 | else: | |
1785 | # Otherwise we need a full manifest. |
|
1787 | # Otherwise we need a full manifest. | |
1786 | m = mnfst.read(mnfstnode) |
|
1788 | m = mnfst.read(mnfstnode) | |
1787 | # For every file in we care about. |
|
1789 | # For every file in we care about. | |
1788 | for f in changedfiles: |
|
1790 | for f in changedfiles: | |
1789 | fnode = m.get(f, None) |
|
1791 | fnode = m.get(f, None) | |
1790 | # If it's in the manifest |
|
1792 | # If it's in the manifest | |
1791 | if fnode is not None: |
|
1793 | if fnode is not None: | |
1792 | # See comments above. |
|
1794 | # See comments above. | |
1793 | clnode = msng_mnfst_set[mnfstnode] |
|
1795 | clnode = msng_mnfst_set[mnfstnode] | |
1794 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1796 | ndset = msng_filenode_set.setdefault(f, {}) | |
1795 | ndset.setdefault(fnode, clnode) |
|
1797 | ndset.setdefault(fnode, clnode) | |
1796 | return collect_msng_filenodes |
|
1798 | return collect_msng_filenodes | |
1797 |
|
1799 | |||
1798 | # We have a list of filenodes we think we need for a file, lets remove |
|
1800 | # We have a list of filenodes we think we need for a file, lets remove | |
1799 | # all those we know the recipient must have. |
|
1801 | # all those we know the recipient must have. | |
1800 | def prune_filenodes(f, filerevlog): |
|
1802 | def prune_filenodes(f, filerevlog): | |
1801 | msngset = msng_filenode_set[f] |
|
1803 | msngset = msng_filenode_set[f] | |
1802 | hasset = set() |
|
1804 | hasset = set() | |
1803 | # If a 'missing' filenode thinks it belongs to a changenode we |
|
1805 | # If a 'missing' filenode thinks it belongs to a changenode we | |
1804 | # assume the recipient must have, then the recipient must have |
|
1806 | # assume the recipient must have, then the recipient must have | |
1805 | # that filenode. |
|
1807 | # that filenode. | |
1806 | for n in msngset: |
|
1808 | for n in msngset: | |
1807 | clnode = cl.node(filerevlog.linkrev(filerevlog.rev(n))) |
|
1809 | clnode = cl.node(filerevlog.linkrev(filerevlog.rev(n))) | |
1808 | if clnode in has_cl_set: |
|
1810 | if clnode in has_cl_set: | |
1809 | hasset.add(n) |
|
1811 | hasset.add(n) | |
1810 | prune_parents(filerevlog, hasset, msngset) |
|
1812 | prune_parents(filerevlog, hasset, msngset) | |
1811 |
|
1813 | |||
1812 | # A function generator function that sets up the a context for the |
|
1814 | # A function generator function that sets up the a context for the | |
1813 | # inner function. |
|
1815 | # inner function. | |
1814 | def lookup_filenode_link_func(fname): |
|
1816 | def lookup_filenode_link_func(fname): | |
1815 | msngset = msng_filenode_set[fname] |
|
1817 | msngset = msng_filenode_set[fname] | |
1816 | # Lookup the changenode the filenode belongs to. |
|
1818 | # Lookup the changenode the filenode belongs to. | |
1817 | def lookup_filenode_link(fnode): |
|
1819 | def lookup_filenode_link(fnode): | |
1818 | return msngset[fnode] |
|
1820 | return msngset[fnode] | |
1819 | return lookup_filenode_link |
|
1821 | return lookup_filenode_link | |
1820 |
|
1822 | |||
1821 | # Add the nodes that were explicitly requested. |
|
1823 | # Add the nodes that were explicitly requested. | |
1822 | def add_extra_nodes(name, nodes): |
|
1824 | def add_extra_nodes(name, nodes): | |
1823 | if not extranodes or name not in extranodes: |
|
1825 | if not extranodes or name not in extranodes: | |
1824 | return |
|
1826 | return | |
1825 |
|
1827 | |||
1826 | for node, linknode in extranodes[name]: |
|
1828 | for node, linknode in extranodes[name]: | |
1827 | if node not in nodes: |
|
1829 | if node not in nodes: | |
1828 | nodes[node] = linknode |
|
1830 | nodes[node] = linknode | |
1829 |
|
1831 | |||
1830 | # Now that we have all theses utility functions to help out and |
|
1832 | # Now that we have all theses utility functions to help out and | |
1831 | # logically divide up the task, generate the group. |
|
1833 | # logically divide up the task, generate the group. | |
1832 | def gengroup(): |
|
1834 | def gengroup(): | |
1833 | # The set of changed files starts empty. |
|
1835 | # The set of changed files starts empty. | |
1834 | changedfiles = {} |
|
1836 | changedfiles = {} | |
1835 | # Create a changenode group generator that will call our functions |
|
1837 | # Create a changenode group generator that will call our functions | |
1836 | # back to lookup the owning changenode and collect information. |
|
1838 | # back to lookup the owning changenode and collect information. | |
1837 | group = cl.group(msng_cl_lst, identity, |
|
1839 | group = cl.group(msng_cl_lst, identity, | |
1838 | manifest_and_file_collector(changedfiles)) |
|
1840 | manifest_and_file_collector(changedfiles)) | |
1839 | for chnk in group: |
|
1841 | for chnk in group: | |
1840 | yield chnk |
|
1842 | yield chnk | |
1841 |
|
1843 | |||
1842 | # The list of manifests has been collected by the generator |
|
1844 | # The list of manifests has been collected by the generator | |
1843 | # calling our functions back. |
|
1845 | # calling our functions back. | |
1844 | prune_manifests() |
|
1846 | prune_manifests() | |
1845 | add_extra_nodes(1, msng_mnfst_set) |
|
1847 | add_extra_nodes(1, msng_mnfst_set) | |
1846 | msng_mnfst_lst = msng_mnfst_set.keys() |
|
1848 | msng_mnfst_lst = msng_mnfst_set.keys() | |
1847 | # Sort the manifestnodes by revision number. |
|
1849 | # Sort the manifestnodes by revision number. | |
1848 | msng_mnfst_lst.sort(key=mnfst.rev) |
|
1850 | msng_mnfst_lst.sort(key=mnfst.rev) | |
1849 | # Create a generator for the manifestnodes that calls our lookup |
|
1851 | # Create a generator for the manifestnodes that calls our lookup | |
1850 | # and data collection functions back. |
|
1852 | # and data collection functions back. | |
1851 | group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, |
|
1853 | group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, | |
1852 | filenode_collector(changedfiles)) |
|
1854 | filenode_collector(changedfiles)) | |
1853 | for chnk in group: |
|
1855 | for chnk in group: | |
1854 | yield chnk |
|
1856 | yield chnk | |
1855 |
|
1857 | |||
1856 | # These are no longer needed, dereference and toss the memory for |
|
1858 | # These are no longer needed, dereference and toss the memory for | |
1857 | # them. |
|
1859 | # them. | |
1858 | msng_mnfst_lst = None |
|
1860 | msng_mnfst_lst = None | |
1859 | msng_mnfst_set.clear() |
|
1861 | msng_mnfst_set.clear() | |
1860 |
|
1862 | |||
1861 | if extranodes: |
|
1863 | if extranodes: | |
1862 | for fname in extranodes: |
|
1864 | for fname in extranodes: | |
1863 | if isinstance(fname, int): |
|
1865 | if isinstance(fname, int): | |
1864 | continue |
|
1866 | continue | |
1865 | msng_filenode_set.setdefault(fname, {}) |
|
1867 | msng_filenode_set.setdefault(fname, {}) | |
1866 | changedfiles[fname] = 1 |
|
1868 | changedfiles[fname] = 1 | |
1867 | # Go through all our files in order sorted by name. |
|
1869 | # Go through all our files in order sorted by name. | |
1868 | for fname in sorted(changedfiles): |
|
1870 | for fname in sorted(changedfiles): | |
1869 | filerevlog = self.file(fname) |
|
1871 | filerevlog = self.file(fname) | |
1870 | if not len(filerevlog): |
|
1872 | if not len(filerevlog): | |
1871 | raise util.Abort(_("empty or missing revlog for %s") % fname) |
|
1873 | raise util.Abort(_("empty or missing revlog for %s") % fname) | |
1872 | # Toss out the filenodes that the recipient isn't really |
|
1874 | # Toss out the filenodes that the recipient isn't really | |
1873 | # missing. |
|
1875 | # missing. | |
1874 | if fname in msng_filenode_set: |
|
1876 | if fname in msng_filenode_set: | |
1875 | prune_filenodes(fname, filerevlog) |
|
1877 | prune_filenodes(fname, filerevlog) | |
1876 | add_extra_nodes(fname, msng_filenode_set[fname]) |
|
1878 | add_extra_nodes(fname, msng_filenode_set[fname]) | |
1877 | msng_filenode_lst = msng_filenode_set[fname].keys() |
|
1879 | msng_filenode_lst = msng_filenode_set[fname].keys() | |
1878 | else: |
|
1880 | else: | |
1879 | msng_filenode_lst = [] |
|
1881 | msng_filenode_lst = [] | |
1880 | # If any filenodes are left, generate the group for them, |
|
1882 | # If any filenodes are left, generate the group for them, | |
1881 | # otherwise don't bother. |
|
1883 | # otherwise don't bother. | |
1882 | if len(msng_filenode_lst) > 0: |
|
1884 | if len(msng_filenode_lst) > 0: | |
1883 | yield changegroup.chunkheader(len(fname)) |
|
1885 | yield changegroup.chunkheader(len(fname)) | |
1884 | yield fname |
|
1886 | yield fname | |
1885 | # Sort the filenodes by their revision # |
|
1887 | # Sort the filenodes by their revision # | |
1886 | msng_filenode_lst.sort(key=filerevlog.rev) |
|
1888 | msng_filenode_lst.sort(key=filerevlog.rev) | |
1887 | # Create a group generator and only pass in a changenode |
|
1889 | # Create a group generator and only pass in a changenode | |
1888 | # lookup function as we need to collect no information |
|
1890 | # lookup function as we need to collect no information | |
1889 | # from filenodes. |
|
1891 | # from filenodes. | |
1890 | group = filerevlog.group(msng_filenode_lst, |
|
1892 | group = filerevlog.group(msng_filenode_lst, | |
1891 | lookup_filenode_link_func(fname)) |
|
1893 | lookup_filenode_link_func(fname)) | |
1892 | for chnk in group: |
|
1894 | for chnk in group: | |
1893 | yield chnk |
|
1895 | yield chnk | |
1894 | if fname in msng_filenode_set: |
|
1896 | if fname in msng_filenode_set: | |
1895 | # Don't need this anymore, toss it to free memory. |
|
1897 | # Don't need this anymore, toss it to free memory. | |
1896 | del msng_filenode_set[fname] |
|
1898 | del msng_filenode_set[fname] | |
1897 | # Signal that no more groups are left. |
|
1899 | # Signal that no more groups are left. | |
1898 | yield changegroup.closechunk() |
|
1900 | yield changegroup.closechunk() | |
1899 |
|
1901 | |||
1900 | if msng_cl_lst: |
|
1902 | if msng_cl_lst: | |
1901 | self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source) |
|
1903 | self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source) | |
1902 |
|
1904 | |||
1903 | return util.chunkbuffer(gengroup()) |
|
1905 | return util.chunkbuffer(gengroup()) | |
1904 |
|
1906 | |||
1905 | def changegroup(self, basenodes, source): |
|
1907 | def changegroup(self, basenodes, source): | |
1906 | # to avoid a race we use changegroupsubset() (issue1320) |
|
1908 | # to avoid a race we use changegroupsubset() (issue1320) | |
1907 | return self.changegroupsubset(basenodes, self.heads(), source) |
|
1909 | return self.changegroupsubset(basenodes, self.heads(), source) | |
1908 |
|
1910 | |||
1909 | def _changegroup(self, nodes, source): |
|
1911 | def _changegroup(self, nodes, source): | |
1910 | """Compute the changegroup of all nodes that we have that a recipient |
|
1912 | """Compute the changegroup of all nodes that we have that a recipient | |
1911 | doesn't. Return a chunkbuffer object whose read() method will return |
|
1913 | doesn't. Return a chunkbuffer object whose read() method will return | |
1912 | successive changegroup chunks. |
|
1914 | successive changegroup chunks. | |
1913 |
|
1915 | |||
1914 | This is much easier than the previous function as we can assume that |
|
1916 | This is much easier than the previous function as we can assume that | |
1915 | the recipient has any changenode we aren't sending them. |
|
1917 | the recipient has any changenode we aren't sending them. | |
1916 |
|
1918 | |||
1917 | nodes is the set of nodes to send""" |
|
1919 | nodes is the set of nodes to send""" | |
1918 |
|
1920 | |||
1919 | self.hook('preoutgoing', throw=True, source=source) |
|
1921 | self.hook('preoutgoing', throw=True, source=source) | |
1920 |
|
1922 | |||
1921 | cl = self.changelog |
|
1923 | cl = self.changelog | |
1922 | revset = set([cl.rev(n) for n in nodes]) |
|
1924 | revset = set([cl.rev(n) for n in nodes]) | |
1923 | self.changegroupinfo(nodes, source) |
|
1925 | self.changegroupinfo(nodes, source) | |
1924 |
|
1926 | |||
1925 | def identity(x): |
|
1927 | def identity(x): | |
1926 | return x |
|
1928 | return x | |
1927 |
|
1929 | |||
1928 | def gennodelst(log): |
|
1930 | def gennodelst(log): | |
1929 | for r in log: |
|
1931 | for r in log: | |
1930 | if log.linkrev(r) in revset: |
|
1932 | if log.linkrev(r) in revset: | |
1931 | yield log.node(r) |
|
1933 | yield log.node(r) | |
1932 |
|
1934 | |||
1933 | def changed_file_collector(changedfileset): |
|
1935 | def changed_file_collector(changedfileset): | |
1934 | def collect_changed_files(clnode): |
|
1936 | def collect_changed_files(clnode): | |
1935 | c = cl.read(clnode) |
|
1937 | c = cl.read(clnode) | |
1936 | changedfileset.update(c[3]) |
|
1938 | changedfileset.update(c[3]) | |
1937 | return collect_changed_files |
|
1939 | return collect_changed_files | |
1938 |
|
1940 | |||
1939 | def lookuprevlink_func(revlog): |
|
1941 | def lookuprevlink_func(revlog): | |
1940 | def lookuprevlink(n): |
|
1942 | def lookuprevlink(n): | |
1941 | return cl.node(revlog.linkrev(revlog.rev(n))) |
|
1943 | return cl.node(revlog.linkrev(revlog.rev(n))) | |
1942 | return lookuprevlink |
|
1944 | return lookuprevlink | |
1943 |
|
1945 | |||
1944 | def gengroup(): |
|
1946 | def gengroup(): | |
1945 | '''yield a sequence of changegroup chunks (strings)''' |
|
1947 | '''yield a sequence of changegroup chunks (strings)''' | |
1946 | # construct a list of all changed files |
|
1948 | # construct a list of all changed files | |
1947 | changedfiles = set() |
|
1949 | changedfiles = set() | |
1948 |
|
1950 | |||
1949 | for chnk in cl.group(nodes, identity, |
|
1951 | for chnk in cl.group(nodes, identity, | |
1950 | changed_file_collector(changedfiles)): |
|
1952 | changed_file_collector(changedfiles)): | |
1951 | yield chnk |
|
1953 | yield chnk | |
1952 |
|
1954 | |||
1953 | mnfst = self.manifest |
|
1955 | mnfst = self.manifest | |
1954 | nodeiter = gennodelst(mnfst) |
|
1956 | nodeiter = gennodelst(mnfst) | |
1955 | for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)): |
|
1957 | for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)): | |
1956 | yield chnk |
|
1958 | yield chnk | |
1957 |
|
1959 | |||
1958 | for fname in sorted(changedfiles): |
|
1960 | for fname in sorted(changedfiles): | |
1959 | filerevlog = self.file(fname) |
|
1961 | filerevlog = self.file(fname) | |
1960 | if not len(filerevlog): |
|
1962 | if not len(filerevlog): | |
1961 | raise util.Abort(_("empty or missing revlog for %s") % fname) |
|
1963 | raise util.Abort(_("empty or missing revlog for %s") % fname) | |
1962 | nodeiter = gennodelst(filerevlog) |
|
1964 | nodeiter = gennodelst(filerevlog) | |
1963 | nodeiter = list(nodeiter) |
|
1965 | nodeiter = list(nodeiter) | |
1964 | if nodeiter: |
|
1966 | if nodeiter: | |
1965 | yield changegroup.chunkheader(len(fname)) |
|
1967 | yield changegroup.chunkheader(len(fname)) | |
1966 | yield fname |
|
1968 | yield fname | |
1967 | lookup = lookuprevlink_func(filerevlog) |
|
1969 | lookup = lookuprevlink_func(filerevlog) | |
1968 | for chnk in filerevlog.group(nodeiter, lookup): |
|
1970 | for chnk in filerevlog.group(nodeiter, lookup): | |
1969 | yield chnk |
|
1971 | yield chnk | |
1970 |
|
1972 | |||
1971 | yield changegroup.closechunk() |
|
1973 | yield changegroup.closechunk() | |
1972 |
|
1974 | |||
1973 | if nodes: |
|
1975 | if nodes: | |
1974 | self.hook('outgoing', node=hex(nodes[0]), source=source) |
|
1976 | self.hook('outgoing', node=hex(nodes[0]), source=source) | |
1975 |
|
1977 | |||
1976 | return util.chunkbuffer(gengroup()) |
|
1978 | return util.chunkbuffer(gengroup()) | |
1977 |
|
1979 | |||
1978 | def addchangegroup(self, source, srctype, url, emptyok=False): |
|
1980 | def addchangegroup(self, source, srctype, url, emptyok=False): | |
1979 | """add changegroup to repo. |
|
1981 | """add changegroup to repo. | |
1980 |
|
1982 | |||
1981 | return values: |
|
1983 | return values: | |
1982 | - nothing changed or no source: 0 |
|
1984 | - nothing changed or no source: 0 | |
1983 | - more heads than before: 1+added heads (2..n) |
|
1985 | - more heads than before: 1+added heads (2..n) | |
1984 | - less heads than before: -1-removed heads (-2..-n) |
|
1986 | - less heads than before: -1-removed heads (-2..-n) | |
1985 | - number of heads stays the same: 1 |
|
1987 | - number of heads stays the same: 1 | |
1986 | """ |
|
1988 | """ | |
1987 | def csmap(x): |
|
1989 | def csmap(x): | |
1988 | self.ui.debug("add changeset %s\n" % short(x)) |
|
1990 | self.ui.debug("add changeset %s\n" % short(x)) | |
1989 | return len(cl) |
|
1991 | return len(cl) | |
1990 |
|
1992 | |||
1991 | def revmap(x): |
|
1993 | def revmap(x): | |
1992 | return cl.rev(x) |
|
1994 | return cl.rev(x) | |
1993 |
|
1995 | |||
1994 | if not source: |
|
1996 | if not source: | |
1995 | return 0 |
|
1997 | return 0 | |
1996 |
|
1998 | |||
1997 | self.hook('prechangegroup', throw=True, source=srctype, url=url) |
|
1999 | self.hook('prechangegroup', throw=True, source=srctype, url=url) | |
1998 |
|
2000 | |||
1999 | changesets = files = revisions = 0 |
|
2001 | changesets = files = revisions = 0 | |
2000 |
|
2002 | |||
2001 | # write changelog data to temp files so concurrent readers will not see |
|
2003 | # write changelog data to temp files so concurrent readers will not see | |
2002 | # inconsistent view |
|
2004 | # inconsistent view | |
2003 | cl = self.changelog |
|
2005 | cl = self.changelog | |
2004 | cl.delayupdate() |
|
2006 | cl.delayupdate() | |
2005 | oldheads = len(cl.heads()) |
|
2007 | oldheads = len(cl.heads()) | |
2006 |
|
2008 | |||
2007 | tr = self.transaction() |
|
2009 | tr = self.transaction() | |
2008 | try: |
|
2010 | try: | |
2009 | trp = weakref.proxy(tr) |
|
2011 | trp = weakref.proxy(tr) | |
2010 | # pull off the changeset group |
|
2012 | # pull off the changeset group | |
2011 | self.ui.status(_("adding changesets\n")) |
|
2013 | self.ui.status(_("adding changesets\n")) | |
2012 | clstart = len(cl) |
|
2014 | clstart = len(cl) | |
2013 | chunkiter = changegroup.chunkiter(source) |
|
2015 | chunkiter = changegroup.chunkiter(source) | |
2014 | if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok: |
|
2016 | if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok: | |
2015 | raise util.Abort(_("received changelog group is empty")) |
|
2017 | raise util.Abort(_("received changelog group is empty")) | |
2016 | clend = len(cl) |
|
2018 | clend = len(cl) | |
2017 | changesets = clend - clstart |
|
2019 | changesets = clend - clstart | |
2018 |
|
2020 | |||
2019 | # pull off the manifest group |
|
2021 | # pull off the manifest group | |
2020 | self.ui.status(_("adding manifests\n")) |
|
2022 | self.ui.status(_("adding manifests\n")) | |
2021 | chunkiter = changegroup.chunkiter(source) |
|
2023 | chunkiter = changegroup.chunkiter(source) | |
2022 | # no need to check for empty manifest group here: |
|
2024 | # no need to check for empty manifest group here: | |
2023 | # if the result of the merge of 1 and 2 is the same in 3 and 4, |
|
2025 | # if the result of the merge of 1 and 2 is the same in 3 and 4, | |
2024 | # no new manifest will be created and the manifest group will |
|
2026 | # no new manifest will be created and the manifest group will | |
2025 | # be empty during the pull |
|
2027 | # be empty during the pull | |
2026 | self.manifest.addgroup(chunkiter, revmap, trp) |
|
2028 | self.manifest.addgroup(chunkiter, revmap, trp) | |
2027 |
|
2029 | |||
2028 | # process the files |
|
2030 | # process the files | |
2029 | self.ui.status(_("adding file changes\n")) |
|
2031 | self.ui.status(_("adding file changes\n")) | |
2030 | while 1: |
|
2032 | while 1: | |
2031 | f = changegroup.getchunk(source) |
|
2033 | f = changegroup.getchunk(source) | |
2032 | if not f: |
|
2034 | if not f: | |
2033 | break |
|
2035 | break | |
2034 | self.ui.debug("adding %s revisions\n" % f) |
|
2036 | self.ui.debug("adding %s revisions\n" % f) | |
2035 | fl = self.file(f) |
|
2037 | fl = self.file(f) | |
2036 | o = len(fl) |
|
2038 | o = len(fl) | |
2037 | chunkiter = changegroup.chunkiter(source) |
|
2039 | chunkiter = changegroup.chunkiter(source) | |
2038 | if fl.addgroup(chunkiter, revmap, trp) is None: |
|
2040 | if fl.addgroup(chunkiter, revmap, trp) is None: | |
2039 | raise util.Abort(_("received file revlog group is empty")) |
|
2041 | raise util.Abort(_("received file revlog group is empty")) | |
2040 | revisions += len(fl) - o |
|
2042 | revisions += len(fl) - o | |
2041 | files += 1 |
|
2043 | files += 1 | |
2042 |
|
2044 | |||
2043 | newheads = len(cl.heads()) |
|
2045 | newheads = len(cl.heads()) | |
2044 | heads = "" |
|
2046 | heads = "" | |
2045 | if oldheads and newheads != oldheads: |
|
2047 | if oldheads and newheads != oldheads: | |
2046 | heads = _(" (%+d heads)") % (newheads - oldheads) |
|
2048 | heads = _(" (%+d heads)") % (newheads - oldheads) | |
2047 |
|
2049 | |||
2048 | self.ui.status(_("added %d changesets" |
|
2050 | self.ui.status(_("added %d changesets" | |
2049 | " with %d changes to %d files%s\n") |
|
2051 | " with %d changes to %d files%s\n") | |
2050 | % (changesets, revisions, files, heads)) |
|
2052 | % (changesets, revisions, files, heads)) | |
2051 |
|
2053 | |||
2052 | if changesets > 0: |
|
2054 | if changesets > 0: | |
2053 | p = lambda: cl.writepending() and self.root or "" |
|
2055 | p = lambda: cl.writepending() and self.root or "" | |
2054 | self.hook('pretxnchangegroup', throw=True, |
|
2056 | self.hook('pretxnchangegroup', throw=True, | |
2055 | node=hex(cl.node(clstart)), source=srctype, |
|
2057 | node=hex(cl.node(clstart)), source=srctype, | |
2056 | url=url, pending=p) |
|
2058 | url=url, pending=p) | |
2057 |
|
2059 | |||
2058 | # make changelog see real files again |
|
2060 | # make changelog see real files again | |
2059 | cl.finalize(trp) |
|
2061 | cl.finalize(trp) | |
2060 |
|
2062 | |||
2061 | tr.close() |
|
2063 | tr.close() | |
2062 | finally: |
|
2064 | finally: | |
2063 | del tr |
|
2065 | del tr | |
2064 |
|
2066 | |||
2065 | if changesets > 0: |
|
2067 | if changesets > 0: | |
2066 | # forcefully update the on-disk branch cache |
|
2068 | # forcefully update the on-disk branch cache | |
2067 | self.ui.debug("updating the branch cache\n") |
|
2069 | self.ui.debug("updating the branch cache\n") | |
2068 | self.branchtags() |
|
2070 | self.branchtags() | |
2069 | self.hook("changegroup", node=hex(cl.node(clstart)), |
|
2071 | self.hook("changegroup", node=hex(cl.node(clstart)), | |
2070 | source=srctype, url=url) |
|
2072 | source=srctype, url=url) | |
2071 |
|
2073 | |||
2072 | for i in xrange(clstart, clend): |
|
2074 | for i in xrange(clstart, clend): | |
2073 | self.hook("incoming", node=hex(cl.node(i)), |
|
2075 | self.hook("incoming", node=hex(cl.node(i)), | |
2074 | source=srctype, url=url) |
|
2076 | source=srctype, url=url) | |
2075 |
|
2077 | |||
2076 | # never return 0 here: |
|
2078 | # never return 0 here: | |
2077 | if newheads < oldheads: |
|
2079 | if newheads < oldheads: | |
2078 | return newheads - oldheads - 1 |
|
2080 | return newheads - oldheads - 1 | |
2079 | else: |
|
2081 | else: | |
2080 | return newheads - oldheads + 1 |
|
2082 | return newheads - oldheads + 1 | |
2081 |
|
2083 | |||
2082 |
|
2084 | |||
2083 | def stream_in(self, remote): |
|
2085 | def stream_in(self, remote): | |
2084 | fp = remote.stream_out() |
|
2086 | fp = remote.stream_out() | |
2085 | l = fp.readline() |
|
2087 | l = fp.readline() | |
2086 | try: |
|
2088 | try: | |
2087 | resp = int(l) |
|
2089 | resp = int(l) | |
2088 | except ValueError: |
|
2090 | except ValueError: | |
2089 | raise error.ResponseError( |
|
2091 | raise error.ResponseError( | |
2090 | _('Unexpected response from remote server:'), l) |
|
2092 | _('Unexpected response from remote server:'), l) | |
2091 | if resp == 1: |
|
2093 | if resp == 1: | |
2092 | raise util.Abort(_('operation forbidden by server')) |
|
2094 | raise util.Abort(_('operation forbidden by server')) | |
2093 | elif resp == 2: |
|
2095 | elif resp == 2: | |
2094 | raise util.Abort(_('locking the remote repository failed')) |
|
2096 | raise util.Abort(_('locking the remote repository failed')) | |
2095 | elif resp != 0: |
|
2097 | elif resp != 0: | |
2096 | raise util.Abort(_('the server sent an unknown error code')) |
|
2098 | raise util.Abort(_('the server sent an unknown error code')) | |
2097 | self.ui.status(_('streaming all changes\n')) |
|
2099 | self.ui.status(_('streaming all changes\n')) | |
2098 | l = fp.readline() |
|
2100 | l = fp.readline() | |
2099 | try: |
|
2101 | try: | |
2100 | total_files, total_bytes = map(int, l.split(' ', 1)) |
|
2102 | total_files, total_bytes = map(int, l.split(' ', 1)) | |
2101 | except (ValueError, TypeError): |
|
2103 | except (ValueError, TypeError): | |
2102 | raise error.ResponseError( |
|
2104 | raise error.ResponseError( | |
2103 | _('Unexpected response from remote server:'), l) |
|
2105 | _('Unexpected response from remote server:'), l) | |
2104 | self.ui.status(_('%d files to transfer, %s of data\n') % |
|
2106 | self.ui.status(_('%d files to transfer, %s of data\n') % | |
2105 | (total_files, util.bytecount(total_bytes))) |
|
2107 | (total_files, util.bytecount(total_bytes))) | |
2106 | start = time.time() |
|
2108 | start = time.time() | |
2107 | for i in xrange(total_files): |
|
2109 | for i in xrange(total_files): | |
2108 | # XXX doesn't support '\n' or '\r' in filenames |
|
2110 | # XXX doesn't support '\n' or '\r' in filenames | |
2109 | l = fp.readline() |
|
2111 | l = fp.readline() | |
2110 | try: |
|
2112 | try: | |
2111 | name, size = l.split('\0', 1) |
|
2113 | name, size = l.split('\0', 1) | |
2112 | size = int(size) |
|
2114 | size = int(size) | |
2113 | except (ValueError, TypeError): |
|
2115 | except (ValueError, TypeError): | |
2114 | raise error.ResponseError( |
|
2116 | raise error.ResponseError( | |
2115 | _('Unexpected response from remote server:'), l) |
|
2117 | _('Unexpected response from remote server:'), l) | |
2116 | self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) |
|
2118 | self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) | |
2117 | # for backwards compat, name was partially encoded |
|
2119 | # for backwards compat, name was partially encoded | |
2118 | ofp = self.sopener(store.decodedir(name), 'w') |
|
2120 | ofp = self.sopener(store.decodedir(name), 'w') | |
2119 | for chunk in util.filechunkiter(fp, limit=size): |
|
2121 | for chunk in util.filechunkiter(fp, limit=size): | |
2120 | ofp.write(chunk) |
|
2122 | ofp.write(chunk) | |
2121 | ofp.close() |
|
2123 | ofp.close() | |
2122 | elapsed = time.time() - start |
|
2124 | elapsed = time.time() - start | |
2123 | if elapsed <= 0: |
|
2125 | if elapsed <= 0: | |
2124 | elapsed = 0.001 |
|
2126 | elapsed = 0.001 | |
2125 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % |
|
2127 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % | |
2126 | (util.bytecount(total_bytes), elapsed, |
|
2128 | (util.bytecount(total_bytes), elapsed, | |
2127 | util.bytecount(total_bytes / elapsed))) |
|
2129 | util.bytecount(total_bytes / elapsed))) | |
2128 | self.invalidate() |
|
2130 | self.invalidate() | |
2129 | return len(self.heads()) + 1 |
|
2131 | return len(self.heads()) + 1 | |
2130 |
|
2132 | |||
2131 | def clone(self, remote, heads=[], stream=False): |
|
2133 | def clone(self, remote, heads=[], stream=False): | |
2132 | '''clone remote repository. |
|
2134 | '''clone remote repository. | |
2133 |
|
2135 | |||
2134 | keyword arguments: |
|
2136 | keyword arguments: | |
2135 | heads: list of revs to clone (forces use of pull) |
|
2137 | heads: list of revs to clone (forces use of pull) | |
2136 | stream: use streaming clone if possible''' |
|
2138 | stream: use streaming clone if possible''' | |
2137 |
|
2139 | |||
2138 | # now, all clients that can request uncompressed clones can |
|
2140 | # now, all clients that can request uncompressed clones can | |
2139 | # read repo formats supported by all servers that can serve |
|
2141 | # read repo formats supported by all servers that can serve | |
2140 | # them. |
|
2142 | # them. | |
2141 |
|
2143 | |||
2142 | # if revlog format changes, client will have to check version |
|
2144 | # if revlog format changes, client will have to check version | |
2143 | # and format flags on "stream" capability, and use |
|
2145 | # and format flags on "stream" capability, and use | |
2144 | # uncompressed only if compatible. |
|
2146 | # uncompressed only if compatible. | |
2145 |
|
2147 | |||
2146 | if stream and not heads and remote.capable('stream'): |
|
2148 | if stream and not heads and remote.capable('stream'): | |
2147 | return self.stream_in(remote) |
|
2149 | return self.stream_in(remote) | |
2148 | return self.pull(remote, heads) |
|
2150 | return self.pull(remote, heads) | |
2149 |
|
2151 | |||
2150 | # used to avoid circular references so destructors work |
|
2152 | # used to avoid circular references so destructors work | |
2151 | def aftertrans(files): |
|
2153 | def aftertrans(files): | |
2152 | renamefiles = [tuple(t) for t in files] |
|
2154 | renamefiles = [tuple(t) for t in files] | |
2153 | def a(): |
|
2155 | def a(): | |
2154 | for src, dest in renamefiles: |
|
2156 | for src, dest in renamefiles: | |
2155 | util.rename(src, dest) |
|
2157 | util.rename(src, dest) | |
2156 | return a |
|
2158 | return a | |
2157 |
|
2159 | |||
2158 | def instance(ui, path, create): |
|
2160 | def instance(ui, path, create): | |
2159 | return localrepository(ui, util.drop_scheme('file', path), create) |
|
2161 | return localrepository(ui, util.drop_scheme('file', path), create) | |
2160 |
|
2162 | |||
2161 | def islocal(path): |
|
2163 | def islocal(path): | |
2162 | return True |
|
2164 | return True |
General Comments 0
You need to be logged in to leave comments.
Login now