Struct MercurialRepository

Source
pub struct MercurialRepository { /* private fields */ }
Expand description

Mercurial repository. Top-level structure for access to change sets and tags.

Implementations§

Source§

impl MercurialRepository

Source

pub fn open<P: AsRef<Path>>( root_path: P, ) -> Result<MercurialRepository, ErrorKind>

Opens MercurialRepository at root_path.

Examples found in repository?
examples/git-fast-import.rs (line 18)
16fn export_repo<P: AsRef<Path>>(path: P) -> Result<(), Error> {
17    let start = Instant::now();
18    let repo = MercurialRepository::open(path)?;
19
20    let stdout = std::io::stdout();
21    let mut writer = stdout.lock();
22
23    for changeset in &repo {
24        let revision = changeset.revision;
25        eprintln!("rev: {:?}", revision);
26
27        let header = &changeset.header;
28        let mut branch = None;
29        let mut closed = false;
30        for (key, value) in &header.extra {
31            if key == b"branch" {
32                branch = Some(value.as_slice());
33            }
34
35            if key == b"close" && value == b"1" {
36                closed = true;
37            }
38        }
39
40        let mut branch: Vec<_> = branch.unwrap_or(b"master").into();
41        for b in branch.iter_mut() {
42            if *b == b' ' {
43                *b = b'-';
44            }
45        }
46
47        let user = String::from_utf8_lossy(&header.user);
48        let desc = String::from_utf8_lossy(&header.comment);
49
50        let time = header.time.timestamp_secs();
51        let timezone = header.time.tz_offset_secs();
52        let tz = format!("{:+03}{:02}", -timezone / 3600, ((-timezone % 3600) / 60));
53
54        write!(writer, "reset refs/heads/")?;
55        writer.write_all(&branch)?;
56        write!(writer, "\ncommit refs/heads/")?;
57        writer.write_all(&branch)?;
58        writeln!(writer, "\nmark :{}", mark(revision))?;
59
60        writeln!(writer, "author {} {} {}", user, time, tz)?;
61        writeln!(writer, "committer {} {} {}", user, time, tz)?;
62        writeln!(writer, "data {}", desc.len() + 1)?;
63        writeln!(writer, "{}\n", desc)?;
64
65        match (header.p1, header.p2) {
66            (Some(p1), Some(p2)) => {
67                writeln!(writer, "from :{}", mark(p1))?;
68                writeln!(writer, "merge :{}", mark(p2))?;
69            }
70            (Some(p), None) | (None, Some(p)) => {
71                writeln!(writer, "from :{}", mark(p))?;
72            }
73            _ => (),
74        }
75
76        for file in changeset.files {
77            match (file.data, file.manifest_entry) {
78                (None, None) => {
79                    write!(writer, "D ")?;
80                    writer.write_all(&file.path)?;
81                    writeln!(writer)?;
82                }
83                (Some(data), Some(manifest_entry)) => {
84                    write!(
85                        writer,
86                        "M {} inline ",
87                        match manifest_entry.details {
88                            ManifestEntryDetails::File(FileType::Symlink) => "120000",
89                            ManifestEntryDetails::File(FileType::Executable) => "100755",
90                            ManifestEntryDetails::Tree
91                            | ManifestEntryDetails::File(FileType::Regular) => "100644",
92                        }
93                    )?;
94                    writer.write_all(&file.path)?;
95                    let data = file_content(&data);
96                    writeln!(writer, "\ndata {}", data.len())?;
97                    writer.write_all(data)?;
98                }
99                _ => panic!("Wrong file data!"),
100            }
101        }
102
103        if closed {
104            write!(writer, "reset refs/tags/archive/")?;
105            writer.write_all(&branch)?;
106            writeln!(writer, "\nfrom :{}\n", mark(revision))?;
107
108            write!(writer, "reset refs/heads/")?;
109            writer.write_all(&branch)?;
110            writeln!(writer, "\nfrom 0000000000000000000000000000000000000000\n")?;
111        }
112    }
113
114    for (rev, tag) in repo.tags().unwrap() {
115        eprintln!("export tag {}", tag.name);
116        writeln!(writer, "reset refs/tags/{}", tag.name).unwrap();
117        writeln!(writer, "from :{}", mark(rev)).unwrap();
118        writeln!(writer).unwrap();
119    }
120
121    eprintln!("Done. Elapsed: {:?}", start.elapsed());
122    Ok(())
123}
Source

pub fn open_with_options<P: AsRef<Path>>( root_path: P, options: MercurialRepositoryOptions, ) -> Result<MercurialRepository, ErrorKind>

Opens MercurialRepository at root_path with options.

Source

pub fn last_rev(&self) -> Revision

Last Revision in revision log.

Source

pub fn iter(&self) -> ChangesetIter<'_>

Changeset iterator other all revisions in log.

Source

pub fn header_iter(&self) -> ChangesetHeaderIter<'_>

Changeset header iterator other all revisions in log.

