Show More
@@ -56,6 +56,67 b' class statusentry:' | |||
|
56 | 56 | def __str__(self): |
|
57 | 57 | return self.rev + ':' + self.name |
|
58 | 58 | |
|
59 | class patchheader(object): | |
|
60 | def __init__(self, message, comments, user, date, haspatch): | |
|
61 | self.message = message | |
|
62 | self.comments = comments | |
|
63 | self.user = user | |
|
64 | self.date = date | |
|
65 | self.haspatch = haspatch | |
|
66 | ||
|
67 | def setuser(self, user): | |
|
68 | if not self.setheader(['From: ', '# User '], user): | |
|
69 | try: | |
|
70 | patchheaderat = self.comments.index('# HG changeset patch') | |
|
71 | self.comments.insert(patchheaderat + 1,'# User ' + user) | |
|
72 | except ValueError: | |
|
73 | self.comments = ['From: ' + user, ''] + self.comments | |
|
74 | self.user = user | |
|
75 | ||
|
76 | def setdate(self, date): | |
|
77 | if self.setheader(['# Date '], date): | |
|
78 | self.date = date | |
|
79 | ||
|
80 | def setmessage(self, message): | |
|
81 | if self.comments: | |
|
82 | self._delmsg() | |
|
83 | self.message = [message] | |
|
84 | self.comments += self.message | |
|
85 | ||
|
86 | def setheader(self, prefixes, new): | |
|
87 | '''Update all references to a field in the patch header. | |
|
88 | If none found, add it email style.''' | |
|
89 | res = False | |
|
90 | for prefix in prefixes: | |
|
91 | for i in xrange(len(self.comments)): | |
|
92 | if self.comments[i].startswith(prefix): | |
|
93 | self.comments[i] = prefix + new | |
|
94 | res = True | |
|
95 | break | |
|
96 | return res | |
|
97 | ||
|
98 | def __str__(self): | |
|
99 | if not self.comments: | |
|
100 | return '' | |
|
101 | return '\n'.join(self.comments) + '\n\n' | |
|
102 | ||
|
103 | def _delmsg(self): | |
|
104 | '''Remove existing message, keeping the rest of the comments fields. | |
|
105 | If comments contains 'subject: ', message will prepend | |
|
106 | the field and a blank line.''' | |
|
107 | if self.message: | |
|
108 | subj = 'subject: ' + self.message[0].lower() | |
|
109 | for i in xrange(len(self.comments)): | |
|
110 | if subj == self.comments[i].lower(): | |
|
111 | del self.comments[i] | |
|
112 | self.message = self.message[2:] | |
|
113 | break | |
|
114 | ci = 0 | |
|
115 | for mi in xrange(len(self.message)): | |
|
116 | while self.message[mi] != self.comments[ci]: | |
|
117 | ci += 1 | |
|
118 | del self.comments[ci] | |
|
119 | ||
|
59 | 120 | class queue: |
|
60 | 121 | def __init__(self, ui, path, patchdir=None): |
|
61 | 122 | self.basepath = path |
@@ -307,7 +368,7 b' class queue:' | |||
|
307 | 368 | if format and format.startswith("tag") and subject: |
|
308 | 369 | message.insert(0, "") |
|
309 | 370 | message.insert(0, subject) |
|
310 | return (message, comments, user, date, diffstart > 1) | |
|
371 | return patchheader(message, comments, user, date, diffstart > 1) | |
|
311 | 372 | |
|
312 | 373 | def removeundo(self, repo): |
|
313 | 374 | undo = repo.sjoin('undo') |
@@ -351,13 +412,13 b' class queue:' | |||
|
351 | 412 | if n == None: |
|
352 | 413 | raise util.Abort(_("repo commit failed")) |
|
353 | 414 | try: |
|
354 |
|
|
|
415 | ph = mergeq.readheaders(patch) | |
|
355 | 416 | except: |
|
356 | 417 | raise util.Abort(_("unable to read %s") % patch) |
|
357 | 418 | |
|
358 | 419 | patchf = self.opener(patch, "w") |
|
420 | comments = str(ph) | |
|
359 | 421 | if comments: |
|
360 | comments = "\n".join(comments) + '\n\n' | |
|
361 | 422 | patchf.write(comments) |
|
362 | 423 | self.printdiff(repo, head, n, fp=patchf) |
|
363 | 424 | patchf.close() |
@@ -477,12 +538,13 b' class queue:' | |||
|
477 | 538 | pf = os.path.join(patchdir, patchname) |
|
478 | 539 | |
|
479 | 540 | try: |
|
480 |
|
|
|
541 | ph = self.readheaders(patchname) | |
|
481 | 542 | except: |
|
482 | 543 | self.ui.warn(_("Unable to read %s\n") % patchname) |
|
483 | 544 | err = 1 |
|
484 | 545 | break |
|
485 | 546 | |
|
547 | message = ph.message | |
|
486 | 548 | if not message: |
|
487 | 549 | message = _("imported patch %s\n") % patchname |
|
488 | 550 | else: |
@@ -512,7 +574,7 b' class queue:' | |||
|
512 | 574 | |
|
513 | 575 | files = patch.updatedir(self.ui, repo, files) |
|
514 | 576 | match = cmdutil.matchfiles(repo, files or []) |
|
515 | n = repo.commit(files, message, user, date, match=match, | |
|
577 | n = repo.commit(files, message, ph.user, ph.date, match=match, | |
|
516 | 578 | force=True) |
|
517 | 579 | |
|
518 | 580 | if n == None: |
@@ -522,7 +584,7 b' class queue:' | |||
|
522 | 584 | self.applied.append(statusentry(revlog.hex(n), patchname)) |
|
523 | 585 | |
|
524 | 586 | if patcherr: |
|
525 |
if not patch |
|
|
587 | if not ph.haspatch: | |
|
526 | 588 | self.ui.warn(_("patch %s is empty\n") % patchname) |
|
527 | 589 | err = 0 |
|
528 | 590 | else: |
@@ -1015,6 +1077,8 b' class queue:' | |||
|
1015 | 1077 | if len(self.applied) == 0: |
|
1016 | 1078 | self.ui.write(_("No patches applied\n")) |
|
1017 | 1079 | return 1 |
|
1080 | msg = opts.get('msg', '').rstrip() | |
|
1081 | newuser = opts.get('user') | |
|
1018 | 1082 | newdate = opts.get('date') |
|
1019 | 1083 | if newdate: |
|
1020 | 1084 | newdate = '%d %d' % util.parsedate(newdate) |
@@ -1027,7 +1091,7 b' class queue:' | |||
|
1027 | 1091 | raise util.Abort(_("cannot refresh a revision with children")) |
|
1028 | 1092 | cparents = repo.changelog.parents(top) |
|
1029 | 1093 | patchparent = self.qparents(repo, top) |
|
1030 |
|
|
|
1094 | ph = self.readheaders(patchfn) | |
|
1031 | 1095 | |
|
1032 | 1096 | patchf = self.opener(patchfn, 'r+') |
|
1033 | 1097 | |
@@ -1037,59 +1101,18 b' class queue:' | |||
|
1037 | 1101 | self.diffopts().git = True |
|
1038 | 1102 | break |
|
1039 | 1103 | |
|
1040 | msg = opts.get('msg', '').rstrip() | |
|
1041 | if msg and comments: | |
|
1042 | # Remove existing message, keeping the rest of the comments | |
|
1043 | # fields. | |
|
1044 | # If comments contains 'subject: ', message will prepend | |
|
1045 | # the field and a blank line. | |
|
1046 | if message: | |
|
1047 | subj = 'subject: ' + message[0].lower() | |
|
1048 | for i in xrange(len(comments)): | |
|
1049 | if subj == comments[i].lower(): | |
|
1050 | del comments[i] | |
|
1051 | message = message[2:] | |
|
1052 | break | |
|
1053 | ci = 0 | |
|
1054 | for mi in xrange(len(message)): | |
|
1055 | while message[mi] != comments[ci]: | |
|
1056 | ci += 1 | |
|
1057 | del comments[ci] | |
|
1058 | ||
|
1059 | def setheaderfield(comments, prefixes, new): | |
|
1060 | # Update all references to a field in the patch header. | |
|
1061 | # If none found, add it email style. | |
|
1062 | res = False | |
|
1063 | for prefix in prefixes: | |
|
1064 | for i in xrange(len(comments)): | |
|
1065 | if comments[i].startswith(prefix): | |
|
1066 | comments[i] = prefix + new | |
|
1067 | res = True | |
|
1068 | break | |
|
1069 | return res | |
|
1070 | ||
|
1071 | newuser = opts.get('user') | |
|
1104 | if msg: | |
|
1105 | ph.setmessage(msg) | |
|
1072 | 1106 | if newuser: |
|
1073 | if not setheaderfield(comments, ['From: ', '# User '], newuser): | |
|
1074 | try: | |
|
1075 | patchheaderat = comments.index('# HG changeset patch') | |
|
1076 | comments.insert(patchheaderat + 1,'# User ' + newuser) | |
|
1077 | except ValueError: | |
|
1078 | comments = ['From: ' + newuser, ''] + comments | |
|
1079 | user = newuser | |
|
1080 | ||
|
1107 | ph.setuser(newuser) | |
|
1081 | 1108 | if newdate: |
|
1082 |
|
|
|
1083 | date = newdate | |
|
1084 | ||
|
1085 | if msg: | |
|
1086 | comments.append(msg) | |
|
1109 | ph.setdate(newdate) | |
|
1087 | 1110 | |
|
1088 | 1111 | patchf.seek(0) |
|
1089 | 1112 | patchf.truncate() |
|
1090 | 1113 | |
|
1114 | comments = str(ph) | |
|
1091 | 1115 | if comments: |
|
1092 | comments = "\n".join(comments) + '\n\n' | |
|
1093 | 1116 | patchf.write(comments) |
|
1094 | 1117 | |
|
1095 | 1118 | if opts.get('git'): |
@@ -1204,22 +1227,21 b' class queue:' | |||
|
1204 | 1227 | repo.dirstate.forget(f) |
|
1205 | 1228 | |
|
1206 | 1229 | if not msg: |
|
1207 | if not message: | |
|
1230 | if not ph.message: | |
|
1208 | 1231 | message = "[mq]: %s\n" % patchfn |
|
1209 | 1232 | else: |
|
1210 | message = "\n".join(message) | |
|
1233 | message = "\n".join(ph.message) | |
|
1211 | 1234 | else: |
|
1212 | 1235 | message = msg |
|
1213 | 1236 | |
|
1214 | if not user: | |
|
1215 | user = changes[1] | |
|
1237 | user = ph.user or changes[1] | |
|
1216 | 1238 | |
|
1217 | 1239 | self.applied.pop() |
|
1218 | 1240 | self.applied_dirty = 1 |
|
1219 | 1241 | self.strip(repo, top, update=False, |
|
1220 | 1242 | backup='strip') |
|
1221 |
n = repo.commit(match.files(), message, user, date, |
|
|
1222 | force=1) | |
|
1243 | n = repo.commit(match.files(), message, user, ph.date, | |
|
1244 | match=match, force=1) | |
|
1223 | 1245 | self.applied.append(statusentry(revlog.hex(n), patchfn)) |
|
1224 | 1246 | self.removeundo(repo) |
|
1225 | 1247 | else: |
@@ -1273,7 +1295,8 b' class queue:' | |||
|
1273 | 1295 | summary=False): |
|
1274 | 1296 | def displayname(patchname): |
|
1275 | 1297 | if summary: |
|
1276 |
|
|
|
1298 | ph = self.readheaders(patchname) | |
|
1299 | msg = ph.message | |
|
1277 | 1300 | msg = msg and ': ' + msg[0] or ': ' |
|
1278 | 1301 | else: |
|
1279 | 1302 | msg = '' |
@@ -1828,8 +1851,8 b' def refresh(ui, repo, *pats, **opts):' | |||
|
1828 | 1851 | if message: |
|
1829 | 1852 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1830 | 1853 | patch = q.applied[-1].name |
|
1831 |
|
|
|
1832 | message = ui.edit('\n'.join(message), user or ui.username()) | |
|
1854 | ph = q.readheaders(patch) | |
|
1855 | message = ui.edit('\n'.join(ph.message), ph.user or ui.username()) | |
|
1833 | 1856 | setupheaderopts(ui, opts) |
|
1834 | 1857 | ret = q.refresh(repo, pats, msg=message, **opts) |
|
1835 | 1858 | q.save_dirty() |
@@ -1887,7 +1910,8 b' def fold(ui, repo, *files, **opts):' | |||
|
1887 | 1910 | |
|
1888 | 1911 | for p in patches: |
|
1889 | 1912 | if not message: |
|
1890 |
|
|
|
1913 | ph = q.readheaders(p) | |
|
1914 | messages.append(ph.message) | |
|
1891 | 1915 | pf = q.join(p) |
|
1892 | 1916 | (patchsuccess, files, fuzz) = q.patch(repo, pf) |
|
1893 | 1917 | if not patchsuccess: |
@@ -1895,7 +1919,8 b' def fold(ui, repo, *files, **opts):' | |||
|
1895 | 1919 | patch.updatedir(ui, repo, files) |
|
1896 | 1920 | |
|
1897 | 1921 | if not message: |
|
1898 |
|
|
|
1922 | ph = q.readheaders(parent) | |
|
1923 | message, user = ph.message, ph.user | |
|
1899 | 1924 | for msg in messages: |
|
1900 | 1925 | message.append('* * *') |
|
1901 | 1926 | message.extend(msg) |
@@ -1978,9 +2003,9 b' def header(ui, repo, patch=None):' | |||
|
1978 | 2003 | ui.write('No patches applied\n') |
|
1979 | 2004 | return 1 |
|
1980 | 2005 | patch = q.lookup('qtip') |
|
1981 |
|
|
|
2006 | ph = repo.mq.readheaders(patch) | |
|
1982 | 2007 | |
|
1983 | ui.write('\n'.join(message) + '\n') | |
|
2008 | ui.write('\n'.join(ph.message) + '\n') | |
|
1984 | 2009 | |
|
1985 | 2010 | def lastsavename(path): |
|
1986 | 2011 | (directory, base) = os.path.split(path) |
General Comments 0
You need to be logged in to leave comments.
Login now