D10198: rebase: inline simple function for finding obsolete subset of commits

2021-03-12 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `_filterobsoleterevs()` is just one line long. It was introduced in
  2d294dada4f8 
 
(rebase: small refactoring to allow better extensibility
  from extensions, 2016-01-14), for use by the "inhibit" extension. That
  extension was removed from the evolve repo in 87e87881059d (compat:
  drop the inhibit hacky extension, 2017-10-24).

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/rebase.py

CHANGE DETAILS

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -474,7 +474,7 @@
 )
 
 # Calculate self.obsoletenotrebased
-obsrevs = _filterobsoleterevs(self.repo, self.state)
+obsrevs = {r for r in self.state if self.repo[r].obsolete()}
 self._handleskippingobsolete(obsrevs, self.destmap)
 
 # Keep track of the active bookmarks in order to reset them later
@@ -2184,11 +2184,6 @@
 return ret
 
 
-def _filterobsoleterevs(repo, revs):
-"""returns a set of the obsolete revisions in revs"""
-return {r for r in revs if repo[r].obsolete()}
-
-
 def _computeobsoletenotrebased(repo, rebaseobsrevs, destmap):
 """Return (obsoletenotrebased, obsoletewithoutsuccessorindestination).
 



To: martinvonz, #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


D10197: amend: mark commit obsolete after moving working copy

2021-03-12 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We were doing it this way:
  
  1. move working copy (repo.setparents)
  2. add obsmarkers (scmutil.cleanupnodes)
  3. fix dirstate (dirstate.normal/drop)
  
  Step 1 and 3 are closely related, so let's move them together. It
  seems safest to create the obsmarkers last. This patch thus makes the
  order 1, 3, 2.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cmdutil.py

CHANGE DETAILS

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2967,20 +2967,6 @@
 
 # Reroute the working copy parent to the new changeset
 repo.setparents(newid, nullid)
-mapping = {old.node(): (newid,)}
-obsmetadata = None
-if opts.get(b'note'):
-obsmetadata = {b'note': encoding.fromlocal(opts[b'note'])}
-backup = ui.configbool(b'rewrite', b'backup-bundle')
-scmutil.cleanupnodes(
-repo,
-mapping,
-b'amend',
-metadata=obsmetadata,
-fixphase=True,
-targetphase=commitphase,
-backup=backup,
-)
 
 # Fixing the dirstate because localrepo.commitctx does not update
 # it. This is rather convenient because we did not need to update
@@ -3003,6 +2989,21 @@
 for f in removedfiles:
 dirstate.drop(f)
 
+mapping = {old.node(): (newid,)}
+obsmetadata = None
+if opts.get(b'note'):
+obsmetadata = {b'note': encoding.fromlocal(opts[b'note'])}
+backup = ui.configbool(b'rewrite', b'backup-bundle')
+scmutil.cleanupnodes(
+repo,
+mapping,
+b'amend',
+metadata=obsmetadata,
+fixphase=True,
+targetphase=commitphase,
+backup=backup,
+)
+
 return newid
 
 



To: martinvonz, #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


Failed pipeline for branch/default | mercurial-devel | 7cc7820f

2021-03-12 Thread Heptapod


Pipeline #19277 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: 7cc7820f ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/commit/7cc7820fd6b96b9ec010abd42a435c9b720aceb2
 )
Commit Message: ci: hook network-io tests into the pipeline

Th...
Commit Author: Jörg Sonnenberger ( https://foss.heptapod.net/joerg )

Pipeline #19277 ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/pipelines/19277 ) triggered 
by Administrator ( https://foss.heptapod.net/root )
had 1 failed build.

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

Stage: tests
Name: test-py3-pure

-- 
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


D10195: run-test: install rhg if --rhg is passed

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

REVISION SUMMARY
  Before this, --rhg was only working with --local.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  tests/run-tests.py

CHANGE DETAILS

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -3389,6 +3389,9 @@
 if self.options.chg:
 assert self._installdir
 self._installchg()
+if self.options.rhg:
+assert self._installdir
+self._installrhg()
 
 log(
 'running %d tests using %d parallel processes'
@@ -3750,6 +3753,33 @@
 sys.stdout.write(out)
 sys.exit(1)
 
+def _installrhg(self):
+"""Install rhg into the test environment"""
+vlog('# Performing temporary installation of rhg')
+assert os.path.dirname(self._bindir) == self._installdir
+assert self._hgroot, 'must be called after _installhg()'
+cmd = b'"%(make)s" install-rhg PREFIX="%(prefix)s"' % {
+b'make': b'make',  # TODO: switch by option or environment?
+b'prefix': self._installdir,
+}
+cwd = self._hgroot
+vlog("# Running", cmd)
+proc = subprocess.Popen(
+cmd,
+shell=True,
+cwd=cwd,
+stdin=subprocess.PIPE,
+stdout=subprocess.PIPE,
+stderr=subprocess.STDOUT,
+)
+out, _err = proc.communicate()
+if proc.returncode != 0:
+if PYTHON3:
+sys.stdout.buffer.write(out)
+else:
+sys.stdout.write(out)
+sys.exit(1)
+
 def _outputcoverage(self):
 """Produce code coverage output."""
 import coverage



To: SimonSapin, #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


D10190: tests: Disable for rhg remaining tests that fail in that mode

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

REVISION SUMMARY
  These cases are in features not yet implemented by rhg
  for which triggering a fallback is not practical.
  
  Disabling some tests allows us to reach passing CI and catch
  any future regression in the rest of the tests.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  tests/test-config.t
  tests/test-debugcommands.t
  tests/test-dispatch.t
  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
@@ -65,6 +65,8 @@
 
 -R with path aliases:
 
+TODO: add rhg support for path aliases
+#if no-rhg
   $ cd c
   $ hg -R default identify
   8580ff50825a tip
@@ -75,6 +77,7 @@
   $ HOME=`pwd`/../ hg -R relativetohome identify
   8580ff50825a tip
   $ cd ..
+#endif
 
 #if no-outer-repo
 
@@ -215,6 +218,8 @@
 
   $ 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]
@@ -230,6 +235,7 @@
   $ hg --cwd c --config .b= tip -q
   abort: malformed --config option: '.b=' (use --config section.name=value)
   [10]
+#endif
 
 Testing --debug:
 
diff --git a/tests/test-dispatch.t b/tests/test-dispatch.t
--- a/tests/test-dispatch.t
+++ b/tests/test-dispatch.t
@@ -90,9 +90,12 @@
 
   $ mkdir -p badrepo/.hg
   $ echo 'invalid-syntax' > badrepo/.hg/hgrc
+TODO: add rhg support for detailed exit codes
+#if no-rhg
   $ hg log -b -Rbadrepo default
   config error at badrepo/.hg/hgrc:1: invalid-syntax
   [30]
+#endif
 
   $ hg log -b --cwd=inexistent default
   abort: $ENOENT$: 'inexistent'
diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t
--- a/tests/test-debugcommands.t
+++ b/tests/test-debugcommands.t
@@ -531,9 +531,17 @@
 
 Test WdirUnsupported exception
 
+#if no-rhg
   $ hg debugdata -c 
   abort: working directory revision cannot be specified
   [255]
+#else
+TODO: add rhg support for (at least parsing) the working directory 
pseudo-changeset
+  $ hg debugdata -c 
+  abort: working directory revision cannot be specified 
(missing-correct-output !)
+  abort: invalid revision identifier:  
(known-bad-output !)
+  [255]
+#endif
 
 Test cache warming command
 
diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -3,6 +3,8 @@
 
 Invalid syntax: no value
 
+TODO: add rhg support for detailed exit codes
+#if no-rhg
   $ cat > .hg/hgrc << EOF
   > novaluekey
   > EOF
@@ -35,6 +37,7 @@
   $ hg showconfig
   config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace:  
[section]
   [30]
+#endif
 
 Reset hgrc
 



To: SimonSapin, #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


D10196: ci: Add a job testing with rhg installed as `hg`

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

REVISION SUMMARY
  This significantly increases test coverage of rhg, without duplicating
  many tests that already exist.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  contrib/heptapod-ci.yml

CHANGE DETAILS

diff --git a/contrib/heptapod-ci.yml b/contrib/heptapod-ci.yml
--- a/contrib/heptapod-ci.yml
+++ b/contrib/heptapod-ci.yml
@@ -25,17 +25,6 @@
 - echo "$RUNTEST_ARGS"
 - HGMODULEPOLICY="$TEST_HGMODULEPOLICY" "$PYTHON" tests/run-tests.py 
--color=always $RUNTEST_ARGS
 
-
-.rust_template: &rust
-before_script:
-  - hg clone . /tmp/mercurial-ci/ --noupdate --config phases.publish=no
-  - hg -R /tmp/mercurial-ci/ update `hg log --rev '.' --template '{node}'`
-  - ls -1 tests/test-check-*.* > /tmp/check-tests.txt
-  - cd /tmp/mercurial-ci/rust/rhg
-  - cargo build --release
-  - cd /tmp/mercurial-ci/
-
-
 checks-py2:
 <<: *runtests
 variables:
@@ -92,7 +81,6 @@
 
 test-py2-rust:
 <<: *runtests
-<<: *rust
 variables:
 HGWITHRUSTEXT: cpython
 RUNTEST_ARGS: "--rust --blacklist /tmp/check-tests.txt"
@@ -100,13 +88,20 @@
 
 test-py3-rust:
 <<: *runtests
-<<: *rust
 variables:
 HGWITHRUSTEXT: cpython
 RUNTEST_ARGS: "--rust --blacklist /tmp/check-tests.txt"
 PYTHON: python3
 TEST_HGMODULEPOLICY: "rust+c"
 
+test-py3-rhg:
+<<: *runtests
+variables:
+HGWITHRUSTEXT: cpython
+RUNTEST_ARGS: "--rust --rhg --blacklist /tmp/check-tests.txt"
+PYTHON: python3
+TEST_HGMODULEPOLICY: "rust+c"
+
 test-py2-chg:
 <<: *runtests
 variables:



To: SimonSapin, #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


D10189: rhg: Remove `rhg.fallback-executable=hg` default configuration

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

REVISION SUMMARY
  When `rhg.on-unsupported` is configured to `fallback` and an unsupported
  feature is encountered, the previous default was to look for an `hg`
  executable in `$PATH`.
  
  This default was fragile since it was easy to end up accidentally using
  an older version of Mercurial installed system-wide,
  when a local (perhaps patched) installation was intended.
  
  Instead, it is now an error to have `rhg.on-unsupported=fallback`
  without also configuring an explicit path or the fallback executable.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS

diff --git a/tests/test-rhg.t b/tests/test-rhg.t
--- a/tests/test-rhg.t
+++ b/tests/test-rhg.t
@@ -150,6 +150,10 @@
   $ rhg cat original
   original content
 
+  $ env -u RHG_FALLBACK_EXECUTABLE rhg cat original
+  abort: 'rhg.on-unsupported=fallback' requires configuring a 
'rhg.fallback-executable' path
+  [255]
+
   $ rhg cat original --config rhg.fallback-executable=false
   [1]
 
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
@@ -138,7 +138,7 @@
 exit(
 &initial_current_dir,
 &ui,
-OnUnsupported::from_config(&non_repo_config),
+OnUnsupported::from_config(&ui, &non_repo_config),
 Err(CommandError::UnsupportedFeature {
 message: format_bytes!(
 b"URL-like --repository {}",
@@ -158,7 +158,7 @@
 Err(error) => exit(
 &initial_current_dir,
 &ui,
-OnUnsupported::from_config(&non_repo_config),
+OnUnsupported::from_config(&ui, &non_repo_config),
 Err(error.into()),
 ),
 };
@@ -168,6 +168,7 @@
 } else {
 &non_repo_config
 };
+let on_unsupported = OnUnsupported::from_config(&ui, config);
 
 let result = main_with_result(
 &process_start_time,
@@ -175,12 +176,7 @@
 repo_result.as_ref(),
 config,
 );
-exit(
-&initial_current_dir,
-&ui,
-OnUnsupported::from_config(config),
-result,
-)
+exit(&initial_current_dir, &ui, on_unsupported, result)
 }
 
 fn exit_code(result: &Result<(), CommandError>) -> i32 {
@@ -242,6 +238,14 @@
 }
 }
 }
+exit_no_fallback(ui, on_unsupported, result)
+}
+
+fn exit_no_fallback(
+ui: &Ui,
+on_unsupported: OnUnsupported,
+result: Result<(), CommandError>,
+) -> ! {
 match &result {
 Ok(_) => {}
 Err(CommandError::Unsuccessful) => {}
@@ -387,9 +391,8 @@
 
 impl OnUnsupported {
 const DEFAULT: Self = OnUnsupported::Abort;
-const DEFAULT_FALLBACK_EXECUTABLE: &'static [u8] = b"hg";
 
-fn from_config(config: &Config) -> Self {
+fn from_config(ui: &Ui, config: &Config) -> Self {
 match config
 .get(b"rhg", b"on-unsupported")
 .map(|value| value.to_ascii_lowercase())
@@ -400,7 +403,16 @@
 Some(b"fallback") => OnUnsupported::Fallback {
 executable: config
 .get(b"rhg", b"fallback-executable")
-.unwrap_or(Self::DEFAULT_FALLBACK_EXECUTABLE)
+.unwrap_or_else(|| {
+exit_no_fallback(
+ui,
+Self::Abort,
+Err(CommandError::abort(
+"abort: 'rhg.on-unsupported=fallback' requires 
configuring \
+a 'rhg.fallback-executable' path"
+)),
+)
+})
 .to_owned(),
 },
 None => Self::DEFAULT,



To: SimonSapin, #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


D10193: makefile: add a build-rhg option

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

REVISION SUMMARY
  This gives an easy action to build the rhg-binary. This will be useful for the
  `install-rhg` action in the next changeset.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  Makefile

CHANGE DETAILS

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -71,6 +71,9 @@
 build-chg:
make -C contrib/chg
 
+build-rhg:
+   (cd rust/rhg; cargo build --release)
+
 wheel:
FORCE_SETUPTOOLS=1 $(PYTHON) setup.py $(PURE) bdist_wheel 
$(COMPILERFLAG)
 



To: SimonSapin, #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


D10194: makefile: add a install option

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

REVISION SUMMARY
  This gives and easy way to install rhg that we can use in `run-test.py` in the
  next changesets.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  Makefile

CHANGE DETAILS

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -116,6 +116,9 @@
 install-home-doc: doc
cd doc && $(MAKE) $(MFLAGS) PREFIX="$(HOME)" install
 
+install-rhg: build-rhg
+   install -m 755 rust/target/release/rhg "$(PREFIX)"/bin/
+
 MANIFEST-doc:
$(MAKE) -C doc MANIFEST
 



To: SimonSapin, #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


D10192: makefile: add a install-chg option

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

REVISION SUMMARY
  This is done as a gratuitous improvement on the way to add makefile entry to
  build and install rhg.
  
  It seems saner to have equivalent entry for chg too.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  Makefile

CHANGE DETAILS

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -99,6 +99,9 @@
 install-bin: build
$(PYTHON) setup.py $(PURE) install --root="$(DESTDIR)/" 
--prefix="$(PREFIX)" --force
 
+install-chg: build-chg
+   make -C contrib/chg install PREFIX="$(PREFIX)"
+
 install-doc: doc
cd doc && $(MAKE) $(MFLAGS) install
 



To: SimonSapin, #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


D10191: makefile: add a build-chg option

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

REVISION SUMMARY
  This is done as a gratuitous improvement on the way to add makefile entry to
  build and install rhg.
  
  It seems saner to have equivalent entry for chg too.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  Makefile

CHANGE DETAILS

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -68,6 +68,9 @@
 build:
$(PYTHON) setup.py $(PURE) build $(COMPILERFLAG)
 
+build-chg:
+   make -C contrib/chg
+
 wheel:
FORCE_SETUPTOOLS=1 $(PYTHON) setup.py $(PURE) bdist_wheel 
$(COMPILERFLAG)
 



To: SimonSapin, #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


D10188: rhg: Add an allow-list of ignored extensions

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

REVISION SUMMARY
  Because rhg doesn’t know how a Python extension would affect
  behavior it implements in Rust, when an unsupported extension
  is enabled it conservatively falls back to Python-based hg.
  
  However many users will have unsupported extensions enabled in practice.
  Maybe they don’t actually affect rhg behavior, but we don’t know.
  This adds a `rhg.ignored-extensions` configuration that lets
  users list extensions that rhg can safely ignore and proceed even
  if they’re not supported in Rust.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -365,12 +365,20 @@
 unsupported.remove(supported);
 }
 
+if let Some(ignored_list) =
+config.get_simple_list(b"rhg", b"ignored-extensions")
+{
+for ignored in ignored_list {
+unsupported.remove(ignored);
+}
+}
+
 if unsupported.is_empty() {
 Ok(())
 } else {
 Err(CommandError::UnsupportedFeature {
 message: format_bytes!(
-b"extensions: {}",
+b"extensions: {}.\nConsider adding them to 
'rhg.ignored-extensions' config.",
 join(unsupported, b", ")
 ),
 })
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
@@ -13,6 +13,7 @@
 ConfigError, ConfigLayer, ConfigOrigin, ConfigValue,
 };
 use crate::utils::files::get_bytes_from_os_str;
+use crate::utils::SliceExt;
 use format_bytes::{write_bytes, DisplayBytes};
 use std::collections::HashSet;
 use std::env;
@@ -339,6 +340,31 @@
 Ok(self.get_option(section, item)?.unwrap_or(false))
 }
 
+/// Returns the corresponding list-value in the config if found, or `None`.
+///
+/// This is appropriate for new configuration keys. The value syntax is
+/// **not** the same as most existing list-valued config, which has Python
+/// parsing implemented in `parselist()` in `mercurial/config.py`.
+/// Faithfully porting that parsing algorithm to Rust (including behavior
+/// that are arguably bugs) turned out to be non-trivial and hasn’t been
+/// completed as of this writing.
+///
+/// Instead, the "simple" syntax is: split on comma, then trim leading and
+/// trailing whitespace of each component. Quotes or backslashes are not
+/// interpreted in any way. Commas are mandatory between values. Values
+/// that contain a comma are not supported.
+pub fn get_simple_list(
+&self,
+section: &[u8],
+item: &[u8],
+) -> Option> {
+self.get(section, item).map(|value| {
+value
+.split(|&byte| byte == b',')
+.map(|component| component.trim())
+})
+}
+
 /// Returns the raw value bytes of the first one found, or `None`.
 pub fn get(&self, section: &[u8], item: &[u8]) -> Option<&[u8]> {
 self.get_inner(section, item)



To: SimonSapin, #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


D10187: tests: Enable rhg fallback to Python by default in tests

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

REVISION SUMMARY
  This premise of `run-tests.py --rhg`: fallback should make
  `rhg` behave the same as `hg`, except faster in some cases.
  To test run the whole test suite with installed `rhg` as `hg`
  and with fallback enabled.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  tests/run-tests.py
  tests/test-rhg.t

CHANGE DETAILS

diff --git a/tests/test-rhg.t b/tests/test-rhg.t
--- a/tests/test-rhg.t
+++ b/tests/test-rhg.t
@@ -11,8 +11,10 @@
   > fi
   > }
 
+  $ NO_FALLBACK="env RHG_ON_UNSUPPORTED=abort"
+
 Unimplemented command
-  $ rhg unimplemented-command
+  $ $NO_FALLBACK rhg unimplemented-command
   unsupported feature: error: Found argument 'unimplemented-command' which 
wasn't expected, or isn't valid in this context
   
   USAGE:
@@ -25,35 +27,35 @@
   [252]
 
 Finding root
-  $ rhg root
+  $ $NO_FALLBACK rhg root
   abort: no repository found in '$TESTTMP' (.hg not found)!
   [255]
 
   $ hg init repository
   $ cd repository
-  $ rhg root
+  $ $NO_FALLBACK rhg root
   $TESTTMP/repository
 
 Reading and setting configuration
   $ echo "[ui]" >> $HGRCPATH
   $ echo "username = user1" >> $HGRCPATH
-  $ rhg config ui.username
+  $ $NO_FALLBACK rhg config ui.username
   user1
   $ echo "[ui]" >> .hg/hgrc
   $ echo "username = user2" >> .hg/hgrc
-  $ rhg config ui.username
+  $ $NO_FALLBACK rhg config ui.username
   user2
-  $ rhg --config ui.username=user3 config ui.username
+  $ $NO_FALLBACK rhg --config ui.username=user3 config ui.username
   user3
 
 Unwritable file descriptor
-  $ rhg root > /dev/full
+  $ $NO_FALLBACK rhg root > /dev/full
   abort: No space left on device (os error 28)
   [255]
 
 Deleted repository
   $ rm -rf `pwd`
-  $ rhg root
+  $ $NO_FALLBACK rhg root
   abort: $ENOENT$: current directory
   [255]
 
@@ -68,7 +70,7 @@
   > hg commit -m "commit $i" -q
 
 Listing tracked files from root
-  $ rhg files
+  $ $NO_FALLBACK rhg files
   file1
   file2
   file3
@@ -76,13 +78,13 @@
 Listing tracked files from subdirectory
   $ mkdir -p path/to/directory
   $ cd path/to/directory
-  $ rhg files
+  $ $NO_FALLBACK rhg files
   ../../../file1
   ../../../file2
   ../../../file3
 
 Listing tracked files through broken pipe
-  $ rhg files | head -n 1
+  $ $NO_FALLBACK rhg files | head -n 1
   ../../../file1
 
 Debuging data in inline index
@@ -95,20 +97,20 @@
   >   hg add file-$i
   >   hg commit -m "Commit $i" -q
   > done
-  $ rhg debugdata -c 2
+  $ $NO_FALLBACK rhg debugdata -c 2
   8d0267cb034247ebfa5ee58ce59e22e57a492297
   test
   0 0
   file-3
   
   Commit 3 (no-eol)
-  $ rhg debugdata -m 2
+  $ $NO_FALLBACK rhg debugdata -m 2
   file-1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc)
   file-2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc)
   file-3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc)
 
 Debuging with full node id
-  $ rhg debugdata -c `hg log -r 0 -T '{node}'`
+  $ $NO_FALLBACK rhg debugdata -c `hg log -r 0 -T '{node}'`
   d1d1c679d3053e8926061b6f45ca52009f011e3f
   test
   0 0
@@ -124,16 +126,16 @@
   cf8b83f14ead62b374b6e91a0e9303b85dfd9ed7
   91c6f6e73e39318534dc415ea4e8a09c99cd74d6
   6ae9681c6d30389694d8701faf24b583cf3ccafe
-  $ rhg files -r cf8b83
+  $ $NO_FALLBACK rhg files -r cf8b83
   file-1
   file-2
   file-3
-  $ rhg cat -r cf8b83 file-2
+  $ $NO_FALLBACK rhg cat -r cf8b83 file-2
   2
-  $ rhg cat -r c file-2
+  $ $NO_FALLBACK rhg cat -r c file-2
   abort: ambiguous revision identifier c
   [255]
-  $ rhg cat -r d file-2
+  $ $NO_FALLBACK rhg cat -r d file-2
   2
 
 Cat files
@@ -144,37 +146,36 @@
   $ echo "original content" > original
   $ hg add original
   $ hg commit -m "add original" original
-  $ rhg cat -r 0 original
+  $ $NO_FALLBACK rhg cat -r 0 original
   original content
 Cat copied file should not display copy metadata
   $ hg copy original copy_of_original
   $ hg commit -m "add copy of original"
-  $ rhg cat -r 1 copy_of_original
+  $ $NO_FALLBACK rhg cat -r 1 copy_of_original
   original content
 
 Fallback to Python
-  $ rhg cat original
+  $ $NO_FALLBACK rhg cat original
   unsupported feature: `rhg cat` without `--rev` / `-r`
   [252]
-  $ FALLBACK="--config rhg.on-unsupported=fallback"
-  $ rhg cat original $FALLBACK
+  $ rhg cat original
   original content
 
-  $ rhg cat original $FALLBACK --config rhg.fallback-executable=false
+  $ rhg cat original --config rhg.fallback-executable=false
   [1]
 
-  $ rhg cat original $FALLBACK --config rhg.fallback-executable=hg-non-existent
+  $ rhg cat original --config rhg.fallback-executable=hg-non-existent
   tried to fall back to a 'hg-non-existent' sub-process but got error $ENOENT$
   unsupported feature: `rhg cat` without `--rev` / `-r`
   [252]
 
-  $ rhg cat original $FALLBACK --config rhg.fallback-executable="$RHG"
+  $ rhg cat original --config rhg.fallback-executable="$RHG"
   Block

D10186: rhg: Add environment variables for fallback configuration

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

REVISION SUMMARY
  For the `rust-tests.py --rhg` we want every `hg` command in tests
  to run `rhg` with fallback enabled, but other methods of setting
  configuration are limited or disruptive as discussed in code comment.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS

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
@@ -78,9 +78,27 @@
 if opt_rc_path.is_none() {
 config.add_system_config()?
 }
+
 config.add_for_environment_variable("EDITOR", b"ui", b"editor");
 config.add_for_environment_variable("VISUAL", b"ui", b"editor");
 config.add_for_environment_variable("PAGER", b"pager", b"pager");
+
+// These are set by `run-tests.py --rhg` to enable fallback for the
+// entire test suite. Alternatives would be setting configuration
+// through `$HGRCPATH` but some tests override that, or changing the
+// `hg` shell alias to include `--config` but that disrupts tests that
+// print command lines and check expected output.
+config.add_for_environment_variable(
+"RHG_ON_UNSUPPORTED",
+b"rhg",
+b"on-unsupported",
+);
+config.add_for_environment_variable(
+"RHG_FALLBACK_EXECUTABLE",
+b"rhg",
+b"fallback-executable",
+);
+
 // HGRCPATH replaces user config
 if opt_rc_path.is_none() {
 config.add_user_config()?



To: SimonSapin, #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


Failed pipeline for branch/default | mercurial-devel | 7cc7820f

2021-03-12 Thread Heptapod


Pipeline #19277 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: 7cc7820f ( 
https://foss.heptapod.net/octobus/mercurial-devel/-/commit/7cc7820fd6b96b9ec010abd42a435c9b720aceb2
 )
Commit Message: ci: hook network-io tests into the pipeline

Th...
Commit Author: Jörg Sonnenberger ( https://foss.heptapod.net/joerg )

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

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

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

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

Stage: tests
Name: test-py3-pure

-- 
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


D10185: black: merge config into main pyproject.toml now that we have it

2021-03-12 Thread durin42 (Augie Fackler)
durin42 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This means that naive contributors who just run `black` on a source file
  will get reasonable behavior as long as they have a recent black. Yay!
  
  This was previously D9834  but was 
rolled back due to test
  failures. nbjoerg thinks it's time to try again, so let's give it a
  shot.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  black.toml
  contrib/examples/fix.hgrc
  pyproject.toml
  tests/test-check-code.t
  tests/test-check-format.t

CHANGE DETAILS

diff --git a/tests/test-check-format.t b/tests/test-check-format.t
--- a/tests/test-check-format.t
+++ b/tests/test-check-format.t
@@ -1,5 +1,5 @@
 #require black test-repo
 
   $ cd $RUNTESTDIR/..
-  $ black --config=black.toml --check --diff `hg files 'set:(**.py + 
grep("^#!.*python")) - mercurial/thirdparty/**'`
+  $ black --check --diff `hg files 'set:(**.py + grep("^#!.*python")) - 
mercurial/thirdparty/**'`
 
diff --git a/tests/test-check-code.t b/tests/test-check-code.t
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -66,7 +66,6 @@
   COPYING
   Makefile
   README.rst
-  black.toml
   hg
   hgeditor
   hgweb.cgi
diff --git a/pyproject.toml b/pyproject.toml
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,3 +1,18 @@
 [build-system]
 requires = ["setuptools", "wheel"]
 build-backend = "setuptools.build_meta"
+
+[tool.black]
+line-length = 80
+exclude = '''
+build/
+| wheelhouse/
+| dist/
+| packages/
+| \.hg/
+| \.mypy_cache/
+| \.venv/
+| mercurial/thirdparty/
+'''
+skip-string-normalization = true
+quiet = true
diff --git a/contrib/examples/fix.hgrc b/contrib/examples/fix.hgrc
--- a/contrib/examples/fix.hgrc
+++ b/contrib/examples/fix.hgrc
@@ -5,7 +5,7 @@
 rustfmt:command = rustfmt +nightly
 rustfmt:pattern = set:"**.rs" - "mercurial/thirdparty/**"
 
-black:command = black --config=black.toml -
+black:command = black
 black:pattern = set:**.py - mercurial/thirdparty/**
 
 # Mercurial doesn't have any Go code, but if we did this is how we
diff --git a/black.toml b/black.toml
deleted file mode 100644
--- a/black.toml
+++ /dev/null
@@ -1,14 +0,0 @@
-[tool.black]
-line-length = 80
-exclude = '''
-build/
-| wheelhouse/
-| dist/
-| packages/
-| \.hg/
-| \.mypy_cache/
-| \.venv/
-| mercurial/thirdparty/
-'''
-skip-string-normalization = true
-quiet = true



To: durin42, #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


D10184: pyproject: add config file

2021-03-12 Thread durin42 (Augie Fackler)
durin42 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This will tell pip et al to call our setup.py for the majority of
  packaging concerns, but also gives us a place to put standard config
  stuff like black.
  
  This was previously D9833 , but was 
rolled back due to test
  breakage. nbjoerg thinks that breakage is now resolved, so we're
  trying again.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  pyproject.toml
  tests/test-check-code.t

CHANGE DETAILS

diff --git a/tests/test-check-code.t b/tests/test-check-code.t
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -70,6 +70,7 @@
   hg
   hgeditor
   hgweb.cgi
+  pyproject.toml
   rustfmt.toml
   setup.py
 
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,3 @@
+[build-system]
+requires = ["setuptools", "wheel"]
+build-backend = "setuptools.build_meta"



To: durin42, #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


[Bug 6497] New: RFE: hg which command, that identifies where a subcommand is defined

2021-03-12 Thread mercurial-bugs
https://bz.mercurial-scm.org/show_bug.cgi?id=6497

Bug ID: 6497
   Summary: RFE: hg which command, that identifies where a
subcommand is defined
   Product: Mercurial
   Version: unspecified
  Hardware: All
OS: All
Status: UNCONFIRMED
  Severity: feature
  Priority: wish
 Component: Mercurial
  Assignee: bugzi...@mercurial-scm.org
  Reporter: a...@anm.me
CC: mercurial-devel@mercurial-scm.org
Python Version: ---

This is a feature request for a "which" subcommand.

Like which in Unix-like environments, "hg which subcommand" should identify
where 'subcommand' was defined, be it an alias (including which config file
defined the alias, ideally with line number), an extension (possibly including
which config file declared its inclusion), or a core command.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D10178: patch: convert a UI message to bytes when editing a patch

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/patch.py

CHANGE DETAILS

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1210,7 +1210,7 @@
 # Patch comment based on the Git one (based on comment at end 
of
 # https://mercurial-scm.org/wiki/RecordExtension)
 phelp = b'---' + _(
-"""
+b"""
 To remove '-' lines, make them ' ' lines (context).
 To remove '+' lines, delete them.
 Lines starting with # will be removed from the patch.



To: mharbison72, #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


D10182: wireprotoserver: convert ErrorResponse to bytes

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Caught by pytype:
  
File "/mnt/c/Users/Matt/hg/mercurial/wireprotoserver.py", line 236, in 
handlewsgirequest: Function _bytestr.__init__ was called with the wrong 
arguments [wrong-arg-types]
 Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: mercurial.hgweb.common.ErrorResponse)
  The following methods aren't implemented on 
mercurial.hgweb.common.ErrorResponse:
  __iter__
File "/mnt/c/Users/Matt/hg/mercurial/wireprotoserver.py", line 239, in 
handlewsgirequest: Function _bytestr.__init__ was called with the wrong 
arguments [wrong-arg-types]
 Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: mercurial.hgweb.common.ErrorResponse)
  The following methods aren't implemented on 
mercurial.hgweb.common.ErrorResponse:
  __iter__
File "/mnt/c/Users/Matt/hg/mercurial/wireprotov2server.py", line 91, in 
handlehttpv2request: Function _bytestr.__init__ was called with the wrong 
arguments [wrong-arg-types]
 Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: mercurial.hgweb.common.ErrorResponse)
  The following methods aren't implemented on 
mercurial.hgweb.common.ErrorResponse:
  __iter__

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/wireprotoserver.py
  mercurial/wireprotov2server.py

CHANGE DETAILS

diff --git a/mercurial/wireprotov2server.py b/mercurial/wireprotov2server.py
--- a/mercurial/wireprotov2server.py
+++ b/mercurial/wireprotov2server.py
@@ -88,7 +88,9 @@
 try:
 checkperm(rctx, req, b'pull' if permission == b'ro' else b'push')
 except hgwebcommon.ErrorResponse as e:
-res.status = hgwebcommon.statusmessage(e.code, pycompat.bytestr(e))
+res.status = hgwebcommon.statusmessage(
+e.code, stringutil.forcebytestr(e)
+)
 for k, v in e.headers:
 res.headers[k] = v
 res.setbodybytes(b'permission denied')
diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py
--- a/mercurial/wireprotoserver.py
+++ b/mercurial/wireprotoserver.py
@@ -24,6 +24,7 @@
 from .utils import (
 cborutil,
 compression,
+stringutil,
 )
 
 stringio = util.stringio
@@ -233,10 +234,12 @@
 except hgwebcommon.ErrorResponse as e:
 for k, v in e.headers:
 res.headers[k] = v
-res.status = hgwebcommon.statusmessage(e.code, pycompat.bytestr(e))
+res.status = hgwebcommon.statusmessage(
+e.code, stringutil.forcebytestr(e)
+)
 # TODO This response body assumes the failed command was
 # "unbundle." That assumption is not always valid.
-res.setbodybytes(b'0\n%s\n' % pycompat.bytestr(e))
+res.setbodybytes(b'0\n%s\n' % stringutil.forcebytestr(e))
 
 return True
 



To: mharbison72, #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


D10179: subrepo: handle unexpected file types from git gracefully

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This was flagged by pytype because `tar.extractfile(...)` can return None if 
the
  entry is not a file or symlink.  I don't think that git supports other types,
  but better safe than sorry.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/subrepo.py

CHANGE DETAILS

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1876,7 +1876,12 @@
 if info.issym():
 data = info.linkname
 else:
-data = tar.extractfile(info).read()
+f = tar.extractfile(info)
+if f:
+data = f.read()
+else:
+self.ui.warn(_(b'skipping "%s" (unknown type)') % bname)
+continue
 archiver.addfile(prefix + bname, info.mode, info.issym(), data)
 total += 1
 progress.increment()



To: mharbison72, #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


D10183: typing: disable a module-attr warning in the worker module's py2 code

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/worker.py

CHANGE DETAILS

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -104,7 +104,9 @@
 else:
 
 def ismainthread():
+# pytype: disable=module-attr
 return isinstance(threading.current_thread(), threading._MainThread)
+# pytype: enable=module-attr
 
 def _blockingreader(wrapped):
 return wrapped



To: mharbison72, #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


D10173: grep: convert an exception to bytes for a warning message

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Caught by pytype:
  
File "/mnt/c/Users/Matt/hg/mercurial/commands.py", line 3457, in grep: 
Function _bytestr.__init__ was called with the wrong arguments [wrong-arg-types]
 Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: re.error)
  The following methods aren't implemented on re.error:
  __iter__

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3444,7 +3444,8 @@
 regexp = util.re.compile(pattern, reflags)
 except re.error as inst:
 ui.warn(
-_(b"grep: invalid match pattern: %s\n") % pycompat.bytestr(inst)
+_(b"grep: invalid match pattern: %s\n")
+% stringutil.forcebytestr(inst)
 )
 return 1
 sep, eol = b':', b'\n'



To: mharbison72, #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


D10181: verify: convert an exception to bytes before logging

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I'm not entirely sure why this code appears to be trying to convert twice, but
  it was flagged by pytype:
  
File "/mnt/c/Users/Matt/hg/mercurial/verify.py", line 84, in _exc: Function 
_bytestr.__init__ was called with the wrong arguments [wrong-arg-types]
 Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: Exception)
  The following methods aren't implemented on Exception:
  __iter__

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/verify.py

CHANGE DETAILS

diff --git a/mercurial/verify.py b/mercurial/verify.py
--- a/mercurial/verify.py
+++ b/mercurial/verify.py
@@ -14,6 +14,9 @@
 nullid,
 short,
 )
+from .utils import (
+stringutil,
+)
 
 from . import (
 error,
@@ -81,7 +84,7 @@
 
 def _exc(self, linkrev, msg, inst, filename=None):
 """record exception raised during the verify process"""
-fmsg = pycompat.bytestr(inst)
+fmsg = stringutil.forcebytestr(inst)
 if not fmsg:
 fmsg = pycompat.byterepr(inst)
 self._err(linkrev, b"%s: %s" % (msg, fmsg), filename)



To: mharbison72, #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


D10180: typing: add an assertion to the upgrade engine to help pytype

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/upgrade_utils/engine.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/engine.py 
b/mercurial/upgrade_utils/engine.py
--- a/mercurial/upgrade_utils/engine.py
+++ b/mercurial/upgrade_utils/engine.py
@@ -516,6 +516,7 @@
 # reference to its new location. So clean it up manually. Alternatively, we
 # could update srcrepo.svfs and other variables to point to the new
 # location. This is simpler.
+assert backupvfs is not None  # help pytype
 backupvfs.unlink(b'store/lock')
 
 return backuppath



To: mharbison72, #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


D10174: debug: convert a few exceptions to bytes before wrapping in another error

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Caught by pytype:
  
File "/mnt/c/Users/Matt/hg/mercurial/debugcommands.py", line 2118, in 
debugmanifestfulltextcache: Function Abort.__init__ was called with the wrong 
arguments [wrong-arg-types]
 Expected: (self, message: Union[bytearray, bytes, memoryview], ...)
  Actually passed: (self, message: mercurial.error.LookupError, ...)
File "/mnt/c/Users/Matt/hg/mercurial/debugcommands.py", line 2453, in 
debugobsolete: Function _bytestr.__init__ was called with the wrong arguments 
[wrong-arg-types]
 Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: ValueError)
  The following methods aren't implemented on ValueError:
  __iter__

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/debugcommands.py

CHANGE DETAILS

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2041,7 +2041,9 @@
 try:
 manifest = m[store.lookup(n)]
 except error.LookupError as e:
-raise error.Abort(e, hint=b"Check your manifest node id")
+raise error.Abort(
+bytes(e), hint=b"Check your manifest node id"
+)
 manifest.read()  # stores revisision in cache too
 return
 
@@ -2376,7 +2378,7 @@
 tr.close()
 except ValueError as exc:
 raise error.Abort(
-_(b'bad obsmarker input: %s') % pycompat.bytestr(exc)
+_(b'bad obsmarker input: %s') % 
stringutil.forcebytestr(exc)
 )
 finally:
 tr.release()



To: mharbison72, #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


D10177: merge: force an exception message to bytes before printing as a warning

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Caught by pytype:
  
File "/mnt/c/Users/Matt/hg/mercurial/merge.py", line 1346, in batchremove: 
Function _bytestr.__init__ was called with the wrong arguments [wrong-arg-types]
 Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: str)

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -20,6 +20,7 @@
 nullrev,
 )
 from .thirdparty import attr
+from .utils import stringutil
 from . import (
 copies,
 encoding,
@@ -1341,7 +1342,7 @@
 except OSError as inst:
 repo.ui.warn(
 _(b"update failed to remove %s: %s!\n")
-% (f, pycompat.bytestr(inst.strerror))
+% (f, stringutil.forcebytestr(inst.strerror))
 )
 if i == 100:
 yield i, f



To: mharbison72, #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


D10176: hg: convert an exception to bytes in the repo creation exception handler

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Caught by pytype:
  
File "/mnt/c/Users/Matt/hg/mercurial/hg.py", line 77, in _local: Function 
_bytestr.__init__ was called with the wrong arguments [wrong-arg-types]
 Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: Union[TypeError, ValueError])

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/hg.py

CHANGE DETAILS

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -41,7 +41,6 @@
 mergestate as mergestatemod,
 narrowspec,
 phases,
-pycompat,
 requirements,
 scmutil,
 sshpeer,
@@ -53,7 +52,11 @@
 verify as verifymod,
 vfs as vfsmod,
 )
-from .utils import hashutil
+from .utils import (
+hashutil,
+stringutil,
+)
+
 
 release = lock.release
 
@@ -74,7 +77,7 @@
 # Python 2 raises TypeError, Python 3 ValueError.
 except (TypeError, ValueError) as e:
 raise error.Abort(
-_(b'invalid path %s: %s') % (path, pycompat.bytestr(e))
+_(b'invalid path %s: %s') % (path, stringutil.forcebytestr(e))
 )
 except OSError:
 isfile = False



To: mharbison72, #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


D10172: morestatus: convert a UI message about merge conflicts to bytes

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/cmdutil.py

CHANGE DETAILS

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -869,7 +869,7 @@
 )
 msg = (
 _(
-'''Unresolved merge conflicts:
+b'''Unresolved merge conflicts:
 
 %s
 



To: mharbison72, #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


D10175: typing: add an assertion instead of blacklisting mercurial/extensions.py

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/extensions.py

CHANGE DETAILS

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -912,6 +912,7 @@
 exts = {}
 for ename, ext in extensions():
 doc = gettext(ext.__doc__) or _(b'(no help text available)')
+assert doc is not None  # help pytype
 if shortname:
 ename = ename.split(b'.')[-1]
 exts[ename] = doc.splitlines()[0].strip()



To: mharbison72, #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


D10171: changegroup: convert a warning message to bytes

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/changegroup.py

CHANGE DETAILS

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -797,7 +797,7 @@
 
 configtarget = repo.ui.config(b'devel', b'bundle.delta')
 if configtarget not in (b'', b'p1', b'full'):
-msg = _("""config "devel.bundle.delta" as unknown value: %s""")
+msg = _(b"""config "devel.bundle.delta" as unknown value: %s""")
 repo.ui.warn(msg % configtarget)
 
 deltamode = repository.CG_DELTAMODE_STD



To: mharbison72, #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


D10170: branchmap: force Exception to bytes before logging

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Here was an instance where `black` mangled the formatting so that `pytype`
  didn't recognize the suppression directive.  But it seems that the error was
  correct, and the code should follow other recent changes around exception
  conversion.
  
File "/mnt/c/Users/Matt/hg/mercurial/branchmap.py", line 303, in fromfile: 
Function _bytestr.__init__ was called with the wrong arguments [wrong-arg-types]
 Expected: (self, ints: Iterable[int])
  Actually passed: (self, ints: Exception)
  The following methods aren't implemented on Exception:
  __iter__

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/branchmap.py

CHANGE DETAILS

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -299,9 +299,7 @@
 msg
 % (
 _branchcachedesc(repo),
-pycompat.bytestr(
-inst
-),  # pytype: disable=wrong-arg-types
+stringutil.forcebytestr(inst),
 )
 )
 bcache = None



To: mharbison72, #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


D10168: mail: convert SMTPException to bytes before passing to error.Abort()

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Caught by pytype:
  
File "/mnt/c/Users/Matt/hg/mercurial/mail.py", line 168, in _smtp: Function 
Abort.__init__ was called with the wrong arguments [wrong-arg-types]
 Expected: (self, message: Union[bytearray, bytes, memoryview], ...)
  Actually passed: (self, message: smtplib.SMTPException)

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/mail.py

CHANGE DETAILS

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -165,7 +165,7 @@
 try:
 s.login(username, password)
 except smtplib.SMTPException as inst:
-raise error.Abort(inst)
+raise error.Abort(stringutil.forcebytestr(inst))
 
 def send(sender, recipients, msg):
 try:



To: mharbison72, #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


D10169: nodemap: convert error message to bytes

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/revlogutils/nodemap.py

CHANGE DETAILS

diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py
+++ b/mercurial/revlogutils/nodemap.py
@@ -557,7 +557,7 @@
 def parse_data(data):
 """parse parse nodemap data into a nodemap Trie"""
 if (len(data) % S_BLOCK.size) != 0:
-msg = "nodemap data size is not a multiple of block size (%d): %d"
+msg = b"nodemap data size is not a multiple of block size (%d): %d"
 raise error.Abort(msg % (S_BLOCK.size, len(data)))
 if not data:
 return Block(), None



To: mharbison72, #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


D10167: typing: switch an argument type to the generic form

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This fixes the following pytype complaint:
  
File "/mnt/c/Users/Matt/hg/mercurial/commands.py", line 4672, in log: 
Function mercurial.logcmdutil.parseopts was called with the wrong arguments 
[wrong-arg-types]
 Expected: (ui, pats: List[Union[bytearray, bytes, memoryview]], 
...)
  Actually passed: (ui, pats: tuple, ...)

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/logcmdutil.py

CHANGE DETAILS

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -51,6 +51,7 @@
 Dict,
 List,
 Optional,
+Sequence,
 Tuple,
 )
 
@@ -723,7 +724,7 @@
 
 
 def parseopts(ui, pats, opts):
-# type: (Any, List[bytes], Dict[bytes, Any]) -> walkopts
+# type: (Any, Sequence[bytes], Dict[bytes, Any]) -> walkopts
 """Parse log command options into walkopts
 
 The returned walkopts will be passed in to getrevs() or makewalker().