Source

pub fn range_iter<RR: Into<RevisionRange>>( &self, revisions_range: RR, ) -> ChangesetIter<'_>

Changeset iterator other range of revisions in log.

Source

pub fn range_header_iter<RR: Into<RevisionRange>>( &self, revisions_range: RR, ) -> ChangesetHeaderIter<'_>

Changeset header iterator other range of revisions in log.

Source

pub fn tags(&self) -> Result<BTreeMap<Revision, MercurialTag>, ErrorKind>

List tags in repository. Tags read from .hg/cache/tags2-visible or .hgtags.

Examples found in repository?
examples/git-fast-import.rs (line 114)
16fn export_repo<P: AsRef<Path>>(path: P) -> Result<(), Error> {
17    let start = Instant::now();
18    let repo = MercurialRepository::open(path)?;
19
20    let stdout = std::io::stdout();
21    let mut writer = stdout.lock();
22
23    for changeset in &repo {
24        let revision = changeset.revision;
25        eprintln!("rev: {:?}", revision);
26
27        let header = &changeset.header;
28        let mut branch = None;
29        let mut closed = false;
30        for (key, value) in &header.extra {
31            if key == b"branch" {
32                branch = Some(value.as_slice());
33            }
34
35            if key == b"close" && value == b"1" {
36                closed = true;
37            }
38        }
39
40        let mut branch: Vec<_> = branch.unwrap_or(b"master").into();
41        for b in branch.iter_mut() {
42            if *b == b' ' {
43                *b = b'-';
44            }
45        }
46
47        let user = String::from_utf8_lossy(&header.user);
48        let desc = String::from_utf8_lossy(&header.comment);
49
50        let time = header.time.timestamp_secs();
51        let timezone = header.time.tz_offset_secs();
52        let tz = format!("{:+03}{:02}", -timezone / 3600, ((-timezone % 3600) / 60));
53
54        write!(writer, "reset refs/heads/")?;
55        writer.write_all(&branch)?;
56        write!(writer, "\ncommit refs/heads/")?;
57        writer.write_all(&branch)?;
58        writeln!(writer, "\nmark :{}", mark(revision))?;
59
60        writeln!(writer, "author {} {} {}", user, time, tz)?;
61        writeln!(writer, "committer {} {} {}", user, time, tz)?;
62        writeln!(writer, "data {}", desc.len() + 1)?;
63        writeln!(writer, "{}\n", desc)?;
64
65        match (header.p1, header.p2) {
66            (Some(p1), Some(p2)) => {
67                writeln!(writer, "from :{}", mark(p1))?;
68                writeln!(writer, "merge :{}", mark(p2))?;
69            }
70            (Some(p), None) | (None, Some(p)) => {
71                writeln!(writer, "from :{}", mark(p))?;
72            }
73            _ => (),
74        }
75
76        for file in changeset.files {
77            match (file.data, file.manifest_entry) {
78                (None, None) => {
79                    write!(writer, "D ")?;
80                    writer.write_all(&file.path)?;
81                    writeln!(writer)?;
82                }
83                (Some(data), Some(manifest_entry)) => {
84                    write!(
85                        writer,
86                        "M {} inline ",
87                        match manifest_entry.details {
88                            ManifestEntryDetails::File(FileType::Symlink) => "120000",
89                            ManifestEntryDetails::File(FileType::Executable) => "100755",
90                            ManifestEntryDetails::Tree
91                            | ManifestEntryDetails::File(FileType::Regular) => "100644",
92                        }
93                    )?;
94                    writer.write_all(&file.path)?;
95                    let data = file_content(&data);
96                    writeln!(writer, "\ndata {}", data.len())?;
97                    writer.write_all(data)?;
98                }
99                _ => panic!("Wrong file data!"),
100            }
101        }
102
103        if closed {
104            write!(writer, "reset refs/tags/archive/")?;
105            writer.write_all(&branch)?;
106            writeln!(writer, "\nfrom :{}\n", mark(revision))?;
107
108            write!(writer, "reset refs/heads/")?;
109            writer.write_all(&branch)?;
110            writeln!(writer, "\nfrom 0000000000000000000000000000000000000000\n")?;
111        }
112    }
113
114    for (rev, tag) in repo.tags().unwrap() {
115        eprintln!("export tag {}", tag.name);
116        writeln!(writer, "reset refs/tags/{}", tag.name).unwrap();
117        writeln!(writer, "from :{}", mark(rev)).unwrap();
118        writeln!(writer).unwrap();
119    }
120
121    eprintln!("Done. Elapsed: {:?}", start.elapsed());
122    Ok(())
123}

Trait Implementations§

Source§

impl Debug for MercurialRepository

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<MercurialRepository> for CachedMercurialRepository

Source§

fn from(repository: MercurialRepository) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a MercurialRepository

Source§

type Item = Changeset

The type of the elements being iterated over.
Source§

type IntoIter = ChangesetIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.