Show More
@@ -84,6 +84,7 b' from __future__ import absolute_import, ' | |||||
84 |
|
84 | |||
85 | import collections |
|
85 | import collections | |
86 | import itertools |
|
86 | import itertools | |
|
87 | import re | |||
87 |
|
88 | |||
88 | from mercurial.i18n import _ |
|
89 | from mercurial.i18n import _ | |
89 | from mercurial import ( |
|
90 | from mercurial import ( | |
@@ -275,6 +276,12 b' def _walkgraph(edges):' | |||||
275 | if leaf in v: |
|
276 | if leaf in v: | |
276 | v.remove(leaf) |
|
277 | v.remove(leaf) | |
277 |
|
278 | |||
|
279 | def _getcomments(text): | |||
|
280 | for line in text.splitlines(): | |||
|
281 | if ' # ' not in line: | |||
|
282 | continue | |||
|
283 | yield line.split(' # ', 1)[1].split(' # ')[0].strip() | |||
|
284 | ||||
278 | @command('debugdrawdag', []) |
|
285 | @command('debugdrawdag', []) | |
279 | def debugdrawdag(ui, repo, **opts): |
|
286 | def debugdrawdag(ui, repo, **opts): | |
280 | """read an ASCII graph from stdin and create changesets |
|
287 | """read an ASCII graph from stdin and create changesets | |
@@ -301,6 +308,13 b' def debugdrawdag(ui, repo, **opts):' | |||||
301 | raise error.Abort(_('%s: too many parents: %s') |
|
308 | raise error.Abort(_('%s: too many parents: %s') | |
302 | % (k, ' '.join(v))) |
|
309 | % (k, ' '.join(v))) | |
303 |
|
310 | |||
|
311 | # parse comments to get extra file content instructions | |||
|
312 | files = collections.defaultdict(dict) # {(name, path): content} | |||
|
313 | comments = list(_getcomments(text)) | |||
|
314 | filere = re.compile(r'^(\w+)/([\w/]+)\s*=\s*(.*)$', re.M) | |||
|
315 | for name, path, content in filere.findall('\n'.join(comments)): | |||
|
316 | files[name][path] = content.replace(r'\n', '\n') | |||
|
317 | ||||
304 | committed = {None: node.nullid} # {name: node} |
|
318 | committed = {None: node.nullid} # {name: node} | |
305 |
|
319 | |||
306 | # for leaf nodes, try to find existing nodes in repo |
|
320 | # for leaf nodes, try to find existing nodes in repo | |
@@ -326,6 +340,9 b' def debugdrawdag(ui, repo, **opts):' | |||||
326 | else: |
|
340 | else: | |
327 | # If it's not a merge, add a single file |
|
341 | # If it's not a merge, add a single file | |
328 | added[name] = name |
|
342 | added[name] = name | |
|
343 | # add extra file contents in comments | |||
|
344 | for path, content in files.get(name, {}).items(): | |||
|
345 | added[path] = content | |||
329 | ctx = simplecommitctx(repo, name, pctxs, added) |
|
346 | ctx = simplecommitctx(repo, name, pctxs, added) | |
330 | n = ctx.commit() |
|
347 | n = ctx.commit() | |
331 | committed[name] = n |
|
348 | committed[name] = n | |
@@ -335,12 +352,8 b' def debugdrawdag(ui, repo, **opts):' | |||||
335 | # handle special comments |
|
352 | # handle special comments | |
336 | with repo.wlock(), repo.lock(), repo.transaction('drawdag'): |
|
353 | with repo.wlock(), repo.lock(), repo.transaction('drawdag'): | |
337 | getctx = lambda x: repo.unfiltered()[committed[x.strip()]] |
|
354 | getctx = lambda x: repo.unfiltered()[committed[x.strip()]] | |
338 | for line in text.splitlines(): |
|
355 | for comment in comments: | |
339 | if ' # ' not in line: |
|
|||
340 | continue |
|
|||
341 |
|
||||
342 | rels = [] # obsolete relationships |
|
356 | rels = [] # obsolete relationships | |
343 | comment = line.split(' # ', 1)[1].split(' # ')[0].strip() |
|
|||
344 | args = comment.split(':', 1) |
|
357 | args = comment.split(':', 1) | |
345 | if len(args) <= 1: |
|
358 | if len(args) <= 1: | |
346 | continue |
|
359 | continue |
@@ -232,3 +232,41 b' Create obsmarkers via comments' | |||||
232 | be0ef73c17ade3fc89dc41701eb9fc3a91b58282 575c4b5ec114d64b681d33f8792853568bfb2b2c 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} |
|
232 | be0ef73c17ade3fc89dc41701eb9fc3a91b58282 575c4b5ec114d64b681d33f8792853568bfb2b2c 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} | |
233 | 64a8289d249234b9886244d379f15e6b650b28e3 0 {7fb047a69f220c21711122dfd94305a9efb60cba} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} |
|
233 | 64a8289d249234b9886244d379f15e6b650b28e3 0 {7fb047a69f220c21711122dfd94305a9efb60cba} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} | |
234 | 58e6b987bf7045fcd9c54f496396ca1d1fc81047 0 {575c4b5ec114d64b681d33f8792853568bfb2b2c} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} |
|
234 | 58e6b987bf7045fcd9c54f496396ca1d1fc81047 0 {575c4b5ec114d64b681d33f8792853568bfb2b2c} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} | |
|
235 | ||||
|
236 | Change file contents via comments | |||
|
237 | ||||
|
238 | $ reinit | |||
|
239 | $ hg debugdrawdag <<'EOS' | |||
|
240 | > C # A/dir1/a = 1\n2 | |||
|
241 | > |\ # B/dir2/b = 34 | |||
|
242 | > A B # C/dir1/c = 5 | |||
|
243 | > # C/dir2/c = 6 | |||
|
244 | > # C/A = a | |||
|
245 | > # C/B = b | |||
|
246 | > EOS | |||
|
247 | ||||
|
248 | $ hg log -G -T '{desc} {files}' | |||
|
249 | o C A B dir1/c dir2/c | |||
|
250 | |\ | |||
|
251 | | o B B dir2/b | |||
|
252 | | | |||
|
253 | o A A dir1/a | |||
|
254 | ||||
|
255 | $ for f in `hg files -r C`; do | |||
|
256 | > echo FILE "$f" | |||
|
257 | > hg cat -r C "$f" | |||
|
258 | > echo | |||
|
259 | > done | |||
|
260 | FILE A | |||
|
261 | a | |||
|
262 | FILE B | |||
|
263 | b | |||
|
264 | FILE dir1/a | |||
|
265 | 1 | |||
|
266 | 2 | |||
|
267 | FILE dir1/c | |||
|
268 | 5 | |||
|
269 | FILE dir2/b | |||
|
270 | 34 | |||
|
271 | FILE dir2/c | |||
|
272 | 6 |
General Comments 0
You need to be logged in to leave comments.
Login now