Re: [PATCH] rust-fmt: run cargo fmt

2019-08-29 Thread Yuya Nishihara
On Thu, 29 Aug 2019 16:38:46 +0200, Raphaël Gomès wrote:
> # HG changeset patch
> # User Raphaël Gomès 
> # Date 1567086556 -7200
> #  Thu Aug 29 15:49:16 2019 +0200
> # Node ID 6ccae60f6d85c186b530095102acbc7b3d5ed7ba
> # Parent  383fdfa6bba9366abe3aceeddfa65dd4a0b3870d
> # EXP-Topic rust-fmt
> rust-fmt: run cargo fmt

Queued, thanks.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6774: rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf

2019-08-29 Thread Raphaël Gomès
Alphare created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6774

AFFECTED FILES
  rust/hg-core/src/dirstate.rs
  rust/hg-core/src/dirstate/dirs_multiset.rs
  rust/hg-core/src/dirstate/dirstate_map.rs
  rust/hg-core/src/dirstate/parsers.rs
  rust/hg-core/src/filepatterns.rs
  rust/hg-core/src/lib.rs
  rust/hg-core/src/utils/files.rs
  rust/hg-cpython/src/dirstate.rs
  rust/hg-cpython/src/dirstate/copymap.rs
  rust/hg-cpython/src/dirstate/dirs_multiset.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs
  rust/hg-cpython/src/filepatterns.rs
  rust/hg-cpython/src/parsers.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/parsers.rs b/rust/hg-cpython/src/parsers.rs
--- a/rust/hg-cpython/src/parsers.rs
+++ b/rust/hg-cpython/src/parsers.rs
@@ -15,8 +15,8 @@
 PythonObject, ToPyObject,
 };
 use hg::{
-pack_dirstate, parse_dirstate, DirstateEntry, DirstatePackError,
-DirstateParents, DirstateParseError, PARENT_SIZE,
+pack_dirstate, parse_dirstate, utils::hg_path::HgPathBuf, DirstateEntry,
+DirstatePackError, DirstateParents, DirstateParseError, PARENT_SIZE,
 };
 use std::collections::HashMap;
 use std::convert::TryInto;
