Mercurial > hg
annotate rust/hg-core/src/revlog/changelog.rs @ 49631:c7fb9b74e753
rust: remove newly redundant `use` statements with the 2021 edition prelude
https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 14 Nov 2022 15:20:48 +0100 |
parents | 07ec9f4f24bf |
children | e98fd81bb151 |
rev | line source |
---|---|
46443
43d63979a75e
rust: use HgError in RevlogError and Vfs
Simon Sapin <simon.sapin@octobus.net>
parents:
46433
diff
changeset
|
1 use crate::errors::HgError; |
49065
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
2 use crate::revlog::revlog::{Revlog, RevlogEntry, RevlogError}; |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
3 use crate::revlog::Revision; |
46744
b1f2c2b336ec
rhg: `cat` command: print error messages for missing files
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
4 use crate::revlog::{Node, NodePrefix}; |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
5 use crate::utils::hg_path::HgPath; |
49090
a5ef50becea8
rust-revlog: make `Changelog` and `ManifestLog` unaware of `Repo`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49089
diff
changeset
|
6 use crate::vfs::Vfs; |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
7 use itertools::Itertools; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
8 use std::ascii::escape_default; |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
9 use std::borrow::Cow; |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
10 use std::fmt::{Debug, Formatter}; |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
11 |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
12 /// A specialized `Revlog` to work with `changelog` data format. |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
13 pub struct Changelog { |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
14 /// The generic `revlog` format. |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46431
diff
changeset
|
15 pub(crate) revlog: Revlog, |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
16 } |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
17 |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
18 impl Changelog { |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
19 /// Open the `changelog` of a repository given by its root. |
49090
a5ef50becea8
rust-revlog: make `Changelog` and `ManifestLog` unaware of `Repo`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49089
diff
changeset
|
20 pub fn open(store_vfs: &Vfs, use_nodemap: bool) -> Result<Self, HgError> { |
a5ef50becea8
rust-revlog: make `Changelog` and `ManifestLog` unaware of `Repo`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49089
diff
changeset
|
21 let revlog = |
a5ef50becea8
rust-revlog: make `Changelog` and `ManifestLog` unaware of `Repo`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49089
diff
changeset
|
22 Revlog::open(store_vfs, "00changelog.i", None, use_nodemap)?; |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
23 Ok(Self { revlog }) |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
24 } |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
25 |
47969
87e3f878e65f
rust: Rename get_node methods to data_for_node, get_rev to data_for_rev
Simon Sapin <simon.sapin@octobus.net>
parents:
47968
diff
changeset
|
26 /// Return the `ChangelogEntry` for the given node ID. |
87e3f878e65f
rust: Rename get_node methods to data_for_node, get_rev to data_for_rev
Simon Sapin <simon.sapin@octobus.net>
parents:
47968
diff
changeset
|
27 pub fn data_for_node( |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
28 &self, |
46431
645ee7225fab
rust: Make NodePrefix allocation-free and Copy, remove NodePrefixRef
Simon Sapin <simon.sapin@octobus.net>
parents:
46167
diff
changeset
|
29 node: NodePrefix, |
48540
20d0d896183e
rhg: Rename some revlog-related types and methods
Simon Sapin <simon.sapin@octobus.net>
parents:
48198
diff
changeset
|
30 ) -> Result<ChangelogRevisionData, RevlogError> { |
47968
6f579618ea7b
rust: Rename the `Revlog::get_node_rev` method to `rev_from_node`
Simon Sapin <simon.sapin@octobus.net>
parents:
47967
diff
changeset
|
31 let rev = self.revlog.rev_from_node(node)?; |
47969
87e3f878e65f
rust: Rename get_node methods to data_for_node, get_rev to data_for_rev
Simon Sapin <simon.sapin@octobus.net>
parents:
47968
diff
changeset
|
32 self.data_for_rev(rev) |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
33 } |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
34 |
49065
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
35 /// Return the `RevlogEntry` of the given revision number. |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
36 pub fn entry_for_rev( |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
37 &self, |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
38 rev: Revision, |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
39 ) -> Result<RevlogEntry, RevlogError> { |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
40 self.revlog.get_entry(rev) |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
41 } |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
42 |
47969
87e3f878e65f
rust: Rename get_node methods to data_for_node, get_rev to data_for_rev
Simon Sapin <simon.sapin@octobus.net>
parents:
47968
diff
changeset
|
43 /// Return the `ChangelogEntry` of the given revision number. |
87e3f878e65f
rust: Rename get_node methods to data_for_node, get_rev to data_for_rev
Simon Sapin <simon.sapin@octobus.net>
parents:
47968
diff
changeset
|
44 pub fn data_for_rev( |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
45 &self, |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
46 rev: Revision, |
48540
20d0d896183e
rhg: Rename some revlog-related types and methods
Simon Sapin <simon.sapin@octobus.net>
parents:
48198
diff
changeset
|
47 ) -> Result<ChangelogRevisionData, RevlogError> { |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
48 let bytes = self.revlog.get_rev_data(rev)?; |
49063
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
49 if bytes.is_empty() { |
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
50 Ok(ChangelogRevisionData::null()) |
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
51 } else { |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
52 Ok(ChangelogRevisionData::new(bytes).map_err(|err| { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
53 RevlogError::Other(HgError::CorruptedRepository(format!( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
54 "Invalid changelog data for revision {}: {:?}", |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
55 rev, err |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
56 ))) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
57 })?) |
49063
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
58 } |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
59 } |
46744
b1f2c2b336ec
rhg: `cat` command: print error messages for missing files
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
60 |
b1f2c2b336ec
rhg: `cat` command: print error messages for missing files
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
61 pub fn node_from_rev(&self, rev: Revision) -> Option<&Node> { |
47967
6c653d9d41b8
rust: Make private the `index` field of the `Revlog` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
47964
diff
changeset
|
62 self.revlog.node_from_rev(rev) |
46744
b1f2c2b336ec
rhg: `cat` command: print error messages for missing files
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
63 } |
49065
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
64 |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
65 pub fn rev_from_node( |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
66 &self, |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
67 node: NodePrefix, |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
68 ) -> Result<Revision, RevlogError> { |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
69 self.revlog.rev_from_node(node) |
5d205e476057
rust-revlog: add methods for getting parent revs and entries
Martin von Zweigbergk <martinvonz@google.com>
parents:
49064
diff
changeset
|
70 } |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
71 } |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
72 |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
73 /// `Changelog` entry which knows how to interpret the `changelog` data bytes. |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
74 #[derive(PartialEq)] |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
75 pub struct ChangelogRevisionData<'changelog> { |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
76 /// The data bytes of the `changelog` entry. |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
77 bytes: Cow<'changelog, [u8]>, |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
78 /// The end offset for the hex manifest (not including the newline) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
79 manifest_end: usize, |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
80 /// The end offset for the user+email (not including the newline) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
81 user_end: usize, |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
82 /// The end offset for the timestamp+timezone+extras (not including the |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
83 /// newline) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
84 timestamp_end: usize, |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
85 /// The end offset for the file list (not including the newline) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
86 files_end: usize, |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
87 } |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
88 |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
89 impl<'changelog> ChangelogRevisionData<'changelog> { |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
90 fn new(bytes: Cow<'changelog, [u8]>) -> Result<Self, HgError> { |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
91 let mut line_iter = bytes.split(|b| b == &b'\n'); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
92 let manifest_end = line_iter |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
93 .next() |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
94 .expect("Empty iterator from split()?") |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
95 .len(); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
96 let user_slice = line_iter.next().ok_or_else(|| { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
97 HgError::corrupted("Changeset data truncated after manifest line") |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
98 })?; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
99 let user_end = manifest_end + 1 + user_slice.len(); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
100 let timestamp_slice = line_iter.next().ok_or_else(|| { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
101 HgError::corrupted("Changeset data truncated after user line") |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
102 })?; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
103 let timestamp_end = user_end + 1 + timestamp_slice.len(); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
104 let mut files_end = timestamp_end + 1; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
105 loop { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
106 let line = line_iter.next().ok_or_else(|| { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
107 HgError::corrupted("Changeset data truncated in files list") |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
108 })?; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
109 if line.is_empty() { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
110 if files_end == bytes.len() { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
111 // The list of files ended with a single newline (there |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
112 // should be two) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
113 return Err(HgError::corrupted( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
114 "Changeset data truncated after files list", |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
115 )); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
116 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
117 files_end -= 1; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
118 break; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
119 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
120 files_end += line.len() + 1; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
121 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
122 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
123 Ok(Self { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
124 bytes, |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
125 manifest_end, |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
126 user_end, |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
127 timestamp_end, |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
128 files_end, |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
129 }) |
49063
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
130 } |
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
131 |
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
132 fn null() -> Self { |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
133 Self::new(Cow::Borrowed( |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
134 b"0000000000000000000000000000000000000000\n\n0 0\n\n", |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
135 )) |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
136 .unwrap() |
49063
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
137 } |
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
138 |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
139 /// Return an iterator over the lines of the entry. |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
140 pub fn lines(&self) -> impl Iterator<Item = &[u8]> { |
49062
fb82b5cb8301
rust-changelog: don't skip empty lines when iterating over changeset lines
Martin von Zweigbergk <martinvonz@google.com>
parents:
48541
diff
changeset
|
141 self.bytes.split(|b| b == &b'\n') |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
142 } |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
143 |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
144 /// Return the node id of the `manifest` referenced by this `changelog` |
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
145 /// entry. |
47964
796206e74b10
rhg: Reuse manifest when checking status of multiple ambiguous files
Simon Sapin <simon.sapin@octobus.net>
parents:
47963
diff
changeset
|
146 pub fn manifest_node(&self) -> Result<Node, HgError> { |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
147 let manifest_node_hex = &self.bytes[..self.manifest_end]; |
49063
cc132255261b
rust-changelog: remove special parsing of empty changelog data for null rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
49062
diff
changeset
|
148 Node::from_hex_for_repo(manifest_node_hex) |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
149 } |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
150 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
151 /// The full user string (usually a name followed by an email enclosed in |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
152 /// angle brackets) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
153 pub fn user(&self) -> &[u8] { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
154 &self.bytes[self.manifest_end + 1..self.user_end] |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
155 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
156 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
157 /// The full timestamp line (timestamp in seconds, offset in seconds, and |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
158 /// possibly extras) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
159 // TODO: We should expose this in a more useful way |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
160 pub fn timestamp_line(&self) -> &[u8] { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
161 &self.bytes[self.user_end + 1..self.timestamp_end] |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
162 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
163 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
164 /// The files changed in this revision. |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
165 pub fn files(&self) -> impl Iterator<Item = &HgPath> { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
166 self.bytes[self.timestamp_end + 1..self.files_end] |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
167 .split(|b| b == &b'\n') |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
168 .map(|path| HgPath::new(path)) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
169 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
170 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
171 /// The change description. |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
172 pub fn description(&self) -> &[u8] { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
173 &self.bytes[self.files_end + 2..] |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
174 } |
45532
c2317b7624fd
hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
175 } |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
176 |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
177 impl Debug for ChangelogRevisionData<'_> { |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
178 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
179 f.debug_struct("ChangelogRevisionData") |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
180 .field("bytes", &debug_bytes(&self.bytes)) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
181 .field("manifest", &debug_bytes(&self.bytes[..self.manifest_end])) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
182 .field( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
183 "user", |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
184 &debug_bytes( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
185 &self.bytes[self.manifest_end + 1..self.user_end], |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
186 ), |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
187 ) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
188 .field( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
189 "timestamp", |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
190 &debug_bytes( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
191 &self.bytes[self.user_end + 1..self.timestamp_end], |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
192 ), |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
193 ) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
194 .field( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
195 "files", |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
196 &debug_bytes( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
197 &self.bytes[self.timestamp_end + 1..self.files_end], |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
198 ), |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
199 ) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
200 .field( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
201 "description", |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
202 &debug_bytes(&self.bytes[self.files_end + 2..]), |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
203 ) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
204 .finish() |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
205 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
206 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
207 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
208 fn debug_bytes(bytes: &[u8]) -> String { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
209 String::from_utf8_lossy( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
210 &bytes.iter().flat_map(|b| escape_default(*b)).collect_vec(), |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
211 ) |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
212 .to_string() |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
213 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
214 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
215 #[cfg(test)] |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
216 mod tests { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
217 use super::*; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
218 use pretty_assertions::assert_eq; |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
219 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
220 #[test] |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
221 fn test_create_changelogrevisiondata_invalid() { |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
222 // Completely empty |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
223 assert!(ChangelogRevisionData::new(Cow::Borrowed(b"abcd")).is_err()); |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
224 // No newline after manifest |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
225 assert!(ChangelogRevisionData::new(Cow::Borrowed(b"abcd")).is_err()); |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
226 // No newline after user |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
227 assert!(ChangelogRevisionData::new(Cow::Borrowed(b"abcd\n")).is_err()); |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
228 // No newline after timestamp |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
229 assert!( |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
230 ChangelogRevisionData::new(Cow::Borrowed(b"abcd\n\n0 0")).is_err() |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
231 ); |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
232 // Missing newline after files |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
233 assert!(ChangelogRevisionData::new(Cow::Borrowed( |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
234 b"abcd\n\n0 0\nfile1\nfile2" |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
235 )) |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
236 .is_err(),); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
237 // Only one newline after files |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
238 assert!(ChangelogRevisionData::new(Cow::Borrowed( |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
239 b"abcd\n\n0 0\nfile1\nfile2\n" |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
240 )) |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
241 .is_err(),); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
242 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
243 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
244 #[test] |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
245 fn test_create_changelogrevisiondata() { |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
246 let data = ChangelogRevisionData::new(Cow::Borrowed( |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
247 b"0123456789abcdef0123456789abcdef01234567 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
248 Some One <someone@example.com> |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
249 0 0 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
250 file1 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
251 file2 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
252 |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
253 some |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
254 commit |
49096
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
255 message", |
07ec9f4f24bf
changelog: avoid copying changeset data into `ChangesetRevisionData`
Martin von Zweigbergk <martinvonz@google.com>
parents:
49090
diff
changeset
|
256 )) |
49064
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
257 .unwrap(); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
258 assert_eq!( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
259 data.manifest_node().unwrap(), |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
260 Node::from_hex("0123456789abcdef0123456789abcdef01234567") |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
261 .unwrap() |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
262 ); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
263 assert_eq!(data.user(), b"Some One <someone@example.com>"); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
264 assert_eq!(data.timestamp_line(), b"0 0"); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
265 assert_eq!( |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
266 data.files().collect_vec(), |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
267 vec![HgPath::new("file1"), HgPath::new("file2")] |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
268 ); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
269 assert_eq!(data.description(), b"some\ncommit\nmessage"); |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
270 } |
95da3e99cbd8
rust-changelog: start parsing changeset data
Martin von Zweigbergk <martinvonz@google.com>
parents:
49063
diff
changeset
|
271 } |