D11613: rhg: refactor function to relativize paths in utils

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

REVISION SUMMARY
  Commands like `files`, `status` supports printing relative paths. Hence we 
need
  to re-use this code in other places too. So let's take this out from `rhg 
files`
  into a utility function.
  
  Next patch will make `rhg status` use it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/commands/files.rs
  rust/rhg/src/main.rs
  rust/rhg/src/utils/path_utils.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/utils/path_utils.rs b/rust/rhg/src/utils/path_utils.rs
new file mode 100644
--- /dev/null
+++ b/rust/rhg/src/utils/path_utils.rs
@@ -0,0 +1,48 @@
+// path utils module
+//
+// This software may be used and distributed according to the terms of the
+// GNU General Public License version 2 or any later version.
+
+use crate::error::CommandError;
+use crate::ui::UiError;
+use hg::repo::Repo;
+use hg::utils::current_dir;
+use hg::utils::files::{get_bytes_from_path, relativize_path};
+use hg::utils::hg_path::HgPath;
+use hg::utils::hg_path::HgPathBuf;
+use std::borrow::Cow;
+
+pub fn relativize_paths(
+repo: ,
+paths: impl IntoIterator>,
+mut callback: impl FnMut(Cow<[u8]>) -> Result<(), UiError>,
+) -> Result<(), CommandError> {
+let cwd = current_dir()?;
+let repo_root = repo.working_directory_path();
+let repo_root = cwd.join(repo_root); // Make it absolute
+let repo_root_hgpath =
+HgPathBuf::from(get_bytes_from_path(repo_root.to_owned()));
+let outside_repo: bool;
+let cwd_hgpath: HgPathBuf;
+
+if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(_root) {
+// The current directory is inside the repo, so we can work with
+// relative paths
+outside_repo = false;
+cwd_hgpath =
+HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo));
+} else {
+outside_repo = true;
+cwd_hgpath = HgPathBuf::from(get_bytes_from_path(cwd));
+}
+
+for file in paths {
+if outside_repo {
+let file = repo_root_hgpath.join(file.as_ref());
+callback(relativize_path(, _hgpath))?;
+} else {
+callback(relativize_path(file.as_ref(), _hgpath))?;
+}
+}
+Ok(())
+}
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
@@ -17,6 +17,9 @@
 mod blackbox;
 mod error;
 mod ui;
+pub mod utils {
+pub mod path_utils;
+}
 use error::CommandError;
 
 fn main_with_result(
diff --git a/rust/rhg/src/commands/files.rs b/rust/rhg/src/commands/files.rs
--- a/rust/rhg/src/commands/files.rs
+++ b/rust/rhg/src/commands/files.rs
@@ -1,12 +1,13 @@
 use crate::error::CommandError;
 use crate::ui::Ui;
+use crate::ui::UiError;
+use crate::utils::path_utils::relativize_paths;
 use clap::Arg;
 use hg::operations::list_rev_tracked_files;
 use hg::operations::Dirstate;
 use hg::repo::Repo;
-use hg::utils::current_dir;
-use hg::utils::files::{get_bytes_from_path, relativize_path};
-use hg::utils::hg_path::{HgPath, HgPathBuf};
+use hg::utils::hg_path::HgPath;
+use std::borrow::Cow;
 
 pub const HELP_TEXT:  = "
 List tracked files.
@@ -54,34 +55,13 @@
 files: impl IntoIterator,
 ) -> Result<(), CommandError> {
 let mut stdout = ui.stdout_buffer();
-
-let cwd = current_dir()?;
-let working_directory = repo.working_directory_path();
-let working_directory = cwd.join(working_directory); // Make it absolute
+let mut any = false;
 
-let mut any = false;
-if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(_directory) {
-// The current directory is inside the repo, so we can work with
-// relative paths
-let cwd = HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo));
-for file in files {
-any = true;
-stdout.write_all(relativize_path(, ).as_ref())?;
-stdout.write_all(b"\n")?;
-}
-} else {
-let working_directory =
-HgPathBuf::from(get_bytes_from_path(working_directory));
-let cwd = HgPathBuf::from(get_bytes_from_path(cwd));
-for file in files {
-any = true;
-// Absolute path in the filesystem
-let file = working_directory.join(file);
-stdout.write_all(relativize_path(, ).as_ref())?;
-stdout.write_all(b"\n")?;
-}
-}
-
+relativize_paths(repo, files, |path: Cow<[u8]>| -> Result<(), UiError> {
+any = true;
+stdout.write_all(path.as_ref())?;
+stdout.write_all(b"\n")
+})?;
 stdout.flush()?;
 if any {
 Ok(())



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


D11614: rhg: add relative paths support in `rhg status`

2021-10-05 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/D11614

AFFECTED FILES
  rust/rhg/src/commands/status.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs
--- a/rust/rhg/src/commands/status.rs
+++ b/rust/rhg/src/commands/status.rs
@@ -6,9 +6,11 @@
 // GNU General Public License version 2 or any later version.
 
 use crate::error::CommandError;
-use crate::ui::Ui;
+use crate::ui::{Ui, UiError};
+use crate::utils::path_utils::relativize_paths;
 use clap::{Arg, SubCommand};
 use hg;
+use hg::config::Config;
 use hg::errors::HgError;
 use hg::manifest::Manifest;
 use hg::matchers::AlwaysMatcher;
@@ -16,6 +18,7 @@
 use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
 use hg::{HgPathCow, StatusOptions};
 use log::{info, warn};
+use std::borrow::Cow;
 
 pub const HELP_TEXT:  = "
 Show changed files in the working directory
@@ -146,6 +149,7 @@
 }
 
 let ui = invocation.ui;
+let config = invocation.config;
 let args = invocation.subcommand_args;
 let display_states = if args.is_present("all") {
 // TODO when implementing `--quiet`: it excludes clean files
@@ -225,25 +229,25 @@
 }
 }
 if display_states.modified {
-display_status_paths(ui,  ds_status.modified, b"M")?;
+display_status_paths(ui, repo, config,  ds_status.modified, b"M")?;
 }
 if display_states.added {
-display_status_paths(ui,  ds_status.added, b"A")?;
+display_status_paths(ui, repo, config,  ds_status.added, b"A")?;
 }
 if display_states.removed {
-display_status_paths(ui,  ds_status.removed, b"R")?;
+display_status_paths(ui, repo, config,  ds_status.removed, b"R")?;
 }
 if display_states.deleted {
-display_status_paths(ui,  ds_status.deleted, b"!")?;
+display_status_paths(ui, repo, config,  ds_status.deleted, b"!")?;
 }
 if display_states.unknown {
-display_status_paths(ui,  ds_status.unknown, b"?")?;
+display_status_paths(ui, repo, config,  ds_status.unknown, b"?")?;
 }
 if display_states.ignored {
-display_status_paths(ui,  ds_status.ignored, b"I")?;
+display_status_paths(ui, repo, config,  ds_status.ignored, b"I")?;
 }
 if display_states.clean {
-display_status_paths(ui,  ds_status.clean, b"C")?;
+display_status_paths(ui, repo, config,  ds_status.clean, b"C")?;
 }
 Ok(())
 }
@@ -252,16 +256,35 @@
 // harcode HgPathBuf, but probably not really useful at this point
 fn display_status_paths(
 ui: ,
+repo: ,
+config: ,
 paths:  [HgPathCow],
 status_prefix: &[u8],
 ) -> Result<(), CommandError> {
 paths.sort_unstable();
-for path in paths {
-// Same TODO as in commands::root
-let bytes: &[u8] = path.as_bytes();
-// TODO optim, probably lots of unneeded copies here, especially
-// if out stream is buffered
-ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?;
+let mut relative: bool =
+config.get_bool(b"ui", b"relative-paths").unwrap_or(false);
+relative = config
+.get_bool(b"commands", b"status.relative")
+.unwrap_or(relative);
+if relative {
+relativize_paths(
+repo,
+paths,
+|path: Cow<[u8]>| -> Result<(), UiError> {
+ui.write_stdout(
+&[status_prefix, b" ", path.as_ref(), b"\n"].concat(),
+)
+},
+)?;
+} else {
+for path in paths {
+// Same TODO as in commands::root
+let bytes: &[u8] = path.as_bytes();
+// TODO optim, probably lots of unneeded copies here, especially
+// if out stream is buffered
+ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?;
+}
 }
 Ok(())
 }



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


D11610: largefiles: pass current transaction to `lfdirstate.write()`

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

REVISION SUMMARY
  Right now, the largefile dirstate is not included in transaction which makes
  things complex. Next patch will add code to do so, so let's make it mandatory 
to
  pass current transaction and pass from all existing callers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/largefiles/lfcommands.py
  hgext/largefiles/lfutil.py
  hgext/largefiles/overrides.py
  hgext/largefiles/reposetup.py

CHANGE DETAILS

diff --git a/hgext/largefiles/reposetup.py b/hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py
+++ b/hgext/largefiles/reposetup.py
@@ -310,7 +310,7 @@
 ]
 
 if gotlock:
-lfdirstate.write()
+lfdirstate.write(self.currenttransaction())
 
 self.lfstatus = True
 return scmutil.status(*result)
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -151,7 +151,7 @@
 )
 standins.append(standinname)
 lfdirstate.set_tracked(f)
-lfdirstate.write()
+lfdirstate.write(repo.currenttransaction())
 bad += [
 lfutil.splitstandin(f)
 for f in repo[None].add(standins)
@@ -229,7 +229,7 @@
 for f in remove:
 lfdirstate.set_untracked(lfutil.splitstandin(f))
 
-lfdirstate.write()
+lfdirstate.write(repo.currenttransaction())
 
 return result
 
@@ -659,7 +659,7 @@
 )
 # make sure lfile doesn't get synclfdirstate'd as normal
 lfdirstate.update_file(lfile, p1_tracked=False, 
wc_tracked=True)
-lfdirstate.write()
+lfdirstate.write(repo.currenttransaction())
 
 return orig(repo, actions, branchmerge, getfiledata)
 
@@ -864,7 +864,7 @@
 util.copyfile(repo.wjoin(srclfile), repo.wjoin(destlfile))
 
 lfdirstate.set_tracked(destlfile)
-lfdirstate.write()
+lfdirstate.write(repo.currenttransaction())
 except error.Abort as e:
 if e.message != _(b'no files to copy'):
 raise e
@@ -896,7 +896,7 @@
 with repo.wlock():
 lfdirstate = lfutil.openlfdirstate(ui, repo)
 s = lfutil.lfdirstatestatus(lfdirstate, repo)
-lfdirstate.write()
+lfdirstate.write(repo.currenttransaction())
 for lfile in s.modified:
 lfutil.updatestandin(repo, lfile, lfutil.standin(lfile))
 for lfile in s.deleted:
@@ -1383,7 +1383,7 @@
 lfdirstate = lfutil.openlfdirstate(ui, repo)
 for f in forget:
 lfdirstate.set_untracked(f)
-lfdirstate.write()
+lfdirstate.write(repo.currenttransaction())
 standins = [lfutil.standin(f) for f in forget]
 for f in standins:
 repo.wvfs.unlinkpath(f, ignoremissing=True)
@@ -1792,7 +1792,7 @@
 # interrupted before largefiles and lfdirstate are synchronized
 for lfile in oldclean:
 lfdirstate.set_possibly_dirty(lfile)
-lfdirstate.write()
+lfdirstate.write(repo.currenttransaction())
 
 oldstandins = lfutil.getstandinsstate(repo)
 wc = kwargs.get('wc')
@@ -1812,7 +1812,7 @@
 # all the ones that didn't change as clean
 for lfile in oldclean.difference(filelist):
 lfdirstate.update_file(lfile, p1_tracked=True, wc_tracked=True)
-lfdirstate.write()
+lfdirstate.write(repo.currenttransaction())
 
 if branchmerge or force or partial:
 filelist.extend(s.deleted + s.removed)
diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -191,7 +191,7 @@
 def _ignore(self, f):
 return False
 
-def write(self, tr=False):
+def write(self, tr):
 # (1) disable PENDING mode always
 # (lfdirstate isn't yet managed as a part of the transaction)
 # (2) avoid develwarn 'use dirstate.write with '
@@ -588,7 +588,7 @@
 lfile = splitstandin(f)
 if lfile is not None:
 synclfdirstate(repo, lfdirstate, lfile, False)
-lfdirstate.write()
+lfdirstate.write(repo.currenttransaction())
 
 # As part of committing, copy all of the largefiles into the cache.
 #
diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -569,7 +569,7 @@
 removed += 1
 
 # largefile processing might be slow and be interrupted - be prepared
-lfdirstate.write()
+

D11612: largefiles: partially undo 61e526585b20e2ff15f19497d0451d18fea02db8 and child

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

REVISION SUMMARY
  Since the largefiles dirstate is now part of transaction, we get rid of this
  temporary fix which lived for ~7 years.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/largefiles/overrides.py

CHANGE DETAILS

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -1636,18 +1636,6 @@
 for standin in orphans:
 repo.wvfs.unlinkpath(standin, ignoremissing=True)
 
-lfdirstate = lfutil.openlfdirstate(ui, repo)
-with lfdirstate.parentchange():
-orphans = set(lfdirstate)
-lfiles = lfutil.listlfiles(repo)
-for file in lfiles:
-lfutil.synclfdirstate(repo, lfdirstate, file, True)
-orphans.discard(file)
-for lfile in orphans:
-lfdirstate.update_file(
-lfile, p1_tracked=False, wc_tracked=False
-)
-lfdirstate.write()
 return result
 
 



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


D11611: largefiles: add tr backup for largefilesdirstate

2021-10-05 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 automatically restoring the largefilesdirstate if a
  transaction is rolled back.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/largefiles/lfutil.py
  tests/test-largefiles-cache.t

CHANGE DETAILS

diff --git a/tests/test-largefiles-cache.t b/tests/test-largefiles-cache.t
--- a/tests/test-largefiles-cache.t
+++ b/tests/test-largefiles-cache.t
@@ -185,10 +185,12 @@
 
   $ find share_dst/.hg/largefiles/* | sort
   share_dst/.hg/largefiles/dirstate
+  share_dst/.hg/largefiles/undo.backup.dirstate
 
   $ find src/.hg/largefiles/* | egrep "(dirstate|$hash)" | sort
   src/.hg/largefiles/dirstate
   src/.hg/largefiles/e2fb5f2139d086ded2cb600d5a91a196e76bf020
+  src/.hg/largefiles/undo.backup.dirstate
 
 Verify that backwards compatibility is maintained for old storage layout
   $ mv src/.hg/largefiles/$hash share_dst/.hg/largefiles
diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -195,6 +195,8 @@
 # (1) disable PENDING mode always
 # (lfdirstate isn't yet managed as a part of the transaction)
 # (2) avoid develwarn 'use dirstate.write with '
+if tr:
+tr.addbackup(b'largefiles/dirstate', location=b'plain')
 super(largefilesdirstate, self).write(None)
 
 



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


D10913: rhg: refactor relative path resolution in utility fn

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

REVISION SUMMARY
  The same code is being used in `rhg files` and `rhg status` and I expect it to
  be used at more places in upcoming future. So let's have a utility function 
for
  that.
  
  `rhg files` still doesn't use this codepath but will start using in upcoming
  patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/commands/status.rs
  rust/rhg/src/main.rs
  rust/rhg/src/utils/path_utils.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/utils/path_utils.rs b/rust/rhg/src/utils/path_utils.rs
new file mode 100644
--- /dev/null
+++ b/rust/rhg/src/utils/path_utils.rs
@@ -0,0 +1,48 @@
+// path utils module
+//
+// This software may be used and distributed according to the terms of the
+// GNU General Public License version 2 or any later version.
+
+use crate::error::CommandError;
+use crate::ui::UiError;
+use hg::repo::Repo;
+use hg::utils::current_dir;
+use hg::utils::files::{get_bytes_from_path, relativize_path};
+use hg::utils::hg_path::HgPathBuf;
+use hg::HgPathCow;
+use std::borrow::Cow;
+
+pub fn relativize_paths(
+repo: ,
+paths: &[HgPathCow],
+callback:  Fn(Cow<[u8]>) -> Result<(), UiError>,
+) -> Result<(), CommandError> {
+let cwd = current_dir()?;
+let working_directory = repo.working_directory_path();
+let working_directory = cwd.join(working_directory); // Make it absolute
+let working_directory_hgpath =
+HgPathBuf::from(get_bytes_from_path(working_directory.to_owned()));
+let outside_repo: bool;
+let cwd_hgpath: HgPathBuf;
+
+if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(_directory) {
+// The current directory is inside the repo, so we can work with
+// relative paths
+outside_repo = false;
+cwd_hgpath =
+HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo));
+} else {
+outside_repo = true;
+cwd_hgpath = HgPathBuf::from(get_bytes_from_path(cwd));
+}
+
+for file in paths {
+if outside_repo {
+let file = working_directory_hgpath.join(file);
+callback(relativize_path(, _hgpath))?;
+} else {
+callback(relativize_path(file, _hgpath))?;
+}
+}
+Ok(())
+}
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
@@ -17,6 +17,9 @@
 mod blackbox;
 mod error;
 mod ui;
+pub mod utils {
+pub mod path_utils;
+}
 use error::CommandError;
 
 fn main_with_result(
diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs
--- a/rust/rhg/src/commands/status.rs
+++ b/rust/rhg/src/commands/status.rs
@@ -7,6 +7,7 @@
 
 use crate::error::CommandError;
 use crate::ui::{Ui, UiError};
+use crate::utils::path_utils::relativize_paths;
 use clap::{Arg, SubCommand};
 use hg;
 use hg::config::Config;
@@ -17,13 +18,11 @@
 use hg::operations::cat;
 use hg::repo::Repo;
 use hg::revlog::node::Node;
-use hg::utils::current_dir;
-use hg::utils::files::{get_bytes_from_path, relativize_path};
-use hg::utils::hg_path::HgPathBuf;
 use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
 use hg::StatusError;
 use hg::{HgPathCow, StatusOptions};
 use log::{info, warn};
+use std::borrow::Cow;
 use std::convert::TryInto;
 use std::fs;
 use std::io::BufReader;
@@ -291,46 +290,12 @@
 .get_bool(b"commands", b"status.relative")
 .unwrap_or(relative);
 if relative && !ui.plain() {
-let cwd = current_dir()?;
-let working_directory = repo.working_directory_path();
-let working_directory = cwd.join(working_directory); // Make it 
absolute
-let working_directory_hgpath =
-HgPathBuf::from(get_bytes_from_path(working_directory.to_owned()));
-let outside_repo: bool;
-let cwd_hgpath: HgPathBuf;
-
-if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(_directory)
-{
-// The current directory is inside the repo, so we can work with
-// relative paths
-outside_repo = false;
-cwd_hgpath =
-HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo));
-} else {
-outside_repo = true;
-cwd_hgpath = HgPathBuf::from(get_bytes_from_path(cwd));
-}
-
-let print_path = |path: | -> Result<(), UiError> {
+let print_path = |path: Cow<[u8]>| -> Result<(), UiError> {
 ui.write_stdout(
-&[
-status_prefix,
-b" ",
-relativize_path(path, _hgpath).as_ref(),
-b"\n",
-]
-.concat(),
+&[status_prefix, b" ", path.as_ref(), b"\n"].concat(),
 )
 };
-
-for file in paths {
-if outside_repo {
-

D10912: rhg: add ui.plain() and check it before showing relative paths in status

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

REVISION SUMMARY
  Adds a very basic replica of `ui.plain()`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/commands/status.rs
  rust/rhg/src/ui.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/ui.rs b/rust/rhg/src/ui.rs
--- a/rust/rhg/src/ui.rs
+++ b/rust/rhg/src/ui.rs
@@ -1,5 +1,6 @@
 use format_bytes::format_bytes;
 use std::borrow::Cow;
+use std::env;
 use std::io;
 use std::io::{ErrorKind, Write};
 
@@ -49,6 +50,28 @@
 
 stderr.flush().or_else(handle_stderr_error)
 }
+
+/// is plain mode active
+///
+/// Plain mode means that all configuration variables which affect
+/// the behavior and output of Mercurial should be
+/// ignored. Additionally, the output should be stable,
+/// reproducible and suitable for use in scripts or applications.
+///
+/// The only way to trigger plain mode is by setting either the
+/// `HGPLAIN' or `HGPLAINEXCEPT' environment variables.
+///
+/// The return value can either be
+/// - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT
+/// - False if feature is disabled by default and not included in HGPLAIN
+/// - True otherwise
+pub fn plain() -> bool {
+// TODO: add support for HGPLAINEXCEPT
+match env::var("HGPLAIN") {
+Ok(_) => true,
+Err(_) => false,
+}
+}
 }
 
 /// A buffered stdout writer for faster batch printing operations.
diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs
--- a/rust/rhg/src/commands/status.rs
+++ b/rust/rhg/src/commands/status.rs
@@ -290,7 +290,7 @@
 relative = config
 .get_bool(b"commands", b"status.relative")
 .unwrap_or(relative);
-if relative {
+if relative && !ui.plain() {
 let cwd = current_dir()?;
 let working_directory = repo.working_directory_path();
 let working_directory = cwd.join(working_directory); // Make it 
absolute



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


D10911: rhg: add relative path output functionality in status command

2021-06-25 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/D10911

AFFECTED FILES
  rust/rhg/src/commands/status.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs
--- a/rust/rhg/src/commands/status.rs
+++ b/rust/rhg/src/commands/status.rs
@@ -6,9 +6,10 @@
 // GNU General Public License version 2 or any later version.
 
 use crate::error::CommandError;
-use crate::ui::Ui;
+use crate::ui::{Ui, UiError};
 use clap::{Arg, SubCommand};
 use hg;
+use hg::config::Config;
 use hg::dirstate_tree::dirstate_map::DirstateMap;
 use hg::errors::HgResultExt;
 use hg::errors::IoResultExt;
@@ -16,6 +17,9 @@
 use hg::operations::cat;
 use hg::repo::Repo;
 use hg::revlog::node::Node;
+use hg::utils::current_dir;
+use hg::utils::files::{get_bytes_from_path, relativize_path};
+use hg::utils::hg_path::HgPathBuf;
 use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
 use hg::StatusError;
 use hg::{HgPathCow, StatusOptions};
@@ -154,6 +158,7 @@
 }
 
 let ui = invocation.ui;
+let config = invocation.config;
 let args = invocation.subcommand_args;
 let display_states = if args.is_present("all") {
 // TODO when implementing `--quiet`: it excludes clean files
@@ -247,25 +252,25 @@
 }
 }
 if display_states.modified {
-display_status_paths(ui,  ds_status.modified, b"M")?;
+display_status_paths(ui, repo, config,  ds_status.modified, b"M")?;
 }
 if display_states.added {
-display_status_paths(ui,  ds_status.added, b"A")?;
+display_status_paths(ui, repo, config,  ds_status.added, b"A")?;
 }
 if display_states.removed {
-display_status_paths(ui,  ds_status.removed, b"R")?;
+display_status_paths(ui, repo, config,  ds_status.removed, b"R")?;
 }
 if display_states.deleted {
-display_status_paths(ui,  ds_status.deleted, b"!")?;
+display_status_paths(ui, repo, config,  ds_status.deleted, b"!")?;
 }
 if display_states.unknown {
-display_status_paths(ui,  ds_status.unknown, b"?")?;
+display_status_paths(ui, repo, config,  ds_status.unknown, b"?")?;
 }
 if display_states.ignored {
-display_status_paths(ui,  ds_status.ignored, b"I")?;
+display_status_paths(ui, repo, config,  ds_status.ignored, b"I")?;
 }
 if display_states.clean {
-display_status_paths(ui,  ds_status.clean, b"C")?;
+display_status_paths(ui, repo, config,  ds_status.clean, b"C")?;
 }
 Ok(())
 }
@@ -274,16 +279,66 @@
 // harcode HgPathBuf, but probably not really useful at this point
 fn display_status_paths(
 ui: ,
+repo: ,
+config: ,
 paths:  [HgPathCow],
 status_prefix: &[u8],
 ) -> Result<(), CommandError> {
 paths.sort_unstable();
-for path in paths {
-// Same TODO as in commands::root
-let bytes: &[u8] = path.as_bytes();
-// TODO optim, probably lots of unneeded copies here, especially
-// if out stream is buffered
-ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?;
+let mut relative: bool =
+config.get_bool(b"ui", b"relative-paths").unwrap_or(false);
+relative = config
+.get_bool(b"commands", b"status.relative")
+.unwrap_or(relative);
+if relative {
+let cwd = current_dir()?;
+let working_directory = repo.working_directory_path();
+let working_directory = cwd.join(working_directory); // Make it 
absolute
+let working_directory_hgpath =
+HgPathBuf::from(get_bytes_from_path(working_directory.to_owned()));
+let outside_repo: bool;
+let cwd_hgpath: HgPathBuf;
+
+if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(_directory)
+{
+// The current directory is inside the repo, so we can work with
+// relative paths
+outside_repo = false;
+cwd_hgpath =
+HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo));
+} else {
+outside_repo = true;
+cwd_hgpath = HgPathBuf::from(get_bytes_from_path(cwd));
+}
+
+let print_path = |path: | -> Result<(), UiError> {
+ui.write_stdout(
+&[
+status_prefix,
+b" ",
+relativize_path(path, _hgpath).as_ref(),
+b"\n",
+]
+.concat(),
+)
+};
+
+for file in paths {
+if outside_repo {
+let file = working_directory_hgpath.join(file);
+print_path()?;
+} else {
+print_path(file)?;
+}
+}
+} else {
+for path in paths {
+// Same TODO as in commands::root
+let bytes: 

D10910: rhg: refactor code a little around printing of relative paths

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

REVISION SUMMARY
  It's easier to understand when setup to compute relative path is decoupled 
from
  actual iteration over list of files.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/commands/files.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/commands/files.rs b/rust/rhg/src/commands/files.rs
--- a/rust/rhg/src/commands/files.rs
+++ b/rust/rhg/src/commands/files.rs
@@ -58,28 +58,32 @@
 let cwd = current_dir()?;
 let working_directory = repo.working_directory_path();
 let working_directory = cwd.join(working_directory); // Make it absolute
+let working_directory_hgpath =
+HgPathBuf::from(get_bytes_from_path(working_directory.to_owned()));
 
-let mut any = false;
+let outside_repo: bool;
+let cwd_hgpath: HgPathBuf;
 if let Ok(cwd_relative_to_repo) = cwd.strip_prefix(_directory) {
 // The current directory is inside the repo, so we can work with
 // relative paths
-let cwd = HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo));
-for file in files {
-any = true;
-stdout.write_all(relativize_path(, ).as_ref())?;
-stdout.write_all(b"\n")?;
-}
+outside_repo = false;
+cwd_hgpath =
+HgPathBuf::from(get_bytes_from_path(cwd_relative_to_repo));
 } else {
-let working_directory =
-HgPathBuf::from(get_bytes_from_path(working_directory));
-let cwd = HgPathBuf::from(get_bytes_from_path(cwd));
-for file in files {
-any = true;
-// Absolute path in the filesystem
-let file = working_directory.join(file);
-stdout.write_all(relativize_path(, ).as_ref())?;
-stdout.write_all(b"\n")?;
+outside_repo = true;
+cwd_hgpath = HgPathBuf::from(get_bytes_from_path(cwd));
+}
+
+let mut any = false;
+for file in files {
+any = true;
+if outside_repo {
+let file = working_directory_hgpath.join(file);
+stdout.write_all(relativize_path(, _hgpath).as_ref())?;
+} else {
+stdout.write_all(relativize_path(, _hgpath).as_ref())?;
 }
+stdout.write_all(b"\n")?;
 }
 
 stdout.flush()?;



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


D10906: rhg: fallback if tweakdefaults or statuscopies is enabled with status

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

REVISION SUMMARY
  `rhg status` is experimental right now and does not support all 
functionalities.
  While the long term target is to implement them, for now we add a fallback to
  have all tests pass with `rhg status` enabled.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/commands/status.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs
--- a/rust/rhg/src/commands/status.rs
+++ b/rust/rhg/src/commands/status.rs
@@ -141,6 +141,30 @@
 ));
 }
 