@@ -46,7 +46,7 @@
 
 dmap.set_item(
 py,
-PyBytes::new(py, ),
+PyBytes::new(py, filename.as_ref()),
 decapsule_make_dirstate_tuple(py)?(
 state as c_char,
 entry.mode,
@@ -58,8 +58,8 @@
 for (path, copy_path) in copies {
 copymap.set_item(
 py,
-PyBytes::new(py, ),
-PyBytes::new(py, _path),
+PyBytes::new(py, path.as_ref()),
+PyBytes::new(py, copy_path.as_ref()),
 )?;
 }
 Ok(
@@ -99,13 +99,13 @@
 
 let mut dirstate_map = extract_dirstate(py, )?;
 
-let copies: Result, Vec>, PyErr> = copymap
+let copies: Result, PyErr> = copymap
 .items(py)
 .iter()
 .map(|(key, value)| {
 Ok((
-key.extract::(py)?.data(py).to_owned(),
-value.extract::(py)?.data(py).to_owned(),
+HgPathBuf::from_bytes(key.extract::(py)?.data(py)),
+HgPathBuf::from_bytes(value.extract::(py)?.data(py)),
 ))
 })
 .collect();
@@ -144,7 +144,7 @@
 let state: u8 = state.into();
 dmap.set_item(
 py,
-PyBytes::new(py, [..]),
+PyBytes::new(py, filename.as_ref()),
 decapsule_make_dirstate_tuple(py)?(
 state as c_char,
 mode,
diff --git a/rust/hg-cpython/src/filepatterns.rs 
b/rust/hg-cpython/src/filepatterns.rs
--- a/rust/hg-cpython/src/filepatterns.rs
+++ b/rust/hg-cpython/src/filepatterns.rs
@@ -14,7 +14,11 @@
 use cpython::{
 PyBytes, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, ToPyObject,
 };
-use hg::{build_single_regex, read_pattern_file, LineNumber, PatternTuple};
+use hg::{
+build_single_regex, read_pattern_file,
+utils::hg_path::{HgPath, HgPathBuf},
+LineNumber, PatternTuple,
+};
 
 /// Rust does not like functions with different return signatures.
 /// The 3-tuple version is always returned by the hg-core function,
@@ -32,7 +36,10 @@
 warn: bool,
 source_info: bool,
 ) -> PyResult {
-match read_pattern_file(file_path.extract::(py)?.data(py), warn) {
+match read_pattern_file(
+HgPath::new(file_path.extract::(py)?.data(py)),
+warn,
+) {
 Ok((patterns, warnings)) => {
 if source_info {
 let itemgetter = |x: | {
@@ -57,11 +64,13 @@
 
 fn warnings_to_py_bytes(
 py: Python,
-warnings: &[(Vec, Vec)],
+warnings: &[(HgPathBuf, Vec)],
 ) -> Vec<(PyBytes, PyBytes)> {
 warnings
 .iter()
-.map(|(path, syn)| (PyBytes::new(py, path), PyBytes::new(py, syn)))
+.map(|(path, syn)| {
+(PyBytes::new(py, path.as_ref()), PyBytes::new(py, syn))
+})
 .collect()
 }
 
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
@@ -24,6 +24,7 @@
 ref_sharing::PySharedState,
 };
 use hg::{
+utils::hg_path::{HgPath, HgPathBuf},
 DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap,
 DirstateParents, DirstateParseError, EntryState, PARENT_SIZE,
 };
@@ -64,7 +65,7 @@
 default: Option = None
 ) -> PyResult> {
 let key = key.extract::(py)?;
-match self.inner(py).borrow().get(key.data(py)) {
+match 

D6773: rust-hgpath: add HgPath and HgPathBuf structs to encapsulate handling of paths

2019-08-29 Thread Raphaël Gomès
Alphare created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This change is a direct consequence of this discussion on the mailing list:
  
https://www.mercurial-scm.org/pipermail/mercurial-devel/2019-August/133574.html
  
  The implementations of `HgPath` and `HgPathBuf` are, for the most part, taken
  directly from `OsStr` and `OsString` respectively from the standard library.
  
  What this change does *not* yet do is implement the Windows MBCS to WTF8
  conversion, but it lays the basis for a very flexible interface for paths.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6773

AFFECTED FILES
  rust/hg-core/src/utils.rs
  rust/hg-core/src/utils/hg_path.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/utils/hg_path.rs 
b/rust/hg-core/src/utils/hg_path.rs
new file mode 100644
--- /dev/null
+++ b/rust/hg-core/src/utils/hg_path.rs
@@ -0,0 +1,350 @@
+use crate::PatternFileError;
+use std::borrow::Borrow;
+use std::convert::TryInto;
+use std::ffi::OsString;
+use std::iter::FusedIterator;
+use std::ops::{Deref, Index, Range, RangeFrom, RangeFull, RangeTo};
+use std::path::{Path, PathBuf};
+
+/// This is a repository-relative path (or canonical path):
+/// - posix-like even on Windows,
+/// - no leading slash,
+/// - no "." nor ".." of special meaning,
+/// - stored in repository and shared across platforms.
+///
+/// This allows us to be encoding-transparent as much as possible, until really
+/// needed; `HgPath` can be transformed into a platform-specific path (`OsStr`
+/// or `Path`) whenever more complex operations are needed:
+/// On Unix, it's just byte-to-byte conversion. On Windows, it has to be
+/// decoded from MBCS to WTF-8. If WindowsUTF8Plan is implemented, the source
+/// character encoding will be determined per repository basis.
+#[derive(Eq, Ord, PartialEq, PartialOrd, Debug, Hash)]
+pub struct HgPath {
+inner: [u8],
+}
+
+impl HgPath {
+pub fn new + ?Sized>(s: ) ->  {
+unsafe { &*(s.as_ref() as *const [u8] as *const Self) }
+}
+pub fn is_empty() -> bool {
+self.inner.len() == 0
+}
+pub fn len() -> usize {
+self.inner.len()
+}
+fn to_hg_path_buf() -> HgPathBuf {
+HgPathBuf {
+inner: self.inner.to_owned(),
+}
+}
+fn from_inner(inner: &[u8]) ->  {
+unsafe { &*(inner as *const [u8] as *const HgPath) }
+}
+pub fn iter() -> HgPathIterator {
+HgPathIterator { path:  }
+}
+pub fn to_ascii_uppercase() -> HgPathBuf {
+HgPathBuf::from(self.inner.to_ascii_uppercase())
+}
+pub fn to_ascii_lowercase() -> HgPathBuf {
+HgPathBuf::from(self.inner.to_ascii_lowercase())
+}
+pub fn bytes() -> &[u8] {
+unsafe { &*( as *const _ as *const [u8]) }
+}
+}
+
+impl Index for HgPath {
+type Output = u8;
+
+fn index(, i: usize) -> ::Output {
+[i]
+}
+}
+
+impl Index for HgPath {
+type Output = HgPath;
+
+#[inline]
+fn index(, _index: RangeFull) ->  {
+
+}
+}
+
+impl Index> for HgPath {
+type Output = HgPath;
+
+#[inline]
+fn index(, range_to: RangeTo) ->  {
+HgPath::new([range_to])
+}
+}
+
+impl Index> for HgPath {
+type Output = HgPath;
+
+#[inline]
+fn index(, range_from: RangeFrom) ->  {
+HgPath::new([range_from])
+}
+}
+impl Index> for HgPath {
+type Output = HgPath;
+
+#[inline]
+fn index(, range: Range) ->  {
+HgPath::new([range])
+}
+}
+
+impl Index for HgPathBuf {
+type Output = u8;
+
+fn index(, i: usize) -> ::Output {
+[i]
+}
+}
+
+impl Index for HgPathBuf {
+type Output = HgPath;
+
+#[inline]
+fn index(, _index: RangeFull) ->  {
+HgPath::from_inner(self.inner.as_slice())
+}
+}
+
+impl Index> for HgPathBuf {
+type Output = HgPath;
+
+#[inline]
+fn index(, range_to: RangeTo) ->  {
+::new([range_to])
+}
+}
+
+impl Index> for HgPathBuf {
+type Output = HgPath;
+
+#[inline]
+fn index(, range_from: RangeFrom) ->  {
+HgPath::new([range_from])
+}
+}
+
+#[derive(Debug)]
+pub struct HgPathIterator<'a> {
+path: &'a HgPath,
+}
+
+impl<'a> Iterator for HgPathIterator<'a> {
+type Item = u8;
+fn next( self) -> Option {
+if self.path.len() == 0 {
+None
+} else {
+let ret = self.path[0];
+self.path = [1..self.path.len()];
+Some(ret)
+}
+}
+}
+
+impl<'a> ExactSizeIterator for HgPathIterator<'a> {
+// We can easily calculate the remaining number of iterations.
+fn len() -> usize {
+self.path.len()
+}
+}
+
+impl<'a> DoubleEndedIterator for HgPathIterator<'a> {
+fn next_back( self) -> Option {
+if self.path.len() == 0 {
+None
+} else {
+let back_position = self.path.len() - 

[PATCH] rust-fmt: run cargo fmt

2019-08-29 Thread Raphaël Gomès
# HG changeset patch
# User Raphaël Gomès 
# Date 1567086556 -7200
#  Thu Aug 29 15:49:16 2019 +0200
# Node ID 6ccae60f6d85c186b530095102acbc7b3d5ed7ba
# Parent  383fdfa6bba9366abe3aceeddfa65dd4a0b3870d
# EXP-Topic rust-fmt
rust-fmt: run cargo fmt

diff -r 383fdfa6bba9 -r 6ccae60f6d85 rust/hg-cpython/src/lib.rs
--- a/rust/hg-cpython/src/lib.rsThu Aug 22 16:47:31 2019 -0700
+++ b/rust/hg-cpython/src/lib.rsThu Aug 29 15:49:16 2019 +0200
@@ -31,10 +31,10 @@
 pub mod ref_sharing;
 pub mod dagops;
 pub mod dirstate;
-pub mod parsers;
 pub mod discovery;
 pub mod exceptions;
 pub mod filepatterns;
+pub mod parsers;
 
 py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| {
 m.add(
diff -r 383fdfa6bba9 -r 6ccae60f6d85 rust/hg-direct-ffi/src/ancestors.rs
--- a/rust/hg-direct-ffi/src/ancestors.rs   Thu Aug 22 16:47:31 2019 -0700
+++ b/rust/hg-direct-ffi/src/ancestors.rs   Thu Aug 29 15:49:16 2019 +0200
@@ -36,9 +36,7 @@
 
 impl Index {
 pub fn new(index: IndexPtr) -> Self {
-Index {
-index: index,
-}
+Index { index: index }
 }
 }
 
@@ -46,8 +44,13 @@
 /// wrap a call to the C extern parents function
 fn parents(, rev: Revision) -> Result<[Revision; 2], GraphError> {
 let mut res: [c_int; 2] = [0; 2];
-let code =
-unsafe { HgRevlogIndex_GetParents(self.index, rev,  res as 
*mut [c_int; 2]) };
+let code = unsafe {
+HgRevlogIndex_GetParents(
+self.index,
+rev,
+ res as *mut [c_int; 2],
+)
+};
 match code {
 0 => Ok(res),
 _ => Err(GraphError::ParentOutOfRange(rev)),
@@ -98,22 +101,26 @@
 
 let slice = slice::from_raw_parts(initrevs, initrevslen);
 
-Box::into_raw(Box::new(match AncestorsIterator::new(
-graph,
-slice.into_iter().map(|| r as Revision),
-stoprev as Revision,
-inclb,
-) {
-Ok(it) => it,
-Err(_) => {
-return null_mut();
-}
-}))
+Box::into_raw(Box::new(
+match AncestorsIterator::new(
+graph,
+slice.into_iter().map(|| r as Revision),
+stoprev as Revision,
+inclb,
+) {
+Ok(it) => it,
+Err(_) => {
+return null_mut();
+}
+},
+))
 }
 
 /// Deallocator to be called from C code
 #[no_mangle]
-pub extern "C" fn rustlazyancestors_drop(raw_iter: *mut 
AncestorsIterator) {
+pub extern "C" fn rustlazyancestors_drop(
+raw_iter: *mut AncestorsIterator,
+) {
 raw_drop(raw_iter);
 }
 
@@ -131,7 +138,9 @@
 /// it will be up to the C wrapper to convert that back into a Python end of
 /// iteration
 #[no_mangle]
-pub extern "C" fn rustlazyancestors_next(raw: *mut AncestorsIterator) 
-> c_long {
+pub extern "C" fn rustlazyancestors_next(
+raw: *mut AncestorsIterator,
+) -> c_long {
 raw_next(raw)
 }
 
@@ -227,7 +236,9 @@
 let mut initrevs: Vec = vec![11, 13];
 let initrevs_len = initrevs.len();
 let initrevs_ptr = initrevs.as_mut_ptr() as usize;
-let handler = thread::spawn(move || stub_raw_init(initrevs_len, 
initrevs_ptr, 0, 1));
+let handler = thread::spawn(move || {
+stub_raw_init(initrevs_len, initrevs_ptr, 0, 1)
+});
 let raw = handler.join().unwrap() as *mut AncestorsIterator;
 
 assert_eq!(raw_next(raw), 13);
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6772: remotefilelog: reduce probability of race-condition in remotefilelog tests

2019-08-29 Thread lothiraldan (Boris Feld)
lothiraldan created this revision.
Herald added subscribers: mercurial-devel, mjpieters.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  ca1014ad3de4 
 
introduced a new parameter `ensurestart` to speed up
  remotefilelog background processes start. Unfortunately it seems to have
  increased the possibility of race-conditions in remotefilelog tests testing
  those background processes.
  
  With `ensurestart=False`, it seems that it's more probable to enter in a race
  condition with `debugwaitonprefetch` and `debugwaitonrepack` in remotefilelog
  background tests. Our CI seems to have a high probability of triggering this
  race condition so make it configurable to ensure tests are stable.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6772

AFFECTED FILES
  hgext/remotefilelog/__init__.py
  hgext/remotefilelog/repack.py
  hgext/remotefilelog/shallowrepo.py
  tests/test-remotefilelog-bgprefetch.t
  tests/test-remotefilelog-repack-fast.t
  tests/test-remotefilelog-repack.t

CHANGE DETAILS

diff --git a/tests/test-remotefilelog-repack.t 
b/tests/test-remotefilelog-repack.t
--- a/tests/test-remotefilelog-repack.t
+++ b/tests/test-remotefilelog-repack.t
@@ -1,6 +1,12 @@
 #require no-windows
 
   $ . "$TESTDIR/remotefilelog-library.sh"
+# devel.remotefilelog.ensurestart: reduce race condition with
+# waiton{repack/prefetch}
+  $ cat >> $HGRCPATH < [devel]
+  > remotefilelog.ensurestart=True
+  > EOF
 
   $ hg init master
   $ cd master
diff --git a/tests/test-remotefilelog-repack-fast.t 
b/tests/test-remotefilelog-repack-fast.t
--- a/tests/test-remotefilelog-repack-fast.t
+++ b/tests/test-remotefilelog-repack-fast.t
@@ -1,10 +1,13 @@
 #require no-windows
 
   $ . "$TESTDIR/remotefilelog-library.sh"
-
+# devel.remotefilelog.ensurestart: reduce race condition with
+# waiton{repack/prefetch}
   $ cat >> $HGRCPATH < [remotefilelog]
   > fastdatapack=True
+  > [devel]
+  > remotefilelog.ensurestart=True
   > EOF
 
   $ hg init master
diff --git a/tests/test-remotefilelog-bgprefetch.t 
b/tests/test-remotefilelog-bgprefetch.t
--- a/tests/test-remotefilelog-bgprefetch.t
+++ b/tests/test-remotefilelog-bgprefetch.t
@@ -1,6 +1,12 @@
 #require no-windows
 
   $ . "$TESTDIR/remotefilelog-library.sh"
+# devel.remotefilelog.ensurestart: reduce race condition with
+# waiton{repack/prefetch}
+  $ cat >> $HGRCPATH < [devel]
+  > remotefilelog.ensurestart=True
+  > EOF
 
   $ hg init master
   $ cd master
diff --git a/hgext/remotefilelog/shallowrepo.py 
b/hgext/remotefilelog/shallowrepo.py
--- a/hgext/remotefilelog/shallowrepo.py
+++ b/hgext/remotefilelog/shallowrepo.py
@@ -183,7 +183,7 @@
 origctx=origctx)
 
 def backgroundprefetch(self, revs, base=None, repack=False, pats=None,
-   opts=None):
+   opts=None, ensurestart=False):
 """Runs prefetch in background with optional repack
 """
 cmd = [procutil.hgexecutable(), '-R', repo.origroot, 'prefetch']
@@ -193,7 +193,8 @@
 cmd += ['-r', revs]
 # We know this command will find a binary, so don't block
 # on it starting.
-procutil.runbgcommand(cmd, encoding.environ, ensurestart=False)
+procutil.runbgcommand(cmd, encoding.environ,
+  ensurestart=ensurestart)
 
 def prefetch(self, revs, base=None, pats=None, opts=None):
 """Prefetches all the necessary file revisions for the given revs
diff --git a/hgext/remotefilelog/repack.py b/hgext/remotefilelog/repack.py
--- a/hgext/remotefilelog/repack.py
+++ b/hgext/remotefilelog/repack.py
@@ -34,7 +34,8 @@
 class RepackAlreadyRunning(error.Abort):
 pass
 
-def backgroundrepack(repo, incremental=True, packsonly=False):
+def backgroundrepack(repo, incremental=True, packsonly=False,
+ ensurestart=False):
 cmd = [procutil.hgexecutable(), '-R', repo.origroot, 'repack']
 msg = _("(running background repack)\n")
 if incremental:
@@ -44,7 +45,7 @@
 cmd.append('--packsonly')
 repo.ui.warn(msg)
 # We know this command will find a binary, so don't block on it starting.
-procutil.runbgcommand(cmd, encoding.environ, ensurestart=False)
+procutil.runbgcommand(cmd, encoding.environ, ensurestart=ensurestart)
 
 def fullrepack(repo, options=None):
 """If ``packsonly`` is True, stores creating only loose objects are 
skipped.
diff --git a/hgext/remotefilelog/__init__.py b/hgext/remotefilelog/__init__.py
--- a/hgext/remotefilelog/__init__.py
+++ b/hgext/remotefilelog/__init__.py
@@ -224,6 +224,8 @@
 configitem('packs', 'maxpacksize', default=0)
 configitem('packs', 'maxchainlen', default=1000)
 
+configitem('devel', 'remotefilelog.ensurestart', default=False)
+
 #  default TTL limit is 30 days
 _defaultlimit = 

D6771: py3: use pycompat.maplist() in chgserver

2019-08-29 Thread martinvonz (Martin von Zweigbergk)
Closed by commit rHG0cbe17335857: py3: use pycompat.maplist() in chgserver 
(authored by martinvonz).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6771?vs=16332=16333

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6771/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6771

AFFECTED FILES
  mercurial/chgserver.py

CHANGE DETAILS

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -172,7 +172,7 @@
 except OSError:
 # could be ENOENT, EPERM etc. not fatal in any case
 pass
-return _hashlist(map(trystat, paths))[:12]
+return _hashlist(pycompat.maplist(trystat, paths))[:12]
 
 class hashstate(object):
 """a structure storing confighash, mtimehash, paths used for mtimehash"""



To: martinvonz, #hg-reviewers, pulkit
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel