54 .map_err(|_| CommandError::abort(""))?; |
54 .map_err(|_| CommandError::abort(""))?; |
55 let hg_file = HgPathBuf::try_from(stripped.to_path_buf()) |
55 let hg_file = HgPathBuf::try_from(stripped.to_path_buf()) |
56 .map_err(|e| CommandError::abort(e.to_string()))?; |
56 .map_err(|e| CommandError::abort(e.to_string()))?; |
57 files.push(hg_file); |
57 files.push(hg_file); |
58 } |
58 } |
|
59 // TODO probably move this to a util function like `repo.default_rev` or |
|
60 // something when it's used somewhere else |
|
61 let rev = match rev { |
|
62 Some(r) => r.to_string(), |
|
63 None => format!("{:x}", repo.dirstate_parents()?.p1), |
|
64 }; |
59 |
65 |
60 match rev { |
66 let output = cat(&repo, &rev, &files).map_err(|e| (e, rev.as_str()))?; |
61 Some(rev) => { |
67 invocation.ui.write_stdout(&output.concatenated)?; |
62 let output = cat(&repo, rev, &files).map_err(|e| (e, rev))?; |
68 if !output.missing.is_empty() { |
63 invocation.ui.write_stdout(&output.concatenated)?; |
69 let short = format!("{:x}", output.node.short()).into_bytes(); |
64 if !output.missing.is_empty() { |
70 for path in &output.missing { |
65 let short = format!("{:x}", output.node.short()).into_bytes(); |
71 invocation.ui.write_stderr(&format_bytes!( |
66 for path in &output.missing { |
72 b"{}: no such file in rev {}\n", |
67 invocation.ui.write_stderr(&format_bytes!( |
73 path.as_bytes(), |
68 b"{}: no such file in rev {}\n", |
74 short |
69 path.as_bytes(), |
75 ))?; |
70 short |
|
71 ))?; |
|
72 } |
|
73 } |
|
74 if output.found_any { |
|
75 Ok(()) |
|
76 } else { |
|
77 Err(CommandError::Unsuccessful) |
|
78 } |
|
79 } |
76 } |
80 None => Err(CommandError::unsupported( |
77 } |
81 "`rhg cat` without `--rev` / `-r`", |
78 if output.found_any { |
82 )), |
79 Ok(()) |
|
80 } else { |
|
81 Err(CommandError::Unsuccessful) |
83 } |
82 } |
84 } |
83 } |