+// TODO: lift this limitation
+match invocation.config.get_bool(b"ui", b"tweakdefaults") {
+Ok(val) => {
+if val {
+return Err(CommandError::unsupported(
+"ui.tweakdefaults is not yet supported with rhg status",
+));
+}
+}
+Err(_) => {}
+};
+
+// TODO: lift this limitation
+match invocation.config.get_bool(b"ui", b"statuscopies") {
+Ok(val) => {
+if val {
+return Err(CommandError::unsupported(
+"ui.statuscopies is not yet supported with rhg status",
+));
+}
+}
+Err(_) => {}
+};
+
 let ui = invocation.ui;
 let args = invocation.subcommand_args;
 let display_states = if args.is_present("all") {



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


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


D10767: rhg: look for repository in ancestors also instead of cwd only

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

REVISION SUMMARY
  Last patch introduced config reading at startup to parse value of 
`--repository`
  flag. However, that patch only tried to check for current repository at 
current
  working directory and not it's ancestors. This patch fixes that.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/repo.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
@@ -174,8 +174,7 @@
 } else {
 let local_config = {
 if std::env::var_os("HGRCSKIPREPO").is_none() {
-let current_dir = hg::utils::current_dir();
-if let Ok(current_dir_path) = current_dir {
+if let Ok(current_dir_path) = Repo::try_find_repo_root() {
 let config_files = vec![
 ConfigSource::AbsPath(
 current_dir_path.join(".hg/hgrc"),
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
@@ -43,6 +43,22 @@
 }
 
 impl Repo {
+/// tries to find a repository in current working directory and returns its
+/// root path
+pub fn try_find_repo_root() -> Result {
+let current_directory = crate::utils::current_dir()?;
+// ancestors() is inclusive: it first yields `current_directory`
+// as-is.
+for ancestor in current_directory.ancestors() {
+if ancestor.join(".hg").is_dir() {
+return Ok(ancestor.to_path_buf());
+}
+}
+return Err(RepoError::NotFound {
+at: current_directory,
+});
+}
+
 /// Find a repository, either at the given path (which must contain a `.hg`
 /// sub-directory) or by searching the current directory and its
 /// ancestors.
@@ -66,17 +82,12 @@
 })
 }
 } else {
-let current_directory = crate::utils::current_dir()?;
-// ancestors() is inclusive: it first yields `current_directory`
-// as-is.
-for ancestor in current_directory.ancestors() {
-if ancestor.join(".hg").is_dir() {
-return Self::new_at_path(ancestor.to_owned(), config);
-}
+let repo_root = Self::try_find_repo_root();
+if repo_root.is_ok() {
+Self::new_at_path(repo_root.unwrap(), config)
+} else {
+Err(repo_root.unwrap_err())
 }
-Err(RepoError::NotFound {
-at: current_directory,
-})
 }
 }
 



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


D10296: rhg: try read [paths] for `--repository` value

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

REVISION SUMMARY
  hg parses -R and --repository CLI arguments "early" in order to know which
  local repository to load config from. (Config can then affect whether or how 
to
  fall back.)
  
  The value of of those arguments can be not only a filesystem path, but also an
  alias configured in the [paths] section. This part was missing in rhg and this
  patch implements that.
  
  The `#if no-rhg` is still not removed completely as those two `[paths]` are 
read
  from `.hg/hgrc` of directory in which the command is running. That will be
  implemented in the next patch.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/main.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
@@ -65,19 +65,19 @@
 
 -R with path aliases:
 
+  $ cd c
 TODO: add rhg support for path aliases
 #if no-rhg
-  $ cd c
   $ hg -R default identify
   8580ff50825a tip
   $ hg -R relative identify
   8580ff50825a tip
+#endif
   $ echo '[paths]' >> $HGRCPATH
   $ echo 'relativetohome = a' >> $HGRCPATH
   $ HOME=`pwd`/../ hg -R relativetohome identify
   8580ff50825a tip
   $ cd ..
-#endif
 
 #if no-outer-repo
 
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
@@ -167,7 +167,29 @@
 )
 }
 }
-let repo_path = early_args.repo.as_deref().map(get_path_from_bytes);
+let repo_arg = early_args.repo.unwrap_or(Vec::new());
+let repo_path = {
+if repo_arg.len() == 0 {
+None
+} else {
+let config_val = non_repo_config.get_str(b"paths", &(repo_arg));
+if config_val.is_ok() {
+let val = config_val.unwrap();
+if !val.is_none() {
+let real_val = val.unwrap();
+if real_val.len() > 0 {
+Some(get_path_from_bytes(val.unwrap().as_bytes()))
+} else {
+Some(get_path_from_bytes(_arg))
+}
+} else {
+Some(get_path_from_bytes(_arg))
+}
+} else {
+Some(get_path_from_bytes(_arg))
+}
+}
+};
 let repo_result = match Repo::find(_repo_config, repo_path) {
 Ok(repo) => Ok(repo),
 Err(RepoError::NotFound { at }) if repo_path.is_none() => {



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


D10254: rhg: raise wdir specific error for `hg debugdata`

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

REVISION SUMMARY
  Helps remove the conditional in `test-debugcommands.t` for rhg.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/hg-core/src/revlog.rs
  rust/hg-core/src/revlog/revlog.rs
  rust/hg-core/src/revset.rs
  rust/rhg/src/error.rs
  tests/test-debugcommands.t

CHANGE DETAILS

diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t
--- a/tests/test-debugcommands.t
+++ b/tests/test-debugcommands.t
@@ -531,17 +531,9 @@
 
 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/rust/rhg/src/error.rs b/rust/rhg/src/error.rs
--- a/rust/rhg/src/error.rs
+++ b/rust/rhg/src/error.rs
@@ -157,6 +157,9 @@
 impl From<(RevlogError, )> for CommandError {
 fn from((err, rev): (RevlogError, )) -> CommandError {
 match err {
+RevlogError::WDirUnsupported => CommandError::abort(
+"abort: working directory revision cannot be specified",
+),
 RevlogError::InvalidRevision => CommandError::abort(format!(
 "abort: invalid revision identifier: {}",
 rev
diff --git a/rust/hg-core/src/revset.rs b/rust/hg-core/src/revset.rs
--- a/rust/hg-core/src/revset.rs
+++ b/rust/hg-core/src/revset.rs
@@ -7,7 +7,7 @@
 use crate::revlog::changelog::Changelog;
 use crate::revlog::revlog::{Revlog, RevlogError};
 use crate::revlog::NodePrefix;
-use crate::revlog::{Revision, NULL_REVISION};
+use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX};
 
 /// Resolve a query string into a single revision.
 ///
@@ -50,6 +50,9 @@
 return Ok(integer);
 }
 }
+if input == WORKING_DIRECTORY_HEX {
+return Err(RevlogError::WDirUnsupported);
+}
 if let Ok(prefix) = NodePrefix::from_hex(input) {
 return revlog.get_node_rev(prefix);
 }
diff --git a/rust/hg-core/src/revlog/revlog.rs 
b/rust/hg-core/src/revlog/revlog.rs
--- a/rust/hg-core/src/revlog/revlog.rs
+++ b/rust/hg-core/src/revlog/revlog.rs
@@ -23,6 +23,8 @@
 #[derive(derive_more::From)]
 pub enum RevlogError {
 InvalidRevision,
+/// Working directory is not supported
+WDirUnsupported,
 /// Found more than one entry whose ID match the requested prefix
 AmbiguousPrefix,
 #[from]
diff --git a/rust/hg-core/src/revlog.rs b/rust/hg-core/src/revlog.rs
--- a/rust/hg-core/src/revlog.rs
+++ b/rust/hg-core/src/revlog.rs
@@ -35,6 +35,9 @@
 #[allow(clippy::unreadable_literal)]
 pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fff;
 
+pub const WORKING_DIRECTORY_HEX:  =
+"";
+
 /// The simplest expression of what we need of Mercurial DAGs.
 pub trait Graph {
 /// Return the two parents of the given `Revision`.



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


D10253: rhg: add support for detailed exit code for ConfigParseError

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

REVISION SUMMARY
  This patch adds basic support for detailed exit code to rhg with support for
  ConfigParseError.
  
  For now, if parsing the config results in error, we silently fallbacks to
  `false`. The python version in this case emits a traceback.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/error.rs
  rust/rhg/src/exitcode.rs
  rust/rhg/src/main.rs
  tests/test-config.t
  tests/test-dispatch.t

CHANGE DETAILS

diff --git a/tests/test-dispatch.t b/tests/test-dispatch.t
--- a/tests/test-dispatch.t
+++ b/tests/test-dispatch.t
@@ -90,12 +90,9 @@
 
   $ 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-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -3,8 +3,6 @@
 
 Invalid syntax: no value
 
-TODO: add rhg support for detailed exit codes
-#if no-rhg
   $ cat > .hg/hgrc << EOF
   > novaluekey
   > EOF
@@ -37,7 +35,6 @@
   $ hg showconfig
   config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace:  
[section]
   [30]
-#endif
 
 Reset hgrc
 
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
@@ -82,7 +82,14 @@
 let blackbox = blackbox::Blackbox::new(, process_start_time)?;
 blackbox.log_command_start();
 let result = run();
-blackbox.log_command_end(exit_code());
+blackbox.log_command_end(exit_code(
+,
+// TODO: show a warning or combine with original error if `get_bool`
+// returns an error
+config
+.get_bool(b"ui", b"detailed-exit-code")
+.unwrap_or(false),
+));
 result
 }
 
@@ -114,6 +121,7 @@
 error,
 cwd.display()
 ))),
+false,
 )
 })
 });
@@ -125,7 +133,13 @@
 // "unsupported" error but that is not enforced by the type system.
 let on_unsupported = OnUnsupported::Abort;
 
-exit(_current_dir, , on_unsupported, Err(error.into()))
+exit(
+_current_dir,
+,
+on_unsupported,
+Err(error.into()),
+false,
+)
 });
 
 if let Some(repo_path_bytes) = _args.repo {
@@ -145,6 +159,11 @@
 repo_path_bytes
 ),
 }),
+// TODO: show a warning or combine with original error if 
`get_bool`
+// returns an error
+non_repo_config
+.get_bool(b"ui", b"detailed-exit-code")
+.unwrap_or(false),
 )
 }
 }
@@ -160,6 +179,11 @@
 ,
 OnUnsupported::from_config(, _repo_config),
 Err(error.into()),
+// TODO: show a warning or combine with original error if 
`get_bool`
+// returns an error
+non_repo_config
+.get_bool(b"ui", b"detailed-exit-code")
+.unwrap_or(false),
 ),
 };
 
@@ -176,13 +200,35 @@
 repo_result.as_ref(),
 config,
 );
-exit(_current_dir, , on_unsupported, result)
+exit(
+_current_dir,
+,
+on_unsupported,
+result,
+// TODO: show a warning or combine with original error if `get_bool`
+// returns an error
+config
+.get_bool(b"ui", b"detailed-exit-code")
+.unwrap_or(false),
+)
 }
 
-fn exit_code(result: <(), CommandError>) -> i32 {
+fn exit_code(
+result: <(), CommandError>,
+use_detailed_exit_code: bool,
+) -> i32 {
 match result {
 Ok(()) => exitcode::OK,
-Err(CommandError::Abort { .. }) => exitcode::ABORT,
+Err(CommandError::Abort {
+message: _,
+detailed_exit_code,
+}) => {
+if use_detailed_exit_code {
+*detailed_exit_code
+} else {
+exitcode::ABORT
+}
+}
 Err(CommandError::Unsuccessful) => exitcode::UNSUCCESSFUL,
 
 // Exit with a specific code and no error message to let a potential
@@ -198,6 +244,7 @@
 ui: ,
 mut on_unsupported: OnUnsupported,
 result: Result<(), CommandError>,
+use_detailed_exit_code: bool,
 ) -> ! {
 if let (
 OnUnsupported::Fallback { executable },
@@ -238,18 +285,22 @@
 }
 }
 }
-exit_no_fallback(ui, on_unsupported, result)
+exit_no_fallback(ui, on_unsupported, 

D10149: commit: get info from mergestate whether a file was merged or not

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

REVISION SUMMARY
  While commiting a merge, the commit code does not know whether a file was 
merged
  during `hg merge` or not. This leads the commit code to look for filelog
  ancestor to choose parents of new filelog created on merge commit.
  This leads to wrong results in some cases as demonstrated by previous patch.
  
  From this patch, we start storing information about merged files in mergestate
  in stateextras and then use that on commit to detect whether we need to set 
two
  parents or not.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/commit.py
  mercurial/merge.py
  tests/test-backout.t
  tests/test-copies-chain-merge.t
  tests/test-histedit-non-commute-abort.t
  tests/test-merge-changedelete.t
  tests/test-merge-criss-cross.t
  tests/test-obsolete.t
  tests/test-rebase-abort.t
  tests/test-resolve.t

CHANGE DETAILS

diff --git a/tests/test-resolve.t b/tests/test-resolve.t
--- a/tests/test-resolve.t
+++ b/tests/test-resolve.t
@@ -255,11 +255,13 @@
 ancestor path: file1 (node 2ed2a3912a0b24502043eae84ee4b279c18b90dd)
 other path: file1 (node 6f4310b00b9a147241b071a60c28a650827fb03d)
 extra: ancestorlinknode = 99726c03216e233810a2564cbc0adfe395007eac
+extra: merged = yes
   file: file2 (state "u")
 local path: file2 (hash cb99b709a1978bd205ab9dfd4c5aaa1fc91c7523, flags "")
 ancestor path: file2 (node 2ed2a3912a0b24502043eae84ee4b279c18b90dd)
 other path: file2 (node 6f4310b00b9a147241b071a60c28a650827fb03d)
 extra: ancestorlinknode = 99726c03216e233810a2564cbc0adfe395007eac
+extra: merged = yes
   $ hg resolve -l
   R file1
   U file2
@@ -271,7 +273,7 @@
{
 "commits": [{"label": "working copy", "name": "local", "node": 
"57653b9f834a4493f7240b0681efcb9ae7cab745"}, {"label": "merge rev", "name": 
"other", "node": "dc77451844e37f03f5c559e3b8529b2b48d381d1"}],
 "extras": [],
-"files": [{"ancestor_node": "2ed2a3912a0b24502043eae84ee4b279c18b90dd", 
"ancestor_path": "file1", "extras": [{"key": "ancestorlinknode", "value": 
"99726c03216e233810a2564cbc0adfe395007eac"}], "local_flags": "", "local_key": 
"60b27f004e454aca81b0480209cce5081ec52390", "local_path": "file1", 
"other_node": "6f4310b00b9a147241b071a60c28a650827fb03d", "other_path": 
"file1", "path": "file1", "state": "r"}, {"ancestor_node": 
"2ed2a3912a0b24502043eae84ee4b279c18b90dd", "ancestor_path": "file2", "extras": 
[{"key": "ancestorlinknode", "value": 
"99726c03216e233810a2564cbc0adfe395007eac"}], "local_flags": "", "local_key": 
"cb99b709a1978bd205ab9dfd4c5aaa1fc91c7523", "local_path": "file2", 
"other_node": "6f4310b00b9a147241b071a60c28a650827fb03d", "other_path": 
"file2", "path": "file2", "state": "u"}]
+"files": [{"ancestor_node": "2ed2a3912a0b24502043eae84ee4b279c18b90dd", 
"ancestor_path": "file1", "extras": [{"key": "ancestorlinknode", "value": 
"99726c03216e233810a2564cbc0adfe395007eac"}, {"key": "merged", "value": 
"yes"}], "local_flags": "", "local_key": 
"60b27f004e454aca81b0480209cce5081ec52390", "local_path": "file1", 
"other_node": "6f4310b00b9a147241b071a60c28a650827fb03d", "other_path": 
"file1", "path": "file1", "state": "r"}, {"ancestor_node": 
"2ed2a3912a0b24502043eae84ee4b279c18b90dd", "ancestor_path": "file2", "extras": 
[{"key": "ancestorlinknode", "value": 
"99726c03216e233810a2564cbc0adfe395007eac"}, {"key": "merged", "value": 
"yes"}], "local_flags": "", "local_key": 
"cb99b709a1978bd205ab9dfd4c5aaa1fc91c7523", "local_path": "file2", 
"other_node": "6f4310b00b9a147241b071a60c28a650827fb03d", "other_path": 
"file2", "path": "file2", "state": "u"}]
}
   ]
 
diff --git a/tests/test-rebase-abort.t b/tests/test-rebase-abort.t
--- a/tests/test-rebase-abort.t
+++ b/tests/test-rebase-abort.t
@@ -95,6 +95,7 @@
 ancestor path: common (node de0a666fdd9c1a0b0698b90d85064d8bd34f74b6)
 other path: common (node 2f6411de53677f6f1048fef5bf888d67a342e0a5)
 extra: ancestorlinknode = 3163e20567cc93074fbb7a53c8b93312e59dbf2c
+extra: merged = yes
   $ hg resolve -l
   U common
 
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -1844,6 +1844,7 @@
 ancestor path: file (node bc7ebe2d260cff30d2a39a130d84add36216f791)
 other path: file (node b789fdd96dc2f3bd229c1dd8eedf0fc60e2b68e3)
 extra: ancestorlinknode = b73b8c9a4ab4da89a5a35a6f10dfb13edc84ca37
+extra: merged = yes
 We should be able to see the log (without the deleted commit, of course)
   $ hg log -G
   @  0:f53e9479dce5 (draft) [tip ] first
diff --git a/tests/test-merge-criss-cross.t b/tests/test-merge-criss-cross.t
--- a/tests/test-merge-criss-cross.t
+++ b/tests/test-merge-criss-cross.t
@@ -540,6 +540,7 @@
 other path: the-file (node 59e363a07dc876278f0e41756236f30213b6b460)
 

D10148: mergestate: don't pop stateextras when there are no conflicts on filemerge

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

REVISION SUMMARY
  Even if `filemerge.filemerge()` didn't result in conflicts, we should not 
remove
  stateextras for a file since we now use that for more things than just merge
  time information. We use stateextras to store information which is required to
  be used by commit.
  
  I tracked this down while finding why a patch of mine which adds more commit
  related information does not work as expected and looses the extras in
  mergestate.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/mergestate.py

CHANGE DETAILS

diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -382,7 +382,6 @@
 if merge_ret is None:
 # If return value of merge is None, then there are no real conflict
 del self._state[dfile]
-self._stateextras.pop(dfile, None)
 self._dirty = True
 elif not merge_ret:
 self.mark(dfile, MERGE_RECORD_RESOLVED)



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


D10147: commit: reorder if-else conditional to give mergestate info priority

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

REVISION SUMMARY
  Looking at the code now, I was unable to find a good reason as why we only 
rely
  on mergestate extras info after checking whether a filelog parent is ancestor 
of
  other or not.
  
  I mean if we have stored in mergestate that `other` was chosed, we should
  blindly pick that one.
  
  This cleanup will also help introduce more cases when both `fparent1` and
  `fparent2` are non-null but using info from mergestate, we can fastpath.
  
  The test change actually demonstrates the point of the patch. During merge we
  were getting the other side of the file but on commit we were marking that as
  merged.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/commit.py
  tests/test-rebase-conflicts.t

CHANGE DETAILS

diff --git a/tests/test-rebase-conflicts.t b/tests/test-rebase-conflicts.t
--- a/tests/test-rebase-conflicts.t
+++ b/tests/test-rebase-conflicts.t
@@ -276,13 +276,13 @@
   committing manifest
   committing changelog
   updating the branch cache
-  rebased as 2a7f09cac94c
+  rebased as c1ffa3b5274e
   rebase status stored
   rebase merging completed
   update back to initial working directory parent
   resolving manifests
branchmerge: False, force: False, partial: False
-   ancestor: 2a7f09cac94c, local: 2a7f09cac94c+, remote: d79e2059b5c0
+   ancestor: c1ffa3b5274e, local: c1ffa3b5274e+, remote: d79e2059b5c0
f1.txt: other deleted -> r
   removing f1.txt
f2.txt: remote created -> g
@@ -300,7 +300,7 @@
   list of changesets:
   4c9fbe56a16f30c0d5dcc40ec1a97bbe3325209c
   19c888675e133ab5dff84516926a65672eaf04d9
-  2a7f09cac94c7f4b73ebd5cd1a62d3b2e8e336bf
+  c1ffa3b5274e92a9388fe782854e295d2e8d0443
   bundle2-output-bundle: "HG20", 3 parts total
   bundle2-output-part: "changegroup" (params: 1 mandatory 1 advisory) streamed 
payload
   bundle2-output-part: "cache:rev-branch-cache" (advisory) streamed payload
@@ -311,7 +311,7 @@
   adding changesets
   add changeset 4c9fbe56a16f
   add changeset 19c888675e13
-  add changeset 2a7f09cac94c
+  add changeset c1ffa3b5274e
   adding manifests
   adding file changes
   adding f1.txt revisions
diff --git a/mercurial/commit.py b/mercurial/commit.py
--- a/mercurial/commit.py
+++ b/mercurial/commit.py
@@ -359,19 +359,15 @@
 elif fparent1 == nullid:
 fparent1, fparent2 = fparent2, nullid
 elif fparent2 != nullid:
-# is one parent an ancestor of the other?
-fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
-if fparent1 in fparentancestors:
+if ms.active() and ms.extras(fname).get(b'filenode-source') == 
b'other':
 fparent1, fparent2 = fparent2, nullid
-elif fparent2 in fparentancestors:
-fparent2 = nullid
-elif not fparentancestors:
-# TODO: this whole if-else might be simplified much more
-if (
-ms.active()
-and ms.extras(fname).get(b'filenode-source') == b'other'
-):
+# is one parent an ancestor of the other?
+else:
+fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
+if fparent1 in fparentancestors:
 fparent1, fparent2 = fparent2, nullid
+elif fparent2 in fparentancestors:
+fparent2 = nullid
 
 force_new_node = False
 # The file might have been deleted by merge code and user explicitly choose



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


D10116: commit: reorder if-else conditional to give mergestate info priority

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

REVISION SUMMARY
  Looking at the code now, I was unable to find a good reason as why we only 
rely
  on mergestate extras info after checking whether a filelog parent is ancestor 
of
  other or not.
  
  I mean if we have stored in mergestate that `other` was chosed, we should
  blindly pick that one.
  
  This cleanup will also help introduce more cases when both `fparent1` and
  `fparent2` are non-null but using info from mergestate, we can fastpath.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/commit.py

CHANGE DETAILS

diff --git a/mercurial/commit.py b/mercurial/commit.py
--- a/mercurial/commit.py
+++ b/mercurial/commit.py
@@ -359,19 +359,18 @@
 elif fparent1 == nullid:
 fparent1, fparent2 = fparent2, nullid
 elif fparent2 != nullid:
-# is one parent an ancestor of the other?
-fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
-if fparent1 in fparentancestors:
+if (
+ms.active()
+and ms.extras(fname).get(b'filenode-source') == b'other'
+):
 fparent1, fparent2 = fparent2, nullid
-elif fparent2 in fparentancestors:
-fparent2 = nullid
-elif not fparentancestors:
-# TODO: this whole if-else might be simplified much more
-if (
-ms.active()
-and ms.extras(fname).get(b'filenode-source') == b'other'
-):
+# is one parent an ancestor of the other?
+else:
+fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
+if fparent1 in fparentancestors:
 fparent1, fparent2 = fparent2, nullid
+elif fparent2 in fparentancestors:
+fparent2 = nullid
 
 force_new_node = False
 # The file might have been deleted by merge code and user explicitly choose



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


D10083: tags: validate nodes in _getfnodes() and update cache in case of unknown nodes

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

REVISION SUMMARY
  `hgtagsfnodescache` can contain unknown nodes due to cache corruption and this
  lead to a traceback on operations like `hg tags` as we don't validate nodes.
  
  This patch validates that all filenodes returned after `hgtagsfnodescache` are
  known to the repository. If there exists any unknown filenode, we force
  recompute it and update the cache.
  
  The test change demonstrates the fix.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/tags.py
  tests/test-tags.t

CHANGE DETAILS

diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -452,8 +452,8 @@
   5 8dbfe60eff306a54259cfe007db9e330e7ecf866 
0c04f2a8deadde17fab7422878ee5a2dadbc943d (unknown node)
 
   $ hg tags
-  abort: data/.hgtags.i@0c04f2a8deadde17fab7422878ee5a2dadbc943d: no match 
found
-  [50]
+  tip5:8dbfe60eff30
+  bar1:78391a272241
 
 BUG: Unless this file is restored, the `hg tags` in the next unix-permissions
 conditional will fail: "abort: data/.hgtags.i@0c04f2a8dead: no match found"
diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -494,11 +494,25 @@
 starttime = util.timer()
 fnodescache = hgtagsfnodescache(repo.unfiltered())
 cachefnode = {}
+validatedfnodes = set()
+unknownentries = set()
 for node in nodes:
 fnode = fnodescache.getfnode(node)
 if fnode != nullid:
+if fnode not in validatedfnodes:
+try:
+repo.filectx(b'.hgtags', fileid=fnode).data()
+validatedfnodes.add(fnode)
+except error.LookupError:
+unknownentries.add(node)
 cachefnode[node] = fnode
 
+if unknownentries:
+fixednodemap = fnodescache.recomputefnodes(unknownentries)
+for node, fnode in pycompat.iteritems(fixednodemap):
+if fnode != nullid:
+cachefnode[node] = fnode
+
 fnodescache.write()
 
 duration = util.timer() - starttime
@@ -826,6 +840,16 @@
 
 self._writeentry(ctx.rev() * _fnodesrecsize, node[0:4], fnode)
 
+def recomputefnodes(self, nodes):
+"""recomputes file nodes for given nodes as the current ones are
+unknown and return a map of node -> recomputed fnode"""
+fixednodemap = {}
+for node in nodes:
+fnode = self._computefnode(node)
+fixednodemap[node] = fnode
+self.setfnode(node, fnode)
+return fixednodemap
+
 def _writeentry(self, offset, prefix, fnode):
 # Slices on array instances only accept other array.
 entry = bytearray(prefix + fnode)



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


D10015: debugtagscache: verify that filenode is correct

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

REVISION SUMMARY
  Previous patch from Matt demonstrates that `debugtagscache` does not warn 
about
  filenode being invalid which can be caused by a corrupted cache.
  
  We start by showing that it's an invalid node.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/debugcommands.py
  tests/test-tags.t

CHANGE DETAILS

diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -444,12 +444,12 @@
 
   $ hg debugtagscache | tail -2
   4 0c192d7d5e6b78a714de54a2e9627952a877e25a 
0c04f2a8af31de17fab7422878ee5a2dadbc943d
-  5 8dbfe60eff306a54259cfe007db9e330e7ecf866 
0c04f2a8deadde17fab7422878ee5a2dadbc943d
+  5 8dbfe60eff306a54259cfe007db9e330e7ecf866 
0c04f2a8deadde17fab7422878ee5a2dadbc943d (invalid node)
 
   $ rm -f .hg/cache/tags2-visible
   $ hg debugtagscache | tail -2
   4 0c192d7d5e6b78a714de54a2e9627952a877e25a 
0c04f2a8af31de17fab7422878ee5a2dadbc943d
-  5 8dbfe60eff306a54259cfe007db9e330e7ecf866 
0c04f2a8deadde17fab7422878ee5a2dadbc943d
+  5 8dbfe60eff306a54259cfe007db9e330e7ecf866 
0c04f2a8deadde17fab7422878ee5a2dadbc943d (invalid node)
 
   $ hg tags
   abort: data/.hgtags.i@0c04f2a8deadde17fab7422878ee5a2dadbc943d: no match 
found
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -3870,6 +3870,10 @@
 tagsnode = cache.getfnode(node, computemissing=False)
 if tagsnode:
 tagsnodedisplay = hex(tagsnode)
+try:
+repo.filectx(b'.hgtags', fileid=tagsnode).data()
+except error.LookupError:
+tagsnodedisplay += b' (invalid node)'
 elif tagsnode is None:
 tagsnodedisplay = b'missing'
 else:



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


D10018: tags: update the hgtagsfnodes cache if invalid file nodes are found

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

REVISION SUMMARY
  The cache update happens but it happens post calculation of alltags and hence 
we
  still don't get correct list of tags in current run.
  Next patch will try to fix this.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/tags.py
  tests/test-tags.t

CHANGE DETAILS

diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -451,9 +451,17 @@
   4 0c192d7d5e6b78a714de54a2e9627952a877e25a 
0c04f2a8af31de17fab7422878ee5a2dadbc943d
   5 8dbfe60eff306a54259cfe007db9e330e7ecf866 
0c04f2a8deadde17fab7422878ee5a2dadbc943d (invalid node)
 
-  $ hg tags
-  tip5:8dbfe60eff30
-  bar1:78391a272241
+  $ hg tags --debug
+  found invalid fnodes for "8dbfe60eff306a54259cfe007db9e330e7ecf866", 
updating them
+  tip5:8dbfe60eff306a54259cfe007db9e330e7ecf866
+  bar1:78391a272241d70354aa14c874552cad6b51bb42
+
+  $ hg debugtagscache | tail -2
+  4 0c192d7d5e6b78a714de54a2e9627952a877e25a 
0c04f2a8af31de17fab7422878ee5a2dadbc943d
+  5 8dbfe60eff306a54259cfe007db9e330e7ecf866 
0c04f2a8af31de17fab7422878ee5a2dadbc943d
+  $ hg tags --debug
+  tip5:8dbfe60eff306a54259cfe007db9e330e7ecf866
+  bar1:78391a272241d70354aa14c874552cad6b51bb42
 
 BUG: Unless this file is restored, the `hg tags` in the next unix-permissions
 conditional will fail: "abort: data/.hgtags.i@0c04f2a8dead: no match found"
diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -201,6 +201,18 @@
 ), b"tag cache returned bogus head %s" % short(head)
 fnodes = _filterfnodes(tagfnode, reversed(heads))
 alltags, invalidnodes = _tagsfromfnodes(ui, repo, fnodes)
