rust/hg-cpython/src/exceptions.rs
author Martin von Zweigbergk <martinvonz@google.com>
Tue, 08 Dec 2020 16:45:13 -0800
changeset 46108 bdc2bf68f19e
parent 44529 f96b28aa4b79
child 48519 35ebe6f824be
permissions -rw-r--r--
mergetools: add new conflict marker format with diffs in I use 3-way conflict markers. Often when I resolve them, I manually compare one the base with one side and apply the differences to the other side. That can be hard when the conflict marker is large. This patch introduces a new type of conflict marker, which I'm hoping will make it easier to resolve conflicts. The new format uses `<<<<<<<` and `>>>>>>>` to open and close the markers, just like our existing 2-way and 3-way conflict markers. Instead of having 2 or 3 snapshots (left+right or left+base+right), it has a sequence of diffs. A diff looks like this: ``` ------- base +++++++ left a -b +c d ``` A diff that adds one side ("diff from nothing") has a `=======` header instead and does not have have `+` prefixed on its lines. A regular 3-way merge can be viewed as adding one side plus a diff between the base and the other side. It thus has two ways of being represented, depending on which side is being diffed: ``` <<<<<<< ======= left contents on left ------- base +++++++ right contents on -left +right >>>>>>> ``` or ``` <<<<<<< ------- base +++++++ left contents on -right +left ======= right contents on right >>>>>>> ``` I've made it so the new merge tool tries to pick a version that has the most common lines (no difference in the example above). I've called the new tool "mergediff" to stick to the convention of starting with "merge" if the tool tries a regular 3-way merge. The idea came from my pet VCS (placeholder name `jj`), which has support for octopus merges and other ways of ending up with merges of more than 3 versions. I wanted to be able to represent such conflicts in the working copy and therefore thought of this format (although I have not yet implemented it in my VCS). I then attended a meeting with Larry McVoy, who said BitKeeper has an option (`bk smerge -g`) for showing a similar format, which reminded me to actually attempt this in Mercurial. Differential Revision: https://phab.mercurial-scm.org/D9551
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41184
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
     1
// ancestors.rs
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
     2
//
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
     3
// Copyright 2018 Georges Racinet <gracinet@anybox.fr>
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
     4
//
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
     5
// This software may be used and distributed according to the terms of the
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
     6
// GNU General Public License version 2 or any later version.
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
     7
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
     8
//! Bindings for Rust errors
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
     9
//!
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
    10
//! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError`
41349
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
    11
//! but some variants of `hg::GraphError` can be converted directly to other
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
    12
//! existing Python exceptions if appropriate.
41184
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
    13
//!
dcf818267bc1 rust-cpython: rustdoc improvements
Georges Racinet <georges.racinet@octobus.net>
parents: 40965
diff changeset
    14
//! [`GraphError`]: struct.GraphError.html
42609
326fdce22fb2 rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents: 42557
diff changeset
    15
use cpython::{
44137
3bd77c64bc74 rust-filepatterns: remove bridge code for filepatterns-related functions
Raphaël Gomès <rgomes@octobus.net>
parents: 42957
diff changeset
    16
    exc::{RuntimeError, ValueError},
42609
326fdce22fb2 rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents: 42557
diff changeset
    17
    py_exception, PyErr, Python,
326fdce22fb2 rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents: 42557
diff changeset
    18
};
40965
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    19
use hg;
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    20
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    21
py_exception!(rustext, GraphError, ValueError);
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    22
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    23
impl GraphError {
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    24
    pub fn pynew(py: Python, inner: hg::GraphError) -> PyErr {
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    25
        match inner {
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    26
            hg::GraphError::ParentOutOfRange(r) => {
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    27
                GraphError::new(py, ("ParentOutOfRange", r))
5532823e8c18 rust-cpython: start cpython crate bindings
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
    28
            }
41349
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
    29
            hg::GraphError::WorkingDirectoryUnsupported => {
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
    30
                match py
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
    31
                    .import("mercurial.error")
ee943a920606 rust: error for WdirUnsupported with cpython conversion as exception
Georges Racinet <georges.racinet@octobus.net>
parents: 41184
diff changeset
    32
                    .and_then(|m| m.get(py, "WdirUnsupported"))
42557
d26e4a434fe5 rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents: 42328
diff changeset
    33
                {
d26e4a434fe5 rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents: 42328
diff changeset
    34
                    Err(e) => e,
d26e4a434fe5 rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents: 42328
diff changeset
    35
                    Ok(cls) => PyErr::from_instance(py, cls),
d26e4a434fe5 rust: run rfmt on all hg-core/hg-cpython code
Raphaël Gomès <rgomes@octobus.net>
parents: 42328
diff changeset
    36
                }
42328
94f3a73b6672 rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Raphaël Gomès <rgomes@octobus.net>
parents: 41349
diff changeset
    37
            }
94f3a73b6672 rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Raphaël Gomès <rgomes@octobus.net>
parents: 41349
diff changeset
    38
        }
94f3a73b6672 rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Raphaël Gomès <rgomes@octobus.net>
parents: 41349
diff changeset
    39
    }
94f3a73b6672 rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Raphaël Gomès <rgomes@octobus.net>
parents: 41349
diff changeset
    40
}
94f3a73b6672 rust-filepatterns: add `rust-cpython` bindings for `filepatterns`
Raphaël Gomès <rgomes@octobus.net>
parents: 41349
diff changeset
    41
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42752
diff changeset
    42
py_exception!(rustext, HgPathPyError, RuntimeError);
44529
f96b28aa4b79 rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents: 44206
diff changeset
    43
py_exception!(rustext, FallbackError, RuntimeError);
f96b28aa4b79 rust-status: update rust-cpython bridge to account for the changes in core
Raphaël Gomès <rgomes@octobus.net>
parents: 44206
diff changeset
    44
py_exception!(shared_ref, AlreadyBorrowed, RuntimeError);