drawdag: document and augment file creation capability stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 11 Mar 2025 10:33:15 +0100
branchstable
changeset 53040 25079cc2016f
parent 53039 d686448e8eb6
child 53041 46603c00a9f2
drawdag: document and augment file creation capability In order to test some stream clone related feature, we need to be able to create file with more complex name and delete them. We document the file related feature in the process.
tests/drawdag.py
tests/test-drawdag.t
--- a/tests/drawdag.py	Tue Mar 11 11:38:30 2025 +0100
+++ b/tests/drawdag.py	Tue Mar 11 10:33:15 2025 +0100
@@ -82,7 +82,8 @@
 
 Special comment can also be used to control file content for some revision.
 
-The example below create two extra files in A, update on in B.
+The example below create two extra files in A, update on in B and delete the
+other on in C (using a special content to mark the deletion).
 
 In all case the file matching the node name is created for all non-merge
 commit.
@@ -90,7 +91,7 @@
     C # A/file/path=content in A
     | # A/other/file/path=content for another file
     B # B/file/path=updated content in B
-    | 
+    | # C/other/file/path=<deleted>
     A
 """
 
@@ -313,7 +314,10 @@
             self._parents.append(repo[repo.nullid])
 
     def filectx(self, key):
-        return simplefilectx(key, self._added[key])
+        content = self._added.get(key)
+        if content is not None:
+            return simplefilectx(key, content)
+        return None
 
     def commit(self):
         return self._repo.commitctx(self)
@@ -394,10 +398,13 @@
     # parse comments to get extra file content instructions
     files = collections.defaultdict(dict)  # {(name, path): content}
     comments = list(_getcomments(text))
-    filere = re.compile(br'^(\w+)/([\w/]+)\s*=\s*(.*)$', re.M)
+    filere = re.compile(br'^(\w+)/([-_\w/"]+)\s*=\s*(.*)$', re.M)
     for name, path, content in filere.findall(b'\n'.join(comments)):
         content = content.replace(br'\n', b'\n').replace(br'\1', b'\1')
-        files[name][path] = content
+        if content == b"<deleted>":
+            files[name][path] = None
+        else:
+            files[name][path] = content
 
     committed = {None: repo.nullid}  # {name: node}
 
--- a/tests/test-drawdag.t	Tue Mar 11 11:38:30 2025 +0100
+++ b/tests/test-drawdag.t	Tue Mar 11 10:33:15 2025 +0100
@@ -242,36 +242,43 @@
   > |\      # B/dir2/b = 34
   > A B     # C/dir1/c = 5
   >         # C/dir2/c = 6
+  >         # A/to-be"deleted" = I am doomed.
+  >         # B/to-be-deleted_too = The end is near.
+  >         # C/to-be"deleted"=<deleted>
+  >         # C/to-be-deleted_too = <deleted>
   >         # C/A = a
   >         # C/B = b
   > EOS
 
   $ hg log -G -T '{desc} {files}'
-  o    C A B dir1/c dir2/c
+  o    C A B dir1/c dir2/c to-be"deleted" to-be-deleted_too
   |\
-  | o  B B dir2/b
+  | o  B B dir2/b to-be-deleted_too
   |
-  o  A A dir1/a
+  o  A A dir1/a to-be"deleted"
   
   $ for r in `hg log -T '{rev} ' --rev "sort(all())"`; do
   >     hg log --rev $r -T "### {tags} ###\n";
   >     hg diff --change $r --stat;
   > done
   ### A ###
-   A      |  1 +
-   dir1/a |  2 ++
-   2 files changed, 3 insertions(+), 0 deletions(-)
+   A              |  1 +
+   dir1/a         |  2 ++
+   to-be"deleted" |  1 +
+   3 files changed, 4 insertions(+), 0 deletions(-)
   ### B ###
-   B      |  1 +
-   dir2/b |  1 +
-   2 files changed, 2 insertions(+), 0 deletions(-)
+   B                 |  1 +
+   dir2/b            |  1 +
+   to-be-deleted_too |  1 +
+   3 files changed, 3 insertions(+), 0 deletions(-)
   ### C tip ###
-   A      |  1 +
-   B      |  2 +-
-   dir1/a |  2 ++
-   dir1/c |  1 +
-   dir2/c |  1 +
-   5 files changed, 6 insertions(+), 1 deletions(-)
+   A              |  2 +-
+   B              |  1 +
+   dir1/c         |  1 +
+   dir2/b         |  1 +
+   dir2/c         |  1 +
+   to-be"deleted" |  1 -
+   6 files changed, 5 insertions(+), 2 deletions(-)
   $ hg files -r C
   A
   B