py3: fix treedirstate unicode handling

Summary:
There was a spot where we returned bytes for a filepath. Fix this to
make dirstate tests pass more.

Reviewed By: quark-zju

Differential Revision: D19786274

fbshipit-source-id: 7465cae8bb2e3be7758abc6279ed3f5f59581732
This commit is contained in:
Durham Goode 2020-02-17 14:47:28 -08:00 committed by Facebook Github Bot
parent 4f8c30b04e
commit fdbaaeeff9
3 changed files with 11 additions and 4 deletions

View File

@ -256,7 +256,7 @@ py_class!(class treedirstatemap |py| {
// Get the next dirstate object after the provided filename. If the filename is None, // Get the next dirstate object after the provided filename. If the filename is None,
// returns the first file in the tree. If the provided filename is the last file, returns // returns the first file in the tree. If the provided filename is the last file, returns
// None. // None.
def getnext(&self, filename: Option<PyPathBuf>, removed: bool) -> PyResult<Option<(PyBytes, (PyString, u32, i32, i32))>> { def getnext(&self, filename: Option<PyPathBuf>, removed: bool) -> PyResult<Option<(PyPathBuf, (PyString, u32, i32, i32))>> {
let mut dirstate = self.dirstate(py).borrow_mut(); let mut dirstate = self.dirstate(py).borrow_mut();
let next = if removed { let next = if removed {
match filename { match filename {
@ -284,7 +284,16 @@ py_class!(class treedirstatemap |py| {
} }
} }
}; };
Ok(next.map(|(f, s)| (PyBytes::new(py, &f), (PyString::new(py, unsafe {std::str::from_utf8_unchecked(&[s.state; 1])}), s.mode, s.size, s.mtime))))
Ok(match next {
Some((f, s)) => {
Some((
PyPathBuf::from_utf8_bytes(f.to_vec()).map_pyerr(py)?,
(PyString::new(py, unsafe {std::str::from_utf8_unchecked(&[s.state; 1])}), s.mode, s.size, s.mtime)
))
},
None => None,
})
} }
def addfile( def addfile(

View File

@ -1,4 +1,3 @@
#require py2
#chg-compatible #chg-compatible
$ disable treemanifest $ disable treemanifest

View File

@ -1,4 +1,3 @@
#require py2
#chg-compatible #chg-compatible
This test tries to exercise the ssh functionality with a dummy script This test tries to exercise the ssh functionality with a dummy script