… passing it a new all argument for the --all CLI option,
instead of conditionally calling .debug_iter() or .items()
This prepares for the next commit.
Alphare |
hg-reviewers |
… passing it a new all argument for the --all CLI option,
instead of conditionally calling .debug_iter() or .items()
This prepares for the next commit.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/debugcommands.py (5 lines) | |||
M | mercurial/dirstatemap.py (10 lines) | |||
M | rust/hg-core/src/dirstate_tree/dirstate_map.rs (8 lines) | |||
M | rust/hg-core/src/dirstate_tree/dispatch.rs (8 lines) | |||
M | rust/hg-core/src/dirstate_tree/owning_dispatch.rs (3 lines) | |||
M | rust/hg-cpython/src/dirstate/dirstate_map.rs (4 lines) |
Status | Author | Revision | |
---|---|---|---|
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin |
if datesort: | if datesort: | ||||
keyfunc = lambda x: ( | keyfunc = lambda x: ( | ||||
x[1].v1_mtime(), | x[1].v1_mtime(), | ||||
x[0], | x[0], | ||||
) # sort by mtime, then by filename | ) # sort by mtime, then by filename | ||||
else: | else: | ||||
keyfunc = None # sort by filename | keyfunc = None # sort by filename | ||||
if opts['all']: | entries = list(repo.dirstate._map.debug_iter(all=opts['all'])) | ||||
entries = list(repo.dirstate._map.debug_iter()) | |||||
else: | |||||
entries = list(pycompat.iteritems(repo.dirstate)) | |||||
entries.sort(key=keyfunc) | entries.sort(key=keyfunc) | ||||
for file_, ent in entries: | for file_, ent in entries: | ||||
if ent.v1_mtime() == -1: | if ent.v1_mtime() == -1: | ||||
timestr = b'unset ' | timestr = b'unset ' | ||||
elif nodates: | elif nodates: | ||||
timestr = b'set ' | timestr = b'set ' | ||||
else: | else: | ||||
timestr = time.strftime( | timestr = time.strftime( |
util.clearcachedproperty(self, b"otherparentset") | util.clearcachedproperty(self, b"otherparentset") | ||||
def items(self): | def items(self): | ||||
return pycompat.iteritems(self._map) | return pycompat.iteritems(self._map) | ||||
# forward for python2,3 compat | # forward for python2,3 compat | ||||
iteritems = items | iteritems = items | ||||
debug_iter = items | def debug_iter(self, all): | ||||
""" | |||||
`all` is unused when Rust is not enabled | |||||
""" | |||||
return self.item() | |||||
def __len__(self): | def __len__(self): | ||||
return len(self._map) | return len(self._map) | ||||
def __iter__(self): | def __iter__(self): | ||||
return iter(self._map) | return iter(self._map) | ||||
def get(self, key, default=None): | def get(self, key, default=None): | ||||
def get(self, *args, **kwargs): | def get(self, *args, **kwargs): | ||||
return self._rustmap.get(*args, **kwargs) | return self._rustmap.get(*args, **kwargs) | ||||
@property | @property | ||||
def copymap(self): | def copymap(self): | ||||
return self._rustmap.copymap() | return self._rustmap.copymap() | ||||
def debug_iter(self): | def debug_iter(self, all): | ||||
return self._rustmap.debug_iter() | return self._rustmap.debug_iter(all) | ||||
def preload(self): | def preload(self): | ||||
self._rustmap | self._rustmap | ||||
def clear(self): | def clear(self): | ||||
self._rustmap.clear() | self._rustmap.clear() | ||||
self.setparents( | self.setparents( | ||||
self._nodeconstants.nullid, self._nodeconstants.nullid | self._nodeconstants.nullid, self._nodeconstants.nullid |
None | None | ||||
}) | }) | ||||
}, | }, | ||||
))) | ))) | ||||
} | } | ||||
fn debug_iter( | fn debug_iter( | ||||
&self, | &self, | ||||
all: bool, | |||||
) -> Box< | ) -> Box< | ||||
dyn Iterator< | dyn Iterator< | ||||
Item = Result< | Item = Result< | ||||
(&HgPath, (u8, i32, i32, i32)), | (&HgPath, (u8, i32, i32, i32)), | ||||
DirstateV2ParseError, | DirstateV2ParseError, | ||||
>, | >, | ||||
> + Send | > + Send | ||||
+ '_, | + '_, | ||||
> { | > { | ||||
Box::new(self.iter_nodes().map(move |node| { | Box::new(filter_map_results(self.iter_nodes(), move |node| { | ||||
let node = node?; | |||||
let debug_tuple = if let Some(entry) = node.entry()? { | let debug_tuple = if let Some(entry) = node.entry()? { | ||||
entry.debug_tuple() | entry.debug_tuple() | ||||
} else if !all { | |||||
return Ok(None); | |||||
} else if let Some(mtime) = node.cached_directory_mtime() { | } else if let Some(mtime) = node.cached_directory_mtime() { | ||||
(b' ', 0, -1, mtime.seconds() as i32) | (b' ', 0, -1, mtime.seconds() as i32) | ||||
} else { | } else { | ||||
(b' ', 0, -1, -1) | (b' ', 0, -1, -1) | ||||
}; | }; | ||||
Ok((node.full_path(self.on_disk)?, debug_tuple)) | Ok(Some((node.full_path(self.on_disk)?, debug_tuple))) | ||||
})) | })) | ||||
} | } | ||||
} | } |
>, | >, | ||||
DirstateError, | DirstateError, | ||||
>; | >; | ||||
/// Return an iterator of `(path, (state, mode, size, mtime))` for every | /// Return an iterator of `(path, (state, mode, size, mtime))` for every | ||||
/// node stored in this dirstate map, for the purpose of the `hg | /// node stored in this dirstate map, for the purpose of the `hg | ||||
/// debugdirstate` command. | /// debugdirstate` command. | ||||
/// | /// | ||||
/// For nodes that don’t have an entry, `state` is the ASCII space. | /// If `all` is true, include nodes that don’t have an entry. | ||||
/// For such nodes `state` is the ASCII space. | |||||
/// An `mtime` may still be present. It is used to optimize `status`. | /// An `mtime` may still be present. It is used to optimize `status`. | ||||
/// | /// | ||||
/// Because parse errors can happen during iteration, the iterated items | /// Because parse errors can happen during iteration, the iterated items | ||||
/// are `Result`s. | /// are `Result`s. | ||||
fn debug_iter( | fn debug_iter( | ||||
&self, | &self, | ||||
all: bool, | |||||
) -> Box< | ) -> Box< | ||||
dyn Iterator< | dyn Iterator< | ||||
Item = Result< | Item = Result< | ||||
(&HgPath, (u8, i32, i32, i32)), | (&HgPath, (u8, i32, i32, i32)), | ||||
DirstateV2ParseError, | DirstateV2ParseError, | ||||
>, | >, | ||||
> + Send | > + Send | ||||
+ '_, | + '_, | ||||
.unwrap() | .unwrap() | ||||
.iter() | .iter() | ||||
.map(|path| Ok(&**path)), | .map(|path| Ok(&**path)), | ||||
)) | )) | ||||
} | } | ||||
fn debug_iter( | fn debug_iter( | ||||
&self, | &self, | ||||
all: bool, | |||||
) -> Box< | ) -> Box< | ||||
dyn Iterator< | dyn Iterator< | ||||
Item = Result< | Item = Result< | ||||
(&HgPath, (u8, i32, i32, i32)), | (&HgPath, (u8, i32, i32, i32)), | ||||
DirstateV2ParseError, | DirstateV2ParseError, | ||||
>, | >, | ||||
> + Send | > + Send | ||||
+ '_, | + '_, | ||||
> { | > { | ||||
// Not used for the flat (not tree-based) DirstateMap | |||||
let _ = all; | |||||
Box::new( | Box::new( | ||||
(&**self) | (&**self) | ||||
.iter() | .iter() | ||||
.map(|(path, entry)| Ok((&**path, entry.debug_tuple()))), | .map(|(path, entry)| Ok((&**path, entry.debug_tuple()))), | ||||
) | ) | ||||
} | } | ||||
} | } |
>, | >, | ||||
DirstateError, | DirstateError, | ||||
> { | > { | ||||
self.get_mut().iter_tracked_dirs() | self.get_mut().iter_tracked_dirs() | ||||
} | } | ||||
fn debug_iter( | fn debug_iter( | ||||
&self, | &self, | ||||
all: bool, | |||||
) -> Box< | ) -> Box< | ||||
dyn Iterator< | dyn Iterator< | ||||
Item = Result< | Item = Result< | ||||
(&HgPath, (u8, i32, i32, i32)), | (&HgPath, (u8, i32, i32, i32)), | ||||
DirstateV2ParseError, | DirstateV2ParseError, | ||||
>, | >, | ||||
> + Send | > + Send | ||||
+ '_, | + '_, | ||||
> { | > { | ||||
self.get().debug_iter() | self.get().debug_iter(all) | ||||
} | } | ||||
} | } |
{ | { | ||||
let path = path.map_err(|e| v2_error(py, e))?; | let path = path.map_err(|e| v2_error(py, e))?; | ||||
let path = PyBytes::new(py, path.as_bytes()); | let path = PyBytes::new(py, path.as_bytes()); | ||||
dirs.append(py, path.into_object()) | dirs.append(py, path.into_object()) | ||||
} | } | ||||
Ok(dirs) | Ok(dirs) | ||||
} | } | ||||
def debug_iter(&self) -> PyResult<PyList> { | def debug_iter(&self, all: bool) -> PyResult<PyList> { | ||||
let dirs = PyList::new(py, &[]); | let dirs = PyList::new(py, &[]); | ||||
for item in self.inner(py).borrow().debug_iter() { | for item in self.inner(py).borrow().debug_iter(all) { | ||||
let (path, (state, mode, size, mtime)) = | let (path, (state, mode, size, mtime)) = | ||||
item.map_err(|e| v2_error(py, e))?; | item.map_err(|e| v2_error(py, e))?; | ||||
let path = PyBytes::new(py, path.as_bytes()); | let path = PyBytes::new(py, path.as_bytes()); | ||||
let item = make_dirstate_item_raw(py, state, mode, size, mtime)?; | let item = make_dirstate_item_raw(py, state, mode, size, mtime)?; | ||||
dirs.append(py, (path, item).to_py_object(py).into_object()) | dirs.append(py, (path, item).to_py_object(py).into_object()) | ||||
} | } | ||||
Ok(dirs) | Ok(dirs) | ||||
} | } |