Mercurial > public > mercurial-scm > hg
comparison rust/hg-cpython/src/revlog.rs @ 48269:aa88fb60ecb4 stable
rust-nodemap: backed out mitigation for issue 6554
This is a backout of changeset 3fffb48539ee.
Issue 6554 is now considered solved, hence its mitigation
has to be removed, if only for its performance cost.
Differential Revision: https://phab.mercurial-scm.org/D11703
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Tue, 19 Oct 2021 19:05:41 +0200 |
parents | 3fffb48539ee |
children | 455fce57e89e |
comparison
equal
deleted
inserted
replaced
48245:531d26b1390a | 48269:aa88fb60ecb4 |
---|---|
57 | 57 |
58 // Index API involving nodemap, as defined in mercurial/pure/parsers.py | 58 // Index API involving nodemap, as defined in mercurial/pure/parsers.py |
59 | 59 |
60 /// Return Revision if found, raises a bare `error.RevlogError` | 60 /// Return Revision if found, raises a bare `error.RevlogError` |
61 /// in case of ambiguity, same as C version does | 61 /// in case of ambiguity, same as C version does |
62 def get_rev(&self, pynode: PyBytes) -> PyResult<Option<Revision>> { | 62 def get_rev(&self, node: PyBytes) -> PyResult<Option<Revision>> { |
63 let opt = self.get_nodetree(py)?.borrow(); | 63 let opt = self.get_nodetree(py)?.borrow(); |
64 let nt = opt.as_ref().unwrap(); | 64 let nt = opt.as_ref().unwrap(); |
65 let idx = &*self.cindex(py).borrow(); | 65 let idx = &*self.cindex(py).borrow(); |
66 let node = node_from_py_bytes(py, &pynode)?; | 66 let node = node_from_py_bytes(py, &node)?; |
67 match nt.find_bin(idx, node.into()) | 67 nt.find_bin(idx, node.into()).map_err(|e| nodemap_error(py, e)) |
68 { | |
69 Ok(None) => | |
70 // fallback to C implementation, remove once | |
71 // https://bz.mercurial-scm.org/show_bug.cgi?id=6554 | |
72 // is fixed (a simple backout should do) | |
73 self.call_cindex(py, "get_rev", &PyTuple::new(py, &[pynode.into_object()]), None)? | |
74 .extract(py), | |
75 Ok(Some(rev)) => Ok(Some(rev)), | |
76 Err(e) => Err(nodemap_error(py, e)), | |
77 } | |
78 } | 68 } |
79 | 69 |
80 /// same as `get_rev()` but raises a bare `error.RevlogError` if node | 70 /// same as `get_rev()` but raises a bare `error.RevlogError` if node |
81 /// is not found. | 71 /// is not found. |
82 /// | 72 /// |
102 Ok(None) => Err(revlog_error(py)), | 92 Ok(None) => Err(revlog_error(py)), |
103 Err(e) => Err(nodemap_error(py, e)), | 93 Err(e) => Err(nodemap_error(py, e)), |
104 } | 94 } |
105 } | 95 } |
106 | 96 |
107 def partialmatch(&self, pynode: PyObject) -> PyResult<Option<PyBytes>> { | 97 def partialmatch(&self, node: PyObject) -> PyResult<Option<PyBytes>> { |
108 let opt = self.get_nodetree(py)?.borrow(); | 98 let opt = self.get_nodetree(py)?.borrow(); |
109 let nt = opt.as_ref().unwrap(); | 99 let nt = opt.as_ref().unwrap(); |
110 let idx = &*self.cindex(py).borrow(); | 100 let idx = &*self.cindex(py).borrow(); |
111 | 101 |
112 let node_as_string = if cfg!(feature = "python3-sys") { | 102 let node_as_string = if cfg!(feature = "python3-sys") { |
113 pynode.cast_as::<PyString>(py)?.to_string(py)?.to_string() | 103 node.cast_as::<PyString>(py)?.to_string(py)?.to_string() |
114 } | 104 } |
115 else { | 105 else { |
116 let node = pynode.extract::<PyBytes>(py)?; | 106 let node = node.extract::<PyBytes>(py)?; |
117 String::from_utf8_lossy(node.data(py)).to_string() | 107 String::from_utf8_lossy(node.data(py)).to_string() |
118 }; | 108 }; |
119 | 109 |
120 let prefix = NodePrefix::from_hex(&node_as_string).map_err(|_| PyErr::new::<ValueError, _>(py, "Invalid node or prefix"))?; | 110 let prefix = NodePrefix::from_hex(&node_as_string).map_err(|_| PyErr::new::<ValueError, _>(py, "Invalid node or prefix"))?; |
121 | 111 |
122 match nt.find_bin(idx, prefix) { | 112 nt.find_bin(idx, prefix) |
123 Ok(None) => | 113 // TODO make an inner API returning the node directly |
124 // fallback to C implementation, remove once | 114 .map(|opt| opt.map( |
125 // https://bz.mercurial-scm.org/show_bug.cgi?id=6554 | 115 |rev| PyBytes::new(py, idx.node(rev).unwrap().as_bytes()))) |
126 // is fixed (a simple backout should do) | 116 .map_err(|e| nodemap_error(py, e)) |
127 self.call_cindex( | 117 |
128 py, "partialmatch", | |
129 &PyTuple::new(py, &[pynode]), None | |
130 )?.extract(py), | |
131 Ok(Some(rev)) => | |
132 Ok(Some(PyBytes::new(py, idx.node(rev).unwrap().as_bytes()))), | |
133 Err(e) => Err(nodemap_error(py, e)), | |
134 } | |
135 } | 118 } |
136 | 119 |
137 /// append an index entry | 120 /// append an index entry |
138 def append(&self, tup: PyTuple) -> PyResult<PyObject> { | 121 def append(&self, tup: PyTuple) -> PyResult<PyObject> { |
139 if tup.len(py) < 8 { | 122 if tup.len(py) < 8 { |