D12481: debuglock: ignore ENOENT error when unlocking

2022-04-06 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is consistent with the main `lock.release` code.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D12481

AFFECTED FILES
  mercurial/debugcommands.py

CHANGE DETAILS

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2148,9 +2148,17 @@
 """
 
 if opts.get('force_free_lock'):
-repo.svfs.unlink(b'lock')
+try:
+repo.svfs.unlink(b'lock')
+except (OSError, IOError) as e:
+if e.errno != errno.ENOENT:
+raise
 if opts.get('force_free_wlock'):
-repo.vfs.unlink(b'wlock')
+try:
+repo.vfs.unlink(b'wlock')
+except (OSError, IOError) as e:
+if e.errno != errno.ENOENT:
+raise
 if opts.get('force_free_lock') or opts.get('force_free_wlock'):
 return 0
 



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12480: run-tests: introduce "forward-slash" version of everything on windows

2022-04-06 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This should be useful for some shell invocation.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D12480

AFFECTED FILES
  tests/run-tests.py
  tests/test-racy-mutations.t

CHANGE DETAILS

diff --git a/tests/test-racy-mutations.t b/tests/test-racy-mutations.t
--- a/tests/test-racy-mutations.t
+++ b/tests/test-racy-mutations.t
@@ -9,12 +9,12 @@
   $ hg init a
   $ cd a
 
-  $ cat > "$TESTTMP/waitlock_editor.sh" < "$TESTTMP_FORWARD_SLASH/waitlock_editor.sh" < [ -n "\${WAITLOCK_ANNOUNCE:-}" ] && touch "\${WAITLOCK_ANNOUNCE}"
   > f="\${WAITLOCK_FILE}"
   > start=\`date +%s\`
   > timeout=5
-  > $RUNTESTDIR/testlib/wait-on-file "\$timeout" "\$f"
+  > "$RUNTESTDIR_FORWARD_SLASH/testlib/wait-on-file" "\$timeout" "\$f"
   > if [ \$# -gt 1 ]; then
   > cat "\$@"
   > fi
@@ -27,9 +27,9 @@
   $ hg commit -qAm 'r0'
 
 Start an hg commit that will take a while
-  $ EDITOR_STARTED="$(pwd)/.editor_started"
-  $ MISCHIEF_MANAGED="$(pwd)/.mischief_managed"
-  $ JOBS_FINISHED="$(pwd)/.jobs_finished"
+  $ EDITOR_STARTED="$TESTTMP_FORWARD_SLASH/a/.editor_started"
+  $ MISCHIEF_MANAGED="$TESTTMP_FORWARD_SLASH/a/.mischief_managed"
+  $ JOBS_FINISHED="$TESTTMP_FORWARD_SLASH/a/.jobs_finished"
 
 #if fail-if-detected
   $ cat >> .hg/hgrc << EOF
@@ -40,7 +40,7 @@
 
   $ cat >> .hg/hgrc << EOF
   > [ui]
-  > editor=sh $TESTTMP/waitlock_editor.sh
+  > editor=sh $TESTTMP_FORWARD_SLASH/waitlock_editor.sh
   > EOF
 
   $ echo foo > foo
@@ -50,7 +50,7 @@
   >   hg commit -qAm 'r1 (foo)' --edit foo > .foo_commit_out 2>&1 ; 
touch "${JOBS_FINISHED}") &
 
 Wait for the "editor" to actually start
-  $ sh "$RUNTESTDIR/testlib/wait-on-file" 5 "${EDITOR_STARTED}"
+  $ sh "$RUNTESTDIR_FORWARD_SLASH/testlib/wait-on-file" 5 "${EDITOR_STARTED}"
 
   $ cat >> .hg/hgrc << EOF
   > [ui]
@@ -69,7 +69,7 @@
 Awaken the editor from that first commit
   $ touch "${MISCHIEF_MANAGED}"
 And wait for it to finish
-  $ WAITLOCK_FILE="${JOBS_FINISHED}" sh "$TESTTMP/waitlock_editor.sh"
+  $ WAITLOCK_FILE="${JOBS_FINISHED}" sh 
"$TESTTMP_FORWARD_SLASH/waitlock_editor.sh"
 
 #if skip-detection
 (Ensure there was no output)
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1433,6 +1433,9 @@
 env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or ''
 env['HGEMITWARNINGS'] = '1'
 env['TESTTMP'] = _bytes2sys(self._testtmp)
+# the FORWARD_SLASH version is useful when running `sh` on non unix
+# system (e.g. Windows)
+env['TESTTMP_FORWARD_SLASH'] = env['TESTTMP'].replace(os.sep, '/')
 uid_file = os.path.join(_bytes2sys(self._testtmp), 'UID')
 env['HGTEST_UUIDFILE'] = uid_file
 env['TESTNAME'] = self.name
@@ -3113,6 +3116,8 @@
 if pathname:
 testdir = os.path.join(testdir, pathname)
 self._testdir = osenvironb[b'TESTDIR'] = testdir
+osenvironb[b'TESTDIR_FORWARD_SLASH'] = 
osenvironb[b'TESTDIR'].replace(os.sep.encode('ascii'), b'/')
+
 if self.options.outputdir:
 self._outputdir = canonpath(_sys2bytes(self.options.outputdir))
 else:
@@ -3257,6 +3262,7 @@
 fileb = _sys2bytes(__file__)
 runtestdir = os.path.abspath(os.path.dirname(fileb))
 osenvironb[b'RUNTESTDIR'] = runtestdir
+osenvironb[b'RUNTESTDIR_FORWARD_SLASH'] = 
osenvironb[b'RUNTESTDIR'].replace(os.sep.encode('ascii'), b'/')
 if PYTHON3:
 sepb = _sys2bytes(os.pathsep)
 else:



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12479: tests-racy-mutation: pass the editor through config instead of env variable

2022-04-06 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  On Windows msys seems to do awful mangling of the environment variable content
  that confuses everything to the death. Going through the config works fine, so
  we do that instead.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D12479

AFFECTED FILES
  tests/test-racy-mutations.t

CHANGE DETAILS

diff --git a/tests/test-racy-mutations.t b/tests/test-racy-mutations.t
--- a/tests/test-racy-mutations.t
+++ b/tests/test-racy-mutations.t
@@ -38,14 +38,24 @@
   > EOF
 #endif
 
+  $ cat >> .hg/hgrc << EOF
+  > [ui]
+  > editor=sh $TESTTMP/waitlock_editor.sh
+  > EOF
+
   $ echo foo > foo
-  $ (WAITLOCK_ANNOUNCE="${EDITOR_STARTED}" \
+  $ (unset HGEDITOR;
+  >  WAITLOCK_ANNOUNCE="${EDITOR_STARTED}" \
   >  WAITLOCK_FILE="${MISCHIEF_MANAGED}" \
-  >   HGEDITOR="sh $TESTTMP/waitlock_editor.sh" \
   >   hg commit -qAm 'r1 (foo)' --edit foo > .foo_commit_out 2>&1 ; 
touch "${JOBS_FINISHED}") &
 
 Wait for the "editor" to actually start
-  $ WAITLOCK_FILE="${EDITOR_STARTED}" sh "$TESTTMP/waitlock_editor.sh"
+  $ sh "$RUNTESTDIR/testlib/wait-on-file" 5 "${EDITOR_STARTED}"
+
+  $ cat >> .hg/hgrc << EOF
+  > [ui]
+  > editor=
+  > EOF
 
 Break the locks, and make another commit.
   $ hg debuglocks -LW



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12478: rust-dirstatemap: add unit tests

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  These were missing and have already proven valuable since they have found
  two bugs (fixed in previous patches).
  
  There may be other behavior to test, but this gives us a decent coverage.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12478

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -1427,3 +1427,417 @@
 }))
 }
 }
+#[cfg(test)]
+mod tests {
+use super::*;
+
+/// Shortcut to return tracked descendants of a path.
+/// Panics if the path does not exist.
+fn tracked_descendants(map: , path: &[u8]) -> u32 {
+let path = dbg!(HgPath::new(path));
+let node = map.get_map().get_node(path);
+node.unwrap().unwrap().tracked_descendants_count()
+}
+
+/// Shortcut to return descendants with an entry.
+/// Panics if the path does not exist.
+fn descendants_with_an_entry(map: , path: &[u8]) -> u32 {
+let path = dbg!(HgPath::new(path));
+let node = map.get_map().get_node(path);
+node.unwrap().unwrap().descendants_with_entry_count()
+}
+
+fn assert_does_not_exist(map: , path: &[u8]) {
+let path = dbg!(HgPath::new(path));
+let node = map.get_map().get_node(path);
+assert!(node.unwrap().is_none());
+}
+
+/// Shortcut for path creation in tests
+fn p(b: &[u8]) ->  {
+HgPath::new(b)
+}
+
+/// Test the very simple case a single tracked file
+#[test]
+fn test_tracked_descendants_simple() -> Result<(), DirstateError> {
+let mut map = OwningDirstateMap::new_empty(vec![]);
+assert_eq!(map.len(), 0);
+
+map.set_tracked(p(b"some/nested/path"))?;
+
+assert_eq!(map.len(), 1);
+assert_eq!(tracked_descendants(, b"some"), 1);
+assert_eq!(tracked_descendants(, b"some/nested"), 1);
+assert_eq!(tracked_descendants(, b"some/nested/path"), 0);
+
+map.set_untracked(p(b"some/nested/path"))?;
+assert_eq!(map.len(), 0);
+assert!(map.get_map().get_node(p(b"some"))?.is_none());
+
+Ok(())
+}
+
+/// Test the simple case of all tracked, but multiple files
+#[test]
+fn test_tracked_descendants_multiple() -> Result<(), DirstateError> {
+let mut map = OwningDirstateMap::new_empty(vec![]);
+
+map.set_tracked(p(b"some/nested/path"))?;
+map.set_tracked(p(b"some/nested/file"))?;
+// one layer without any files to test deletion cascade
+map.set_tracked(p(b"some/other/nested/path"))?;
+map.set_tracked(p(b"root_file"))?;
+map.set_tracked(p(b"some/file"))?;
+map.set_tracked(p(b"some/file2"))?;
+map.set_tracked(p(b"some/file3"))?;
+
+assert_eq!(map.len(), 7);
+assert_eq!(tracked_descendants(, b"some"), 6);
+assert_eq!(tracked_descendants(, b"some/nested"), 2);
+assert_eq!(tracked_descendants(, b"some/other"), 1);
+assert_eq!(tracked_descendants(, b"some/other/nested"), 1);
+assert_eq!(tracked_descendants(, b"some/nested/path"), 0);
+
+map.set_untracked(p(b"some/nested/path"))?;
+assert_eq!(map.len(), 6);
+assert_eq!(tracked_descendants(, b"some"), 5);
+assert_eq!(tracked_descendants(, b"some/nested"), 1);
+assert_eq!(tracked_descendants(, b"some/other"), 1);
+assert_eq!(tracked_descendants(, b"some/other/nested"), 1);
+
+map.set_untracked(p(b"some/nested/file"))?;
+assert_eq!(map.len(), 5);
+assert_eq!(tracked_descendants(, b"some"), 4);
+assert_eq!(tracked_descendants(, b"some/other"), 1);
+assert_eq!(tracked_descendants(, b"some/other/nested"), 1);
+assert_does_not_exist(, b"some_nested");
+
+map.set_untracked(p(b"some/other/nested/path"))?;
+assert_eq!(map.len(), 4);
+assert_eq!(tracked_descendants(, b"some"), 3);
+assert_does_not_exist(, b"some/other");
+
+map.set_untracked(p(b"root_file"))?;
+assert_eq!(map.len(), 3);
+assert_eq!(tracked_descendants(, b"some"), 3);
+assert_does_not_exist(, b"root_file");
+
+map.set_untracked(p(b"some/file"))?;
+assert_eq!(map.len(), 2);
+assert_eq!(tracked_descendants(, b"some"), 2);
+assert_does_not_exist(, b"some/file");
+
+map.set_untracked(p(b"some/file2"))?;
+assert_eq!(map.len(), 1);
+assert_eq!(tracked_descendants(, b"some"), 1);
+assert_does_not_exist(, b"some/file2");
+
+map.set_untracked(p(b"some/file3"))?;
+assert_eq!(map.len(), 0);
+

D12477: rust: add `Debug` trait to a bunch of structs

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is useful when... debugging. Right now the output is not in the most
  readable state it could be, but this is very low effort and is good enough
  for now. We may want to write a nicer custom debug formatter for some of those
  structs in the future.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12477

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-core/src/dirstate_tree/on_disk.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/dirstate_tree/on_disk.rs 
b/rust/hg-core/src/dirstate_tree/on_disk.rs
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs
+++ b/rust/hg-core/src/dirstate_tree/on_disk.rs
@@ -84,7 +84,7 @@
 
 /// Fields are documented in the *The data file format*
 /// section of `mercurial/helptext/internals/dirstate-v2.txt`
-#[derive(BytesCast)]
+#[derive(BytesCast, Debug)]
 #[repr(C)]
 pub(super) struct Node {
 full_path: PathSlice,
@@ -124,7 +124,7 @@
 }
 
 /// Duration since the Unix epoch
-#[derive(BytesCast, Copy, Clone)]
+#[derive(BytesCast, Copy, Clone, Debug)]
 #[repr(C)]
 struct PackedTruncatedTimestamp {
 truncated_seconds: U32Be,
@@ -152,7 +152,7 @@
 /// Always sorted by ascending `full_path`, to allow binary search.
 /// Since nodes with the same parent nodes also have the same parent path,
 /// only the `base_name`s need to be compared during binary search.
-#[derive(BytesCast, Copy, Clone)]
+#[derive(BytesCast, Copy, Clone, Debug)]
 #[repr(C)]
 struct ChildNodes {
 start: Offset,
@@ -160,7 +160,7 @@
 }
 
 /// A `HgPath` of `len` bytes
-#[derive(BytesCast, Copy, Clone)]
+#[derive(BytesCast, Copy, Clone, Debug)]
 #[repr(C)]
 struct PathSlice {
 start: Offset,
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -32,6 +32,7 @@
 /// anymore) is less than this fraction of the total amount of existing data.
 const ACCEPTABLE_UNREACHABLE_BYTES_RATIO: f32 = 0.5;
 
+#[derive(Debug)]
 pub struct DirstateMap<'on_disk> {
 /// Contents of the `.hg/dirstate` file
 pub(super) on_disk: &'on_disk [u8],
@@ -61,21 +62,25 @@
 
 /// Similar to `&'tree Cow<'on_disk, HgPath>`, but can also be returned
 /// for on-disk nodes that don’t actually have a `Cow` to borrow.
+#[derive(Debug)]
 pub(super) enum BorrowedPath<'tree, 'on_disk> {
 InMemory(&'tree HgPathBuf),
 OnDisk(&'on_disk HgPath),
 }
 
+#[derive(Debug)]
 pub(super) enum ChildNodes<'on_disk> {
 InMemory(FastHashMap, Node<'on_disk>>),
 OnDisk(&'on_disk [on_disk::Node]),
 }
 
+#[derive(Debug)]
 pub(super) enum ChildNodesRef<'tree, 'on_disk> {
 InMemory(&'tree FastHashMap, Node<'on_disk>>),
 OnDisk(&'on_disk [on_disk::Node]),
 }
 
+#[derive(Debug)]
 pub(super) enum NodeRef<'tree, 'on_disk> {
 InMemory(&'tree NodeKey<'on_disk>, &'tree Node<'on_disk>),
 OnDisk(&'on_disk on_disk::Node),
@@ -383,7 +388,7 @@
 }
 
 /// Represents a file or a directory
-#[derive(Default)]
+#[derive(Default, Debug)]
 pub(super) struct Node<'on_disk> {
 pub(super) data: NodeData,
 
@@ -399,6 +404,7 @@
 pub(super) tracked_descendants_count: u32,
 }
 
+#[derive(Debug)]
 pub(super) enum NodeData {
 Entry(DirstateEntry),
 CachedDirectory { mtime: TruncatedTimestamp },



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12476: rust-dirstatemap: use `` instead of `HgPathBuf` in `copy_map_insert`

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  No reason to require an owned path here.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12476

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -23,13 +23,10 @@
 pybytes_deref::PyBytesDeref,
 };
 use hg::{
-dirstate::StateMapIter,
-dirstate_tree::on_disk::DirstateV2ParseError,
-dirstate_tree::owning::OwningDirstateMap,
-revlog::Node,
-utils::files::normalize_case,
-utils::hg_path::{HgPath, HgPathBuf},
-DirstateEntry, DirstateError, DirstateParents, EntryState,
+dirstate::StateMapIter, dirstate_tree::on_disk::DirstateV2ParseError,
+dirstate_tree::owning::OwningDirstateMap, revlog::Node,
+utils::files::normalize_case, utils::hg_path::HgPath, DirstateEntry,
+DirstateError, DirstateParents, EntryState,
 };
 
 // TODO
@@ -428,8 +425,8 @@
 self.inner(py)
 .borrow_mut()
 .copy_map_insert(
-HgPathBuf::from_bytes(key.data(py)),
-HgPathBuf::from_bytes(value.data(py)),
+HgPath::new(key.data(py)),
+HgPath::new(value.data(py)),
 )
 .map_err(|e| v2_error(py, e))?;
 Ok(py.None())
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -1278,8 +1278,8 @@
 
 pub fn copy_map_insert(
  self,
-key: HgPathBuf,
-value: HgPathBuf,
+key: ,
+value: ,
 ) -> Result, DirstateV2ParseError> {
 self.with_dmap_mut(|map| {
 let node = DirstateMap::get_or_insert_node(
@@ -1293,7 +1293,10 @@
 if node.copy_source.is_none() {
 map.nodes_with_copy_source_count += 1
 }
-Ok(node.copy_source.replace(value.into()).map(Cow::into_owned))
+Ok(node
+.copy_source
+.replace(value.to_owned().into())
+.map(Cow::into_owned))
 })
 }
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12475: rust-dirstatemap: use `DirstateEntry::tracked` directly

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `state()` is a legacy API that will be removed at some point, let's use the
  newer API.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12475

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -982,9 +982,7 @@
  self,
 filename: ,
 ) -> Result<(), DirstateError> {
-let was_tracked = self
-.get(filename)?
-.map_or(false, |e| e.state().is_tracked());
+let was_tracked = self.get(filename)?.map_or(false, |e| e.tracked());
 struct Dropped {
 was_tracked: bool,
 had_entry: bool,



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12473: rust-dirstatemap: remove `set_dirstate_entry`/`set_entry` methods

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  These methods were needed crutches before the Rust implementation caught up
  to Python. Calling `set_entry` (whether from Python or Rust) was dangerous
  since it didn't update any of the counters of the DirstateMap data structure,
  while having no real way of knowing when to use it "correctly" except it you
  were one of the 3 people who looked deep enough into the soul of this code.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12473

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -104,20 +104,6 @@
 }
 }
 
-def set_dirstate_item(
-,
-path: PyObject,
-item: DirstateItem
-) -> PyResult {
-let f = path.extract::(py)?;
-let filename = HgPath::new(f.data(py));
-self.inner(py)
-.borrow_mut()
-.set_entry(filename, item.get_entry(py))
-.map_err(|e| v2_error(py, e))?;
-Ok(py.None())
-}
-
 def set_tracked(, f: PyObject) -> PyResult {
 Ok(self.inner(py).borrow_mut()
 .set_tracked(
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -878,17 +878,6 @@
 });
 }
 
-pub fn set_entry(
- self,
-filename: ,
-entry: DirstateEntry,
-) -> Result<(), DirstateV2ParseError> {
-self.with_dmap_mut(|map| {
-map.get_or_insert()?.data = NodeData::Entry(entry);
-Ok(())
-})
-}
-
 pub fn set_tracked(
  self,
 filename: ,



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12474: rust-cpython: remove unused API to `drop_entry_and_copy_source`

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is not used anywhere anymore and its use cases are covered by the new API

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12474

AFFECTED FILES
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -222,17 +222,6 @@
 Ok(PyNone)
 }
 
-def drop_item_and_copy_source(
-,
-f: PyBytes,
-) -> PyResult {
-self.inner(py)
-.borrow_mut()
-.drop_entry_and_copy_source(HgPath::new(f.data(py)))
-.map_err(|e |dirstate_error(py, e))?;
-Ok(PyNone)
-}
-
 def hastrackeddir(, d: PyObject) -> PyResult {
 let d = d.extract::(py)?;
 Ok(self.inner(py).borrow_mut()



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12472: rust-dirstatemap: implement part of the `setparents` logic

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The Python code does many round-trip calls to the Rust dirstatemap when copy
  information needs to be dropped in `setparents`.
  
  This may result in improved performance on `commit`, `update` and other such
  commands, but was mostly done to drop the last use of `set_dirstate_item`.
  See inline comments for an asterisk about performance, and see next patch for
  why `set_dirstate_item` has to go.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12472

AFFECTED FILES
  mercurial/dirstatemap.py
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -506,6 +506,19 @@
 Ok(dirs)
 }
 
+def setparents_fixup() -> PyResult {
+let dict = PyDict::new(py);
+let copies = self.inner(py).borrow_mut().setparents_fixup();
+for (key, value) in copies.map_err(|e| v2_error(py, e))? {
+dict.set_item(
+py,
+PyBytes::new(py, key.as_bytes()),
+PyBytes::new(py, value.as_bytes()),
+)?;
+}
+Ok(dict)
+}
+
 def debug_iter(, all: bool) -> PyResult {
 let dirs = PyList::new(py, &[]);
 for item in self.inner(py).borrow().debug_iter(all) {
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -1369,6 +1369,41 @@
 )))
 }
 
+/// Only public because it needs to be exposed to the Python layer.
+/// It is not the full `setparents` logic, only the parts that mutate the
+/// entries.
+pub fn setparents_fixup(
+ self,
+) -> Result, DirstateV2ParseError> {
+// XXX
+// All the copying and re-querying is quite inefficient, but this is
+// still a lot better than doing it from Python.
+//
+// The better solution is to develop a mechanism for `iter_mut`,
+// which will be a lot more involved: we're dealing with a lazy,
+// append-mostly, tree-like data structure. This will do for now.
+let mut copies = vec![];
+let mut files_with_p2_info = vec![];
+for res in self.iter() {
+let (path, entry) = res?;
+if entry.p2_info() {
+files_with_p2_info.push(path.to_owned())
+}
+}
+self.with_dmap_mut(|map| {
+for path in files_with_p2_info.iter() {
+let node = map.get_or_insert(path)?;
+let entry =
+node.data.as_entry_mut().expect("entry should exist");
+entry.drop_merge_data();
+if let Some(source) = node.copy_source.take().as_deref() {
+copies.push((path.to_owned(), source.to_owned()));
+}
+}
+Ok(copies)
+})
+}
+
 pub fn debug_iter(
 ,
 all: bool,
diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -593,22 +593,7 @@
 self._dirtyparents = True
 copies = {}
 if fold_p2:
-# Collect into an intermediate list to avoid a `RuntimeError`
-# exception due to mutation during iteration.
-# TODO: move this the whole loop to Rust where `iter_mut`
-# enables in-place mutation of elements of a collection while
-# iterating it, without mutating the collection itself.
-files_with_p2_info = [
-f for f, s in self._map.items() if s.p2_info
-]
-rust_map = self._map
-for f in files_with_p2_info:
-e = rust_map.get(f)
-source = self.copymap.pop(f, None)
-if source:
-copies[f] = source
-e.drop_merge_data()
-rust_map.set_dirstate_item(f, e)
+copies = self._map.setparents_fixup()
 return copies
 
 ### disk interaction



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12471: dirstate-item: add missing bit of docstring

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12471

AFFECTED FILES
  mercurial/pure/parsers.py

CHANGE DETAILS

diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -278,7 +278,7 @@
 self._mtime_ns = None
 
 def drop_merge_data(self):
-"""remove all "merge-only" from a DirstateItem
+"""remove all "merge-only" information from a DirstateItem
 
 This is to be call by the dirstatemap code when the second parent is 
dropped
 """



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12470: dirstatemap: move `_dirs_incr` and `_dirs_decr` methods out of the common

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  They are only used by the Python implementation now

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12470

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -79,25 +79,6 @@
 def __getitem__(self, item):
 return self._map[item]
 
