D385: drawdag: allow override file contents via comments
This revision was automatically updated to reflect the committed changes. Closed by commit rHG0531ffd59a98: drawdag: allow override file contents via comments (authored by quark). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D385?vs=872&id=874 REVISION DETAIL https://phab.mercurial-scm.org/D385 AFFECTED FILES tests/drawdag.py tests/test-drawdag.t CHANGE DETAILS diff --git a/tests/test-drawdag.t b/tests/test-drawdag.t --- a/tests/test-drawdag.t +++ b/tests/test-drawdag.t @@ -232,3 +232,41 @@ be0ef73c17ade3fc89dc41701eb9fc3a91b58282 575c4b5ec114d64b681d33f8792853568bfb2b2c 0 (Thu Jan 01 00:00:00 1970 +) {'user': 'test'} 64a8289d249234b9886244d379f15e6b650b28e3 0 {7fb047a69f220c21711122dfd94305a9efb60cba} (Thu Jan 01 00:00:00 1970 +) {'user': 'test'} 58e6b987bf7045fcd9c54f496396ca1d1fc81047 0 {575c4b5ec114d64b681d33f8792853568bfb2b2c} (Thu Jan 01 00:00:00 1970 +) {'user': 'test'} + +Change file contents via comments + + $ reinit + $ hg debugdrawdag <<'EOS' + > C # A/dir1/a = 1\n2 + > |\ # B/dir2/b = 34 + > A B # C/dir1/c = 5 + > # C/dir2/c = 6 + > # C/A = a + > # C/B = b + > EOS + + $ hg log -G -T '{desc} {files}' + oC A B dir1/c dir2/c + |\ + | o B B dir2/b + | + o A A dir1/a + + $ for f in `hg files -r C`; do + > echo FILE "$f" + > hg cat -r C "$f" + > echo + > done + FILE A + a + FILE B + b + FILE dir1/a + 1 + 2 + FILE dir1/c + 5 + FILE dir2/b + 34 + FILE dir2/c + 6 diff --git a/tests/drawdag.py b/tests/drawdag.py --- a/tests/drawdag.py +++ b/tests/drawdag.py @@ -84,6 +84,7 @@ import collections import itertools +import re from mercurial.i18n import _ from mercurial import ( @@ -275,6 +276,12 @@ if leaf in v: v.remove(leaf) +def _getcomments(text): +for line in text.splitlines(): +if ' # ' not in line: +continue +yield line.split(' # ', 1)[1].split(' # ')[0].strip() + @command('debugdrawdag', []) def debugdrawdag(ui, repo, **opts): """read an ASCII graph from stdin and create changesets @@ -301,6 +308,13 @@ raise error.Abort(_('%s: too many parents: %s') % (k, ' '.join(v))) +# parse comments to get extra file content instructions +files = collections.defaultdict(dict) # {(name, path): content} +comments = list(_getcomments(text)) +filere = re.compile(r'^(\w+)/([\w/]+)\s*=\s*(.*)$', re.M) +for name, path, content in filere.findall('\n'.join(comments)): +files[name][path] = content.replace(r'\n', '\n') + committed = {None: node.nullid} # {name: node} # for leaf nodes, try to find existing nodes in repo @@ -326,6 +340,9 @@ else: # If it's not a merge, add a single file added[name] = name +# add extra file contents in comments +for path, content in files.get(name, {}).items(): +added[path] = content ctx = simplecommitctx(repo, name, pctxs, added) n = ctx.commit() committed[name] = n @@ -335,12 +352,8 @@ # handle special comments with repo.wlock(), repo.lock(), repo.transaction('drawdag'): getctx = lambda x: repo.unfiltered()[committed[x.strip()]] -for line in text.splitlines(): -if ' # ' not in line: -continue - +for comment in comments: rels = [] # obsolete relationships -comment = line.split(' # ', 1)[1].split(' # ')[0].strip() args = comment.split(':', 1) if len(args) <= 1: continue To: quark, #hg-reviewers, martinvonz Cc: martinvonz, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D385: drawdag: allow override file contents via comments
quark updated this revision to Diff 872. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D385?vs=867&id=872 REVISION DETAIL https://phab.mercurial-scm.org/D385 AFFECTED FILES tests/drawdag.py tests/test-drawdag.t CHANGE DETAILS diff --git a/tests/test-drawdag.t b/tests/test-drawdag.t --- a/tests/test-drawdag.t +++ b/tests/test-drawdag.t @@ -232,3 +232,41 @@ be0ef73c17ade3fc89dc41701eb9fc3a91b58282 575c4b5ec114d64b681d33f8792853568bfb2b2c 0 (Thu Jan 01 00:00:00 1970 +) {'user': 'test'} 64a8289d249234b9886244d379f15e6b650b28e3 0 {7fb047a69f220c21711122dfd94305a9efb60cba} (Thu Jan 01 00:00:00 1970 +) {'user': 'test'} 58e6b987bf7045fcd9c54f496396ca1d1fc81047 0 {575c4b5ec114d64b681d33f8792853568bfb2b2c} (Thu Jan 01 00:00:00 1970 +) {'user': 'test'} + +Change file contents via comments + + $ reinit + $ hg debugdrawdag <<'EOS' + > C # A/dir1/a = 1\n2 + > |\ # B/dir2/b = 34 + > A B # C/dir1/c = 5 + > # C/dir2/c = 6 + > # C/A = a + > # C/B = b + > EOS + + $ hg log -G -T '{desc} {files}' + oC A B dir1/c dir2/c + |\ + | o B B dir2/b + | + o A A dir1/a + + $ for f in `hg files -r C`; do + > echo FILE "$f" + > hg cat -r C "$f" + > echo + > done + FILE A + a + FILE B + b + FILE dir1/a + 1 + 2 + FILE dir1/c + 5 + FILE dir2/b + 34 + FILE dir2/c + 6 diff --git a/tests/drawdag.py b/tests/drawdag.py --- a/tests/drawdag.py +++ b/tests/drawdag.py @@ -84,6 +84,7 @@ import collections import itertools +import re from mercurial.i18n import _ from mercurial import ( @@ -275,6 +276,12 @@ if leaf in v: v.remove(leaf) +def _getcomments(text): +for line in text.splitlines(): +if ' # ' not in line: +continue +yield line.split(' # ', 1)[1].split(' # ')[0].strip() + @command('debugdrawdag', []) def debugdrawdag(ui, repo, **opts): """read an ASCII graph from stdin and create changesets @@ -301,6 +308,13 @@ raise error.Abort(_('%s: too many parents: %s') % (k, ' '.join(v))) +# parse comments to get extra file content instructions +files = collections.defaultdict(dict) # {(name, path): content} +comments = list(_getcomments(text)) +filere = re.compile(r'^(\w+)/([\w/]+)\s*=\s*(.*)$', re.M) +for name, path, content in filere.findall('\n'.join(comments)): +files[name][path] = content.replace(r'\n', '\n') + committed = {None: node.nullid} # {name: node} # for leaf nodes, try to find existing nodes in repo @@ -326,6 +340,9 @@ else: # If it's not a merge, add a single file added[name] = name +# add extra file contents in comments +for path, content in files.get(name, {}).items(): +added[path] = content ctx = simplecommitctx(repo, name, pctxs, added) n = ctx.commit() committed[name] = n @@ -335,12 +352,8 @@ # handle special comments with repo.wlock(), repo.lock(), repo.transaction('drawdag'): getctx = lambda x: repo.unfiltered()[committed[x.strip()]] -for line in text.splitlines(): -if ' # ' not in line: -continue - +for comment in comments: rels = [] # obsolete relationships -comment = line.split(' # ', 1)[1].split(' # ')[0].strip() args = comment.split(':', 1) if len(args) <= 1: continue To: quark, #hg-reviewers Cc: martinvonz, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D385: drawdag: allow override file contents via comments
quark added a comment. Wait, I guess I know what you're saying. Let me double check. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D385 To: quark, #hg-reviewers Cc: martinvonz, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D385: drawdag: allow override file contents via comments
quark added inline comments. INLINE COMMENTS > martinvonz wrote in test-drawdag.t:243 > Does it support creating graphs of resolved conflicts as follows? > > > C # A/f = a > > |\ # B/f = b > > A B # C/f = c Yes. I uses `=` to indicate "replace the content". In the future we might want `+=` to do "append content" etc. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D385 To: quark, #hg-reviewers Cc: martinvonz, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D385: drawdag: allow override file contents via comments
martinvonz added inline comments. INLINE COMMENTS > test-drawdag.t:243 > + > A B # C/dir1/c = 5 > + > # C/dir2/c = 6 > + > EOS Does it support creating graphs of resolved conflicts as follows? > C # A/f = a > |\ # B/f = b > A B # C/f = c REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D385 To: quark, #hg-reviewers Cc: martinvonz, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D385: drawdag: allow override file contents via comments
quark created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY This makes drawdag more flexible, and allow us to create non-clean merges in test cases. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D385 AFFECTED FILES tests/drawdag.py tests/test-drawdag.t CHANGE DETAILS diff --git a/tests/test-drawdag.t b/tests/test-drawdag.t --- a/tests/test-drawdag.t +++ b/tests/test-drawdag.t @@ -232,3 +232,39 @@ be0ef73c17ade3fc89dc41701eb9fc3a91b58282 575c4b5ec114d64b681d33f8792853568bfb2b2c 0 (Thu Jan 01 00:00:00 1970 +) {'user': 'test'} 64a8289d249234b9886244d379f15e6b650b28e3 0 {7fb047a69f220c21711122dfd94305a9efb60cba} (Thu Jan 01 00:00:00 1970 +) {'user': 'test'} 58e6b987bf7045fcd9c54f496396ca1d1fc81047 0 {575c4b5ec114d64b681d33f8792853568bfb2b2c} (Thu Jan 01 00:00:00 1970 +) {'user': 'test'} + +Change file contents via comments + + $ reinit + $ hg debugdrawdag <<'EOS' + > C # A/dir1/a = 1\n2 + > |\ # B/dir2/b = 34 + > A B # C/dir1/c = 5 + > # C/dir2/c = 6 + > EOS + + $ hg log -G -T '{desc} {files}' + oC dir1/c dir2/c + |\ + | o B B dir2/b + | + o A A dir1/a + + $ for f in `hg files -r C`; do + > echo FILE "$f" + > hg cat -r C "$f" + > echo + > done + FILE A + A + FILE B + B + FILE dir1/a + 1 + 2 + FILE dir1/c + 5 + FILE dir2/b + 34 + FILE dir2/c + 6 diff --git a/tests/drawdag.py b/tests/drawdag.py --- a/tests/drawdag.py +++ b/tests/drawdag.py @@ -84,6 +84,7 @@ import collections import itertools +import re from mercurial.i18n import _ from mercurial import ( @@ -275,6 +276,12 @@ if leaf in v: v.remove(leaf) +def _getcomments(text): +for line in text.splitlines(): +if ' # ' not in line: +continue +yield line.split(' # ', 1)[1].split(' # ')[0].strip() + @command('debugdrawdag', []) def debugdrawdag(ui, repo, **opts): """read an ASCII graph from stdin and create changesets @@ -301,6 +308,13 @@ raise error.Abort(_('%s: too many parents: %s') % (k, ' '.join(v))) +# parse comments to get extra file content instructions +files = collections.defaultdict(dict) # {(name, path): content} +comments = list(_getcomments(text)) +filere = re.compile(r'^(\w+)/([\w/]+)\s*=\s*(.*)$', re.M) +for name, path, content in filere.findall('\n'.join(comments)): +files[name][path] = content.replace(r'\n', '\n') + committed = {None: node.nullid} # {name: node} # for leaf nodes, try to find existing nodes in repo @@ -326,6 +340,9 @@ else: # If it's not a merge, add a single file added[name] = name +# add extra file contents in comments +for path, content in files.get(name, {}).items(): +added[path] = content ctx = simplecommitctx(repo, name, pctxs, added) n = ctx.commit() committed[name] = n @@ -335,12 +352,8 @@ # handle special comments with repo.wlock(), repo.lock(), repo.transaction('drawdag'): getctx = lambda x: repo.unfiltered()[committed[x.strip()]] -for line in text.splitlines(): -if ' # ' not in line: -continue - +for comment in comments: rels = [] # obsolete relationships -comment = line.split(' # ', 1)[1].split(' # ')[0].strip() args = comment.split(':', 1) if len(args) <= 1: continue To: quark, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel