debugsate: Change debug_iter() to yield tuples instead of DirstateItem
This removes the need for `DirstateItem` to support the `state == ' '`
special case which represents dirstate tree nodes without an item.
Differential Revision: https://phab.mercurial-scm.org/D11463
--- a/mercurial/debugcommands.py Mon Sep 20 19:59:09 2021 +0200
+++ b/mercurial/debugcommands.py Mon Sep 20 20:20:55 2021 +0200
@@ -962,32 +962,29 @@
datesort = opts.get('datesort')
if datesort:
- keyfunc = lambda x: (
- x[1].v1_mtime(),
- x[0],
- ) # sort by mtime, then by filename
+
+ def keyfunc(entry):
+ filename, _state, _mode, _size, mtime = entry
+ return (mtime, filename)
+
else:
keyfunc = None # sort by filename
entries = list(repo.dirstate._map.debug_iter(all=opts['all']))
entries.sort(key=keyfunc)
- for file_, ent in entries:
- if ent.v1_mtime() == -1:
+ for entry in entries:
+ filename, state, mode, size, mtime = entry
+ if mtime == -1:
timestr = b'unset '
elif nodates:
timestr = b'set '
else:
- timestr = time.strftime(
- "%Y-%m-%d %H:%M:%S ", time.localtime(ent.v1_mtime())
- )
+ timestr = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(mtime))
timestr = encoding.strtolocal(timestr)
- if ent.mode & 0o20000:
+ if mode & 0o20000:
mode = b'lnk'
else:
- mode = b'%3o' % (ent.v1_mode() & 0o777 & ~util.umask)
- ui.write(
- b"%c %s %10d %s%s\n"
- % (ent.v1_state(), mode, ent.v1_size(), timestr, file_)
- )
+ mode = b'%3o' % (mode & 0o777 & ~util.umask)
+ ui.write(b"%c %s %10d %s%s\n" % (state, mode, size, timestr, filename))
for f in repo.dirstate.copies():
ui.write(_(b"copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
--- a/mercurial/dirstatemap.py Mon Sep 20 19:59:09 2021 +0200
+++ b/mercurial/dirstatemap.py Mon Sep 20 20:20:55 2021 +0200
@@ -120,9 +120,12 @@
def debug_iter(self, all):
"""
+ Return an iterator of (filename, state, mode, size, mtime) tuples
+
`all` is unused when Rust is not enabled
"""
- return self.item()
+ for (filename, item) in self.items():
+ yield (filename, item.state, item.mode, item.size, item.mtime)
def __len__(self):
return len(self._map)
@@ -705,6 +708,13 @@
return self._rustmap.copymap()
def debug_iter(self, all):
+ """
+ Return an iterator of (filename, state, mode, size, mtime) tuples
+
+ `all`: also include with `state == b' '` dirstate tree nodes that
+ don't have an associated `DirstateItem`.
+
+ """
return self._rustmap.debug_iter(all)
def preload(self):
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Mon Sep 20 19:59:09 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Mon Sep 20 20:20:55 2021 +0200
@@ -20,7 +20,6 @@
use crate::{
dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
dirstate::make_dirstate_item,
- dirstate::make_dirstate_item_raw,
dirstate::non_normal_entries::{
NonNormalEntries, NonNormalEntriesIterator,
},
@@ -612,8 +611,8 @@
let (path, (state, mode, size, mtime)) =
item.map_err(|e| v2_error(py, e))?;
let path = PyBytes::new(py, path.as_bytes());
- let item = make_dirstate_item_raw(py, state, mode, size, mtime)?;
- dirs.append(py, (path, item).to_py_object(py).into_object())
+ let item = (path, state, mode, size, mtime);
+ dirs.append(py, item.to_py_object(py).into_object())
}
Ok(dirs)
}