# HG changeset patch # User Simon Sapin # Date 2021-09-20 18:20:55 # Node ID cedfe2606adf89b207b7f15dc41efb2f4ab79c39 # Parent 357307feaf61011528892c18a20cfd23eb465e99 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 diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -962,32 +962,29 @@ def debugstate(ui, repo, **opts): 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)) diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py --- a/mercurial/dirstatemap.py +++ b/mercurial/dirstatemap.py @@ -120,9 +120,12 @@ class dirstatemap(object): 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 @@ if rustmod is not None: 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/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 cpython::{ 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 @@ py_class!(pub class DirstateMap |py| { 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) }