Skip to content

Commit

Permalink
Use hg.m.o's raw-file viewer instead of github, so that it renders th…
Browse files Browse the repository at this point in the history
…ings like SVGs and HTML files
  • Loading branch information
staktrace authored and bill-mccloskey committed Nov 15, 2017
1 parent abf3f72 commit 18355d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tests/config.json
Expand Up @@ -15,7 +15,8 @@
"objdir_path": "$WORKING/searchfox/objdir",
"git_path": "$MOZSEARCH_PATH",
"codesearch_path": "$WORKING/searchfox/livegrep.idx",
"codesearch_port": 8081
"codesearch_port": 8081,
"hg_root": "https://hg.mozilla.org/nonexistent-searchfox-hg-mirror"
}
}
}
4 changes: 2 additions & 2 deletions tools/src/bin/output-file.rs
Expand Up @@ -137,11 +137,11 @@ fn main() {
update_link_lineno: true,
}, PanelItem {
title: "Log".to_owned(),
link: format!("https://hg.mozilla.org/mozilla-central/log/tip/{}", path),
link: format!("{}/log/tip/{}", config::get_hg_root(tree_config), path),
update_link_lineno: false,
}, PanelItem {
title: "Raw".to_owned(),
link: format!("https://raw.githubusercontent.com/mozilla/gecko-dev/{}/{}", oid, path),
link: format!("{}/raw-file/tip/{}", config::get_hg_root(tree_config), path),
update_link_lineno: false,
}, PanelItem {
title: "Blame".to_owned(),
Expand Down
12 changes: 12 additions & 0 deletions tools/src/config.rs
Expand Up @@ -16,6 +16,7 @@ pub struct TreeConfigPaths {
pub git_path: Option<String>,
pub git_blame_path: Option<String>,
pub objdir_path: String,
pub hg_root: Option<String>,
}

pub struct GitData {
Expand Down Expand Up @@ -50,6 +51,17 @@ pub fn get_git_path(tree_config: &TreeConfig) -> Result<&str, &'static str> {
}
}

pub fn get_hg_root(tree_config: &TreeConfig) -> String {
// For temporary backwards compatibility, produce the m-c root if
// there isn't one specified. We can remove this once all relevant
// deployed config.json files have an explicit hg root, and make
// this return an Option<&str> instead.
match &tree_config.paths.hg_root {
&Some(ref hg_root) => hg_root.clone(),
&None => String::from("https://hg.mozilla.org/mozilla-central"),
}
}

fn index_blame(_repo: &Repository, blame_repo: &Repository) -> (HashMap<Oid, Oid>, HashMap<Oid, String>) {
let mut walk = blame_repo.revwalk().unwrap();
walk.push_head().unwrap();
Expand Down
16 changes: 13 additions & 3 deletions tools/src/format.rs
Expand Up @@ -417,6 +417,12 @@ pub fn format_path(cfg: &config::Config,
let jumps : HashMap<String, analysis::Jump> = HashMap::new();
let analysis = Vec::new();

let hg_rev : &str =
tree_config.git.as_ref()
.and_then(|git| git.hg_map.get(&commit.id()))
.and_then(|rev| Some(rev.as_ref())) // &String to &str conversion
.unwrap_or(&"tip");

let panel = vec![PanelSection {
name: "Revision control".to_owned(),
items: vec![PanelItem {
Expand All @@ -425,7 +431,11 @@ pub fn format_path(cfg: &config::Config,
update_link_lineno: true,
}, PanelItem {
title: "Log".to_owned(),
link: format!("https://hg.mozilla.org/mozilla-central/log/tip/{}", path),
link: format!("{}/log/{}/{}", config::get_hg_root(tree_config), hg_rev, path),
update_link_lineno: false,
}, PanelItem {
title: "Raw".to_owned(),
link: format!("{}/raw-file/{}/{}", config::get_hg_root(tree_config), hg_rev, path),
update_link_lineno: false,
}, PanelItem {
title: "Blame".to_owned(),
Expand Down Expand Up @@ -601,7 +611,7 @@ pub fn format_diff(cfg: &config::Config,
update_link_lineno: true,
}, PanelItem {
title: "Log".to_owned(),
link: format!("https://hg.mozilla.org/mozilla-central/log/tip/{}", path),
link: format!("{}/log/tip/{}", config::get_hg_root(tree_config), path),
update_link_lineno: false,
}],
}];
Expand Down Expand Up @@ -744,7 +754,7 @@ fn generate_commit_info(tree_name: &str,
let git = try!(config::get_git(tree_config));
let hg = match git.hg_map.get(&commit.id()) {
Some(hg_id) => {
let hg_link = format!("<a href=\"https://hg.mozilla.org/mozilla-central/rev/{}\">{}</a>", hg_id, hg_id);
let hg_link = format!("<a href=\"{}/rev/{}\">{}</a>", config::get_hg_root(tree_config), hg_id, hg_id);
vec![F::T(format!("<tr><td>hg</td><td>{}</td></tr>", hg_link))]
},

Expand Down

0 comments on commit 18355d1

Please sign in to comment.