+recomputeheads = []
+for head, fnode in pycompat.iteritems(tagfnode):
+if fnode in invalidnodes:
+recomputeheads.append(head)
+# only hgtagsfnodes contains fnodes explicitly
+if source == 'hgtagsfnodes' and recomputeheads:
+ui.debug(
+b'found invalid fnodes for "%s", updating them\n'
+% b','.join([hex(h) for h in recomputeheads])
+)
+fnodescache = hgtagsfnodescache(repo.unfiltered())
+fnodescache.recomputefnodes(recomputeheads)
 
 # and update the cache (if necessary)
 if shouldwrite:
@@ -795,6 +807,14 @@
 self._writeentry(offset, properprefix, fnode)
 return fnode
 
+def recomputefnodes(self, nodes):
+"""recomputes file nodes for given nodes as the current ones are
+invalid and write the updates to the cache"""
+for node in nodes:
+fnode = self._computefnode(node)
+self.setfnode(node, fnode)
+self.write()
+
 def _computefnode(self, node):
 """Finds the tag filenode for a node which is missing or invalid
 in cache"""



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


D10014: debugcommands: prevent using `is False`

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

REVISION SUMMARY
  I was touching this code in a future patch and marmoute warned about usage of
  `is False` here.
  
  Quoting marmoute:
  
"is False" is going to check if the object you have the very same object in
memory than the one Python allocated for False (in practice 0)
This will "mostly work" on cpython because of implementation details, but
is semantically wrong and can start breaking unexpectedly

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -3870,10 +3870,10 @@
 tagsnode = cache.getfnode(node, computemissing=False)
 if tagsnode:
 tagsnodedisplay = hex(tagsnode)
-elif tagsnode is False:
+elif tagsnode is None:
+tagsnodedisplay = b'missing'
+else:
 tagsnodedisplay = b'invalid'
-else:
-tagsnodedisplay = b'missing'
 
 ui.write(b'%d %s %s\n' % (r, hex(node), tagsnodedisplay))
 



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


D10017: tags: return set of invalid nodes from _tagsfromfnodes()

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

REVISION SUMMARY
  We pass a list of file nodes to that function but some can be invalid because
  they were read from a cache which was corrupted.
  
  This patches catches LookupError which is being raised because of invalid
  fnodes, builds a set of such nodes and return it to the callers.
  In next patch, we will add logic to update cache in such cases.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/tags.py
  tests/test-tags.t

CHANGE DETAILS

diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -452,8 +452,8 @@
   5 8dbfe60eff306a54259cfe007db9e330e7ecf866 
0c04f2a8deadde17fab7422878ee5a2dadbc943d (invalid node)
 
   $ hg tags
-  abort: data/.hgtags.i@0c04f2a8deadde17fab7422878ee5a2dadbc943d: no match 
found
-  [50]
+  tip5:8dbfe60eff30
+  bar1:78391a272241
 
 BUG: Unless this file is restored, the `hg tags` in the next unix-permissions
 conditional will fail: "abort: data/.hgtags.i@0c04f2a8dead: no match found"
diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -117,8 +117,8 @@
 """
 if oldfnodes == newfnodes:
 return []
-oldtags = _tagsfromfnodes(ui, repo, oldfnodes)
-newtags = _tagsfromfnodes(ui, repo, newfnodes)
+oldtags = _tagsfromfnodes(ui, repo, oldfnodes)[0]
+newtags = _tagsfromfnodes(ui, repo, newfnodes)[0]
 
 # list of (tag, old, new): None means missing
 entries = []
@@ -200,7 +200,7 @@
 head
 ), b"tag cache returned bogus head %s" % short(head)
 fnodes = _filterfnodes(tagfnode, reversed(heads))
-alltags = _tagsfromfnodes(ui, repo, fnodes)
+alltags, invalidnodes = _tagsfromfnodes(ui, repo, fnodes)
 
 # and update the cache (if necessary)
 if shouldwrite:
@@ -225,21 +225,27 @@
 
 
 def _tagsfromfnodes(ui, repo, fnodes):
-"""return a tagsmap from a list of file-node
+"""return a tuple
+(tagsmap from a list of file-node, list of invalid fnodes)
 
 tagsmap: tag name to (node, hist) 2-tuples.
 
 The order of the list matters."""
 alltags = {}
+invalidfnodes = set()
 fctx = None
 for fnode in fnodes:
 if fctx is None:
 fctx = repo.filectx(b'.hgtags', fileid=fnode)
 else:
 fctx = fctx.filectx(fnode)
-filetags = _readtags(ui, repo, fctx.data().splitlines(), fctx)
+try:
+filetags = _readtags(ui, repo, fctx.data().splitlines(), fctx)
+except error.LookupError:
+# some fnodes can be invalid because of broken cache
+invalidfnodes.add(fnode)
 _updatetags(filetags, alltags)
-return alltags
+return (alltags, invalidfnodes)
 
 
 def readlocaltags(ui, repo, alltags, tagtypes):



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


D10016: tags: return tag cache source from _readtagcache()

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

REVISION SUMMARY
  If the cache is invalid, _readtagcache() can return data which has a wrong
  filenode. We want to fix the cache in such cases by replacing the wrong 
filenode
  with a correct one. To do so, first the callers need to be aware from
  which cache values returned by this function are read.
  
  This patch adds a new return value which depicts the source of data return 
from
  `_readtagcache()`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/tags.py

CHANGE DETAILS

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -183,7 +183,9 @@
 
 The tags cache is read and updated as a side-effect of calling.
 """
-(heads, tagfnode, valid, cachetags, shouldwrite) = _readtagcache(ui, repo)
+(heads, tagfnode, valid, cachetags, shouldwrite, source) = _readtagcache(
+ui, repo
+)
 if cachetags is not None:
 assert not shouldwrite
 # XXX is this really 100% correct?  are there oddball special
@@ -392,7 +394,7 @@
 def _readtagcache(ui, repo):
 """Read the tag cache.
 
-Returns a tuple (heads, fnodes, validinfo, cachetags, shouldwrite).
+Returns a tuple (heads, fnodes, validinfo, cachetags, shouldwrite, source).
 
 If the cache is completely up-to-date, "cachetags" is a dict of the
 form returned by _readtags() and "heads", "fnodes", and "validinfo" are
@@ -404,6 +406,12 @@
 when writing the tags cache. "fnodes" is a mapping from head to .hgtags
 filenode. "shouldwrite" is True.
 
