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