-### sub-class utility method
-#
-# Use to allow for generic implementation of some method while still coping
-# with minor difference between implementation.
-
-def _dirs_incr(self, filename, old_entry=None):
-"""increment the dirstate counter if applicable
-
-This might be a no-op for some subclasses who deal with directory
-tracking in a different way.
-"""
-
-def _dirs_decr(self, filename, old_entry=None, remove_variant=False):
-"""decrement the dirstate counter if applicable
-
-This might be a no-op for some subclasses who deal with directory
-tracking in a different way.
-"""
-
 ### disk interaction
 
 def _opendirstatefile(self):
@@ -354,7 +335,7 @@
 # (e.g. "has_dir")
 
 def _dirs_incr(self, filename, old_entry=None):
-"""incremente the dirstate counter if applicable"""
+"""increment the dirstate counter if applicable"""
 if (
 old_entry is None or old_entry.removed
 ) and "_dirs" in self.__dict__:
@@ -363,7 +344,7 @@
 self._alldirs.addpath(filename)
 
 def _dirs_decr(self, filename, old_entry=None, remove_variant=False):
-"""decremente the dirstate counter if applicable"""
+"""decrement the dirstate counter if applicable"""
 if old_entry is not None:
 if "_dirs" in self.__dict__ and not old_entry.removed:
 self._dirs.delpath(filename)



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12469: dirstatemap: move `_refresh_entry` out of the common methods

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is only used in the Python implementation now

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12469

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -98,9 +98,6 @@
 tracking in a different way.
 """
 
-def _refresh_entry(self, f, entry):
-"""record updated state of an entry"""
-
 ### disk interaction
 
 def _opendirstatefile(self):
@@ -523,6 +520,7 @@
 self._refresh_entry(filename, entry)
 
 def _refresh_entry(self, f, entry):
+"""record updated state of an entry"""
 if not entry.any_tracked:
 self._map.pop(f, None)
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12468: dirstatemap: move `_drop_entry` out of the common methods

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Only the Python implementation uses it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12468

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -101,13 +101,6 @@
 def _refresh_entry(self, f, entry):
 """record updated state of an entry"""
 
-def _drop_entry(self, f):
-"""remove any entry for file f
-
-This should also drop associated copy information
-
-The fact we actually need to drop it is the responsability of the 
caller"""
-
 ### disk interaction
 
 def _opendirstatefile(self):
@@ -534,6 +527,11 @@
 self._map.pop(f, None)
 
 def _drop_entry(self, f):
+"""remove any entry for file f
+
+This should also drop associated copy information
+
+The fact we actually need to drop it is the responsability of the 
caller"""
 self._map.pop(f, None)
 self.copymap.pop(f, None)
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12467: rust-dirstatemap: remove `_drop_entry`

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is not used anywhere anymore

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12467

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -730,6 +730,3 @@
 has_meaningful_mtime,
 parentfiledata,
 )
-
-def _drop_entry(self, f):
-self._map.drop_item_and_copy_source(f)



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12466: rust-dirstatemap: remove `__settitem__`

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is not used anywhere now.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12466

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -733,7 +733,3 @@
 
 def _drop_entry(self, f):
 self._map.drop_item_and_copy_source(f)
-
-def __setitem__(self, key, value):
-assert isinstance(value, DirstateItem)
-self._map.set_dirstate_item(key, value)



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12464: rust-distatemap: remove `addfile` API

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  All of its users have been migrated to the new API

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12464

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -118,20 +118,6 @@
 Ok(py.None())
 }
 
-def addfile(
-,
-f: PyBytes,
-item: DirstateItem,
-) -> PyResult {
-let filename = HgPath::new(f.data(py));
-let entry = item.get_entry(py);
-self.inner(py)
-.borrow_mut()
-.add_file(filename, entry)
-.map_err(|e |dirstate_error(py, e))?;
-Ok(PyNone)
-}
-
 def set_tracked(, f: PyObject) -> PyResult {
 Ok(self.inner(py).borrow_mut()
 .set_tracked(
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -728,49 +728,6 @@
 Ok(new)
 }
 
-fn add_or_remove_file(
- self,
-path: ,
-old_state: Option,
-new_entry: DirstateEntry,
-) -> Result<(), DirstateV2ParseError> {
-let had_entry = old_state.is_some();
-let was_tracked = old_state.map_or(false, |s| s.is_tracked());
-let tracked_count_increment =
-match (was_tracked, new_entry.state().is_tracked()) {
-(false, true) => 1,
-(true, false) => -1,
-_ => 0,
-};
-
-let node = Self::get_or_insert_node(
-self.on_disk,
- self.unreachable_bytes,
- self.root,
-path,
-WithBasename::to_cow_owned,
-|ancestor| {
-if !had_entry {
-ancestor.descendants_with_entry_count += 1;
-}
-
-// We can’t use `+= increment` because the counter is unsigned,
-// and we want debug builds to detect accidental underflow
-// through zero
-match tracked_count_increment {
-1 => ancestor.tracked_descendants_count += 1,
--1 => ancestor.tracked_descendants_count -= 1,
-_ => {}
-}
-},
-)?;
-if !had_entry {
-self.nodes_with_entry_count += 1
-}
-node.data = NodeData::Entry(new_entry);
-Ok(())
-}
-
 /// It is the responsibility of the caller to know that there was an entry
 /// there before. Does not handle the removal of copy source
 fn set_untracked(
@@ -932,17 +889,6 @@
 })
 }
 
-pub fn add_file(
- self,
-filename: ,
-entry: DirstateEntry,
-) -> Result<(), DirstateError> {
-let old_state = self.get(filename)?.map(|e| e.state());
-self.with_dmap_mut(|map| {
-Ok(map.add_or_remove_file(filename, old_state, entry)?)
-})
-}
-
 pub fn set_tracked(
  self,
 filename: ,



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12465: rust-dirstatemap: remove unused `_refresh_entry` implementation

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This was only used in the newer APIs, all of which have been rewritten in Rust

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12465

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -701,12 +701,6 @@
 
 ### code related to manipulation of entries and copy-sources
 
-def _refresh_entry(self, f, entry):
-if not entry.any_tracked:
-self._map.drop_item_and_copy_source(f)
-else:
-self._map.addfile(f, entry)
-
 def set_tracked(self, f):
 return self._map.set_tracked(f)
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12463: rust-dirstatemap: remove `removefile` API

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Its callers have been migrated to the newer dirstate API.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12463

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -250,25 +250,6 @@
 Ok(PyNone)
 }
 
-def removefile(
-,
-f: PyObject,
-in_merge: PyObject
-) -> PyResult {
-self.inner(py).borrow_mut()
-.remove_file(
-HgPath::new(f.extract::(py)?.data(py)),
-in_merge.extract::(py)?.is_true(),
-)
-.or_else(|_| {
-Err(PyErr::new::(
-py,
-"Dirstate error".to_string(),
-))
-})?;
-Ok(py.None())
-}
-
 def drop_item_and_copy_source(
 ,
 f: PyBytes,
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -15,8 +15,6 @@
 use crate::dirstate::ParentFileData;
 use crate::dirstate::StateMapIter;
 use crate::dirstate::TruncatedTimestamp;
-use crate::dirstate::SIZE_FROM_OTHER_PARENT;
-use crate::dirstate::SIZE_NON_NORMAL;
 use crate::matchers::Matcher;
 use crate::utils::hg_path::{HgPath, HgPathBuf};
 use crate::DirstateEntry;
@@ -1045,40 +1043,6 @@
 })
 }
 
-pub fn remove_file(
- self,
-filename: ,
-in_merge: bool,
-) -> Result<(), DirstateError> {
-let old_entry_opt = self.get(filename)?;
-let old_state = old_entry_opt.map(|e| e.state());
-let mut size = 0;
-if in_merge {
-// XXX we should not be able to have 'm' state and 'FROM_P2' if not
-// during a merge. So I (marmoute) am not sure we need the
-// conditionnal at all. Adding double checking this with assert
-// would be nice.
-if let Some(old_entry) = old_entry_opt {
-// backup the previous state
-if old_entry.state() == EntryState::Merged {
-size = SIZE_NON_NORMAL;
-} else if old_entry.state() == EntryState::Normal
-&& old_entry.size() == SIZE_FROM_OTHER_PARENT
-{
-// other parent
-size = SIZE_FROM_OTHER_PARENT;
-}
-}
-}
-if size == 0 {
-self.copy_map_remove(filename)?;
-}
-self.with_dmap_mut(|map| {
-let entry = DirstateEntry::new_removed(size);
-Ok(map.add_or_remove_file(filename, old_state, entry)?)
-})
-}
-
 pub fn drop_entry_and_copy_source(
  self,
 filename: ,



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12462: rhg: use the new `set_clean` API

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12462

AFFECTED FILES
  rust/rhg/src/commands/status.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs
--- a/rust/rhg/src/commands/status.rs
+++ b/rust/rhg/src/commands/status.rs
@@ -15,7 +15,6 @@
 use hg::dirstate::has_exec_bit;
 use hg::dirstate::status::StatusPath;
 use hg::dirstate::TruncatedTimestamp;
-use hg::dirstate::RANGE_MASK_31BIT;
 use hg::errors::{HgError, IoResultExt};
 use hg::lock::LockError;
 use hg::manifest::Manifest;
@@ -390,12 +389,8 @@
 .when_reading_file(_path)?
 {
 let mode = fs_metadata.mode();
-let size = fs_metadata.len() as u32 & RANGE_MASK_31BIT;
-let mut entry = dmap
-.get(_path)?
-.expect("ambiguous file not in dirstate");
-entry.set_clean(mode, size, mtime);
-dmap.add_file(_path, entry)?;
+let size = fs_metadata.len();
+dmap.set_clean(_path, mode, size as u32, mtime)?;
 dirstate_write_needed = true
 }
 }



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12460: rust-dirstatemap: add `set_untracked` method

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is the new API that Python has already migrated to

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12460

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -145,6 +145,19 @@
 })?.to_py_object(py))
 }
 
+def set_untracked(, f: PyObject) -> PyResult {
+Ok(self.inner(py).borrow_mut()
+.set_untracked(
+HgPath::new(f.extract::(py)?.data(py)),
+)
+.or_else(|_| {
+Err(PyErr::new::(
+py,
+"Dirstate error".to_string(),
+))
+})?.to_py_object(py))
+}
+
 def set_clean(
 ,
 f: PyObject,
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -773,6 +773,29 @@
 Ok(())
 }
 
+/// It is the responsibility of the caller to know that there was an entry
+/// there before. Does not handle the removal of copy source
+fn set_untracked(
+ self,
+filename: ,
+old_entry: DirstateEntry,
+) -> Result<(), DirstateV2ParseError> {
+let node = Self::get_or_insert_node(
+self.on_disk,
+ self.unreachable_bytes,
+ self.root,
+filename,
+WithBasename::to_cow_owned,
+|ancestor| {
+ancestor.tracked_descendants_count -= 1;
+},
+)?;
+let mut new_entry = old_entry.clone();
+new_entry.set_untracked();
+node.data = NodeData::Entry(new_entry);
+Ok(())
+}
+
 fn set_clean(
  self,
 filename: ,
@@ -930,6 +953,39 @@
 self.with_dmap_mut(|map| map.set_tracked(filename, old_entry_opt))
 }
 
+pub fn set_untracked(
+ self,
+filename: ,
+) -> Result {
+let old_entry_opt = self.get(filename)?;
+match old_entry_opt {
+None => Ok(false),
+Some(old_entry) => {
+if !old_entry.tracked() {
+// `DirstateMap::set_untracked` is not a noop if
+// already not tracked as it will decrement the
+// tracked counters while going down.
+return Ok(true);
+}
+if old_entry.added() {
+// Untracking an "added" entry will just result in a
+// worthless entry (and other parts of the code will
+// complain about it), just drop it entirely.
+self.drop_entry_and_copy_source(filename)?;
+return Ok(true);
+}
+if !old_entry.p2_info() {
+self.copy_map_remove(filename)?;
+}
+
+self.with_dmap_mut(|map| {
+map.set_untracked(filename, old_entry)?;
+Ok(true)
+})
+}
+}
+}
+
 pub fn set_clean(
  self,
 filename: ,



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12461: dirstatemap: move `set_untracked` out of the common methods

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  There is a dedicated Rust implementation now

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12461

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -108,21 +108,6 @@
 
 The fact we actually need to drop it is the responsability of the 
caller"""
 
