[Request] [+- ] D11463: debugsate: Change debug_iter() to yield tuples instead of DirstateItem
SimonSapin
phabricator at mercurial-scm.org
Mon Sep 20 22:19:52 UTC 2021
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
This removes the need for `DirstateItem`Â to support the `state == ' '`
special case which represents dirstate tree nodes without an item.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D11463
AFFECTED FILES
mercurial/debugcommands.py
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
@@ -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)
}
diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -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):
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -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))
To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210920/815f376a/attachment-0001.html>
More information about the Mercurial-patches
mailing list