##// END OF EJS Templates
rhg: allow specifying a changeset ID prefix...
Simon Sapin -
r46646:8d616409 default
parent child Browse files
Show More
@@ -26,6 +26,8 b' pub enum CatRevErrorKind {'
26 26 IoError(std::io::Error),
27 27 /// The revision has not been found.
28 28 InvalidRevision,
29 /// Found more than one revision whose ID match the requested prefix
30 AmbiguousPrefix,
29 31 /// A `revlog` file is corrupted.
30 32 CorruptedRevlog,
31 33 /// The `revlog` format version is not supported.
@@ -55,6 +57,7 b' impl From<RevlogError> for CatRevError {'
55 57 CatRevErrorKind::UnsuportedRevlogVersion(version)
56 58 }
57 59 RevlogError::InvalidRevision => CatRevErrorKind::InvalidRevision,
60 RevlogError::AmbiguousPrefix => CatRevErrorKind::AmbiguousPrefix,
58 61 RevlogError::Corrupted => CatRevErrorKind::CorruptedRevlog,
59 62 RevlogError::UnknowDataFormat(format) => {
60 63 CatRevErrorKind::UnknowRevlogDataFormat(format)
@@ -24,6 +24,8 b' pub enum DebugDataErrorKind {'
24 24 IoError(std::io::Error),
25 25 /// The revision has not been found.
26 26 InvalidRevision,
27 /// Found more than one revision whose ID match the requested prefix
28 AmbiguousPrefix,
27 29 /// A `revlog` file is corrupted.
28 30 CorruptedRevlog,
29 31 /// The `revlog` format version is not supported.
@@ -69,6 +71,9 b' impl From<RevlogError> for DebugDataErro'
69 71 RevlogError::InvalidRevision => {
70 72 DebugDataErrorKind::InvalidRevision
71 73 }
74 RevlogError::AmbiguousPrefix => {
75 DebugDataErrorKind::AmbiguousPrefix
76 }
72 77 RevlogError::Corrupted => DebugDataErrorKind::CorruptedRevlog,
73 78 RevlogError::UnknowDataFormat(format) => {
74 79 DebugDataErrorKind::UnknowRevlogDataFormat(format)
@@ -86,6 +86,8 b' pub enum ListRevTrackedFilesErrorKind {'
86 86 IoError(std::io::Error),
87 87 /// The revision has not been found.
88 88 InvalidRevision,
89 /// Found more than one revision whose ID match the requested prefix
90 AmbiguousPrefix,
89 91 /// A `revlog` file is corrupted.
90 92 CorruptedRevlog,
91 93 /// The `revlog` format version is not supported.
@@ -119,6 +121,9 b' impl From<RevlogError> for ListRevTracke'
119 121 RevlogError::InvalidRevision => {
120 122 ListRevTrackedFilesErrorKind::InvalidRevision
121 123 }
124 RevlogError::AmbiguousPrefix => {
125 ListRevTrackedFilesErrorKind::AmbiguousPrefix
126 }
122 127 RevlogError::Corrupted => {
123 128 ListRevTrackedFilesErrorKind::CorruptedRevlog
124 129 }
@@ -21,6 +21,8 b' pub enum RevlogError {'
21 21 IoError(std::io::Error),
22 22 UnsuportedVersion(u16),
23 23 InvalidRevision,
24 /// Found more than one entry whose ID match the requested prefix
25 AmbiguousPrefix,
24 26 Corrupted,
25 27 UnknowDataFormat(u8),
26 28 }
@@ -93,14 +95,21 b' impl Revlog {'
93 95 pub fn get_node_rev(&self, node: &[u8]) -> Result<Revision, RevlogError> {
94 96 // This is brute force. But it is fast enough for now.
95 97 // Optimization will come later.
98 let mut found_by_prefix = None;
96 99 for rev in (0..self.len() as Revision).rev() {
97 100 let index_entry =
98 101 self.index.get_entry(rev).ok_or(RevlogError::Corrupted)?;
99 if node == index_entry.hash() {
102 if index_entry.hash() == node {
100 103 return Ok(rev);
101 104 }
105 if index_entry.hash().starts_with(node) {
106 if found_by_prefix.is_some() {
107 return Err(RevlogError::AmbiguousPrefix);
102 108 }
103 Err(RevlogError::InvalidRevision)
109 found_by_prefix = Some(rev)
110 }
111 }
112 found_by_prefix.ok_or(RevlogError::InvalidRevision)
104 113 }
105 114
106 115 /// Return the full data associated to a revision.
@@ -75,6 +75,13 b' fn map_rev_error(rev: &str, err: CatRevE'
75 75 ))
76 76 .into(),
77 77 )),
78 CatRevErrorKind::AmbiguousPrefix => CommandErrorKind::Abort(Some(
79 utf8_to_local(&format!(
80 "abort: ambiguous revision identifier {}\n",
81 rev
82 ))
83 .into(),
84 )),
78 85 CatRevErrorKind::UnsuportedRevlogVersion(version) => {
79 86 CommandErrorKind::Abort(Some(
80 87 utf8_to_local(&format!(
@@ -55,6 +55,15 b' fn to_command_error(rev: &str, err: Debu'
55 55 .into(),
56 56 )),
57 57 },
58 DebugDataErrorKind::AmbiguousPrefix => CommandError {
59 kind: CommandErrorKind::Abort(Some(
60 utf8_to_local(&format!(
61 "abort: ambiguous revision identifier{}\n",
62 rev
63 ))
64 .into(),
65 )),
66 },
58 67 DebugDataErrorKind::UnsuportedRevlogVersion(version) => CommandError {
59 68 kind: CommandErrorKind::Abort(Some(
60 69 utf8_to_local(&format!(
@@ -91,6 +91,15 b' fn map_rev_error(rev: &str, err: ListRev'
91 91 .into(),
92 92 ))
93 93 }
94 ListRevTrackedFilesErrorKind::AmbiguousPrefix => {
95 CommandErrorKind::Abort(Some(
96 utf8_to_local(&format!(
97 "abort: ambiguous revision identifier {}\n",
98 rev
99 ))
100 .into(),
101 ))
102 }
94 103 ListRevTrackedFilesErrorKind::UnsuportedRevlogVersion(version) => {
95 104 CommandErrorKind::Abort(Some(
96 105 utf8_to_local(&format!(
@@ -74,31 +74,49 b' Debuging data in inline index'
74 74 $ rm -rf repository
75 75 $ hg init repository
76 76 $ cd repository
77 $ for i in 1 2 3; do
78 > echo $i >> file$i
79 > hg add file$i
80 > hg commit -m "commit $i" -q
77 $ for i in 1 2 3 4 5 6; do
78 > echo $i >> file-$i
79 > hg add file-$i
80 > hg commit -m "Commit $i" -q
81 81 > done
82 82 $ rhg debugdata -c 2
83 e36fa63d37a576b27a69057598351db6ee5746bd
83 8d0267cb034247ebfa5ee58ce59e22e57a492297
84 84 test
85 85 0 0
86 file3
86 file-3
87 87
88 commit 3 (no-eol)
88 Commit 3 (no-eol)
89 89 $ rhg debugdata -m 2
90 file1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc)
91 file2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc)
92 file3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc)
90 file-1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc)
91 file-2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc)
92 file-3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc)
93 93
94 94 Debuging with full node id
95 95 $ rhg debugdata -c `hg log -r 0 -T '{node}'`
96 c8e64718e1ca0312eeee0f59d37f8dc612793856
96 d1d1c679d3053e8926061b6f45ca52009f011e3f
97 97 test
98 98 0 0
99 file1
99 file-1
100
101 Commit 1 (no-eol)
100 102
101 commit 1 (no-eol)
103 Specifying revisions by changeset ID
104 $ hg log -T '{node}\n'
105 c6ad58c44207b6ff8a4fbbca7045a5edaa7e908b
106 d654274993d0149eecc3cc03214f598320211900
107 f646af7e96481d3a5470b695cf30ad8e3ab6c575
108 cf8b83f14ead62b374b6e91a0e9303b85dfd9ed7
109 91c6f6e73e39318534dc415ea4e8a09c99cd74d6
110 6ae9681c6d30389694d8701faf24b583cf3ccafe
111 $ rhg files -r cf8b83
112 file-1
113 file-2
114 file-3
115 $ rhg cat -r cf8b83 file-2
116 2
117 $ rhg cat -r c file-2
118 abort: invalid revision identifier c
119 [255]
102 120
103 121 Cat files
104 122 $ cd $TESTTMP
@@ -116,26 +134,6 b' Cat copied file should not display copy '
116 134 $ rhg cat -r 1 copy_of_original
117 135 original content
118 136
119 Specifying revisions by changeset ID
120 $ hg log
121 changeset: 1:41263439dc17
122 tag: tip
123 user: test
124 date: Thu Jan 01 00:00:00 1970 +0000
125 summary: add copy of original
126
127 changeset: 0:1c9e69808da7
128 user: test
129 date: Thu Jan 01 00:00:00 1970 +0000
130 summary: add original
131
132 $ rhg files -r 41263439dc17
133 abort: invalid revision identifier 41263439dc17
134 [255]
135 $ rhg cat -r 41263439dc17 original
136 abort: invalid revision identifier 41263439dc17
137 [255]
138
139 137 Requirements
140 138 $ rhg debugrequirements
141 139 dotencode
General Comments 0
You need to be logged in to leave comments. Login now