-### method to manipulate the entries
-
-def set_untracked(self, f):
-"""Mark a file as no longer tracked in the dirstate map"""
-entry = self.get(f)
-if entry is None:
-return False
-else:
-self._dirs_decr(f, old_entry=entry, remove_variant=not entry.added)
-if not entry.p2_info:
-self.copymap.pop(f, None)
-entry.set_untracked()
-self._refresh_entry(f, entry)
-return True
-
 ### disk interaction
 
 def _opendirstatefile(self):
@@ -517,6 +502,19 @@
 self._refresh_entry(filename, entry)
 return new
 
+def set_untracked(self, f):
+"""Mark a file as no longer tracked in the dirstate map"""
+entry = self.get(f)
+if entry is None:
+return False
+else:
+self._dirs_decr(f, old_entry=entry, remove_variant=not entry.added)
+if not entry.p2_info:
+self.copymap.pop(f, None)
+entry.set_untracked()
+self._refresh_entry(f, entry)
+return True
+
 def set_clean(self, filename, mode, size, mtime):
 """mark a file as back to a clean state"""
 entry = self[filename]
@@ -712,6 +710,9 @@
 def set_tracked(self, f):
 return self._map.set_tracked(f)
 
+def set_untracked(self, f):
+return self._map.set_untracked(f)
+
 def set_clean(self, filename, mode, size, mtime):
 self._map.set_clean(filename, mode, size, mtime)
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12458: rust-dirstatemap: add `set_possibly_dirty` method

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is the new API that Python has already migrated to.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12458

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -172,6 +172,20 @@
 Ok(PyNone)
 }
 
+def set_possibly_dirty(, f: PyObject) -> PyResult {
+self.inner(py).borrow_mut()
+.set_possibly_dirty(
+HgPath::new(f.extract::(py)?.data(py)),
+)
+.or_else(|_| {
+Err(PyErr::new::(
+py,
+"Dirstate error".to_string(),
+))
+})?;
+Ok(PyNone)
+}
+
 def reset_state(
 ,
 f: PyObject,
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -427,6 +427,13 @@
 _ => None,
 }
 }
+
+fn as_entry_mut( self) -> Option< DirstateEntry> {
+match self {
+NodeData::Entry(entry) => Some(entry),
+_ => None,
+}
+}
 }
 
 impl<'on_disk> DirstateMap<'on_disk> {
@@ -788,6 +795,24 @@
 Ok(())
 }
 
+fn set_possibly_dirty(
+ self,
+filename: ,
+) -> Result<(), DirstateError> {
+let node = Self::get_or_insert_node(
+self.on_disk,
+ self.unreachable_bytes,
+ self.root,
+filename,
+WithBasename::to_cow_owned,
+|_ancestor| {},
+)?;
+let entry = node.data.as_entry_mut().expect("entry should exist");
+entry.set_possibly_dirty();
+node.data = NodeData::Entry(*entry);
+Ok(())
+}
+
 fn iter_nodes<'tree>(
 &'tree self,
 ) -> impl Iterator<
