pub struct MercurialRepository { /* private fields */ }
Expand description
Mercurial repository. Top-level structure for access to change sets and tags.
Implementations§
Source§impl MercurialRepository
impl MercurialRepository
Sourcepub fn open<P: AsRef<Path>>(
root_path: P,
) -> Result<MercurialRepository, ErrorKind>
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}
Sourcepub fn open_with_options<P: AsRef<Path>>(
root_path: P,
options: MercurialRepositoryOptions,
) -> Result<MercurialRepository, ErrorKind>
pub fn open_with_options<P: AsRef<Path>>( root_path: P, options: MercurialRepositoryOptions, ) -> Result<MercurialRepository, ErrorKind>
Opens MercurialRepository
at root_path
with options.
Sourcepub fn iter(&self) -> ChangesetIter<'_> ⓘ
pub fn iter(&self) -> ChangesetIter<'_> ⓘ
Changeset iterator other all revisions in log.
Sourcepub fn header_iter(&self) -> ChangesetHeaderIter<'_> ⓘ
pub fn header_iter(&self) -> ChangesetHeaderIter<'_> ⓘ
Changeset header iterator other all revisions in log.
Sourcepub fn range_iter<RR: Into<RevisionRange>>(
&self,
revisions_range: RR,
) -> ChangesetIter<'_> ⓘ
pub fn range_iter<RR: Into<RevisionRange>>( &self, revisions_range: RR, ) -> ChangesetIter<'_> ⓘ
Changeset iterator other range of revisions in log.
Sourcepub fn range_header_iter<RR: Into<RevisionRange>>(
&self,
revisions_range: RR,
) -> ChangesetHeaderIter<'_> ⓘ
pub fn range_header_iter<RR: Into<RevisionRange>>( &self, revisions_range: RR, ) -> ChangesetHeaderIter<'_> ⓘ
Changeset header iterator other range of revisions in log.
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
impl Debug for MercurialRepository
Source§impl From<MercurialRepository> for CachedMercurialRepository
impl From<MercurialRepository> for CachedMercurialRepository
Source§fn from(repository: MercurialRepository) -> Self
fn from(repository: MercurialRepository) -> Self
Converts to this type from the input type.
Source§impl<'a> IntoIterator for &'a MercurialRepository
impl<'a> IntoIterator for &'a MercurialRepository
Auto Trait Implementations§
impl Freeze for MercurialRepository
impl RefUnwindSafe for MercurialRepository
impl Send for MercurialRepository
impl Sync for MercurialRepository
impl Unpin for MercurialRepository
impl UnwindSafe for MercurialRepository
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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