RE: How to fix integrity errors ?

2021-06-25 Thread PERTIN Francois
Hello Mr David,

Thank you for your explanation. 
We fixed our repo by applying the following procedure and fisheye get back to 
work.

b) there was only one revision but the entire revlog is missing

In most cases, you simply copy the revlog from .hg/store/data in another
clone, but if you don't have any intact clones, then things are more
difficult.

If you had a single missing file revision (case b) and you have the
-exact- file somewhere, you can do a hack like this:

hg clone myrepo myrepo-backup
hg clone -r 530 myrepo myrepo-hack # we need the next commit to be 531
cp myfile myrepo-hack/
hg add myfile
hg ci -m "A new 531"

Best regards.

Francois PERTIN
Embeded software team leader
STAUBLI FAVERGES
Place Robert Staubli CS 30070
74210 Faverges-Seythenex / FR
Phone: +33 4 50 65 62 59
Mobile: 
mailto: f.per...@staubli.com
www.staubli.com
This e-mail and any attachment (the 'message') are confidential and privileged 
and intended solely for the person or the entity
to which it is addressed. If you have received it in error, please advise the 
sender by return e-mail and delete it immediately.
Any use not in accordance with its purpose, any dissemination or reproduction, 
either whole or partial, by entities other than
the intended recipient is strictly prohibited.

-Message d'origine-
De : Pierre-Yves David  
Envoyé : jeudi 17 juin 2021 23:16
À : PERTIN Francois ; mercurial-devel@mercurial-scm.org
Objet : Re: How to fix integrity errors ?

This Message Is From an External Sender   This message came from outside your 
organization. 

__
Hi M. Pertin

On 6/10/21 4:26 PM, PERTIN Francois wrote:
> We are using mercurial version 3.7.3 on a Linux server.


This version of Mercurial was released 5 years ago and is considered 
quite ancient. There have been 21 other major releases of Mercurial in 
the meantime, including multiple security releases.

I strongly encourage you to upgrade your client and server.


> At one time a user got an error while trying to push.
>
> He did it again, the error disappear and push succeed but all users 
> had to re-clone the repository from the server to be able to push again.
>

This is quite suspicious. Do you have any record of the error that user 
got while pushing? Or of the error the other people got while pushing?

When did this happened?


> Since that time, running hg verify on user repository and on server 
> repository returns the following error.
>
> myfile@23805  
> : 
> ddb482e379a1 in manifests not found
> 21293 files, 24338 changesets, 98658 total revisions
> 1 integrity errors encountered!
> (first damaged changeset appears to be 23805)

So it looks like a corruption was pushed to you repository, the revision 
of a given file is referenced in the history but is missing from the 
storage for that file. Have you kept backups of the users' repositories 
at the time of the error?

Does revision `23805` (number to use on the same repository you used to 
run verify) have any children?


> This is not an issue for all the users except for fisheye.
>
> It is not able to index the repository, it always restart after the 
> following error.
>
> Atlasian ask us to fix the server repository by using the method 
> described here: RepositoryCorruption - Mercurial 
> 
>
> I spend a lot of time trying to fix this without success.\
>
>
> Does any one know how to fix this issue?
>

It looks like Fisheye is trying to load the entire history into its own 
database and is chocking on the specific revision that contains the 
corruption. That file revision is corrupted so you will never be able to 
restore it as is. However they are multiple options to get out of this 
situation:

1) remove the changeset with the corruption from the repository (if it 
is an unused head), or rewrite the dependant history,
2) find an un-corrupted version of that file in some backup,
3) use "censors" to mark the content of that revision non-accessible 
(might need some development to the mercurial code-base),
4) convince Fisheye to be less picky.


I don't know which of the above options are actually possible in your 
case. And I don't know which one will be the best. However we can 
probably get to a solution with some email roundtrips. Can you please 
have a look at the question I wrote earlier in this email?

Cheers,

-- 

Pierre-Yves David

___
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