To: mharbison72, #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


D10166: typing: ensure that error.Abort is given bytes

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  There's a bunch more typing to be done here, but the list of things to fix is
  already long, and I know there are instances where this is being used
  incorrectly.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/error.py

CHANGE DETAILS

diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -18,6 +18,11 @@
 # Do not import anything but pycompat here, please
 from . import pycompat
 
+if pycompat.TYPE_CHECKING:
+from typing import (
+Optional,
+)
+
 
 def _tobytes(exc):
 """Byte-stringify exception in the same way as BaseException_str()"""
@@ -169,6 +174,7 @@
 """Raised if a command needs to print an error and exit."""
 
 def __init__(self, message, hint=None):
+# type: (bytes, Optional[bytes]) -> None
 self.message = message
 self.hint = hint
 # Pass the message into the Exception constructor to help extensions



To: mharbison72, #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


D10165: typing: fix a suppression directive that was mangled by black formatting

2021-03-12 Thread mharbison72 (Matt Harbison)
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It looks like black is moving comments needed by pytype out of position, and
  causing some things that should be disabled to be enforced anyway.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/posix.py

CHANGE DETAILS

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -321,9 +321,10 @@
 fullpath = os.path.join(cachedir, target)
 open(fullpath, b'w').close()
 except IOError as inst:
-if (
-inst[0] == errno.EACCES
-):  # pytype: disable=unsupported-operands
+# pytype: disable=unsupported-operands
+if inst[0] == errno.EACCES:
+# pytype: enable=unsupported-operands
+
 # If we can't write to cachedir, just pretend
 # that the fs is readonly and by association
 # that the fs won't support symlinks. This



To: mharbison72, #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


D10164: split: close transaction in the unlikely event of a conflict while rebasing

2021-03-12 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `hg split` *should* never result in conflicts, but in case there are
  bugs, we should at least commit the transaction so they can continue
  the rebase. One of our users ran into the regression fixed by
  D10120 . They fixed the conflict and 
the tried to continue the rebase,
  but it failed with "abort: cannot continue inconsistent rebase"
  because the rebase state referred to commits written in a transaction
  that was never committed.
  
  Side note: `hg split` should probably turn off copy tracing to reduce
  the impact of such bugs, and to speed it up as well. Copies made in
  the rebased commits should still be respected because `hg rebase`
  calls `copies.graftcopies()`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/split.py

CHANGE DETAILS

diff --git a/hgext/split.py b/hgext/split.py
--- a/hgext/split.py
+++ b/hgext/split.py
@@ -27,6 +27,7 @@
 revsetlang,
 rewriteutil,
 scmutil,
