D10838: rhg: add exit code to HgError::Abort()

2021-06-07 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  My previous attempts to have rhg end with correct exit code was more of bug
  hunting. I found cases which were failing and fixed them. But as one might
  expect, more tests started failing.
  
  Let's add exit code `HgError::Abort()` and make it users explicitly tell what
  exit code they want.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/config/layer.rs
  rust/hg-core/src/errors.rs
  rust/hg-core/src/repo.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/repo.rs b/rust/hg-core/src/repo.rs
--- a/rust/hg-core/src/repo.rs
+++ b/rust/hg-core/src/repo.rs
@@ -152,6 +152,7 @@
 Some(b"abort") | None => HgError::abort(
 "abort: share source does not support share-safe 
requirement\n\
 (see `hg help config.format.use-share-safe` for more 
information)",
+30,
 ),
 _ => HgError::unsupported("share-safe downgrade"),
 }
@@ -163,6 +164,7 @@
 "abort: version mismatch: source uses share-safe \
 functionality while the current share does not\n\
 (see `hg help config.format.use-share-safe` for 
more information)",
+30,
 ),
 _ => HgError::unsupported("share-safe upgrade"),
 }
diff --git a/rust/hg-core/src/errors.rs b/rust/hg-core/src/errors.rs
--- a/rust/hg-core/src/errors.rs
+++ b/rust/hg-core/src/errors.rs
@@ -29,7 +29,7 @@
 ///
 /// The given string is a short explanation for users, not intended to be
 /// machine-readable.
-Abort(String),
+Abort(String, i32),
 
 /// A configuration value is not in the expected syntax.
 ///
@@ -69,8 +69,9 @@
 pub fn unsupported(explanation: impl Into) -> Self {
 HgError::UnsupportedFeature(explanation.into())
 }
-pub fn abort(explanation: impl Into) -> Self {
-HgError::Abort(explanation.into())
+
+pub fn abort(explanation: impl Into, exit_code: i32) -> Self {
+HgError::Abort(explanation.into(), exit_code)
 }
 }
 
@@ -78,7 +79,7 @@
 impl fmt::Display for HgError {
 fn fmt(, f:  fmt::Formatter) -> fmt::Result {
 match self {
-HgError::Abort(explanation) => write!(f, "{}", explanation),
+HgError::Abort(explanation, _) => write!(f, "{}", explanation),
 HgError::IoError { error, context } => {
 write!(f, "abort: {}: {}", context, error)
 }
diff --git a/rust/hg-core/src/config/layer.rs b/rust/hg-core/src/config/layer.rs
--- a/rust/hg-core/src/config/layer.rs
+++ b/rust/hg-core/src/config/layer.rs
@@ -73,11 +73,14 @@
 if let Some((section, item, value)) = parse_one(arg) {
 layer.add(section, item, value, None);
 } else {
-Err(HgError::abort(format!(
-"abort: malformed --config option: '{}' \
+Err(HgError::abort(
+format!(
+"abort: malformed --config option: '{}' \
 (use --config section.name=value)",
-String::from_utf8_lossy(arg),
-)))?
+String::from_utf8_lossy(arg),
+),
+10,
+))?
 }
 }
 if layer.sections.is_empty() {



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


D10839: rhg: propogate error coming from HgError::Abort to CommandError

2021-06-07 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/error.rs
  tests/test-globalopts.t

CHANGE DETAILS

diff --git a/tests/test-globalopts.t b/tests/test-globalopts.t
--- a/tests/test-globalopts.t
+++ b/tests/test-globalopts.t
@@ -220,7 +220,6 @@
   $ hg --cwd c --config paths.quuxfoo=bar paths | grep quuxfoo > /dev/null && 
echo quuxfoo
   quuxfoo
 TODO: add rhg support for detailed exit codes
-#if no-rhg
   $ hg --cwd c --config '' tip -q
   abort: malformed --config option: '' (use --config section.name=value)
   [10]
@@ -236,7 +235,6 @@
   $ hg --cwd c --config .b= tip -q
   abort: malformed --config option: '.b=' (use --config section.name=value)
   [10]
-#endif
 
 Testing --debug:
 
diff --git a/rust/rhg/src/error.rs b/rust/rhg/src/error.rs
--- a/rust/rhg/src/error.rs
+++ b/rust/rhg/src/error.rs
@@ -69,6 +69,9 @@
 HgError::UnsupportedFeature(message) => {
 CommandError::unsupported(message)
 }
+HgError::Abort(message, exit_code) => {
+CommandError::abort_with_exit_code(message, exit_code)
+}
 _ => CommandError::abort(error.to_string()),
 }
 }