@@ -926,6 +951,16 @@
 })
 }
 
+pub fn set_possibly_dirty(
+ self,
+filename: ,
+) -> Result<(), DirstateError> {
+if self.get(filename)?.is_none() {
+return Err(DirstateMapError::PathNotFound(filename.into()).into());
+}
+self.with_dmap_mut(|map| map.set_possibly_dirty(filename))
+}
+
 pub fn reset_state(
  self,
 filename: ,



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12459: dirstatemap: move `set_possibly_dirty` out of the common methods

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  There exists now a dedicated Rust implementation

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12459

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -110,12 +110,6 @@
 
 ### method to manipulate the entries
 
-def set_possibly_dirty(self, filename):
-"""record that the current state of the file on disk is unknown"""
-entry = self[filename]
-entry.set_possibly_dirty()
-self._refresh_entry(filename, entry)
-
 def set_untracked(self, f):
 """Mark a file as no longer tracked in the dirstate map"""
 entry = self.get(f)
@@ -531,6 +525,12 @@
 self._refresh_entry(filename, entry)
 self.copymap.pop(filename, None)
 
+def set_possibly_dirty(self, filename):
+"""record that the current state of the file on disk is unknown"""
+entry = self[filename]
+entry.set_possibly_dirty()
+self._refresh_entry(filename, entry)
+
 def _refresh_entry(self, f, entry):
 if not entry.any_tracked:
 self._map.pop(f, None)
@@ -715,6 +715,9 @@
 def set_clean(self, filename, mode, size, mtime):
 self._map.set_clean(filename, mode, size, mtime)
 
+def set_possibly_dirty(self, f):
+self._map.set_possibly_dirty(f)
+
 def reset_state(
 self,
 filename,



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12457: dirstatemap: move `set_clean` out of common methods

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This now has a dedicated Rust implementation

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12457

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -116,14 +116,6 @@
 entry.set_possibly_dirty()
 self._refresh_entry(filename, entry)
 
-def set_clean(self, filename, mode, size, mtime):
-"""mark a file as back to a clean state"""
-entry = self[filename]
-size = size & rangemask
-entry.set_clean(mode, size, mtime)
-self._refresh_entry(filename, entry)
-self.copymap.pop(filename, None)
-
 def set_untracked(self, f):
 """Mark a file as no longer tracked in the dirstate map"""
 entry = self.get(f)
@@ -531,6 +523,14 @@
 self._refresh_entry(filename, entry)
 return new
 
+def set_clean(self, filename, mode, size, mtime):
+"""mark a file as back to a clean state"""
+entry = self[filename]
+size = size & rangemask
+entry.set_clean(mode, size, mtime)
+self._refresh_entry(filename, entry)
+self.copymap.pop(filename, None)
+
 def _refresh_entry(self, f, entry):
 if not entry.any_tracked:
 self._map.pop(f, None)
@@ -712,6 +712,9 @@
 def set_tracked(self, f):
 return self._map.set_tracked(f)
 
+def set_clean(self, filename, mode, size, mtime):
+self._map.set_clean(filename, mode, size, mtime)
+
 def reset_state(
 self,
 filename,



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12456: rust-dirstatemap: add `set_clean` method

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is the new dirstate API that has already been moved to in Python.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12456

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -145,6 +145,33 @@
 })?.to_py_object(py))
 }
 
+def set_clean(
+,
+f: PyObject,
+mode: u32,
+size: u32,
+mtime: (i64, u32, bool)
+) -> PyResult {
+let (mtime_s, mtime_ns, second_ambiguous) = mtime;
+let timestamp = TruncatedTimestamp::new_truncate(
+mtime_s, mtime_ns, second_ambiguous
+);
+self.inner(py).borrow_mut()
+.set_clean(
+HgPath::new(f.extract::(py)?.data(py)),
+mode,
+size,
+timestamp,
+)
+.or_else(|_| {
+Err(PyErr::new::(
+py,
+"Dirstate error".to_string(),
+))
+})?;
+Ok(PyNone)
+}
+
 def reset_state(
 ,
 f: PyObject,
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -21,6 +21,7 @@
 use crate::utils::hg_path::{HgPath, HgPathBuf};
 use crate::DirstateEntry;
 use crate::DirstateError;
+use crate::DirstateMapError;
 use crate::DirstateParents;
 use crate::DirstateStatus;
 use crate::EntryState;
@@ -765,6 +766,28 @@
 Ok(())
 }
 
+fn set_clean(
+ self,
+filename: ,
+old_entry: DirstateEntry,
+mode: u32,
+size: u32,
+mtime: TruncatedTimestamp,
+) -> Result<(), DirstateError> {
+let node = Self::get_or_insert_node(
+self.on_disk,
+ self.unreachable_bytes,
+ self.root,
+filename,
+WithBasename::to_cow_owned,
+|_ancestor| {},
+)?;
+let mut new_entry = old_entry.clone();
+new_entry.set_clean(mode, size, mtime);
+node.data = NodeData::Entry(new_entry);
+Ok(())
+}
+
 fn iter_nodes<'tree>(
 &'tree self,
 ) -> impl Iterator<
@@ -882,6 +905,27 @@
 self.with_dmap_mut(|map| map.set_tracked(filename, old_entry_opt))
 }
 
+pub fn set_clean(
+ self,
+filename: ,
+mode: u32,
+size: u32,
+mtime: TruncatedTimestamp,
+) -> Result<(), DirstateError> {
+let old_entry = match self.get(filename)? {
+None => {
+return Err(
+DirstateMapError::PathNotFound(filename.into()).into()
+)
+}
+Some(e) => e,
+};
+self.copy_map_remove(filename)?;
+self.with_dmap_mut(|map| {
+map.set_clean(filename, old_entry, mode, size, mtime)
+})
+}
+
 pub fn reset_state(
  self,
 filename: ,



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12453: rust-dirstatemap: add Rust implementation of `reset_state`

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is the new API which has already been defined in Python

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12453

AFFECTED FILES
  rust/hg-core/src/dirstate/entry.rs
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -15,6 +15,7 @@
 exc, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, PyNone, PyObject,
 PyResult, Python, PythonObject, ToPyObject, UnsafePyLeaked,
 };
+use hg::dirstate::{ParentFileData, TruncatedTimestamp};
 
 use crate::{
 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
@@ -144,6 +145,57 @@
 })?.to_py_object(py))
 }
 
+def reset_state(
+,
+f: PyObject,
+wc_tracked: bool,
+p1_tracked: bool,
+p2_info: bool,
+has_meaningful_mtime: bool,
+parentfiledata: Option<(u32, u32, Option<(i64, u32, bool)>)>,
+) -> PyResult {
+let mut has_meaningful_mtime = has_meaningful_mtime;
+let parent_file_data = match parentfiledata {
+None => {
+has_meaningful_mtime = false;
+None
+},
+Some(data) => {
+let (mode, size, mtime_info) = data;
+let mtime = if let Some(mtime_info) = mtime_info {
+let (mtime_s, mtime_ns, second_ambiguous) = mtime_info;
+let timestamp = TruncatedTimestamp::new_truncate(
+mtime_s, mtime_ns, second_ambiguous
+);
+Some(timestamp)
+} else {
+has_meaningful_mtime = false;
+None
+};
+Some(ParentFileData {
+mode_size: Some((mode, size)),
+mtime,
+})
+}
+};
+self.inner(py).borrow_mut()
+.reset_state(
+HgPath::new(f.extract::(py)?.data(py)),
+wc_tracked,
+p1_tracked,
+p2_info,
+has_meaningful_mtime,
+parent_file_data,
+)
+.or_else(|_| {
+Err(PyErr::new::(
+py,
+"Dirstate error".to_string(),
+))
+})?;
+Ok(PyNone)
+}
+
 def removefile(
 ,
 f: PyObject,
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -11,6 +11,8 @@
 use crate::dirstate::parsers::packed_entry_size;
 use crate::dirstate::parsers::parse_dirstate_entries;
 use crate::dirstate::CopyMapIter;
+use crate::dirstate::DirstateV2Data;
+use crate::dirstate::ParentFileData;
 use crate::dirstate::StateMapIter;
 use crate::dirstate::TruncatedTimestamp;
 use crate::dirstate::SIZE_FROM_OTHER_PARENT;
@@ -606,6 +608,73 @@
 }
 }
 
+fn reset_state(
+ self,
+filename: ,
+old_entry_opt: Option,
+wc_tracked: bool,
+p1_tracked: bool,
+p2_info: bool,
+has_meaningful_mtime: bool,
+parent_file_data_opt: Option,
+) -> Result<(), DirstateError> {
+let (had_entry, was_tracked) = match old_entry_opt {
+Some(old_entry) => (true, old_entry.tracked()),
+None => (false, false),
+};
+let node = Self::get_or_insert_node(
+self.on_disk,
+ self.unreachable_bytes,
+ self.root,
+filename,
+WithBasename::to_cow_owned,
+|ancestor| {
+if !had_entry {
+ancestor.descendants_with_entry_count += 1;
+}
+if was_tracked {
+if !wc_tracked {
+ancestor.tracked_descendants_count = ancestor
+.tracked_descendants_count
+.checked_sub(1)
+.expect("tracked count to be >= 0");
+}
+} else {
+if wc_tracked {
+ancestor.tracked_descendants_count += 1;
+}
+}
+},
+)?;
+
+let v2_data = if let Some(parent_file_data) = parent_file_data_opt {
+DirstateV2Data {
+wc_tracked,
+p1_tracked,
+p2_info,
+mode_size: 

D12455: dirstatemap: remove `_insert_entry`

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This was needed as a compatibility layer for the Python and Rust
  implementations, but it is not called from anywhere in Rust anymore.
  
  The two remaining calls have been inlined.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12455

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -101,12 +101,6 @@
 def _refresh_entry(self, f, entry):
 """record updated state of an entry"""
 
-def _insert_entry(self, f, entry):
-"""add a new dirstate entry (or replace an unrelated one)
-
-The fact it is actually new is the responsability of the caller
-"""
-
 def _drop_entry(self, f):
 """remove any entry for file f
 
@@ -511,7 +505,7 @@
 has_meaningful_mtime=has_meaningful_mtime,
 parentfiledata=parentfiledata,
 )
-self._insert_entry(filename, entry)
+self._map[filename] = entry
 
 def set_tracked(self, filename):
 new = False
@@ -522,7 +516,7 @@
 wc_tracked=True,
 )
 
-self._insert_entry(filename, entry)
+self._map[filename] = entry
 new = True
 elif not entry.tracked:
 self._dirs_incr(filename, entry)
@@ -541,9 +535,6 @@
 if not entry.any_tracked:
 self._map.pop(f, None)
 
-def _insert_entry(self, f, entry):
-self._map[f] = entry
-
 def _drop_entry(self, f):
 self._map.pop(f, None)
 self.copymap.pop(f, None)
@@ -718,9 +709,6 @@
 else:
 self._map.addfile(f, entry)
 
-def _insert_entry(self, f, entry):
-self._map.addfile(f, entry)
-
 def set_tracked(self, f):
 return self._map.set_tracked(f)
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12454: dirstatemap: move `reset_state` out of common methods

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Now that we have a Rust implementation, we defer to that accordingly.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12454

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -143,45 +143,6 @@
 self._refresh_entry(f, entry)
 return True
 
-def reset_state(
-self,
-filename,
-wc_tracked=False,
-p1_tracked=False,
-p2_info=False,
-has_meaningful_mtime=True,
-parentfiledata=None,
-):
-"""Set a entry to a given state, diregarding all previous state
-
-This is to be used by the part of the dirstate API dedicated to
-adjusting the dirstate after a update/merge.
-
-note: calling this might result to no entry existing at all if the
-dirstate map does not see any point at having one for this file
-anymore.
-"""
-# copy information are now outdated
-# (maybe new information should be in directly passed to this function)
-self.copymap.pop(filename, None)
-
-if not (p1_tracked or p2_info or wc_tracked):
-old_entry = self._map.get(filename)
-self._drop_entry(filename)
-self._dirs_decr(filename, old_entry=old_entry)
-return
-
-old_entry = self._map.get(filename)
-self._dirs_incr(filename, old_entry)
-entry = DirstateItem(
-wc_tracked=wc_tracked,
-p1_tracked=p1_tracked,
-p2_info=p2_info,
-has_meaningful_mtime=has_meaningful_mtime,
-parentfiledata=parentfiledata,
-)
-self._insert_entry(filename, entry)
-
 ### disk interaction
 
 def _opendirstatefile(self):
@@ -513,6 +474,45 @@
 
 ### code related to manipulation of entries and copy-sources
 
+def reset_state(
+self,
+filename,
+wc_tracked=False,
+p1_tracked=False,
+p2_info=False,
+has_meaningful_mtime=True,
+parentfiledata=None,
+):
+"""Set a entry to a given state, diregarding all previous state
+
+This is to be used by the part of the dirstate API dedicated to
+adjusting the dirstate after a update/merge.
+
+note: calling this might result to no entry existing at all if the
+dirstate map does not see any point at having one for this file
+anymore.
+"""
+# copy information are now outdated
+# (maybe new information should be in directly passed to this function)
+self.copymap.pop(filename, None)
+
+if not (p1_tracked or p2_info or wc_tracked):
+old_entry = self._map.get(filename)
+self._drop_entry(filename)
+self._dirs_decr(filename, old_entry=old_entry)
+return
+
+old_entry = self._map.get(filename)
+self._dirs_incr(filename, old_entry)
+entry = DirstateItem(
+wc_tracked=wc_tracked,
+p1_tracked=p1_tracked,
+p2_info=p2_info,
+has_meaningful_mtime=has_meaningful_mtime,
+parentfiledata=parentfiledata,
+)
+self._insert_entry(filename, entry)
+
 def set_tracked(self, filename):
 new = False
 entry = self.get(filename)
@@ -724,6 +724,24 @@
 def set_tracked(self, f):
 return self._map.set_tracked(f)
 
+def reset_state(
+self,
+filename,
+wc_tracked=False,
+p1_tracked=False,
+p2_info=False,
+has_meaningful_mtime=True,
+parentfiledata=None,
+):
+return self._map.reset_state(
+filename,
+wc_tracked,
+p1_tracked,
+p2_info,
+has_meaningful_mtime,
+parentfiledata,
+)
+
 def _drop_entry(self, f):
 self._map.drop_item_and_copy_source(f)
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12452: rust-dirstate: introduce intermediate struct for dirstate-v2 data

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is passed often as a long tuple that is not easy to know the form of, so
  we refactor everything in this struct.
  
  This also renames `wdir_tracked` to follow the Python `wc_tracked`, even 
though
  the on-disk format uses `WDIR_TRACKED`.
  I think a single naming scheme is better, but we can't easily break the Python
  impl now because of extensions, so this is low-effort enough and facilitates
  grepping.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12452

AFFECTED FILES
  rust/hg-core/src/dirstate/entry.rs
  rust/hg-core/src/dirstate_tree/on_disk.rs
  rust/hg-cpython/src/dirstate/item.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/item.rs 
b/rust/hg-cpython/src/dirstate/item.rs
--- a/rust/hg-cpython/src/dirstate/item.rs
+++ b/rust/hg-cpython/src/dirstate/item.rs
@@ -8,6 +8,7 @@
 use cpython::Python;
 use cpython::PythonObject;
 use hg::dirstate::DirstateEntry;
+use hg::dirstate::DirstateV2Data;
 use hg::dirstate::TruncatedTimestamp;
 use std::cell::Cell;
 
@@ -38,15 +39,15 @@
 }
 }
 }
-let entry = DirstateEntry::from_v2_data(
-wc_tracked,
+let entry = DirstateEntry::from_v2_data(DirstateV2Data {
+wc_tracked: wc_tracked,
 p1_tracked,
 p2_info,
-mode_size_opt,
-mtime_opt,
+mode_size: mode_size_opt,
+mtime: mtime_opt,
 fallback_exec,
 fallback_symlink,
-);
+});
 DirstateItem::create_instance(py, Cell::new(entry))
 }
 
diff --git a/rust/hg-core/src/dirstate_tree/on_disk.rs 
b/rust/hg-core/src/dirstate_tree/on_disk.rs
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs
+++ b/rust/hg-core/src/dirstate_tree/on_disk.rs
@@ -2,7 +2,7 @@
 //!
 //! See `mercurial/helptext/internals/dirstate-v2.txt`
 
-use crate::dirstate::TruncatedTimestamp;
+use crate::dirstate::{DirstateV2Data, TruncatedTimestamp};
 use crate::dirstate_tree::dirstate_map::{self, DirstateMap, NodeRef};
 use crate::dirstate_tree::path_with_basename::WithBasename;
 use crate::errors::HgError;
@@ -412,7 +412,7 @@
 
 fn assume_entry() -> Result {
 // TODO: convert through raw bits instead?
-let wdir_tracked = self.flags().contains(Flags::WDIR_TRACKED);
+let wc_tracked = self.flags().contains(Flags::WDIR_TRACKED);
 let p1_tracked = self.flags().contains(Flags::P1_TRACKED);
 let p2_info = self.flags().contains(Flags::P2_INFO);
 let mode_size = if self.flags().contains(Flags::HAS_MODE_AND_SIZE)
@@ -442,15 +442,15 @@
 } else {
 None
 };
-Ok(DirstateEntry::from_v2_data(
-wdir_tracked,
+Ok(DirstateEntry::from_v2_data(DirstateV2Data {
+wc_tracked,
 p1_tracked,
 p2_info,
 mode_size,
 mtime,
 fallback_exec,
 fallback_symlink,
-))
+}))
 }
 
 pub(super) fn entry(
@@ -490,18 +490,18 @@
 fn from_dirstate_entry(
 entry: ,
 ) -> (Flags, U32Be, PackedTruncatedTimestamp) {
-let (
-wdir_tracked,
+let DirstateV2Data {
+wc_tracked,
 p1_tracked,
 p2_info,
-mode_size_opt,
-mtime_opt,
+mode_size: mode_size_opt,
+mtime: mtime_opt,
 fallback_exec,
 fallback_symlink,
-) = entry.v2_data();
-// TODO: convert throug raw flag bits instead?
+} = entry.v2_data();
+// TODO: convert through raw flag bits instead?
 let mut flags = Flags::empty();
-flags.set(Flags::WDIR_TRACKED, wdir_tracked);
+flags.set(Flags::WDIR_TRACKED, wc_tracked);
 flags.set(Flags::P1_TRACKED, p1_tracked);
 flags.set(Flags::P2_INFO, p2_info);
 let size = if let Some((m, s)) = mode_size_opt {
diff --git a/rust/hg-core/src/dirstate/entry.rs 
b/rust/hg-core/src/dirstate/entry.rs
--- a/rust/hg-core/src/dirstate/entry.rs
+++ b/rust/hg-core/src/dirstate/entry.rs
@@ -248,23 +248,35 @@
 /// dirstate v1 format.
 pub const SIZE_NON_NORMAL: i32 = -1;
 
+#[derive(Debug, Default, Copy, Clone)]
+pub struct DirstateV2Data {
+pub wc_tracked: bool,
+pub p1_tracked: bool,
+pub p2_info: bool,
+pub mode_size: Option<(u32, u32)>,
+pub mtime: Option,
+pub fallback_exec: Option,
+pub fallback_symlink: Option,
+}
+
 impl DirstateEntry {
-pub fn from_v2_data(
-wdir_tracked: bool,
-p1_tracked: bool,
-p2_info: bool,
-mode_size: Option<(u32, u32)>,
-mtime: Option,
-fallback_exec: Option,
-fallback_symlink: Option,
-) -> Self {
+pub fn from_v2_data(v2_data: DirstateV2Data) -> Self {
+let 

D12451: dirstatemap: remove unused parameter from `reset_state`

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This has no callers using it and is not used inside the method itself.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12451

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -150,7 +150,6 @@
 p1_tracked=False,
 p2_info=False,
 has_meaningful_mtime=True,
-has_meaningful_data=True,
 parentfiledata=None,
 ):
 """Set a entry to a given state, diregarding all previous state



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12450: dirstatemap: move `set_tracked` out of common methods and plug in Rust

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We now have a Rust-specific implementation of this method, it is no longer
  shared between both implementations.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12450

AFFECTED FILES
  mercurial/dirstatemap.py
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs 
b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -131,6 +131,19 @@
 Ok(PyNone)
 }
 
+def set_tracked(, f: PyObject) -> PyResult {
+Ok(self.inner(py).borrow_mut()
+.set_tracked(
+HgPath::new(f.extract::(py)?.data(py)),
+)
+.or_else(|_| {
+Err(PyErr::new::(
+py,
+"Dirstate error".to_string(),
+))
+})?.to_py_object(py))
+}
+
 def removefile(
 ,
 f: PyObject,
diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -130,30 +130,6 @@
 self._refresh_entry(filename, entry)
 self.copymap.pop(filename, None)
 
-def set_tracked(self, filename):
-new = False
-entry = self.get(filename)
-if entry is None:
-self._dirs_incr(filename)
-entry = DirstateItem(
-wc_tracked=True,
-)
-
-self._insert_entry(filename, entry)
-new = True
-elif not entry.tracked:
-self._dirs_incr(filename, entry)
-entry.set_tracked()
-self._refresh_entry(filename, entry)
-new = True
-else:
-# XXX This is probably overkill for more case, but we need this to
-# fully replace the `normallookup` call with `set_tracked` one.
-# Consider smoothing this in the future.
-entry.set_possibly_dirty()
-self._refresh_entry(filename, entry)
-return new
-
 def set_untracked(self, f):
 """Mark a file as no longer tracked in the dirstate map"""
 entry = self.get(f)
@@ -538,6 +514,30 @@
 
 ### code related to manipulation of entries and copy-sources
 
+def set_tracked(self, filename):
+new = False
+entry = self.get(filename)
+if entry is None:
+self._dirs_incr(filename)
+entry = DirstateItem(
+wc_tracked=True,
+)
+
+self._insert_entry(filename, entry)
+new = True
+elif not entry.tracked:
+self._dirs_incr(filename, entry)
+entry.set_tracked()
+self._refresh_entry(filename, entry)
+new = True
+else:
+# XXX This is probably overkill for more case, but we need this to
+# fully replace the `normallookup` call with `set_tracked` one.
+# Consider smoothing this in the future.
+entry.set_possibly_dirty()
+self._refresh_entry(filename, entry)
+return new
+
 def _refresh_entry(self, f, entry):
 if not entry.any_tracked:
 self._map.pop(f, None)
@@ -722,6 +722,9 @@
 def _insert_entry(self, f, entry):
 self._map.addfile(f, entry)
 
+def set_tracked(self, f):
+return self._map.set_tracked(f)
+
 def _drop_entry(self, f):
 self._map.drop_item_and_copy_source(f)
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12449: rust-dirstatemap: add `set_tracked` method

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is the new dirstate API that has already been moved to in Python.
  It will be used in place of the old `addfile`/`removefile` one.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12449

AFFECTED FILES
  rust/hg-core/src/dirstate/entry.rs
  rust/hg-core/src/dirstate_tree/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -606,6 +606,53 @@
 }
 }
 
+fn set_tracked(
+ self,
+filename: ,
+old_entry_opt: Option,
+) -> Result {
+let old_state = old_entry_opt.map(|e| e.state());
+let had_entry = old_state.is_some();
+let was_tracked = old_state.map_or(false, |s| s.is_tracked());
+let tracked_count_increment = if was_tracked { 0 } else { 1 };
+let mut new = false;
+
+let node = Self::get_or_insert_node(
+self.on_disk,
+ self.unreachable_bytes,
+ self.root,
+filename,
+WithBasename::to_cow_owned,
+|ancestor| {
+if !had_entry {
+ancestor.descendants_with_entry_count += 1;
+}
+
+ancestor.tracked_descendants_count += tracked_count_increment;
+},
+)?;
+let new_entry = if let Some(old_entry) = old_entry_opt {
+let mut e = old_entry.clone();
+if e.tracked() {
+// XXX
+// This is probably overkill for more case, but we need this to
+// fully replace the `normallookup` call with `set_tracked`
+// one. Consider smoothing this in the future.
+e.set_possibly_dirty();
+} else {
+new = true;
+e.set_tracked();
+}
+e
+} else {
+self.nodes_with_entry_count += 1;
+new = true;
+DirstateEntry::new_tracked()
+};
+node.data = NodeData::Entry(new_entry);
+Ok(new)
+}
+
 fn add_or_remove_file(
  self,
 path: ,
@@ -758,6 +805,14 @@
 })
 }
 
