Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
...that actually does something _remotely_ useful. :)
  • Loading branch information
perlun committed Nov 23, 2016
1 parent e23279a commit 351ea4d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "changelog-rs"
version = "0.1.0"
authors = ["Per Lundberg <[email protected]>"]

[dependencies]
45 changes: 45 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std::env;
use std::process::Command;
use std::process::exit;

pub fn get_commits(dir: &str, from_revision: &str, to_revision: &str) {
let range = format!("{}..{}", from_revision, to_revision);

let output = Command::new("git")
.arg("log")
.arg("--oneline")
.arg(&range)
.current_dir(dir)
.output().unwrap_or_else(|e| panic!("Failed to run 'git log' with error: {}", e));

let stdout_output = String::from_utf8_lossy(&output.stdout);
let lines = stdout_output
.split('\n')
.collect::<Vec<_>>();
let mut lines_iterator = lines.iter();

print!("## {}\n\n", to_revision);

loop {
match lines_iterator.next() {
Some(line) => {
if line.is_empty() { return; }
println!("* {}", line)
},
None => break
}
}
}

fn main() {
let args: Vec<_> = env::args().collect();

if args.len() == 4 {
get_commits(&args[1], &args[2], &args[3]);
}
else {
println!("Usage: {} <path> <from_revision> <to_revision>\n", args[0]);
println!("The path must be a clone of valid git repository.");
exit(1);
}
}

0 comments on commit 351ea4d

Please sign in to comment.