+util,
 )
 
 # allow people to use split without explicitly enabling rebase extension
@@ -69,57 +70,62 @@
 if opts.get(b'rev'):
 revlist.append(opts.get(b'rev'))
 revlist.extend(revs)
-with repo.wlock(), repo.lock(), repo.transaction(b'split') as tr:
-revs = scmutil.revrange(repo, revlist or [b'.'])
-if len(revs) > 1:
-raise error.InputError(_(b'cannot split multiple revisions'))
+with repo.wlock(), repo.lock():
+tr = repo.transaction(b'split')
+# If the rebase somehow runs into conflicts, make sure
+# we close the transaction so the user can continue it.
+with util.acceptintervention(tr):
+revs = scmutil.revrange(repo, revlist or [b'.'])
+if len(revs) > 1:
+raise error.InputError(_(b'cannot split multiple revisions'))
 
-rev = revs.first()
-ctx = repo[rev]
-# Handle nullid specially here (instead of leaving for precheck()
-# below) so we get a nicer message and error code.
-if rev is None or ctx.node() == nullid:
-ui.status(_(b'nothing to split\n'))
-return 1
-if ctx.node() is None:
-raise error.InputError(_(b'cannot split working directory'))
+rev = revs.first()
+ctx = repo[rev]
+# Handle nullid specially here (instead of leaving for precheck()
+# below) so we get a nicer message and error code.
+if rev is None or ctx.node() == nullid:
+ui.status(_(b'nothing to split\n'))
+return 1
+if ctx.node() is None:
+raise error.InputError(_(b'cannot split working directory'))
 