+pub fn set_tracked(
+ self,
+filename: ,
+) -> Result {
+let old_entry_opt = self.get(filename)?;
+self.with_dmap_mut(|map| map.set_tracked(filename, old_entry_opt))
+}
+
 pub fn remove_file(
  self,
 filename: ,
diff --git a/rust/hg-core/src/dirstate/entry.rs 
b/rust/hg-core/src/dirstate/entry.rs
--- a/rust/hg-core/src/dirstate/entry.rs
+++ b/rust/hg-core/src/dirstate/entry.rs
@@ -367,6 +367,10 @@
 Self::from_v1_data(EntryState::Removed, 0, size, 0)
 }
 
+pub fn new_tracked() -> Self {
+Self::from_v2_data(true, false, false, None, None, None, None)
+}
+
 pub fn tracked() -> bool {
 self.flags.contains(Flags::WDIR_TRACKED)
 }



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12447: dirstate: remove v1_* methods from Python/C/Rust shared API

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  These methods are used for v1 parsing by their respective implementations, but
  do not need to be shared between them.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12447

AFFECTED FILES
  hgext/fsmonitor/__init__.py
  mercurial/cext/parsers.c
  mercurial/pure/parsers.py
  rust/hg-cpython/src/dirstate/item.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/item.rs 
b/rust/hg-cpython/src/dirstate/item.rs
--- a/rust/hg-cpython/src/dirstate/item.rs
+++ b/rust/hg-cpython/src/dirstate/item.rs
@@ -8,10 +8,8 @@
 use cpython::Python;
 use cpython::PythonObject;
 use hg::dirstate::DirstateEntry;
-use hg::dirstate::EntryState;
 use hg::dirstate::TruncatedTimestamp;
 use std::cell::Cell;
