Show More
@@ -1,110 +1,114 b'' | |||||
1 | // debugdata.rs |
|
1 | // debugdata.rs | |
2 | // |
|
2 | // | |
3 | // Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net> |
|
3 | // Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net> | |
4 | // |
|
4 | // | |
5 | // This software may be used and distributed according to the terms of the |
|
5 | // This software may be used and distributed according to the terms of the | |
6 | // GNU General Public License version 2 or any later version. |
|
6 | // GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | use super::find_root; |
|
8 | use super::find_root; | |
9 | use crate::revlog::revlog::{Revlog, RevlogError}; |
|
9 | use crate::revlog::revlog::{Revlog, RevlogError}; | |
10 | use crate::revlog::Revision; |
|
10 | use crate::revlog::Revision; | |
11 |
|
11 | |||
12 | /// Kind of data to debug |
|
12 | /// Kind of data to debug | |
13 | #[derive(Debug, Copy, Clone)] |
|
13 | #[derive(Debug, Copy, Clone)] | |
14 | pub enum DebugDataKind { |
|
14 | pub enum DebugDataKind { | |
15 | Changelog, |
|
15 | Changelog, | |
16 | Manifest, |
|
16 | Manifest, | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | /// Kind of error encountered by DebugData |
|
19 | /// Kind of error encountered by DebugData | |
20 | #[derive(Debug)] |
|
20 | #[derive(Debug)] | |
21 | pub enum DebugDataErrorKind { |
|
21 | pub enum DebugDataErrorKind { | |
22 | FindRootError(find_root::FindRootError), |
|
22 | FindRootError(find_root::FindRootError), | |
23 | /// Error when reading a `revlog` file. |
|
23 | /// Error when reading a `revlog` file. | |
24 | IoError(std::io::Error), |
|
24 | IoError(std::io::Error), | |
25 | /// The revision has not been found. |
|
25 | /// The revision has not been found. | |
26 | InvalidRevision, |
|
26 | InvalidRevision, | |
27 | /// A `revlog` file is corrupted. |
|
27 | /// A `revlog` file is corrupted. | |
28 | CorruptedRevlog, |
|
28 | CorruptedRevlog, | |
29 | /// The `revlog` format version is not supported. |
|
29 | /// The `revlog` format version is not supported. | |
30 | UnsuportedRevlogVersion(u16), |
|
30 | UnsuportedRevlogVersion(u16), | |
31 | /// The `revlog` data format is not supported. |
|
31 | /// The `revlog` data format is not supported. | |
32 | UnknowRevlogDataFormat(u8), |
|
32 | UnknowRevlogDataFormat(u8), | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | /// A DebugData error |
|
35 | /// A DebugData error | |
36 | #[derive(Debug)] |
|
36 | #[derive(Debug)] | |
37 | pub struct DebugDataError { |
|
37 | pub struct DebugDataError { | |
38 | /// Kind of error encountered by DebugData |
|
38 | /// Kind of error encountered by DebugData | |
39 | pub kind: DebugDataErrorKind, |
|
39 | pub kind: DebugDataErrorKind, | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | impl From<DebugDataErrorKind> for DebugDataError { |
|
42 | impl From<DebugDataErrorKind> for DebugDataError { | |
43 | fn from(kind: DebugDataErrorKind) -> Self { |
|
43 | fn from(kind: DebugDataErrorKind) -> Self { | |
44 | DebugDataError { kind } |
|
44 | DebugDataError { kind } | |
45 | } |
|
45 | } | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | impl From<find_root::FindRootError> for DebugDataError { |
|
48 | impl From<find_root::FindRootError> for DebugDataError { | |
49 | fn from(err: find_root::FindRootError) -> Self { |
|
49 | fn from(err: find_root::FindRootError) -> Self { | |
50 | let kind = DebugDataErrorKind::FindRootError(err); |
|
50 | let kind = DebugDataErrorKind::FindRootError(err); | |
51 | DebugDataError { kind } |
|
51 | DebugDataError { kind } | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | impl From<std::io::Error> for DebugDataError { |
|
55 | impl From<std::io::Error> for DebugDataError { | |
56 | fn from(err: std::io::Error) -> Self { |
|
56 | fn from(err: std::io::Error) -> Self { | |
57 | let kind = DebugDataErrorKind::IoError(err); |
|
57 | let kind = DebugDataErrorKind::IoError(err); | |
58 | DebugDataError { kind } |
|
58 | DebugDataError { kind } | |
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | impl From<RevlogError> for DebugDataError { |
|
62 | impl From<RevlogError> for DebugDataError { | |
63 | fn from(err: RevlogError) -> Self { |
|
63 | fn from(err: RevlogError) -> Self { | |
64 | match err { |
|
64 | match err { | |
65 | RevlogError::IoError(err) => DebugDataErrorKind::IoError(err), |
|
65 | RevlogError::IoError(err) => DebugDataErrorKind::IoError(err), | |
66 | RevlogError::UnsuportedVersion(version) => { |
|
66 | RevlogError::UnsuportedVersion(version) => { | |
67 | DebugDataErrorKind::UnsuportedRevlogVersion(version) |
|
67 | DebugDataErrorKind::UnsuportedRevlogVersion(version) | |
68 | } |
|
68 | } | |
69 | RevlogError::InvalidRevision => { |
|
69 | RevlogError::InvalidRevision => { | |
70 | DebugDataErrorKind::InvalidRevision |
|
70 | DebugDataErrorKind::InvalidRevision | |
71 | } |
|
71 | } | |
72 | RevlogError::Corrupted => DebugDataErrorKind::CorruptedRevlog, |
|
72 | RevlogError::Corrupted => DebugDataErrorKind::CorruptedRevlog, | |
73 | RevlogError::UnknowDataFormat(format) => { |
|
73 | RevlogError::UnknowDataFormat(format) => { | |
74 | DebugDataErrorKind::UnknowRevlogDataFormat(format) |
|
74 | DebugDataErrorKind::UnknowRevlogDataFormat(format) | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 | .into() |
|
77 | .into() | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /// Dump the contents data of a revision. |
|
81 | /// Dump the contents data of a revision. | |
82 | pub struct DebugData<'a> { |
|
82 | pub struct DebugData<'a> { | |
83 | /// Revision or hash of the revision. |
|
83 | /// Revision or hash of the revision. | |
84 | rev: &'a str, |
|
84 | rev: &'a str, | |
85 | /// Kind of data to debug. |
|
85 | /// Kind of data to debug. | |
86 | kind: DebugDataKind, |
|
86 | kind: DebugDataKind, | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | impl<'a> DebugData<'a> { |
|
89 | impl<'a> DebugData<'a> { | |
90 | pub fn new(rev: &'a str, kind: DebugDataKind) -> Self { |
|
90 | pub fn new(rev: &'a str, kind: DebugDataKind) -> Self { | |
91 | DebugData { rev, kind } |
|
91 | DebugData { rev, kind } | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | pub fn run(&mut self) -> Result<Vec<u8>, DebugDataError> { |
|
94 | pub fn run(&mut self) -> Result<Vec<u8>, DebugDataError> { | |
95 | let rev = self |
|
|||
96 | .rev |
|
|||
97 | .parse::<Revision>() |
|
|||
98 | .or(Err(DebugDataErrorKind::InvalidRevision))?; |
|
|||
99 |
|
||||
100 | let root = find_root::FindRoot::new().run()?; |
|
95 | let root = find_root::FindRoot::new().run()?; | |
101 | let index_file = match self.kind { |
|
96 | let index_file = match self.kind { | |
102 | DebugDataKind::Changelog => root.join(".hg/store/00changelog.i"), |
|
97 | DebugDataKind::Changelog => root.join(".hg/store/00changelog.i"), | |
103 | DebugDataKind::Manifest => root.join(".hg/store/00manifest.i"), |
|
98 | DebugDataKind::Manifest => root.join(".hg/store/00manifest.i"), | |
104 | }; |
|
99 | }; | |
105 | let revlog = Revlog::open(&index_file, None)?; |
|
100 | let revlog = Revlog::open(&index_file, None)?; | |
106 | let data = revlog.get_rev_data(rev)?; |
|
101 | ||
|
102 | let data = match self.rev.parse::<Revision>() { | |||
|
103 | Ok(rev) => revlog.get_rev_data(rev)?, | |||
|
104 | _ => { | |||
|
105 | let node = hex::decode(&self.rev) | |||
|
106 | .map_err(|_| DebugDataErrorKind::InvalidRevision)?; | |||
|
107 | let rev = revlog.get_node_rev(&node)?; | |||
|
108 | revlog.get_rev_data(rev)? | |||
|
109 | } | |||
|
110 | }; | |||
107 |
|
111 | |||
108 | Ok(data) |
|
112 | Ok(data) | |
109 | } |
|
113 | } | |
110 | } |
|
114 | } |
@@ -1,108 +1,117 b'' | |||||
1 | #require rust |
|
1 | #require rust | |
2 |
|
2 | |||
3 | Define an rhg function that will only run if rhg exists |
|
3 | Define an rhg function that will only run if rhg exists | |
4 | $ rhg() { |
|
4 | $ rhg() { | |
5 | > if [ -f "$RUNTESTDIR/../rust/target/debug/rhg" ]; then |
|
5 | > if [ -f "$RUNTESTDIR/../rust/target/debug/rhg" ]; then | |
6 | > "$RUNTESTDIR/../rust/target/debug/rhg" "$@" |
|
6 | > "$RUNTESTDIR/../rust/target/debug/rhg" "$@" | |
7 | > else |
|
7 | > else | |
8 | > echo "skipped: Cannot find rhg. Try to run cargo build in rust/rhg." |
|
8 | > echo "skipped: Cannot find rhg. Try to run cargo build in rust/rhg." | |
9 | > exit 80 |
|
9 | > exit 80 | |
10 | > fi |
|
10 | > fi | |
11 | > } |
|
11 | > } | |
12 |
|
12 | |||
13 | Unimplemented command |
|
13 | Unimplemented command | |
14 | $ rhg unimplemented-command |
|
14 | $ rhg unimplemented-command | |
15 | error: Found argument 'unimplemented-command' which wasn't expected, or isn't valid in this context |
|
15 | error: Found argument 'unimplemented-command' which wasn't expected, or isn't valid in this context | |
16 |
|
16 | |||
17 | USAGE: |
|
17 | USAGE: | |
18 | rhg <SUBCOMMAND> |
|
18 | rhg <SUBCOMMAND> | |
19 |
|
19 | |||
20 | For more information try --help |
|
20 | For more information try --help | |
21 | [252] |
|
21 | [252] | |
22 |
|
22 | |||
23 | Finding root |
|
23 | Finding root | |
24 | $ rhg root |
|
24 | $ rhg root | |
25 | abort: no repository found in '$TESTTMP' (.hg not found)! |
|
25 | abort: no repository found in '$TESTTMP' (.hg not found)! | |
26 | [255] |
|
26 | [255] | |
27 |
|
27 | |||
28 | $ hg init repository |
|
28 | $ hg init repository | |
29 | $ cd repository |
|
29 | $ cd repository | |
30 | $ rhg root |
|
30 | $ rhg root | |
31 | $TESTTMP/repository |
|
31 | $TESTTMP/repository | |
32 |
|
32 | |||
33 | Unwritable file descriptor |
|
33 | Unwritable file descriptor | |
34 | $ rhg root > /dev/full |
|
34 | $ rhg root > /dev/full | |
35 | abort: No space left on device (os error 28) |
|
35 | abort: No space left on device (os error 28) | |
36 | [255] |
|
36 | [255] | |
37 |
|
37 | |||
38 | Deleted repository |
|
38 | Deleted repository | |
39 | $ rm -rf `pwd` |
|
39 | $ rm -rf `pwd` | |
40 | $ rhg root |
|
40 | $ rhg root | |
41 | abort: error getting current working directory: $ENOENT$ |
|
41 | abort: error getting current working directory: $ENOENT$ | |
42 | [255] |
|
42 | [255] | |
43 |
|
43 | |||
44 | Listing tracked files |
|
44 | Listing tracked files | |
45 | $ cd $TESTTMP |
|
45 | $ cd $TESTTMP | |
46 | $ hg init repository |
|
46 | $ hg init repository | |
47 | $ cd repository |
|
47 | $ cd repository | |
48 | $ for i in 1 2 3; do |
|
48 | $ for i in 1 2 3; do | |
49 | > echo $i >> file$i |
|
49 | > echo $i >> file$i | |
50 | > hg add file$i |
|
50 | > hg add file$i | |
51 | > done |
|
51 | > done | |
52 | > hg commit -m "commit $i" -q |
|
52 | > hg commit -m "commit $i" -q | |
53 |
|
53 | |||
54 | Listing tracked files from root |
|
54 | Listing tracked files from root | |
55 | $ rhg files |
|
55 | $ rhg files | |
56 | file1 |
|
56 | file1 | |
57 | file2 |
|
57 | file2 | |
58 | file3 |
|
58 | file3 | |
59 |
|
59 | |||
60 | Listing tracked files from subdirectory |
|
60 | Listing tracked files from subdirectory | |
61 | $ mkdir -p path/to/directory |
|
61 | $ mkdir -p path/to/directory | |
62 | $ cd path/to/directory |
|
62 | $ cd path/to/directory | |
63 | $ rhg files |
|
63 | $ rhg files | |
64 | ../../../file1 |
|
64 | ../../../file1 | |
65 | ../../../file2 |
|
65 | ../../../file2 | |
66 | ../../../file3 |
|
66 | ../../../file3 | |
67 |
|
67 | |||
68 | Listing tracked files through broken pipe |
|
68 | Listing tracked files through broken pipe | |
69 | $ rhg files | head -n 1 |
|
69 | $ rhg files | head -n 1 | |
70 | ../../../file1 |
|
70 | ../../../file1 | |
71 |
|
71 | |||
72 | Debuging data in inline index |
|
72 | Debuging data in inline index | |
73 | $ cd $TESTTMP |
|
73 | $ cd $TESTTMP | |
74 | $ rm -rf repository |
|
74 | $ rm -rf repository | |
75 | $ hg init repository |
|
75 | $ hg init repository | |
76 | $ cd repository |
|
76 | $ cd repository | |
77 | $ for i in 1 2 3; do |
|
77 | $ for i in 1 2 3; do | |
78 | > echo $i >> file$i |
|
78 | > echo $i >> file$i | |
79 | > hg add file$i |
|
79 | > hg add file$i | |
80 | > hg commit -m "commit $i" -q |
|
80 | > hg commit -m "commit $i" -q | |
81 | > done |
|
81 | > done | |
82 | $ rhg debugdata -c 2 |
|
82 | $ rhg debugdata -c 2 | |
83 | e36fa63d37a576b27a69057598351db6ee5746bd |
|
83 | e36fa63d37a576b27a69057598351db6ee5746bd | |
84 | test |
|
84 | test | |
85 | 0 0 |
|
85 | 0 0 | |
86 | file3 |
|
86 | file3 | |
87 |
|
87 | |||
88 | commit 3 (no-eol) |
|
88 | commit 3 (no-eol) | |
89 | $ rhg debugdata -m 2 |
|
89 | $ rhg debugdata -m 2 | |
90 | file1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc) |
|
90 | file1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc) | |
91 | file2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc) |
|
91 | file2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc) | |
92 | file3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc) |
|
92 | file3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc) | |
93 |
|
93 | |||
|
94 | Debuging with full node id | |||
|
95 | $ rhg debugdata -c `hg log -r 0 -T '{node}'` | |||
|
96 | c8e64718e1ca0312eeee0f59d37f8dc612793856 | |||
|
97 | test | |||
|
98 | 0 0 | |||
|
99 | file1 | |||
|
100 | ||||
|
101 | commit 1 (no-eol) | |||
|
102 | ||||
94 | Cat files |
|
103 | Cat files | |
95 | $ cd $TESTTMP |
|
104 | $ cd $TESTTMP | |
96 | $ rm -rf repository |
|
105 | $ rm -rf repository | |
97 | $ hg init repository |
|
106 | $ hg init repository | |
98 | $ cd repository |
|
107 | $ cd repository | |
99 | $ echo "original content" > original |
|
108 | $ echo "original content" > original | |
100 | $ hg add original |
|
109 | $ hg add original | |
101 | $ hg commit -m "add original" original |
|
110 | $ hg commit -m "add original" original | |
102 | $ rhg cat -r 0 original |
|
111 | $ rhg cat -r 0 original | |
103 | original content |
|
112 | original content | |
104 | Cat copied file should not display copy metadata |
|
113 | Cat copied file should not display copy metadata | |
105 | $ hg copy original copy_of_original |
|
114 | $ hg copy original copy_of_original | |
106 | $ hg commit -m "add copy of original" |
|
115 | $ hg commit -m "add copy of original" | |
107 | $ rhg cat -r 1 copy_of_original |
|
116 | $ rhg cat -r 1 copy_of_original | |
108 | original content |
|
117 | original content |
General Comments 0
You need to be logged in to leave comments.
Login now