##// END OF EJS Templates
strip trailing whitespace, replace tabs by spaces
Dirkjan Ochtman -
r6923:ebf1462f default
parent child Browse files
Show More
@@ -1,196 +1,196 b''
1 # convert.py Foreign SCM converter
1 # convert.py Foreign SCM converter
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
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7 '''converting foreign VCS repositories to Mercurial'''
7 '''converting foreign VCS repositories to Mercurial'''
8
8
9 import convcmd
9 import convcmd
10 from mercurial import commands
10 from mercurial import commands
11
11
12 # Commands definition was moved elsewhere to ease demandload job.
12 # Commands definition was moved elsewhere to ease demandload job.
13
13
14 def convert(ui, src, dest=None, revmapfile=None, **opts):
14 def convert(ui, src, dest=None, revmapfile=None, **opts):
15 """Convert a foreign SCM repository to a Mercurial one.
15 """Convert a foreign SCM repository to a Mercurial one.
16
16
17 Accepted source formats:
17 Accepted source formats:
18 - Mercurial
18 - Mercurial
19 - CVS
19 - CVS
20 - Darcs
20 - Darcs
21 - git
21 - git
22 - Subversion
22 - Subversion
23 - Monotone
23 - Monotone
24 - GNU Arch
24 - GNU Arch
25
25
26 Accepted destination formats:
26 Accepted destination formats:
27 - Mercurial
27 - Mercurial
28 - Subversion (history on branches is not preserved)
28 - Subversion (history on branches is not preserved)
29
29
30 If no revision is given, all revisions will be converted. Otherwise,
30 If no revision is given, all revisions will be converted. Otherwise,
31 convert will only import up to the named revision (given in a format
31 convert will only import up to the named revision (given in a format
32 understood by the source).
32 understood by the source).
33
33
34 If no destination directory name is specified, it defaults to the
34 If no destination directory name is specified, it defaults to the
35 basename of the source with '-hg' appended. If the destination
35 basename of the source with '-hg' appended. If the destination
36 repository doesn't exist, it will be created.
36 repository doesn't exist, it will be created.
37
37
38 If <REVMAP> isn't given, it will be put in a default location
38 If <REVMAP> isn't given, it will be put in a default location
39 (<dest>/.hg/shamap by default). The <REVMAP> is a simple text
39 (<dest>/.hg/shamap by default). The <REVMAP> is a simple text
40 file that maps each source commit ID to the destination ID for
40 file that maps each source commit ID to the destination ID for
41 that revision, like so:
41 that revision, like so:
42 <source ID> <destination ID>
42 <source ID> <destination ID>
43
43
44 If the file doesn't exist, it's automatically created. It's updated
44 If the file doesn't exist, it's automatically created. It's updated
45 on each commit copied, so convert-repo can be interrupted and can
45 on each commit copied, so convert-repo can be interrupted and can
46 be run repeatedly to copy new commits.
46 be run repeatedly to copy new commits.
47
47
48 The [username mapping] file is a simple text file that maps each source
48 The [username mapping] file is a simple text file that maps each source
49 commit author to a destination commit author. It is handy for source SCMs
49 commit author to a destination commit author. It is handy for source SCMs
50 that use unix logins to identify authors (eg: CVS). One line per author
50 that use unix logins to identify authors (eg: CVS). One line per author
51 mapping and the line format is:
51 mapping and the line format is:
52 srcauthor=whatever string you want
52 srcauthor=whatever string you want
53
53
54 The filemap is a file that allows filtering and remapping of files
54 The filemap is a file that allows filtering and remapping of files
55 and directories. Comment lines start with '#'. Each line can
55 and directories. Comment lines start with '#'. Each line can
56 contain one of the following directives:
56 contain one of the following directives:
57
57
58 include path/to/file
58 include path/to/file
59
59
60 exclude path/to/file
60 exclude path/to/file
61
61
62 rename from/file to/file
62 rename from/file to/file
63
63
64 The 'include' directive causes a file, or all files under a
64 The 'include' directive causes a file, or all files under a
65 directory, to be included in the destination repository, and the
65 directory, to be included in the destination repository, and the
66 exclusion of all other files and dirs not explicitely included.
66 exclusion of all other files and dirs not explicitely included.
67 The 'exclude' directive causes files or directories to be omitted.
67 The 'exclude' directive causes files or directories to be omitted.
68 The 'rename' directive renames a file or directory. To rename from a
68 The 'rename' directive renames a file or directory. To rename from a
69 subdirectory into the root of the repository, use '.' as the path to
69 subdirectory into the root of the repository, use '.' as the path to
70 rename to.
70 rename to.
71
71
72 The splicemap is a file that allows insertion of synthetic
72 The splicemap is a file that allows insertion of synthetic
73 history, letting you specify the parents of a revision. This is
73 history, letting you specify the parents of a revision. This is
74 useful if you want to e.g. give a Subversion merge two parents, or
74 useful if you want to e.g. give a Subversion merge two parents, or
75 graft two disconnected series of history together. Each entry
75 graft two disconnected series of history together. Each entry
76 contains a key, followed by a space, followed by one or two
76 contains a key, followed by a space, followed by one or two
77 values, separated by spaces. The key is the revision ID in the
77 values, separated by spaces. The key is the revision ID in the
78 source revision control system whose parents should be modified
78 source revision control system whose parents should be modified
79 (same format as a key in .hg/shamap). The values are the revision
79 (same format as a key in .hg/shamap). The values are the revision
80 IDs (in either the source or destination revision control system)
80 IDs (in either the source or destination revision control system)
81 that should be used as the new parents for that node.
81 that should be used as the new parents for that node.
82
82
83 Mercurial Source
83 Mercurial Source
84 -----------------
84 -----------------
85
85
86 --config convert.hg.saverev=True (boolean)
86 --config convert.hg.saverev=True (boolean)
87 allow target to preserve source revision ID
87 allow target to preserve source revision ID
88 --config convert.hg.startrev=0 (hg revision identifier)
88 --config convert.hg.startrev=0 (hg revision identifier)
89 convert start revision and its descendants
89 convert start revision and its descendants
90
90
91 CVS Source
91 CVS Source
92 ----------
92 ----------
93
93
94 CVS source will use a sandbox (i.e. a checked-out copy) from CVS
94 CVS source will use a sandbox (i.e. a checked-out copy) from CVS
95 to indicate the starting point of what will be converted. Direct
95 to indicate the starting point of what will be converted. Direct
96 access to the repository files is not needed, unless of course
96 access to the repository files is not needed, unless of course
97 the repository is :local:. The conversion uses the top level
97 the repository is :local:. The conversion uses the top level
98 directory in the sandbox to find the CVS repository, and then uses
98 directory in the sandbox to find the CVS repository, and then uses
99 CVS rlog commands to find files to convert. This means that unless
99 CVS rlog commands to find files to convert. This means that unless
100 a filemap is given, all files under the starting directory will be
100 a filemap is given, all files under the starting directory will be
101 converted, and that any directory reorganisation in the CVS
101 converted, and that any directory reorganisation in the CVS
102 sandbox is ignored.
102 sandbox is ignored.
103
103
104 Because CVS does not have changesets, it is necessary to collect
104 Because CVS does not have changesets, it is necessary to collect
105 individual commits to CVS and merge them into changesets. CVS source
105 individual commits to CVS and merge them into changesets. CVS source
106 can use the external 'cvsps' program (this is a legacy option and may
106 can use the external 'cvsps' program (this is a legacy option and may
107 be removed in future) or use its internal changeset merging code.
107 be removed in future) or use its internal changeset merging code.
108 External cvsps is default, and options may be passed to it by setting
108 External cvsps is default, and options may be passed to it by setting
109 --config convert.cvsps='cvsps -A -u --cvs-direct -q'
109 --config convert.cvsps='cvsps -A -u --cvs-direct -q'
110 The options shown are the defaults.
110 The options shown are the defaults.
111
111
112 Internal cvsps is selected by setting
112 Internal cvsps is selected by setting
113 --config convert.cvsps=builtin
113 --config convert.cvsps=builtin
114 and has a few more configurable options:
114 and has a few more configurable options:
115 --config convert.cvsps.fuzz=60 (integer)
115 --config convert.cvsps.fuzz=60 (integer)
116 Specify the maximum time (in seconds) that is allowed between
116 Specify the maximum time (in seconds) that is allowed between
117 commits with identical user and log message in a single
117 commits with identical user and log message in a single
118 changeset. When very large files were checked in as part
118 changeset. When very large files were checked in as part
119 of a changeset then the default may not be long enough.
119 of a changeset then the default may not be long enough.
120 --config convert.cvsps.mergeto='{{mergetobranch ([-\w]+)}}'
120 --config convert.cvsps.mergeto='{{mergetobranch ([-\w]+)}}'
121 Specify a regular expression to which commit log messages are
121 Specify a regular expression to which commit log messages are
122 matched. If a match occurs, then the conversion process will
122 matched. If a match occurs, then the conversion process will
123 insert a dummy revision merging the branch on which this log
123 insert a dummy revision merging the branch on which this log
124 message occurs to the branch indicated in the regex.
124 message occurs to the branch indicated in the regex.
125 --config convert.cvsps.mergefrom='{{mergefrombranch ([-\w]+)}}'
125 --config convert.cvsps.mergefrom='{{mergefrombranch ([-\w]+)}}'
126 Specify a regular expression to which commit log messages are
126 Specify a regular expression to which commit log messages are
127 matched. If a match occurs, then the conversion process will
127 matched. If a match occurs, then the conversion process will
128 add the most recent revision on the branch indicated in the
128 add the most recent revision on the branch indicated in the
129 regex as the second parent of the changeset.
129 regex as the second parent of the changeset.
130
130
131 The hgext/convert/cvsps wrapper script allows the builtin changeset
131 The hgext/convert/cvsps wrapper script allows the builtin changeset
132 merging code to be run without doing a conversion. Its parameters and
132 merging code to be run without doing a conversion. Its parameters and
133 output are similar to that of cvsps 2.1.
133 output are similar to that of cvsps 2.1.
134
134
135 Subversion Source
135 Subversion Source
136 -----------------
136 -----------------
137
137
138 Subversion source detects classical trunk/branches/tags layouts.
138 Subversion source detects classical trunk/branches/tags layouts.
139 By default, the supplied "svn://repo/path/" source URL is
139 By default, the supplied "svn://repo/path/" source URL is
140 converted as a single branch. If "svn://repo/path/trunk" exists
140 converted as a single branch. If "svn://repo/path/trunk" exists
141 it replaces the default branch. If "svn://repo/path/branches"
141 it replaces the default branch. If "svn://repo/path/branches"
142 exists, its subdirectories are listed as possible branches. If
142 exists, its subdirectories are listed as possible branches. If
143 "svn://repo/path/tags" exists, it is looked for tags referencing
143 "svn://repo/path/tags" exists, it is looked for tags referencing
144 converted branches. Default "trunk", "branches" and "tags" values
144 converted branches. Default "trunk", "branches" and "tags" values
145 can be overriden with following options. Set them to paths
145 can be overriden with following options. Set them to paths
146 relative to the source URL, or leave them blank to disable
146 relative to the source URL, or leave them blank to disable
147 autodetection.
147 autodetection.
148
148
149 --config convert.svn.branches=branches (directory name)
149 --config convert.svn.branches=branches (directory name)
150 specify the directory containing branches
150 specify the directory containing branches
151 --config convert.svn.tags=tags (directory name)
151 --config convert.svn.tags=tags (directory name)
152 specify the directory containing tags
152 specify the directory containing tags
153 --config convert.svn.trunk=trunk (directory name)
153 --config convert.svn.trunk=trunk (directory name)
154 specify the name of the trunk branch
154 specify the name of the trunk branch
155
155
156 Source history can be retrieved starting at a specific revision,
156 Source history can be retrieved starting at a specific revision,
157 instead of being integrally converted. Only single branch
157 instead of being integrally converted. Only single branch
158 conversions are supported.
158 conversions are supported.
159
159
160 --config convert.svn.startrev=0 (svn revision number)
160 --config convert.svn.startrev=0 (svn revision number)
161 specify start Subversion revision.
161 specify start Subversion revision.
162
162
163 Mercurial Destination
163 Mercurial Destination
164 ---------------------
164 ---------------------
165
165
166 --config convert.hg.clonebranches=False (boolean)
166 --config convert.hg.clonebranches=False (boolean)
167 dispatch source branches in separate clones.
167 dispatch source branches in separate clones.
168 --config convert.hg.tagsbranch=default (branch name)
168 --config convert.hg.tagsbranch=default (branch name)
169 tag revisions branch name
169 tag revisions branch name
170 --config convert.hg.usebranchnames=True (boolean)
170 --config convert.hg.usebranchnames=True (boolean)
171 preserve branch names
171 preserve branch names
172
172
173 """
173 """
174 return convcmd.convert(ui, src, dest, revmapfile, **opts)
174 return convcmd.convert(ui, src, dest, revmapfile, **opts)
175
175
176 def debugsvnlog(ui, **opts):
176 def debugsvnlog(ui, **opts):
177 return convcmd.debugsvnlog(ui, **opts)
177 return convcmd.debugsvnlog(ui, **opts)
178
178
179 commands.norepo += " convert debugsvnlog"
179 commands.norepo += " convert debugsvnlog"
180
180
181 cmdtable = {
181 cmdtable = {
182 "convert":
182 "convert":
183 (convert,
183 (convert,
184 [('A', 'authors', '', 'username mapping filename'),
184 [('A', 'authors', '', 'username mapping filename'),
185 ('d', 'dest-type', '', 'destination repository type'),
185 ('d', 'dest-type', '', 'destination repository type'),
186 ('', 'filemap', '', 'remap file names using contents of file'),
186 ('', 'filemap', '', 'remap file names using contents of file'),
187 ('r', 'rev', '', 'import up to target revision REV'),
187 ('r', 'rev', '', 'import up to target revision REV'),
188 ('s', 'source-type', '', 'source repository type'),
188 ('s', 'source-type', '', 'source repository type'),
189 ('', 'splicemap', '', 'splice synthesized history into place'),
189 ('', 'splicemap', '', 'splice synthesized history into place'),
190 ('', 'datesort', None, 'try to sort changesets by date')],
190 ('', 'datesort', None, 'try to sort changesets by date')],
191 'hg convert [OPTION]... SOURCE [DEST [REVMAP]]'),
191 'hg convert [OPTION]... SOURCE [DEST [REVMAP]]'),
192 "debugsvnlog":
192 "debugsvnlog":
193 (debugsvnlog,
193 (debugsvnlog,
194 [],
194 [],
195 'hg debugsvnlog'),
195 'hg debugsvnlog'),
196 }
196 }
@@ -1,317 +1,317 b''
1 # hg backend for convert extension
1 # hg backend for convert extension
2
2
3 # Notes for hg->hg conversion:
3 # Notes for hg->hg conversion:
4 #
4 #
5 # * Old versions of Mercurial didn't trim the whitespace from the ends
5 # * Old versions of Mercurial didn't trim the whitespace from the ends
6 # of commit messages, but new versions do. Changesets created by
6 # of commit messages, but new versions do. Changesets created by
7 # those older versions, then converted, may thus have different
7 # those older versions, then converted, may thus have different
8 # hashes for changesets that are otherwise identical.
8 # hashes for changesets that are otherwise identical.
9 #
9 #
10 # * By default, the source revision is stored in the converted
10 # * By default, the source revision is stored in the converted
11 # revision. This will cause the converted revision to have a
11 # revision. This will cause the converted revision to have a
12 # different identity than the source. To avoid this, use the
12 # different identity than the source. To avoid this, use the
13 # following option: "--config convert.hg.saverev=false"
13 # following option: "--config convert.hg.saverev=false"
14
14
15
15
16 import os, time
16 import os, time
17 from mercurial.i18n import _
17 from mercurial.i18n import _
18 from mercurial.repo import RepoError
18 from mercurial.repo import RepoError
19 from mercurial.node import bin, hex, nullid
19 from mercurial.node import bin, hex, nullid
20 from mercurial import hg, revlog, util, context
20 from mercurial import hg, revlog, util, context
21
21
22 from common import NoRepo, commit, converter_source, converter_sink
22 from common import NoRepo, commit, converter_source, converter_sink
23
23
24 class mercurial_sink(converter_sink):
24 class mercurial_sink(converter_sink):
25 def __init__(self, ui, path):
25 def __init__(self, ui, path):
26 converter_sink.__init__(self, ui, path)
26 converter_sink.__init__(self, ui, path)
27 self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
27 self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
28 self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
28 self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
29 self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default')
29 self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default')
30 self.lastbranch = None
30 self.lastbranch = None
31 if os.path.isdir(path) and len(os.listdir(path)) > 0:
31 if os.path.isdir(path) and len(os.listdir(path)) > 0:
32 try:
32 try:
33 self.repo = hg.repository(self.ui, path)
33 self.repo = hg.repository(self.ui, path)
34 if not self.repo.local():
34 if not self.repo.local():
35 raise NoRepo(_('%s is not a local Mercurial repo') % path)
35 raise NoRepo(_('%s is not a local Mercurial repo') % path)
36 except RepoError, err:
36 except RepoError, err:
37 ui.print_exc()
37 ui.print_exc()
38 raise NoRepo(err.args[0])
38 raise NoRepo(err.args[0])
39 else:
39 else:
40 try:
40 try:
41 ui.status(_('initializing destination %s repository\n') % path)
41 ui.status(_('initializing destination %s repository\n') % path)
42 self.repo = hg.repository(self.ui, path, create=True)
42 self.repo = hg.repository(self.ui, path, create=True)
43 if not self.repo.local():
43 if not self.repo.local():
44 raise NoRepo(_('%s is not a local Mercurial repo') % path)
44 raise NoRepo(_('%s is not a local Mercurial repo') % path)
45 self.created.append(path)
45 self.created.append(path)
46 except RepoError, err:
46 except RepoError, err:
47 ui.print_exc()
47 ui.print_exc()
48 raise NoRepo("could not create hg repo %s as sink" % path)
48 raise NoRepo("could not create hg repo %s as sink" % path)
49 self.lock = None
49 self.lock = None
50 self.wlock = None
50 self.wlock = None
51 self.filemapmode = False
51 self.filemapmode = False
52
52
53 def before(self):
53 def before(self):
54 self.ui.debug(_('run hg sink pre-conversion action\n'))
54 self.ui.debug(_('run hg sink pre-conversion action\n'))
55 self.wlock = self.repo.wlock()
55 self.wlock = self.repo.wlock()
56 self.lock = self.repo.lock()
56 self.lock = self.repo.lock()
57
57
58 def after(self):
58 def after(self):
59 self.ui.debug(_('run hg sink post-conversion action\n'))
59 self.ui.debug(_('run hg sink post-conversion action\n'))
60 self.lock = None
60 self.lock = None
61 self.wlock = None
61 self.wlock = None
62
62
63 def revmapfile(self):
63 def revmapfile(self):
64 return os.path.join(self.path, ".hg", "shamap")
64 return os.path.join(self.path, ".hg", "shamap")
65
65
66 def authorfile(self):
66 def authorfile(self):
67 return os.path.join(self.path, ".hg", "authormap")
67 return os.path.join(self.path, ".hg", "authormap")
68
68
69 def getheads(self):
69 def getheads(self):
70 h = self.repo.changelog.heads()
70 h = self.repo.changelog.heads()
71 return [ hex(x) for x in h ]
71 return [ hex(x) for x in h ]
72
72
73 def setbranch(self, branch, pbranches):
73 def setbranch(self, branch, pbranches):
74 if not self.clonebranches:
74 if not self.clonebranches:
75 return
75 return
76
76
77 setbranch = (branch != self.lastbranch)
77 setbranch = (branch != self.lastbranch)
78 self.lastbranch = branch
78 self.lastbranch = branch
79 if not branch:
79 if not branch:
80 branch = 'default'
80 branch = 'default'
81 pbranches = [(b[0], b[1] and b[1] or 'default') for b in pbranches]
81 pbranches = [(b[0], b[1] and b[1] or 'default') for b in pbranches]
82 pbranch = pbranches and pbranches[0][1] or 'default'
82 pbranch = pbranches and pbranches[0][1] or 'default'
83
83
84 branchpath = os.path.join(self.path, branch)
84 branchpath = os.path.join(self.path, branch)
85 if setbranch:
85 if setbranch:
86 self.after()
86 self.after()
87 try:
87 try:
88 self.repo = hg.repository(self.ui, branchpath)
88 self.repo = hg.repository(self.ui, branchpath)
89 except:
89 except:
90 self.repo = hg.repository(self.ui, branchpath, create=True)
90 self.repo = hg.repository(self.ui, branchpath, create=True)
91 self.before()
91 self.before()
92
92
93 # pbranches may bring revisions from other branches (merge parents)
93 # pbranches may bring revisions from other branches (merge parents)
94 # Make sure we have them, or pull them.
94 # Make sure we have them, or pull them.
95 missings = {}
95 missings = {}
96 for b in pbranches:
96 for b in pbranches:
97 try:
97 try:
98 self.repo.lookup(b[0])
98 self.repo.lookup(b[0])
99 except:
99 except:
100 missings.setdefault(b[1], []).append(b[0])
100 missings.setdefault(b[1], []).append(b[0])
101
101
102 if missings:
102 if missings:
103 self.after()
103 self.after()
104 for pbranch, heads in missings.iteritems():
104 for pbranch, heads in missings.iteritems():
105 pbranchpath = os.path.join(self.path, pbranch)
105 pbranchpath = os.path.join(self.path, pbranch)
106 prepo = hg.repository(self.ui, pbranchpath)
106 prepo = hg.repository(self.ui, pbranchpath)
107 self.ui.note(_('pulling from %s into %s\n') % (pbranch, branch))
107 self.ui.note(_('pulling from %s into %s\n') % (pbranch, branch))
108 self.repo.pull(prepo, [prepo.lookup(h) for h in heads])
108 self.repo.pull(prepo, [prepo.lookup(h) for h in heads])
109 self.before()
109 self.before()
110
110
111 def putcommit(self, files, copies, parents, commit, source):
111 def putcommit(self, files, copies, parents, commit, source):
112
112
113 files = dict(files)
113 files = dict(files)
114 def getfilectx(repo, memctx, f):
114 def getfilectx(repo, memctx, f):
115 v = files[f]
115 v = files[f]
116 data = source.getfile(f, v)
116 data = source.getfile(f, v)
117 e = source.getmode(f, v)
117 e = source.getmode(f, v)
118 return context.memfilectx(f, data, 'l' in e, 'x' in e, copies.get(f))
118 return context.memfilectx(f, data, 'l' in e, 'x' in e, copies.get(f))
119
119
120 pl = []
120 pl = []
121 for p in parents:
121 for p in parents:
122 if p not in pl:
122 if p not in pl:
123 pl.append(p)
123 pl.append(p)
124 parents = pl
124 parents = pl
125 nparents = len(parents)
125 nparents = len(parents)
126 if self.filemapmode and nparents == 1:
126 if self.filemapmode and nparents == 1:
127 m1node = self.repo.changelog.read(bin(parents[0]))[0]
127 m1node = self.repo.changelog.read(bin(parents[0]))[0]
128 parent = parents[0]
128 parent = parents[0]
129
129
130 if len(parents) < 2: parents.append("0" * 40)
130 if len(parents) < 2: parents.append("0" * 40)
131 if len(parents) < 2: parents.append("0" * 40)
131 if len(parents) < 2: parents.append("0" * 40)
132 p2 = parents.pop(0)
132 p2 = parents.pop(0)
133
133
134 text = commit.desc
134 text = commit.desc
135 extra = commit.extra.copy()
135 extra = commit.extra.copy()
136 if self.branchnames and commit.branch:
136 if self.branchnames and commit.branch:
137 extra['branch'] = commit.branch
137 extra['branch'] = commit.branch
138 if commit.rev:
138 if commit.rev:
139 extra['convert_revision'] = commit.rev
139 extra['convert_revision'] = commit.rev
140
140
141 while parents:
141 while parents:
142 p1 = p2
142 p1 = p2
143 p2 = parents.pop(0)
143 p2 = parents.pop(0)
144 ctx = context.memctx(self.repo, (p1, p2), text, files.keys(), getfilectx,
144 ctx = context.memctx(self.repo, (p1, p2), text, files.keys(), getfilectx,
145 commit.author, commit.date, extra)
145 commit.author, commit.date, extra)
146 a = self.repo.commitctx(ctx)
146 a = self.repo.commitctx(ctx)
147 text = "(octopus merge fixup)\n"
147 text = "(octopus merge fixup)\n"
148 p2 = hex(self.repo.changelog.tip())
148 p2 = hex(self.repo.changelog.tip())
149
149
150 if self.filemapmode and nparents == 1:
150 if self.filemapmode and nparents == 1:
151 man = self.repo.manifest
151 man = self.repo.manifest
152 mnode = self.repo.changelog.read(bin(p2))[0]
152 mnode = self.repo.changelog.read(bin(p2))[0]
153 if not man.cmp(m1node, man.revision(mnode)):
153 if not man.cmp(m1node, man.revision(mnode)):
154 self.repo.rollback()
154 self.repo.rollback()
155 return parent
155 return parent
156 return p2
156 return p2
157
157
158 def puttags(self, tags):
158 def puttags(self, tags):
159 try:
159 try:
160 parentctx = self.repo[self.tagsbranch]
160 parentctx = self.repo[self.tagsbranch]
161 tagparent = parentctx.node()
161 tagparent = parentctx.node()
162 except RepoError, inst:
162 except RepoError, inst:
163 parentctx = None
163 parentctx = None
164 tagparent = nullid
164 tagparent = nullid
165
165
166 try:
166 try:
167 oldlines = util.sort(parentctx['.hgtags'].data().splitlines(1))
167 oldlines = util.sort(parentctx['.hgtags'].data().splitlines(1))
168 except:
168 except:
169 oldlines = []
169 oldlines = []
170
170
171 newlines = util.sort([("%s %s\n" % (tags[tag], tag)) for tag in tags])
171 newlines = util.sort([("%s %s\n" % (tags[tag], tag)) for tag in tags])
172
172
173 if newlines == oldlines:
173 if newlines == oldlines:
174 return None
174 return None
175 data = "".join(newlines)
175 data = "".join(newlines)
176
176
177 def getfilectx(repo, memctx, f):
177 def getfilectx(repo, memctx, f):
178 return context.memfilectx(f, data, False, False, None)
178 return context.memfilectx(f, data, False, False, None)
179
179
180 self.ui.status("updating tags\n")
180 self.ui.status("updating tags\n")
181 date = "%s 0" % int(time.mktime(time.gmtime()))
181 date = "%s 0" % int(time.mktime(time.gmtime()))
182 extra = {'branch': self.tagsbranch}
182 extra = {'branch': self.tagsbranch}
183 ctx = context.memctx(self.repo, (tagparent, None), "update tags",
183 ctx = context.memctx(self.repo, (tagparent, None), "update tags",
184 [".hgtags"], getfilectx, "convert-repo", date,
184 [".hgtags"], getfilectx, "convert-repo", date,
185 extra)
185 extra)
186 self.repo.commitctx(ctx)
186 self.repo.commitctx(ctx)
187 return hex(self.repo.changelog.tip())
187 return hex(self.repo.changelog.tip())
188
188
189 def setfilemapmode(self, active):
189 def setfilemapmode(self, active):
190 self.filemapmode = active
190 self.filemapmode = active
191
191
192 class mercurial_source(converter_source):
192 class mercurial_source(converter_source):
193 def __init__(self, ui, path, rev=None):
193 def __init__(self, ui, path, rev=None):
194 converter_source.__init__(self, ui, path, rev)
194 converter_source.__init__(self, ui, path, rev)
195 self.saverev = ui.configbool('convert', 'hg.saverev', True)
195 self.saverev = ui.configbool('convert', 'hg.saverev', True)
196 try:
196 try:
197 self.repo = hg.repository(self.ui, path)
197 self.repo = hg.repository(self.ui, path)
198 # try to provoke an exception if this isn't really a hg
198 # try to provoke an exception if this isn't really a hg
199 # repo, but some other bogus compatible-looking url
199 # repo, but some other bogus compatible-looking url
200 if not self.repo.local():
200 if not self.repo.local():
201 raise RepoError()
201 raise RepoError()
202 except RepoError:
202 except RepoError:
203 ui.print_exc()
203 ui.print_exc()
204 raise NoRepo("%s is not a local Mercurial repo" % path)
204 raise NoRepo("%s is not a local Mercurial repo" % path)
205 self.lastrev = None
205 self.lastrev = None
206 self.lastctx = None
206 self.lastctx = None
207 self._changescache = None
207 self._changescache = None
208 self.convertfp = None
208 self.convertfp = None
209 # Restrict converted revisions to startrev descendants
209 # Restrict converted revisions to startrev descendants
210 startnode = ui.config('convert', 'hg.startrev')
210 startnode = ui.config('convert', 'hg.startrev')
211 if startnode is not None:
211 if startnode is not None:
212 try:
212 try:
213 startnode = self.repo.lookup(startnode)
213 startnode = self.repo.lookup(startnode)
214 except repo.RepoError:
214 except repo.RepoError:
215 raise util.Abort(_('%s is not a valid start revision')
215 raise util.Abort(_('%s is not a valid start revision')
216 % startnode)
216 % startnode)
217 startrev = self.repo.changelog.rev(startnode)
217 startrev = self.repo.changelog.rev(startnode)
218 children = {startnode: 1}
218 children = {startnode: 1}
219 for rev in self.repo.changelog.descendants(startrev):
219 for rev in self.repo.changelog.descendants(startrev):
220 children[self.repo.changelog.node(rev)] = 1
220 children[self.repo.changelog.node(rev)] = 1
221 self.keep = children.__contains__
221 self.keep = children.__contains__
222 else:
222 else:
223 self.keep = util.always
223 self.keep = util.always
224
224
225 def changectx(self, rev):
225 def changectx(self, rev):
226 if self.lastrev != rev:
226 if self.lastrev != rev:
227 self.lastctx = self.repo[rev]
227 self.lastctx = self.repo[rev]
228 self.lastrev = rev
228 self.lastrev = rev
229 return self.lastctx
229 return self.lastctx
230
230
231 def parents(self, ctx):
231 def parents(self, ctx):
232 return [p.node() for p in ctx.parents()
232 return [p.node() for p in ctx.parents()
233 if p and self.keep(p.node())]
233 if p and self.keep(p.node())]
234
234
235 def getheads(self):
235 def getheads(self):
236 if self.rev:
236 if self.rev:
237 heads = [self.repo[self.rev].node()]
237 heads = [self.repo[self.rev].node()]
238 else:
238 else:
239 heads = self.repo.heads()
239 heads = self.repo.heads()
240 return [hex(h) for h in heads if self.keep(h)]
240 return [hex(h) for h in heads if self.keep(h)]
241
241
242 def getfile(self, name, rev):
242 def getfile(self, name, rev):
243 try:
243 try:
244 return self.changectx(rev)[name].data()
244 return self.changectx(rev)[name].data()
245 except revlog.LookupError, err:
245 except revlog.LookupError, err:
246 raise IOError(err)
246 raise IOError(err)
247
247
248 def getmode(self, name, rev):
248 def getmode(self, name, rev):
249 return self.changectx(rev).manifest().flags(name)
249 return self.changectx(rev).manifest().flags(name)
250
250
251 def getchanges(self, rev):
251 def getchanges(self, rev):
252 ctx = self.changectx(rev)
252 ctx = self.changectx(rev)
253 parents = self.parents(ctx)
253 parents = self.parents(ctx)
254 if not parents:
254 if not parents:
255 files = util.sort(ctx.manifest().keys())
255 files = util.sort(ctx.manifest().keys())
256 return [(f, rev) for f in files], {}
256 return [(f, rev) for f in files], {}
257 if self._changescache and self._changescache[0] == rev:
257 if self._changescache and self._changescache[0] == rev:
258 m, a, r = self._changescache[1]
258 m, a, r = self._changescache[1]
259 else:
259 else:
260 m, a, r = self.repo.status(parents[0], ctx.node())[:3]
260 m, a, r = self.repo.status(parents[0], ctx.node())[:3]
261 changes = [(name, rev) for name in m + a + r]
261 changes = [(name, rev) for name in m + a + r]
262 return util.sort(changes), self.getcopies(ctx, m + a)
262 return util.sort(changes), self.getcopies(ctx, m + a)
263
263
264 def getcopies(self, ctx, files):
264 def getcopies(self, ctx, files):
265 copies = {}
265 copies = {}
266 for name in files:
266 for name in files:
267 try:
267 try:
268 copynode = ctx.filectx(name).renamed()[0]
268 copynode = ctx.filectx(name).renamed()[0]
269 if self.keep(copynode):
269 if self.keep(copynode):
270 copies[name] = copynode
270 copies[name] = copynode
271 except TypeError:
271 except TypeError:
272 pass
272 pass
273 return copies
273 return copies
274
274
275 def getcommit(self, rev):
275 def getcommit(self, rev):
276 ctx = self.changectx(rev)
276 ctx = self.changectx(rev)
277 parents = [hex(p) for p in self.parents(ctx)]
277 parents = [hex(p) for p in self.parents(ctx)]
278 if self.saverev:
278 if self.saverev:
279 crev = rev
279 crev = rev
280 else:
280 else:
281 crev = None
281 crev = None
282 return commit(author=ctx.user(), date=util.datestr(ctx.date()),
282 return commit(author=ctx.user(), date=util.datestr(ctx.date()),
283 desc=ctx.description(), rev=crev, parents=parents,
283 desc=ctx.description(), rev=crev, parents=parents,
284 branch=ctx.branch(), extra=ctx.extra())
284 branch=ctx.branch(), extra=ctx.extra())
285
285
286 def gettags(self):
286 def gettags(self):
287 tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
287 tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
288 return dict([(name, hex(node)) for name, node in tags
288 return dict([(name, hex(node)) for name, node in tags
289 if self.keep(node)])
289 if self.keep(node)])
290
290
291 def getchangedfiles(self, rev, i):
291 def getchangedfiles(self, rev, i):
292 ctx = self.changectx(rev)
292 ctx = self.changectx(rev)
293 parents = self.parents(ctx)
293 parents = self.parents(ctx)
294 if not parents and i is None:
294 if not parents and i is None:
295 i = 0
295 i = 0
296 changes = [], ctx.manifest().keys(), []
296 changes = [], ctx.manifest().keys(), []
297 else:
297 else:
298 i = i or 0
298 i = i or 0
299 changes = self.repo.status(parents[i], ctx.node())[:3]
299 changes = self.repo.status(parents[i], ctx.node())[:3]
300
300
301 if i == 0:
301 if i == 0:
302 self._changescache = (rev, changes)
302 self._changescache = (rev, changes)
303
303
304 return changes[0] + changes[1] + changes[2]
304 return changes[0] + changes[1] + changes[2]
305
305
306 def converted(self, rev, destrev):
306 def converted(self, rev, destrev):
307 if self.convertfp is None:
307 if self.convertfp is None:
308 self.convertfp = open(os.path.join(self.path, '.hg', 'shamap'),
308 self.convertfp = open(os.path.join(self.path, '.hg', 'shamap'),
309 'a')
309 'a')
310 self.convertfp.write('%s %s\n' % (destrev, rev))
310 self.convertfp.write('%s %s\n' % (destrev, rev))
311 self.convertfp.flush()
311 self.convertfp.flush()
312
312
313 def before(self):
313 def before(self):
314 self.ui.debug(_('run hg source pre-conversion action\n'))
314 self.ui.debug(_('run hg source pre-conversion action\n'))
315
315
316 def after(self):
316 def after(self):
317 self.ui.debug(_('run hg source post-conversion action\n'))
317 self.ui.debug(_('run hg source post-conversion action\n'))
@@ -1,401 +1,401 b''
1 # rebase.py - rebasing feature for mercurial
1 # rebase.py - rebasing feature for mercurial
2 #
2 #
3 # Copyright 2008 Stefano Tortarolo <stefano.tortarolo at gmail dot com>
3 # Copyright 2008 Stefano Tortarolo <stefano.tortarolo at gmail dot com>
4 #
4 #
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 ''' Rebasing feature
8 ''' Rebasing feature
9
9
10 This extension lets you rebase changesets in an existing Mercurial repository.
10 This extension lets you rebase changesets in an existing Mercurial repository.
11
11
12 For more information:
12 For more information:
13 http://www.selenic.com/mercurial/wiki/index.cgi/RebaseProject
13 http://www.selenic.com/mercurial/wiki/index.cgi/RebaseProject
14 '''
14 '''
15
15
16 from mercurial import util, repair, merge, cmdutil, dispatch, commands
16 from mercurial import util, repair, merge, cmdutil, dispatch, commands
17 from mercurial.commands import templateopts
17 from mercurial.commands import templateopts
18 from mercurial.node import nullrev
18 from mercurial.node import nullrev
19 from mercurial.i18n import _
19 from mercurial.i18n import _
20 import os, errno
20 import os, errno
21
21
22 def rebase(ui, repo, **opts):
22 def rebase(ui, repo, **opts):
23 """move changeset (and descendants) to a different branch
23 """move changeset (and descendants) to a different branch
24
24
25 Rebase uses repeated merging to graft changesets from one part of history
25 Rebase uses repeated merging to graft changesets from one part of history
26 onto another. This can be useful for linearizing local changes relative to
26 onto another. This can be useful for linearizing local changes relative to
27 a master development tree.
27 a master development tree.
28
28
29 If a rebase is interrupted to manually resolve a merge, it can be continued
29 If a rebase is interrupted to manually resolve a merge, it can be continued
30 with --continue or aborted with --abort.
30 with --continue or aborted with --abort.
31 """
31 """
32 originalwd = target = source = None
32 originalwd = target = source = None
33 external = nullrev
33 external = nullrev
34 state = skipped = {}
34 state = skipped = {}
35
35
36 lock = wlock = None
36 lock = wlock = None
37 try:
37 try:
38 lock = repo.lock()
38 lock = repo.lock()
39 wlock = repo.wlock()
39 wlock = repo.wlock()
40
40
41 # Validate input and define rebasing points
41 # Validate input and define rebasing points
42 destf = opts.get('dest', None)
42 destf = opts.get('dest', None)
43 srcf = opts.get('source', None)
43 srcf = opts.get('source', None)
44 basef = opts.get('base', None)
44 basef = opts.get('base', None)
45 contf = opts.get('continue')
45 contf = opts.get('continue')
46 abortf = opts.get('abort')
46 abortf = opts.get('abort')
47 collapsef = opts.get('collapse', False)
47 collapsef = opts.get('collapse', False)
48 if contf or abortf:
48 if contf or abortf:
49 if contf and abortf:
49 if contf and abortf:
50 raise dispatch.ParseError('rebase',
50 raise dispatch.ParseError('rebase',
51 _('cannot use both abort and continue'))
51 _('cannot use both abort and continue'))
52 if collapsef:
52 if collapsef:
53 raise dispatch.ParseError('rebase',
53 raise dispatch.ParseError('rebase',
54 _('cannot use collapse with continue or abort'))
54 _('cannot use collapse with continue or abort'))
55
55
56 if (srcf or basef or destf):
56 if (srcf or basef or destf):
57 raise dispatch.ParseError('rebase',
57 raise dispatch.ParseError('rebase',
58 _('abort and continue do not allow specifying revisions'))
58 _('abort and continue do not allow specifying revisions'))
59
59
60 originalwd, target, state, collapsef, external = restorestatus(repo)
60 originalwd, target, state, collapsef, external = restorestatus(repo)
61 if abortf:
61 if abortf:
62 abort(repo, originalwd, target, state)
62 abort(repo, originalwd, target, state)
63 return
63 return
64 else:
64 else:
65 if srcf and basef:
65 if srcf and basef:
66 raise dispatch.ParseError('rebase', _('cannot specify both a '
66 raise dispatch.ParseError('rebase', _('cannot specify both a '
67 'revision and a base'))
67 'revision and a base'))
68 cmdutil.bail_if_changed(repo)
68 cmdutil.bail_if_changed(repo)
69 result = buildstate(repo, destf, srcf, basef, collapsef)
69 result = buildstate(repo, destf, srcf, basef, collapsef)
70 if result:
70 if result:
71 originalwd, target, state, external = result
71 originalwd, target, state, external = result
72 else: # Empty state built, nothing to rebase
72 else: # Empty state built, nothing to rebase
73 repo.ui.status(_('nothing to rebase\n'))
73 repo.ui.status(_('nothing to rebase\n'))
74 return
74 return
75
75
76 # Rebase
76 # Rebase
77 targetancestors = list(repo.changelog.ancestors(target))
77 targetancestors = list(repo.changelog.ancestors(target))
78 targetancestors.append(target)
78 targetancestors.append(target)
79
79
80 for rev in util.sort(state):
80 for rev in util.sort(state):
81 if state[rev] == -1:
81 if state[rev] == -1:
82 storestatus(repo, originalwd, target, state, collapsef,
82 storestatus(repo, originalwd, target, state, collapsef,
83 external)
83 external)
84 rebasenode(repo, rev, target, state, skipped, targetancestors,
84 rebasenode(repo, rev, target, state, skipped, targetancestors,
85 collapsef)
85 collapsef)
86 ui.note(_('rebase merging completed\n'))
86 ui.note(_('rebase merging completed\n'))
87
87
88 if collapsef:
88 if collapsef:
89 p1, p2 = defineparents(repo, min(state), target,
89 p1, p2 = defineparents(repo, min(state), target,
90 state, targetancestors)
90 state, targetancestors)
91 concludenode(repo, rev, p1, external, state, collapsef,
91 concludenode(repo, rev, p1, external, state, collapsef,
92 last=True, skipped=skipped)
92 last=True, skipped=skipped)
93
93
94 if 'qtip' in repo.tags():
94 if 'qtip' in repo.tags():
95 updatemq(repo, state, skipped, **opts)
95 updatemq(repo, state, skipped, **opts)
96
96
97 if not opts.get('keep'):
97 if not opts.get('keep'):
98 # Remove no more useful revisions
98 # Remove no more useful revisions
99 if (util.set(repo.changelog.descendants(min(state)))
99 if (util.set(repo.changelog.descendants(min(state)))
100 - util.set(state.keys())):
100 - util.set(state.keys())):
101 ui.warn(_("warning: new changesets detected on source branch, "
101 ui.warn(_("warning: new changesets detected on source branch, "
102 "not stripping\n"))
102 "not stripping\n"))
103 else:
103 else:
104 repair.strip(repo.ui, repo, repo[min(state)].node(), "strip")
104 repair.strip(repo.ui, repo, repo[min(state)].node(), "strip")
105
105
106 clearstatus(repo)
106 clearstatus(repo)
107 ui.status(_("rebase completed\n"))
107 ui.status(_("rebase completed\n"))
108 if skipped:
108 if skipped:
109 ui.note(_("%d revisions have been skipped\n") % len(skipped))
109 ui.note(_("%d revisions have been skipped\n") % len(skipped))
110 finally:
110 finally:
111 del lock, wlock
111 del lock, wlock
112
112
113 def concludenode(repo, rev, p1, p2, state, collapse, last=False, skipped={}):
113 def concludenode(repo, rev, p1, p2, state, collapse, last=False, skipped={}):
114 """Skip commit if collapsing has been required and rev is not the last
114 """Skip commit if collapsing has been required and rev is not the last
115 revision, commit otherwise
115 revision, commit otherwise
116 """
116 """
117 repo.dirstate.setparents(repo[p1].node(), repo[p2].node())
117 repo.dirstate.setparents(repo[p1].node(), repo[p2].node())
118
118
119 if collapse and not last:
119 if collapse and not last:
120 return None
120 return None
121
121
122 # Commit, record the old nodeid
122 # Commit, record the old nodeid
123 m, a, r = repo.status()[:3]
123 m, a, r = repo.status()[:3]
124 newrev = nullrev
124 newrev = nullrev
125 try:
125 try:
126 if last:
126 if last:
127 commitmsg = 'Collapsed revision'
127 commitmsg = 'Collapsed revision'
128 for rebased in state:
128 for rebased in state:
129 if rebased not in skipped:
129 if rebased not in skipped:
130 commitmsg += '\n* %s' % repo[rebased].description()
130 commitmsg += '\n* %s' % repo[rebased].description()
131 commitmsg = repo.ui.edit(commitmsg, repo.ui.username())
131 commitmsg = repo.ui.edit(commitmsg, repo.ui.username())
132 else:
132 else:
133 commitmsg = repo[rev].description()
133 commitmsg = repo[rev].description()
134 # Commit might fail if unresolved files exist
134 # Commit might fail if unresolved files exist
135 newrev = repo.commit(m+a+r,
135 newrev = repo.commit(m+a+r,
136 text=commitmsg,
136 text=commitmsg,
137 user=repo[rev].user(),
137 user=repo[rev].user(),
138 date=repo[rev].date(),
138 date=repo[rev].date(),
139 extra={'rebase_source': repo[rev].hex()})
139 extra={'rebase_source': repo[rev].hex()})
140 return newrev
140 return newrev
141 except util.Abort:
141 except util.Abort:
142 # Invalidate the previous setparents
142 # Invalidate the previous setparents
143 repo.dirstate.invalidate()
143 repo.dirstate.invalidate()
144 raise
144 raise
145
145
146 def rebasenode(repo, rev, target, state, skipped, targetancestors, collapse):
146 def rebasenode(repo, rev, target, state, skipped, targetancestors, collapse):
147 'Rebase a single revision'
147 'Rebase a single revision'
148 repo.ui.debug(_("rebasing %d:%s\n") % (rev, repo[rev].node()))
148 repo.ui.debug(_("rebasing %d:%s\n") % (rev, repo[rev].node()))
149
149
150 p1, p2 = defineparents(repo, rev, target, state, targetancestors)
150 p1, p2 = defineparents(repo, rev, target, state, targetancestors)
151
151
152 # Merge phase
152 # Merge phase
153 if len(repo.parents()) != 2:
153 if len(repo.parents()) != 2:
154 # Update to target and merge it with local
154 # Update to target and merge it with local
155 merge.update(repo, p1, False, True, False)
155 merge.update(repo, p1, False, True, False)
156 repo.dirstate.write()
156 repo.dirstate.write()
157 stats = merge.update(repo, rev, True, False, False)
157 stats = merge.update(repo, rev, True, False, False)
158
158
159 if stats[3] > 0:
159 if stats[3] > 0:
160 raise util.Abort(_('fix unresolved conflicts with hg resolve then '
160 raise util.Abort(_('fix unresolved conflicts with hg resolve then '
161 'run hg rebase --continue'))
161 'run hg rebase --continue'))
162 else: # we have an interrupted rebase
162 else: # we have an interrupted rebase
163 repo.ui.debug(_('resuming interrupted rebase\n'))
163 repo.ui.debug(_('resuming interrupted rebase\n'))
164
164
165
165
166 newrev = concludenode(repo, rev, p1, p2, state, collapse)
166 newrev = concludenode(repo, rev, p1, p2, state, collapse)
167
167
168 # Update the state
168 # Update the state
169 if newrev is not None:
169 if newrev is not None:
170 state[rev] = repo[newrev].rev()
170 state[rev] = repo[newrev].rev()
171 else:
171 else:
172 if not collapse:
172 if not collapse:
173 repo.ui.note('no changes, revision %d skipped\n' % rev)
173 repo.ui.note('no changes, revision %d skipped\n' % rev)
174 repo.ui.debug('next revision set to %s\n' % p1)
174 repo.ui.debug('next revision set to %s\n' % p1)
175 skipped[rev] = True
175 skipped[rev] = True
176 state[rev] = p1
176 state[rev] = p1
177
177
178 def defineparents(repo, rev, target, state, targetancestors):
178 def defineparents(repo, rev, target, state, targetancestors):
179 'Return the new parent relationship of the revision that will be rebased'
179 'Return the new parent relationship of the revision that will be rebased'
180 parents = repo[rev].parents()
180 parents = repo[rev].parents()
181 p1 = p2 = nullrev
181 p1 = p2 = nullrev
182
182
183 P1n = parents[0].rev()
183 P1n = parents[0].rev()
184 if P1n in targetancestors:
184 if P1n in targetancestors:
185 p1 = target
185 p1 = target
186 elif P1n in state:
186 elif P1n in state:
187 p1 = state[P1n]
187 p1 = state[P1n]
188 else: # P1n external
188 else: # P1n external
189 p1 = target
189 p1 = target
190 p2 = P1n
190 p2 = P1n
191
191
192 if len(parents) == 2 and parents[1].rev() not in targetancestors:
192 if len(parents) == 2 and parents[1].rev() not in targetancestors:
193 P2n = parents[1].rev()
193 P2n = parents[1].rev()
194 # interesting second parent
194 # interesting second parent
195 if P2n in state:
195 if P2n in state:
196 if p1 == target: # P1n in targetancestors or external
196 if p1 == target: # P1n in targetancestors or external
197 p1 = state[P2n]
197 p1 = state[P2n]
198 else:
198 else:
199 p2 = state[P2n]
199 p2 = state[P2n]
200 else: # P2n external
200 else: # P2n external
201 if p2 != nullrev: # P1n external too => rev is a merged revision
201 if p2 != nullrev: # P1n external too => rev is a merged revision
202 raise util.Abort(_('cannot use revision %d as base, result '
202 raise util.Abort(_('cannot use revision %d as base, result '
203 'would have 3 parents') % rev)
203 'would have 3 parents') % rev)
204 p2 = P2n
204 p2 = P2n
205 return p1, p2
205 return p1, p2
206
206
207 def updatemq(repo, state, skipped, **opts):
207 def updatemq(repo, state, skipped, **opts):
208 'Update rebased mq patches - finalize and then import them'
208 'Update rebased mq patches - finalize and then import them'
209 mqrebase = {}
209 mqrebase = {}
210 for p in repo.mq.applied:
210 for p in repo.mq.applied:
211 if repo[p.rev].rev() in state:
211 if repo[p.rev].rev() in state:
212 repo.ui.debug('revision %d is an mq patch (%s), finalize it.\n' %
212 repo.ui.debug('revision %d is an mq patch (%s), finalize it.\n' %
213 (repo[p.rev].rev(), p.name))
213 (repo[p.rev].rev(), p.name))
214 mqrebase[repo[p.rev].rev()] = p.name
214 mqrebase[repo[p.rev].rev()] = p.name
215
215
216 if mqrebase:
216 if mqrebase:
217 repo.mq.finish(repo, mqrebase.keys())
217 repo.mq.finish(repo, mqrebase.keys())
218
218
219 # We must start import from the newest revision
219 # We must start import from the newest revision
220 mq = mqrebase.keys()
220 mq = mqrebase.keys()
221 mq.sort()
221 mq.sort()
222 mq.reverse()
222 mq.reverse()
223 for rev in mq:
223 for rev in mq:
224 if rev not in skipped:
224 if rev not in skipped:
225 repo.ui.debug('import mq patch %d (%s)\n' % (state[rev],
225 repo.ui.debug('import mq patch %d (%s)\n' % (state[rev],
226 mqrebase[rev]))
226 mqrebase[rev]))
227 repo.mq.qimport(repo, (), patchname=mqrebase[rev],
227 repo.mq.qimport(repo, (), patchname=mqrebase[rev],
228 git=opts.get('git', False),rev=[str(state[rev])])
228 git=opts.get('git', False),rev=[str(state[rev])])
229 repo.mq.save_dirty()
229 repo.mq.save_dirty()
230
230
231 def storestatus(repo, originalwd, target, state, collapse, external):
231 def storestatus(repo, originalwd, target, state, collapse, external):
232 'Store the current status to allow recovery'
232 'Store the current status to allow recovery'
233 f = repo.opener("rebasestate", "w")
233 f = repo.opener("rebasestate", "w")
234 f.write(repo[originalwd].hex() + '\n')
234 f.write(repo[originalwd].hex() + '\n')
235 f.write(repo[target].hex() + '\n')
235 f.write(repo[target].hex() + '\n')
236 f.write(repo[external].hex() + '\n')
236 f.write(repo[external].hex() + '\n')
237 f.write('%d\n' % int(collapse))
237 f.write('%d\n' % int(collapse))
238 for d, v in state.items():
238 for d, v in state.items():
239 oldrev = repo[d].hex()
239 oldrev = repo[d].hex()
240 newrev = repo[v].hex()
240 newrev = repo[v].hex()
241 f.write("%s:%s\n" % (oldrev, newrev))
241 f.write("%s:%s\n" % (oldrev, newrev))
242 f.close()
242 f.close()
243 repo.ui.debug(_('rebase status stored\n'))
243 repo.ui.debug(_('rebase status stored\n'))
244
244
245 def clearstatus(repo):
245 def clearstatus(repo):
246 'Remove the status files'
246 'Remove the status files'
247 if os.path.exists(repo.join("rebasestate")):
247 if os.path.exists(repo.join("rebasestate")):
248 util.unlink(repo.join("rebasestate"))
248 util.unlink(repo.join("rebasestate"))
249
249
250 def restorestatus(repo):
250 def restorestatus(repo):
251 'Restore a previously stored status'
251 'Restore a previously stored status'
252 try:
252 try:
253 target = None
253 target = None
254 collapse = False
254 collapse = False
255 external = nullrev
255 external = nullrev
256 state = {}
256 state = {}
257 f = repo.opener("rebasestate")
257 f = repo.opener("rebasestate")
258 for i, l in enumerate(f.read().splitlines()):
258 for i, l in enumerate(f.read().splitlines()):
259 if i == 0:
259 if i == 0:
260 originalwd = repo[l].rev()
260 originalwd = repo[l].rev()
261 elif i == 1:
261 elif i == 1:
262 target = repo[l].rev()
262 target = repo[l].rev()
263 elif i == 2:
263 elif i == 2:
264 external = repo[l].rev()
264 external = repo[l].rev()
265 elif i == 3:
265 elif i == 3:
266 collapse = bool(int(l))
266 collapse = bool(int(l))
267 else:
267 else:
268 oldrev, newrev = l.split(':')
268 oldrev, newrev = l.split(':')
269 state[repo[oldrev].rev()] = repo[newrev].rev()
269 state[repo[oldrev].rev()] = repo[newrev].rev()
270 repo.ui.debug(_('rebase status resumed\n'))
270 repo.ui.debug(_('rebase status resumed\n'))
271 return originalwd, target, state, collapse, external
271 return originalwd, target, state, collapse, external
272 except IOError, err:
272 except IOError, err:
273 if err.errno != errno.ENOENT:
273 if err.errno != errno.ENOENT:
274 raise
274 raise
275 raise util.Abort(_('no rebase in progress'))
275 raise util.Abort(_('no rebase in progress'))
276
276
277 def abort(repo, originalwd, target, state):
277 def abort(repo, originalwd, target, state):
278 'Restore the repository to its original state'
278 'Restore the repository to its original state'
279 if util.set(repo.changelog.descendants(target)) - util.set(state.values()):
279 if util.set(repo.changelog.descendants(target)) - util.set(state.values()):
280 repo.ui.warn(_("warning: new changesets detected on target branch, "
280 repo.ui.warn(_("warning: new changesets detected on target branch, "
281 "not stripping\n"))
281 "not stripping\n"))
282 else:
282 else:
283 # Strip from the first rebased revision
283 # Strip from the first rebased revision
284 merge.update(repo, repo[originalwd].rev(), False, True, False)
284 merge.update(repo, repo[originalwd].rev(), False, True, False)
285 rebased = filter(lambda x: x > -1, state.values())
285 rebased = filter(lambda x: x > -1, state.values())
286 if rebased:
286 if rebased:
287 strippoint = min(rebased)
287 strippoint = min(rebased)
288 repair.strip(repo.ui, repo, repo[strippoint].node(), "strip")
288 repair.strip(repo.ui, repo, repo[strippoint].node(), "strip")
289 clearstatus(repo)
289 clearstatus(repo)
290 repo.ui.status(_('rebase aborted\n'))
290 repo.ui.status(_('rebase aborted\n'))
291
291
292 def buildstate(repo, dest, src, base, collapse):
292 def buildstate(repo, dest, src, base, collapse):
293 'Define which revisions are going to be rebased and where'
293 'Define which revisions are going to be rebased and where'
294 state = {}
294 state = {}
295 targetancestors = util.set()
295 targetancestors = util.set()
296
296
297 if not dest:
297 if not dest:
298 # Destination defaults to the latest revision in the current branch
298 # Destination defaults to the latest revision in the current branch
299 branch = repo[None].branch()
299 branch = repo[None].branch()
300 dest = repo[branch].rev()
300 dest = repo[branch].rev()
301 else:
301 else:
302 if 'qtip' in repo.tags() and (repo[dest].hex() in
302 if 'qtip' in repo.tags() and (repo[dest].hex() in
303 [s.rev for s in repo.mq.applied]):
303 [s.rev for s in repo.mq.applied]):
304 raise util.Abort(_('cannot rebase onto an applied mq patch'))
304 raise util.Abort(_('cannot rebase onto an applied mq patch'))
305 dest = repo[dest].rev()
305 dest = repo[dest].rev()
306
306
307 if src:
307 if src:
308 commonbase = repo[src].ancestor(repo[dest])
308 commonbase = repo[src].ancestor(repo[dest])
309 if commonbase == repo[src]:
309 if commonbase == repo[src]:
310 raise util.Abort(_('cannot rebase an ancestor'))
310 raise util.Abort(_('cannot rebase an ancestor'))
311 if commonbase == repo[dest]:
311 if commonbase == repo[dest]:
312 raise util.Abort(_('cannot rebase a descendant'))
312 raise util.Abort(_('cannot rebase a descendant'))
313 source = repo[src].rev()
313 source = repo[src].rev()
314 else:
314 else:
315 if base:
315 if base:
316 cwd = repo[base].rev()
316 cwd = repo[base].rev()
317 else:
317 else:
318 cwd = repo['.'].rev()
318 cwd = repo['.'].rev()
319
319
320 if cwd == dest:
320 if cwd == dest:
321 repo.ui.debug(_('already working on current\n'))
321 repo.ui.debug(_('already working on current\n'))
322 return None
322 return None
323
323
324 targetancestors = util.set(repo.changelog.ancestors(dest))
324 targetancestors = util.set(repo.changelog.ancestors(dest))
325 if cwd in targetancestors:
325 if cwd in targetancestors:
326 repo.ui.debug(_('already working on the current branch\n'))
326 repo.ui.debug(_('already working on the current branch\n'))
327 return None
327 return None
328
328
329 cwdancestors = util.set(repo.changelog.ancestors(cwd))
329 cwdancestors = util.set(repo.changelog.ancestors(cwd))
330 cwdancestors.add(cwd)
330 cwdancestors.add(cwd)
331 rebasingbranch = cwdancestors - targetancestors
331 rebasingbranch = cwdancestors - targetancestors
332 source = min(rebasingbranch)
332 source = min(rebasingbranch)
333
333
334 repo.ui.debug(_('rebase onto %d starting from %d\n') % (dest, source))
334 repo.ui.debug(_('rebase onto %d starting from %d\n') % (dest, source))
335 state = dict.fromkeys(repo.changelog.descendants(source), nullrev)
335 state = dict.fromkeys(repo.changelog.descendants(source), nullrev)
336 external = nullrev
336 external = nullrev
337 if collapse:
337 if collapse:
338 if not targetancestors:
338 if not targetancestors:
339 targetancestors = util.set(repo.changelog.ancestors(dest))
339 targetancestors = util.set(repo.changelog.ancestors(dest))
340 for rev in state:
340 for rev in state:
341 # Check externals and fail if there are more than one
341 # Check externals and fail if there are more than one
342 for p in repo[rev].parents():
342 for p in repo[rev].parents():
343 if (p.rev() not in state and p.rev() != source
343 if (p.rev() not in state and p.rev() != source
344 and p.rev() not in targetancestors):
344 and p.rev() not in targetancestors):
345 if external != nullrev:
345 if external != nullrev:
346 raise util.Abort(_('unable to collapse, there is more '
346 raise util.Abort(_('unable to collapse, there is more '
347 'than one external parent'))
347 'than one external parent'))
348 external = p.rev()
348 external = p.rev()
349
349
350 state[source] = nullrev
350 state[source] = nullrev
351 return repo['.'].rev(), repo[dest].rev(), state, external
351 return repo['.'].rev(), repo[dest].rev(), state, external
352
352
353 def pulldelegate(pullfunction, repo, *args, **opts):
353 def pulldelegate(pullfunction, repo, *args, **opts):
354 'Call rebase after pull if the latter has been invoked with --rebase'
354 'Call rebase after pull if the latter has been invoked with --rebase'
355 if opts.get('rebase'):
355 if opts.get('rebase'):
356 if opts.get('update'):
356 if opts.get('update'):
357 raise util.Abort(_('--update and --rebase are not compatible'))
357 raise util.Abort(_('--update and --rebase are not compatible'))
358
358
359 cmdutil.bail_if_changed(repo)
359 cmdutil.bail_if_changed(repo)
360 revsprepull = len(repo)
360 revsprepull = len(repo)
361 pullfunction(repo.ui, repo, *args, **opts)
361 pullfunction(repo.ui, repo, *args, **opts)
362 revspostpull = len(repo)
362 revspostpull = len(repo)
363 if revspostpull > revsprepull:
363 if revspostpull > revsprepull:
364 rebase(repo.ui, repo, **opts)
364 rebase(repo.ui, repo, **opts)
365 else:
365 else:
366 pullfunction(repo.ui, repo, *args, **opts)
366 pullfunction(repo.ui, repo, *args, **opts)
367
367
368 def uisetup(ui):
368 def uisetup(ui):
369 'Replace pull with a decorator to provide --rebase option'
369 'Replace pull with a decorator to provide --rebase option'
370 # cribbed from color.py
370 # cribbed from color.py
371 aliases, entry = cmdutil.findcmd(ui, 'pull', commands.table)
371 aliases, entry = cmdutil.findcmd(ui, 'pull', commands.table)
372 for candidatekey, candidateentry in commands.table.iteritems():
372 for candidatekey, candidateentry in commands.table.iteritems():
373 if candidateentry is entry:
373 if candidateentry is entry:
374 cmdkey, cmdentry = candidatekey, entry
374 cmdkey, cmdentry = candidatekey, entry
375 break
375 break
376
376
377 decorator = lambda ui, repo, *args, **opts: \
377 decorator = lambda ui, repo, *args, **opts: \
378 pulldelegate(cmdentry[0], repo, *args, **opts)
378 pulldelegate(cmdentry[0], repo, *args, **opts)
379 # make sure 'hg help cmd' still works
379 # make sure 'hg help cmd' still works
380 decorator.__doc__ = cmdentry[0].__doc__
380 decorator.__doc__ = cmdentry[0].__doc__
381 decoratorentry = (decorator,) + cmdentry[1:]
381 decoratorentry = (decorator,) + cmdentry[1:]
382 rebaseopt = ('', 'rebase', None,
382 rebaseopt = ('', 'rebase', None,
383 _("rebase working directory to branch head"))
383 _("rebase working directory to branch head"))
384 decoratorentry[1].append(rebaseopt)
384 decoratorentry[1].append(rebaseopt)
385 commands.table[cmdkey] = decoratorentry
385 commands.table[cmdkey] = decoratorentry
386
386
387 cmdtable = {
387 cmdtable = {
388 "rebase":
388 "rebase":
389 (rebase,
389 (rebase,
390 [
390 [
391 ('', 'keep', False, _('keep original revisions')),
391 ('', 'keep', False, _('keep original revisions')),
392 ('s', 'source', '', _('rebase from a given revision')),
392 ('s', 'source', '', _('rebase from a given revision')),
393 ('b', 'base', '', _('rebase from the base of a given revision')),
393 ('b', 'base', '', _('rebase from the base of a given revision')),
394 ('d', 'dest', '', _('rebase onto a given revision')),
394 ('d', 'dest', '', _('rebase onto a given revision')),
395 ('', 'collapse', False, _('collapse the rebased revisions')),
395 ('', 'collapse', False, _('collapse the rebased revisions')),
396 ('c', 'continue', False, _('continue an interrupted rebase')),
396 ('c', 'continue', False, _('continue an interrupted rebase')),
397 ('a', 'abort', False, _('abort an interrupted rebase')),] +
397 ('a', 'abort', False, _('abort an interrupted rebase')),] +
398 templateopts,
398 templateopts,
399 _('hg rebase [-s rev | -b rev] [-d rev] [--collapse] | [-c] | [-a] | '
399 _('hg rebase [-s rev | -b rev] [-d rev] [--collapse] | [-c] | [-a] | '
400 '[--keep]')),
400 '[--keep]')),
401 }
401 }
@@ -1,2070 +1,2070 b''
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
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, 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
10 import repo, changegroup
11 import changelog, dirstate, filelog, manifest, context, weakref
11 import changelog, dirstate, filelog, manifest, context, weakref
12 import lock, transaction, stat, errno, ui, store
12 import lock, transaction, stat, errno, ui, store
13 import os, revlog, time, util, extensions, hook, inspect
13 import os, revlog, time, util, extensions, hook, inspect
14 import match as match_
14 import match as match_
15 import merge as merge_
15 import merge as merge_
16
16
17 class localrepository(repo.repository):
17 class localrepository(repo.repository):
18 capabilities = util.set(('lookup', 'changegroupsubset'))
18 capabilities = util.set(('lookup', 'changegroupsubset'))
19 supported = ('revlogv1', 'store')
19 supported = ('revlogv1', 'store')
20
20
21 def __init__(self, parentui, path=None, create=0):
21 def __init__(self, parentui, path=None, create=0):
22 repo.repository.__init__(self)
22 repo.repository.__init__(self)
23 self.root = os.path.realpath(path)
23 self.root = os.path.realpath(path)
24 self.path = os.path.join(self.root, ".hg")
24 self.path = os.path.join(self.root, ".hg")
25 self.origroot = path
25 self.origroot = path
26 self.opener = util.opener(self.path)
26 self.opener = util.opener(self.path)
27 self.wopener = util.opener(self.root)
27 self.wopener = util.opener(self.root)
28
28
29 if not os.path.isdir(self.path):
29 if not os.path.isdir(self.path):
30 if create:
30 if create:
31 if not os.path.exists(path):
31 if not os.path.exists(path):
32 os.mkdir(path)
32 os.mkdir(path)
33 os.mkdir(self.path)
33 os.mkdir(self.path)
34 requirements = ["revlogv1"]
34 requirements = ["revlogv1"]
35 if parentui.configbool('format', 'usestore', True):
35 if parentui.configbool('format', 'usestore', True):
36 os.mkdir(os.path.join(self.path, "store"))
36 os.mkdir(os.path.join(self.path, "store"))
37 requirements.append("store")
37 requirements.append("store")
38 # create an invalid changelog
38 # create an invalid changelog
39 self.opener("00changelog.i", "a").write(
39 self.opener("00changelog.i", "a").write(
40 '\0\0\0\2' # represents revlogv2
40 '\0\0\0\2' # represents revlogv2
41 ' dummy changelog to prevent using the old repo layout'
41 ' dummy changelog to prevent using the old repo layout'
42 )
42 )
43 reqfile = self.opener("requires", "w")
43 reqfile = self.opener("requires", "w")
44 for r in requirements:
44 for r in requirements:
45 reqfile.write("%s\n" % r)
45 reqfile.write("%s\n" % r)
46 reqfile.close()
46 reqfile.close()
47 else:
47 else:
48 raise repo.RepoError(_("repository %s not found") % path)
48 raise repo.RepoError(_("repository %s not found") % path)
49 elif create:
49 elif create:
50 raise repo.RepoError(_("repository %s already exists") % path)
50 raise repo.RepoError(_("repository %s already exists") % path)
51 else:
51 else:
52 # find requirements
52 # find requirements
53 requirements = []
53 requirements = []
54 try:
54 try:
55 requirements = self.opener("requires").read().splitlines()
55 requirements = self.opener("requires").read().splitlines()
56 for r in requirements:
56 for r in requirements:
57 if r not in self.supported:
57 if r not in self.supported:
58 raise repo.RepoError(_("requirement '%s' not supported") % r)
58 raise repo.RepoError(_("requirement '%s' not supported") % r)
59 except IOError, inst:
59 except IOError, inst:
60 if inst.errno != errno.ENOENT:
60 if inst.errno != errno.ENOENT:
61 raise
61 raise
62
62
63 self.store = store.store(requirements, self.path, util.opener)
63 self.store = store.store(requirements, self.path, util.opener)
64 self.spath = self.store.path
64 self.spath = self.store.path
65 self.sopener = self.store.opener
65 self.sopener = self.store.opener
66 self.sjoin = self.store.join
66 self.sjoin = self.store.join
67 self.opener.createmode = self.store.createmode
67 self.opener.createmode = self.store.createmode
68
68
69 self.ui = ui.ui(parentui=parentui)
69 self.ui = ui.ui(parentui=parentui)
70 try:
70 try:
71 self.ui.readconfig(self.join("hgrc"), self.root)
71 self.ui.readconfig(self.join("hgrc"), self.root)
72 extensions.loadall(self.ui)
72 extensions.loadall(self.ui)
73 except IOError:
73 except IOError:
74 pass
74 pass
75
75
76 self.tagscache = None
76 self.tagscache = None
77 self._tagstypecache = None
77 self._tagstypecache = None
78 self.branchcache = None
78 self.branchcache = None
79 self._ubranchcache = None # UTF-8 version of branchcache
79 self._ubranchcache = None # UTF-8 version of branchcache
80 self._branchcachetip = None
80 self._branchcachetip = None
81 self.nodetagscache = None
81 self.nodetagscache = None
82 self.filterpats = {}
82 self.filterpats = {}
83 self._datafilters = {}
83 self._datafilters = {}
84 self._transref = self._lockref = self._wlockref = None
84 self._transref = self._lockref = self._wlockref = None
85
85
86 def __getattr__(self, name):
86 def __getattr__(self, name):
87 if name == 'changelog':
87 if name == 'changelog':
88 self.changelog = changelog.changelog(self.sopener)
88 self.changelog = changelog.changelog(self.sopener)
89 self.sopener.defversion = self.changelog.version
89 self.sopener.defversion = self.changelog.version
90 return self.changelog
90 return self.changelog
91 if name == 'manifest':
91 if name == 'manifest':
92 self.changelog
92 self.changelog
93 self.manifest = manifest.manifest(self.sopener)
93 self.manifest = manifest.manifest(self.sopener)
94 return self.manifest
94 return self.manifest
95 if name == 'dirstate':
95 if name == 'dirstate':
96 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
96 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
97 return self.dirstate
97 return self.dirstate
98 else:
98 else:
99 raise AttributeError, name
99 raise AttributeError, name
100
100
101 def __getitem__(self, changeid):
101 def __getitem__(self, changeid):
102 if changeid == None:
102 if changeid == None:
103 return context.workingctx(self)
103 return context.workingctx(self)
104 return context.changectx(self, changeid)
104 return context.changectx(self, changeid)
105
105
106 def __nonzero__(self):
106 def __nonzero__(self):
107 return True
107 return True
108
108
109 def __len__(self):
109 def __len__(self):
110 return len(self.changelog)
110 return len(self.changelog)
111
111
112 def __iter__(self):
112 def __iter__(self):
113 for i in xrange(len(self)):
113 for i in xrange(len(self)):
114 yield i
114 yield i
115
115
116 def url(self):
116 def url(self):
117 return 'file:' + self.root
117 return 'file:' + self.root
118
118
119 def hook(self, name, throw=False, **args):
119 def hook(self, name, throw=False, **args):
120 return hook.hook(self.ui, self, name, throw, **args)
120 return hook.hook(self.ui, self, name, throw, **args)
121
121
122 tag_disallowed = ':\r\n'
122 tag_disallowed = ':\r\n'
123
123
124 def _tag(self, names, node, message, local, user, date, parent=None,
124 def _tag(self, names, node, message, local, user, date, parent=None,
125 extra={}):
125 extra={}):
126 use_dirstate = parent is None
126 use_dirstate = parent is None
127
127
128 if isinstance(names, str):
128 if isinstance(names, str):
129 allchars = names
129 allchars = names
130 names = (names,)
130 names = (names,)
131 else:
131 else:
132 allchars = ''.join(names)
132 allchars = ''.join(names)
133 for c in self.tag_disallowed:
133 for c in self.tag_disallowed:
134 if c in allchars:
134 if c in allchars:
135 raise util.Abort(_('%r cannot be used in a tag name') % c)
135 raise util.Abort(_('%r cannot be used in a tag name') % c)
136
136
137 for name in names:
137 for name in names:
138 self.hook('pretag', throw=True, node=hex(node), tag=name,
138 self.hook('pretag', throw=True, node=hex(node), tag=name,
139 local=local)
139 local=local)
140
140
141 def writetags(fp, names, munge, prevtags):
141 def writetags(fp, names, munge, prevtags):
142 fp.seek(0, 2)
142 fp.seek(0, 2)
143 if prevtags and prevtags[-1] != '\n':
143 if prevtags and prevtags[-1] != '\n':
144 fp.write('\n')
144 fp.write('\n')
145 for name in names:
145 for name in names:
146 m = munge and munge(name) or name
146 m = munge and munge(name) or name
147 if self._tagstypecache and name in self._tagstypecache:
147 if self._tagstypecache and name in self._tagstypecache:
148 old = self.tagscache.get(name, nullid)
148 old = self.tagscache.get(name, nullid)
149 fp.write('%s %s\n' % (hex(old), m))
149 fp.write('%s %s\n' % (hex(old), m))
150 fp.write('%s %s\n' % (hex(node), m))
150 fp.write('%s %s\n' % (hex(node), m))
151 fp.close()
151 fp.close()
152
152
153 prevtags = ''
153 prevtags = ''
154 if local:
154 if local:
155 try:
155 try:
156 fp = self.opener('localtags', 'r+')
156 fp = self.opener('localtags', 'r+')
157 except IOError, err:
157 except IOError, err:
158 fp = self.opener('localtags', 'a')
158 fp = self.opener('localtags', 'a')
159 else:
159 else:
160 prevtags = fp.read()
160 prevtags = fp.read()
161
161
162 # local tags are stored in the current charset
162 # local tags are stored in the current charset
163 writetags(fp, names, None, prevtags)
163 writetags(fp, names, None, prevtags)
164 for name in names:
164 for name in names:
165 self.hook('tag', node=hex(node), tag=name, local=local)
165 self.hook('tag', node=hex(node), tag=name, local=local)
166 return
166 return
167
167
168 if use_dirstate:
168 if use_dirstate:
169 try:
169 try:
170 fp = self.wfile('.hgtags', 'rb+')
170 fp = self.wfile('.hgtags', 'rb+')
171 except IOError, err:
171 except IOError, err:
172 fp = self.wfile('.hgtags', 'ab')
172 fp = self.wfile('.hgtags', 'ab')
173 else:
173 else:
174 prevtags = fp.read()
174 prevtags = fp.read()
175 else:
175 else:
176 try:
176 try:
177 prevtags = self.filectx('.hgtags', parent).data()
177 prevtags = self.filectx('.hgtags', parent).data()
178 except revlog.LookupError:
178 except revlog.LookupError:
179 pass
179 pass
180 fp = self.wfile('.hgtags', 'wb')
180 fp = self.wfile('.hgtags', 'wb')
181 if prevtags:
181 if prevtags:
182 fp.write(prevtags)
182 fp.write(prevtags)
183
183
184 # committed tags are stored in UTF-8
184 # committed tags are stored in UTF-8
185 writetags(fp, names, util.fromlocal, prevtags)
185 writetags(fp, names, util.fromlocal, prevtags)
186
186
187 if use_dirstate and '.hgtags' not in self.dirstate:
187 if use_dirstate and '.hgtags' not in self.dirstate:
188 self.add(['.hgtags'])
188 self.add(['.hgtags'])
189
189
190 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent,
190 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent,
191 extra=extra)
191 extra=extra)
192
192
193 for name in names:
193 for name in names:
194 self.hook('tag', node=hex(node), tag=name, local=local)
194 self.hook('tag', node=hex(node), tag=name, local=local)
195
195
196 return tagnode
196 return tagnode
197
197
198 def tag(self, names, node, message, local, user, date):
198 def tag(self, names, node, message, local, user, date):
199 '''tag a revision with one or more symbolic names.
199 '''tag a revision with one or more symbolic names.
200
200
201 names is a list of strings or, when adding a single tag, names may be a
201 names is a list of strings or, when adding a single tag, names may be a
202 string.
202 string.
203
203
204 if local is True, the tags are stored in a per-repository file.
204 if local is True, the tags are stored in a per-repository file.
205 otherwise, they are stored in the .hgtags file, and a new
205 otherwise, they are stored in the .hgtags file, and a new
206 changeset is committed with the change.
206 changeset is committed with the change.
207
207
208 keyword arguments:
208 keyword arguments:
209
209
210 local: whether to store tags in non-version-controlled file
210 local: whether to store tags in non-version-controlled file
211 (default False)
211 (default False)
212
212
213 message: commit message to use if committing
213 message: commit message to use if committing
214
214
215 user: name of user to use if committing
215 user: name of user to use if committing
216
216
217 date: date tuple to use if committing'''
217 date: date tuple to use if committing'''
218
218
219 for x in self.status()[:5]:
219 for x in self.status()[:5]:
220 if '.hgtags' in x:
220 if '.hgtags' in x:
221 raise util.Abort(_('working copy of .hgtags is changed '
221 raise util.Abort(_('working copy of .hgtags is changed '
222 '(please commit .hgtags manually)'))
222 '(please commit .hgtags manually)'))
223
223
224 self._tag(names, node, message, local, user, date)
224 self._tag(names, node, message, local, user, date)
225
225
226 def tags(self):
226 def tags(self):
227 '''return a mapping of tag to node'''
227 '''return a mapping of tag to node'''
228 if self.tagscache:
228 if self.tagscache:
229 return self.tagscache
229 return self.tagscache
230
230
231 globaltags = {}
231 globaltags = {}
232 tagtypes = {}
232 tagtypes = {}
233
233
234 def readtags(lines, fn, tagtype):
234 def readtags(lines, fn, tagtype):
235 filetags = {}
235 filetags = {}
236 count = 0
236 count = 0
237
237
238 def warn(msg):
238 def warn(msg):
239 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg))
239 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg))
240
240
241 for l in lines:
241 for l in lines:
242 count += 1
242 count += 1
243 if not l:
243 if not l:
244 continue
244 continue
245 s = l.split(" ", 1)
245 s = l.split(" ", 1)
246 if len(s) != 2:
246 if len(s) != 2:
247 warn(_("cannot parse entry"))
247 warn(_("cannot parse entry"))
248 continue
248 continue
249 node, key = s
249 node, key = s
250 key = util.tolocal(key.strip()) # stored in UTF-8
250 key = util.tolocal(key.strip()) # stored in UTF-8
251 try:
251 try:
252 bin_n = bin(node)
252 bin_n = bin(node)
253 except TypeError:
253 except TypeError:
254 warn(_("node '%s' is not well formed") % node)
254 warn(_("node '%s' is not well formed") % node)
255 continue
255 continue
256 if bin_n not in self.changelog.nodemap:
256 if bin_n not in self.changelog.nodemap:
257 warn(_("tag '%s' refers to unknown node") % key)
257 warn(_("tag '%s' refers to unknown node") % key)
258 continue
258 continue
259
259
260 h = []
260 h = []
261 if key in filetags:
261 if key in filetags:
262 n, h = filetags[key]
262 n, h = filetags[key]
263 h.append(n)
263 h.append(n)
264 filetags[key] = (bin_n, h)
264 filetags[key] = (bin_n, h)
265
265
266 for k, nh in filetags.items():
266 for k, nh in filetags.items():
267 if k not in globaltags:
267 if k not in globaltags:
268 globaltags[k] = nh
268 globaltags[k] = nh
269 tagtypes[k] = tagtype
269 tagtypes[k] = tagtype
270 continue
270 continue
271
271
272 # we prefer the global tag if:
272 # we prefer the global tag if:
273 # it supercedes us OR
273 # it supercedes us OR
274 # mutual supercedes and it has a higher rank
274 # mutual supercedes and it has a higher rank
275 # otherwise we win because we're tip-most
275 # otherwise we win because we're tip-most
276 an, ah = nh
276 an, ah = nh
277 bn, bh = globaltags[k]
277 bn, bh = globaltags[k]
278 if (bn != an and an in bh and
278 if (bn != an and an in bh and
279 (bn not in ah or len(bh) > len(ah))):
279 (bn not in ah or len(bh) > len(ah))):
280 an = bn
280 an = bn
281 ah.extend([n for n in bh if n not in ah])
281 ah.extend([n for n in bh if n not in ah])
282 globaltags[k] = an, ah
282 globaltags[k] = an, ah
283 tagtypes[k] = tagtype
283 tagtypes[k] = tagtype
284
284
285 # read the tags file from each head, ending with the tip
285 # read the tags file from each head, ending with the tip
286 f = None
286 f = None
287 for rev, node, fnode in self._hgtagsnodes():
287 for rev, node, fnode in self._hgtagsnodes():
288 f = (f and f.filectx(fnode) or
288 f = (f and f.filectx(fnode) or
289 self.filectx('.hgtags', fileid=fnode))
289 self.filectx('.hgtags', fileid=fnode))
290 readtags(f.data().splitlines(), f, "global")
290 readtags(f.data().splitlines(), f, "global")
291
291
292 try:
292 try:
293 data = util.fromlocal(self.opener("localtags").read())
293 data = util.fromlocal(self.opener("localtags").read())
294 # localtags are stored in the local character set
294 # localtags are stored in the local character set
295 # while the internal tag table is stored in UTF-8
295 # while the internal tag table is stored in UTF-8
296 readtags(data.splitlines(), "localtags", "local")
296 readtags(data.splitlines(), "localtags", "local")
297 except IOError:
297 except IOError:
298 pass
298 pass
299
299
300 self.tagscache = {}
300 self.tagscache = {}
301 self._tagstypecache = {}
301 self._tagstypecache = {}
302 for k,nh in globaltags.items():
302 for k,nh in globaltags.items():
303 n = nh[0]
303 n = nh[0]
304 if n != nullid:
304 if n != nullid:
305 self.tagscache[k] = n
305 self.tagscache[k] = n
306 self._tagstypecache[k] = tagtypes[k]
306 self._tagstypecache[k] = tagtypes[k]
307 self.tagscache['tip'] = self.changelog.tip()
307 self.tagscache['tip'] = self.changelog.tip()
308 return self.tagscache
308 return self.tagscache
309
309
310 def tagtype(self, tagname):
310 def tagtype(self, tagname):
311 '''
311 '''
312 return the type of the given tag. result can be:
312 return the type of the given tag. result can be:
313
313
314 'local' : a local tag
314 'local' : a local tag
315 'global' : a global tag
315 'global' : a global tag
316 None : tag does not exist
316 None : tag does not exist
317 '''
317 '''
318
318
319 self.tags()
319 self.tags()
320
320
321 return self._tagstypecache.get(tagname)
321 return self._tagstypecache.get(tagname)
322
322
323 def _hgtagsnodes(self):
323 def _hgtagsnodes(self):
324 heads = self.heads()
324 heads = self.heads()
325 heads.reverse()
325 heads.reverse()
326 last = {}
326 last = {}
327 ret = []
327 ret = []
328 for node in heads:
328 for node in heads:
329 c = self[node]
329 c = self[node]
330 rev = c.rev()
330 rev = c.rev()
331 try:
331 try:
332 fnode = c.filenode('.hgtags')
332 fnode = c.filenode('.hgtags')
333 except revlog.LookupError:
333 except revlog.LookupError:
334 continue
334 continue
335 ret.append((rev, node, fnode))
335 ret.append((rev, node, fnode))
336 if fnode in last:
336 if fnode in last:
337 ret[last[fnode]] = None
337 ret[last[fnode]] = None
338 last[fnode] = len(ret) - 1
338 last[fnode] = len(ret) - 1
339 return [item for item in ret if item]
339 return [item for item in ret if item]
340
340
341 def tagslist(self):
341 def tagslist(self):
342 '''return a list of tags ordered by revision'''
342 '''return a list of tags ordered by revision'''
343 l = []
343 l = []
344 for t, n in self.tags().items():
344 for t, n in self.tags().items():
345 try:
345 try:
346 r = self.changelog.rev(n)
346 r = self.changelog.rev(n)
347 except:
347 except:
348 r = -2 # sort to the beginning of the list if unknown
348 r = -2 # sort to the beginning of the list if unknown
349 l.append((r, t, n))
349 l.append((r, t, n))
350 return [(t, n) for r, t, n in util.sort(l)]
350 return [(t, n) for r, t, n in util.sort(l)]
351
351
352 def nodetags(self, node):
352 def nodetags(self, node):
353 '''return the tags associated with a node'''
353 '''return the tags associated with a node'''
354 if not self.nodetagscache:
354 if not self.nodetagscache:
355 self.nodetagscache = {}
355 self.nodetagscache = {}
356 for t, n in self.tags().items():
356 for t, n in self.tags().items():
357 self.nodetagscache.setdefault(n, []).append(t)
357 self.nodetagscache.setdefault(n, []).append(t)
358 return self.nodetagscache.get(node, [])
358 return self.nodetagscache.get(node, [])
359
359
360 def _branchtags(self, partial, lrev):
360 def _branchtags(self, partial, lrev):
361 tiprev = len(self) - 1
361 tiprev = len(self) - 1
362 if lrev != tiprev:
362 if lrev != tiprev:
363 self._updatebranchcache(partial, lrev+1, tiprev+1)
363 self._updatebranchcache(partial, lrev+1, tiprev+1)
364 self._writebranchcache(partial, self.changelog.tip(), tiprev)
364 self._writebranchcache(partial, self.changelog.tip(), tiprev)
365
365
366 return partial
366 return partial
367
367
368 def branchtags(self):
368 def branchtags(self):
369 tip = self.changelog.tip()
369 tip = self.changelog.tip()
370 if self.branchcache is not None and self._branchcachetip == tip:
370 if self.branchcache is not None and self._branchcachetip == tip:
371 return self.branchcache
371 return self.branchcache
372
372
373 oldtip = self._branchcachetip
373 oldtip = self._branchcachetip
374 self._branchcachetip = tip
374 self._branchcachetip = tip
375 if self.branchcache is None:
375 if self.branchcache is None:
376 self.branchcache = {} # avoid recursion in changectx
376 self.branchcache = {} # avoid recursion in changectx
377 else:
377 else:
378 self.branchcache.clear() # keep using the same dict
378 self.branchcache.clear() # keep using the same dict
379 if oldtip is None or oldtip not in self.changelog.nodemap:
379 if oldtip is None or oldtip not in self.changelog.nodemap:
380 partial, last, lrev = self._readbranchcache()
380 partial, last, lrev = self._readbranchcache()
381 else:
381 else:
382 lrev = self.changelog.rev(oldtip)
382 lrev = self.changelog.rev(oldtip)
383 partial = self._ubranchcache
383 partial = self._ubranchcache
384
384
385 self._branchtags(partial, lrev)
385 self._branchtags(partial, lrev)
386
386
387 # the branch cache is stored on disk as UTF-8, but in the local
387 # the branch cache is stored on disk as UTF-8, but in the local
388 # charset internally
388 # charset internally
389 for k, v in partial.items():
389 for k, v in partial.items():
390 self.branchcache[util.tolocal(k)] = v
390 self.branchcache[util.tolocal(k)] = v
391 self._ubranchcache = partial
391 self._ubranchcache = partial
392 return self.branchcache
392 return self.branchcache
393
393
394 def _readbranchcache(self):
394 def _readbranchcache(self):
395 partial = {}
395 partial = {}
396 try:
396 try:
397 f = self.opener("branch.cache")
397 f = self.opener("branch.cache")
398 lines = f.read().split('\n')
398 lines = f.read().split('\n')
399 f.close()
399 f.close()
400 except (IOError, OSError):
400 except (IOError, OSError):
401 return {}, nullid, nullrev
401 return {}, nullid, nullrev
402
402
403 try:
403 try:
404 last, lrev = lines.pop(0).split(" ", 1)
404 last, lrev = lines.pop(0).split(" ", 1)
405 last, lrev = bin(last), int(lrev)
405 last, lrev = bin(last), int(lrev)
406 if lrev >= len(self) or self[lrev].node() != last:
406 if lrev >= len(self) or self[lrev].node() != last:
407 # invalidate the cache
407 # invalidate the cache
408 raise ValueError('invalidating branch cache (tip differs)')
408 raise ValueError('invalidating branch cache (tip differs)')
409 for l in lines:
409 for l in lines:
410 if not l: continue
410 if not l: continue
411 node, label = l.split(" ", 1)
411 node, label = l.split(" ", 1)
412 partial[label.strip()] = bin(node)
412 partial[label.strip()] = bin(node)
413 except (KeyboardInterrupt, util.SignalInterrupt):
413 except (KeyboardInterrupt, util.SignalInterrupt):
414 raise
414 raise
415 except Exception, inst:
415 except Exception, inst:
416 if self.ui.debugflag:
416 if self.ui.debugflag:
417 self.ui.warn(str(inst), '\n')
417 self.ui.warn(str(inst), '\n')
418 partial, last, lrev = {}, nullid, nullrev
418 partial, last, lrev = {}, nullid, nullrev
419 return partial, last, lrev
419 return partial, last, lrev
420
420
421 def _writebranchcache(self, branches, tip, tiprev):
421 def _writebranchcache(self, branches, tip, tiprev):
422 try:
422 try:
423 f = self.opener("branch.cache", "w", atomictemp=True)
423 f = self.opener("branch.cache", "w", atomictemp=True)
424 f.write("%s %s\n" % (hex(tip), tiprev))
424 f.write("%s %s\n" % (hex(tip), tiprev))
425 for label, node in branches.iteritems():
425 for label, node in branches.iteritems():
426 f.write("%s %s\n" % (hex(node), label))
426 f.write("%s %s\n" % (hex(node), label))
427 f.rename()
427 f.rename()
428 except (IOError, OSError):
428 except (IOError, OSError):
429 pass
429 pass
430
430
431 def _updatebranchcache(self, partial, start, end):
431 def _updatebranchcache(self, partial, start, end):
432 for r in xrange(start, end):
432 for r in xrange(start, end):
433 c = self[r]
433 c = self[r]
434 b = c.branch()
434 b = c.branch()
435 partial[b] = c.node()
435 partial[b] = c.node()
436
436
437 def lookup(self, key):
437 def lookup(self, key):
438 if key == '.':
438 if key == '.':
439 return self.dirstate.parents()[0]
439 return self.dirstate.parents()[0]
440 elif key == 'null':
440 elif key == 'null':
441 return nullid
441 return nullid
442 n = self.changelog._match(key)
442 n = self.changelog._match(key)
443 if n:
443 if n:
444 return n
444 return n
445 if key in self.tags():
445 if key in self.tags():
446 return self.tags()[key]
446 return self.tags()[key]
447 if key in self.branchtags():
447 if key in self.branchtags():
448 return self.branchtags()[key]
448 return self.branchtags()[key]
449 n = self.changelog._partialmatch(key)
449 n = self.changelog._partialmatch(key)
450 if n:
450 if n:
451 return n
451 return n
452 try:
452 try:
453 if len(key) == 20:
453 if len(key) == 20:
454 key = hex(key)
454 key = hex(key)
455 except:
455 except:
456 pass
456 pass
457 raise repo.RepoError(_("unknown revision '%s'") % key)
457 raise repo.RepoError(_("unknown revision '%s'") % key)
458
458
459 def local(self):
459 def local(self):
460 return True
460 return True
461
461
462 def join(self, f):
462 def join(self, f):
463 return os.path.join(self.path, f)
463 return os.path.join(self.path, f)
464
464
465 def wjoin(self, f):
465 def wjoin(self, f):
466 return os.path.join(self.root, f)
466 return os.path.join(self.root, f)
467
467
468 def rjoin(self, f):
468 def rjoin(self, f):
469 return os.path.join(self.root, util.pconvert(f))
469 return os.path.join(self.root, util.pconvert(f))
470
470
471 def file(self, f):
471 def file(self, f):
472 if f[0] == '/':
472 if f[0] == '/':
473 f = f[1:]
473 f = f[1:]
474 return filelog.filelog(self.sopener, f)
474 return filelog.filelog(self.sopener, f)
475
475
476 def changectx(self, changeid):
476 def changectx(self, changeid):
477 return self[changeid]
477 return self[changeid]
478
478
479 def parents(self, changeid=None):
479 def parents(self, changeid=None):
480 '''get list of changectxs for parents of changeid'''
480 '''get list of changectxs for parents of changeid'''
481 return self[changeid].parents()
481 return self[changeid].parents()
482
482
483 def filectx(self, path, changeid=None, fileid=None):
483 def filectx(self, path, changeid=None, fileid=None):
484 """changeid can be a changeset revision, node, or tag.
484 """changeid can be a changeset revision, node, or tag.
485 fileid can be a file revision or node."""
485 fileid can be a file revision or node."""
486 return context.filectx(self, path, changeid, fileid)
486 return context.filectx(self, path, changeid, fileid)
487
487
488 def getcwd(self):
488 def getcwd(self):
489 return self.dirstate.getcwd()
489 return self.dirstate.getcwd()
490
490
491 def pathto(self, f, cwd=None):
491 def pathto(self, f, cwd=None):
492 return self.dirstate.pathto(f, cwd)
492 return self.dirstate.pathto(f, cwd)
493
493
494 def wfile(self, f, mode='r'):
494 def wfile(self, f, mode='r'):
495 return self.wopener(f, mode)
495 return self.wopener(f, mode)
496
496
497 def _link(self, f):
497 def _link(self, f):
498 return os.path.islink(self.wjoin(f))
498 return os.path.islink(self.wjoin(f))
499
499
500 def _filter(self, filter, filename, data):
500 def _filter(self, filter, filename, data):
501 if filter not in self.filterpats:
501 if filter not in self.filterpats:
502 l = []
502 l = []
503 for pat, cmd in self.ui.configitems(filter):
503 for pat, cmd in self.ui.configitems(filter):
504 mf = util.matcher(self.root, "", [pat], [], [])[1]
504 mf = util.matcher(self.root, "", [pat], [], [])[1]
505 fn = None
505 fn = None
506 params = cmd
506 params = cmd
507 for name, filterfn in self._datafilters.iteritems():
507 for name, filterfn in self._datafilters.iteritems():
508 if cmd.startswith(name):
508 if cmd.startswith(name):
509 fn = filterfn
509 fn = filterfn
510 params = cmd[len(name):].lstrip()
510 params = cmd[len(name):].lstrip()
511 break
511 break
512 if not fn:
512 if not fn:
513 fn = lambda s, c, **kwargs: util.filter(s, c)
513 fn = lambda s, c, **kwargs: util.filter(s, c)
514 # Wrap old filters not supporting keyword arguments
514 # Wrap old filters not supporting keyword arguments
515 if not inspect.getargspec(fn)[2]:
515 if not inspect.getargspec(fn)[2]:
516 oldfn = fn
516 oldfn = fn
517 fn = lambda s, c, **kwargs: oldfn(s, c)
517 fn = lambda s, c, **kwargs: oldfn(s, c)
518 l.append((mf, fn, params))
518 l.append((mf, fn, params))
519 self.filterpats[filter] = l
519 self.filterpats[filter] = l
520
520
521 for mf, fn, cmd in self.filterpats[filter]:
521 for mf, fn, cmd in self.filterpats[filter]:
522 if mf(filename):
522 if mf(filename):
523 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
523 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
524 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
524 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
525 break
525 break
526
526
527 return data
527 return data
528
528
529 def adddatafilter(self, name, filter):
529 def adddatafilter(self, name, filter):
530 self._datafilters[name] = filter
530 self._datafilters[name] = filter
531
531
532 def wread(self, filename):
532 def wread(self, filename):
533 if self._link(filename):
533 if self._link(filename):
534 data = os.readlink(self.wjoin(filename))
534 data = os.readlink(self.wjoin(filename))
535 else:
535 else:
536 data = self.wopener(filename, 'r').read()
536 data = self.wopener(filename, 'r').read()
537 return self._filter("encode", filename, data)
537 return self._filter("encode", filename, data)
538
538
539 def wwrite(self, filename, data, flags):
539 def wwrite(self, filename, data, flags):
540 data = self._filter("decode", filename, data)
540 data = self._filter("decode", filename, data)
541 try:
541 try:
542 os.unlink(self.wjoin(filename))
542 os.unlink(self.wjoin(filename))
543 except OSError:
543 except OSError:
544 pass
544 pass
545 if 'l' in flags:
545 if 'l' in flags:
546 self.wopener.symlink(data, filename)
546 self.wopener.symlink(data, filename)
547 else:
547 else:
548 self.wopener(filename, 'w').write(data)
548 self.wopener(filename, 'w').write(data)
549 if 'x' in flags:
549 if 'x' in flags:
550 util.set_flags(self.wjoin(filename), False, True)
550 util.set_flags(self.wjoin(filename), False, True)
551
551
552 def wwritedata(self, filename, data):
552 def wwritedata(self, filename, data):
553 return self._filter("decode", filename, data)
553 return self._filter("decode", filename, data)
554
554
555 def transaction(self):
555 def transaction(self):
556 if self._transref and self._transref():
556 if self._transref and self._transref():
557 return self._transref().nest()
557 return self._transref().nest()
558
558
559 # abort here if the journal already exists
559 # abort here if the journal already exists
560 if os.path.exists(self.sjoin("journal")):
560 if os.path.exists(self.sjoin("journal")):
561 raise repo.RepoError(_("journal already exists - run hg recover"))
561 raise repo.RepoError(_("journal already exists - run hg recover"))
562
562
563 # save dirstate for rollback
563 # save dirstate for rollback
564 try:
564 try:
565 ds = self.opener("dirstate").read()
565 ds = self.opener("dirstate").read()
566 except IOError:
566 except IOError:
567 ds = ""
567 ds = ""
568 self.opener("journal.dirstate", "w").write(ds)
568 self.opener("journal.dirstate", "w").write(ds)
569 self.opener("journal.branch", "w").write(self.dirstate.branch())
569 self.opener("journal.branch", "w").write(self.dirstate.branch())
570
570
571 renames = [(self.sjoin("journal"), self.sjoin("undo")),
571 renames = [(self.sjoin("journal"), self.sjoin("undo")),
572 (self.join("journal.dirstate"), self.join("undo.dirstate")),
572 (self.join("journal.dirstate"), self.join("undo.dirstate")),
573 (self.join("journal.branch"), self.join("undo.branch"))]
573 (self.join("journal.branch"), self.join("undo.branch"))]
574 tr = transaction.transaction(self.ui.warn, self.sopener,
574 tr = transaction.transaction(self.ui.warn, self.sopener,
575 self.sjoin("journal"),
575 self.sjoin("journal"),
576 aftertrans(renames),
576 aftertrans(renames),
577 self.store.createmode)
577 self.store.createmode)
578 self._transref = weakref.ref(tr)
578 self._transref = weakref.ref(tr)
579 return tr
579 return tr
580
580
581 def recover(self):
581 def recover(self):
582 l = self.lock()
582 l = self.lock()
583 try:
583 try:
584 if os.path.exists(self.sjoin("journal")):
584 if os.path.exists(self.sjoin("journal")):
585 self.ui.status(_("rolling back interrupted transaction\n"))
585 self.ui.status(_("rolling back interrupted transaction\n"))
586 transaction.rollback(self.sopener, self.sjoin("journal"))
586 transaction.rollback(self.sopener, self.sjoin("journal"))
587 self.invalidate()
587 self.invalidate()
588 return True
588 return True
589 else:
589 else:
590 self.ui.warn(_("no interrupted transaction available\n"))
590 self.ui.warn(_("no interrupted transaction available\n"))
591 return False
591 return False
592 finally:
592 finally:
593 del l
593 del l
594
594
595 def rollback(self):
595 def rollback(self):
596 wlock = lock = None
596 wlock = lock = None
597 try:
597 try:
598 wlock = self.wlock()
598 wlock = self.wlock()
599 lock = self.lock()
599 lock = self.lock()
600 if os.path.exists(self.sjoin("undo")):
600 if os.path.exists(self.sjoin("undo")):
601 self.ui.status(_("rolling back last transaction\n"))
601 self.ui.status(_("rolling back last transaction\n"))
602 transaction.rollback(self.sopener, self.sjoin("undo"))
602 transaction.rollback(self.sopener, self.sjoin("undo"))
603 util.rename(self.join("undo.dirstate"), self.join("dirstate"))
603 util.rename(self.join("undo.dirstate"), self.join("dirstate"))
604 try:
604 try:
605 branch = self.opener("undo.branch").read()
605 branch = self.opener("undo.branch").read()
606 self.dirstate.setbranch(branch)
606 self.dirstate.setbranch(branch)
607 except IOError:
607 except IOError:
608 self.ui.warn(_("Named branch could not be reset, "
608 self.ui.warn(_("Named branch could not be reset, "
609 "current branch still is: %s\n")
609 "current branch still is: %s\n")
610 % util.tolocal(self.dirstate.branch()))
610 % util.tolocal(self.dirstate.branch()))
611 self.invalidate()
611 self.invalidate()
612 self.dirstate.invalidate()
612 self.dirstate.invalidate()
613 else:
613 else:
614 self.ui.warn(_("no rollback information available\n"))
614 self.ui.warn(_("no rollback information available\n"))
615 finally:
615 finally:
616 del lock, wlock
616 del lock, wlock
617
617
618 def invalidate(self):
618 def invalidate(self):
619 for a in "changelog manifest".split():
619 for a in "changelog manifest".split():
620 if a in self.__dict__:
620 if a in self.__dict__:
621 delattr(self, a)
621 delattr(self, a)
622 self.tagscache = None
622 self.tagscache = None
623 self._tagstypecache = None
623 self._tagstypecache = None
624 self.nodetagscache = None
624 self.nodetagscache = None
625 self.branchcache = None
625 self.branchcache = None
626 self._ubranchcache = None
626 self._ubranchcache = None
627 self._branchcachetip = None
627 self._branchcachetip = None
628
628
629 def _lock(self, lockname, wait, releasefn, acquirefn, desc):
629 def _lock(self, lockname, wait, releasefn, acquirefn, desc):
630 try:
630 try:
631 l = lock.lock(lockname, 0, releasefn, desc=desc)
631 l = lock.lock(lockname, 0, releasefn, desc=desc)
632 except lock.LockHeld, inst:
632 except lock.LockHeld, inst:
633 if not wait:
633 if not wait:
634 raise
634 raise
635 self.ui.warn(_("waiting for lock on %s held by %r\n") %
635 self.ui.warn(_("waiting for lock on %s held by %r\n") %
636 (desc, inst.locker))
636 (desc, inst.locker))
637 # default to 600 seconds timeout
637 # default to 600 seconds timeout
638 l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")),
638 l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")),
639 releasefn, desc=desc)
639 releasefn, desc=desc)
640 if acquirefn:
640 if acquirefn:
641 acquirefn()
641 acquirefn()
642 return l
642 return l
643
643
644 def lock(self, wait=True):
644 def lock(self, wait=True):
645 if self._lockref and self._lockref():
645 if self._lockref and self._lockref():
646 return self._lockref()
646 return self._lockref()
647
647
648 l = self._lock(self.sjoin("lock"), wait, None, self.invalidate,
648 l = self._lock(self.sjoin("lock"), wait, None, self.invalidate,
649 _('repository %s') % self.origroot)
649 _('repository %s') % self.origroot)
650 self._lockref = weakref.ref(l)
650 self._lockref = weakref.ref(l)
651 return l
651 return l
652
652
653 def wlock(self, wait=True):
653 def wlock(self, wait=True):
654 if self._wlockref and self._wlockref():
654 if self._wlockref and self._wlockref():
655 return self._wlockref()
655 return self._wlockref()
656
656
657 l = self._lock(self.join("wlock"), wait, self.dirstate.write,
657 l = self._lock(self.join("wlock"), wait, self.dirstate.write,
658 self.dirstate.invalidate, _('working directory of %s') %
658 self.dirstate.invalidate, _('working directory of %s') %
659 self.origroot)
659 self.origroot)
660 self._wlockref = weakref.ref(l)
660 self._wlockref = weakref.ref(l)
661 return l
661 return l
662
662
663 def filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
663 def filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
664 """
664 """
665 commit an individual file as part of a larger transaction
665 commit an individual file as part of a larger transaction
666 """
666 """
667
667
668 fn = fctx.path()
668 fn = fctx.path()
669 t = fctx.data()
669 t = fctx.data()
670 fl = self.file(fn)
670 fl = self.file(fn)
671 fp1 = manifest1.get(fn, nullid)
671 fp1 = manifest1.get(fn, nullid)
672 fp2 = manifest2.get(fn, nullid)
672 fp2 = manifest2.get(fn, nullid)
673
673
674 meta = {}
674 meta = {}
675 cp = fctx.renamed()
675 cp = fctx.renamed()
676 if cp and cp[0] != fn:
676 if cp and cp[0] != fn:
677 # Mark the new revision of this file as a copy of another
677 # Mark the new revision of this file as a copy of another
678 # file. This copy data will effectively act as a parent
678 # file. This copy data will effectively act as a parent
679 # of this new revision. If this is a merge, the first
679 # of this new revision. If this is a merge, the first
680 # parent will be the nullid (meaning "look up the copy data")
680 # parent will be the nullid (meaning "look up the copy data")
681 # and the second one will be the other parent. For example:
681 # and the second one will be the other parent. For example:
682 #
682 #
683 # 0 --- 1 --- 3 rev1 changes file foo
683 # 0 --- 1 --- 3 rev1 changes file foo
684 # \ / rev2 renames foo to bar and changes it
684 # \ / rev2 renames foo to bar and changes it
685 # \- 2 -/ rev3 should have bar with all changes and
685 # \- 2 -/ rev3 should have bar with all changes and
686 # should record that bar descends from
686 # should record that bar descends from
687 # bar in rev2 and foo in rev1
687 # bar in rev2 and foo in rev1
688 #
688 #
689 # this allows this merge to succeed:
689 # this allows this merge to succeed:
690 #
690 #
691 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
691 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
692 # \ / merging rev3 and rev4 should use bar@rev2
692 # \ / merging rev3 and rev4 should use bar@rev2
693 # \- 2 --- 4 as the merge base
693 # \- 2 --- 4 as the merge base
694 #
694 #
695
695
696 cf = cp[0]
696 cf = cp[0]
697 cr = manifest1.get(cf)
697 cr = manifest1.get(cf)
698 nfp = fp2
698 nfp = fp2
699
699
700 if manifest2: # branch merge
700 if manifest2: # branch merge
701 if fp2 == nullid: # copied on remote side
701 if fp2 == nullid: # copied on remote side
702 if fp1 != nullid or cf in manifest2:
702 if fp1 != nullid or cf in manifest2:
703 cr = manifest2[cf]
703 cr = manifest2[cf]
704 nfp = fp1
704 nfp = fp1
705
705
706 # find source in nearest ancestor if we've lost track
706 # find source in nearest ancestor if we've lost track
707 if not cr:
707 if not cr:
708 self.ui.debug(_(" %s: searching for copy revision for %s\n") %
708 self.ui.debug(_(" %s: searching for copy revision for %s\n") %
709 (fn, cf))
709 (fn, cf))
710 for a in self['.'].ancestors():
710 for a in self['.'].ancestors():
711 if cf in a:
711 if cf in a:
712 cr = a[cf].filenode()
712 cr = a[cf].filenode()
713 break
713 break
714
714
715 self.ui.debug(_(" %s: copy %s:%s\n") % (fn, cf, hex(cr)))
715 self.ui.debug(_(" %s: copy %s:%s\n") % (fn, cf, hex(cr)))
716 meta["copy"] = cf
716 meta["copy"] = cf
717 meta["copyrev"] = hex(cr)
717 meta["copyrev"] = hex(cr)
718 fp1, fp2 = nullid, nfp
718 fp1, fp2 = nullid, nfp
719 elif fp2 != nullid:
719 elif fp2 != nullid:
720 # is one parent an ancestor of the other?
720 # is one parent an ancestor of the other?
721 fpa = fl.ancestor(fp1, fp2)
721 fpa = fl.ancestor(fp1, fp2)
722 if fpa == fp1:
722 if fpa == fp1:
723 fp1, fp2 = fp2, nullid
723 fp1, fp2 = fp2, nullid
724 elif fpa == fp2:
724 elif fpa == fp2:
725 fp2 = nullid
725 fp2 = nullid
726
726
727 # is the file unmodified from the parent? report existing entry
727 # is the file unmodified from the parent? report existing entry
728 if fp2 == nullid and not fl.cmp(fp1, t) and not meta:
728 if fp2 == nullid and not fl.cmp(fp1, t) and not meta:
729 return fp1
729 return fp1
730
730
731 changelist.append(fn)
731 changelist.append(fn)
732 return fl.add(t, meta, tr, linkrev, fp1, fp2)
732 return fl.add(t, meta, tr, linkrev, fp1, fp2)
733
733
734 def rawcommit(self, files, text, user, date, p1=None, p2=None, extra={}):
734 def rawcommit(self, files, text, user, date, p1=None, p2=None, extra={}):
735 if p1 is None:
735 if p1 is None:
736 p1, p2 = self.dirstate.parents()
736 p1, p2 = self.dirstate.parents()
737 return self.commit(files=files, text=text, user=user, date=date,
737 return self.commit(files=files, text=text, user=user, date=date,
738 p1=p1, p2=p2, extra=extra, empty_ok=True)
738 p1=p1, p2=p2, extra=extra, empty_ok=True)
739
739
740 def commit(self, files=None, text="", user=None, date=None,
740 def commit(self, files=None, text="", user=None, date=None,
741 match=None, force=False, force_editor=False,
741 match=None, force=False, force_editor=False,
742 p1=None, p2=None, extra={}, empty_ok=False):
742 p1=None, p2=None, extra={}, empty_ok=False):
743 wlock = lock = None
743 wlock = lock = None
744 if files:
744 if files:
745 files = util.unique(files)
745 files = util.unique(files)
746 try:
746 try:
747 wlock = self.wlock()
747 wlock = self.wlock()
748 lock = self.lock()
748 lock = self.lock()
749 use_dirstate = (p1 is None) # not rawcommit
749 use_dirstate = (p1 is None) # not rawcommit
750
750
751 if use_dirstate:
751 if use_dirstate:
752 p1, p2 = self.dirstate.parents()
752 p1, p2 = self.dirstate.parents()
753 update_dirstate = True
753 update_dirstate = True
754
754
755 if (not force and p2 != nullid and
755 if (not force and p2 != nullid and
756 (match and (match.files() or match.anypats()))):
756 (match and (match.files() or match.anypats()))):
757 raise util.Abort(_('cannot partially commit a merge '
757 raise util.Abort(_('cannot partially commit a merge '
758 '(do not specify files or patterns)'))
758 '(do not specify files or patterns)'))
759
759
760 if files:
760 if files:
761 modified, removed = [], []
761 modified, removed = [], []
762 for f in files:
762 for f in files:
763 s = self.dirstate[f]
763 s = self.dirstate[f]
764 if s in 'nma':
764 if s in 'nma':
765 modified.append(f)
765 modified.append(f)
766 elif s == 'r':
766 elif s == 'r':
767 removed.append(f)
767 removed.append(f)
768 else:
768 else:
769 self.ui.warn(_("%s not tracked!\n") % f)
769 self.ui.warn(_("%s not tracked!\n") % f)
770 changes = [modified, [], removed, [], []]
770 changes = [modified, [], removed, [], []]
771 else:
771 else:
772 changes = self.status(match=match)
772 changes = self.status(match=match)
773 else:
773 else:
774 p1, p2 = p1, p2 or nullid
774 p1, p2 = p1, p2 or nullid
775 update_dirstate = (self.dirstate.parents()[0] == p1)
775 update_dirstate = (self.dirstate.parents()[0] == p1)
776 changes = [files, [], [], [], []]
776 changes = [files, [], [], [], []]
777
777
778 ms = merge_.mergestate(self)
778 ms = merge_.mergestate(self)
779 for f in changes[0]:
779 for f in changes[0]:
780 if f in ms and ms[f] == 'u':
780 if f in ms and ms[f] == 'u':
781 raise util.Abort(_("unresolved merge conflicts "
781 raise util.Abort(_("unresolved merge conflicts "
782 "(see hg resolve)"))
782 "(see hg resolve)"))
783 wctx = context.workingctx(self, (p1, p2), text, user, date,
783 wctx = context.workingctx(self, (p1, p2), text, user, date,
784 extra, changes)
784 extra, changes)
785 return self._commitctx(wctx, force, force_editor, empty_ok,
785 return self._commitctx(wctx, force, force_editor, empty_ok,
786 use_dirstate, update_dirstate)
786 use_dirstate, update_dirstate)
787 finally:
787 finally:
788 del lock, wlock
788 del lock, wlock
789
789
790 def commitctx(self, ctx):
790 def commitctx(self, ctx):
791 wlock = lock = None
791 wlock = lock = None
792 try:
792 try:
793 wlock = self.wlock()
793 wlock = self.wlock()
794 lock = self.lock()
794 lock = self.lock()
795 return self._commitctx(ctx, force=True, force_editor=False,
795 return self._commitctx(ctx, force=True, force_editor=False,
796 empty_ok=True, use_dirstate=False,
796 empty_ok=True, use_dirstate=False,
797 update_dirstate=False)
797 update_dirstate=False)
798 finally:
798 finally:
799 del lock, wlock
799 del lock, wlock
800
800
801 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
801 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
802 use_dirstate=True, update_dirstate=True):
802 use_dirstate=True, update_dirstate=True):
803 tr = None
803 tr = None
804 valid = 0 # don't save the dirstate if this isn't set
804 valid = 0 # don't save the dirstate if this isn't set
805 try:
805 try:
806 commit = util.sort(wctx.modified() + wctx.added())
806 commit = util.sort(wctx.modified() + wctx.added())
807 remove = wctx.removed()
807 remove = wctx.removed()
808 extra = wctx.extra().copy()
808 extra = wctx.extra().copy()
809 branchname = extra['branch']
809 branchname = extra['branch']
810 user = wctx.user()
810 user = wctx.user()
811 text = wctx.description()
811 text = wctx.description()
812
812
813 p1, p2 = [p.node() for p in wctx.parents()]
813 p1, p2 = [p.node() for p in wctx.parents()]
814 c1 = self.changelog.read(p1)
814 c1 = self.changelog.read(p1)
815 c2 = self.changelog.read(p2)
815 c2 = self.changelog.read(p2)
816 m1 = self.manifest.read(c1[0]).copy()
816 m1 = self.manifest.read(c1[0]).copy()
817 m2 = self.manifest.read(c2[0])
817 m2 = self.manifest.read(c2[0])
818
818
819 if use_dirstate:
819 if use_dirstate:
820 oldname = c1[5].get("branch") # stored in UTF-8
820 oldname = c1[5].get("branch") # stored in UTF-8
821 if (not commit and not remove and not force and p2 == nullid
821 if (not commit and not remove and not force and p2 == nullid
822 and branchname == oldname):
822 and branchname == oldname):
823 self.ui.status(_("nothing changed\n"))
823 self.ui.status(_("nothing changed\n"))
824 return None
824 return None
825
825
826 xp1 = hex(p1)
826 xp1 = hex(p1)
827 if p2 == nullid: xp2 = ''
827 if p2 == nullid: xp2 = ''
828 else: xp2 = hex(p2)
828 else: xp2 = hex(p2)
829
829
830 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
830 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
831
831
832 tr = self.transaction()
832 tr = self.transaction()
833 trp = weakref.proxy(tr)
833 trp = weakref.proxy(tr)
834
834
835 # check in files
835 # check in files
836 new = {}
836 new = {}
837 changed = []
837 changed = []
838 linkrev = len(self)
838 linkrev = len(self)
839 for f in commit:
839 for f in commit:
840 self.ui.note(f + "\n")
840 self.ui.note(f + "\n")
841 try:
841 try:
842 fctx = wctx.filectx(f)
842 fctx = wctx.filectx(f)
843 newflags = fctx.flags()
843 newflags = fctx.flags()
844 new[f] = self.filecommit(fctx, m1, m2, linkrev, trp, changed)
844 new[f] = self.filecommit(fctx, m1, m2, linkrev, trp, changed)
845 if ((not changed or changed[-1] != f) and
845 if ((not changed or changed[-1] != f) and
846 m2.get(f) != new[f]):
846 m2.get(f) != new[f]):
847 # mention the file in the changelog if some
847 # mention the file in the changelog if some
848 # flag changed, even if there was no content
848 # flag changed, even if there was no content
849 # change.
849 # change.
850 if m1.flags(f) != newflags:
850 if m1.flags(f) != newflags:
851 changed.append(f)
851 changed.append(f)
852 m1.set(f, newflags)
852 m1.set(f, newflags)
853 if use_dirstate:
853 if use_dirstate:
854 self.dirstate.normal(f)
854 self.dirstate.normal(f)
855
855
856 except (OSError, IOError):
856 except (OSError, IOError):
857 if use_dirstate:
857 if use_dirstate:
858 self.ui.warn(_("trouble committing %s!\n") % f)
858 self.ui.warn(_("trouble committing %s!\n") % f)
859 raise
859 raise
860 else:
860 else:
861 remove.append(f)
861 remove.append(f)
862
862
863 # update manifest
863 # update manifest
864 m1.update(new)
864 m1.update(new)
865 removed = []
865 removed = []
866
866
867 for f in util.sort(remove):
867 for f in util.sort(remove):
868 if f in m1:
868 if f in m1:
869 del m1[f]
869 del m1[f]
870 removed.append(f)
870 removed.append(f)
871 elif f in m2:
871 elif f in m2:
872 removed.append(f)
872 removed.append(f)
873 mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0],
873 mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0],
874 (new, removed))
874 (new, removed))
875
875
876 # add changeset
876 # add changeset
877 if (not empty_ok and not text) or force_editor:
877 if (not empty_ok and not text) or force_editor:
878 edittext = []
878 edittext = []
879 if text:
879 if text:
880 edittext.append(text)
880 edittext.append(text)
881 edittext.append("")
881 edittext.append("")
882 edittext.append("") # Empty line between message and comments.
882 edittext.append("") # Empty line between message and comments.
883 edittext.append(_("HG: Enter commit message."
883 edittext.append(_("HG: Enter commit message."
884 " Lines beginning with 'HG:' are removed."))
884 " Lines beginning with 'HG:' are removed."))
885 edittext.append("HG: --")
885 edittext.append("HG: --")
886 edittext.append("HG: user: %s" % user)
886 edittext.append("HG: user: %s" % user)
887 if p2 != nullid:
887 if p2 != nullid:
888 edittext.append("HG: branch merge")
888 edittext.append("HG: branch merge")
889 if branchname:
889 if branchname:
890 edittext.append("HG: branch '%s'" % util.tolocal(branchname))
890 edittext.append("HG: branch '%s'" % util.tolocal(branchname))
891 edittext.extend(["HG: changed %s" % f for f in changed])
891 edittext.extend(["HG: changed %s" % f for f in changed])
892 edittext.extend(["HG: removed %s" % f for f in removed])
892 edittext.extend(["HG: removed %s" % f for f in removed])
893 if not changed and not remove:
893 if not changed and not remove:
894 edittext.append("HG: no files changed")
894 edittext.append("HG: no files changed")
895 edittext.append("")
895 edittext.append("")
896 # run editor in the repository root
896 # run editor in the repository root
897 olddir = os.getcwd()
897 olddir = os.getcwd()
898 os.chdir(self.root)
898 os.chdir(self.root)
899 text = self.ui.edit("\n".join(edittext), user)
899 text = self.ui.edit("\n".join(edittext), user)
900 os.chdir(olddir)
900 os.chdir(olddir)
901
901
902 lines = [line.rstrip() for line in text.rstrip().splitlines()]
902 lines = [line.rstrip() for line in text.rstrip().splitlines()]
903 while lines and not lines[0]:
903 while lines and not lines[0]:
904 del lines[0]
904 del lines[0]
905 if not lines and use_dirstate:
905 if not lines and use_dirstate:
906 raise util.Abort(_("empty commit message"))
906 raise util.Abort(_("empty commit message"))
907 text = '\n'.join(lines)
907 text = '\n'.join(lines)
908
908
909 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
909 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
910 user, wctx.date(), extra)
910 user, wctx.date(), extra)
911 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
911 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
912 parent2=xp2)
912 parent2=xp2)
913 tr.close()
913 tr.close()
914
914
915 if self.branchcache:
915 if self.branchcache:
916 self.branchtags()
916 self.branchtags()
917
917
918 if use_dirstate or update_dirstate:
918 if use_dirstate or update_dirstate:
919 self.dirstate.setparents(n)
919 self.dirstate.setparents(n)
920 if use_dirstate:
920 if use_dirstate:
921 for f in removed:
921 for f in removed:
922 self.dirstate.forget(f)
922 self.dirstate.forget(f)
923 valid = 1 # our dirstate updates are complete
923 valid = 1 # our dirstate updates are complete
924
924
925 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
925 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
926 return n
926 return n
927 finally:
927 finally:
928 if not valid: # don't save our updated dirstate
928 if not valid: # don't save our updated dirstate
929 self.dirstate.invalidate()
929 self.dirstate.invalidate()
930 del tr
930 del tr
931
931
932 def walk(self, match, node=None):
932 def walk(self, match, node=None):
933 '''
933 '''
934 walk recursively through the directory tree or a given
934 walk recursively through the directory tree or a given
935 changeset, finding all files matched by the match
935 changeset, finding all files matched by the match
936 function
936 function
937 '''
937 '''
938 return self[node].walk(match)
938 return self[node].walk(match)
939
939
940 def status(self, node1='.', node2=None, match=None,
940 def status(self, node1='.', node2=None, match=None,
941 ignored=False, clean=False, unknown=False):
941 ignored=False, clean=False, unknown=False):
942 """return status of files between two nodes or node and working directory
942 """return status of files between two nodes or node and working directory
943
943
944 If node1 is None, use the first dirstate parent instead.
944 If node1 is None, use the first dirstate parent instead.
945 If node2 is None, compare node1 with working directory.
945 If node2 is None, compare node1 with working directory.
946 """
946 """
947
947
948 def mfmatches(ctx):
948 def mfmatches(ctx):
949 mf = ctx.manifest().copy()
949 mf = ctx.manifest().copy()
950 for fn in mf.keys():
950 for fn in mf.keys():
951 if not match(fn):
951 if not match(fn):
952 del mf[fn]
952 del mf[fn]
953 return mf
953 return mf
954
954
955 ctx1 = self[node1]
955 ctx1 = self[node1]
956 ctx2 = self[node2]
956 ctx2 = self[node2]
957 working = ctx2 == self[None]
957 working = ctx2 == self[None]
958 parentworking = working and ctx1 == self['.']
958 parentworking = working and ctx1 == self['.']
959 match = match or match_.always(self.root, self.getcwd())
959 match = match or match_.always(self.root, self.getcwd())
960 listignored, listclean, listunknown = ignored, clean, unknown
960 listignored, listclean, listunknown = ignored, clean, unknown
961
961
962 if working: # we need to scan the working dir
962 if working: # we need to scan the working dir
963 s = self.dirstate.status(match, listignored, listclean, listunknown)
963 s = self.dirstate.status(match, listignored, listclean, listunknown)
964 cmp, modified, added, removed, deleted, unknown, ignored, clean = s
964 cmp, modified, added, removed, deleted, unknown, ignored, clean = s
965
965
966 # check for any possibly clean files
966 # check for any possibly clean files
967 if parentworking and cmp:
967 if parentworking and cmp:
968 fixup = []
968 fixup = []
969 # do a full compare of any files that might have changed
969 # do a full compare of any files that might have changed
970 for f in cmp:
970 for f in cmp:
971 if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
971 if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
972 or ctx1[f].cmp(ctx2[f].data())):
972 or ctx1[f].cmp(ctx2[f].data())):
973 modified.append(f)
973 modified.append(f)
974 else:
974 else:
975 fixup.append(f)
975 fixup.append(f)
976
976
977 if listclean:
977 if listclean:
978 clean += fixup
978 clean += fixup
979
979
980 # update dirstate for files that are actually clean
980 # update dirstate for files that are actually clean
981 if fixup:
981 if fixup:
982 wlock = None
982 wlock = None
983 try:
983 try:
984 try:
984 try:
985 wlock = self.wlock(False)
985 wlock = self.wlock(False)
986 for f in fixup:
986 for f in fixup:
987 self.dirstate.normal(f)
987 self.dirstate.normal(f)
988 except lock.LockException:
988 except lock.LockException:
989 pass
989 pass
990 finally:
990 finally:
991 del wlock
991 del wlock
992
992
993 if not parentworking:
993 if not parentworking:
994 mf1 = mfmatches(ctx1)
994 mf1 = mfmatches(ctx1)
995 if working:
995 if working:
996 # we are comparing working dir against non-parent
996 # we are comparing working dir against non-parent
997 # generate a pseudo-manifest for the working dir
997 # generate a pseudo-manifest for the working dir
998 mf2 = mfmatches(self['.'])
998 mf2 = mfmatches(self['.'])
999 for f in cmp + modified + added:
999 for f in cmp + modified + added:
1000 mf2[f] = None
1000 mf2[f] = None
1001 mf2.set(f, ctx2.flags(f))
1001 mf2.set(f, ctx2.flags(f))
1002 for f in removed:
1002 for f in removed:
1003 if f in mf2:
1003 if f in mf2:
1004 del mf2[f]
1004 del mf2[f]
1005 else:
1005 else:
1006 # we are comparing two revisions
1006 # we are comparing two revisions
1007 deleted, unknown, ignored = [], [], []
1007 deleted, unknown, ignored = [], [], []
1008 mf2 = mfmatches(ctx2)
1008 mf2 = mfmatches(ctx2)
1009
1009
1010 modified, added, clean = [], [], []
1010 modified, added, clean = [], [], []
1011 for fn in mf2:
1011 for fn in mf2:
1012 if fn in mf1:
1012 if fn in mf1:
1013 if (mf1.flags(fn) != mf2.flags(fn) or
1013 if (mf1.flags(fn) != mf2.flags(fn) or
1014 (mf1[fn] != mf2[fn] and
1014 (mf1[fn] != mf2[fn] and
1015 (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))):
1015 (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))):
1016 modified.append(fn)
1016 modified.append(fn)
1017 elif listclean:
1017 elif listclean:
1018 clean.append(fn)
1018 clean.append(fn)
1019 del mf1[fn]
1019 del mf1[fn]
1020 else:
1020 else:
1021 added.append(fn)
1021 added.append(fn)
1022 removed = mf1.keys()
1022 removed = mf1.keys()
1023
1023
1024 r = modified, added, removed, deleted, unknown, ignored, clean
1024 r = modified, added, removed, deleted, unknown, ignored, clean
1025 [l.sort() for l in r]
1025 [l.sort() for l in r]
1026 return r
1026 return r
1027
1027
1028 def add(self, list):
1028 def add(self, list):
1029 wlock = self.wlock()
1029 wlock = self.wlock()
1030 try:
1030 try:
1031 rejected = []
1031 rejected = []
1032 for f in list:
1032 for f in list:
1033 p = self.wjoin(f)
1033 p = self.wjoin(f)
1034 try:
1034 try:
1035 st = os.lstat(p)
1035 st = os.lstat(p)
1036 except:
1036 except:
1037 self.ui.warn(_("%s does not exist!\n") % f)
1037 self.ui.warn(_("%s does not exist!\n") % f)
1038 rejected.append(f)
1038 rejected.append(f)
1039 continue
1039 continue
1040 if st.st_size > 10000000:
1040 if st.st_size > 10000000:
1041 self.ui.warn(_("%s: files over 10MB may cause memory and"
1041 self.ui.warn(_("%s: files over 10MB may cause memory and"
1042 " performance problems\n"
1042 " performance problems\n"
1043 "(use 'hg revert %s' to unadd the file)\n")
1043 "(use 'hg revert %s' to unadd the file)\n")
1044 % (f, f))
1044 % (f, f))
1045 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1045 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1046 self.ui.warn(_("%s not added: only files and symlinks "
1046 self.ui.warn(_("%s not added: only files and symlinks "
1047 "supported currently\n") % f)
1047 "supported currently\n") % f)
1048 rejected.append(p)
1048 rejected.append(p)
1049 elif self.dirstate[f] in 'amn':
1049 elif self.dirstate[f] in 'amn':
1050 self.ui.warn(_("%s already tracked!\n") % f)
1050 self.ui.warn(_("%s already tracked!\n") % f)
1051 elif self.dirstate[f] == 'r':
1051 elif self.dirstate[f] == 'r':
1052 self.dirstate.normallookup(f)
1052 self.dirstate.normallookup(f)
1053 else:
1053 else:
1054 self.dirstate.add(f)
1054 self.dirstate.add(f)
1055 return rejected
1055 return rejected
1056 finally:
1056 finally:
1057 del wlock
1057 del wlock
1058
1058
1059 def forget(self, list):
1059 def forget(self, list):
1060 wlock = self.wlock()
1060 wlock = self.wlock()
1061 try:
1061 try:
1062 for f in list:
1062 for f in list:
1063 if self.dirstate[f] != 'a':
1063 if self.dirstate[f] != 'a':
1064 self.ui.warn(_("%s not added!\n") % f)
1064 self.ui.warn(_("%s not added!\n") % f)
1065 else:
1065 else:
1066 self.dirstate.forget(f)
1066 self.dirstate.forget(f)
1067 finally:
1067 finally:
1068 del wlock
1068 del wlock
1069
1069
1070 def remove(self, list, unlink=False):
1070 def remove(self, list, unlink=False):
1071 wlock = None
1071 wlock = None
1072 try:
1072 try:
1073 if unlink:
1073 if unlink:
1074 for f in list:
1074 for f in list:
1075 try:
1075 try:
1076 util.unlink(self.wjoin(f))
1076 util.unlink(self.wjoin(f))
1077 except OSError, inst:
1077 except OSError, inst:
1078 if inst.errno != errno.ENOENT:
1078 if inst.errno != errno.ENOENT:
1079 raise
1079 raise
1080 wlock = self.wlock()
1080 wlock = self.wlock()
1081 for f in list:
1081 for f in list:
1082 if unlink and os.path.exists(self.wjoin(f)):
1082 if unlink and os.path.exists(self.wjoin(f)):
1083 self.ui.warn(_("%s still exists!\n") % f)
1083 self.ui.warn(_("%s still exists!\n") % f)
1084 elif self.dirstate[f] == 'a':
1084 elif self.dirstate[f] == 'a':
1085 self.dirstate.forget(f)
1085 self.dirstate.forget(f)
1086 elif f not in self.dirstate:
1086 elif f not in self.dirstate:
1087 self.ui.warn(_("%s not tracked!\n") % f)
1087 self.ui.warn(_("%s not tracked!\n") % f)
1088 else:
1088 else:
1089 self.dirstate.remove(f)
1089 self.dirstate.remove(f)
1090 finally:
1090 finally:
1091 del wlock
1091 del wlock
1092
1092
1093 def undelete(self, list):
1093 def undelete(self, list):
1094 wlock = None
1094 wlock = None
1095 try:
1095 try:
1096 manifests = [self.manifest.read(self.changelog.read(p)[0])
1096 manifests = [self.manifest.read(self.changelog.read(p)[0])
1097 for p in self.dirstate.parents() if p != nullid]
1097 for p in self.dirstate.parents() if p != nullid]
1098 wlock = self.wlock()
1098 wlock = self.wlock()
1099 for f in list:
1099 for f in list:
1100 if self.dirstate[f] != 'r':
1100 if self.dirstate[f] != 'r':
1101 self.ui.warn("%s not removed!\n" % f)
1101 self.ui.warn("%s not removed!\n" % f)
1102 else:
1102 else:
1103 m = f in manifests[0] and manifests[0] or manifests[1]
1103 m = f in manifests[0] and manifests[0] or manifests[1]
1104 t = self.file(f).read(m[f])
1104 t = self.file(f).read(m[f])
1105 self.wwrite(f, t, m.flags(f))
1105 self.wwrite(f, t, m.flags(f))
1106 self.dirstate.normal(f)
1106 self.dirstate.normal(f)
1107 finally:
1107 finally:
1108 del wlock
1108 del wlock
1109
1109
1110 def copy(self, source, dest):
1110 def copy(self, source, dest):
1111 wlock = None
1111 wlock = None
1112 try:
1112 try:
1113 p = self.wjoin(dest)
1113 p = self.wjoin(dest)
1114 if not (os.path.exists(p) or os.path.islink(p)):
1114 if not (os.path.exists(p) or os.path.islink(p)):
1115 self.ui.warn(_("%s does not exist!\n") % dest)
1115 self.ui.warn(_("%s does not exist!\n") % dest)
1116 elif not (os.path.isfile(p) or os.path.islink(p)):
1116 elif not (os.path.isfile(p) or os.path.islink(p)):
1117 self.ui.warn(_("copy failed: %s is not a file or a "
1117 self.ui.warn(_("copy failed: %s is not a file or a "
1118 "symbolic link\n") % dest)
1118 "symbolic link\n") % dest)
1119 else:
1119 else:
1120 wlock = self.wlock()
1120 wlock = self.wlock()
1121 if dest not in self.dirstate:
1121 if dest not in self.dirstate:
1122 self.dirstate.add(dest)
1122 self.dirstate.add(dest)
1123 self.dirstate.copy(source, dest)
1123 self.dirstate.copy(source, dest)
1124 finally:
1124 finally:
1125 del wlock
1125 del wlock
1126
1126
1127 def heads(self, start=None):
1127 def heads(self, start=None):
1128 heads = self.changelog.heads(start)
1128 heads = self.changelog.heads(start)
1129 # sort the output in rev descending order
1129 # sort the output in rev descending order
1130 heads = [(-self.changelog.rev(h), h) for h in heads]
1130 heads = [(-self.changelog.rev(h), h) for h in heads]
1131 return [n for (r, n) in util.sort(heads)]
1131 return [n for (r, n) in util.sort(heads)]
1132
1132
1133 def branchheads(self, branch=None, start=None):
1133 def branchheads(self, branch=None, start=None):
1134 if branch is None:
1134 if branch is None:
1135 branch = self[None].branch()
1135 branch = self[None].branch()
1136 branches = self.branchtags()
1136 branches = self.branchtags()
1137 if branch not in branches:
1137 if branch not in branches:
1138 return []
1138 return []
1139 # The basic algorithm is this:
1139 # The basic algorithm is this:
1140 #
1140 #
1141 # Start from the branch tip since there are no later revisions that can
1141 # Start from the branch tip since there are no later revisions that can
1142 # possibly be in this branch, and the tip is a guaranteed head.
1142 # possibly be in this branch, and the tip is a guaranteed head.
1143 #
1143 #
1144 # Remember the tip's parents as the first ancestors, since these by
1144 # Remember the tip's parents as the first ancestors, since these by
1145 # definition are not heads.
1145 # definition are not heads.
1146 #
1146 #
1147 # Step backwards from the brach tip through all the revisions. We are
1147 # Step backwards from the brach tip through all the revisions. We are
1148 # guaranteed by the rules of Mercurial that we will now be visiting the
1148 # guaranteed by the rules of Mercurial that we will now be visiting the
1149 # nodes in reverse topological order (children before parents).
1149 # nodes in reverse topological order (children before parents).
1150 #
1150 #
1151 # If a revision is one of the ancestors of a head then we can toss it
1151 # If a revision is one of the ancestors of a head then we can toss it
1152 # out of the ancestors set (we've already found it and won't be
1152 # out of the ancestors set (we've already found it and won't be
1153 # visiting it again) and put its parents in the ancestors set.
1153 # visiting it again) and put its parents in the ancestors set.
1154 #
1154 #
1155 # Otherwise, if a revision is in the branch it's another head, since it
1155 # Otherwise, if a revision is in the branch it's another head, since it
1156 # wasn't in the ancestor list of an existing head. So add it to the
1156 # wasn't in the ancestor list of an existing head. So add it to the
1157 # head list, and add its parents to the ancestor list.
1157 # head list, and add its parents to the ancestor list.
1158 #
1158 #
1159 # If it is not in the branch ignore it.
1159 # If it is not in the branch ignore it.
1160 #
1160 #
1161 # Once we have a list of heads, use nodesbetween to filter out all the
1161 # Once we have a list of heads, use nodesbetween to filter out all the
1162 # heads that cannot be reached from startrev. There may be a more
1162 # heads that cannot be reached from startrev. There may be a more
1163 # efficient way to do this as part of the previous algorithm.
1163 # efficient way to do this as part of the previous algorithm.
1164
1164
1165 set = util.set
1165 set = util.set
1166 heads = [self.changelog.rev(branches[branch])]
1166 heads = [self.changelog.rev(branches[branch])]
1167 # Don't care if ancestors contains nullrev or not.
1167 # Don't care if ancestors contains nullrev or not.
1168 ancestors = set(self.changelog.parentrevs(heads[0]))
1168 ancestors = set(self.changelog.parentrevs(heads[0]))
1169 for rev in xrange(heads[0] - 1, nullrev, -1):
1169 for rev in xrange(heads[0] - 1, nullrev, -1):
1170 if rev in ancestors:
1170 if rev in ancestors:
1171 ancestors.update(self.changelog.parentrevs(rev))
1171 ancestors.update(self.changelog.parentrevs(rev))
1172 ancestors.remove(rev)
1172 ancestors.remove(rev)
1173 elif self[rev].branch() == branch:
1173 elif self[rev].branch() == branch:
1174 heads.append(rev)
1174 heads.append(rev)
1175 ancestors.update(self.changelog.parentrevs(rev))
1175 ancestors.update(self.changelog.parentrevs(rev))
1176 heads = [self.changelog.node(rev) for rev in heads]
1176 heads = [self.changelog.node(rev) for rev in heads]
1177 if start is not None:
1177 if start is not None:
1178 heads = self.changelog.nodesbetween([start], heads)[2]
1178 heads = self.changelog.nodesbetween([start], heads)[2]
1179 return heads
1179 return heads
1180
1180
1181 def branches(self, nodes):
1181 def branches(self, nodes):
1182 if not nodes:
1182 if not nodes:
1183 nodes = [self.changelog.tip()]
1183 nodes = [self.changelog.tip()]
1184 b = []
1184 b = []
1185 for n in nodes:
1185 for n in nodes:
1186 t = n
1186 t = n
1187 while 1:
1187 while 1:
1188 p = self.changelog.parents(n)
1188 p = self.changelog.parents(n)
1189 if p[1] != nullid or p[0] == nullid:
1189 if p[1] != nullid or p[0] == nullid:
1190 b.append((t, n, p[0], p[1]))
1190 b.append((t, n, p[0], p[1]))
1191 break
1191 break
1192 n = p[0]
1192 n = p[0]
1193 return b
1193 return b
1194
1194
1195 def between(self, pairs):
1195 def between(self, pairs):
1196 r = []
1196 r = []
1197
1197
1198 for top, bottom in pairs:
1198 for top, bottom in pairs:
1199 n, l, i = top, [], 0
1199 n, l, i = top, [], 0
1200 f = 1
1200 f = 1
1201
1201
1202 while n != bottom:
1202 while n != bottom:
1203 p = self.changelog.parents(n)[0]
1203 p = self.changelog.parents(n)[0]
1204 if i == f:
1204 if i == f:
1205 l.append(n)
1205 l.append(n)
1206 f = f * 2
1206 f = f * 2
1207 n = p
1207 n = p
1208 i += 1
1208 i += 1
1209
1209
1210 r.append(l)
1210 r.append(l)
1211
1211
1212 return r
1212 return r
1213
1213
1214 def findincoming(self, remote, base=None, heads=None, force=False):
1214 def findincoming(self, remote, base=None, heads=None, force=False):
1215 """Return list of roots of the subsets of missing nodes from remote
1215 """Return list of roots of the subsets of missing nodes from remote
1216
1216
1217 If base dict is specified, assume that these nodes and their parents
1217 If base dict is specified, assume that these nodes and their parents
1218 exist on the remote side and that no child of a node of base exists
1218 exist on the remote side and that no child of a node of base exists
1219 in both remote and self.
1219 in both remote and self.
1220 Furthermore base will be updated to include the nodes that exists
1220 Furthermore base will be updated to include the nodes that exists
1221 in self and remote but no children exists in self and remote.
1221 in self and remote but no children exists in self and remote.
1222 If a list of heads is specified, return only nodes which are heads
1222 If a list of heads is specified, return only nodes which are heads
1223 or ancestors of these heads.
1223 or ancestors of these heads.
1224
1224
1225 All the ancestors of base are in self and in remote.
1225 All the ancestors of base are in self and in remote.
1226 All the descendants of the list returned are missing in self.
1226 All the descendants of the list returned are missing in self.
1227 (and so we know that the rest of the nodes are missing in remote, see
1227 (and so we know that the rest of the nodes are missing in remote, see
1228 outgoing)
1228 outgoing)
1229 """
1229 """
1230 m = self.changelog.nodemap
1230 m = self.changelog.nodemap
1231 search = []
1231 search = []
1232 fetch = {}
1232 fetch = {}
1233 seen = {}
1233 seen = {}
1234 seenbranch = {}
1234 seenbranch = {}
1235 if base == None:
1235 if base == None:
1236 base = {}
1236 base = {}
1237
1237
1238 if not heads:
1238 if not heads:
1239 heads = remote.heads()
1239 heads = remote.heads()
1240
1240
1241 if self.changelog.tip() == nullid:
1241 if self.changelog.tip() == nullid:
1242 base[nullid] = 1
1242 base[nullid] = 1
1243 if heads != [nullid]:
1243 if heads != [nullid]:
1244 return [nullid]
1244 return [nullid]
1245 return []
1245 return []
1246
1246
1247 # assume we're closer to the tip than the root
1247 # assume we're closer to the tip than the root
1248 # and start by examining the heads
1248 # and start by examining the heads
1249 self.ui.status(_("searching for changes\n"))
1249 self.ui.status(_("searching for changes\n"))
1250
1250
1251 unknown = []
1251 unknown = []
1252 for h in heads:
1252 for h in heads:
1253 if h not in m:
1253 if h not in m:
1254 unknown.append(h)
1254 unknown.append(h)
1255 else:
1255 else:
1256 base[h] = 1
1256 base[h] = 1
1257
1257
1258 if not unknown:
1258 if not unknown:
1259 return []
1259 return []
1260
1260
1261 req = dict.fromkeys(unknown)
1261 req = dict.fromkeys(unknown)
1262 reqcnt = 0
1262 reqcnt = 0
1263
1263
1264 # search through remote branches
1264 # search through remote branches
1265 # a 'branch' here is a linear segment of history, with four parts:
1265 # a 'branch' here is a linear segment of history, with four parts:
1266 # head, root, first parent, second parent
1266 # head, root, first parent, second parent
1267 # (a branch always has two parents (or none) by definition)
1267 # (a branch always has two parents (or none) by definition)
1268 unknown = remote.branches(unknown)
1268 unknown = remote.branches(unknown)
1269 while unknown:
1269 while unknown:
1270 r = []
1270 r = []
1271 while unknown:
1271 while unknown:
1272 n = unknown.pop(0)
1272 n = unknown.pop(0)
1273 if n[0] in seen:
1273 if n[0] in seen:
1274 continue
1274 continue
1275
1275
1276 self.ui.debug(_("examining %s:%s\n")
1276 self.ui.debug(_("examining %s:%s\n")
1277 % (short(n[0]), short(n[1])))
1277 % (short(n[0]), short(n[1])))
1278 if n[0] == nullid: # found the end of the branch
1278 if n[0] == nullid: # found the end of the branch
1279 pass
1279 pass
1280 elif n in seenbranch:
1280 elif n in seenbranch:
1281 self.ui.debug(_("branch already found\n"))
1281 self.ui.debug(_("branch already found\n"))
1282 continue
1282 continue
1283 elif n[1] and n[1] in m: # do we know the base?
1283 elif n[1] and n[1] in m: # do we know the base?
1284 self.ui.debug(_("found incomplete branch %s:%s\n")
1284 self.ui.debug(_("found incomplete branch %s:%s\n")
1285 % (short(n[0]), short(n[1])))
1285 % (short(n[0]), short(n[1])))
1286 search.append(n) # schedule branch range for scanning
1286 search.append(n) # schedule branch range for scanning
1287 seenbranch[n] = 1
1287 seenbranch[n] = 1
1288 else:
1288 else:
1289 if n[1] not in seen and n[1] not in fetch:
1289 if n[1] not in seen and n[1] not in fetch:
1290 if n[2] in m and n[3] in m:
1290 if n[2] in m and n[3] in m:
1291 self.ui.debug(_("found new changeset %s\n") %
1291 self.ui.debug(_("found new changeset %s\n") %
1292 short(n[1]))
1292 short(n[1]))
1293 fetch[n[1]] = 1 # earliest unknown
1293 fetch[n[1]] = 1 # earliest unknown
1294 for p in n[2:4]:
1294 for p in n[2:4]:
1295 if p in m:
1295 if p in m:
1296 base[p] = 1 # latest known
1296 base[p] = 1 # latest known
1297
1297
1298 for p in n[2:4]:
1298 for p in n[2:4]:
1299 if p not in req and p not in m:
1299 if p not in req and p not in m:
1300 r.append(p)
1300 r.append(p)
1301 req[p] = 1
1301 req[p] = 1
1302 seen[n[0]] = 1
1302 seen[n[0]] = 1
1303
1303
1304 if r:
1304 if r:
1305 reqcnt += 1
1305 reqcnt += 1
1306 self.ui.debug(_("request %d: %s\n") %
1306 self.ui.debug(_("request %d: %s\n") %
1307 (reqcnt, " ".join(map(short, r))))
1307 (reqcnt, " ".join(map(short, r))))
1308 for p in xrange(0, len(r), 10):
1308 for p in xrange(0, len(r), 10):
1309 for b in remote.branches(r[p:p+10]):
1309 for b in remote.branches(r[p:p+10]):
1310 self.ui.debug(_("received %s:%s\n") %
1310 self.ui.debug(_("received %s:%s\n") %
1311 (short(b[0]), short(b[1])))
1311 (short(b[0]), short(b[1])))
1312 unknown.append(b)
1312 unknown.append(b)
1313
1313
1314 # do binary search on the branches we found
1314 # do binary search on the branches we found
1315 while search:
1315 while search:
1316 n = search.pop(0)
1316 n = search.pop(0)
1317 reqcnt += 1
1317 reqcnt += 1
1318 l = remote.between([(n[0], n[1])])[0]
1318 l = remote.between([(n[0], n[1])])[0]
1319 l.append(n[1])
1319 l.append(n[1])
1320 p = n[0]
1320 p = n[0]
1321 f = 1
1321 f = 1
1322 for i in l:
1322 for i in l:
1323 self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i)))
1323 self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i)))
1324 if i in m:
1324 if i in m:
1325 if f <= 2:
1325 if f <= 2:
1326 self.ui.debug(_("found new branch changeset %s\n") %
1326 self.ui.debug(_("found new branch changeset %s\n") %
1327 short(p))
1327 short(p))
1328 fetch[p] = 1
1328 fetch[p] = 1
1329 base[i] = 1
1329 base[i] = 1
1330 else:
1330 else:
1331 self.ui.debug(_("narrowed branch search to %s:%s\n")
1331 self.ui.debug(_("narrowed branch search to %s:%s\n")
1332 % (short(p), short(i)))
1332 % (short(p), short(i)))
1333 search.append((p, i))
1333 search.append((p, i))
1334 break
1334 break
1335 p, f = i, f * 2
1335 p, f = i, f * 2
1336
1336
1337 # sanity check our fetch list
1337 # sanity check our fetch list
1338 for f in fetch.keys():
1338 for f in fetch.keys():
1339 if f in m:
1339 if f in m:
1340 raise repo.RepoError(_("already have changeset ") + short(f[:4]))
1340 raise repo.RepoError(_("already have changeset ") + short(f[:4]))
1341
1341
1342 if base.keys() == [nullid]:
1342 if base.keys() == [nullid]:
1343 if force:
1343 if force:
1344 self.ui.warn(_("warning: repository is unrelated\n"))
1344 self.ui.warn(_("warning: repository is unrelated\n"))
1345 else:
1345 else:
1346 raise util.Abort(_("repository is unrelated"))
1346 raise util.Abort(_("repository is unrelated"))
1347
1347
1348 self.ui.debug(_("found new changesets starting at ") +
1348 self.ui.debug(_("found new changesets starting at ") +
1349 " ".join([short(f) for f in fetch]) + "\n")
1349 " ".join([short(f) for f in fetch]) + "\n")
1350
1350
1351 self.ui.debug(_("%d total queries\n") % reqcnt)
1351 self.ui.debug(_("%d total queries\n") % reqcnt)
1352
1352
1353 return fetch.keys()
1353 return fetch.keys()
1354
1354
1355 def findoutgoing(self, remote, base=None, heads=None, force=False):
1355 def findoutgoing(self, remote, base=None, heads=None, force=False):
1356 """Return list of nodes that are roots of subsets not in remote
1356 """Return list of nodes that are roots of subsets not in remote
1357
1357
1358 If base dict is specified, assume that these nodes and their parents
1358 If base dict is specified, assume that these nodes and their parents
1359 exist on the remote side.
1359 exist on the remote side.
1360 If a list of heads is specified, return only nodes which are heads
1360 If a list of heads is specified, return only nodes which are heads
1361 or ancestors of these heads, and return a second element which
1361 or ancestors of these heads, and return a second element which
1362 contains all remote heads which get new children.
1362 contains all remote heads which get new children.
1363 """
1363 """
1364 if base == None:
1364 if base == None:
1365 base = {}
1365 base = {}
1366 self.findincoming(remote, base, heads, force=force)
1366 self.findincoming(remote, base, heads, force=force)
1367
1367
1368 self.ui.debug(_("common changesets up to ")
1368 self.ui.debug(_("common changesets up to ")
1369 + " ".join(map(short, base.keys())) + "\n")
1369 + " ".join(map(short, base.keys())) + "\n")
1370
1370
1371 remain = dict.fromkeys(self.changelog.nodemap)
1371 remain = dict.fromkeys(self.changelog.nodemap)
1372
1372
1373 # prune everything remote has from the tree
1373 # prune everything remote has from the tree
1374 del remain[nullid]
1374 del remain[nullid]
1375 remove = base.keys()
1375 remove = base.keys()
1376 while remove:
1376 while remove:
1377 n = remove.pop(0)
1377 n = remove.pop(0)
1378 if n in remain:
1378 if n in remain:
1379 del remain[n]
1379 del remain[n]
1380 for p in self.changelog.parents(n):
1380 for p in self.changelog.parents(n):
1381 remove.append(p)
1381 remove.append(p)
1382
1382
1383 # find every node whose parents have been pruned
1383 # find every node whose parents have been pruned
1384 subset = []
1384 subset = []
1385 # find every remote head that will get new children
1385 # find every remote head that will get new children
1386 updated_heads = {}
1386 updated_heads = {}
1387 for n in remain:
1387 for n in remain:
1388 p1, p2 = self.changelog.parents(n)
1388 p1, p2 = self.changelog.parents(n)
1389 if p1 not in remain and p2 not in remain:
1389 if p1 not in remain and p2 not in remain:
1390 subset.append(n)
1390 subset.append(n)
1391 if heads:
1391 if heads:
1392 if p1 in heads:
1392 if p1 in heads:
1393 updated_heads[p1] = True
1393 updated_heads[p1] = True
1394 if p2 in heads:
1394 if p2 in heads:
1395 updated_heads[p2] = True
1395 updated_heads[p2] = True
1396
1396
1397 # this is the set of all roots we have to push
1397 # this is the set of all roots we have to push
1398 if heads:
1398 if heads:
1399 return subset, updated_heads.keys()
1399 return subset, updated_heads.keys()
1400 else:
1400 else:
1401 return subset
1401 return subset
1402
1402
1403 def pull(self, remote, heads=None, force=False):
1403 def pull(self, remote, heads=None, force=False):
1404 lock = self.lock()
1404 lock = self.lock()
1405 try:
1405 try:
1406 fetch = self.findincoming(remote, heads=heads, force=force)
1406 fetch = self.findincoming(remote, heads=heads, force=force)
1407 if fetch == [nullid]:
1407 if fetch == [nullid]:
1408 self.ui.status(_("requesting all changes\n"))
1408 self.ui.status(_("requesting all changes\n"))
1409
1409
1410 if not fetch:
1410 if not fetch:
1411 self.ui.status(_("no changes found\n"))
1411 self.ui.status(_("no changes found\n"))
1412 return 0
1412 return 0
1413
1413
1414 if heads is None:
1414 if heads is None:
1415 cg = remote.changegroup(fetch, 'pull')
1415 cg = remote.changegroup(fetch, 'pull')
1416 else:
1416 else:
1417 if 'changegroupsubset' not in remote.capabilities:
1417 if 'changegroupsubset' not in remote.capabilities:
1418 raise util.Abort(_("Partial pull cannot be done because other repository doesn't support changegroupsubset."))
1418 raise util.Abort(_("Partial pull cannot be done because other repository doesn't support changegroupsubset."))
1419 cg = remote.changegroupsubset(fetch, heads, 'pull')
1419 cg = remote.changegroupsubset(fetch, heads, 'pull')
1420 return self.addchangegroup(cg, 'pull', remote.url())
1420 return self.addchangegroup(cg, 'pull', remote.url())
1421 finally:
1421 finally:
1422 del lock
1422 del lock
1423
1423
1424 def push(self, remote, force=False, revs=None):
1424 def push(self, remote, force=False, revs=None):
1425 # there are two ways to push to remote repo:
1425 # there are two ways to push to remote repo:
1426 #
1426 #
1427 # addchangegroup assumes local user can lock remote
1427 # addchangegroup assumes local user can lock remote
1428 # repo (local filesystem, old ssh servers).
1428 # repo (local filesystem, old ssh servers).
1429 #
1429 #
1430 # unbundle assumes local user cannot lock remote repo (new ssh
1430 # unbundle assumes local user cannot lock remote repo (new ssh
1431 # servers, http servers).
1431 # servers, http servers).
1432
1432
1433 if remote.capable('unbundle'):
1433 if remote.capable('unbundle'):
1434 return self.push_unbundle(remote, force, revs)
1434 return self.push_unbundle(remote, force, revs)
1435 return self.push_addchangegroup(remote, force, revs)
1435 return self.push_addchangegroup(remote, force, revs)
1436
1436
1437 def prepush(self, remote, force, revs):
1437 def prepush(self, remote, force, revs):
1438 base = {}
1438 base = {}
1439 remote_heads = remote.heads()
1439 remote_heads = remote.heads()
1440 inc = self.findincoming(remote, base, remote_heads, force=force)
1440 inc = self.findincoming(remote, base, remote_heads, force=force)
1441
1441
1442 update, updated_heads = self.findoutgoing(remote, base, remote_heads)
1442 update, updated_heads = self.findoutgoing(remote, base, remote_heads)
1443 if revs is not None:
1443 if revs is not None:
1444 msng_cl, bases, heads = self.changelog.nodesbetween(update, revs)
1444 msng_cl, bases, heads = self.changelog.nodesbetween(update, revs)
1445 else:
1445 else:
1446 bases, heads = update, self.changelog.heads()
1446 bases, heads = update, self.changelog.heads()
1447
1447
1448 if not bases:
1448 if not bases:
1449 self.ui.status(_("no changes found\n"))
1449 self.ui.status(_("no changes found\n"))
1450 return None, 1
1450 return None, 1
1451 elif not force:
1451 elif not force:
1452 # check if we're creating new remote heads
1452 # check if we're creating new remote heads
1453 # to be a remote head after push, node must be either
1453 # to be a remote head after push, node must be either
1454 # - unknown locally
1454 # - unknown locally
1455 # - a local outgoing head descended from update
1455 # - a local outgoing head descended from update
1456 # - a remote head that's known locally and not
1456 # - a remote head that's known locally and not
1457 # ancestral to an outgoing head
1457 # ancestral to an outgoing head
1458
1458
1459 warn = 0
1459 warn = 0
1460
1460
1461 if remote_heads == [nullid]:
1461 if remote_heads == [nullid]:
1462 warn = 0
1462 warn = 0
1463 elif not revs and len(heads) > len(remote_heads):
1463 elif not revs and len(heads) > len(remote_heads):
1464 warn = 1
1464 warn = 1
1465 else:
1465 else:
1466 newheads = list(heads)
1466 newheads = list(heads)
1467 for r in remote_heads:
1467 for r in remote_heads:
1468 if r in self.changelog.nodemap:
1468 if r in self.changelog.nodemap:
1469 desc = self.changelog.heads(r, heads)
1469 desc = self.changelog.heads(r, heads)
1470 l = [h for h in heads if h in desc]
1470 l = [h for h in heads if h in desc]
1471 if not l:
1471 if not l:
1472 newheads.append(r)
1472 newheads.append(r)
1473 else:
1473 else:
1474 newheads.append(r)
1474 newheads.append(r)
1475 if len(newheads) > len(remote_heads):
1475 if len(newheads) > len(remote_heads):
1476 warn = 1
1476 warn = 1
1477
1477
1478 if warn:
1478 if warn:
1479 self.ui.warn(_("abort: push creates new remote heads!\n"))
1479 self.ui.warn(_("abort: push creates new remote heads!\n"))
1480 self.ui.status(_("(did you forget to merge?"
1480 self.ui.status(_("(did you forget to merge?"
1481 " use push -f to force)\n"))
1481 " use push -f to force)\n"))
1482 return None, 0
1482 return None, 0
1483 elif inc:
1483 elif inc:
1484 self.ui.warn(_("note: unsynced remote changes!\n"))
1484 self.ui.warn(_("note: unsynced remote changes!\n"))
1485
1485
1486
1486
1487 if revs is None:
1487 if revs is None:
1488 cg = self.changegroup(update, 'push')
1488 cg = self.changegroup(update, 'push')
1489 else:
1489 else:
1490 cg = self.changegroupsubset(update, revs, 'push')
1490 cg = self.changegroupsubset(update, revs, 'push')
1491 return cg, remote_heads
1491 return cg, remote_heads
1492
1492
1493 def push_addchangegroup(self, remote, force, revs):
1493 def push_addchangegroup(self, remote, force, revs):
1494 lock = remote.lock()
1494 lock = remote.lock()
1495 try:
1495 try:
1496 ret = self.prepush(remote, force, revs)
1496 ret = self.prepush(remote, force, revs)
1497 if ret[0] is not None:
1497 if ret[0] is not None:
1498 cg, remote_heads = ret
1498 cg, remote_heads = ret
1499 return remote.addchangegroup(cg, 'push', self.url())
1499 return remote.addchangegroup(cg, 'push', self.url())
1500 return ret[1]
1500 return ret[1]
1501 finally:
1501 finally:
1502 del lock
1502 del lock
1503
1503
1504 def push_unbundle(self, remote, force, revs):
1504 def push_unbundle(self, remote, force, revs):
1505 # local repo finds heads on server, finds out what revs it
1505 # local repo finds heads on server, finds out what revs it
1506 # must push. once revs transferred, if server finds it has
1506 # must push. once revs transferred, if server finds it has
1507 # different heads (someone else won commit/push race), server
1507 # different heads (someone else won commit/push race), server
1508 # aborts.
1508 # aborts.
1509
1509
1510 ret = self.prepush(remote, force, revs)
1510 ret = self.prepush(remote, force, revs)
1511 if ret[0] is not None:
1511 if ret[0] is not None:
1512 cg, remote_heads = ret
1512 cg, remote_heads = ret
1513 if force: remote_heads = ['force']
1513 if force: remote_heads = ['force']
1514 return remote.unbundle(cg, remote_heads, 'push')
1514 return remote.unbundle(cg, remote_heads, 'push')
1515 return ret[1]
1515 return ret[1]
1516
1516
1517 def changegroupinfo(self, nodes, source):
1517 def changegroupinfo(self, nodes, source):
1518 if self.ui.verbose or source == 'bundle':
1518 if self.ui.verbose or source == 'bundle':
1519 self.ui.status(_("%d changesets found\n") % len(nodes))
1519 self.ui.status(_("%d changesets found\n") % len(nodes))
1520 if self.ui.debugflag:
1520 if self.ui.debugflag:
1521 self.ui.debug(_("List of changesets:\n"))
1521 self.ui.debug(_("List of changesets:\n"))
1522 for node in nodes:
1522 for node in nodes:
1523 self.ui.debug("%s\n" % hex(node))
1523 self.ui.debug("%s\n" % hex(node))
1524
1524
1525 def changegroupsubset(self, bases, heads, source, extranodes=None):
1525 def changegroupsubset(self, bases, heads, source, extranodes=None):
1526 """This function generates a changegroup consisting of all the nodes
1526 """This function generates a changegroup consisting of all the nodes
1527 that are descendents of any of the bases, and ancestors of any of
1527 that are descendents of any of the bases, and ancestors of any of
1528 the heads.
1528 the heads.
1529
1529
1530 It is fairly complex as determining which filenodes and which
1530 It is fairly complex as determining which filenodes and which
1531 manifest nodes need to be included for the changeset to be complete
1531 manifest nodes need to be included for the changeset to be complete
1532 is non-trivial.
1532 is non-trivial.
1533
1533
1534 Another wrinkle is doing the reverse, figuring out which changeset in
1534 Another wrinkle is doing the reverse, figuring out which changeset in
1535 the changegroup a particular filenode or manifestnode belongs to.
1535 the changegroup a particular filenode or manifestnode belongs to.
1536
1536
1537 The caller can specify some nodes that must be included in the
1537 The caller can specify some nodes that must be included in the
1538 changegroup using the extranodes argument. It should be a dict
1538 changegroup using the extranodes argument. It should be a dict
1539 where the keys are the filenames (or 1 for the manifest), and the
1539 where the keys are the filenames (or 1 for the manifest), and the
1540 values are lists of (node, linknode) tuples, where node is a wanted
1540 values are lists of (node, linknode) tuples, where node is a wanted
1541 node and linknode is the changelog node that should be transmitted as
1541 node and linknode is the changelog node that should be transmitted as
1542 the linkrev.
1542 the linkrev.
1543 """
1543 """
1544
1544
1545 self.hook('preoutgoing', throw=True, source=source)
1545 self.hook('preoutgoing', throw=True, source=source)
1546
1546
1547 # Set up some initial variables
1547 # Set up some initial variables
1548 # Make it easy to refer to self.changelog
1548 # Make it easy to refer to self.changelog
1549 cl = self.changelog
1549 cl = self.changelog
1550 # msng is short for missing - compute the list of changesets in this
1550 # msng is short for missing - compute the list of changesets in this
1551 # changegroup.
1551 # changegroup.
1552 msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads)
1552 msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads)
1553 self.changegroupinfo(msng_cl_lst, source)
1553 self.changegroupinfo(msng_cl_lst, source)
1554 # Some bases may turn out to be superfluous, and some heads may be
1554 # Some bases may turn out to be superfluous, and some heads may be
1555 # too. nodesbetween will return the minimal set of bases and heads
1555 # too. nodesbetween will return the minimal set of bases and heads
1556 # necessary to re-create the changegroup.
1556 # necessary to re-create the changegroup.
1557
1557
1558 # Known heads are the list of heads that it is assumed the recipient
1558 # Known heads are the list of heads that it is assumed the recipient
1559 # of this changegroup will know about.
1559 # of this changegroup will know about.
1560 knownheads = {}
1560 knownheads = {}
1561 # We assume that all parents of bases are known heads.
1561 # We assume that all parents of bases are known heads.
1562 for n in bases:
1562 for n in bases:
1563 for p in cl.parents(n):
1563 for p in cl.parents(n):
1564 if p != nullid:
1564 if p != nullid:
1565 knownheads[p] = 1
1565 knownheads[p] = 1
1566 knownheads = knownheads.keys()
1566 knownheads = knownheads.keys()
1567 if knownheads:
1567 if knownheads:
1568 # Now that we know what heads are known, we can compute which
1568 # Now that we know what heads are known, we can compute which
1569 # changesets are known. The recipient must know about all
1569 # changesets are known. The recipient must know about all
1570 # changesets required to reach the known heads from the null
1570 # changesets required to reach the known heads from the null
1571 # changeset.
1571 # changeset.
1572 has_cl_set, junk, junk = cl.nodesbetween(None, knownheads)
1572 has_cl_set, junk, junk = cl.nodesbetween(None, knownheads)
1573 junk = None
1573 junk = None
1574 # Transform the list into an ersatz set.
1574 # Transform the list into an ersatz set.
1575 has_cl_set = dict.fromkeys(has_cl_set)
1575 has_cl_set = dict.fromkeys(has_cl_set)
1576 else:
1576 else:
1577 # If there were no known heads, the recipient cannot be assumed to
1577 # If there were no known heads, the recipient cannot be assumed to
1578 # know about any changesets.
1578 # know about any changesets.
1579 has_cl_set = {}
1579 has_cl_set = {}
1580
1580
1581 # Make it easy to refer to self.manifest
1581 # Make it easy to refer to self.manifest
1582 mnfst = self.manifest
1582 mnfst = self.manifest
1583 # We don't know which manifests are missing yet
1583 # We don't know which manifests are missing yet
1584 msng_mnfst_set = {}
1584 msng_mnfst_set = {}
1585 # Nor do we know which filenodes are missing.
1585 # Nor do we know which filenodes are missing.
1586 msng_filenode_set = {}
1586 msng_filenode_set = {}
1587
1587
1588 junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex
1588 junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex
1589 junk = None
1589 junk = None
1590
1590
1591 # A changeset always belongs to itself, so the changenode lookup
1591 # A changeset always belongs to itself, so the changenode lookup
1592 # function for a changenode is identity.
1592 # function for a changenode is identity.
1593 def identity(x):
1593 def identity(x):
1594 return x
1594 return x
1595
1595
1596 # A function generating function. Sets up an environment for the
1596 # A function generating function. Sets up an environment for the
1597 # inner function.
1597 # inner function.
1598 def cmp_by_rev_func(revlog):
1598 def cmp_by_rev_func(revlog):
1599 # Compare two nodes by their revision number in the environment's
1599 # Compare two nodes by their revision number in the environment's
1600 # revision history. Since the revision number both represents the
1600 # revision history. Since the revision number both represents the
1601 # most efficient order to read the nodes in, and represents a
1601 # most efficient order to read the nodes in, and represents a
1602 # topological sorting of the nodes, this function is often useful.
1602 # topological sorting of the nodes, this function is often useful.
1603 def cmp_by_rev(a, b):
1603 def cmp_by_rev(a, b):
1604 return cmp(revlog.rev(a), revlog.rev(b))
1604 return cmp(revlog.rev(a), revlog.rev(b))
1605 return cmp_by_rev
1605 return cmp_by_rev
1606
1606
1607 # If we determine that a particular file or manifest node must be a
1607 # If we determine that a particular file or manifest node must be a
1608 # node that the recipient of the changegroup will already have, we can
1608 # node that the recipient of the changegroup will already have, we can
1609 # also assume the recipient will have all the parents. This function
1609 # also assume the recipient will have all the parents. This function
1610 # prunes them from the set of missing nodes.
1610 # prunes them from the set of missing nodes.
1611 def prune_parents(revlog, hasset, msngset):
1611 def prune_parents(revlog, hasset, msngset):
1612 haslst = hasset.keys()
1612 haslst = hasset.keys()
1613 haslst.sort(cmp_by_rev_func(revlog))
1613 haslst.sort(cmp_by_rev_func(revlog))
1614 for node in haslst:
1614 for node in haslst:
1615 parentlst = [p for p in revlog.parents(node) if p != nullid]
1615 parentlst = [p for p in revlog.parents(node) if p != nullid]
1616 while parentlst:
1616 while parentlst:
1617 n = parentlst.pop()
1617 n = parentlst.pop()
1618 if n not in hasset:
1618 if n not in hasset:
1619 hasset[n] = 1
1619 hasset[n] = 1
1620 p = [p for p in revlog.parents(n) if p != nullid]
1620 p = [p for p in revlog.parents(n) if p != nullid]
1621 parentlst.extend(p)
1621 parentlst.extend(p)
1622 for n in hasset:
1622 for n in hasset:
1623 msngset.pop(n, None)
1623 msngset.pop(n, None)
1624
1624
1625 # This is a function generating function used to set up an environment
1625 # This is a function generating function used to set up an environment
1626 # for the inner function to execute in.
1626 # for the inner function to execute in.
1627 def manifest_and_file_collector(changedfileset):
1627 def manifest_and_file_collector(changedfileset):
1628 # This is an information gathering function that gathers
1628 # This is an information gathering function that gathers
1629 # information from each changeset node that goes out as part of
1629 # information from each changeset node that goes out as part of
1630 # the changegroup. The information gathered is a list of which
1630 # the changegroup. The information gathered is a list of which
1631 # manifest nodes are potentially required (the recipient may
1631 # manifest nodes are potentially required (the recipient may
1632 # already have them) and total list of all files which were
1632 # already have them) and total list of all files which were
1633 # changed in any changeset in the changegroup.
1633 # changed in any changeset in the changegroup.
1634 #
1634 #
1635 # We also remember the first changenode we saw any manifest
1635 # We also remember the first changenode we saw any manifest
1636 # referenced by so we can later determine which changenode 'owns'
1636 # referenced by so we can later determine which changenode 'owns'
1637 # the manifest.
1637 # the manifest.
1638 def collect_manifests_and_files(clnode):
1638 def collect_manifests_and_files(clnode):
1639 c = cl.read(clnode)
1639 c = cl.read(clnode)
1640 for f in c[3]:
1640 for f in c[3]:
1641 # This is to make sure we only have one instance of each
1641 # This is to make sure we only have one instance of each
1642 # filename string for each filename.
1642 # filename string for each filename.
1643 changedfileset.setdefault(f, f)
1643 changedfileset.setdefault(f, f)
1644 msng_mnfst_set.setdefault(c[0], clnode)
1644 msng_mnfst_set.setdefault(c[0], clnode)
1645 return collect_manifests_and_files
1645 return collect_manifests_and_files
1646
1646
1647 # Figure out which manifest nodes (of the ones we think might be part
1647 # Figure out which manifest nodes (of the ones we think might be part
1648 # of the changegroup) the recipient must know about and remove them
1648 # of the changegroup) the recipient must know about and remove them
1649 # from the changegroup.
1649 # from the changegroup.
1650 def prune_manifests():
1650 def prune_manifests():
1651 has_mnfst_set = {}
1651 has_mnfst_set = {}
1652 for n in msng_mnfst_set:
1652 for n in msng_mnfst_set:
1653 # If a 'missing' manifest thinks it belongs to a changenode
1653 # If a 'missing' manifest thinks it belongs to a changenode
1654 # the recipient is assumed to have, obviously the recipient
1654 # the recipient is assumed to have, obviously the recipient
1655 # must have that manifest.
1655 # must have that manifest.
1656 linknode = cl.node(mnfst.linkrev(n))
1656 linknode = cl.node(mnfst.linkrev(n))
1657 if linknode in has_cl_set:
1657 if linknode in has_cl_set:
1658 has_mnfst_set[n] = 1
1658 has_mnfst_set[n] = 1
1659 prune_parents(mnfst, has_mnfst_set, msng_mnfst_set)
1659 prune_parents(mnfst, has_mnfst_set, msng_mnfst_set)
1660
1660
1661 # Use the information collected in collect_manifests_and_files to say
1661 # Use the information collected in collect_manifests_and_files to say
1662 # which changenode any manifestnode belongs to.
1662 # which changenode any manifestnode belongs to.
1663 def lookup_manifest_link(mnfstnode):
1663 def lookup_manifest_link(mnfstnode):
1664 return msng_mnfst_set[mnfstnode]
1664 return msng_mnfst_set[mnfstnode]
1665
1665
1666 # A function generating function that sets up the initial environment
1666 # A function generating function that sets up the initial environment
1667 # the inner function.
1667 # the inner function.
1668 def filenode_collector(changedfiles):
1668 def filenode_collector(changedfiles):
1669 next_rev = [0]
1669 next_rev = [0]
1670 # This gathers information from each manifestnode included in the
1670 # This gathers information from each manifestnode included in the
1671 # changegroup about which filenodes the manifest node references
1671 # changegroup about which filenodes the manifest node references
1672 # so we can include those in the changegroup too.
1672 # so we can include those in the changegroup too.
1673 #
1673 #
1674 # It also remembers which changenode each filenode belongs to. It
1674 # It also remembers which changenode each filenode belongs to. It
1675 # does this by assuming the a filenode belongs to the changenode
1675 # does this by assuming the a filenode belongs to the changenode
1676 # the first manifest that references it belongs to.
1676 # the first manifest that references it belongs to.
1677 def collect_msng_filenodes(mnfstnode):
1677 def collect_msng_filenodes(mnfstnode):
1678 r = mnfst.rev(mnfstnode)
1678 r = mnfst.rev(mnfstnode)
1679 if r == next_rev[0]:
1679 if r == next_rev[0]:
1680 # If the last rev we looked at was the one just previous,
1680 # If the last rev we looked at was the one just previous,
1681 # we only need to see a diff.
1681 # we only need to see a diff.
1682 deltamf = mnfst.readdelta(mnfstnode)
1682 deltamf = mnfst.readdelta(mnfstnode)
1683 # For each line in the delta
1683 # For each line in the delta
1684 for f, fnode in deltamf.items():
1684 for f, fnode in deltamf.items():
1685 f = changedfiles.get(f, None)
1685 f = changedfiles.get(f, None)
1686 # And if the file is in the list of files we care
1686 # And if the file is in the list of files we care
1687 # about.
1687 # about.
1688 if f is not None:
1688 if f is not None:
1689 # Get the changenode this manifest belongs to
1689 # Get the changenode this manifest belongs to
1690 clnode = msng_mnfst_set[mnfstnode]
1690 clnode = msng_mnfst_set[mnfstnode]
1691 # Create the set of filenodes for the file if
1691 # Create the set of filenodes for the file if
1692 # there isn't one already.
1692 # there isn't one already.
1693 ndset = msng_filenode_set.setdefault(f, {})
1693 ndset = msng_filenode_set.setdefault(f, {})
1694 # And set the filenode's changelog node to the
1694 # And set the filenode's changelog node to the
1695 # manifest's if it hasn't been set already.
1695 # manifest's if it hasn't been set already.
1696 ndset.setdefault(fnode, clnode)
1696 ndset.setdefault(fnode, clnode)
1697 else:
1697 else:
1698 # Otherwise we need a full manifest.
1698 # Otherwise we need a full manifest.
1699 m = mnfst.read(mnfstnode)
1699 m = mnfst.read(mnfstnode)
1700 # For every file in we care about.
1700 # For every file in we care about.
1701 for f in changedfiles:
1701 for f in changedfiles:
1702 fnode = m.get(f, None)
1702 fnode = m.get(f, None)
1703 # If it's in the manifest
1703 # If it's in the manifest
1704 if fnode is not None:
1704 if fnode is not None:
1705 # See comments above.
1705 # See comments above.
1706 clnode = msng_mnfst_set[mnfstnode]
1706 clnode = msng_mnfst_set[mnfstnode]
1707 ndset = msng_filenode_set.setdefault(f, {})
1707 ndset = msng_filenode_set.setdefault(f, {})
1708 ndset.setdefault(fnode, clnode)
1708 ndset.setdefault(fnode, clnode)
1709 # Remember the revision we hope to see next.
1709 # Remember the revision we hope to see next.
1710 next_rev[0] = r + 1
1710 next_rev[0] = r + 1
1711 return collect_msng_filenodes
1711 return collect_msng_filenodes
1712
1712
1713 # We have a list of filenodes we think we need for a file, lets remove
1713 # We have a list of filenodes we think we need for a file, lets remove
1714 # all those we now the recipient must have.
1714 # all those we now the recipient must have.
1715 def prune_filenodes(f, filerevlog):
1715 def prune_filenodes(f, filerevlog):
1716 msngset = msng_filenode_set[f]
1716 msngset = msng_filenode_set[f]
1717 hasset = {}
1717 hasset = {}
1718 # If a 'missing' filenode thinks it belongs to a changenode we
1718 # If a 'missing' filenode thinks it belongs to a changenode we
1719 # assume the recipient must have, then the recipient must have
1719 # assume the recipient must have, then the recipient must have
1720 # that filenode.
1720 # that filenode.
1721 for n in msngset:
1721 for n in msngset:
1722 clnode = cl.node(filerevlog.linkrev(n))
1722 clnode = cl.node(filerevlog.linkrev(n))
1723 if clnode in has_cl_set:
1723 if clnode in has_cl_set:
1724 hasset[n] = 1
1724 hasset[n] = 1
1725 prune_parents(filerevlog, hasset, msngset)
1725 prune_parents(filerevlog, hasset, msngset)
1726
1726
1727 # A function generator function that sets up the a context for the
1727 # A function generator function that sets up the a context for the
1728 # inner function.
1728 # inner function.
1729 def lookup_filenode_link_func(fname):
1729 def lookup_filenode_link_func(fname):
1730 msngset = msng_filenode_set[fname]
1730 msngset = msng_filenode_set[fname]
1731 # Lookup the changenode the filenode belongs to.
1731 # Lookup the changenode the filenode belongs to.
1732 def lookup_filenode_link(fnode):
1732 def lookup_filenode_link(fnode):
1733 return msngset[fnode]
1733 return msngset[fnode]
1734 return lookup_filenode_link
1734 return lookup_filenode_link
1735
1735
1736 # Add the nodes that were explicitly requested.
1736 # Add the nodes that were explicitly requested.
1737 def add_extra_nodes(name, nodes):
1737 def add_extra_nodes(name, nodes):
1738 if not extranodes or name not in extranodes:
1738 if not extranodes or name not in extranodes:
1739 return
1739 return
1740
1740
1741 for node, linknode in extranodes[name]:
1741 for node, linknode in extranodes[name]:
1742 if node not in nodes:
1742 if node not in nodes:
1743 nodes[node] = linknode
1743 nodes[node] = linknode
1744
1744
1745 # Now that we have all theses utility functions to help out and
1745 # Now that we have all theses utility functions to help out and
1746 # logically divide up the task, generate the group.
1746 # logically divide up the task, generate the group.
1747 def gengroup():
1747 def gengroup():
1748 # The set of changed files starts empty.
1748 # The set of changed files starts empty.
1749 changedfiles = {}
1749 changedfiles = {}
1750 # Create a changenode group generator that will call our functions
1750 # Create a changenode group generator that will call our functions
1751 # back to lookup the owning changenode and collect information.
1751 # back to lookup the owning changenode and collect information.
1752 group = cl.group(msng_cl_lst, identity,
1752 group = cl.group(msng_cl_lst, identity,
1753 manifest_and_file_collector(changedfiles))
1753 manifest_and_file_collector(changedfiles))
1754 for chnk in group:
1754 for chnk in group:
1755 yield chnk
1755 yield chnk
1756
1756
1757 # The list of manifests has been collected by the generator
1757 # The list of manifests has been collected by the generator
1758 # calling our functions back.
1758 # calling our functions back.
1759 prune_manifests()
1759 prune_manifests()
1760 add_extra_nodes(1, msng_mnfst_set)
1760 add_extra_nodes(1, msng_mnfst_set)
1761 msng_mnfst_lst = msng_mnfst_set.keys()
1761 msng_mnfst_lst = msng_mnfst_set.keys()
1762 # Sort the manifestnodes by revision number.
1762 # Sort the manifestnodes by revision number.
1763 msng_mnfst_lst.sort(cmp_by_rev_func(mnfst))
1763 msng_mnfst_lst.sort(cmp_by_rev_func(mnfst))
1764 # Create a generator for the manifestnodes that calls our lookup
1764 # Create a generator for the manifestnodes that calls our lookup
1765 # and data collection functions back.
1765 # and data collection functions back.
1766 group = mnfst.group(msng_mnfst_lst, lookup_manifest_link,
1766 group = mnfst.group(msng_mnfst_lst, lookup_manifest_link,
1767 filenode_collector(changedfiles))
1767 filenode_collector(changedfiles))
1768 for chnk in group:
1768 for chnk in group:
1769 yield chnk
1769 yield chnk
1770
1770
1771 # These are no longer needed, dereference and toss the memory for
1771 # These are no longer needed, dereference and toss the memory for
1772 # them.
1772 # them.
1773 msng_mnfst_lst = None
1773 msng_mnfst_lst = None
1774 msng_mnfst_set.clear()
1774 msng_mnfst_set.clear()
1775
1775
1776 if extranodes:
1776 if extranodes:
1777 for fname in extranodes:
1777 for fname in extranodes:
1778 if isinstance(fname, int):
1778 if isinstance(fname, int):
1779 continue
1779 continue
1780 add_extra_nodes(fname,
1780 add_extra_nodes(fname,
1781 msng_filenode_set.setdefault(fname, {}))
1781 msng_filenode_set.setdefault(fname, {}))
1782 changedfiles[fname] = 1
1782 changedfiles[fname] = 1
1783 # Go through all our files in order sorted by name.
1783 # Go through all our files in order sorted by name.
1784 for fname in util.sort(changedfiles):
1784 for fname in util.sort(changedfiles):
1785 filerevlog = self.file(fname)
1785 filerevlog = self.file(fname)
1786 if not len(filerevlog):
1786 if not len(filerevlog):
1787 raise util.Abort(_("empty or missing revlog for %s") % fname)
1787 raise util.Abort(_("empty or missing revlog for %s") % fname)
1788 # Toss out the filenodes that the recipient isn't really
1788 # Toss out the filenodes that the recipient isn't really
1789 # missing.
1789 # missing.
1790 if fname in msng_filenode_set:
1790 if fname in msng_filenode_set:
1791 prune_filenodes(fname, filerevlog)
1791 prune_filenodes(fname, filerevlog)
1792 msng_filenode_lst = msng_filenode_set[fname].keys()
1792 msng_filenode_lst = msng_filenode_set[fname].keys()
1793 else:
1793 else:
1794 msng_filenode_lst = []
1794 msng_filenode_lst = []
1795 # If any filenodes are left, generate the group for them,
1795 # If any filenodes are left, generate the group for them,
1796 # otherwise don't bother.
1796 # otherwise don't bother.
1797 if len(msng_filenode_lst) > 0:
1797 if len(msng_filenode_lst) > 0:
1798 yield changegroup.chunkheader(len(fname))
1798 yield changegroup.chunkheader(len(fname))
1799 yield fname
1799 yield fname
1800 # Sort the filenodes by their revision #
1800 # Sort the filenodes by their revision #
1801 msng_filenode_lst.sort(cmp_by_rev_func(filerevlog))
1801 msng_filenode_lst.sort(cmp_by_rev_func(filerevlog))
1802 # Create a group generator and only pass in a changenode
1802 # Create a group generator and only pass in a changenode
1803 # lookup function as we need to collect no information
1803 # lookup function as we need to collect no information
1804 # from filenodes.
1804 # from filenodes.
1805 group = filerevlog.group(msng_filenode_lst,
1805 group = filerevlog.group(msng_filenode_lst,
1806 lookup_filenode_link_func(fname))
1806 lookup_filenode_link_func(fname))
1807 for chnk in group:
1807 for chnk in group:
1808 yield chnk
1808 yield chnk
1809 if fname in msng_filenode_set:
1809 if fname in msng_filenode_set:
1810 # Don't need this anymore, toss it to free memory.
1810 # Don't need this anymore, toss it to free memory.
1811 del msng_filenode_set[fname]
1811 del msng_filenode_set[fname]
1812 # Signal that no more groups are left.
1812 # Signal that no more groups are left.
1813 yield changegroup.closechunk()
1813 yield changegroup.closechunk()
1814
1814
1815 if msng_cl_lst:
1815 if msng_cl_lst:
1816 self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source)
1816 self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source)
1817
1817
1818 return util.chunkbuffer(gengroup())
1818 return util.chunkbuffer(gengroup())
1819
1819
1820 def changegroup(self, basenodes, source):
1820 def changegroup(self, basenodes, source):
1821 """Generate a changegroup of all nodes that we have that a recipient
1821 """Generate a changegroup of all nodes that we have that a recipient
1822 doesn't.
1822 doesn't.
1823
1823
1824 This is much easier than the previous function as we can assume that
1824 This is much easier than the previous function as we can assume that
1825 the recipient has any changenode we aren't sending them."""
1825 the recipient has any changenode we aren't sending them."""
1826
1826
1827 self.hook('preoutgoing', throw=True, source=source)
1827 self.hook('preoutgoing', throw=True, source=source)
1828
1828
1829 cl = self.changelog
1829 cl = self.changelog
1830 nodes = cl.nodesbetween(basenodes, None)[0]
1830 nodes = cl.nodesbetween(basenodes, None)[0]
1831 revset = dict.fromkeys([cl.rev(n) for n in nodes])
1831 revset = dict.fromkeys([cl.rev(n) for n in nodes])
1832 self.changegroupinfo(nodes, source)
1832 self.changegroupinfo(nodes, source)
1833
1833
1834 def identity(x):
1834 def identity(x):
1835 return x
1835 return x
1836
1836
1837 def gennodelst(log):
1837 def gennodelst(log):
1838 for r in log:
1838 for r in log:
1839 n = log.node(r)
1839 n = log.node(r)
1840 if log.linkrev(n) in revset:
1840 if log.linkrev(n) in revset:
1841 yield n
1841 yield n
1842
1842
1843 def changed_file_collector(changedfileset):
1843 def changed_file_collector(changedfileset):
1844 def collect_changed_files(clnode):
1844 def collect_changed_files(clnode):
1845 c = cl.read(clnode)
1845 c = cl.read(clnode)
1846 for fname in c[3]:
1846 for fname in c[3]:
1847 changedfileset[fname] = 1
1847 changedfileset[fname] = 1
1848 return collect_changed_files
1848 return collect_changed_files
1849
1849
1850 def lookuprevlink_func(revlog):
1850 def lookuprevlink_func(revlog):
1851 def lookuprevlink(n):
1851 def lookuprevlink(n):
1852 return cl.node(revlog.linkrev(n))
1852 return cl.node(revlog.linkrev(n))
1853 return lookuprevlink
1853 return lookuprevlink
1854
1854
1855 def gengroup():
1855 def gengroup():
1856 # construct a list of all changed files
1856 # construct a list of all changed files
1857 changedfiles = {}
1857 changedfiles = {}
1858
1858
1859 for chnk in cl.group(nodes, identity,
1859 for chnk in cl.group(nodes, identity,
1860 changed_file_collector(changedfiles)):
1860 changed_file_collector(changedfiles)):
1861 yield chnk
1861 yield chnk
1862
1862
1863 mnfst = self.manifest
1863 mnfst = self.manifest
1864 nodeiter = gennodelst(mnfst)
1864 nodeiter = gennodelst(mnfst)
1865 for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)):
1865 for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)):
1866 yield chnk
1866 yield chnk
1867
1867
1868 for fname in util.sort(changedfiles):
1868 for fname in util.sort(changedfiles):
1869 filerevlog = self.file(fname)
1869 filerevlog = self.file(fname)
1870 if not len(filerevlog):
1870 if not len(filerevlog):
1871 raise util.Abort(_("empty or missing revlog for %s") % fname)
1871 raise util.Abort(_("empty or missing revlog for %s") % fname)
1872 nodeiter = gennodelst(filerevlog)
1872 nodeiter = gennodelst(filerevlog)
1873 nodeiter = list(nodeiter)
1873 nodeiter = list(nodeiter)
1874 if nodeiter:
1874 if nodeiter:
1875 yield changegroup.chunkheader(len(fname))
1875 yield changegroup.chunkheader(len(fname))
1876 yield fname
1876 yield fname
1877 lookup = lookuprevlink_func(filerevlog)
1877 lookup = lookuprevlink_func(filerevlog)
1878 for chnk in filerevlog.group(nodeiter, lookup):
1878 for chnk in filerevlog.group(nodeiter, lookup):
1879 yield chnk
1879 yield chnk
1880
1880
1881 yield changegroup.closechunk()
1881 yield changegroup.closechunk()
1882
1882
1883 if nodes:
1883 if nodes:
1884 self.hook('outgoing', node=hex(nodes[0]), source=source)
1884 self.hook('outgoing', node=hex(nodes[0]), source=source)
1885
1885
1886 return util.chunkbuffer(gengroup())
1886 return util.chunkbuffer(gengroup())
1887
1887
1888 def addchangegroup(self, source, srctype, url, emptyok=False):
1888 def addchangegroup(self, source, srctype, url, emptyok=False):
1889 """add changegroup to repo.
1889 """add changegroup to repo.
1890
1890
1891 return values:
1891 return values:
1892 - nothing changed or no source: 0
1892 - nothing changed or no source: 0
1893 - more heads than before: 1+added heads (2..n)
1893 - more heads than before: 1+added heads (2..n)
1894 - less heads than before: -1-removed heads (-2..-n)
1894 - less heads than before: -1-removed heads (-2..-n)
1895 - number of heads stays the same: 1
1895 - number of heads stays the same: 1
1896 """
1896 """
1897 def csmap(x):
1897 def csmap(x):
1898 self.ui.debug(_("add changeset %s\n") % short(x))
1898 self.ui.debug(_("add changeset %s\n") % short(x))
1899 return len(cl)
1899 return len(cl)
1900
1900
1901 def revmap(x):
1901 def revmap(x):
1902 return cl.rev(x)
1902 return cl.rev(x)
1903
1903
1904 if not source:
1904 if not source:
1905 return 0
1905 return 0
1906
1906
1907 self.hook('prechangegroup', throw=True, source=srctype, url=url)
1907 self.hook('prechangegroup', throw=True, source=srctype, url=url)
1908
1908
1909 changesets = files = revisions = 0
1909 changesets = files = revisions = 0
1910
1910
1911 # write changelog data to temp files so concurrent readers will not see
1911 # write changelog data to temp files so concurrent readers will not see
1912 # inconsistent view
1912 # inconsistent view
1913 cl = self.changelog
1913 cl = self.changelog
1914 cl.delayupdate()
1914 cl.delayupdate()
1915 oldheads = len(cl.heads())
1915 oldheads = len(cl.heads())
1916
1916
1917 tr = self.transaction()
1917 tr = self.transaction()
1918 try:
1918 try:
1919 trp = weakref.proxy(tr)
1919 trp = weakref.proxy(tr)
1920 # pull off the changeset group
1920 # pull off the changeset group
1921 self.ui.status(_("adding changesets\n"))
1921 self.ui.status(_("adding changesets\n"))
1922 cor = len(cl) - 1
1922 cor = len(cl) - 1
1923 chunkiter = changegroup.chunkiter(source)
1923 chunkiter = changegroup.chunkiter(source)
1924 if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok:
1924 if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok:
1925 raise util.Abort(_("received changelog group is empty"))
1925 raise util.Abort(_("received changelog group is empty"))
1926 cnr = len(cl) - 1
1926 cnr = len(cl) - 1
1927 changesets = cnr - cor
1927 changesets = cnr - cor
1928
1928
1929 # pull off the manifest group
1929 # pull off the manifest group
1930 self.ui.status(_("adding manifests\n"))
1930 self.ui.status(_("adding manifests\n"))
1931 chunkiter = changegroup.chunkiter(source)
1931 chunkiter = changegroup.chunkiter(source)
1932 # no need to check for empty manifest group here:
1932 # no need to check for empty manifest group here:
1933 # if the result of the merge of 1 and 2 is the same in 3 and 4,
1933 # if the result of the merge of 1 and 2 is the same in 3 and 4,
1934 # no new manifest will be created and the manifest group will
1934 # no new manifest will be created and the manifest group will
1935 # be empty during the pull
1935 # be empty during the pull
1936 self.manifest.addgroup(chunkiter, revmap, trp)
1936 self.manifest.addgroup(chunkiter, revmap, trp)
1937
1937
1938 # process the files
1938 # process the files
1939 self.ui.status(_("adding file changes\n"))
1939 self.ui.status(_("adding file changes\n"))
1940 while 1:
1940 while 1:
1941 f = changegroup.getchunk(source)
1941 f = changegroup.getchunk(source)
1942 if not f:
1942 if not f:
1943 break
1943 break
1944 self.ui.debug(_("adding %s revisions\n") % f)
1944 self.ui.debug(_("adding %s revisions\n") % f)
1945 fl = self.file(f)
1945 fl = self.file(f)
1946 o = len(fl)
1946 o = len(fl)
1947 chunkiter = changegroup.chunkiter(source)
1947 chunkiter = changegroup.chunkiter(source)
1948 if fl.addgroup(chunkiter, revmap, trp) is None:
1948 if fl.addgroup(chunkiter, revmap, trp) is None:
1949 raise util.Abort(_("received file revlog group is empty"))
1949 raise util.Abort(_("received file revlog group is empty"))
1950 revisions += len(fl) - o
1950 revisions += len(fl) - o
1951 files += 1
1951 files += 1
1952
1952
1953 # make changelog see real files again
1953 # make changelog see real files again
1954 cl.finalize(trp)
1954 cl.finalize(trp)
1955
1955
1956 newheads = len(self.changelog.heads())
1956 newheads = len(self.changelog.heads())
1957 heads = ""
1957 heads = ""
1958 if oldheads and newheads != oldheads:
1958 if oldheads and newheads != oldheads:
1959 heads = _(" (%+d heads)") % (newheads - oldheads)
1959 heads = _(" (%+d heads)") % (newheads - oldheads)
1960
1960
1961 self.ui.status(_("added %d changesets"
1961 self.ui.status(_("added %d changesets"
1962 " with %d changes to %d files%s\n")
1962 " with %d changes to %d files%s\n")
1963 % (changesets, revisions, files, heads))
1963 % (changesets, revisions, files, heads))
1964
1964
1965 if changesets > 0:
1965 if changesets > 0:
1966 self.hook('pretxnchangegroup', throw=True,
1966 self.hook('pretxnchangegroup', throw=True,
1967 node=hex(self.changelog.node(cor+1)), source=srctype,
1967 node=hex(self.changelog.node(cor+1)), source=srctype,
1968 url=url)
1968 url=url)
1969
1969
1970 tr.close()
1970 tr.close()
1971 finally:
1971 finally:
1972 del tr
1972 del tr
1973
1973
1974 if changesets > 0:
1974 if changesets > 0:
1975 # forcefully update the on-disk branch cache
1975 # forcefully update the on-disk branch cache
1976 self.ui.debug(_("updating the branch cache\n"))
1976 self.ui.debug(_("updating the branch cache\n"))
1977 self.branchtags()
1977 self.branchtags()
1978 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
1978 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
1979 source=srctype, url=url)
1979 source=srctype, url=url)
1980
1980
1981 for i in xrange(cor + 1, cnr + 1):
1981 for i in xrange(cor + 1, cnr + 1):
1982 self.hook("incoming", node=hex(self.changelog.node(i)),
1982 self.hook("incoming", node=hex(self.changelog.node(i)),
1983 source=srctype, url=url)
1983 source=srctype, url=url)
1984
1984
1985 # never return 0 here:
1985 # never return 0 here:
1986 if newheads < oldheads:
1986 if newheads < oldheads:
1987 return newheads - oldheads - 1
1987 return newheads - oldheads - 1
1988 else:
1988 else:
1989 return newheads - oldheads + 1
1989 return newheads - oldheads + 1
1990
1990
1991
1991
1992 def stream_in(self, remote):
1992 def stream_in(self, remote):
1993 fp = remote.stream_out()
1993 fp = remote.stream_out()
1994 l = fp.readline()
1994 l = fp.readline()
1995 try:
1995 try:
1996 resp = int(l)
1996 resp = int(l)
1997 except ValueError:
1997 except ValueError:
1998 raise util.UnexpectedOutput(
1998 raise util.UnexpectedOutput(
1999 _('Unexpected response from remote server:'), l)
1999 _('Unexpected response from remote server:'), l)
2000 if resp == 1:
2000 if resp == 1:
2001 raise util.Abort(_('operation forbidden by server'))
2001 raise util.Abort(_('operation forbidden by server'))
2002 elif resp == 2:
2002 elif resp == 2:
2003 raise util.Abort(_('locking the remote repository failed'))
2003 raise util.Abort(_('locking the remote repository failed'))
2004 elif resp != 0:
2004 elif resp != 0:
2005 raise util.Abort(_('the server sent an unknown error code'))
2005 raise util.Abort(_('the server sent an unknown error code'))
2006 self.ui.status(_('streaming all changes\n'))
2006 self.ui.status(_('streaming all changes\n'))
2007 l = fp.readline()
2007 l = fp.readline()
2008 try:
2008 try:
2009 total_files, total_bytes = map(int, l.split(' ', 1))
2009 total_files, total_bytes = map(int, l.split(' ', 1))
2010 except (ValueError, TypeError):
2010 except (ValueError, TypeError):
2011 raise util.UnexpectedOutput(
2011 raise util.UnexpectedOutput(
2012 _('Unexpected response from remote server:'), l)
2012 _('Unexpected response from remote server:'), l)
2013 self.ui.status(_('%d files to transfer, %s of data\n') %
2013 self.ui.status(_('%d files to transfer, %s of data\n') %
2014 (total_files, util.bytecount(total_bytes)))
2014 (total_files, util.bytecount(total_bytes)))
2015 start = time.time()
2015 start = time.time()
2016 for i in xrange(total_files):
2016 for i in xrange(total_files):
2017 # XXX doesn't support '\n' or '\r' in filenames
2017 # XXX doesn't support '\n' or '\r' in filenames
2018 l = fp.readline()
2018 l = fp.readline()
2019 try:
2019 try:
2020 name, size = l.split('\0', 1)
2020 name, size = l.split('\0', 1)
2021 size = int(size)
2021 size = int(size)
2022 except ValueError, TypeError:
2022 except ValueError, TypeError:
2023 raise util.UnexpectedOutput(
2023 raise util.UnexpectedOutput(
2024 _('Unexpected response from remote server:'), l)
2024 _('Unexpected response from remote server:'), l)
2025 self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size)))
2025 self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size)))
2026 ofp = self.sopener(name, 'w')
2026 ofp = self.sopener(name, 'w')
2027 for chunk in util.filechunkiter(fp, limit=size):
2027 for chunk in util.filechunkiter(fp, limit=size):
2028 ofp.write(chunk)
2028 ofp.write(chunk)
2029 ofp.close()
2029 ofp.close()
2030 elapsed = time.time() - start
2030 elapsed = time.time() - start
2031 if elapsed <= 0:
2031 if elapsed <= 0:
2032 elapsed = 0.001
2032 elapsed = 0.001
2033 self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
2033 self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
2034 (util.bytecount(total_bytes), elapsed,
2034 (util.bytecount(total_bytes), elapsed,
2035 util.bytecount(total_bytes / elapsed)))
2035 util.bytecount(total_bytes / elapsed)))
2036 self.invalidate()
2036 self.invalidate()
2037 return len(self.heads()) + 1
2037 return len(self.heads()) + 1
2038
2038
2039 def clone(self, remote, heads=[], stream=False):
2039 def clone(self, remote, heads=[], stream=False):
2040 '''clone remote repository.
2040 '''clone remote repository.
2041
2041
2042 keyword arguments:
2042 keyword arguments:
2043 heads: list of revs to clone (forces use of pull)
2043 heads: list of revs to clone (forces use of pull)
2044 stream: use streaming clone if possible'''
2044 stream: use streaming clone if possible'''
2045
2045
2046 # now, all clients that can request uncompressed clones can
2046 # now, all clients that can request uncompressed clones can
2047 # read repo formats supported by all servers that can serve
2047 # read repo formats supported by all servers that can serve
2048 # them.
2048 # them.
2049
2049
2050 # if revlog format changes, client will have to check version
2050 # if revlog format changes, client will have to check version
2051 # and format flags on "stream" capability, and use
2051 # and format flags on "stream" capability, and use
2052 # uncompressed only if compatible.
2052 # uncompressed only if compatible.
2053
2053
2054 if stream and not heads and remote.capable('stream'):
2054 if stream and not heads and remote.capable('stream'):
2055 return self.stream_in(remote)
2055 return self.stream_in(remote)
2056 return self.pull(remote, heads)
2056 return self.pull(remote, heads)
2057
2057
2058 # used to avoid circular references so destructors work
2058 # used to avoid circular references so destructors work
2059 def aftertrans(files):
2059 def aftertrans(files):
2060 renamefiles = [tuple(t) for t in files]
2060 renamefiles = [tuple(t) for t in files]
2061 def a():
2061 def a():
2062 for src, dest in renamefiles:
2062 for src, dest in renamefiles:
2063 util.rename(src, dest)
2063 util.rename(src, dest)
2064 return a
2064 return a
2065
2065
2066 def instance(ui, path, create):
2066 def instance(ui, path, create):
2067 return localrepository(ui, util.drop_scheme('file', path), create)
2067 return localrepository(ui, util.drop_scheme('file', path), create)
2068
2068
2069 def islocal(path):
2069 def islocal(path):
2070 return True
2070 return True
@@ -1,205 +1,205 b''
1 hg convert [OPTION]... SOURCE [DEST [REVMAP]]
1 hg convert [OPTION]... SOURCE [DEST [REVMAP]]
2
2
3 Convert a foreign SCM repository to a Mercurial one.
3 Convert a foreign SCM repository to a Mercurial one.
4
4
5 Accepted source formats:
5 Accepted source formats:
6 - Mercurial
6 - Mercurial
7 - CVS
7 - CVS
8 - Darcs
8 - Darcs
9 - git
9 - git
10 - Subversion
10 - Subversion
11 - Monotone
11 - Monotone
12 - GNU Arch
12 - GNU Arch
13
13
14 Accepted destination formats:
14 Accepted destination formats:
15 - Mercurial
15 - Mercurial
16 - Subversion (history on branches is not preserved)
16 - Subversion (history on branches is not preserved)
17
17
18 If no revision is given, all revisions will be converted. Otherwise,
18 If no revision is given, all revisions will be converted. Otherwise,
19 convert will only import up to the named revision (given in a format
19 convert will only import up to the named revision (given in a format
20 understood by the source).
20 understood by the source).
21
21
22 If no destination directory name is specified, it defaults to the
22 If no destination directory name is specified, it defaults to the
23 basename of the source with '-hg' appended. If the destination
23 basename of the source with '-hg' appended. If the destination
24 repository doesn't exist, it will be created.
24 repository doesn't exist, it will be created.
25
25
26 If <REVMAP> isn't given, it will be put in a default location
26 If <REVMAP> isn't given, it will be put in a default location
27 (<dest>/.hg/shamap by default). The <REVMAP> is a simple text
27 (<dest>/.hg/shamap by default). The <REVMAP> is a simple text
28 file that maps each source commit ID to the destination ID for
28 file that maps each source commit ID to the destination ID for
29 that revision, like so:
29 that revision, like so:
30 <source ID> <destination ID>
30 <source ID> <destination ID>
31
31
32 If the file doesn't exist, it's automatically created. It's updated
32 If the file doesn't exist, it's automatically created. It's updated
33 on each commit copied, so convert-repo can be interrupted and can
33 on each commit copied, so convert-repo can be interrupted and can
34 be run repeatedly to copy new commits.
34 be run repeatedly to copy new commits.
35
35
36 The [username mapping] file is a simple text file that maps each source
36 The [username mapping] file is a simple text file that maps each source
37 commit author to a destination commit author. It is handy for source SCMs
37 commit author to a destination commit author. It is handy for source SCMs
38 that use unix logins to identify authors (eg: CVS). One line per author
38 that use unix logins to identify authors (eg: CVS). One line per author
39 mapping and the line format is:
39 mapping and the line format is:
40 srcauthor=whatever string you want
40 srcauthor=whatever string you want
41
41
42 The filemap is a file that allows filtering and remapping of files
42 The filemap is a file that allows filtering and remapping of files
43 and directories. Comment lines start with '#'. Each line can
43 and directories. Comment lines start with '#'. Each line can
44 contain one of the following directives:
44 contain one of the following directives:
45
45
46 include path/to/file
46 include path/to/file
47
47
48 exclude path/to/file
48 exclude path/to/file
49
49
50 rename from/file to/file
50 rename from/file to/file
51
51
52 The 'include' directive causes a file, or all files under a
52 The 'include' directive causes a file, or all files under a
53 directory, to be included in the destination repository, and the
53 directory, to be included in the destination repository, and the
54 exclusion of all other files and dirs not explicitely included.
54 exclusion of all other files and dirs not explicitely included.
55 The 'exclude' directive causes files or directories to be omitted.
55 The 'exclude' directive causes files or directories to be omitted.
56 The 'rename' directive renames a file or directory. To rename from a
56 The 'rename' directive renames a file or directory. To rename from a
57 subdirectory into the root of the repository, use '.' as the path to
57 subdirectory into the root of the repository, use '.' as the path to
58 rename to.
58 rename to.
59
59
60 The splicemap is a file that allows insertion of synthetic
60 The splicemap is a file that allows insertion of synthetic
61 history, letting you specify the parents of a revision. This is
61 history, letting you specify the parents of a revision. This is
62 useful if you want to e.g. give a Subversion merge two parents, or
62 useful if you want to e.g. give a Subversion merge two parents, or
63 graft two disconnected series of history together. Each entry
63 graft two disconnected series of history together. Each entry
64 contains a key, followed by a space, followed by one or two
64 contains a key, followed by a space, followed by one or two
65 values, separated by spaces. The key is the revision ID in the
65 values, separated by spaces. The key is the revision ID in the
66 source revision control system whose parents should be modified
66 source revision control system whose parents should be modified
67 (same format as a key in .hg/shamap). The values are the revision
67 (same format as a key in .hg/shamap). The values are the revision
68 IDs (in either the source or destination revision control system)
68 IDs (in either the source or destination revision control system)
69 that should be used as the new parents for that node.
69 that should be used as the new parents for that node.
70
70
71 Mercurial Source
71 Mercurial Source
72 -----------------
72 -----------------
73
73
74 --config convert.hg.saverev=True (boolean)
74 --config convert.hg.saverev=True (boolean)
75 allow target to preserve source revision ID
75 allow target to preserve source revision ID
76 --config convert.hg.startrev=0 (hg revision identifier)
76 --config convert.hg.startrev=0 (hg revision identifier)
77 convert start revision and its descendants
77 convert start revision and its descendants
78
78
79 CVS Source
79 CVS Source
80 ----------
80 ----------
81
81
82 CVS source will use a sandbox (i.e. a checked-out copy) from CVS
82 CVS source will use a sandbox (i.e. a checked-out copy) from CVS
83 to indicate the starting point of what will be converted. Direct
83 to indicate the starting point of what will be converted. Direct
84 access to the repository files is not needed, unless of course
84 access to the repository files is not needed, unless of course
85 the repository is :local:. The conversion uses the top level
85 the repository is :local:. The conversion uses the top level
86 directory in the sandbox to find the CVS repository, and then uses
86 directory in the sandbox to find the CVS repository, and then uses
87 CVS rlog commands to find files to convert. This means that unless
87 CVS rlog commands to find files to convert. This means that unless
88 a filemap is given, all files under the starting directory will be
88 a filemap is given, all files under the starting directory will be
89 converted, and that any directory reorganisation in the CVS
89 converted, and that any directory reorganisation in the CVS
90 sandbox is ignored.
90 sandbox is ignored.
91
91
92 Because CVS does not have changesets, it is necessary to collect
92 Because CVS does not have changesets, it is necessary to collect
93 individual commits to CVS and merge them into changesets. CVS source
93 individual commits to CVS and merge them into changesets. CVS source
94 can use the external 'cvsps' program (this is a legacy option and may
94 can use the external 'cvsps' program (this is a legacy option and may
95 be removed in future) or use its internal changeset merging code.
95 be removed in future) or use its internal changeset merging code.
96 External cvsps is default, and options may be passed to it by setting
96 External cvsps is default, and options may be passed to it by setting
97 --config convert.cvsps='cvsps -A -u --cvs-direct -q'
97 --config convert.cvsps='cvsps -A -u --cvs-direct -q'
98 The options shown are the defaults.
98 The options shown are the defaults.
99
99
100 Internal cvsps is selected by setting
100 Internal cvsps is selected by setting
101 --config convert.cvsps=builtin
101 --config convert.cvsps=builtin
102 and has a few more configurable options:
102 and has a few more configurable options:
103 --config convert.cvsps.fuzz=60 (integer)
103 --config convert.cvsps.fuzz=60 (integer)
104 Specify the maximum time (in seconds) that is allowed between
104 Specify the maximum time (in seconds) that is allowed between
105 commits with identical user and log message in a single
105 commits with identical user and log message in a single
106 changeset. When very large files were checked in as part
106 changeset. When very large files were checked in as part
107 of a changeset then the default may not be long enough.
107 of a changeset then the default may not be long enough.
108 --config convert.cvsps.mergeto='{{mergetobranch ([-\w]+)}}'
108 --config convert.cvsps.mergeto='{{mergetobranch ([-\w]+)}}'
109 Specify a regular expression to which commit log messages are
109 Specify a regular expression to which commit log messages are
110 matched. If a match occurs, then the conversion process will
110 matched. If a match occurs, then the conversion process will
111 insert a dummy revision merging the branch on which this log
111 insert a dummy revision merging the branch on which this log
112 message occurs to the branch indicated in the regex.
112 message occurs to the branch indicated in the regex.
113 --config convert.cvsps.mergefrom='{{mergefrombranch ([-\w]+)}}'
113 --config convert.cvsps.mergefrom='{{mergefrombranch ([-\w]+)}}'
114 Specify a regular expression to which commit log messages are
114 Specify a regular expression to which commit log messages are
115 matched. If a match occurs, then the conversion process will
115 matched. If a match occurs, then the conversion process will
116 add the most recent revision on the branch indicated in the
116 add the most recent revision on the branch indicated in the
117 regex as the second parent of the changeset.
117 regex as the second parent of the changeset.
118
118
119 The hgext/convert/cvsps wrapper script allows the builtin changeset
119 The hgext/convert/cvsps wrapper script allows the builtin changeset
120 merging code to be run without doing a conversion. Its parameters and
120 merging code to be run without doing a conversion. Its parameters and
121 output are similar to that of cvsps 2.1.
121 output are similar to that of cvsps 2.1.
122
122
123 Subversion Source
123 Subversion Source
124 -----------------
124 -----------------
125
125
126 Subversion source detects classical trunk/branches/tags layouts.
126 Subversion source detects classical trunk/branches/tags layouts.
127 By default, the supplied "svn://repo/path/" source URL is
127 By default, the supplied "svn://repo/path/" source URL is
128 converted as a single branch. If "svn://repo/path/trunk" exists
128 converted as a single branch. If "svn://repo/path/trunk" exists
129 it replaces the default branch. If "svn://repo/path/branches"
129 it replaces the default branch. If "svn://repo/path/branches"
130 exists, its subdirectories are listed as possible branches. If
130 exists, its subdirectories are listed as possible branches. If
131 "svn://repo/path/tags" exists, it is looked for tags referencing
131 "svn://repo/path/tags" exists, it is looked for tags referencing
132 converted branches. Default "trunk", "branches" and "tags" values
132 converted branches. Default "trunk", "branches" and "tags" values
133 can be overriden with following options. Set them to paths
133 can be overriden with following options. Set them to paths
134 relative to the source URL, or leave them blank to disable
134 relative to the source URL, or leave them blank to disable
135 autodetection.
135 autodetection.
136
136
137 --config convert.svn.branches=branches (directory name)
137 --config convert.svn.branches=branches (directory name)
138 specify the directory containing branches
138 specify the directory containing branches
139 --config convert.svn.tags=tags (directory name)
139 --config convert.svn.tags=tags (directory name)
140 specify the directory containing tags
140 specify the directory containing tags
141 --config convert.svn.trunk=trunk (directory name)
141 --config convert.svn.trunk=trunk (directory name)
142 specify the name of the trunk branch
142 specify the name of the trunk branch
143
143
144 Source history can be retrieved starting at a specific revision,
144 Source history can be retrieved starting at a specific revision,
145 instead of being integrally converted. Only single branch
145 instead of being integrally converted. Only single branch
146 conversions are supported.
146 conversions are supported.
147
147
148 --config convert.svn.startrev=0 (svn revision number)
148 --config convert.svn.startrev=0 (svn revision number)
149 specify start Subversion revision.
149 specify start Subversion revision.
150
150
151 Mercurial Destination
151 Mercurial Destination
152 ---------------------
152 ---------------------
153
153
154 --config convert.hg.clonebranches=False (boolean)
154 --config convert.hg.clonebranches=False (boolean)
155 dispatch source branches in separate clones.
155 dispatch source branches in separate clones.
156 --config convert.hg.tagsbranch=default (branch name)
156 --config convert.hg.tagsbranch=default (branch name)
157 tag revisions branch name
157 tag revisions branch name
158 --config convert.hg.usebranchnames=True (boolean)
158 --config convert.hg.usebranchnames=True (boolean)
159 preserve branch names
159 preserve branch names
160
160
161 options:
161 options:
162
162
163 -A --authors username mapping filename
163 -A --authors username mapping filename
164 -d --dest-type destination repository type
164 -d --dest-type destination repository type
165 --filemap remap file names using contents of file
165 --filemap remap file names using contents of file
166 -r --rev import up to target revision REV
166 -r --rev import up to target revision REV
167 -s --source-type source repository type
167 -s --source-type source repository type
168 --splicemap splice synthesized history into place
168 --splicemap splice synthesized history into place
169 --datesort try to sort changesets by date
169 --datesort try to sort changesets by date
170
170
171 use "hg -v help convert" to show global options
171 use "hg -v help convert" to show global options
172 adding a
172 adding a
173 assuming destination a-hg
173 assuming destination a-hg
174 initializing destination a-hg repository
174 initializing destination a-hg repository
175 scanning source...
175 scanning source...
176 sorting...
176 sorting...
177 converting...
177 converting...
178 4 a
178 4 a
179 3 b
179 3 b
180 2 c
180 2 c
181 1 d
181 1 d
182 0 e
182 0 e
183 pulling from ../a
183 pulling from ../a
184 searching for changes
184 searching for changes
185 no changes found
185 no changes found
186 % should fail
186 % should fail
187 initializing destination bogusfile repository
187 initializing destination bogusfile repository
188 abort: cannot create new bundle repository
188 abort: cannot create new bundle repository
189 % should fail
189 % should fail
190 abort: Permission denied: bogusdir
190 abort: Permission denied: bogusdir
191 % should succeed
191 % should succeed
192 initializing destination bogusdir repository
192 initializing destination bogusdir repository
193 scanning source...
193 scanning source...
194 sorting...
194 sorting...
195 converting...
195 converting...
196 4 a
196 4 a
197 3 b
197 3 b
198 2 c
198 2 c
199 1 d
199 1 d
200 0 e
200 0 e
201 % test pre and post conversion actions
201 % test pre and post conversion actions
202 run hg source pre-conversion action
202 run hg source pre-conversion action
203 run hg sink pre-conversion action
203 run hg sink pre-conversion action
204 run hg sink post-conversion action
204 run hg sink post-conversion action
205 run hg source post-conversion action
205 run hg source post-conversion action
@@ -1,74 +1,74 b''
1 import os
1 import os
2 from mercurial import hg, ui, merge
2 from mercurial import hg, ui, merge
3 from hgext import graphlog
3 from hgext import graphlog
4
4
5 u = ui.ui()
5 u = ui.ui()
6
6
7 repo = hg.repository(u, 'test1', create=1)
7 repo = hg.repository(u, 'test1', create=1)
8 os.chdir('test1')
8 os.chdir('test1')
9
9
10 def commit(text, time):
10 def commit(text, time):
11 repo.commit(text=text, date="%d 0" % time)
11 repo.commit(text=text, date="%d 0" % time)
12
12
13 def addcommit(name, time):
13 def addcommit(name, time):
14 f = file(name, 'w')
14 f = file(name, 'w')
15 f.write('%s\n' % name)
15 f.write('%s\n' % name)
16 f.close()
16 f.close()
17 repo.add([name])
17 repo.add([name])
18 commit(name, time)
18 commit(name, time)
19
19
20 def update(rev):
20 def update(rev):
21 merge.update(repo, rev, False, True, False)
21 merge.update(repo, rev, False, True, False)
22
22
23 def merge_(rev):
23 def merge_(rev):
24 merge.update(repo, rev, True, False, False)
24 merge.update(repo, rev, True, False, False)
25
25
26 if __name__ == '__main__':
26 if __name__ == '__main__':
27 addcommit("A", 0)
27 addcommit("A", 0)
28 addcommit("B", 1)
28 addcommit("B", 1)
29
29
30 update(0)
30 update(0)
31 addcommit("C", 2)
31 addcommit("C", 2)
32
32
33 merge_(1)
33 merge_(1)
34 commit("D", 3)
34 commit("D", 3)
35
35
36 update(2)
36 update(2)
37 addcommit("E", 4)
37 addcommit("E", 4)
38 addcommit("F", 5)
38 addcommit("F", 5)
39
39
40 update(3)
40 update(3)
41 addcommit("G", 6)
41 addcommit("G", 6)
42
42
43 merge_(5)
43 merge_(5)
44 commit("H", 7)
44 commit("H", 7)
45
45
46 update(5)
46 update(5)
47 addcommit("I", 8)
47 addcommit("I", 8)
48
48
49 # Ancestors
49 # Ancestors
50 print 'Ancestors of 5'
50 print 'Ancestors of 5'
51 for r in repo.changelog.ancestors(5):
51 for r in repo.changelog.ancestors(5):
52 print r,
52 print r,
53
53
54 print '\nAncestors of 6 and 5'
54 print '\nAncestors of 6 and 5'
55 for r in repo.changelog.ancestors(6, 5):
55 for r in repo.changelog.ancestors(6, 5):
56 print r,
56 print r,
57
57
58 print '\nAncestors of 5 and 4'
58 print '\nAncestors of 5 and 4'
59 for r in repo.changelog.ancestors(5, 4):
59 for r in repo.changelog.ancestors(5, 4):
60 print r,
60 print r,
61
61
62 # Descendants
62 # Descendants
63 print '\n\nDescendants of 5'
63 print '\n\nDescendants of 5'
64 for r in repo.changelog.descendants(5):
64 for r in repo.changelog.descendants(5):
65 print r,
65 print r,
66
66
67 print '\nDescendants of 5 and 3'
67 print '\nDescendants of 5 and 3'
68 for r in repo.changelog.descendants(5, 3):
68 for r in repo.changelog.descendants(5, 3):
69 print r,
69 print r,
70
70
71 print '\nDescendants of 5 and 4'
71 print '\nDescendants of 5 and 4'
72 for r in repo.changelog.descendants(5, 4):
72 for r in repo.changelog.descendants(5, 4):
73 print r,
73 print r,
74
74
General Comments 0
You need to be logged in to leave comments. Login now