-use std::convert::TryFrom;
 
 py_class!(pub class DirstateItem |py| {
 data entry: Cell;
@@ -173,27 +171,6 @@
 Ok(self.entry(py).get().any_tracked())
 }
 
-def v1_state() -> PyResult {
-let (state, _mode, _size, _mtime) = self.entry(py).get().v1_data();
-let state_byte: u8 = state.into();
-Ok(PyBytes::new(py, &[state_byte]))
-}
-
-def v1_mode() -> PyResult {
-let (_state, mode, _size, _mtime) = self.entry(py).get().v1_data();
-Ok(mode)
-}
-
-def v1_size() -> PyResult {
-let (_state, _mode, size, _mtime) = self.entry(py).get().v1_data();
-Ok(size)
-}
-
-def v1_mtime() -> PyResult {
-let (_state, _mode, _size, mtime) = self.entry(py).get().v1_data();
-Ok(mtime)
-}
-
 def mtime_likely_equal_to(, other: (u32, u32, bool))
 -> PyResult {
 if let Some(mtime) = self.entry(py).get().truncated_mtime() {
@@ -203,22 +180,6 @@
 }
 }
 
-@classmethod
-def from_v1_data(
-_cls,
-state: PyBytes,
-mode: i32,
-size: i32,
-mtime: i32,
-) -> PyResult {
-let state = <[u8; 1]>::try_from(state.data(py))
-.ok()
-.and_then(|state| EntryState::try_from(state[0]).ok())
-.ok_or_else(|| PyErr::new::(py, "invalid 
state"))?;
-let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
-DirstateItem::create_instance(py, Cell::new(entry))
-}
-
 def drop_merge_data() -> PyResult {
 self.update(py, |entry| entry.drop_merge_data());
 Ok(PyNone)
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -291,15 +291,15 @@
 
 @property
 def mode(self):
-return self.v1_mode()
+return self._v1_mode()
 
 @property
 def size(self):
-return self.v1_size()
+return self._v1_size()
 
 @property
 def mtime(self):
-return self.v1_mtime()
+return self._v1_mtime()
 
 def mtime_likely_equal_to(self, other_mtime):
 self_sec = self._mtime_s
@@ -338,7 +338,7 @@
 """
 if not self.any_tracked:
 return b'?'
-return self.v1_state()
+return self._v1_state()
 
 @property
 def has_fallback_exec(self):
@@ -498,7 +498,7 @@
 # since we never set _DIRSTATE_V2_HAS_DIRCTORY_MTIME
 return (flags, self._size or 0, self._mtime_s or 0, self._mtime_ns or 
0)
 
-def v1_state(self):
+def _v1_state(self):
 """return a "state" suitable for v1 serialization"""
 if not self.any_tracked:
 # the object has no state to record, this is -currently-
@@ -513,11 +513,11 @@
 else:
 return b'n'
 
-def v1_mode(self):
+def _v1_mode(self):
 """return a "mode" suitable for v1 serialization"""
 return self._mode if self._mode is not None else 0
 
-def v1_size(self):
+def _v1_size(self):
 """return a "size" suitable for v1 serialization"""
 if not self.any_tracked:
 # the object has no state to record, this is -currently-
@@ -536,7 +536,7 @@
 else:
 return self._size
 
-def v1_mtime(self):
+def _v1_mtime(self):
 """return a "mtime" suitable for v1 serialization"""
 if not self.any_tracked:
 # the object has no state to record, this is -currently-
@@ -963,10 +963,10 @@
 f = b"%s\0%s" % (f, copymap[f])
 e = _pack(
 b">c",
-e.v1_state(),
-e.v1_mode(),
-e.v1_size(),
-e.v1_mtime(),
+e._v1_state(),
+e._v1_mode(),
+e._v1_size(),
+e._v1_mtime(),
 len(f),
 )
 write(e)
diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -289,27 +289,6 @@
 self->mtime_ns);
 };
 
-static PyObject 

D12448: rust-dirstate: don't return a state for untracked entries

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This `state` API is a remnant of the former API and is slated for removal at
  some point. Any caller of this function will expect an entry that is tracked
  in the larger sense.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12448

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs 
b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -343,7 +343,13 @@
 pub(super) fn state(
 ,
 ) -> Result, DirstateV2ParseError> {
-Ok(self.entry()?.map(|e| e.state()))
+Ok(self.entry()?.and_then(|e| {
+if e.any_tracked() {
+Some(e.state())
+} else {
+None
+}
+}))
 }
 
 pub(super) fn cached_directory_mtime(



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12446: rust-dirstate-entry: fix typo in panic message

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12446

AFFECTED FILES
  rust/hg-core/src/dirstate/entry.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/dirstate/entry.rs 
b/rust/hg-core/src/dirstate/entry.rs
--- a/rust/hg-core/src/dirstate/entry.rs
+++ b/rust/hg-core/src/dirstate/entry.rs
@@ -423,7 +423,7 @@
 ) {
 if !self.any_tracked() {
 // TODO: return an Option instead?
-panic!("Accessing v1_state of an untracked DirstateEntry")
+panic!("Accessing v2_data of an untracked DirstateEntry")
 }
 let wdir_tracked = self.flags.contains(Flags::WDIR_TRACKED);
 let p1_tracked = self.flags.contains(Flags::P1_TRACKED);



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12445: test-issue660: add dirstate-v2 variant

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It's basically a dirstate test, so it makes sense to test out the new version.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12445

AFFECTED FILES
  tests/test-issue660.t

CHANGE DETAILS

diff --git a/tests/test-issue660.t b/tests/test-issue660.t
--- a/tests/test-issue660.t
+++ b/tests/test-issue660.t
@@ -1,3 +1,14 @@
+#testcases dirstate-v1 dirstate-v2
+
+#if dirstate-v2
+  $ cat >> $HGRCPATH << EOF
+  > [format]
+  > use-dirstate-v2=1
+  > [storage]
+  > dirstate-v2.slow-path=allow
+  > EOF
+#endif
+
 https://bz.mercurial-scm.org/660 and:
 https://bz.mercurial-scm.org/322
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12444: test-issue660: test inside a repository, not the test dir

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This causes an issue with a temporary file showing up in test output
  when adding a dirstate-v2 variant of this test.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12444

AFFECTED FILES
  tests/test-issue660.t

CHANGE DETAILS

diff --git a/tests/test-issue660.t b/tests/test-issue660.t
--- a/tests/test-issue660.t
+++ b/tests/test-issue660.t
@@ -1,7 +1,8 @@
 https://bz.mercurial-scm.org/660 and:
 https://bz.mercurial-scm.org/322
 
-  $ hg init
+  $ hg init repo
+  $ cd repo
   $ echo a > a
   $ mkdir b
   $ echo b > b/b



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12443: dirstate: fix some typos in docstrings

2022-04-06 Thread Raphaël Gomès
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I was passing by and they've been bothering me. :)

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12443

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -85,16 +85,16 @@
 # with minor difference between implementation.
 
 def _dirs_incr(self, filename, old_entry=None):
-"""incremente the dirstate counter if applicable
+"""increment the dirstate counter if applicable
 
-This might be a no-op for some subclass who deal with directory
+This might be a no-op for some subclasses who deal with directory
 tracking in a different way.
 """
 
 def _dirs_decr(self, filename, old_entry=None, remove_variant=False):
-"""decremente the dirstate counter if applicable
+"""decrement the dirstate counter if applicable
 
-This might be a no-op for some subclass who deal with directory
+This might be a no-op for some subclasses who deal with directory
 tracking in a different way.
 """
 



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


mercurial-devel | Failed pipeline for branch/default | e50245ee

2022-04-06 Thread Heptapod


Pipeline #47044 has failed!

Project: mercurial-devel ( https://foss.heptapod.net/mercurial/mercurial-devel )
Branch: branch/default ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/commits/branch/default )

Commit: e50245ee ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/commit/e50245ee26d58d8e000d969731d86283f0d3c265
 )
Commit Message: crecord: avoid duplicating lines when reverting...
Commit Author: Kyle Lippincott ( https://foss.heptapod.net/spectral )

Pipeline #47044 ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/pipelines/47044 ) 
triggered by Administrator ( https://foss.heptapod.net/root )
had 1 failed job.

Job #465426 ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/jobs/465426/raw )

Stage: tests
Name: test-c

-- 
You're receiving this email because of your account on foss.heptapod.net.



___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


mercurial-devel | Failed pipeline for branch/default | 1457b779

2022-04-06 Thread Heptapod


Pipeline #47032 has failed!

Project: mercurial-devel ( https://foss.heptapod.net/mercurial/mercurial-devel )
Branch: branch/default ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/commits/branch/default )

Commit: 1457b779 ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/commit/1457b779bdb9bbdf2a82d3e87e7e2077c25e0a2b
 )
Commit Message: stringutil: try to avoid running `splitlines()`...
Commit Author: Martin von Zweigbergk ( https://foss.heptapod.net/martinvonz )

Pipeline #47032 ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/pipelines/47032 ) 
triggered by Administrator ( https://foss.heptapod.net/root )
had 1 failed job.

Job #465247 ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/jobs/465247/raw )

Stage: tests
Name: test-c

-- 
You're receiving this email because of your account on foss.heptapod.net.



___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


mercurial@49009: 4 new changesets (3 on stable)

2022-04-06 Thread Mercurial Commits
4 new changesets (3 on stable) in mercurial:

https://www.mercurial-scm.org/repo/hg/rev/5bd6bcd31dd1
changeset:   49006:5bd6bcd31dd1
branch:  stable
tag: 6.1.1
parent:  49004:9dcfd1d05e6e
user:Raphaël Gomès 
date:Tue Apr 05 17:11:36 2022 +0200
summary: relnotes: add notes for 6.1.1

https://www.mercurial-scm.org/repo/hg/rev/d3709fa59190
changeset:   49007:d3709fa59190
branch:  stable
user:Raphaël Gomès 
date:Tue Apr 05 17:19:22 2022 +0200
summary: Added tag 6.1.1 for changeset 5bd6bcd31dd1

https://www.mercurial-scm.org/repo/hg/rev/dd98bd0b6501
changeset:   49008:dd98bd0b6501
branch:  stable
user:Raphaël Gomès 
date:Tue Apr 05 17:19:29 2022 +0200
summary: Added signature for changeset 5bd6bcd31dd1

https://www.mercurial-scm.org/repo/hg/rev/82dbe3a2920d
changeset:   49009:82dbe3a2920d
bookmark:@
tag: tip
parent:  49005:12adf8c695ed
parent:  49008:dd98bd0b6501
user:Raphaël Gomès 
date:Tue Apr 05 17:31:18 2022 +0200
summary: branching: merge stable into default

-- 
Repository URL: https://www.mercurial-scm.org/repo/hg
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


mercurial-devel | Failed pipeline for branch/default | 69250921

2022-04-06 Thread Heptapod


Pipeline #47030 has failed!

Project: mercurial-devel ( https://foss.heptapod.net/mercurial/mercurial-devel )
Branch: branch/default ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/commits/branch/default )

Commit: 69250921 ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/commit/692509215156ee6b648934581f004d49afa723cf
 )
Commit Message: perf-util: add a `compare-discovery-case` scrip...
Commit Author: Pierre-Yves David ( https://foss.heptapod.net/marmoute )

Pipeline #47030 ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/pipelines/47030 ) 
triggered by Administrator ( https://foss.heptapod.net/root )
had 2 failed jobs.

Job #465219 ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/jobs/465219/raw )

Stage: tests
Name: test-c
Job #465217 ( 
https://foss.heptapod.net/mercurial/mercurial-devel/-/jobs/465217/raw )

Stage: tests
Name: checks

-- 
You're receiving this email because of your account on foss.heptapod.net.



___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel