-fn rev() -> Option<String> {
- let output =
- Command::new("git").args(&["describe", "--tags", "--exclude", "nightly"]).output().ok()?;
+fn rev() -> String {
+ if let Ok(rev) = env::var("RUST_ANALYZER_REV") {
+ return rev;
+ }
+
+ if let Some(commit_hash) = commit_hash() {
+ let mut buf = commit_hash;
+
+ if let Some(date) = build_date() {
+ buf.push(' ');
+ buf.push_str(&date);
+ }
+
+ let channel = env::var("RUST_ANALYZER_CHANNEL").unwrap_or_else(|_| "dev".to_string());
+ buf.push(' ');
+ buf.push_str(&channel);
+
+ return buf;
+ }
+
+ "???????".to_string()
+}
+
+fn commit_hash() -> Option<String> {
+ output_to_string("git rev-parse --short HEAD")
+}
+
+fn build_date() -> Option<String> {
+ output_to_string("date --iso --utc")
+}
+
+fn output_to_string(command: &str) -> Option<String> {
+ let args = command.split_ascii_whitespace().collect::<Vec<_>>();
+ let output = Command::new(args[0]).args(&args[1..]).output().ok()?;