-if opts.get(b'rebase'):
-# Skip obsoleted descendants and their descendants so the rebase
-# won't cause conflicts for sure.
-descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev))
-torebase = list(
-repo.revs(
-b'%ld - (%ld & obsolete())::', descendants, descendants
+if opts.get(b'rebase'):
+# Skip obsoleted descendants and their descendants so the 
rebase
+# won't cause conflicts for sure.
+descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev))
+torebase = list(
+repo.revs(
+b'%ld - (%ld & obsolete())::', descendants, descendants
+)
 )
-)
-else:
-torebase = []
-rewriteutil.precheck(repo, [rev] + torebase, b'split')
+else:
+torebase = []
+rewriteutil.precheck(repo, [rev] + torebase, b'split')
 
-if len(ctx.parents()) > 1:
-raise error.InputError(_(b'cannot split a merge changeset'))
+if len(ctx.parents()) > 1:
+raise error.InputError(_(b'cannot split a merge changeset'))
 
-cmdutil.bailifchanged(repo)
+cmdutil.bailifchanged(repo)
 
-# Deactivate bookmark temporarily so it won't get moved unintentionally
-bname = repo._activebookmark
-if bname and repo._bookmarks[bname] != ctx.node():
-bookmarks.deactivate(repo)
+# Deactivate bookmark temporarily so it won't get moved
+# unintentionally
+bname = repo._activebookmark
+if bname and repo._bookmarks[bname] != ctx.node():
+bookmarks.deactivate(repo)
 
-wnode = repo[b'.'].node()
-top = None
-try:
-top = dosplit(ui, repo, tr, ctx, opts)
-finally:
-# top is None: split failed, need update --clean recovery.
-# wnode == ctx.node(): wnode split, no need to update.