@@ -125,7 +128,10 @@
 fn from(error: ConfigError) -> Self {
 match error {
 ConfigError::Parse(error) => error.into(),
-ConfigError::Other(error) => error.into(),
+ConfigError::Other(HgError::Abort(message, exit_code)) => {
+CommandError::abort_with_exit_code(message, exit_code)
+}
+ConfigError::Other(_) => error.into(),
 }
 }
 }



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


D10837: rhg: split non_repo_config and `--config` loading in different functions

2021-06-07 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This will help us in better handling of error caused when trying to
  load `--config` values.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/config/config.rs
  rust/rhg/src/main.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs
+++ b/rust/rhg/src/main.rs
@@ -126,8 +126,8 @@
 })
 });
 
-let non_repo_config =
-Config::load(early_args.config).unwrap_or_else(|error| {
+let mut non_repo_config =
+Config::load_non_repo().unwrap_or_else(|error| {
 // Normally this is decided based on config, but we don’t have that
 // available. As of this writing config loading never returns an
 // "unsupported" error but that is not enforced by the type system.
@@ -142,6 +142,20 @@
 )
 });
 
+non_repo_config
+.load_cli_args_config(early_args.config)
+.unwrap_or_else(|error| {
+exit(
+_current_dir,
+,
+OnUnsupported::from_config(, _repo_config),
+Err(error.into()),
+non_repo_config
+.get_bool(b"ui", b"detailed-exit-code")
+.unwrap_or(false),
+)
+});
+
 if let Some(repo_path_bytes) = _args.repo {
 lazy_static::lazy_static! {
 static ref SCHEME_RE: regex::bytes::Regex =
diff --git a/rust/hg-core/src/config/config.rs 
b/rust/hg-core/src/config/config.rs
--- a/rust/hg-core/src/config/config.rs
+++ b/rust/hg-core/src/config/config.rs
@@ -88,9 +88,7 @@
 /// Load system and user configuration from various files.
 ///
 /// This is also affected by some environment variables.
-pub fn load(
-cli_config_args: impl IntoIterator>,
-) -> Result {
+pub fn load_non_repo() -> Result {
 let mut config = Self { layers: Vec::new() };
 let opt_rc_path = env::var_os("HGRCPATH");
 // HGRCPATH replaces system config
@@ -133,10 +131,17 @@
 }
 }
 }
+Ok(config)
+}
+
+pub fn load_cli_args_config(
+ self,
+cli_config_args: impl IntoIterator>,
+) -> Result<(), ConfigError> {
 if let Some(layer) = ConfigLayer::parse_cli_args(cli_config_args)? {
-config.layers.push(layer)
+self.layers.push(layer)
 }
-Ok(config)
+Ok(())
 }
 
 fn add_trusted_dir( self, path: ) -> Result<(), ConfigError> {



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


D10836: dirstate-v2: Store a hash of ignore patterns (.hgignore)

2021-06-07 Thread SimonSapin
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Later, this help extend `read_dir` caching to directories that contain ignored
  files (but no unknown files). Such cache must be invalidated when ignore 
patterns
  change since a formerly-ignored file might become unknown.
  
  This helps the default configuration of `hg status` where unknown files must
  be listed, but ignored files are not.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/dirstate/status.rs
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-core/src/dirstate_tree/on_disk.rs
  rust/hg-core/src/dirstate_tree/status.rs
  rust/hg-core/src/filepatterns.rs
  rust/hg-core/src/matchers.rs
  tests/test-hgignore.t

CHANGE DETAILS

diff --git a/tests/test-hgignore.t b/tests/test-hgignore.t
--- a/tests/test-hgignore.t
+++ b/tests/test-hgignore.t
@@ -402,3 +402,23 @@
   $ hg up -qC .
 
 #endif
+
+#if dirstate-v2
+
+Check the hash of ignore patterns written in the dirstate at offset
+12 + 20 + 20 + 8 + 4 + 4 + 4 = 72
+
+  $ hg status > /dev/null
+  $ cat .hg/testhgignore .hg/testhgignorerel .hgignore dir2/.hgignore 
dir1/.hgignore dir1/.hgignoretwo | $TESTDIR/f --sha1
+  sha1=6e315b60f15fb5dfa02be00f3e2c8f923051f5ff
+  >>> import binascii; print(binascii.hexlify(open(".hg/dirstate", 
"rb").read()[72:][:20]).decode())
+  6e315b60f15fb5dfa02be00f3e2c8f923051f5ff
+
+  $ echo rel > .hg/testhgignorerel
+  $ hg status > /dev/null
+  $ cat .hg/testhgignore .hg/testhgignorerel .hgignore dir2/.hgignore 
dir1/.hgignore dir1/.hgignoretwo | $TESTDIR/f --sha1
+  sha1=dea19cc7119213f24b6b582a4bae7b0cb063e34e
+  >>> import binascii; print(binascii.hexlify(open(".hg/dirstate", 
"rb").read()[72:][:20]).decode())
+  dea19cc7119213f24b6b582a4bae7b0cb063e34e
+
+#endif
diff --git a/rust/hg-core/src/matchers.rs b/rust/hg-core/src/matchers.rs
--- a/rust/hg-core/src/matchers.rs
+++ b/rust/hg-core/src/matchers.rs
@@ -564,8 +564,9 @@
 /// function that checks whether a given file (in the general sense) should be
 /// ignored.
 pub fn get_ignore_function<'a>(
-all_pattern_files: Vec,
+mut all_pattern_files: Vec,
 root_dir: ,
+inspect_pattern_bytes:  impl FnMut(&[u8]),
 ) -> PatternResult<(
 Box Fn(&'r HgPath) -> bool + Sync + 'a>,
 Vec,
@@ -573,9 +574,20 @@
 let mut all_patterns = vec![];
 let mut all_warnings = vec![];
 
+// Sort to make the ordering of calls to `inspect_pattern_bytes`
+// deterministic even if the ordering of `all_pattern_files` is not (such
+// as when a iteration order of a Python dict or Rust HashMap is involved).
+// Sort by "string" representation instead of the default by component
+// (with a Rust-specific definition of a component)
+all_pattern_files
+.sort_unstable_by(|a, b| a.as_os_str().cmp(b.as_os_str()));
+
 for pattern_file in _pattern_files {
-let (patterns, warnings) =
-get_patterns_from_file(pattern_file, root_dir)?;
+let (patterns, warnings) = get_patterns_from_file(
+pattern_file,
+root_dir,
+inspect_pattern_bytes,
+)?;
 
 all_patterns.extend(patterns.to_owned());
 all_warnings.extend(warnings);
diff --git a/rust/hg-core/src/filepatterns.rs b/rust/hg-core/src/filepatterns.rs
--- a/rust/hg-core/src/filepatterns.rs
+++ b/rust/hg-core/src/filepatterns.rs
@@ -17,8 +17,6 @@
 };
 use lazy_static::lazy_static;
 use regex::bytes::{NoExpand, Regex};
-use std::fs::File;
-use std::io::Read;
 use std::ops::Deref;
 use std::path::{Path, PathBuf};
 use std::vec::Vec;
@@ -410,24 +408,19 @@
 pub fn read_pattern_file(
 file_path: ,
 warn: bool,
+inspect_pattern_bytes:  impl FnMut(&[u8]),
 ) -> Result<(Vec, Vec), PatternError> {
-let mut f = match File::open(file_path) {
-Ok(f) => Ok(f),
-Err(e) => match e.kind() {
-std::io::ErrorKind::NotFound => {
-return Ok((
-vec![],
-vec![PatternFileWarning::NoSuchFile(file_path.to_owned())],
-))
-}
-_ => Err(e),
-},
-}?;
-let mut contents = Vec::new();
-
-f.read_to_end( contents)?;
-
-Ok(parse_pattern_file_contents(, file_path, warn)?)
+match std::fs::read(file_path) {
+Ok(contents) => {
+inspect_pattern_bytes();
+parse_pattern_file_contents(, file_path, warn)
+}
+Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok((
+vec![],
+vec![PatternFileWarning::NoSuchFile(file_path.to_owned())],
+)),
+Err(e) => Err(e.into()),
+}
 }
 
 /// Represents an entry in an "ignore" file.
@@ -458,8 +451,10 @@
 pub fn get_patterns_from_file(
 pattern_file: ,
 root_dir: ,
+inspect_pattern_bytes:  impl FnMut(&[u8]),
 ) -> 

mercurial@47343: new changeset (1 on stable)

2021-06-07 Thread Mercurial Commits
New changeset (1 on stable) in mercurial:

https://www.mercurial-scm.org/repo/hg/rev/9f798c1b0d89
changeset:   47343:9f798c1b0d89
branch:  stable
tag: tip
parent:  47318:5ac0f2a8ba72
user:Georges Racinet 
date:Sun Jun 06 01:24:30 2021 +0200
summary: cext: fix memory leak in phases computation

-- 
Repository URL: https://www.mercurial-scm.org/repo/hg
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Failed pipeline for branch/default | mercurial-devel | 8adc88fd

2021-06-07 Thread Heptapod


Pipeline #22839 has failed!

Project: mercurial-devel ( https://foss.heptapod.net/octobus/mercurial-devel )
Branch: branch/default ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/commits/branch/default )

Commit: 8adc88fd ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/commit/8adc88fd2d26105504d44f112e5d6910722dca23
 )
Commit Message: censor: implement censoring for revlogv2

It is...
Commit Author: Pierre-Yves David ( https://foss.heptapod.net/marmoute )

Pipeline #22839 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/pipelines/22839 ) triggered 
by Administrator ( https://foss.heptapod.net/root )
had 11 failed builds.

Job #204971 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204971/raw )

Stage: tests
Name: test-py2-rust
Job #204969 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204969/raw )

Stage: tests
Name: test-py2-pure
Job #204973 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204973/raw )

Stage: tests
Name: test-py3-rhg
Job #204974 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204974/raw )

Stage: tests
Name: test-py2-chg
Job #204967 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204967/raw )

Stage: tests
Name: test-py2
Job #204968 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204968/raw )

Stage: tests
Name: test-py3
Job #204972 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204972/raw )

Stage: tests
Name: test-py3-rust
Job #204970 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204970/raw )

Stage: tests
Name: test-py3-pure
Job #204975 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204975/raw )

Stage: tests
Name: test-py3-chg
Job #204963 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204963/raw )

Stage: tests
Name: checks-py2
Job #204964 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/204964/raw )

Stage: tests
Name: checks-py3

-- 
You're receiving this email because of your account on foss.heptapod.net.



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


Re: [PATCH STABLE] cext: fix memory leak in phases computation

2021-06-07 Thread Raphaël Gomès
Also looks correct to me. Since Joerg and the CI agree with this, I'll 
go ahead and queue this patch.


Thanks Georges

On 6/7/21 12:29 AM, Georges Racinet wrote:

# HG changeset patch
# User Georges Racinet 
# Date 1622935470 -7200
#  Sun Jun 06 01:24:30 2021 +0200
# Branch stable
# Node ID be560b55eb7cfe25c68fb6fab5417fab6688cf84
# Parent  5ac0f2a8ba7205266a206ad8da89a79173e8efea
# EXP-Topic memleak-phases
cext: fix memory leak in phases computation

Without this a buffer whose size in bytes is the number of
changesets in the repository is leaked each time the repository is
opened and changeset phases are computed.

Impact: the current code in hgwebdir creates a new `localrepository`
instance for each HTTP request. Since any pull or push is made of several
requests, a team of 100 people can easily produce thousands of such
requests per day.

Being a low-level malloc, this leak can't be seen with the gc module and
tools relying on that, but was spotted by valgrind immediately.

Reproduction


   for i in range(cl_args.iterations):
   repo = hg.repository(baseui, repo_path)
   rev = repo.revs(rev).first()
   ctx = repo[rev]

   del ctx
   del repo
   # avoid any pollution by other type of leak
   # (that should be fixed in 5.8)
   repoview._filteredrepotypes.clear()

   gc.collect()

Measurements


Resident Set Size (RSS), taken on a clone of
mozilla-central for performance analysis (440 000
changesets).

before:
   5.8+hg19.5ac0f2a8ba72  1000 iterations: 1606MB
   5.8+hg19.5ac0f2a8ba72 1 iterations: 5723MB
after:
   5.8+hg20.e2084d39e145  1000 iterations:  555MB
   5.8+hg20.e2084d39e145 1 iterations:  555MB
  (double checked, not a copy/paste error)

(e2084d39e14 is the present changeset, before amendment
of the message to add the measurements)

diff -r 5ac0f2a8ba72 -r be560b55eb7c mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c   Thu May 20 14:20:39 2021 -0400
+++ b/mercurial/cext/revlog.c   Sun Jun 06 01:24:30 2021 +0200
@@ -919,6 +919,7 @@
phasesets[i] = NULL;
}
  
+	free(phases);

return Py_BuildValue("nN", len, phasesetsdict);
  
  release:


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

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