+"source" is from which cache the data is read. Possible values are:
+tags2: when data is read from `tags2-` cache
+hgtagsfnodes: data is read from hgtagsfnodes cache
+other: when data is read from source other than tags2 and
+   hgtagsfnodes cache
+
 If the cache is not up to date, the caller is responsible for reading tag
 info from each returned head. (See findglobaltags().)
 """
@@ -443,7 +451,7 @@
 ):
 tags = _readtags(ui, repo, cachelines, cachefile.name)
 cachefile.close()
-return (None, None, None, tags, False)
+return (None, None, None, tags, False, 'tags2')
 if cachefile:
 cachefile.close()  # ignore rest of file
 
@@ -453,7 +461,7 @@
 # Case 2 (uncommon): empty repo; get out quickly and don't bother
 # writing an empty cache.
 if repoheads == [nullid]:
-return ([], {}, valid, {}, False)
+return ([], {}, valid, {}, False, 'other')
 
 # Case 3 (uncommon): cache file missing or empty.
 
@@ -471,7 +479,7 @@
 if not len(repo.file(b'.hgtags')):
 # No tags have ever been committed, so we can avoid a
 # potentially expensive search.
-return ([], {}, valid, None, True)
+return ([], {}, valid, None, True, 'other')
 
 # Now we have to lookup the .hgtags filenode for every new head.
 # This is the most expensive part of finding tags, so performance
@@ -482,7 +490,7 @@
 
 # Caller has to iterate over all heads, but can use the filenodes in
 # cachefnode to get to each .hgtags revision quickly.
-return (repoheads, cachefnode, valid, None, True)
+return (repoheads, cachefnode, valid, None, True, 'hgtagsfnodes')
 
 
 def _getfnodes(ui, repo, nodes):



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


D10013: hgtagsfnodes: refactor code to compute fnode into separate fn

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

REVISION SUMMARY
  I plan to use this code at one more place while fixing a bug caused by an
  invalid fnode present in cache.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/tags.py

CHANGE DETAILS

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -777,6 +777,15 @@
 return False
 return None
 
+fnode = self._computefnode(node)
+self._writeentry(offset, properprefix, fnode)
+return fnode
+
+def _computefnode(self, node):
+"""Finds the tag filenode for a node which is missing or invalid
+in cache"""
+ctx = self._repo[node]
+rev = ctx.rev()
 fnode = None
 cl = self._repo.changelog
 p1rev, p2rev = cl._uncheckedparentrevs(rev)
@@ -804,8 +813,6 @@
 except error.LookupError:
 # No .hgtags file on this revision.
 fnode = nullid
-
-self._writeentry(offset, properprefix, fnode)
 return fnode
 
 def setfnode(self, node, fnode):



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


D9994: error: remove shortening of node in error message

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

REVISION SUMMARY
  This makes it difficult to figure what exactly was node on which LookupError 
was
  called if we only have the error message.
  
  I was debugging an error message which contained a short node and I tried to
  find out which callers raise LookupError with a short node. This turned out to
  be wrong because we short-ed the node before printing.
  
  If a short node is to be displayed, that should be done by callers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/error.py
  tests/test-bundle-r.t
  tests/test-bundle.t
  tests/test-convert-filemap.t
  tests/test-convert-hg-source.t
  tests/test-hgweb-filelog.t
  tests/test-hgweb.t
  tests/test-hgwebdir.t
  tests/test-narrow-exchange.t
  tests/test-pull-bundle.t

CHANGE DETAILS

diff --git a/tests/test-pull-bundle.t b/tests/test-pull-bundle.t
--- a/tests/test-pull-bundle.t
+++ b/tests/test-pull-bundle.t
@@ -185,7 +185,7 @@
   adding changesets
   adding manifests
   adding file changes
-  abort: 00changelog.i@66f7d451a68b: no node
+  abort: 00changelog.i@66f7d451a68b85ed82ff5fcc254daf50c74144bd: no node
   [50]
   $ cd ..
   $ killdaemons.py
diff --git a/tests/test-narrow-exchange.t b/tests/test-narrow-exchange.t
--- a/tests/test-narrow-exchange.t
+++ b/tests/test-narrow-exchange.t
@@ -105,7 +105,7 @@
   remote: adding file changes
   remote: transaction abort!
   remote: rollback completed
-  remote: abort: data/inside2/f.i@4a1aa07735e6: unknown parent 
(reporevlogstore !)
+  remote: abort: data/inside2/f.i@4a1aa07735e673e20c00fae80f40dc301ee30616: 
unknown parent (reporevlogstore !)
   remote: abort: data/inside2/f/index@4a1aa07735e6: no node (reposimplestore !)
   abort: stream ended unexpectedly (got 0 bytes, expected 4)
   [255]
@@ -218,8 +218,8 @@
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 0 changes to 0 files (no-lfs-on !)
-  remote: error: pretxnchangegroup.lfs hook raised an exception: 
data/inside2/f.i@f59b4e021835: no match found (lfs-on !)
+  remote: error: pretxnchangegroup.lfs hook raised an exception: 
data/inside2/f.i@f59b4e0218355383d2789196f1092abcf2262b0c: no match found 
(lfs-on !)
   remote: transaction abort! (lfs-on !)
   remote: rollback completed (lfs-on !)
-  remote: abort: data/inside2/f.i@f59b4e021835: no match found (lfs-on !)
+  remote: abort: data/inside2/f.i@f59b4e0218355383d2789196f1092abcf2262b0c: no 
match found (lfs-on !)
   abort: stream ended unexpectedly (got 0 bytes, expected 4) (lfs-on !)
diff --git a/tests/test-hgwebdir.t b/tests/test-hgwebdir.t
--- a/tests/test-hgwebdir.t
+++ b/tests/test-hgwebdir.t
@@ -103,7 +103,7 @@
   404 Not Found
   
   
-  error: bork@8580ff50825a: not found in manifest
+  error: bork@8580ff50825a50c8f716709acdf8de0deddcd6ab: not found in manifest
   [1]
 
 should succeed
diff --git a/tests/test-hgweb.t b/tests/test-hgweb.t
--- a/tests/test-hgweb.t
+++ b/tests/test-hgweb.t
@@ -149,7 +149,7 @@
   404 Not Found
   
   
-  error: bork@2ef0ac749a14: not found in manifest
+  error: bork@2ef0ac749a14e4f57a5a822464a0902c6f7f448f: not found in manifest
   [1]
   $ get-with-headers.py localhost:$HGPORT 'file/tip/bork'
   404 Not Found
@@ -202,7 +202,7 @@
   An error occurred while processing your request:
   
   
-  bork@2ef0ac749a14: not found in manifest
+  bork@2ef0ac749a14e4f57a5a822464a0902c6f7f448f: not found in manifest
   
   
   
@@ -218,7 +218,7 @@
   404 Not Found
   
   
-  error: bork@2ef0ac749a14: not found in manifest
+  error: bork@2ef0ac749a14e4f57a5a822464a0902c6f7f448f: not found in manifest
   [1]
 
 try bad style
diff --git a/tests/test-hgweb-filelog.t b/tests/test-hgweb-filelog.t
--- a/tests/test-hgweb-filelog.t
+++ b/tests/test-hgweb-filelog.t
@@ -656,7 +656,7 @@
   An error occurred while processing your request:
   
   
-  a@6563da9dcf87: not found in manifest
+  a@6563da9dcf87b1949716e38ff3e3dfaa3198eb06: not found in manifest
   
   
   
diff --git a/tests/test-convert-hg-source.t b/tests/test-convert-hg-source.t
--- a/tests/test-convert-hg-source.t
+++ b/tests/test-convert-hg-source.t
@@ -182,7 +182,7 @@
   sorting...
   converting...
   4 init
-  ignoring: data/b.i@1e88685f5dde: no match found (reporevlogstore !)
+  ignoring: data/b.i@1e88685f5ddec574a34c70af492f95b6debc8741: no match found 
(reporevlogstore !)
   ignoring: data/b/index@1e88685f5dde: no node (reposimplestore !)
   3 changeall
   2 changebagain
diff --git a/tests/test-convert-filemap.t b/tests/test-convert-filemap.t
--- a/tests/test-convert-filemap.t
+++ b/tests/test-convert-filemap.t
@@ -292,12 +292,12 @@
   $ rm -rf source/.hg/store/data/dir/file4
 #endif
   $ hg -q convert --filemap renames.fmap --datesort source dummydest
-  abort: data/dir/file3.i@e96dce0bc6a2: no match found (reporevlogstore !)
+  abort: 

D9992: upgrade: speed up when we have only nodemap to downgrade

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

REVISION SUMMARY
  Similar to what we do on upgrade, if we have only persistent-nodemap to
  downgrade we will just delete the nodemap files and update repository
  requirements instead of processing all the revlogs.
  
  After downgrade, we are left with unrequired docket and transaction files 
which
  seems fine but can work on deleting them if someone feels we should.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/revlogutils/nodemap.py
  mercurial/upgrade_utils/engine.py
  tests/test-persistent-nodemap.t

CHANGE DETAILS

diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t
--- a/tests/test-persistent-nodemap.t
+++ b/tests/test-persistent-nodemap.t
@@ -581,7 +581,7 @@
   plain-cl-delta: yesyes yes
   compression:zlib   zlibzlib
   compression-level:  default default default
-  $ hg debugupgraderepo --run --no-backup --quiet
+  $ hg debugupgraderepo --run --no-backup
   upgrade will perform the following actions:
   
   requirements
@@ -593,8 +593,17 @@
 - changelog
 - manifest
   
+  beginning upgrade...
+  repository locked and read-only
+  creating temporary repository to stage upgraded data: 
$TESTTMP/test-repo/.hg/upgrade.* (glob)
+  (it is safe to interrupt this process any time before data migration 
completes)
+  downgrading repository to not use persistent nodemap feature
+  removing temporary repository $TESTTMP/test-repo/.hg/upgrade.* (glob)
   $ ls -1 .hg/store/ | egrep '00(changelog|manifest)(\.n|-.*\.nd)'
-  [1]
+  00changelog-*.nd (glob)
+  00manifest-*.nd (glob)
+  undo.backup.00changelog.n
+  undo.backup.00manifest.n
   $ hg debugnodemap --metadata
 
 
@@ -643,6 +652,8 @@
   00changelog.n
   00manifest-*.nd (glob)
   00manifest.n
+  undo.backup.00changelog.n
+  undo.backup.00manifest.n
 
   $ hg debugnodemap --metadata
   uid: * (glob)
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
@@ -476,6 +476,27 @@
 tr, unfi.manifestlog._rootstore._revlog, force=True
 )
 scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
+elif (
+len(upgrade_op.removed_actions) == 1
+and [
+x
+for x in upgrade_op.removed_actions
+if x.name == b'persistent-nodemap'
+]
+and not upgrade_op.upgrade_actions
+):
+ui.status(
+_(b'downgrading repository to not use persistent nodemap 
feature\n')
+)
+with srcrepo.transaction(b'upgrade') as tr:
+unfi = srcrepo.unfiltered()
+cl = unfi.changelog
+nodemap.delete_nodemap(tr, srcrepo, cl)
+# check comment 20 lines above for accessing private attributes
+nodemap.delete_nodemap(
+tr, srcrepo, unfi.manifestlog._rootstore._revlog
+)
+scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
 else:
 with dstrepo.transaction(b'upgrade') as tr:
 _clonerevlogs(
diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py
+++ b/mercurial/revlogutils/nodemap.py
@@ -128,6 +128,14 @@
 notr._postclose[k](None)
 
 
+def delete_nodemap(tr, repo, revlog):
+""" Delete nodemap data on disk for a given revlog"""
+if revlog.nodemap_file is None:
+msg = "calling persist nodemap on a revlog without the feature enabled"
+raise error.ProgrammingError(msg)
+repo.svfs.unlink(revlog.nodemap_file)
+
+
 def persist_nodemap(tr, revlog, pending=False, force=False):
 """Write nodemap data on disk for a given revlog"""
 if getattr(revlog, 'filteredrevs', ()):



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


D9991: upgrade: write nodemap for manifests too

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

REVISION SUMMARY
  In 98e39f04d60e 
 I 
assumed that writing nodemap for manifests was not desirable
  and stopped writing it during upgrade. However in recent discussion with
  Pierre-Yves, I learnt that that's not true.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/engine.py
  tests/test-persistent-nodemap.t

CHANGE DETAILS

diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t
--- a/tests/test-persistent-nodemap.t
+++ b/tests/test-persistent-nodemap.t
@@ -641,6 +641,8 @@
   $ ls -1 .hg/store/ | egrep '00(changelog|manifest)(\.n|-.*\.nd)'
   00changelog-*.nd (glob)
   00changelog.n
+  00manifest-*.nd (glob)
+  00manifest.n
 
   $ hg debugnodemap --metadata
   uid: * (glob)
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
@@ -468,6 +468,13 @@
 unfi = srcrepo.unfiltered()
 cl = unfi.changelog
 nodemap.persist_nodemap(tr, cl, force=True)
+# we want to directly operate on the underlying revlog to force
+# create a nodemap file. This is fine since this is upgrade code
+# and it heavily relies on repository being revlog based
+# hence accessing private attributes can be justified
+nodemap.persist_nodemap(
+tr, unfi.manifestlog._rootstore._revlog, force=True
+)
 scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
 else:
 with dstrepo.transaction(b'upgrade') as tr:



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


D9936: upgrade: implement partial upgrade for upgrading persistent-nodemap

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

REVISION SUMMARY
  Upgrading repositories to use persistent nodemap should be fast and easy as it
  requires only two things:
  
  1. Updating the requirements
  2. Writing a persistent-nodemap on disk
  
  For both of the steps above, we don't need to edit existing revlogs.
  
  This patch makes upgrade only do the above mentioned two steps if we are
  only upgarding to use persistent-nodemap feature.
  
  Since `nodemap.persist_nodemap()` assumes that there exists a nodemap file for
  the given revlog if we are trying to call it, this patch adds `force` argument
  to create a file if does not exist which is true in our upgrade case.
  
  The test changes demonstrate that we no longer write nodemap files for 
manifest
  after upgrade which I think is desirable.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/revlogutils/nodemap.py
  mercurial/upgrade_utils/engine.py
  tests/test-persistent-nodemap.t

CHANGE DETAILS

diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t
--- a/tests/test-persistent-nodemap.t
+++ b/tests/test-persistent-nodemap.t
@@ -636,28 +636,11 @@
   repository locked and read-only
   creating temporary repository to stage upgraded data: 
$TESTTMP/test-repo/.hg/upgrade.* (glob)
   (it is safe to interrupt this process any time before data migration 
completes)
-  migrating 15018 total revisions (5006 in filelogs, 5006 in manifests, 5006 
in changelog)
-  migrating 1.74 MB in store; 569 MB tracked data
-  migrating 5004 filelogs containing 5006 revisions (346 KB in store; 28.2 KB 
tracked data)
-  finished migrating 5006 filelog revisions across 5004 filelogs; change in 
size: 0 bytes
-  migrating 1 manifests containing 5006 revisions (765 KB in store; 569 MB 
tracked data)
-  finished migrating 5006 manifest revisions across 1 manifests; change in 
size: 0 bytes
-  migrating changelog containing 5006 revisions (673 KB in store; 363 KB 
tracked data)
-  finished migrating 5006 changelog revisions; change in size: 0 bytes
-  finished migrating 15018 total revisions; total change in store size: 0 bytes
-  copying phaseroots
-  data fully upgraded in a temporary repository
-  marking source repository as being upgraded; clients will be unable to read 
from repository
-  starting in-place swap of repository data
-  replacing store...
-  store replacement complete; repository was inconsistent for *s (glob)
-  finalizing requirements file and making repository readable again
+  upgrading repository to use persistent nodemap feature
   removing temporary repository $TESTTMP/test-repo/.hg/upgrade.* (glob)
   $ ls -1 .hg/store/ | egrep '00(changelog|manifest)(\.n|-.*\.nd)'
   00changelog-*.nd (glob)
   00changelog.n
-  00manifest-*.nd (glob)
-  00manifest.n
 
   $ hg debugnodemap --metadata
   uid: * (glob)
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
@@ -24,6 +24,7 @@
 util,
 vfs as vfsmod,
 )
+from ..revlogutils import nodemap
 
 
 def _revlogfrompath(repo, path):
@@ -452,6 +453,22 @@
 if upgrade_op.requirements_only:
 ui.status(_(b'upgrading repository requirements\n'))
 scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
+# if there is only one action and that is persistent nodemap upgrade
+# directly write the nodemap file and update requirements instead of going
+# through the whole cloning process
+elif (
+len(upgrade_op.upgrade_actions) == 1
+and b'persistent-nodemap' in upgrade_op._upgrade_actions_names
+and not upgrade_op.removed_actions
+):
+ui.status(
+_(b'upgrading repository to use persistent nodemap feature\n')
+)
+with srcrepo.transaction(b'upgrade') as tr:
+unfi = srcrepo.unfiltered()
+cl = unfi.changelog
+nodemap.persist_nodemap(tr, cl, force=True)
+scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
 else:
 with dstrepo.transaction(b'upgrade') as tr:
 _clonerevlogs(
diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py
+++ b/mercurial/revlogutils/nodemap.py
@@ -128,15 +128,20 @@
 notr._postclose[k](None)
 
 
-def persist_nodemap(tr, revlog, pending=False):
+def persist_nodemap(tr, revlog, pending=False, force=False):
 """Write nodemap data on disk for a given revlog"""
 if getattr(revlog, 'filteredrevs', ()):
 raise error.ProgrammingError(
 "cannot persist nodemap of a filtered changelog"
 )
 if revlog.nodemap_file is None:
-msg = "calling persist nodemap on a revlog without the feature enabled"
-raise 

D9933: revlog: refactor logic to compute nodemap file in separate function

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

REVISION SUMMARY
  I will like to use it one more place.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/revlog.py
  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
@@ -634,3 +634,14 @@
 if isinstance(entry, dict):
 return _find_node(entry, node[1:])
 return entry
+
+
+def get_nodemap_file(opener, indexfile):
+if indexfile.endswith(b'.a'):
+pending_path = indexfile[:-4] + b".n.a"
+if opener.exists(pending_path):
+return pending_path
+else:
+return indexfile[:-4] + b".n"
+else:
+return indexfile[:-2] + b".n"
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -448,14 +448,9 @@
 self.datafile = datafile or (indexfile[:-2] + b".d")
 self.nodemap_file = None
 if persistentnodemap:
-if indexfile.endswith(b'.a'):
-pending_path = indexfile[:-4] + b".n.a"
-if opener.exists(pending_path):
-self.nodemap_file = pending_path
-else:
-self.nodemap_file = indexfile[:-4] + b".n"
-else:
-self.nodemap_file = indexfile[:-2] + b".n"
+self.nodemap_file = nodemaputil.get_nodemap_file(
+opener, self.indexfile
+)
 
 self.opener = opener
 #  When True, indexfile is opened with checkambig=True at writing, to



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


D9930: debugcommands: s/stdin/stdout in debugnodemap help

2021-01-31 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/D9930

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
@@ -2212,9 +2212,9 @@
 b'',
 b'dump-new',
 False,
-_(b'write a (new) persistent binary nodemap on stdin'),
+_(b'write a (new) persistent binary nodemap on stdout'),
 ),
-(b'', b'dump-disk', False, _(b'dump on-disk data on stdin')),
+(b'', b'dump-disk', False, _(b'dump on-disk data on stdout')),
 (
 b'',
 b'check',



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


D9935: tests: unquiet a test to show changes in next patch

2021-01-31 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/D9935

AFFECTED FILES
  tests/test-persistent-nodemap.t

CHANGE DETAILS

diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t
--- a/tests/test-persistent-nodemap.t
+++ b/tests/test-persistent-nodemap.t
@@ -617,18 +617,42 @@
   plain-cl-delta: yesyes yes
   compression:zlib   zlibzlib
   compression-level:  default default default
-  $ hg debugupgraderepo --run --no-backup --quiet
+  $ hg debugupgraderepo --run --no-backup
   upgrade will perform the following actions:
   
   requirements
  preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
  added: persistent-nodemap
   
+  persistent-nodemap
+ Speedup revision lookup by node id.
+  
   processed revlogs:
 - all-filelogs
 - changelog
 - manifest
   
+  beginning upgrade...
+  repository locked and read-only
+  creating temporary repository to stage upgraded data: 
$TESTTMP/test-repo/.hg/upgrade.* (glob)
+  (it is safe to interrupt this process any time before data migration 
completes)
+  migrating 15018 total revisions (5006 in filelogs, 5006 in manifests, 5006 
in changelog)
+  migrating 1.74 MB in store; 569 MB tracked data
+  migrating 5004 filelogs containing 5006 revisions (346 KB in store; 28.2 KB 
tracked data)
+  finished migrating 5006 filelog revisions across 5004 filelogs; change in 
size: 0 bytes
+  migrating 1 manifests containing 5006 revisions (765 KB in store; 569 MB 
tracked data)
+  finished migrating 5006 manifest revisions across 1 manifests; change in 
size: 0 bytes
+  migrating changelog containing 5006 revisions (673 KB in store; 363 KB 
tracked data)
+  finished migrating 5006 changelog revisions; change in size: 0 bytes
+  finished migrating 15018 total revisions; total change in store size: 0 bytes
+  copying phaseroots
+  data fully upgraded in a temporary repository
+  marking source repository as being upgraded; clients will be unable to read 
from repository
+  starting in-place swap of repository data
+  replacing store...
+  store replacement complete; repository was inconsistent for *s (glob)
+  finalizing requirements file and making repository readable again
+  removing temporary repository $TESTTMP/test-repo/.hg/upgrade.* (glob)
   $ ls -1 .hg/store/ | egrep '00(changelog|manifest)(\.n|-.*\.nd)'
   00changelog-*.nd (glob)
   00changelog.n



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


D9934: nodemap: fix a typo in error message

2021-01-31 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/D9934

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
@@ -135,7 +135,7 @@
 "cannot persist nodemap of a filtered changelog"
 )
 if revlog.nodemap_file is None:
-msg = "calling persist nodemap on a revlog without the feature enableb"
+msg = "calling persist nodemap on a revlog without the feature enabled"
 raise error.ProgrammingError(msg)
 
 can_incremental = util.safehasattr(revlog.index, 
"nodemap_data_incremental")



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


D9932: nodemap: make `_persist_nodemap` a public function

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

REVISION SUMMARY
  I will like to have a utility function using which we can directly write out
  nodemap for a repository without going through the recloning process. This
  function seems like the one containing important pieces for that. Let's make 
it
  public.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -81,9 +81,9 @@
 if tr.hasfinalize(callback_id):
 return  # no need to register again
 tr.addpending(
-callback_id, lambda tr: _persist_nodemap(tr, revlog, pending=True)
+callback_id, lambda tr: persist_nodemap(tr, revlog, pending=True)
 )
-tr.addfinalize(callback_id, lambda tr: _persist_nodemap(tr, revlog))
+tr.addfinalize(callback_id, lambda tr: persist_nodemap(tr, revlog))
 
 
 class _NoTransaction(object):
@@ -123,12 +123,12 @@
 return  # we do not use persistent_nodemap on this revlog
 
 notr = _NoTransaction()
-_persist_nodemap(notr, revlog)
+persist_nodemap(notr, revlog)
 for k in sorted(notr._postclose):
 notr._postclose[k](None)
 
 
-def _persist_nodemap(tr, revlog, pending=False):
+def persist_nodemap(tr, revlog, pending=False):
 """Write nodemap data on disk for a given revlog"""
 if getattr(revlog, 'filteredrevs', ()):
 raise error.ProgrammingError(



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


D9931: engine: 'if not, else' -> 'if, else'

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

REVISION SUMMARY
  I personally feel that
  
if x:
pass
else:
pass
  
  is easier to read and edit than
  
if not x:
pass
else:
pass
  
  Next patches will add one more if-else clause.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -449,7 +449,10 @@
 )
 )
 
-if not upgrade_op.requirements_only:
+if upgrade_op.requirements_only:
+ui.status(_(b'upgrading repository requirements\n'))
+scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
+else:
 with dstrepo.transaction(b'upgrade') as tr:
 _clonerevlogs(
 ui,
@@ -532,8 +535,5 @@
 # could update srcrepo.svfs and other variables to point to the new
 # location. This is simpler.
 backupvfs.unlink(b'store/lock')
-else:
-ui.status(_(b'upgrading repository requirements\n'))
-scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
 
 return backuppath



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


D9824: share: make different options for upgrade and downgrade share-safe

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

REVISION SUMMARY
  This makes things more configurable.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/helptext/config.txt
  mercurial/localrepo.py
  mercurial/upgrade.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -486,12 +486,12 @@
 Testing automatic downgrade of shares when config is set
 
   $ touch ../ss-share/.hg/wlock
-  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config 
share.source-safe-mismatch=upgrade-abort
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config 
share.safe-mismatch.source-not-safe=downgrade-abort
   abort: failed to downgrade share, got error: Lock held
   [255]
   $ rm ../ss-share/.hg/wlock
 
-  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config 
share.source-safe-mismatch=upgrade-abort
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config 
share.safe-mismatch.source-not-safe=downgrade-abort
   repository downgraded to not use share-safe mode
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
@@ -533,31 +533,31 @@
   [255]
 
 Check that if lock is taken, upgrade fails but read operation are successful
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgra
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.safe-mismatch.source-safe=upgra
   abort: share-safe mismatch with source.
-  Unrecognized value 'upgra' of `share.source-safe-mismatch` set.
-  (run `hg help config.share.source-safe-mismatch`)
+  Unrecognized value 'upgra' of `share.safe-mismatch.source-safe` set.
+  (run `hg help config.share.safe-mismatch.source-safe`)
   [255]
   $ touch ../nss-share/.hg/wlock
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-allow
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.safe-mismatch.source-safe=upgrade-allow
   failed to upgrade share, got error: Lock held
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
 
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-allow --config 
share.source-safe-mismatch.warn=False
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.safe-mismatch.source-safe=upgrade-allow --config 
share.source-safe-mismatch.warn=False
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
 
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-abort
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.safe-mismatch.source-safe=upgrade-abort
   abort: failed to upgrade share, got error: Lock held
   [255]
 
   $ rm ../nss-share/.hg/wlock
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-abort
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.safe-mismatch.source-safe=upgrade-abort
   repository upgraded to use share-safe mode
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -340,7 +340,7 @@
 except error.LockError as e:
 # If upgrade-abort is set, abort when upgrade fails, else let the
 # process continue as `upgrade-allow` is set
-if mismatch_config == b'upgrade-abort':
+if mismatch_config == b'downgrade-abort':
 raise error.Abort(
 _(b'failed to downgrade share, got error: %s')
 % stringutil.forcebytestr(e.strerror)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -568,7 +568,6 @@
 # repository was shared the old way. We check the share source .hg/requires
 # for SHARESAFE_REQUIREMENT to detect whether the current repository needs
 # to be reshared
-mismatch_config = ui.config(b'share', b'source-safe-mismatch')
 mismatch_warn = ui.configbool(b'share', b'source-safe-mismatch.warn')
 if requirementsmod.SHARESAFE_REQUIREMENT in requirements:
 
@@ -577,10 +576,13 @@
 and requirementsmod.SHARESAFE_REQUIREMENT
 not in _readrequires(sharedvfs, True)
 ):
+mismatch_config = ui.config(
+b'share', b'safe-mismatch.source-not-safe'
+)
 if mismatch_config in (
-b'upgrade-allow',
+b'downgrade-allow',
 b'allow',
-b'upgrade-abort',
+b'downgrade-abort',
 ):
 # prevent cyclic import 

D9823: share: move share safe functionality out of experimental

2021-01-18 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
pulkit updated this revision to Diff 25119.

REVISION SUMMARY
  The share-safe functionality is complete and all configuration options are
  implemented. The behavior is well discussed on mailing list and in reviews.
  
  Let's unmark this as experimental to solve a chichen and egg issue.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/helptext/config.txt
  mercurial/helptext/internals/requirements.txt
  mercurial/localrepo.py
  mercurial/requirements.py
  mercurial/upgrade_utils/actions.py
  tests/test-copies-chain-merge.t
  tests/test-copies-in-changeset.t
  tests/test-help.t
  tests/test-persistent-nodemap.t
  tests/test-share-bookmarks.t
  tests/test-share-safe.t
  tests/test-share.t
  tests/test-sidedata.t
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -56,7 +56,7 @@
   fncache:yes
   dotencode:  yes
   generaldelta:   yes
-  exp-sharesafe:   no
+  share-safe:  no
   sparserevlog:   yes
   sidedata:no
   persistent-nodemap:  no
@@ -69,7 +69,7 @@
   fncache:yesyes yes
   dotencode:  yesyes yes
   generaldelta:   yesyes yes
-  exp-sharesafe:   no no  no
+  share-safe:  no no  no
   sparserevlog:   yesyes yes
   sidedata:no no  no
   persistent-nodemap:  no no  no
@@ -82,7 +82,7 @@
   fncache:yes no yes
   dotencode:  yes no yes
   generaldelta:   yesyes yes
-  exp-sharesafe:   no no  no
+  share-safe:  no no  no
   sparserevlog:   yesyes yes
   sidedata:no no  no
   persistent-nodemap:  no no  no
@@ -95,7 +95,7 @@
   [formatvariant.name.mismatchconfig|fncache:   
][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special| 
no][formatvariant.default| yes]
   [formatvariant.name.mismatchconfig|dotencode: 
][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special| 
no][formatvariant.default| yes]
   [formatvariant.name.uptodate|generaldelta:  
][formatvariant.repo.uptodate| yes][formatvariant.config.default|
yes][formatvariant.default| yes]
-  [formatvariant.name.uptodate|exp-sharesafe: 
][formatvariant.repo.uptodate|  no][formatvariant.config.default| 
no][formatvariant.default|  no]
+  [formatvariant.name.uptodate|share-safe:
][formatvariant.repo.uptodate|  no][formatvariant.config.default| 
no][formatvariant.default|  no]
   [formatvariant.name.uptodate|sparserevlog:  
][formatvariant.repo.uptodate| yes][formatvariant.config.default|
yes][formatvariant.default| yes]
   [formatvariant.name.uptodate|sidedata:  
][formatvariant.repo.uptodate|  no][formatvariant.config.default| 
no][formatvariant.default|  no]
   
[formatvariant.name.uptodate|persistent-nodemap:][formatvariant.repo.uptodate|  
no][formatvariant.config.default| no][formatvariant.default|  no]
@@ -126,7 +126,7 @@
{
 "config": false,
 "default": false,
-"name": "exp-sharesafe",
+"name": "share-safe",
 "repo": false
},
{
@@ -301,7 +301,7 @@
   fncache: no
   dotencode:   no
   generaldelta:no
-  exp-sharesafe:   no
+  share-safe:  no
   sparserevlog:no
   sidedata:no
   persistent-nodemap:  no
@@ -314,7 +314,7 @@
   fncache: noyes yes
   dotencode:   noyes yes
   generaldelta:noyes yes
-  exp-sharesafe:   no no  no
+  share-safe:  no no  no
   sparserevlog:noyes yes
   sidedata:no no  no
   persistent-nodemap:  no no  no
@@ -327,7 +327,7 @@
   fncache: noyes yes
   dotencode:   noyes yes
   generaldelta:no no yes
-  exp-sharesafe:   no no  no
+  share-safe:  no no  no
   sparserevlog:no no yes
   sidedata:no no  no
   persistent-nodemap:  no no  no
@@ -340,7 +340,7 @@
   [formatvariant.name.mismatchconfig|fncache:   
][formatvariant.repo.mismatchconfig|  no][formatvariant.config.default|
yes][formatvariant.default| yes]
   [formatvariant.name.mismatchconfig|dotencode: 
][formatvariant.repo.mismatchconfig|  no][formatvariant.config.default|
yes][formatvariant.default| yes]
   [formatvariant.name.mismatchdefault|generaldelta:  
][formatvariant.repo.mismatchdefault|  no][formatvariant.config.special| 

D9822: upgrade: re-read current requirements after taking lock

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

REVISION SUMMARY
  Since we are writing to repository, it's better to re-read after taking the
  lock.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py

CHANGE DETAILS

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -254,6 +254,19 @@
 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
 try:
 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
+# some process might change the requirement in between, re-read
+# and update current_requirements
+locked_requirements = localrepo._readrequires(hgvfs, True)
+if locked_requirements >= current_requirements and 
current_requirements >= locked_requirements:
+removed = current_requirements - locked_requirements
+# update current_requirements in place because it's passed
+# as reference
+current_requirements -= removed
+current_requirements |= locked_requirements
+diffrequires = current_requirements - store_requirements
+# add share-safe requirement as it will mark the share as 
share-safe
+diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
+current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
 scmutil.writerequires(hgvfs, diffrequires)
 ui.warn(_(b'repository upgraded to use share-safe mode\n'))
 except error.LockError as e:
@@ -290,6 +303,17 @@
 
 try:
 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
+# some process might change the requirement in between, re-read
+# and update current_requirements
+locked_requirements = localrepo._readrequires(hgvfs, True)
+if locked_requirements >= current_requirements and 
current_requirements >= locked_requirements:
+removed = current_requirements - locked_requirements
+# update current_requirements in place because it's passed
+# as reference
+current_requirements -= removed
+current_requirements |= locked_requirements
+current_requirements |= source_requirements
+current_requirements -= set(requirementsmod.SHARESAFE_REQUIREMENT)
 scmutil.writerequires(hgvfs, current_requirements)
 ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
 except error.LockError as e:



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


D9786: share: rename share-safe warning config

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

REVISION SUMMARY
  Config introduced in previous patch was `share.source-safe-mismatch`. Let's
  rename the warn as `share.source-safe-mismatch.warn`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  mercurial/upgrade.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -539,7 +539,7 @@
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
 
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-allow --config 
experimental.sharesafe-warn-outdated-shares=false
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-allow --config 
share.source-safe-mismatch.warn=False
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -242,7 +242,12 @@
 
 
 def upgrade_share_to_safe(
-ui, hgvfs, storevfs, current_requirements, mismatch_config
+ui,
+hgvfs,
+storevfs,
+current_requirements,
+mismatch_config,
+mismatch_warn,
 ):
 """Upgrades a share to use share-safe mechanism"""
 wlock = None
@@ -268,7 +273,7 @@
 _(b'failed to upgrade share, got error: %s')
 % stringutil.forcebytestr(e.strerror)
 )
-elif ui.configbool(b'experimental', b'sharesafe-warn-outdated-shares'):
+elif mismatch_warn:
 ui.warn(
 _(b'failed to upgrade share, got error: %s\n')
 % stringutil.forcebytestr(e.strerror)
@@ -284,6 +289,7 @@
 sharedvfs,
 current_requirements,
 mismatch_config,
+mismatch_warn,
 ):
 """Downgrades a share which use share-safe to not use it"""
 wlock = None
@@ -311,6 +317,11 @@
 _(b'failed to downgrade share, got error: %s')
 % stringutil.forcebytestr(e.strerror)
 )
+elif mismatch_warn:
+ui.warn(
+_(b'failed to downgrade share, got error: %s\n')
+% stringutil.forcebytestr(e.strerror)
+)
 finally:
 if wlock:
 wlock.release()
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -568,6 +568,7 @@
 # for SHARESAFE_REQUIREMENT to detect whether the current repository needs
 # to be reshared
 mismatch_config = ui.config(b'share', b'source-safe-mismatch')
+mismatch_warn = ui.configbool(b'share', b'source-safe-mismatch.warn')
 if requirementsmod.SHARESAFE_REQUIREMENT in requirements:
 
 if (
@@ -589,6 +590,7 @@
 sharedvfs,
 requirements,
 mismatch_config,
+mismatch_warn,
 )
 elif mismatch_config == b'abort':
 raise error.Abort(
@@ -622,6 +624,7 @@
 storevfs,
 requirements,
 mismatch_config,
+mismatch_warn,
 )
 elif mismatch_config == b'abort':
 raise error.Abort(
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1074,11 +1074,6 @@
 )
 coreconfigitem(
 b'experimental',
-b'sharesafe-warn-outdated-shares',
-default=True,
-)
-coreconfigitem(
-b'experimental',
 b'single-head-per-branch',
 default=False,
 )
@@ -1888,6 +1883,11 @@
 default=b'abort',
 )
 coreconfigitem(
+b'share',
+b'source-safe-mismatch.warn',
+default=True,
+)
+coreconfigitem(
 b'shelve',
 b'maxbackups',
 default=10,



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


D9785: share: collapse 3 different bool configs into one enum config

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

REVISION SUMMARY
  Recently I implemented various boolean configs which control how to behave 
when
  there is a share-safe mismatch between source and share repository. Mismatch
  means that source supports share-safe where as share does not or vice versa.
  
  However, while discussion and documentation we realized that it's too
  complicated and there are some combinations of values which makes no sense.
  
  We decided to introduce a single config option with 4 possible values which
  makes controlling and understanding things easier.
  
  The config option `share.source-safe-mismatch` can have following 4 values:
  
  - abort (default): error out if there is mismatch
  - allow: allow to work with respecting share source configuration
  - upgrade-abort: try to upgrade, if it fails, abort
  - upgrade-allow: try to upgrade, if it fails, continue in allow mode
  
  I am not sure if I can explain 3 config options which I deleted right now in
  just 5 lines which is a sign of how complex they became.
  
  No test changes demonstrate that functionality is same, only names have 
changed.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  mercurial/upgrade.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -484,12 +484,12 @@
 Testing automatic downgrade of shares when config is set
 
   $ touch ../ss-share/.hg/wlock
-  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config 
experimental.sharesafe-auto-downgrade-shares=true
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config 
share.source-safe-mismatch=upgrade-abort
   abort: failed to downgrade share, got error: Lock held
   [255]
   $ rm ../ss-share/.hg/wlock
 
-  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config 
experimental.sharesafe-auto-downgrade-shares=true
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config 
share.source-safe-mismatch=upgrade-abort
   repository downgraded to not use share-safe mode
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
@@ -532,25 +532,25 @@
 
 Check that if lock is taken, upgrade fails but read operation are successful
   $ touch ../nss-share/.hg/wlock
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-auto-upgrade-shares=true
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-allow
   failed to upgrade share, got error: Lock held
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
 
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-auto-upgrade-shares=true --config 
experimental.sharesafe-warn-outdated-shares=false
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-allow --config 
experimental.sharesafe-warn-outdated-shares=false
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
 
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-auto-upgrade-shares=true --config 
experimental.sharesafe-auto-upgrade-fail-error=true
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-abort
   abort: failed to upgrade share, got error: Lock held
   [255]
 
   $ rm ../nss-share/.hg/wlock
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-auto-upgrade-shares=true
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
share.source-safe-mismatch=upgrade-abort
   repository upgraded to use share-safe mode
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
   |
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -241,7 +241,9 @@
 upgrade_op.print_post_op_messages()
 
 
-def upgrade_share_to_safe(ui, hgvfs, storevfs, current_requirements):
+def upgrade_share_to_safe(
+ui, hgvfs, storevfs, current_requirements, mismatch_config
+):
 """Upgrades a share to use share-safe mechanism"""
 wlock = None
 store_requirements = localrepo._readrequires(storevfs, False)
@@ -252,12 +254,16 @@
 # add share-safe requirement as it will mark the share as share-safe
 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
+# in `allow` case, we don't try to upgrade, we just respect the source
+# state, update requirements and continue
+if mismatch_config == b'allow':
+return
 try:
 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
 

D9784: localrepo: disallow share if there is a version mismatch by default

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

REVISION SUMMARY
  Earlier we used to allow shares which don't use share-safe mechanism to access
  repository which uses share-safe mechanism. This defeats the purpose and is 
bad
  behavior. This patch disallows that.
  
  Next patch will introduce a config option to allow that and have clearer
  understanding around various options.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/localrepo.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -390,20 +390,11 @@
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
 
-Make sure existing shares still works
-
-  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-warn-outdated-shares=false
-  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
-  |
-  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
-  
+Make sure existing shares dont work with default config
 
   $ hg log -GT "{node}: {desc}\n" -R ../nss-share
-  warning: source repository supports share-safe functionality. Reshare to 
upgrade.
-  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
-  |
-  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
-  
+  abort: version mismatch: source use share-safe functionality while current 
share does not
+  [255]
 
 
 Create a safe share from upgrade one
@@ -536,11 +527,8 @@
   sparserevlog
   store
   $ hg log -GT "{node}: {desc}\n" -R ../nss-share
-  warning: source repository supports share-safe functionality. Reshare to 
upgrade.
-  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
-  |
-  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
-  
+  abort: version mismatch: source use share-safe functionality while current 
share does not
+  [255]
 
 Check that if lock is taken, upgrade fails but read operation are successful
   $ touch ../nss-share/.hg/wlock
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -607,13 +607,11 @@
 storevfs,
 requirements,
 )
-elif ui.configbool(
-b'experimental', b'sharesafe-warn-outdated-shares'
-):
-ui.warn(
+else:
+raise error.Abort(
 _(
-b'warning: source repository supports share-safe 
functionality.'
-b' Reshare to upgrade.\n'
+b'version mismatch: source use share-safe'
+b' functionality while current share does not'
 )
 )
 



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


D9783: upgrade: take lock only for part where it's required

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

REVISION SUMMARY
  The final config calculation code does not require a lock, only writing it 
back
  does require one.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py

CHANGE DETAILS

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -244,17 +244,17 @@
 def upgrade_share_to_safe(ui, hgvfs, storevfs, current_requirements):
 """Upgrades a share to use share-safe mechanism"""
 wlock = None
+store_requirements = localrepo._readrequires(storevfs, False)
+# after upgrade, store requires will be shared, so lets find
+# the requirements which are not present in store and
+# write them to share's .hg/requires
+diffrequires = current_requirements - store_requirements
+# add share-safe requirement as it will mark the share as share-safe
+diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
+current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
 try:
 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
-store_requirements = localrepo._readrequires(storevfs, False)
-# after upgrade, store requires will be shared, so lets find
-# the requirements which are not present in store and
-# write them to share's .hg/requires
-diffrequires = current_requirements - store_requirements
-# add share-safe requirement as it will mark the share as share-safe
-diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
 scmutil.writerequires(hgvfs, diffrequires)
-current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
 ui.warn(_(b'repository upgraded to use share-safe mode\n'))
 except error.LockError as e:
 if ui.configbool(b'experimental', 
b'sharesafe-auto-upgrade-fail-error'):
@@ -280,15 +280,16 @@
 ):
 """Downgrades a share which use share-safe to not use it"""
 wlock = None
+source_requirements = localrepo._readrequires(sharedvfs, True)
+# we cannot be 100% sure on which requirements were present in store when
+# the source supported share-safe. However, we do know that working
+# directory requirements were not there. Hence we remove them
+source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS
+current_requirements |= source_requirements
+current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT)
+
 try:
 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
-source_requirements = localrepo._readrequires(sharedvfs, True)
-# we cannot be 100% sure on which requirements were present in store 
when
-# the source supported share-safe. However, we do know that working
-# directory requirements were not there. Hence we remove them
-source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS
-current_requirements |= source_requirements
-current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT)
 scmutil.writerequires(hgvfs, current_requirements)
 ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
 except error.LockError as e:



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


D9775: upgrade: update only requirements if we can

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

REVISION SUMMARY
  Upgrade operations which involves just upgrading requirements earlier used to 
go
  through whole revlog cloning business.
  Now we just upgrade the requirement and skip the cloning part.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/engine.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -369,26 +369,8 @@
   repository locked and read-only
   creating temporary repository to stage upgraded data: 
$TESTTMP/non-share-safe/.hg/upgrade.* (glob)
   (it is safe to interrupt this process any time before data migration 
completes)
-  migrating 6 total revisions (2 in filelogs, 2 in manifests, 2 in changelog)
-  migrating 626 bytes in store; 271 bytes tracked data
-  migrating 2 filelogs containing 2 revisions (138 bytes in store; 8 bytes 
tracked data)
-  finished migrating 2 filelog revisions across 2 filelogs; change in size: 0 
bytes
-  migrating 1 manifests containing 2 revisions (230 bytes in store; 135 bytes 
tracked data)
-  finished migrating 2 manifest revisions across 1 manifests; change in size: 
0 bytes
-  migrating changelog containing 2 revisions (258 bytes in store; 128 bytes 
tracked data)
-  finished migrating 2 changelog revisions; change in size: 0 bytes
-  finished migrating 6 total revisions; total change in store size: 0 bytes
-  copying phaseroots
-  data fully upgraded in a temporary repository
-  marking source repository as being upgraded; clients will be unable to read 
from repository
-  starting in-place swap of repository data
-  replaced files will be backed up at 
$TESTTMP/non-share-safe/.hg/upgradebackup.* (glob)
-  replacing store...
-  store replacement complete; repository was inconsistent for *s (glob)
-  finalizing requirements file and making repository readable again
+  upgrading repository requirements
   removing temporary repository $TESTTMP/non-share-safe/.hg/upgrade.* (glob)
-  copy of old repository backed up at 
$TESTTMP/non-share-safe/.hg/upgradebackup.* (glob)
-  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified
   repository upgraded to share safe mode, existing shares will still work in 
old non-safe mode. Re-share existing shares to use them in safe mode New shares 
will be created in safe mode.
 
   $ hg debugrequirements
@@ -482,27 +464,8 @@
   repository locked and read-only
   creating temporary repository to stage upgraded data: 
$TESTTMP/non-share-safe/.hg/upgrade.* (glob)
   (it is safe to interrupt this process any time before data migration 
completes)
-  migrating 6 total revisions (2 in filelogs, 2 in manifests, 2 in changelog)
-  migrating 626 bytes in store; 271 bytes tracked data
-  migrating 2 filelogs containing 2 revisions (138 bytes in store; 8 bytes 
tracked data)
-  finished migrating 2 filelog revisions across 2 filelogs; change in size: 0 
bytes
-  migrating 1 manifests containing 2 revisions (230 bytes in store; 135 bytes 
tracked data)
-  finished migrating 2 manifest revisions across 1 manifests; change in size: 
0 bytes
-  migrating changelog containing 2 revisions (258 bytes in store; 128 bytes 
tracked data)
-  finished migrating 2 changelog revisions; change in size: 0 bytes
-  finished migrating 6 total revisions; total change in store size: 0 bytes
-  copying phaseroots
-  copying requires
-  data fully upgraded in a temporary repository
-  marking source repository as being upgraded; clients will be unable to read 
from repository
-  starting in-place swap of repository data
-  replaced files will be backed up at 
$TESTTMP/non-share-safe/.hg/upgradebackup.* (glob)
-  replacing store...
-  store replacement complete; repository was inconsistent for *s (glob)
-  finalizing requirements file and making repository readable again
+  upgrading repository requirements
   removing temporary repository $TESTTMP/non-share-safe/.hg/upgrade.* (glob)
-  copy of old repository backed up at 
$TESTTMP/non-share-safe/.hg/upgradebackup.* (glob)
-  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified
   repository downgraded to not use share safe mode, existing shares will not 
work and needs to be reshared.
 
   $ hg debugrequirements
@@ -585,26 +548,8 @@
   repository locked and read-only
   creating temporary repository to stage upgraded data: 
$TESTTMP/non-share-safe/.hg/upgrade.* (glob)
   (it is safe to interrupt this process any time before data migration 
completes)
-  migrating 6 total revisions (2 in filelogs, 2 in manifests, 2 in changelog)
-  migrating 626 bytes in store; 271 bytes tracked data
-  migrating 2 filelogs containing 2 revisions (138 bytes in store; 8 

D9774: engine: add `if True` to prepare for next patch

2021-01-14 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 making next patch easier to read.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -477,78 +477,81 @@
 )
 )
 
-with dstrepo.transaction(b'upgrade') as tr:
-_clonerevlogs(
-ui,
-srcrepo,
-dstrepo,
-tr,
-upgrade_op,
-)
+if True:
+with dstrepo.transaction(b'upgrade') as tr:
+_clonerevlogs(
+ui,
+srcrepo,
+dstrepo,
+tr,
+upgrade_op,
+)
+
+# Now copy other files in the store directory.
+for p in _files_to_copy_post_revlog_clone(srcrepo):
+srcrepo.ui.status(_(b'copying %s\n') % p)
+src = srcrepo.store.rawvfs.join(p)
+dst = dstrepo.store.rawvfs.join(p)
+util.copyfile(src, dst, copystat=True)
+
+finishdatamigration(ui, srcrepo, dstrepo, requirements)
+
+ui.status(_(b'data fully upgraded in a temporary repository\n'))
 
-# Now copy other files in the store directory.
-for p in _files_to_copy_post_revlog_clone(srcrepo):
-srcrepo.ui.status(_(b'copying %s\n') % p)
-src = srcrepo.store.rawvfs.join(p)
-dst = dstrepo.store.rawvfs.join(p)
-util.copyfile(src, dst, copystat=True)
+if upgrade_op.backup_store:
+backuppath = pycompat.mkdtemp(
+prefix=b'upgradebackup.', dir=srcrepo.path
+)
+backupvfs = vfsmod.vfs(backuppath)
 
-finishdatamigration(ui, srcrepo, dstrepo, requirements)
+# Make a backup of requires file first, as it is the first to be 
modified.
+util.copyfile(
+srcrepo.vfs.join(b'requires'), backupvfs.join(b'requires')
+)
 
-ui.status(_(b'data fully upgraded in a temporary repository\n'))
-
-if upgrade_op.backup_store:
-backuppath = pycompat.mkdtemp(
-prefix=b'upgradebackup.', dir=srcrepo.path
+# We install an arbitrary requirement that clients must not support
+# as a mechanism to lock out new clients during the data swap. This is
+# better than allowing a client to continue while the repository is in
+# an inconsistent state.
+ui.status(
+_(
+b'marking source repository as being upgraded; clients will be 
'
+b'unable to read from repository\n'
+)
 )
-backupvfs = vfsmod.vfs(backuppath)
-
-# Make a backup of requires file first, as it is the first to be 
modified.
-util.copyfile(
-srcrepo.vfs.join(b'requires'), backupvfs.join(b'requires')
+scmutil.writereporequirements(
+srcrepo, srcrepo.requirements | {b'upgradeinprogress'}
 )
 
-# We install an arbitrary requirement that clients must not support
-# as a mechanism to lock out new clients during the data swap. This is
-# better than allowing a client to continue while the repository is in
-# an inconsistent state.
-ui.status(
-_(
-b'marking source repository as being upgraded; clients will be '
-b'unable to read from repository\n'
-)
-)
-scmutil.writereporequirements(
-srcrepo, srcrepo.requirements | {b'upgradeinprogress'}
-)
-
-ui.status(_(b'starting in-place swap of repository data\n'))
-if upgrade_op.backup_store:
-ui.status(_(b'replaced files will be backed up at %s\n') % backuppath)
+ui.status(_(b'starting in-place swap of repository data\n'))
+if upgrade_op.backup_store:
+ui.status(_(b'replaced files will be backed up at %s\n') % 
backuppath)
 
-# Now swap in the new store directory. Doing it as a rename should make
-# the operation nearly instantaneous and atomic (at least in well-behaved
-# environments).
-ui.status(_(b'replacing store...\n'))
-tstart = util.timer()
-_replacestores(srcrepo, dstrepo, backupvfs, upgrade_op)
-elapsed = util.timer() - tstart
-ui.status(
-_(
-b'store replacement complete; repository was inconsistent for '
-b'%0.1fs\n'
+# Now swap in the new store directory. Doing it as a rename should make
+# the operation nearly instantaneous and atomic (at least in 
well-behaved
+# environments).
+ui.status(_(b'replacing store...\n'))
+tstart = util.timer()
+_replacestores(srcrepo, dstrepo, backupvfs, upgrade_op)
+elapsed = util.timer() - 

D9773: test: unquiet few tests to demonstrate changes in upcoming patches

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

REVISION SUMMARY
  Upcoming patches will skip revlog cloning for share-safe upgrades.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -350,18 +350,45 @@
 - changelog
 - manifest
   
-  $ hg debugupgraderepo --run -q
+  $ hg debugupgraderepo --run
   upgrade will perform the following actions:
   
   requirements
  preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
  added: exp-sharesafe
   
+  exp-sharesafe
+ Upgrades a repository to share-safe format so that future shares of this 
repository share its requirements and configs.
+  
   processed revlogs:
 - all-filelogs
 - changelog
 - manifest
   
+  beginning upgrade...
+  repository locked and read-only
+  creating temporary repository to stage upgraded data: 
$TESTTMP/non-share-safe/.hg/upgrade.* (glob)
+  (it is safe to interrupt this process any time before data migration 
completes)
+  migrating 6 total revisions (2 in filelogs, 2 in manifests, 2 in changelog)
+  migrating 626 bytes in store; 271 bytes tracked data
+  migrating 2 filelogs containing 2 revisions (138 bytes in store; 8 bytes 
tracked data)
+  finished migrating 2 filelog revisions across 2 filelogs; change in size: 0 
bytes
+  migrating 1 manifests containing 2 revisions (230 bytes in store; 135 bytes 
tracked data)
+  finished migrating 2 manifest revisions across 1 manifests; change in size: 
0 bytes
+  migrating changelog containing 2 revisions (258 bytes in store; 128 bytes 
tracked data)
+  finished migrating 2 changelog revisions; change in size: 0 bytes
+  finished migrating 6 total revisions; total change in store size: 0 bytes
+  copying phaseroots
+  data fully upgraded in a temporary repository
+  marking source repository as being upgraded; clients will be unable to read 
from repository
+  starting in-place swap of repository data
+  replaced files will be backed up at 
$TESTTMP/non-share-safe/.hg/upgradebackup.* (glob)
+  replacing store...
+  store replacement complete; repository was inconsistent for *s (glob)
+  finalizing requirements file and making repository readable again
+  removing temporary repository $TESTTMP/non-share-safe/.hg/upgrade.* (glob)
+  copy of old repository backed up at 
$TESTTMP/non-share-safe/.hg/upgradebackup.* (glob)
+  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified
   repository upgraded to share safe mode, existing shares will still work in 
old non-safe mode. Re-share existing shares to use them in safe mode New shares 
will be created in safe mode.
 
   $ hg debugrequirements
@@ -439,7 +466,7 @@
 - changelog
 - manifest
   
-  $ hg debugupgraderepo -q --run
+  $ hg debugupgraderepo --run
   upgrade will perform the following actions:
   
   requirements
@@ -451,6 +478,31 @@
 - changelog
 - manifest
   
+  beginning upgrade...
+  repository locked and read-only
+  creating temporary repository to stage upgraded data: 
$TESTTMP/non-share-safe/.hg/upgrade.* (glob)
+  (it is safe to interrupt this process any time before data migration 
completes)
+  migrating 6 total revisions (2 in filelogs, 2 in manifests, 2 in changelog)
+  migrating 626 bytes in store; 271 bytes tracked data
+  migrating 2 filelogs containing 2 revisions (138 bytes in store; 8 bytes 
tracked data)
+  finished migrating 2 filelog revisions across 2 filelogs; change in size: 0 
bytes
+  migrating 1 manifests containing 2 revisions (230 bytes in store; 135 bytes 
tracked data)
+  finished migrating 2 manifest revisions across 1 manifests; change in size: 
0 bytes
+  migrating changelog containing 2 revisions (258 bytes in store; 128 bytes 
tracked data)
+  finished migrating 2 changelog revisions; change in size: 0 bytes
+  finished migrating 6 total revisions; total change in store size: 0 bytes
+  copying phaseroots
+  copying requires
+  data fully upgraded in a temporary repository
+  marking source repository as being upgraded; clients will be unable to read 
from repository
+  starting in-place swap of repository data
+  replaced files will be backed up at 
$TESTTMP/non-share-safe/.hg/upgradebackup.* (glob)
+  replacing store...
+  store replacement complete; repository was inconsistent for *s (glob)
+  finalizing requirements file and making repository readable again
+  removing temporary repository $TESTTMP/non-share-safe/.hg/upgrade.* (glob)
+  copy of old repository backed up at 
$TESTTMP/non-share-safe/.hg/upgradebackup.* (glob)
+  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified
   repository downgraded to not use 

D9770: upgrade: don't create store backup if `--no-backup` is passed

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

REVISION SUMMARY
  If the user explicitly mentioned that they don't need backup, then let's not
  create it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py
  mercurial/upgrade_utils/engine.py
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -628,11 +628,9 @@
   data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
-  replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
   replacing store...
   store replacement complete; repository was inconsistent for * (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ ls -1 .hg/ | grep upgradebackup
   [1]
@@ -675,11 +673,9 @@
   data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
-  replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
 
 Check that the repo still works fine
@@ -755,11 +751,9 @@
   data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
-  replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ hg verify
   checking changesets
@@ -806,11 +800,9 @@
   data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
-  replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ hg verify
   checking changesets
@@ -857,11 +849,9 @@
   data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
-  replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ hg verify
   checking changesets
@@ -915,11 +905,9 @@
   data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
-  replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ hg verify
   checking changesets
@@ -974,11 +962,9 @@
   data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
-  replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable 

D9772: upgrade: mark sharesafe improvement as only touching requirements

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

REVISION SUMMARY
  Upgrading the repository to use share safe functionality only touches
  requirements.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -292,6 +292,12 @@
 b' New shares will be created in safe mode.'
 )
 
+# upgrade only needs to change the requirements
+touches_filelogs = False
+touches_manifests = False
+touches_changelog = False
+touches_requirements = True
+
 
 @registerformatvariant
 class sparserevlog(requirementformatvariant):



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


D9771: actions: calculate what all parts does the operation touches

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

REVISION SUMMARY
  To make upgrade work less in certain situations, we need to teach it to find 
out
  what all parts of repository current operation is touching.
  
  This patch starts doing that. In next patch we will be setting values in
  improvement objects. For now, we assume everything touches everything.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -66,6 +66,18 @@
 postdowngrademessage
Message intended for humans which will be shown post an upgrade
operation in which this improvement was removed
+
+touches_filelogs (bool)
+Whether this improvement touches filelogs
+
+touches_manifests (bool)
+Whether this improvement touches manifests
+
+touches_changelog (bool)
+Whether this improvement touches changelog
+
+touches_requirements (bool)
+Whether this improvement changes repository requirements
 """
 
 def __init__(self, name, type, description, upgrademessage):
