Show More
@@ -1276,12 +1276,80 b' class queue:' | |||
|
1276 | 1276 | self.ui.write("No patches applied\n") |
|
1277 | 1277 | return 1 |
|
1278 | 1278 | |
|
1279 |
def qimport(self, repo, files, patchname=None, existing=None, |
|
|
1280 | if len(files) > 1 and patchname: | |
|
1279 | def qimport(self, repo, files, patchname=None, rev=None, existing=None, | |
|
1280 | force=None): | |
|
1281 | def checkseries(patchname): | |
|
1282 | if patchname in self.series: | |
|
1283 | raise util.Abort(_('patch %s is already in the series file') | |
|
1284 | % patchname) | |
|
1285 | def checkfile(patchname): | |
|
1286 | if not force and os.path.exists(self.join(patchname)): | |
|
1287 | raise util.Abort(_('patch "%s" already exists') | |
|
1288 | % patchname) | |
|
1289 | ||
|
1290 | if rev: | |
|
1291 | if files: | |
|
1292 | raise util.Abort(_('option "-r" not valid when importing ' | |
|
1293 | 'files')) | |
|
1294 | rev = [int(r) for r in cmdutil.revrange(self.ui, repo, rev)] | |
|
1295 | rev.sort(lambda x, y: cmp(y, x)) | |
|
1296 | if (len(files) > 1 or len(rev) > 1) and patchname: | |
|
1281 | 1297 | raise util.Abort(_('option "-n" not valid when importing multiple ' |
|
1282 |
' |
|
|
1298 | 'patches')) | |
|
1283 | 1299 | i = 0 |
|
1284 | 1300 | added = [] |
|
1301 | if rev: | |
|
1302 | # If mq patches are applied, we can only import revisions | |
|
1303 | # that form a linear path to qbase. | |
|
1304 | # Otherwise, they should form a linear path to a head. | |
|
1305 | heads = repo.changelog.heads(repo.changelog.node(rev[-1])) | |
|
1306 | if len(heads) > 1: | |
|
1307 | raise util.Abort(_('revision %d is the root of more than one ' | |
|
1308 | 'branch') % rev[-1]) | |
|
1309 | if self.applied: | |
|
1310 | base = revlog.hex(repo.changelog.node(rev[0])) | |
|
1311 | if base in [n.rev for n in self.applied]: | |
|
1312 | raise util.Abort(_('revision %d is already managed') | |
|
1313 | % rev[0]) | |
|
1314 | if heads != [revlog.bin(self.applied[-1].rev)]: | |
|
1315 | raise util.Abort(_('revision %d is not the parent of ' | |
|
1316 | 'the queue') % rev[0]) | |
|
1317 | base = repo.changelog.rev(revlog.bin(self.applied[0].rev)) | |
|
1318 | lastparent = repo.changelog.parentrevs(base)[0] | |
|
1319 | else: | |
|
1320 | if heads != [repo.changelog.node(rev[0])]: | |
|
1321 | raise util.Abort(_('revision %d has unmanaged children') | |
|
1322 | % rev[0]) | |
|
1323 | lastparent = None | |
|
1324 | ||
|
1325 | for r in rev: | |
|
1326 | p1, p2 = repo.changelog.parentrevs(r) | |
|
1327 | n = repo.changelog.node(r) | |
|
1328 | if p2 != -1: | |
|
1329 | raise util.Abort(_('cannot import merge revision %d') % r) | |
|
1330 | if lastparent and lastparent != r: | |
|
1331 | raise util.Abort(_('revision %d is not the parent of %d') | |
|
1332 | % (r, lastparent)) | |
|
1333 | lastparent = p1 | |
|
1334 | ||
|
1335 | if not patchname: | |
|
1336 | patchname = '%d.diff' % r | |
|
1337 | checkseries(patchname) | |
|
1338 | checkfile(patchname) | |
|
1339 | self.full_series.insert(0, patchname) | |
|
1340 | ||
|
1341 | patchf = self.opener(patchname, "w") | |
|
1342 | patch.export(repo, [n], fp=patchf, opts=self.diffopts()) | |
|
1343 | patchf.close() | |
|
1344 | ||
|
1345 | se = statusentry(revlog.hex(n), patchname) | |
|
1346 | self.applied.insert(0, se) | |
|
1347 | ||
|
1348 | added.append(patchname) | |
|
1349 | patchname = None | |
|
1350 | self.parse_series() | |
|
1351 | self.applied_dirty = 1 | |
|
1352 | ||
|
1285 | 1353 | for filename in files: |
|
1286 | 1354 | if existing: |
|
1287 | 1355 | if not patchname: |
@@ -1295,14 +1363,10 b' class queue:' | |||
|
1295 | 1363 | raise util.Abort(_("unable to read %s") % patchname) |
|
1296 | 1364 | if not patchname: |
|
1297 | 1365 | patchname = os.path.basename(filename) |
|
1298 | if not force and os.path.exists(self.join(patchname)): | |
|
1299 | raise util.Abort(_('patch "%s" already exists') | |
|
1300 | % patchname) | |
|
1366 | checkfile(patchname) | |
|
1301 | 1367 | patchf = self.opener(patchname, "w") |
|
1302 | 1368 | patchf.write(text) |
|
1303 | if patchname in self.series: | |
|
1304 | raise util.Abort(_('patch %s is already in the series file') | |
|
1305 | % patchname) | |
|
1369 | checkseries(patchname) | |
|
1306 | 1370 | index = self.full_series_end() + i |
|
1307 | 1371 | self.full_series[index:index] = [patchname] |
|
1308 | 1372 | self.parse_series() |
@@ -1343,10 +1407,22 b' def unapplied(ui, repo, patch=None, **op' | |||
|
1343 | 1407 | ui.write("%s\n" % p) |
|
1344 | 1408 | |
|
1345 | 1409 | def qimport(ui, repo, *filename, **opts): |
|
1346 |
"""import a patch |
|
|
1410 | """import a patch | |
|
1411 | ||
|
1412 | The patch will have the same name as its source file unless you | |
|
1413 | give it a new one with --name. | |
|
1414 | ||
|
1415 | You can register an existing patch inside the patch directory | |
|
1416 | with the --existing flag. | |
|
1417 | ||
|
1418 | With --force, an existing patch of the same name will be overwritten. | |
|
1419 | ||
|
1420 | An existing changeset may be placed under mq control with --rev | |
|
1421 | (e.g. qimport --rev tip -n patch will place tip under mq control). | |
|
1422 | """ | |
|
1347 | 1423 | q = repo.mq |
|
1348 | 1424 | q.qimport(repo, filename, patchname=opts['name'], |
|
1349 | existing=opts['existing'], force=opts['force']) | |
|
1425 | existing=opts['existing'], force=opts['force'], rev=opts['rev']) | |
|
1350 | 1426 | q.save_dirty() |
|
1351 | 1427 | return 0 |
|
1352 | 1428 | |
@@ -1953,8 +2029,9 b' cmdtable = {' | |||
|
1953 | 2029 | (qimport, |
|
1954 | 2030 | [('e', 'existing', None, 'import file in patch dir'), |
|
1955 | 2031 | ('n', 'name', '', 'patch file name'), |
|
1956 |
('f', 'force', None, 'overwrite existing files') |
|
|
1957 | 'hg qimport [-e] [-n NAME] [-f] FILE...'), | |
|
2032 | ('f', 'force', None, 'overwrite existing files'), | |
|
2033 | ('r', 'rev', [], 'place existing revisions under mq control')], | |
|
2034 | 'hg qimport [-e] [-n NAME] [-f] [-r REV]... FILE...'), | |
|
1958 | 2035 | "^qinit": |
|
1959 | 2036 | (init, |
|
1960 | 2037 | [('c', 'create-repo', None, 'create queue repository')], |
General Comments 0
You need to be logged in to leave comments.
Login now