comparison hgext/mq.py @ 2808:766ecdc83e43

mq: add join method
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Tue, 08 Aug 2006 18:12:48 -0700
parents bdc067ff6cf5
children 2e4ace008c94
comparison
equal deleted inserted replaced
2807:bdc067ff6cf5 2808:766ecdc83e43
54 return self.rev + ':' + self.name 54 return self.rev + ':' + self.name
55 55
56 class queue: 56 class queue:
57 def __init__(self, ui, path, patchdir=None): 57 def __init__(self, ui, path, patchdir=None):
58 self.basepath = path 58 self.basepath = path
59 if patchdir: 59 self.path = patchdir or os.path.join(path, "patches")
60 self.path = patchdir
61 else:
62 self.path = os.path.join(path, "patches")
63 self.opener = util.opener(self.path) 60 self.opener = util.opener(self.path)
64 self.ui = ui 61 self.ui = ui
65 self.applied = [] 62 self.applied = []
66 self.full_series = [] 63 self.full_series = []
67 self.applied_dirty = 0 64 self.applied_dirty = 0
68 self.series_dirty = 0 65 self.series_dirty = 0
69 self.series_path = "series" 66 self.series_path = "series"
70 self.status_path = "status" 67 self.status_path = "status"
71 68
72 if os.path.exists(os.path.join(self.path, self.series_path)): 69 if os.path.exists(self.join(self.series_path)):
73 self.full_series = self.opener(self.series_path).read().splitlines() 70 self.full_series = self.opener(self.series_path).read().splitlines()
74 self.parse_series() 71 self.parse_series()
75 72
76 if os.path.exists(os.path.join(self.path, self.status_path)): 73 if os.path.exists(self.join(self.status_path)):
77 self.applied = [statusentry(l) 74 self.applied = [statusentry(l)
78 for l in self.opener(self.status_path).read().splitlines()] 75 for l in self.opener(self.status_path).read().splitlines()]
76
77 def join(self, *p):
78 return os.path.join(self.path, *p)
79 79
80 def find_series(self, patch): 80 def find_series(self, patch):
81 pre = re.compile("(\s*)([^#]+)") 81 pre = re.compile("(\s*)([^#]+)")
82 index = 0 82 index = 0
83 for l in self.full_series: 83 for l in self.full_series:
122 if re.match('\s*$', l): 122 if re.match('\s*$', l):
123 del lines[-1] 123 del lines[-1]
124 else: 124 else:
125 break 125 break
126 126
127 pf = os.path.join(self.path, patch) 127 pf = self.join(patch)
128 message = [] 128 message = []
129 comments = [] 129 comments = []
130 user = None 130 user = None
131 date = None 131 date = None
132 format = None 132 format = None
388 if force: 388 if force:
389 r = self.qrepo() 389 r = self.qrepo()
390 if r: 390 if r:
391 r.remove([patch], True) 391 r.remove([patch], True)
392 else: 392 else:
393 os.unlink(os.path.join(self.path, patch)) 393 os.unlink(self.join(patch))
394 i = self.find_series(patch) 394 i = self.find_series(patch)
395 del self.full_series[i] 395 del self.full_series[i]
396 self.parse_series() 396 self.parse_series()
397 self.series_dirty = 1 397 self.series_dirty = 1
398 398
407 def check_localchanges(self, repo): 407 def check_localchanges(self, repo):
408 (c, a, r, d, u) = repo.changes(None, None) 408 (c, a, r, d, u) = repo.changes(None, None)
409 if c or a or d or r: 409 if c or a or d or r:
410 raise util.Abort(_("local changes found, refresh first")) 410 raise util.Abort(_("local changes found, refresh first"))
411 def new(self, repo, patch, msg=None, force=None): 411 def new(self, repo, patch, msg=None, force=None):
412 if os.path.exists(os.path.join(self.path, patch)): 412 if os.path.exists(self.join(patch)):
413 raise util.Abort(_('patch "%s" already exists') % patch) 413 raise util.Abort(_('patch "%s" already exists') % patch)
414 commitfiles = [] 414 commitfiles = []
415 (c, a, r, d, u) = repo.changes(None, None) 415 (c, a, r, d, u) = repo.changes(None, None)
416 if c or a or d or r: 416 if c or a or d or r:
417 if not force: 417 if not force:
630 # sure the file name passed in does not exist (checked below) 630 # sure the file name passed in does not exist (checked below)
631 res = partial_name(patch) 631 res = partial_name(patch)
632 if res and res == patch: 632 if res and res == patch:
633 return res 633 return res
634 634
635 if not os.path.isfile(os.path.join(self.path, patch)): 635 if not os.path.isfile(self.join(patch)):
636 try: 636 try:
637 sno = int(patch) 637 sno = int(patch)
638 except(ValueError, OverflowError): 638 except(ValueError, OverflowError):
639 pass 639 pass
640 else: 640 else:
964 def issaveline(self, l): 964 def issaveline(self, l):
965 if l.name == '.hg.patches.save.line': 965 if l.name == '.hg.patches.save.line':
966 return True 966 return True
967 967
968 def qrepo(self, create=False): 968 def qrepo(self, create=False):
969 if create or os.path.isdir(os.path.join(self.path, ".hg")): 969 if create or os.path.isdir(self.join(".hg")):
970 return hg.repository(self.ui, path=self.path, create=create) 970 return hg.repository(self.ui, path=self.path, create=create)
971 971
972 def restore(self, repo, rev, delete=None, qupdate=None): 972 def restore(self, repo, rev, delete=None, qupdate=None):
973 c = repo.changelog.read(rev) 973 c = repo.changelog.read(rev)
974 desc = c[4].strip() 974 desc = c[4].strip()
1124 added = [] 1124 added = []
1125 for filename in files: 1125 for filename in files:
1126 if existing: 1126 if existing:
1127 if not patch: 1127 if not patch:
1128 patch = filename 1128 patch = filename
1129 if not os.path.isfile(os.path.join(self.path, patch)): 1129 if not os.path.isfile(self.join(patch)):
1130 raise util.Abort(_("patch %s does not exist") % patch) 1130 raise util.Abort(_("patch %s does not exist") % patch)
1131 else: 1131 else:
1132 try: 1132 try:
1133 text = file(filename).read() 1133 text = file(filename).read()
1134 except IOError: 1134 except IOError:
1135 raise util.Abort(_("unable to read %s") % patch) 1135 raise util.Abort(_("unable to read %s") % patch)
1136 if not patch: 1136 if not patch:
1137 patch = os.path.split(filename)[1] 1137 patch = os.path.split(filename)[1]
1138 if not force and os.path.exists(os.path.join(self.path, patch)): 1138 if not force and os.path.exists(self.join(patch)):
1139 raise util.Abort(_('patch "%s" already exists') % patch) 1139 raise util.Abort(_('patch "%s" already exists') % patch)
1140 patchf = self.opener(patch, "w") 1140 patchf = self.opener(patch, "w")
1141 patchf.write(text) 1141 patchf.write(text)
1142 if patch in self.series: 1142 if patch in self.series:
1143 raise util.Abort(_('patch %s is already in the series file') 1143 raise util.Abort(_('patch %s is already in the series file')
1348 patches.append(patch) 1348 patches.append(patch)
1349 1349
1350 for patch in patches: 1350 for patch in patches:
1351 if not message: 1351 if not message:
1352 messages.append(q.readheaders(patch)[0]) 1352 messages.append(q.readheaders(patch)[0])
1353 pf = os.path.join(q.path, patch) 1353 pf = q.join(patch)
1354 (patchsuccess, files, fuzz) = q.patch(repo, pf) 1354 (patchsuccess, files, fuzz) = q.patch(repo, pf)
1355 if not patchsuccess: 1355 if not patchsuccess:
1356 raise util.Abort(_('Error folding patch %s') % patch) 1356 raise util.Abort(_('Error folding patch %s') % patch)
1357 1357
1358 if not message: 1358 if not message:
1459 patch = None 1459 patch = None
1460 1460
1461 if name in q.series: 1461 if name in q.series:
1462 raise util.Abort(_('A patch named %s already exists in the series file') % name) 1462 raise util.Abort(_('A patch named %s already exists in the series file') % name)
1463 1463
1464 absdest = os.path.join(q.path, name) 1464 absdest = q.join(name)
1465 if os.path.exists(absdest): 1465 if os.path.exists(absdest):
1466 raise util.Abort(_('%s already exists') % absdest) 1466 raise util.Abort(_('%s already exists') % absdest)
1467 1467
1468 if patch: 1468 if patch:
1469 patch = q.lookup(patch) 1469 patch = q.lookup(patch)
1483 info = q.isapplied(patch) 1483 info = q.isapplied(patch)
1484 if info: 1484 if info:
1485 q.applied[info[0]] = statusentry(info[1], name) 1485 q.applied[info[0]] = statusentry(info[1], name)
1486 q.applied_dirty = 1 1486 q.applied_dirty = 1
1487 1487
1488 util.rename(os.path.join(q.path, patch), absdest) 1488 util.rename(q.join(patch), absdest)
1489 r = q.qrepo() 1489 r = q.qrepo()
1490 if r: 1490 if r:
1491 wlock = r.wlock() 1491 wlock = r.wlock()
1492 if r.dirstate.state(name) == 'r': 1492 if r.dirstate.state(name) == 'r':
1493 r.undelete([name], wlock) 1493 r.undelete([name], wlock)
1528 newpath = savename(path) 1528 newpath = savename(path)
1529 ui.warn("copy %s to %s\n" % (path, newpath)) 1529 ui.warn("copy %s to %s\n" % (path, newpath))
1530 util.copyfiles(path, newpath) 1530 util.copyfiles(path, newpath)
1531 if opts['empty']: 1531 if opts['empty']:
1532 try: 1532 try:
1533 os.unlink(os.path.join(q.path, q.status_path)) 1533 os.unlink(q.join(q.status_path))
1534 except: 1534 except:
1535 pass 1535 pass
1536 return 0 1536 return 0
1537 1537
1538 def strip(ui, repo, rev, **opts): 1538 def strip(ui, repo, rev, **opts):