@@ -75,6 +87,12 @@
 self.upgrademessage = upgrademessage
 self.postupgrademessage = None
 self.postdowngrademessage = None
+# By default for now, we assume every improvement touches
+# all the things
+self.touches_filelogs = True
+self.touches_manifests = True
+self.touches_changelog = True
+self.touches_requirements = True
 
 def __eq__(self, other):
 if not isinstance(other, improvement):
@@ -128,6 +146,13 @@
 # operation in which this improvement was removed
 postdowngrademessage = None
 
+# By default for now, we assume every improvement touches all the things
+touches_filelogs = True
+touches_manifests = True
+touches_changelog = True
+touches_requirements = True
+
+
 def __init__(self):
 raise NotImplementedError()
 
@@ -674,6 +699,72 @@
 # should this operation create a backup of the store
 self.backup_store = backup_store
 
+# whether the operation touches different revlogs at all or not
+self.touches_filelogs = self._touches_filelogs()
+self.touches_manifests = self._touches_manifests()
+self.touches_changelog = self._touches_changelog()
+# whether the operation touches requirements file or not
+self.touches_requirements = self._touches_requirements()
+self.touches_store = (
+self.touches_filelogs
+or self.touches_manifests
+or self.touches_changelog
+)
+# does the operation only touches repository requirement
+self.requirements_only = (
+self.touches_requirements and not self.touches_store
+)
+
+def _touches_filelogs(self):
+for a in self.upgrade_actions:
+# in optimisations, we re-process the revlogs again
+if a.type == OPTIMISATION:
+return True
+elif a.touches_filelogs:
+return True
+for a in self.removed_actions:
+if a.touches_filelogs:
+return True
+return False
+
+def _touches_manifests(self):
+for a in self.upgrade_actions:
+# in optimisations, we re-process the revlogs again
+if a.type == OPTIMISATION:
+return True
+elif a.touches_manifests:
+return True
+for a in self.removed_actions:
+if a.touches_manifests:
+return True
+return False
+
+def _touches_changelog(self):
+for a in self.upgrade_actions:
+# in optimisations, we re-process the revlogs again
+if a.type == OPTIMISATION:
+return True
+elif a.touches_changelog:
+return True
+for a in self.removed_actions:
+if a.touches_changelog:
+return True
+return False
+
+def _touches_requirements(self):
+for a in self.upgrade_actions:
+# optimisations are used to re-process revlogs and does not result
+# in a requirement being added or removed
+if a.type == OPTIMISATION:
+pass
+elif a.touches_requirements:
+return True
+for a in self.removed_actions:
+if a.touches_requirements:
+return True
+
+return False
+
 def _write_labeled(self, l, label):
 """
 Utility function to aid writing of a list under one label



To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

D9769: share: add documentation about various configs introduced recently

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

REVISION SUMMARY
  My recent series added these 4 configs which control how to behave when there 
is
  difference in share-safe state of source and shares. However my patches were
  missing documentation. This patch adds it.
  
  The documentation is added in verbose part as the feature and config are
  experimental.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/share.py

CHANGE DETAILS

diff --git a/hgext/share.py b/hgext/share.py
--- a/hgext/share.py
+++ b/hgext/share.py
@@ -63,6 +63,30 @@
 
 For resharing existing shares, make sure your working directory is clean
 and there are no untracked files, delete that share and create a new share.
+
+Shares can be automatically upgraded and downgraded to use share-safe
+mechanism. Following config options control the behavior:
+
+``experimental.sharesafe-warn-outdated-shares`` (default: True)
+Shows a warning if the current share is outdated and can be upgraded to
+use share-safe functionality.
+
+``experimental.sharesafe-auto-upgrade-shares`` (default: False)
+Automatically upgrades shares if the share source supports share-safe
+functionality.
+If the upgrade fails, a warning is shown and the command which is
+running is continued.
+
+``experimental.sharesafe-auto-upgrade-fail-error`` (default: False)
+If auto upgrade of share fails, error out the process and don't 
continue
+the command which is running.
+
+``experimental.sharesafe-auto-downgrade-shares`` (default: False)
+Automatically downgrade shares if it was using share-safe functionality
+but the share source stopped using it.
+If the downgrade process fails, we error out because current share
+does not have complete set of requirements and shared source no longer
+supports share-safe mechanism.
 '''
 
 from __future__ import absolute_import



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


D9747: largefiles: remove unused imports

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

REVISION SUMMARY
  This fixes test-check-pyflakes.t

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/largefiles/__init__.py
  hgext/largefiles/proto.py

CHANGE DETAILS

diff --git a/hgext/largefiles/proto.py b/hgext/largefiles/proto.py
--- a/hgext/largefiles/proto.py
+++ b/hgext/largefiles/proto.py
@@ -5,7 +5,6 @@
 from __future__ import absolute_import
 
 import os
-import re
 
 from mercurial.i18n import _
 from mercurial.pycompat import open
diff --git a/hgext/largefiles/__init__.py b/hgext/largefiles/__init__.py
--- a/hgext/largefiles/__init__.py
+++ b/hgext/largefiles/__init__.py
@@ -111,9 +111,7 @@
 extensions,
 exthelper,
 hg,
-httppeer,
 localrepo,
-sshpeer,
 wireprotov1server,
 )
 



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


D9695: upgrade: don't perform anything if nothing to do

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

REVISION SUMMARY
  Before this patch, upgrade will process everything, re-clone all revlogs, 
write
  requirements file again even there is no change to be made.
  
  This patch makes it exit earlier.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  tests/test-lfs-serve.t
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -471,30 +471,7 @@
 
   $ hg init modern
   $ hg -R modern debugupgraderepo --run
-  upgrade will perform the following actions:
-  
-  requirements
- preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
-  
-  processed revlogs:
-- all-filelogs
-- changelog
-- manifest
-  
-  beginning upgrade...
-  repository locked and read-only
-  creating temporary repository to stage upgraded data: 
$TESTTMP/modern/.hg/upgrade.* (glob)
-  (it is safe to interrupt this process any time before data migration 
completes)
-  data fully upgraded in a temporary repository
-  marking source repository as being upgraded; clients will be unable to read 
from repository
-  starting in-place swap of repository data
-  replaced files will be backed up at $TESTTMP/modern/.hg/upgradebackup.* 
(glob)
-  replacing store...
-  store replacement complete; repository was inconsistent for *s (glob)
-  finalizing requirements file and making repository readable again
-  removing temporary repository $TESTTMP/modern/.hg/upgrade.* (glob)
-  copy of old repository backed up at $TESTTMP/modern/.hg/upgradebackup.* 
(glob)
-  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified
+  nothing to do
 
 Upgrading a repository to generaldelta works
 
@@ -1025,41 +1002,7 @@
   $ touch .hg/store/.XX_special_filename
 
   $ hg debugupgraderepo --run
-  upgrade will perform the following actions:
-  
-  requirements
- preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
-  
-  processed revlogs:
-- all-filelogs
-- changelog
-- manifest
-  
-  beginning upgrade...
-  repository locked and read-only
-  creating temporary repository to stage upgraded data: 
$TESTTMP/store-filenames/.hg/upgrade.* (glob)
-  (it is safe to interrupt this process any time before data migration 
completes)
-  migrating 3 total revisions (1 in filelogs, 1 in manifests, 1 in changelog)
-  migrating 301 bytes in store; 107 bytes tracked data
-  migrating 1 filelogs containing 1 revisions (64 bytes in store; 0 bytes 
tracked data)
-  finished migrating 1 filelog revisions across 1 filelogs; change in size: 0 
bytes
-  migrating 1 manifests containing 1 revisions (110 bytes in store; 45 bytes 
tracked data)
-  finished migrating 1 manifest revisions across 1 manifests; change in size: 
0 bytes
-  migrating changelog containing 1 revisions (127 bytes in store; 62 bytes 
tracked data)
-  finished migrating 1 changelog revisions; change in size: 0 bytes
-  finished migrating 3 total revisions; total change in store size: 0 bytes
-  copying .XX_special_filename
-  copying phaseroots
-  data fully upgraded in a temporary repository
-  marking source repository as being upgraded; clients will be unable to read 
from repository
-  starting in-place swap of repository data
-  replaced files will be backed up at 
$TESTTMP/store-filenames/.hg/upgradebackup.* (glob)
-  replacing store...
-  store replacement complete; repository was inconsistent for *s (glob)
-  finalizing requirements file and making repository readable again
-  removing temporary repository $TESTTMP/store-filenames/.hg/upgrade.* (glob)
-  copy of old repository backed up at 
$TESTTMP/store-filenames/.hg/upgradebackup.* (glob)
-  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified
+  nothing to do
   $ hg debugupgraderepo --run --optimize 're-delta-fulladd'
   upgrade will perform the following actions:
   
@@ -1132,40 +1075,7 @@
   store
 
   $ hg debugupgraderepo --run
-  upgrade will perform the following actions:
-  
-  requirements
- preserved: dotencode, fncache, generaldelta, largefiles, revlogv1, 
sparserevlog, store
-  
-  processed revlogs:
-- all-filelogs
-- changelog
-- manifest
-  
-  beginning upgrade...
-  repository locked and read-only
-  creating temporary repository to stage upgraded data: 
$TESTTMP/largefilesrepo/.hg/upgrade.* (glob)
-  (it is safe to interrupt this process any time before data migration 
completes)
-  migrating 3 total revisions (1 in filelogs, 1 in manifests, 1 in changelog)
-  migrating 355 bytes in store; 160 bytes tracked data
-  migrating 1 filelogs containing 1 revisions (106 bytes in store; 41 bytes 
tracked data)
-  

D9693: downgrade: if a compression is removed, consider that too

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

REVISION SUMMARY
  For compression format variant, the result of `fromrepo()` and `fromconfig()` 
is
  not a boolean and we have to actually equate those to find change.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -467,6 +467,12 @@
 downgrades = []
 
 for fv in allformatvariant:
+if fv.name == b'compression':
+# If there is a compression change between repository
+# and config, destination repository compression will change
+# and current compression will be removed.
+if fv.fromrepo(repo) != fv.fromconfig(repo):
+downgrades.append(fv)
 # format variant exist in repo but does not exist in new repository
 # config
 if fv.fromrepo(repo) and not fv.fromconfig(repo):



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


D9694: upgrade: demonstrate that a no-op upgrade still performs everything

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

REVISION SUMMARY
  An upgrade operation which is not adding or removing anything should ideally
  error out. However, it does the whole cloning and everything. Next patch will
  fix it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -1644,3 +1644,42 @@
   sparserevlog
   store
   $ hg debugsidedata -c 0
+
+Demonstrate that nothing to perform upgrade will still run all the way through
+FIXME: this should return early
+
+  $ hg debugupgraderepo --run
+  upgrade will perform the following actions:
+  
+  requirements
+ preserved: dotencode, exp-sidedata-flag, fncache, generaldelta, 
revlog-compression-zstd, revlogv1, sparserevlog, store
+  
+  processed revlogs:
+- all-filelogs
+- changelog
+- manifest
+  
+  beginning upgrade...
+  repository locked and read-only
+  creating temporary repository to stage upgraded data: 
$TESTTMP/sparserevlogrepo/.hg/upgrade.1xrhgkjm
+  (it is safe to interrupt this process any time before data migration 
completes)
+  migrating 3 total revisions (1 in filelogs, 1 in manifests, 1 in changelog)
+  migrating 297 bytes in store; 103 bytes tracked data
+  migrating 1 filelogs containing 1 revisions (64 bytes in store; 0 bytes 
tracked data)
+  finished migrating 1 filelog revisions across 1 filelogs; change in size: 0 
bytes
+  migrating 1 manifests containing 1 revisions (110 bytes in store; 45 bytes 
tracked data)
+  finished migrating 1 manifest revisions across 1 manifests; change in size: 
0 bytes
+  migrating changelog containing 1 revisions (123 bytes in store; 58 bytes 
tracked data)
+  finished migrating 1 changelog revisions; change in size: 0 bytes
+  finished migrating 3 total revisions; total change in store size: 0 bytes
+  copying phaseroots
+  data fully upgraded in a temporary repository
+  marking source repository as being upgraded; clients will be unable to read 
from repository
+  starting in-place swap of repository data
+  replaced files will be backed up at 
$TESTTMP/sparserevlogrepo/.hg/upgradebackup.0xno10pk
+  replacing store...
+  store replacement complete; repository was inconsistent for 0.0s
+  finalizing requirements file and making repository readable again
+  removing temporary repository $TESTTMP/sparserevlogrepo/.hg/upgrade.1xrhgkjm
+  copy of old repository backed up at 
$TESTTMP/sparserevlogrepo/.hg/upgradebackup.0xno10pk
+  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified



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


D9692: sharesafe: introduce config to disallow outdated shares from working

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

REVISION SUMMARY
  After this patch, we have config option to control all aspects of shares
  when share source is upgraded or downgraded.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -397,6 +397,9 @@
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-disallow-outdated-shares=true
+  abort: source repository uses share-safe while current share does not
+  [255]
 
   $ hg log -GT "{node}: {desc}\n" -R ../nss-share
   warning: source repository supports share-safe functionality. Reshare to 
upgrade.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -608,6 +608,15 @@
 requirements,
 )
 elif ui.configbool(
+b'experimental', b'sharesafe-disallow-outdated-shares'
+):
+raise error.Abort(
+_(
+b'source repository uses share-safe while'
+b' current share does not'
+)
+)
+elif ui.configbool(
 b'experimental', b'sharesafe-warn-outdated-shares'
 ):
 ui.warn(
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1084,6 +1084,11 @@
 )
 coreconfigitem(
 b'experimental',
+b'sharesafe-disallow-outdated-shares',
+default=False,
+)
+coreconfigitem(
+b'experimental',
 b'sharesafe-warn-outdated-shares',
 default=True,
 )



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


D9691: sharesafe: make warning about outdated share configurable

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

REVISION SUMMARY
  If the source repository upgrades to use sharesafe mode, we show a warning in
  shares. This patch makes that warning configurable and some might not want 
their
  users see this warning.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -392,6 +392,12 @@
 
 Make sure existing shares still works
 
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-warn-outdated-shares=false
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+
   $ hg log -GT "{node}: {desc}\n" -R ../nss-share
   warning: source repository supports share-safe functionality. Reshare to 
upgrade.
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -607,7 +607,9 @@
 storevfs,
 requirements,
 )
-else:
+elif ui.configbool(
+b'experimental', b'sharesafe-warn-outdated-shares'
+):
 ui.warn(
 _(
 b'warning: source repository supports share-safe 
functionality.'
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1084,6 +1084,11 @@
 )
 coreconfigitem(
 b'experimental',
+b'sharesafe-warn-outdated-shares',
+default=True,
+)
+coreconfigitem(
+b'experimental',
 b'single-head-per-branch',
 default=False,
 )



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


D9690: debuglock: rename flag names to better clarity

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

REVISION SUMMARY
  `--force-lock` sounds as if we are taking the lock however in reality it's the
  opposite.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/debugcommands.py
  relnotes/next
  tests/test-completion.t

CHANGE DETAILS

diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -295,7 +295,7 @@
   debuginstall: template
   debugknown: 
   debuglabelcomplete: 
-  debuglocks: force-lock, force-wlock, set-lock, set-wlock
+  debuglocks: force-free-lock, force-free-wlock, set-lock, set-wlock
   debugmanifestfulltextcache: clear, add
   debugmergestate: style, template
   debugnamecomplete: 
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -53,6 +53,8 @@
 
 == Backwards Compatibility Changes ==
 
+ * `--force-lock` and `--force-wlock` options on `hg debuglock` command are
+   renamed to `--force-free-lock` and `--force-free-wlock` respectively.
 
 
 == Internal API Changes ==
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1889,10 +1889,10 @@
 @command(
 b'debuglocks',
 [
-(b'L', b'force-lock', None, _(b'free the store lock (DANGEROUS)')),
+(b'L', b'force-free-lock', None, _(b'free the store lock 
(DANGEROUS)')),
 (
 b'W',
-b'force-wlock',
+b'force-free-wlock',
 None,
 _(b'free the working state lock (DANGEROUS)'),
 ),
@@ -1931,11 +1931,11 @@
 
 """
 
-if opts.get('force_lock'):
+if opts.get('force_free_lock'):
 repo.svfs.unlink(b'lock')
-if opts.get('force_wlock'):
+if opts.get('force_free_wlock'):
 repo.vfs.unlink(b'wlock')
-if opts.get('force_lock') or opts.get('force_wlock'):
+if opts.get('force_free_lock') or opts.get('force_free_wlock'):
 return 0
 
 locks = []



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


D9681: localrepo: move storevfs calculation out of if statement

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

REVISION SUMMARY
  In next patch, we will need this variable in else statement too. So, let's 
take
  it out.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/localrepo.py

CHANGE DETAILS

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -549,8 +549,13 @@
 requirementsmod.SHARED_REQUIREMENT in requirements
 or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements
 )
+storevfs = None
 if shared:
+# This is a shared repo
 sharedvfs = _getsharedvfs(hgvfs, requirements)
+storevfs = vfsmod.vfs(sharedvfs.join(b'store'))
+else:
+storevfs = vfsmod.vfs(hgvfs.join(b'store'))
 
 # if .hg/requires contains the sharesafe requirement, it means
 # there exists a `.hg/store/requires` too and we should read it
@@ -573,12 +578,6 @@
 _(b"share source does not support exp-sharesafe requirement")
 )
 
-if shared:
-# This is a shared repo
-storevfs = vfsmod.vfs(sharedvfs.join(b'store'))
-else:
-storevfs = vfsmod.vfs(hgvfs.join(b'store'))
-
 requirements |= _readrequires(storevfs, False)
 elif shared:
 sourcerequires = _readrequires(sharedvfs, False)



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


D9680: sharesafe: add functionality to automatically downgrade shares

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

REVISION SUMMARY
  Reasoning is same as previous patch which adds automatic upgrade support.
  
  Downgrade is required as if automatic upgrade is enabled, all shares upgrade 
and
  then source repository downgrades, shares won't work. We need to downgrade 
them.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  mercurial/scmutil.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -484,6 +484,20 @@
   abort: share source does not support exp-sharesafe requirement
   [255]
 
+Testing automatic downgrade of shares when config is set
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config 
experimental.sharesafe-auto-downgrade-shares=true
+  repository downgraded to not use share-safe mode
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+
 
 Testing automatic upgrade of shares when config is set
 
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1613,6 +1613,23 @@
 return current_requirements
 
 
+def downgrade_share_to_non_safe(
+hgvfs, current_requirements, source_requirements
+):
+"""Downgrades a share which use share-safe to not use it
+
+Returns the set of new repository requirements
+"""
+# we cannot be 100% sure on which requirements were present in store when
+# the source supported share-safe. However, we do know that working
+# directory requirements were not there. Hence we remove them
+source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS
+current_requirements |= source_requirements
+current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT)
+writerequires(hgvfs, current_requirements)
+return current_requirements
+
+
 class filecachesubentry(object):
 def __init__(self, path, stat):
 self.path = path
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -574,11 +574,24 @@
 and requirementsmod.SHARESAFE_REQUIREMENT
 not in _readrequires(sharedvfs, True)
 ):
-raise error.Abort(
-_(b"share source does not support exp-sharesafe requirement")
-)
-
-requirements |= _readrequires(storevfs, False)
+if ui.configbool(
+b'experimental', b'sharesafe-auto-downgrade-shares'
+):
+sourcerequires = _readrequires(sharedvfs, True)
+requirements = scmutil.downgrade_share_to_non_safe(
+hgvfs, requirements, sourcerequires
+)
+ui.warn(
+_(b'repository downgraded to not use share-safe mode\n')
+)
+else:
+raise error.Abort(
+_(
+b"share source does not support exp-sharesafe 
requirement"
+)
+)
+else:
+requirements |= _readrequires(storevfs, False)
 elif shared:
 sourcerequires = _readrequires(sharedvfs, False)
 if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires:
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1074,6 +1074,11 @@
 )
 coreconfigitem(
 b'experimental',
+b'sharesafe-auto-downgrade-shares',
+default=False,
+)
+coreconfigitem(
+b'experimental',
 b'sharesafe-auto-upgrade-shares',
 default=False,
 )



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


D9679: sharesafe: introduce functionality to automatically upgrade shares

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

REVISION SUMMARY
  In past few months, we have developed a `share-safe` mode for sharing 
repository
  in which share source requirements and config values are shared with the 
shares.
  
  To get it rolling, an important task is to get these shares automatically
  upgraded. We are focusing on an installation where shares are created by 
scripts
  and test jobs. It will be difficult to manually upgrade these and we need some
  functionality to do so automatically.
  
  This patch introduces a config option to deal with it. If all of the following
  conditions are met, we upgrade the share repository automatically:
  
  - If the config option is enabled
  - Share source repository is share-safe enabled
  - Share is not share-safe enabled
  - Any command is run in the share
  
  Upgrading the share is pretty easy as it involves only editing the 
requirements
  file.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  mercurial/scmutil.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -479,8 +479,53 @@
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
-  $ hg unshare -R ../nss-share
 
   $ hg log -GT "{node}: {desc}\n" -R ../ss-share
   abort: share source does not support exp-sharesafe requirement
   [255]
+
+
+Testing automatic upgrade of shares when config is set
+
+  $ hg debugupgraderepo -q --run --config format.exp-share-safe=True
+  upgrade will perform the following actions:
+  
+  requirements
+ preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
+ added: exp-sharesafe
+  
+  processed revlogs:
+- all-filelogs
+- changelog
+- manifest
+  
+  repository upgraded to share safe mode, existing shares will still work in 
old non-safe mode. Re-share existing shares to use them in safe mode New shares 
will be created in safe mode.
+  $ hg debugrequirements
+  dotencode
+  exp-sharesafe
+  fncache
+  generaldelta
+  revlogv1
+  sparserevlog
+  store
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share
+  warning: source repository supports share-safe functionality. Reshare to 
upgrade.
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-auto-upgrade-shares=true
+  repository upgraded to use share-safe mode
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+
+Test that unshare works
+
+  $ hg unshare -R ../nss-share
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1597,6 +1597,22 @@
 fp.write(b"%s\n" % r)
 
 
+def upgrade_share_to_safe(hgvfs, current_requirements, store_requirements):
+"""Upgrades a share to use share-safe mechanism
+
+Returns the set of new requirements for the repository
+"""
+# after upgrade, store requires will be shared, so lets find
+# the requirements which are not present in store and
+# write them to share's .hg/requires
+diffrequires = current_requirements - store_requirements
+# add share-safe requirement as it will mark the share as share-safe
+diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
+writerequires(hgvfs, diffrequires)
+current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
+return current_requirements
+
+
 class filecachesubentry(object):
 def __init__(self, path, stat):
 self.path = path
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -582,12 +582,19 @@
 elif shared:
 sourcerequires = _readrequires(sharedvfs, False)
 if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires:
-ui.warn(
-_(
-b'warning: source repository supports share-safe 
functionality.'
-b' Reshare to upgrade.\n'
+if ui.configbool(b'experimental', 
b'sharesafe-auto-upgrade-shares'):
+storerequires = _readrequires(storevfs, False)
+requirements = scmutil.upgrade_share_to_safe(
+hgvfs, requirements, storerequires
 )
-)
+ui.warn(_(b'repository upgraded to use share-safe mode\n'))
+else:
+ui.warn(
+_(
+

D9677: upgrade: use copy+delete instead of rename while creating backup

2020-12-31 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  A lot of times, we do an upgrade operation which does not touches all the 
parts
  of the stores. But right not, we have a blind logic which processes 
everything.
  To selectively upgrade parts of repository, we need to persist existing data
  which is untouched.
  
  However while creating current repository backup, we rename the whole store
  leaving no option to persist untouched files.
  
  We switch to copy+delete so that we can only delete data files which are 
changed
  by the operation and leave rest untouched.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/engine.py
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -615,10 +615,6 @@
   data
   fncache
   phaseroots
-  undo
-  undo.backup.fncache
-  undo.backupfiles
-  undo.phaseroots
 
 unless --no-backup is passed
 
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
@@ -414,7 +414,35 @@
 """
 # TODO: don't blindly rename everything in store
 # There can be upgrades where store is not touched at all
-util.rename(currentrepo.spath, backupvfs.join(b'store'))
+backupstorevfs = vfsmod.vfs(backupvfs.join(b'store'))
+util.makedirs(backupstorevfs.base)
+for path, kind, st in sorted(currentrepo.store.vfs.readdir(b'', 
stat=True)):
+# Skip transaction related files.
+if path.startswith(b'undo'):
+continue
+# Only copy regular files.
+if kind != stat.S_IFREG:
+continue
+# Skip other skipped files.
+if path in (b'lock',):
+continue
+src = currentrepo.store.rawvfs.join(path)
+dst = backupstorevfs.join(path)
+util.copyfile(src, dst, copystat=True)
+if currentrepo.svfs.exists(b'data'):
+util.copyfiles(
+currentrepo.svfs.join(b'data'),
+backupstorevfs.join(b'data'),
+hardlink=False,
+)
+if currentrepo.svfs.exists(b'meta'):
+util.copyfiles(
+currentrepo.svfs.join(b'meta'),
+backupstorevfs.join(b'meta'),
+hardlink=False,
+)
+
+currentrepo.vfs.rmtree(b'store', forcibly=True)
 util.rename(upgradedrepo.spath, currentrepo.spath)
 
 
@@ -514,10 +542,4 @@
 )
 scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
 
-# The lock file from the old store won't be removed because nothing has a
-# 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.
-backupvfs.unlink(b'store/lock')
-
 return backuppath



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


D9676: upgrade: migrated -> upgraded in ui messages

2020-12-31 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/D9676

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/engine.py
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -483,9 +483,9 @@
   
   beginning upgrade...
   repository locked and read-only
-  creating temporary repository to stage migrated data: 
$TESTTMP/modern/.hg/upgrade.* (glob)
+  creating temporary repository to stage upgraded data: 
$TESTTMP/modern/.hg/upgrade.* (glob)
   (it is safe to interrupt this process any time before data migration 
completes)
-  data fully migrated to temporary repository
+  data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
   replaced files will be backed up at $TESTTMP/modern/.hg/upgradebackup.* 
(glob)
@@ -539,7 +539,7 @@
   
   beginning upgrade...
   repository locked and read-only
-  creating temporary repository to stage migrated data: 
$TESTTMP/upgradegd/.hg/upgrade.* (glob)
+  creating temporary repository to stage upgraded data: 
$TESTTMP/upgradegd/.hg/upgrade.* (glob)
   (it is safe to interrupt this process any time before data migration 
completes)
   migrating 9 total revisions (3 in filelogs, 3 in manifests, 3 in changelog)
   migrating 519 KB in store; 1.05 MB tracked data
@@ -551,7 +551,7 @@
   finished migrating 3 changelog revisions; change in size: 0 bytes
   finished migrating 9 total revisions; total change in store size: -17 bytes
   copying phaseroots
-  data fully migrated to temporary repository
+  data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
   replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
@@ -640,7 +640,7 @@
   
   beginning upgrade...
   repository locked and read-only
-  creating temporary repository to stage migrated data: 
$TESTTMP/upgradegd/.hg/upgrade.* (glob)
+  creating temporary repository to stage upgraded data: 
$TESTTMP/upgradegd/.hg/upgrade.* (glob)
   (it is safe to interrupt this process any time before data migration 
completes)
   migrating 9 total revisions (3 in filelogs, 3 in manifests, 3 in changelog)
   migrating 519 KB in store; 1.05 MB tracked data
@@ -652,7 +652,7 @@
   finished migrating 3 changelog revisions; change in size: 0 bytes
   finished migrating 9 total revisions; total change in store size: 0 bytes
   copying phaseroots
-  data fully migrated to temporary repository
+  data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
   replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
@@ -682,7 +682,7 @@
   
   beginning upgrade...
   repository locked and read-only
-  creating temporary repository to stage migrated data: 
$TESTTMP/upgradegd/.hg/upgrade.* (glob)
+  creating temporary repository to stage upgraded data: 
$TESTTMP/upgradegd/.hg/upgrade.* (glob)
   (it is safe to interrupt this process any time before data migration 
completes)
   migrating 9 total revisions (3 in filelogs, 3 in manifests, 3 in changelog)
   migrating 519 KB in store; 1.05 MB tracked data
@@ -699,7 +699,7 @@
   finished migrating 3 changelog revisions; change in size: 0 bytes
   finished migrating 9 total revisions; total change in store size: 0 bytes
   copying phaseroots
-  data fully migrated to temporary repository
+  data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will be unable to read 
from repository
   starting in-place swap of repository data
   replaced files will be backed up at $TESTTMP/upgradegd/.hg/upgradebackup.* 
(glob)
@@ -762,7 +762,7 @@
   
   beginning upgrade...
   repository locked and read-only
-  creating temporary repository to stage migrated data: 
$TESTTMP/upgradegd/.hg/upgrade.* (glob)
+  creating temporary repository to stage upgraded data: 
$TESTTMP/upgradegd/.hg/upgrade.* (glob)
   (it is safe to interrupt this process any time before data migration 
completes)
   migrating 9 total revisions (3 in filelogs, 3 in manifests, 3 in changelog)
   migrating 519 KB in store; 1.05 MB tracked data
@@ -779,7 +779,7 @@
   finished migrating 3 changelog revisions; change in size: 0 bytes
   finished migrating 9 total revisions; total change in store size: 0 bytes
   copying phaseroots
-  data fully migrated to temporary repository
+  data fully upgraded in a temporary repository
   marking source repository as being upgraded; clients will 

D9675: upgrade: remove unnecessary `is None` check

2020-12-31 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `upgrade_engine.upgrade()` always return the `backuppath` value and there are
  not early returns. Hence I don't see how `backuppath` can be None.
  
  Adding extra unncessary safe checks hides unknown bugs. Hence removing it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py

CHANGE DETAILS

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -205,7 +205,7 @@
 backuppath = upgrade_engine.upgrade(
 ui, repo, dstrepo, upgrade_op
 )
-if not (backup or backuppath is None):
+if not backup:
 ui.status(
 _(b'removing old repository content %s\n') % backuppath
 )



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


D9674: engine: refactor code to replace stores in separate function

2020-12-31 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  In not all upgrades, we need to change the whole store. For example, when
  upgrading repository to share-safe mode, we don't touch revlogs at all hence
  store cloning and copying is not required.
  
  The store replacing code needs to be made aware about what all has changed and
  hence only copy/rename those things. To kickstart that, this patch moves
  existing logic into a separate function.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -399,6 +399,25 @@
 yield path
 
 
+def _replacestores(currentrepo, upgradedrepo, backupvfs, upgrade_op):
+"""Replace the stores after current repository is upgraded
+
+Creates a backup of current repository store at backup path
+Replaces upgraded store files in current repo from upgraded one
+
+Arguments:
+  currentrepo: repo object of current repository
+  upgradedrepo: repo object of the upgraded data
+  backupvfs: vfs object for the backup path
+  upgrade_op: upgrade operation object
+  to be used to decide what all is upgraded
+"""
+# TODO: don't blindly rename everything in store
+# There can be upgrades where store is not touched at all
+util.rename(currentrepo.spath, backupvfs.join(b'store'))
+util.rename(upgradedrepo.spath, currentrepo.spath)
+
+
 def finishdatamigration(ui, srcrepo, dstrepo, requirements):
 """Hook point for extensions to perform additional actions during upgrade.
 
@@ -475,8 +494,7 @@
 # environments).
 ui.status(_(b'replacing store...\n'))
 tstart = util.timer()
-util.rename(srcrepo.spath, backupvfs.join(b'store'))
-util.rename(dstrepo.spath, srcrepo.spath)
+_replacestores(srcrepo, dstrepo, backupvfs, upgrade_op)
 elapsed = util.timer() - tstart
 ui.status(
 _(



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


D9673: engine: prevent a function call for each store file

2020-12-31 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Python function calls are not cheap. Instead of calling the function once for
  each file in store, we use a dedicated function which filters and yields the
  required files.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -375,37 +375,28 @@
 % (revcount, util.bytecount(dstsize - srcsize))
 )
 
-
-def _filterstorefile(srcrepo, dstrepo, requirements, path, mode, st):
-"""Determine whether to copy a store file during upgrade.
-
-This function is called when migrating store files from ``srcrepo`` to
-``dstrepo`` as part of upgrading a repository.
+return True
 
-Args:
-  srcrepo: repo we are copying from
-  dstrepo: repo we are copying to
-  requirements: set of requirements for ``dstrepo``
-  path: store file being examined
-  mode: the ``ST_MODE`` file type of ``path``
-  st: ``stat`` data structure for ``path``
 
-Function should return ``True`` if the file is to be copied.
-"""
-# Skip revlogs.
-if path.endswith((b'.i', b'.d', b'.n', b'.nd')):
-return False
-# Skip transaction related files.
-if path.startswith(b'undo'):
-return False
-# Only copy regular files.
-if mode != stat.S_IFREG:
-return False
-# Skip other skipped files.
-if path in (b'lock', b'fncache'):
-return False
+def _files_to_copy_post_revlog_clone(srcrepo):
+"""yields files which should be copied to destination after revlogs
+are cloned"""
+for path, kind, st in sorted(srcrepo.store.vfs.readdir(b'', stat=True)):
+# don't copy revlogs as they are already cloned
+if path.endswith((b'.i', b'.d', b'.n', b'.nd')):
+continue
+# Skip transaction related files.
+if path.startswith(b'undo'):
+continue
+# Only copy regular files.
+if kind != stat.S_IFREG:
+continue
+# Skip other skipped files.
+if path in (b'lock', b'fncache'):
+continue
+# TODO: should we skip cache too?
 
-return True
+yield path
 
 
 def finishdatamigration(ui, srcrepo, dstrepo, requirements):
@@ -446,13 +437,7 @@
 )
 
 # Now copy other files in the store directory.
-# The sorted() makes execution deterministic.
-for p, kind, st in sorted(srcrepo.store.vfs.readdir(b'', stat=True)):
-if not _filterstorefile(
-srcrepo, dstrepo, upgrade_op.new_requirements, p, kind, st
-):
-continue
-
+for p in _files_to_copy_post_revlog_clone(srcrepo):
 srcrepo.ui.status(_(b'copying %s\n') % p)
 src = srcrepo.store.rawvfs.join(p)
 dst = dstrepo.store.rawvfs.join(p)



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


D9672: engine: make hook point for extension a public function

2020-12-31 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Well there are no private public functions in Python, but we generally treat
  functions and variables starting with `_` as private ones.
  
  A function which needs to be overrided in extension should be a public one.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/lfs/wrapper.py
  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
@@ -408,7 +408,7 @@
 return True
 
 
-def _finishdatamigration(ui, srcrepo, dstrepo, requirements):
+def finishdatamigration(ui, srcrepo, dstrepo, requirements):
 """Hook point for extensions to perform additional actions during upgrade.
 
 This function is called after revlogs and store files have been copied but
@@ -458,7 +458,7 @@
 dst = dstrepo.store.rawvfs.join(p)
 util.copyfile(src, dst, copystat=True)
 
-_finishdatamigration(ui, srcrepo, dstrepo, requirements)
+finishdatamigration(ui, srcrepo, dstrepo, requirements)
 
 ui.status(_(b'data fully migrated to temporary repository\n'))
 
diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -524,7 +524,7 @@
 remoteblob.writebatch(pointers, repo.svfs.lfslocalblobstore)
 
 
-@eh.wrapfunction(upgrade_engine, b'_finishdatamigration')
+@eh.wrapfunction(upgrade_engine, b'finishdatamigration')
 def upgradefinishdatamigration(orig, ui, srcrepo, dstrepo, requirements):
 orig(ui, srcrepo, dstrepo, requirements)
 



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


D9669: engine: prevent multiple checking of re-delta-multibase

2020-12-30 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The _perform_clone function is called for each revlog cloned, hence we should
  prevent this function call overhead.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/actions.py
  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
@@ -140,9 +140,7 @@
 newrl,
 addrevisioncb=oncopiedrevision,
 deltareuse=upgrade_op.delta_reuse_mode,
-forcedeltabothparents=upgrade_op.has_upgrade_action(
-b're-delta-multibase'
-),
+forcedeltabothparents=upgrade_op.force_re_delta_both_parents,
 sidedatacompanion=sidedatacompanion,
 )
 else:
diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -658,6 +658,11 @@
 elif b're-delta-fulladd' in self._upgrade_actions_names:
 self.delta_reuse_mode = revlog.revlog.DELTAREUSEFULLADD
 
+# should this operation force re-delta of both parents
+self.force_re_delta_both_parents = (
+b're-delta-multibase' in self._upgrade_actions_names
+)
+
 def _write_labeled(self, l, label):
 """
 Utility function to aid writing of a list under one label



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


D9668: engine: pass upgrade operation inside `_perform_clone()`

2020-12-30 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Same as previous patch.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -124,15 +124,13 @@
 tr,
 old_revlog,
 unencoded,
-deltareuse,
-forcedeltabothparents,
-revlogs,
+upgrade_op,
 sidedatacompanion,
 oncopiedrevision,
 ):
 """ returns the new revlog object created"""
 newrl = None
-if matchrevlog(revlogs, unencoded):
+if matchrevlog(upgrade_op.revlogs_to_process, unencoded):
 ui.note(
 _(b'cloning %d revisions from %s\n') % (len(old_revlog), unencoded)
 )
@@ -141,8 +139,10 @@
 tr,
 newrl,
 addrevisioncb=oncopiedrevision,
-deltareuse=deltareuse,
-forcedeltabothparents=forcedeltabothparents,
+deltareuse=upgrade_op.delta_reuse_mode,
+forcedeltabothparents=upgrade_op.has_upgrade_action(
+b're-delta-multibase'
+),
 sidedatacompanion=sidedatacompanion,
 )
 else:
@@ -276,9 +276,7 @@
 tr,
 oldrl,
 unencoded,
-upgrade_op.delta_reuse_mode,
-upgrade_op.has_upgrade_action(b're-delta-multibase'),
-upgrade_op.revlogs_to_process,
+upgrade_op,
 sidedatacompanion,
 oncopiedrevision,
 )
@@ -317,9 +315,7 @@
 tr,
 oldrl,
 unencoded,
-upgrade_op.delta_reuse_mode,
-upgrade_op.has_upgrade_action(b're-delta-multibase'),
-upgrade_op.revlogs_to_process,
+upgrade_op,
 sidedatacompanion,
 oncopiedrevision,
 )
@@ -357,9 +353,7 @@
 tr,
 oldrl,
 unencoded,
-upgrade_op.delta_reuse_mode,
-upgrade_op.has_upgrade_action(b're-delta-multibase'),
-upgrade_op.revlogs_to_process,
+upgrade_op,
 sidedatacompanion,
 oncopiedrevision,
 )



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


D9667: engine: pass upgrade operation inside _clonerevlogs()

2020-12-30 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Better to pass the operation instead of passing three of it's members (one of
  the them is a function call) separately.
  
  This will also be useful in future when we will like to control which things 
are
  upgraded.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -159,9 +159,7 @@
 srcrepo,
 dstrepo,
 tr,
-deltareuse,
-forcedeltabothparents,
-revlogs=UPGRADE_ALL_REVLOGS,
+upgrade_op,
 ):
 """Copy revlogs between 2 repos."""
 revcount = 0
@@ -278,9 +276,9 @@
 tr,
 oldrl,
 unencoded,
-deltareuse,
-forcedeltabothparents,
-revlogs,
+upgrade_op.delta_reuse_mode,
+upgrade_op.has_upgrade_action(b're-delta-multibase'),
+upgrade_op.revlogs_to_process,
 sidedatacompanion,
 oncopiedrevision,
 )
@@ -319,9 +317,9 @@
 tr,
 oldrl,
 unencoded,
-deltareuse,
-forcedeltabothparents,
-revlogs,
+upgrade_op.delta_reuse_mode,
+upgrade_op.has_upgrade_action(b're-delta-multibase'),
+upgrade_op.revlogs_to_process,
 sidedatacompanion,
 oncopiedrevision,
 )
@@ -359,9 +357,9 @@
 tr,
 oldrl,
 unencoded,
-deltareuse,
-forcedeltabothparents,
-revlogs,
+upgrade_op.delta_reuse_mode,
+upgrade_op.has_upgrade_action(b're-delta-multibase'),
+upgrade_op.revlogs_to_process,
 sidedatacompanion,
 oncopiedrevision,
 )
@@ -452,9 +450,7 @@
 srcrepo,
 dstrepo,
 tr,
-upgrade_op.delta_reuse_mode,
-upgrade_op.has_upgrade_action(b're-delta-multibase'),
-revlogs=upgrade_op.revlogs_to_process,
+upgrade_op,
 )
 
 # Now copy other files in the store directory.



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


D9666: actions: store deltareuse mode of whole operation in UpgradeOperation

2020-12-30 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  UpgradeOperation should provide easy access to all the things related to the
  current operation. Clients should not need to compute them.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/actions.py
  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
@@ -446,24 +446,13 @@
 )
 )
 
-if upgrade_op.has_upgrade_action(b're-delta-all'):
-deltareuse = revlog.revlog.DELTAREUSENEVER
-elif upgrade_op.has_upgrade_action(b're-delta-parent'):
-deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-elif upgrade_op.has_upgrade_action(b're-delta-multibase'):
-deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-elif upgrade_op.has_upgrade_action(b're-delta-fulladd'):
-deltareuse = revlog.revlog.DELTAREUSEFULLADD
-else:
-deltareuse = revlog.revlog.DELTAREUSEALWAYS
-
 with dstrepo.transaction(b'upgrade') as tr:
 _clonerevlogs(
 ui,
 srcrepo,
 dstrepo,
 tr,
-deltareuse,
+upgrade_op.delta_reuse_mode,
 upgrade_op.has_upgrade_action(b're-delta-multibase'),
 revlogs=upgrade_op.revlogs_to_process,
 )
diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -12,6 +12,7 @@
 error,
 localrepo,
 requirements,
+revlog,
 util,
 )
 
@@ -646,6 +647,17 @@
 i for i in all_optimizations if i not in self.upgrade_actions
 ]
 
+# delta reuse mode of this upgrade operation
+self.delta_reuse_mode = revlog.revlog.DELTAREUSEALWAYS
+if b're-delta-all' in self._upgrade_actions_names:
+self.delta_reuse_mode = revlog.revlog.DELTAREUSENEVER
+elif b're-delta-parent' in self._upgrade_actions_names:
+self.delta_reuse_mode = revlog.revlog.DELTAREUSESAMEREVS
+elif b're-delta-multibase' in self._upgrade_actions_names:
+self.delta_reuse_mode = revlog.revlog.DELTAREUSESAMEREVS
+elif b're-delta-fulladd' in self._upgrade_actions_names:
+self.delta_reuse_mode = revlog.revlog.DELTAREUSEFULLADD
+
 def _write_labeled(self, l, label):
 """
 Utility function to aid writing of a list under one label



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


D9665: engine: refactor how total dstsize is calculated

2020-12-30 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Instead of increasing it with each revlog, we just get the sum of total
  destination changelog, manifest and filelogs sizes.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -285,9 +285,7 @@
 oncopiedrevision,
 )
 info = newrl.storageinfo(storedsize=True)
-datasize = info[b'storedsize'] or 0
-dstsize += datasize
-fdstsize += datasize
+fdstsize += info[b'storedsize'] or 0
 ui.status(
 _(
 b'finished migrating %d filelog revisions across %d '
@@ -328,9 +326,7 @@
 oncopiedrevision,
 )
 info = newrl.storageinfo(storedsize=True)
-datasize = info[b'storedsize'] or 0
-dstsize += datasize
-mdstsize += datasize
+mdstsize += info[b'storedsize'] or 0
 ui.status(
 _(
 b'finished migrating %d manifest revisions across %d '
@@ -370,9 +366,7 @@
 oncopiedrevision,
 )
 info = newrl.storageinfo(storedsize=True)
-datasize = info[b'storedsize'] or 0
-dstsize += datasize
-cdstsize += datasize
+cdstsize += info[b'storedsize'] or 0
 progress.complete()
 ui.status(
 _(
@@ -382,6 +376,7 @@
 % (crevcount, util.bytecount(cdstsize - csrcsize))
 )
 
+dstsize = fdstsize + mdstsize + cdstsize
 ui.status(
 _(
 b'finished migrating %d total revisions; total change in store '



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


D9664: actions: rename DEFICIENCY constant to FORMAT_VARIANT

2020-12-30 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It was not obvious what does deficieny means and every format change can't be 
a
  deficiency. There are some format changes like compression levels, share-safe
  which can't be understood at deficiencies.
  
  This patch renames the constant to make things clearer.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -28,7 +28,7 @@
 return set()
 
 
-DEFICIENCY = b'deficiency'
+FORMAT_VARIANT = b'deficiency'
 OPTIMISATION = b'optimization'
 
 
@@ -42,13 +42,15 @@
will be mapped to an action later in the upgrade process.
 
 type
-   Either ``DEFICIENCY`` or ``OPTIMISATION``. A deficiency is an obvious
-   problem. An optimization is an action (sometimes optional) that
+   Either ``FORMAT_VARIANT`` or ``OPTIMISATION``.
+   A format variant is where we change the storage format. Not all format
+   variant changes are an obvious problem.
+   An optimization is an action (sometimes optional) that
can be taken to further improve the state of the repository.
 
 description
Message intended for humans explaining the improvement in more detail,
-   including the implications of it. For ``DEFICIENCY`` types, should be
+   including the implications of it. For ``FORMAT_VARIANT`` types, should 
be
worded in the present tense. For ``OPTIMISATION`` types, should be
worded in the future tense.
 
@@ -87,7 +89,7 @@
 class formatvariant(improvement):
 """an improvement subclass dedicated to repository format"""
 
-type = DEFICIENCY
+type = FORMAT_VARIANT
 ### The following attributes should be defined for each class:
 
 # machine-readable string uniquely identifying this improvement. it will be
@@ -95,7 +97,8 @@
 name = None
 
 # message intended for humans explaining the improvement in more detail,
-# including the implications of it ``DEFICIENCY`` types, should be worded
+# including the implications of it ``FORMAT_VARIANT`` types, should be
+# worded
 # in the present tense.
 description = None
 



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


D9617: debugupgraderepo: minor documentation fix

2020-12-16 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  When we specify `--no-changelog --no-manifest --no-filelog` we skip all revlog
  optimization instead of all filelog optimization.
  
  Also while I was here, for consistency, I did `optimisation` -> `optimization`
  to make it consistent with rest of occurrences.
  Note: I am not native speaker and I only changed it because of consistency. I
  don't know which one is correct.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -3922,7 +3922,7 @@
   * `--changelog`: optimize the changelog only
   * `--no-changelog --no-manifest`: optimize filelogs only
   * `--filelogs`: optimize the filelogs only
-  * `--no-changelog --no-manifest --no-filelogs`: skip all filelog 
optimisation
+  * `--no-changelog --no-manifest --no-filelogs`: skip all revlog 
optimizations
 """
 return upgrade.upgraderepo(
 ui, repo, run=run, optimize=set(optimize), backup=backup, **opts



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


D9614: upgrade: drop support for old style optimization names

2020-12-16 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Old style optimization names like `redeltaparent` were converted into
  `re-delta-parent` more than two years ago. The old names were kept around for
  sometime because of BC reasons.
  
  Refer 5608b5a6c3231c4ec771171cc3079142c7672be6 
. 
The commit states the map is
  there for a while and we can drop them as the underlying command is a debug
  command.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/upgrade.py
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -211,7 +211,7 @@
 
 --optimize can be used to add optimizations
 
-  $ hg debugupgrade --optimize redeltaparent
+  $ hg debugupgrade --optimize 're-delta-parent'
   (no format upgrades found in existing repository)
   performing an upgrade with "--run" will make the following changes:
   
@@ -1060,7 +1060,7 @@
   removing temporary repository $TESTTMP/store-filenames/.hg/upgrade.* (glob)
   copy of old repository backed up at 
$TESTTMP/store-filenames/.hg/upgradebackup.* (glob)
   the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified
-  $ hg debugupgraderepo --run --optimize redeltafulladd
+  $ hg debugupgraderepo --run --optimize 're-delta-fulladd'
   upgrade will perform the following actions:
   
   requirements
@@ -1289,7 +1289,7 @@
 1   120  p1 21191 98   
0.5130998 00.0 98 98   1.01
 2   120   other 30200107   
0.53500   128210.19626128128   0.835941
 
-  $ hg debugupgraderepo --run --optimize redeltaall
+  $ hg debugupgraderepo --run --optimize 're-delta-all'
   upgrade will perform the following actions:
   
   requirements
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -22,19 +22,6 @@
 
 allformatvariant = upgrade_actions.allformatvariant
 
-# search without '-' to support older form on newer client.
-#
-# We don't enforce backward compatibility for debug command so this
-# might eventually be dropped. However, having to use two different
-# forms in script when comparing result is anoying enough to add
-# backward compatibility for a while.
-legacy_opts_map = {
-b'redeltaparent': b're-delta-parent',
-b'redeltamultibase': b're-delta-multibase',
-b'redeltaall': b're-delta-all',
-b'redeltafulladd': b're-delta-fulladd',
-}
-
 
 def upgraderepo(
 ui,
@@ -48,8 +35,7 @@
 ):
 """Upgrade a repository in place."""
 if optimize is None:
-optimize = []
-optimize = {legacy_opts_map.get(o, o) for o in optimize}
+optimize = {}
 repo = repo.unfiltered()
 
 revlogs = set(upgrade_engine.UPGRADE_ALL_REVLOGS)
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -3925,7 +3925,7 @@
   * `--no-changelog --no-manifest --no-filelogs`: skip all filelog 
optimisation
 """
 return upgrade.upgraderepo(
-ui, repo, run=run, optimize=optimize, backup=backup, **opts
+ui, repo, run=run, optimize=set(optimize), backup=backup, **opts
 )
 
 



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


D9619: upgrade: introduce post upgrade and downgrade message for improvements

2020-12-16 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  For certain imporvements, we will like to show a message after the operation
  completed. This patch introduces that functionality.
  
  Right now it's only used by share-safe feature.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -57,6 +57,14 @@
 upgrademessage
Message intended for humans explaining what an upgrade addressing this
issue will do. Should be worded in the future tense.
+
+postupgrademessage
+   Message intended for humans which will be shown post and upgrade
+   operationupgrade when the improvement will be added
+
+postdowngrademessage
+   Message intended for humans which will be shown post an upgrade
+   operation in which this improvement was removed
 """
 
 def __init__(self, name, type, description, upgrademessage):
@@ -64,6 +72,8 @@
 self.type = type
 self.description = description
 self.upgrademessage = upgrademessage
+self.postupgrademessage = None
+self.postdowngrademessage = None
 
 def __eq__(self, other):
 if not isinstance(other, improvement):
@@ -109,6 +119,14 @@
 # value of current Mercurial default for new repository
 default = None
 
+# Message intended for humans which will be shown post and upgrade
+# operationupgrade when the improvement will be added
+postupgrademessage = None
+
+# Message intended for humans which will be shown post an upgrade
+# operation in which this improvement was removed
+postdowngrademessage = None
+
 def __init__(self):
 raise NotImplementedError()
 
@@ -235,6 +253,19 @@
 b'shares of this repository share its requirements and configs.'
 )
 
+postdowngrademessage = _(
+b'repository downgraded to not use share safe mode, '
+b'existing shares will not work and needs to'
+b' be reshared.'
+)
+
+postupgrademessage = _(
+b'repository upgraded to share safe mode, existing'
+b' shares will still work in old non-safe mode. '
+b'Re-share existing shares to use them in safe mode'
+b' New shares will be created in safe mode.'
+)
+
 
 @registerformatvariant
 class sparserevlog(requirementformatvariant):
@@ -585,6 +616,7 @@
 new_requirements,
 current_requirements,
 upgrade_actions,
+removed_actions,
 revlogs_to_process,
 ):
 self.ui = ui
@@ -593,6 +625,7 @@
 # list of upgrae actions the operation will perform
 self.upgrade_actions = upgrade_actions
 self._upgrade_actions_names = set([a.name for a in upgrade_actions])
+self.removed_actions = removed_actions
 self.revlogs_to_process = revlogs_to_process
 # requirements which will be added by the operation
 self.added_requirements = (
@@ -679,6 +712,15 @@
 """ Check whether the upgrade operation will perform this action """
 return name in self._upgrade_actions_names
 
+def print_post_op_messages(self):
+""" print post upgrade operation warning messages """
+for a in self.upgrade_actions:
+if a.postupgrademessage is not None:
+self.ui.warn(b'%s\n' % a.postupgrademessage)
+for a in self.removed_actions:
+if a.postdowngrademessage is not None:
+self.ui.warn(b'%s\n' % a.postdowngrademessage)
+
 
 ###  Code checking if a repository can got through the upgrade process at all. 
#
 
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -87,6 +87,7 @@
 up_actions = upgrade_actions.determine_upgrade_actions(
 repo, format_upgrades, optimizations, repo.requirements, newreqs
 )
+removed_actions = upgrade_actions.find_format_downgrades(repo)
 
 removedreqs = repo.requirements - newreqs
 addedreqs = newreqs - repo.requirements
@@ -108,6 +109,7 @@
 newreqs,
 repo.requirements,
 up_actions,
+removed_actions,
 revlogs,
 )
 
@@ -226,20 +228,4 @@
 )
 )
 
-if upgrade_actions.sharesafe.name in addedreqs:
-ui.warn(
-_(
-b'repository upgraded to share safe mode, existing'
-b' shares will still work in old non-safe mode. '
-b'Re-share existing shares to use them in safe mode'
-b' New shares will be created in safe mode.\n'
-)
-  

D9618: actions: introduce function to calculate downgrades

2020-12-16 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  An ugrade operation can also downgrade/remove some format variants. Before 
this
  patch there was no clean way to find out all such variants which will be
  removed. This patch adds a function for that.
  
  It will be used in next patch.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -428,6 +428,21 @@
 return upgrades
 
 
+def find_format_downgrades(repo):
+"""returns a list of format downgrades which will be performed on the repo
+because of disabled config option for them"""
+
+downgrades = []
+
+for fv in allformatvariant:
+# format variant exist in repo but does not exist in new repository
+# config
+if fv.fromrepo(repo) and not fv.fromconfig(repo):
+downgrades.append(fv)
+
+return downgrades
+
+
 ALL_OPTIMISATIONS = []
 
 



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


D9616: upgrade: rename actions to upgrade_actions

2020-12-16 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The `actions` were a list of optimizations and format ugrades which will be
  upgraded. This does not include things which will be downgraded.
  
  Let's rename the variable for clarity. It now makes obvious that we don't have
  any concrete information on what things are downgraded.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py
  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
@@ -410,13 +410,13 @@
 )
 )
 
-if upgrade_op.has_action(b're-delta-all'):
+if upgrade_op.has_upgrade_action(b're-delta-all'):
 deltareuse = revlog.revlog.DELTAREUSENEVER
-elif upgrade_op.has_action(b're-delta-parent'):
+elif upgrade_op.has_upgrade_action(b're-delta-parent'):
 deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-elif upgrade_op.has_action(b're-delta-multibase'):
+elif upgrade_op.has_upgrade_action(b're-delta-multibase'):
 deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-elif upgrade_op.has_action(b're-delta-fulladd'):
+elif upgrade_op.has_upgrade_action(b're-delta-fulladd'):
 deltareuse = revlog.revlog.DELTAREUSEFULLADD
 else:
 deltareuse = revlog.revlog.DELTAREUSEALWAYS
@@ -428,7 +428,7 @@
 dstrepo,
 tr,
 deltareuse,
-upgrade_op.has_action(b're-delta-multibase'),
+upgrade_op.has_upgrade_action(b're-delta-multibase'),
 revlogs=upgrade_op.revlogs_to_process,
 )
 
diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -526,7 +526,7 @@
 return list(ALL_OPTIMISATIONS)
 
 
-def determineactions(
+def determine_upgrade_actions(
 repo, format_upgrades, optimizations, sourcereqs, destreqs
 ):
 """Determine upgrade actions that will be performed.
@@ -569,14 +569,15 @@
 ui,
 new_requirements,
 current_requirements,
-actions,
+upgrade_actions,
 revlogs_to_process,
 ):
 self.ui = ui
 self.new_requirements = new_requirements
 self.current_requirements = current_requirements
-self.actions = actions
-self._actions_names = set([a.name for a in actions])
+# list of upgrae actions the operation will perform
+self.upgrade_actions = upgrade_actions
+self._upgrade_actions_names = set([a.name for a in upgrade_actions])
 self.revlogs_to_process = revlogs_to_process
 # requirements which will be added by the operation
 self.added_requirements = (
@@ -594,7 +595,7 @@
 # should use them
 all_optimizations = findoptimizations(None)
 self.unused_optimizations = [
-i for i in all_optimizations if i not in self.actions
+i for i in all_optimizations if i not in self.upgrade_actions
 ]
 
 def _write_labeled(self, l, label):
@@ -630,7 +631,9 @@
 self.ui.write(b'\n')
 
 def print_optimisations(self):
-optimisations = [a for a in self.actions if a.type == OPTIMISATION]
+optimisations = [
+a for a in self.upgrade_actions if a.type == OPTIMISATION
+]
 optimisations.sort(key=lambda a: a.name)
 if optimisations:
 self.ui.write(_(b'optimisations: '))
@@ -641,7 +644,7 @@
 self.ui.write(b'\n\n')
 
 def print_upgrade_actions(self):
-for a in self.actions:
+for a in self.upgrade_actions:
 self.ui.status(b'%s\n   %s\n\n' % (a.name, a.upgrademessage))
 
 def print_affected_revlogs(self):
@@ -657,9 +660,9 @@
 for i in self.unused_optimizations:
 self.ui.status(_(b'%s\n   %s\n\n') % (i.name, i.description))
 
-def has_action(self, name):
+def has_upgrade_action(self, name):
 """ Check whether the upgrade operation will perform this action """
-return name in self._actions_names
+return name in self._upgrade_actions_names
 
 
 ###  Code checking if a repository can got through the upgrade process at all. 
#
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -84,7 +84,7 @@
 )
 
 format_upgrades = upgrade_actions.find_format_upgrades(repo)
-actions = upgrade_actions.determineactions(
+up_actions = upgrade_actions.determine_upgrade_actions(
 repo, format_upgrades, optimizations, repo.requirements, newreqs
 )
 
@@ -107,7 +107,7 @@
 ui,
 newreqs,
 repo.requirements,
-

D9615: upgrade: move optimization addition to determineactions()

2020-12-16 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The documentation of `determineactions()` mention that it is given a list
  returned from `findoptimizations()` however it was not true before this patch.
  
  The code extending actions with optimizations also mentioned about it that 
this
  should be in determineactions.
  
  So let's do what comments at couple of places say.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -526,7 +526,9 @@
 return list(ALL_OPTIMISATIONS)
 
 
-def determineactions(repo, format_upgrades, sourcereqs, destreqs):
+def determineactions(
+repo, format_upgrades, optimizations, sourcereqs, destreqs
+):
 """Determine upgrade actions that will be performed.
 
 Given a list of improvements as returned by ``find_format_upgrades`` and
@@ -551,6 +553,8 @@
 
 newactions.append(d)
 
+newactions.extend(o for o in sorted(optimizations) if o not in newactions)
+
 # FUTURE consider adding some optimizations here for certain transitions.
 # e.g. adding generaldelta could schedule parent redeltas.
 
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -85,13 +85,7 @@
 
 format_upgrades = upgrade_actions.find_format_upgrades(repo)
 actions = upgrade_actions.determineactions(
-repo, format_upgrades, repo.requirements, newreqs
-)
-actions.extend(
-o
-for o in sorted(optimizations)
-# determineactions could have added optimisation
-if o not in actions
+repo, format_upgrades, optimizations, repo.requirements, newreqs
 )
 
 removedreqs = repo.requirements - newreqs



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


D9583: upgrade: add a missing space in status message

2020-12-14 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Found while reading the code to refactor.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -659,7 +659,7 @@
   replacing store...
   store replacement complete; repository was inconsistent for * (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content$TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
+  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ ls -1 .hg/ | grep upgradebackup
   [1]
@@ -706,7 +706,7 @@
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content$TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
+  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
 
 Check that the repo still works fine
@@ -786,7 +786,7 @@
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content$TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
+  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ hg verify
   checking changesets
@@ -837,7 +837,7 @@
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content$TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
+  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ hg verify
   checking changesets
@@ -888,7 +888,7 @@
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content$TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
+  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ hg verify
   checking changesets
@@ -946,7 +946,7 @@
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content$TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
+  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ hg verify
   checking changesets
@@ -1005,7 +1005,7 @@
   replacing store...
   store replacement complete; repository was inconsistent for *s (glob)
   finalizing requirements file and making repository readable again
-  removing old repository content$TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
+  removing old repository content $TESTTMP/upgradegd/.hg/upgradebackup.* (glob)
   removing temporary repository $TESTTMP/upgradegd/.hg/upgrade.* (glob)
   $ hg verify
   checking changesets
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -228,7 +228,7 @@
 )
 if not (backup or backuppath is None):
 ui.status(
-_(b'removing old repository content%s\n') % backuppath
+_(b'removing old repository content %s\n') % backuppath
 )
 repo.vfs.rmtree(backuppath, forcibly=True)
 backuppath = None



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


D9582: upgrade: rename deficiences to format_upgrades

2020-12-14 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It was not obvious what does deficieny means and every format upgrade can't 
be a
  deficiency. There are some format upgrades like compression levels, share-safe
  which can't be understood at deficiencies.
  
  This patch renames to make it more clearer. The ui message also improved
  which is a good thing.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -173,7 +173,7 @@
}
   ]
   $ hg debugupgraderepo
-  (no feature deficiencies found in existing repository)
+  (no format upgrades found in existing repository)
   performing an upgrade with "--run" will make the following changes:
   
   requirements
@@ -212,7 +212,7 @@
 --optimize can be used to add optimizations
 
   $ hg debugupgrade --optimize redeltaparent
-  (no feature deficiencies found in existing repository)
+  (no format upgrades found in existing repository)
   performing an upgrade with "--run" will make the following changes:
   
   requirements
@@ -243,7 +243,7 @@
 modern form of the option
 
   $ hg debugupgrade --optimize re-delta-parent
-  (no feature deficiencies found in existing repository)
+  (no format upgrades found in existing repository)
   performing an upgrade with "--run" will make the following changes:
   
   requirements
diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -28,7 +28,7 @@
 return set()
 
 
-DEFICIENCY = b'deficiency'
+FORMAT_UPGRADE = b'deficiency'
 OPTIMISATION = b'optimization'
 
 
@@ -42,13 +42,15 @@
will be mapped to an action later in the upgrade process.
 
 type
-   Either ``DEFICIENCY`` or ``OPTIMISATION``. A deficiency is an obvious
-   problem. An optimization is an action (sometimes optional) that
+   Either ``FORMAT_UPGRADE`` or ``OPTIMISATION``.
+   A format upgrade is where we can upgrade the storage format. Not
+   all storage formats upgrades are deficiencies.
+   An optimization is an action (sometimes optional) that
can be taken to further improve the state of the repository.
 
 description
Message intended for humans explaining the improvement in more detail,
-   including the implications of it. For ``DEFICIENCY`` types, should be
+   including the implications of it. For ``FORMAT_UPGRADE`` types, should 
be
worded in the present tense. For ``OPTIMISATION`` types, should be
worded in the future tense.
 
@@ -87,7 +89,7 @@
 class formatvariant(improvement):
 """an improvement subclass dedicated to repository format"""
 
-type = DEFICIENCY
+type = FORMAT_UPGRADE
 ### The following attributes should be defined for each class:
 
 # machine-readable string uniquely identifying this improvement. it will be
@@ -95,7 +97,8 @@
 name = None
 
 # message intended for humans explaining the improvement in more detail,
-# including the implications of it ``DEFICIENCY`` types, should be worded
+# including the implications of it ``FORMAT_UPGRADE`` types, should be
+# worded
 # in the present tense.
 description = None
 
@@ -410,9 +413,9 @@
 return bytes(level)
 
 
-def finddeficiencies(repo):
-"""returns a list of deficiencies that the repo suffer from"""
-deficiencies = []
+def find_format_upgrades(repo):
+"""returns a list of format upgrades which can be perform on the repo"""
+upgrades = []
 
 # We could detect lack of revlogv1 and store here, but they were added
 # in 0.9.2 and we don't support upgrading repos without these
@@ -420,9 +423,9 @@
 
 for fv in allformatvariant:
 if not fv.fromrepo(repo):
-deficiencies.append(fv)
+upgrades.append(fv)
 
-return deficiencies
+return upgrades
 
 
 ALL_OPTIMISATIONS = []
@@ -523,10 +526,10 @@
 return list(ALL_OPTIMISATIONS)
 
 
-def determineactions(repo, deficiencies, sourcereqs, destreqs):
+def determineactions(repo, format_upgrades, sourcereqs, destreqs):
 """Determine upgrade actions that will be performed.
 
-Given a list of improvements as returned by ``finddeficiencies`` and
+Given a list of improvements as returned by ``find_format_upgrades`` and
 ``findoptimizations``, determine the list of upgrade actions that
 will be performed.
 
@@ -538,7 +541,7 @@
 """
 newactions = []
 
-for d in deficiencies:
+for d in format_upgrades:
 name = d._requirement
 
 # If the action is a requirement that doesn't show up in the
diff --git 

D9580: engine: unwrap a hard to understand for loop

2020-12-14 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The loop was iterating over all the datafiles and maintaining a set to check
  whether filelogs have been processed, manifests have been processed or not.
  
  The code was hard to understand and it assumed that `alldatafiles` are ordered
  in a certain way.
  
  This refactors the for loop in separate parts for each manifests, changelog 
and
  filelogs. This will also help in future work where we will like more better
  handling on whether we want to upgrade filelogs or not.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -148,6 +148,12 @@
 cdstsize = 0
 
 alldatafiles = list(srcrepo.store.walk())
+# mapping of data files which needs to be cloned
+# key is unencoded filename
+# value is revlog_object_from_srcrepo
+manifests = {}
+changelogs = {}
+filelogs = {}
 
 # Perform a pass to collect metadata. This validates we can open all
 # source files and allows a unified progress bar to be displayed.
@@ -173,15 +179,18 @@
 
 # This is for the separate progress bars.
 if isinstance(rl, changelog.changelog):
+changelogs[unencoded] = rl
 crevcount += len(rl)
 csrcsize += datasize
 crawsize += rawsize
 elif isinstance(rl, manifest.manifestrevlog):
+manifests[unencoded] = rl
 mcount += 1
 mrevcount += len(rl)
 msrcsize += datasize
 mrawsize += rawsize
 elif isinstance(rl, filelog.filelog):
+filelogs[unencoded] = rl
 fcount += 1
 frevcount += len(rl)
 fsrcsize += datasize
@@ -240,101 +249,90 @@
 newrl = _revlogfrompath(dstrepo, unencoded)
 return newrl
 
-# Do the actual copying.
-# FUTURE this operation can be farmed off to worker processes.
-seen = set()
-for unencoded, encoded, size in alldatafiles:
-if unencoded.endswith(b'.d'):
-continue
-
-oldrl = _revlogfrompath(srcrepo, unencoded)
-
-if isinstance(oldrl, changelog.changelog) and b'c' not in seen:
-ui.status(
-_(
-b'finished migrating %d manifest revisions across %d '
-b'manifests; change in size: %s\n'
-)
-% (mrevcount, mcount, util.bytecount(mdstsize - msrcsize))
-)
-
-ui.status(
-_(
-b'migrating changelog containing %d revisions '
-b'(%s in store; %s tracked data)\n'
-)
-% (
-crevcount,
-util.bytecount(csrcsize),
-util.bytecount(crawsize),
-)
-)
-seen.add(b'c')
-progress = srcrepo.ui.makeprogress(
-_(b'changelog revisions'), total=crevcount
-)
-elif isinstance(oldrl, manifest.manifestrevlog) and b'm' not in seen:
-ui.status(
-_(
-b'finished migrating %d filelog revisions across %d '
-b'filelogs; change in size: %s\n'
-)
-% (frevcount, fcount, util.bytecount(fdstsize - fsrcsize))
-)
-
-ui.status(
-_(
-b'migrating %d manifests containing %d revisions '
-b'(%s in store; %s tracked data)\n'
-)
-% (
-mcount,
-mrevcount,
-util.bytecount(msrcsize),
-util.bytecount(mrawsize),
-)
-)
-seen.add(b'm')
-if progress:
-progress.complete()
-progress = srcrepo.ui.makeprogress(
-_(b'manifest revisions'), total=mrevcount
-)
-elif b'f' not in seen:
-ui.status(
-_(
-b'migrating %d filelogs containing %d revisions '
-b'(%s in store; %s tracked data)\n'
-)
-% (
-fcount,
-frevcount,
-util.bytecount(fsrcsize),
-util.bytecount(frawsize),
-)
-)
-seen.add(b'f')
-if progress:
-progress.complete()
-progress = srcrepo.ui.makeprogress(
-_(b'file revisions'), total=frevcount
-)
-
+# Migrating filelogs
+ui.status(
+_(
+   

D9579: engine: refactor actual cloning code into separate function

2020-12-14 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The `for ...` under which this cloning code exists is too complicated and 
based
  on certain assumptions. I am going to refactor it in next patches and make it
  bit saner.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -212,6 +212,34 @@
 
 sidedatacompanion = getsidedatacompanion(srcrepo, dstrepo)
 
+def _perform_clone(
+old_revlog,
+unencoded,
+):
+""" returns the new revlog object created"""
+newrl = None
+if matchrevlog(revlogs, unencoded):
+ui.note(
+_(b'cloning %d revisions from %s\n')
+% (len(old_revlog), unencoded)
+)
+newrl = _revlogfrompath(dstrepo, unencoded)
+oldrl.clone(
+tr,
+newrl,
+addrevisioncb=oncopiedrevision,
+deltareuse=deltareuse,
+forcedeltabothparents=forcedeltabothparents,
+sidedatacompanion=sidedatacompanion,
+)
+else:
+msg = _(b'blindly copying %s containing %i revisions\n')
+ui.note(msg % (unencoded, len(old_revlog)))
+_copyrevlog(tr, dstrepo, old_revlog, unencoded)
+
+newrl = _revlogfrompath(dstrepo, unencoded)
+return newrl
+
 # Do the actual copying.
 # FUTURE this operation can be farmed off to worker processes.
 seen = set()
@@ -292,26 +320,7 @@
 _(b'file revisions'), total=frevcount
 )
 
-if matchrevlog(revlogs, unencoded):
-ui.note(
-_(b'cloning %d revisions from %s\n') % (len(oldrl), unencoded)
-)
-newrl = _revlogfrompath(dstrepo, unencoded)
-oldrl.clone(
-tr,
-newrl,
-addrevisioncb=oncopiedrevision,
-deltareuse=deltareuse,
-forcedeltabothparents=forcedeltabothparents,
-sidedatacompanion=sidedatacompanion,
-)
-else:
-msg = _(b'blindly copying %s containing %i revisions\n')
-ui.note(msg % (unencoded, len(oldrl)))
-_copyrevlog(tr, dstrepo, oldrl, unencoded)
-
-newrl = _revlogfrompath(dstrepo, unencoded)
-
+newrl = _perform_clone(oldrl, unencoded)
 info = newrl.storageinfo(storedsize=True)
 datasize = info[b'storedsize'] or 0
 



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


D9578: upgrade: move printing of unused optimizations to UpgradeOperation class

2020-12-14 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/D9578

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -563,6 +563,7 @@
 new_requirements,
 current_requirements,
 actions,
+all_optimizations,
 revlogs_to_process,
 ):
 self.ui = ui
@@ -583,6 +584,12 @@
 self.preserved_requirements = (
 self.current_requirements & self.new_requirements
 )
+self.all_optimizations = all_optimizations
+# optimizations which are not used and it's recommended that they
+# should use them
+self.unused_optimizations = [
+i for i in all_optimizations if i not in self.actions
+]
 
 def _write_labeled(self, l, label):
 """
@@ -640,6 +647,10 @@
 self.ui.write((b'  - %s\n' % r))
 self.ui.write((b'\n'))
 
+def print_unused_optimizations(self):
+for i in self.unused_optimizations:
+self.ui.status(_(b'%s\n   %s\n\n') % (i.name, i.description))
+
 def has_action(self, name):
 """ Check whether the upgrade operation will perform this action """
 return name in self._actions_names
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -128,6 +128,7 @@
 newreqs,
 repo.requirements,
 actions,
+alloptimizations,
 revlogs,
 )
 
@@ -184,17 +185,14 @@
 upgrade_op.print_upgrade_actions()
 upgrade_op.print_affected_revlogs()
 
-unusedoptimize = [i for i in alloptimizations if i not in actions]
-
-if unusedoptimize:
+if upgrade_op.unused_optimizations:
 ui.status(
 _(
 b'additional optimizations are available by specifying '
 b'"--optimize ":\n\n'
 )
 )
-for i in unusedoptimize:
-ui.status(_(b'%s\n   %s\n\n') % (i.name, i.description))
+upgrade_op.print_unused_optimizations()
 return
 
 # Else we're in the run=true case.



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


D9577: upgrade: move `printrequirements()` to UpgradeOperation class

2020-12-14 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Part of refactor where we make things more arranged and integrated into single
  `UpgradeOperation` class.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py
  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
@@ -429,7 +429,7 @@
 # The sorted() makes execution deterministic.
 for p, kind, st in sorted(srcrepo.store.vfs.readdir(b'', stat=True)):
 if not _filterstorefile(
-srcrepo, dstrepo, upgrade_op.requirements, p, kind, st
+srcrepo, dstrepo, upgrade_op.new_requirements, p, kind, st
 ):
 continue
 
@@ -489,7 +489,7 @@
 b'again\n'
 )
 )
-scmutil.writereporequirements(srcrepo, upgrade_op.requirements)
+scmutil.writereporequirements(srcrepo, upgrade_op.new_requirements)
 
 # The lock file from the old store won't be removed because nothing has a
 # reference to its new location. So clean it up manually. Alternatively, we
diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -557,12 +557,32 @@
 class UpgradeOperation(object):
 """represent the work to be done during an upgrade"""
 
-def __init__(self, ui, requirements, actions, revlogs_to_process):
+def __init__(
+self,
+ui,
+new_requirements,
+current_requirements,
+actions,
+revlogs_to_process,
+):
 self.ui = ui
-self.requirements = requirements
+self.new_requirements = new_requirements
+self.current_requirements = current_requirements
 self.actions = actions
 self._actions_names = set([a.name for a in actions])
 self.revlogs_to_process = revlogs_to_process
+# requirements which will be added by the operation
+self.added_requirements = (
+self.new_requirements - self.current_requirements
+)
+# requirements which will be removed by the operation
+self.removed_requirements = (
+self.current_requirements - self.new_requirements
+)
+# requirements which will be preserved by the operation
+self.preserved_requirements = (
+self.current_requirements & self.new_requirements
+)
 
 def _write_labeled(self, l, label):
 """
@@ -575,6 +595,27 @@
 self.ui.write(r, label=label)
 first = False
 
+def print_requirements(self):
+self.ui.write(_(b'requirements\n'))
+self.ui.write(_(b'   preserved: '))
+self._write_labeled(
+self.preserved_requirements, "upgrade-repo.requirement.preserved"
+)
+self.ui.write((b'\n'))
+if self.removed_requirements:
+self.ui.write(_(b'   removed: '))
+self._write_labeled(
+self.removed_requirements, "upgrade-repo.requirement.removed"
+)
+self.ui.write((b'\n'))
+if self.added_requirements:
+self.ui.write(_(b'   added: '))
+self._write_labeled(
+self.added_requirements, "upgrade-repo.requirement.added"
+)
+self.ui.write((b'\n'))
+self.ui.write(b'\n')
+
 def print_optimisations(self):
 optimisations = [a for a in self.actions if a.type == OPTIMISATION]
 optimisations.sort(key=lambda a: a.name)
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -123,36 +123,10 @@
 ui.warn(msg % b', '.join(sorted(incompatible)))
 revlogs = upgrade_engine.UPGRADE_ALL_REVLOGS
 
-def write_labeled(l, label):
-first = True
-for r in sorted(l):
-if not first:
-ui.write(b', ')
-ui.write(r, label=label)
-first = False
-
-def printrequirements():
-ui.write(_(b'requirements\n'))
-ui.write(_(b'   preserved: '))
-write_labeled(
-newreqs & repo.requirements, "upgrade-repo.requirement.preserved"
-)
-ui.write((b'\n'))
-removed = repo.requirements - newreqs
-if repo.requirements - newreqs:
-ui.write(_(b'   removed: '))
-write_labeled(removed, "upgrade-repo.requirement.removed")
-ui.write((b'\n'))
-added = newreqs - repo.requirements
-if added:
-ui.write(_(b'   added: '))
-write_labeled(added, "upgrade-repo.requirement.added")
-ui.write((b'\n'))
-

D9576: upgrade: move `printoptimisations() to UpgradeOperation class

2020-12-14 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Part of refactor where we make things more arranged and integrated into single
  `UpgradeOperation` class.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -564,6 +564,28 @@
 self._actions_names = set([a.name for a in actions])
 self.revlogs_to_process = revlogs_to_process
 
+def _write_labeled(self, l, label):
+"""
+Utility function to aid writing of a list under one label
+"""
+first = True
+for r in sorted(l):
+if not first:
+self.ui.write(b', ')
+self.ui.write(r, label=label)
+first = False
+
+def print_optimisations(self):
+optimisations = [a for a in self.actions if a.type == OPTIMISATION]
+optimisations.sort(key=lambda a: a.name)
+if optimisations:
+self.ui.write(_(b'optimisations: '))
+self._write_labeled(
+[a.name for a in optimisations],
+"upgrade-repo.optimisation.performed",
+)
+self.ui.write(b'\n\n')
+
 def print_upgrade_actions(self):
 for a in self.actions:
 self.ui.status(b'%s\n   %s\n\n' % (a.name, a.upgrademessage))
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -150,19 +150,6 @@
 ui.write((b'\n'))
 ui.write(b'\n')
 
-def printoptimisations():
-optimisations = [
-a for a in actions if a.type == upgrade_actions.OPTIMISATION
-]
-optimisations.sort(key=lambda a: a.name)
-if optimisations:
-ui.write(_(b'optimisations: '))
-write_labeled(
-[a.name for a in optimisations],
-"upgrade-repo.optimisation.performed",
-)
-ui.write(b'\n\n')
-
 upgrade_op = upgrade_actions.UpgradeOperation(
 ui,
 newreqs,
@@ -219,7 +206,7 @@
 )
 
 printrequirements()
-printoptimisations()
+upgrade_op.print_optimisations()
 upgrade_op.print_upgrade_actions()
 upgrade_op.print_affected_revlogs()
 
@@ -239,7 +226,7 @@
 # Else we're in the run=true case.
 ui.write(_(b'upgrade will perform the following actions:\n\n'))
 printrequirements()
-printoptimisations()
+upgrade_op.print_optimisations()
 upgrade_op.print_upgrade_actions()
 upgrade_op.print_affected_revlogs()
 



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


D9575: upgrade: move `printupgradeactions()` to UpgradeOperation class

2020-12-14 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Part of refactor where we make things more arranged and integrated into single
  `UpgradeOperation` class.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py
  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
@@ -403,13 +403,13 @@
 )
 )
 
-if b're-delta-all' in upgrade_op.actions:
+if upgrade_op.has_action(b're-delta-all'):
 deltareuse = revlog.revlog.DELTAREUSENEVER
-elif b're-delta-parent' in upgrade_op.actions:
+elif upgrade_op.has_action(b're-delta-parent'):
 deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-elif b're-delta-multibase' in upgrade_op.actions:
+elif upgrade_op.has_action(b're-delta-multibase'):
 deltareuse = revlog.revlog.DELTAREUSESAMEREVS
-elif b're-delta-fulladd' in upgrade_op.actions:
+elif upgrade_op.has_action(b're-delta-fulladd'):
 deltareuse = revlog.revlog.DELTAREUSEFULLADD
 else:
 deltareuse = revlog.revlog.DELTAREUSEALWAYS
@@ -421,7 +421,7 @@
 dstrepo,
 tr,
 deltareuse,
-b're-delta-multibase' in upgrade_op.actions,
+upgrade_op.has_action(b're-delta-multibase'),
 revlogs=upgrade_op.revlogs_to_process,
 )
 
diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -561,8 +561,13 @@
 self.ui = ui
 self.requirements = requirements
 self.actions = actions
+self._actions_names = set([a.name for a in actions])
 self.revlogs_to_process = revlogs_to_process
 
+def print_upgrade_actions(self):
+for a in self.actions:
+self.ui.status(b'%s\n   %s\n\n' % (a.name, a.upgrademessage))
+
 def print_affected_revlogs(self):
 if not self.revlogs_to_process:
 self.ui.write((b'no revlogs to process\n'))
@@ -572,6 +577,10 @@
 self.ui.write((b'  - %s\n' % r))
 self.ui.write((b'\n'))
 
+def has_action(self, name):
+""" Check whether the upgrade operation will perform this action """
+return name in self._actions_names
+
 
 ###  Code checking if a repository can got through the upgrade process at all. 
#
 
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -163,14 +163,10 @@
 )
 ui.write(b'\n\n')
 
-def printupgradeactions():
-for a in actions:
-ui.status(b'%s\n   %s\n\n' % (a.name, a.upgrademessage))
-
 upgrade_op = upgrade_actions.UpgradeOperation(
 ui,
 newreqs,
-[a.name for a in actions],
+actions,
 revlogs,
 )
 
@@ -224,7 +220,7 @@
 
 printrequirements()
 printoptimisations()
-printupgradeactions()
+upgrade_op.print_upgrade_actions()
 upgrade_op.print_affected_revlogs()
 
 unusedoptimize = [i for i in alloptimizations if i not in actions]
@@ -244,7 +240,7 @@
 ui.write(_(b'upgrade will perform the following actions:\n\n'))
 printrequirements()
 printoptimisations()
-printupgradeactions()
+upgrade_op.print_upgrade_actions()
 upgrade_op.print_affected_revlogs()
 
 ui.status(_(b'beginning upgrade...\n'))



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


D9574: upgrade: move `print_affected_revlogs()` to UpgradeOperation class

2020-12-14 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Part of refactor where we make things more arranged and integrated into single
  `UpgradeOperation` class.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -557,11 +557,21 @@
 class UpgradeOperation(object):
 """represent the work to be done during an upgrade"""
 
-def __init__(self, requirements, actions, revlogs_to_process):
+def __init__(self, ui, requirements, actions, revlogs_to_process):
+self.ui = ui
 self.requirements = requirements
 self.actions = actions
 self.revlogs_to_process = revlogs_to_process
 
+def print_affected_revlogs(self):
+if not self.revlogs_to_process:
+self.ui.write((b'no revlogs to process\n'))
+else:
+self.ui.write((b'processed revlogs:\n'))
+for r in sorted(self.revlogs_to_process):
+self.ui.write((b'  - %s\n' % r))
+self.ui.write((b'\n'))
+
 
 ###  Code checking if a repository can got through the upgrade process at all. 
#
 
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -167,16 +167,8 @@
 for a in actions:
 ui.status(b'%s\n   %s\n\n' % (a.name, a.upgrademessage))
 
-def print_affected_revlogs():
-if not revlogs:
-ui.write((b'no revlogs to process\n'))
-else:
-ui.write((b'processed revlogs:\n'))
-for r in sorted(revlogs):
-ui.write((b'  - %s\n' % r))
-ui.write((b'\n'))
-
 upgrade_op = upgrade_actions.UpgradeOperation(
+ui,
 newreqs,
 [a.name for a in actions],
 revlogs,
@@ -233,7 +225,7 @@
 printrequirements()
 printoptimisations()
 printupgradeactions()
-print_affected_revlogs()
+upgrade_op.print_affected_revlogs()
 
 unusedoptimize = [i for i in alloptimizations if i not in actions]
 
@@ -253,7 +245,7 @@
 printrequirements()
 printoptimisations()
 printupgradeactions()
-print_affected_revlogs()
+upgrade_op.print_affected_revlogs()
 
 ui.status(_(b'beginning upgrade...\n'))
 with repo.wlock(), repo.lock():



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


D9570: debugcommands: introduce command to upgrade/downgrade shares

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

REVISION SUMMARY
  In past few months, we have developed functionality to share requirements and
  configs of share-source and a way to upgrade repository from old format to
  share-safe format using `debugupgraderepo` command.
  
  However there is still no way to upgrade the shares as `debugupgraderepo` does
  not support upgrading that.
  
  Having share-safe rolled out in existing setup is quite important and hence we
  need a way to upgrade existing shares once share-source upgrades.
  
  This patch introduces a new debug command `debugsharesafe` which can be used 
to
  upgrade or downgrade shares.
  
  Functionality to upgrade shares to use the new method is the last thing left 
in
  the whole work.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/debugcommands.py
  tests/test-completion.t
  tests/test-help.t
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -70,6 +70,16 @@
   $ echo c > c
   $ hg ci -Aqm "added c"
 
+  $ hg debugsharesafe
+  abort: nothing specified
+  [10]
+  $ hg debugsharesafe --upgrade --downgrade
+  abort: cannot specify both --upgrade and --downgrade
+  [10]
+  $ hg debugsharesafe --upgrade
+  abort: repository already uses share-safe method
+  [20]
+
 Check that config of the source repository is also loaded
 
   $ hg showconfig ui.curses
@@ -399,6 +409,26 @@
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
 
+  $ hg debugsharesafe -R ../nss-share --downgrade
+  warning: source repository supports share-safe functionality. Reshare to 
upgrade.
+  abort: repository does not uses share safe method, nothing to do
+  [20]
+
+  $ hg debugsharesafe -R ../nss-share --upgrade
+  warning: source repository supports share-safe functionality. Reshare to 
upgrade.
+  repository upgraded to use share-safe functionality
+  requirements and configs of shared-source will be read from now onwards
+
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+
+  $ hg debugsharesafe -R ../nss-share --downgrade
+  repository downgraded to not use share-safe functionality
+
+
 
 Create a safe share from upgrade one
 
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1068,6 +1068,8 @@
debugserverun a server with advanced settings
debugsetparents
  manually set the parents of the current working directory
+   debugsharesafe
+ upgrade or downgrade shares to enable/disable share-safe mode
debugsidedata
  dump the side data for a cl/manifest/file revision
debugssl  test a secure connection to a server
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -129,6 +129,7 @@
   debugrevspec
   debugserve
   debugsetparents
+  debugsharesafe
   debugsidedata
   debugssl
   debugstrip
@@ -318,6 +319,7 @@
   debugrevspec: optimize, show-revs, show-set, show-stage, no-optimized, 
verify-optimized
   debugserve: sshstdio, logiofd, logiofile
   debugsetparents: 
+  debugsharesafe: upgrade, downgrade, force
   debugsidedata: changelog, manifest, dir
   debugssl: 
   debugstrip: rev, force, no-backup, nobackup, , keep, bookmark, soft
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -69,6 +69,7 @@
 pycompat,
 registrar,
 repair,
+requirements as requirementsmod,
 revlog,
 revset,
 revsetlang,
@@ -3695,6 +3696,107 @@
 
 
 @command(
+b'debugsharesafe',
+[
+(b'', b'upgrade', False, _(b'upgrade current share to share safe')),
+(b'', b'downgrade', False, _(b'downgrade current share')),
+(b'', b'force', False, _(b'forcefully perform operation')),
+],
+)
+def debugsharesafe(ui, repo, *args, **opts):
+"""upgrade or downgrade shares to enable/disable share-safe mode"""
+if not repo.shared():
+raise error.InputError(_(b"current repository is not shared one"))
+
+cmdutil.check_at_most_one_arg(opts, 'upgrade', 'downgrade')
+upgrade = opts.get('upgrade')
+downgrade = opts.get('downgrade')
+
+if not upgrade and not downgrade:
+raise error.InputError(_(b"nothing specified"))
+
+current_requirements = repo.requirements
+if upgrade:
+if requirementsmod.SHARESAFE_REQUIREMENT in current_requirements:
+raise error.StateError(
+_(b"repository already uses share-safe method")
+)
+
+sharesourcerequires = localrepo._readrequires(
+

D9571: debugsharesafe: recommend from `debugupgraderepo` and `help -e share -v`

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

REVISION SUMMARY
  Recommending one debug command from another one sounds fine to me.
  
  Also documentation about share-safe in `hg help -e share -v` was lacking 
correct
  description on how upgrade existing shares. This fixes that and also start
  mentioning about debugsharesafe.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/share.py
  mercurial/upgrade.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -372,7 +372,8 @@
 - changelog
 - manifest
   
-  repository upgraded to share safe mode, existing shares will still work in 
old non-safe mode. Re-share existing shares to use them in safe mode New shares 
will be created in safe mode.
+  repository upgraded to share safe mode, existing shares will still work in 
old non-safe mode.
+  (Run `hg debugsharesafe --upgrade` in shares to  update them to use share 
safe mode.)
 
   $ hg debugrequirements
   dotencode
@@ -475,7 +476,8 @@
 - changelog
 - manifest
   
-  repository downgraded to not use share safe mode, existing shares will not 
work and needs to be reshared.
+  repository downgraded to not use share safe mode, existing shares will not 
work.
+  (Run `hg debugsharesafe --downgrade` in shares to downgrade them.)
 
   $ hg debugrequirements
   dotencode
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -309,16 +309,17 @@
 ui.warn(
 _(
 b'repository upgraded to share safe mode, existing'
-b' shares will still work in old non-safe mode. '
-b'Re-share existing shares to use them in safe mode'
-b' New shares will be created in safe mode.\n'
+b' shares will still work in old non-safe mode.\n'
+b'(Run `hg debugsharesafe --upgrade` in shares to '
+b' update them to use share safe mode.)\n'
 )
 )
 if upgrade_actions.sharesafe.name in removedreqs:
 ui.warn(
 _(
 b'repository downgraded to not use share safe mode, '
-b'existing shares will not work and needs to'
-b' be reshared.\n'
+b'existing shares will not work.\n(Run `hg '
+b'debugsharesafe --downgrade` in shares '
+b'to downgrade them.)\n'
 )
 )
diff --git a/hgext/share.py b/hgext/share.py
--- a/hgext/share.py
+++ b/hgext/share.py
@@ -59,10 +59,9 @@
 requirements. This only applies to shares which are done after enabling
 the config option.
 
-For enabling this in existing shares, enable the config option and reshare.
-
-For resharing existing shares, make sure your working directory is clean
-and there are no untracked files, delete that share and create a new share.
+For enabling this in existing shares, upgrade the shared-source using
+`hg debugupgraderepo` and then upgrade shares using
+`hg debugsharesafe --upgrade` command.
 '''
 
 from __future__ import absolute_import



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


D9569: contrib: run python3+chg tests too in heptapod CI

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

REVISION SUMMARY
  Recent patches made the CI on python3+chg green. Let's enable this before 
there
  are more failures to fix.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -114,3 +114,10 @@
 variables:
 RUNTEST_ARGS: "--blacklist /tmp/check-tests.txt --chg"
 TEST_HGMODULEPOLICY: "c"
+
+test-py3-chg:
+<<: *runtests
+variables:
+PYTHON: python3
+RUNTEST_ARGS: "--blacklist /tmp/check-tests.txt --chg"
+TEST_HGMODULEPOLICY: "c"



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


D9568: scmutil: improve documentation of writereporequirements()

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

REVISION SUMMARY
  This makes it easier to understand the difference between `writerequires()`
  and `writereporequirements()`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1572,7 +1572,12 @@
 
 
 def writereporequirements(repo, requirements=None):
-""" writes requirements for the repo to .hg/requires """
+"""writes requirements for the repo
+
+Requirements are written to .hg/requires and .hg/store/requires based
+on whether share-safe mode is enabled and which requirements are wdir
+requirements and which are store requirements
+"""
 if requirements:
 repo.requirements = requirements
 wcreq, storereq = filterrequirements(repo.requirements)



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


D9517: commandserver: handle IOError related to flushing of streams

2020-12-04 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  After dispatch, without chg we have handling of flushing of streams and
  exception handling related to it. The exception handling part is important
  because there can be exceptions when flushing fout or ferr.
  
  One such case is in `test-basic.t` which was failing on python3+chg without 
this
  patch as this handling was missing from chg.
  
  Failure can be seen at
  https://foss.heptapod.net/octobus/mercurial-devel/-/jobs/128399
  
  Honestly I am not sure which one of `chgserver.py` or `commandserver.py` the
  change should go in.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/commandserver.py
  mercurial/dispatch.py

CHANGE DETAILS

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -104,6 +104,36 @@
 raise exc
 
 
+def closestdio(ui, err):
+status = None
+# In all cases we try to flush stdio streams.
+if util.safehasattr(ui, b'fout'):
+assert ui is not None  # help pytype
+assert ui.fout is not None  # help pytype
+try:
+ui.fout.flush()
+except IOError as e:
+err = e
+status = -1
+
+if util.safehasattr(ui, b'ferr'):
+assert ui is not None  # help pytype
+assert ui.ferr is not None  # help pytype
+try:
+if err is not None and err.errno != errno.EPIPE:
+ui.ferr.write(
+b'abort: %s\n' % encoding.strtolocal(err.strerror)
+)
+ui.ferr.flush()
+# There's not much we can do about an I/O error here. So (possibly)
+# change the status code and move on.
+except IOError:
+status = -1
+
+_silencestdio()
+return status
+
+
 def run():
 """run the command in sys.argv"""
 try:
@@ -117,31 +147,9 @@
 err = e
 status = -1
 
-# In all cases we try to flush stdio streams.
-if util.safehasattr(req.ui, b'fout'):
-assert req.ui is not None  # help pytype
-assert req.ui.fout is not None  # help pytype
-try:
-req.ui.fout.flush()
-except IOError as e:
-err = e
-status = -1
-
-if util.safehasattr(req.ui, b'ferr'):
-assert req.ui is not None  # help pytype
-assert req.ui.ferr is not None  # help pytype
-try:
-if err is not None and err.errno != errno.EPIPE:
-req.ui.ferr.write(
-b'abort: %s\n' % encoding.strtolocal(err.strerror)
-)
-req.ui.ferr.flush()
-# There's not much we can do about an I/O error here. So (possibly)
-# change the status code and move on.
-except IOError:
-status = -1
-
-_silencestdio()
+ret = closestdio(req.ui, err)
+if ret:
+status = ret
 except KeyboardInterrupt:
 # Catch early/late KeyboardInterrupt as last ditch. Here nothing will
 # be printed to console to avoid another IOError/KeyboardInterrupt.
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -355,7 +355,18 @@
 )
 
 try:
-ret = self._dispatchcommand(req) & 255
+err = None
+try:
+status = self._dispatchcommand(req)
+except error.StdioError as e:
+status = -1
+err = e
+
+retval = dispatch.closestdio(req.ui, err)
+if retval:
+status = retval
+
+ret = status & 255
 # If shutdown-on-interrupt is off, it's important to write the
 # result code *after* SIGINT handler removed. If the result code
 # were lost, the client wouldn't be able to continue processing.



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


D9502: tests: conditionalize output in test-ssh.t with chg+py3

2020-12-02 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Because of our wrapping around sys.std* and python3 internal buffering, the
  output order changes. The change in order seems like harmless because just few
  lines above the same command is run which results in same output.
  
  This makes `test-ssh.t` works with --chg on python 3.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  tests/test-ssh.t

CHANGE DETAILS

diff --git a/tests/test-ssh.t b/tests/test-ssh.t
--- a/tests/test-ssh.t
+++ b/tests/test-ssh.t
@@ -331,9 +331,10 @@
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
+  remote: added 1 changesets with 1 changes to 1 files (py3 !)
   remote: KABOOM
   remote: KABOOM IN PROCESS
-  remote: added 1 changesets with 1 changes to 1 files
+  remote: added 1 changesets with 1 changes to 1 files (no-py3 !)
 
 #endif
 



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


D9501: dispatch: disable line ending normalization on sys.stdin if its None

2020-12-02 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Fixes test-chg.t on python 3 with chg.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/dispatch.py

CHANGE DETAILS

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -187,15 +187,16 @@
 sys.stderr.buffer, sys.stderr.encoding, sys.stderr.errors, **kwargs
 )
 
-# No write_through on read-only stream.
-sys.stdin = io.TextIOWrapper(
-sys.stdin.buffer,
-sys.stdin.encoding,
-sys.stdin.errors,
-# None is universal newlines mode.
-newline=None,
-line_buffering=sys.stdin.line_buffering,
-)
+if sys.stdin is not None:
+# No write_through on read-only stream.
+sys.stdin = io.TextIOWrapper(
+sys.stdin.buffer,
+sys.stdin.encoding,
+sys.stdin.errors,
+# None is universal newlines mode.
+newline=None,
+line_buffering=sys.stdin.line_buffering,
+)
 
 def _silencestdio():
 for fp in (sys.stdout, sys.stderr):



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


D9500: procutils: don't try to get `.buffer` if sys.stdin is None

2020-12-02 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  While hunting down following test failure of test-chg.t on Python 3, I 
stumbled
  the case when `.buffer` is not available as sys.stdin is None.
  
  - /home/pulkit/repo/hg-committed/tests/test-chg.t
  
  +++ /home/pulkit/repo/hg-committed/tests/test-chg.t.err
@@ -203,7 +203,31 @@
  
   $ CHGDEBUG=1 chg version -q 0<&-
 chg: debug: * stdio fds are missing (glob)
 chg: debug: * execute original hg (glob)
 -  Mercurial Distributed SCM * (glob)
 +  Traceback (most recent call last):
 +File "/tmp/hgtests.avspvsq4/install/bin/hg", line 43, in 

 +  dispatch.run()
 +File "/usr/lib/python3.6/importlib/util.py", line 233, in
 __getattribute__
 +  self.__spec__.loader.exec_module(self)
 +File "", line 678, 
in
 exec_module
 +File "", line 219, in
 _call_with_frames_removed
 +File
 
"/tmp/hgtests.avspvsq4/install/lib/python/mercurial/dispatch.py", line
 726, in 
 +  class lazyaliasentry(object):
 +File
 
"/tmp/hgtests.avspvsq4/install/lib/python/mercurial/dispatch.py", line
 737, in lazyaliasentry
 +  @util.propertycache
 +File "/usr/lib/python3.6/importlib/util.py", line 233, in
 __getattribute__
 +  self.__spec__.loader.exec_module(self)
 +File "", line 678, 
in
 exec_module
 +File "", line 219, in
 _call_with_frames_removed
 +File 
"/tmp/hgtests.avspvsq4/install/lib/python/mercurial/util.py",
 line 3473, in 
 +  f=procutil.stderr,
 +File "/usr/lib/python3.6/importlib/util.py", line 233, in
 __getattribute__
 +  self.__spec__.loader.exec_module(self)
 +File "", line 678, 
in
 exec_module
 +File "", line 219, in
 _call_with_frames_removed
 +File
 
"/tmp/hgtests.avspvsq4/install/lib/python/mercurial/utils/procutil.py",
 line 127, in 
 +  stdin = sys.stdin.buffer
 +  AttributeError: 'NoneType' object has no attribute 'buffer'
 +  [1]

  server lifecycle
   

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/utils/procutil.py

CHANGE DETAILS

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -124,7 +124,9 @@
 # Python 3 implements its own I/O streams.
 # TODO: .buffer might not exist if std streams were replaced; we'll need
 # a silly wrapper to make a bytes stream backed by a unicode one.
-stdin = sys.stdin.buffer
+
+# sys.stdin can be None
+stdin = sys.stdin.buffer if sys.stdin else sys.stdin
 stdout = _make_write_all(sys.stdout.buffer)
 stderr = _make_write_all(sys.stderr.buffer)
 if pycompat.iswindows:



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


D9463: tests: conditionalize return code on chg in test-config.t

2020-11-30 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  If there is any error while reading config, chg just returns 255 instead of 
30.
  
  It seems to me that we cannot conditionalize only return codes in output using
  trailing `(chg !)` and hence used testcases.
  
  The test was failing with chg but after this patch, it now passes.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  tests/test-config.t

CHANGE DETAILS

diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -6,35 +6,59 @@
   $ cat > .hg/hgrc << EOF
   > novaluekey
   > EOF
+#if chg
+  $ hg showconfig
+  config error at $TESTTMP/.hg/hgrc:1: novaluekey
+  [255]
+#else
   $ hg showconfig
   config error at $TESTTMP/.hg/hgrc:1: novaluekey
   [30]
+#endif
 
 Invalid syntax: no key
 
   $ cat > .hg/hgrc << EOF
   > =nokeyvalue
   > EOF
+#if chg
+  $ hg showconfig
+  config error at $TESTTMP/.hg/hgrc:1: =nokeyvalue
+  [255]
+#else
   $ hg showconfig
   config error at $TESTTMP/.hg/hgrc:1: =nokeyvalue
   [30]
+#endif
 
 Test hint about invalid syntax from leading white space
 
   $ cat > .hg/hgrc << EOF
   >  key=value
   > EOF
+#if chg
+  $ hg showconfig
+  config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace:  
key=value
+  [255]
+#else
   $ hg showconfig
   config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace:  
key=value
   [30]
+#endif
 
   $ cat > .hg/hgrc << EOF
   >  [section]
   > key=value
   > EOF
+#if chg
+  $ hg showconfig
+  config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace:  
[section]
+  [255]
+#else
   $ hg showconfig
   config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace:  
[section]
   [30]
+#endif
 
 Reset hgrc
 



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


D9462: chgserver: catch RepoError while loading configuration

2020-11-30 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Recent share safe work introduced functionality to read share source config 
file
  on dispatch. This can result in RepoError while reading config file as the
  shared source might not be present.
  
  `test-share.t#safe` was failing with chg earlier because of this.

REPOSITORY
  rHG Mercurial

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

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
@@ -504,10 +504,21 @@
 the instructions.
 """
 args = self._readlist()
+errorraised = False
 try:
 self.ui, lui = _loadnewui(self.ui, args, self.cdebug)
+except error.RepoError as inst:
+# RepoError can be raised while trying to read shared source
+# configuration
+self.ui.error(_(b"abort: %s\n") % inst)
+if inst.hint:
+self.ui.error(_("(%s)\n") % inst.hint)
+errorraised = True
 except error.Abort as inst:
 self.ui.error(inst.format())
+errorraised = True
+
+if errorraised:
 self.ui.flush()
 self.cresult.write(b'exit 255')
 return



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


D9414: tests: update test-chg.t with output change

2020-11-27 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Since this part of tests is only run with chg, hence it didn't get updated
  when the error message changed.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  tests/test-chg.t

CHANGE DETAILS

diff --git a/tests/test-chg.t b/tests/test-chg.t
--- a/tests/test-chg.t
+++ b/tests/test-chg.t
@@ -29,7 +29,7 @@
   $ chg status
   $ echo '=brokenconfig' >> $HGRCPATH
   $ chg status
-  hg: parse error at * (glob)
+  config error at * =brokenconfig (glob)
   [255]
 
   $ cp $HGRCPATH.orig $HGRCPATH



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


  1   2   3   4   5   6   7   8   9   10   >