Skip to content

Commit

Permalink
support multiple tags per commit (#62)
Browse files Browse the repository at this point in the history
* support multiple tags per commit
* update changelog
* make sure clippy works in CI
  • Loading branch information
Stephan Dilly authored May 16, 2020
1 parent 3375128 commit 8b096fb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- name: Run clippy
run: |
rustup component add clippy
cargo clean
make clippy
- name: Build Release
run: make build-release
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- better error message when trying to run outside of a valid git repo ([#56](https://github.com/extrawurst/gitui/issues/56))
- improve ctrl+c handling so it is checked first and no component needs to worry of blocking it

### Fixed
- support multiple tags per commit in log ([#61](https://github.com/extrawurst/gitui/issues/61))

## [0.2.3] - 2020-05-12
### Added
- support more navigation keys: home/end/pageUp/pageDown ([#43](https://github.com/extrawurst/gitui/issues/43))
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test:
cargo test --workspace

clippy:
cargo clean
cargo clean -p gitui -p asyncgit -p scopetime
cargo clippy --all-features

clippy-pedantic:
Expand Down
53 changes: 50 additions & 3 deletions asyncgit/src/sync/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ use crate::error::Result;
use scopetime::scope_time;
use std::collections::HashMap;

/// hashmap of tag target commit hash to tag name
pub type Tags = HashMap<String, String>;
/// hashmap of tag target commit hash to tag names
pub type Tags = HashMap<String, Vec<String>>;

/// returns `Tags` type filled with all tags found in repo
pub fn get_tags(repo_path: &str) -> Result<Tags> {
scope_time!("get_tags");

let mut res = Tags::new();
let mut adder = |key: String, value: String| {
if let Some(key) = res.get_mut(&key) {
key.push(value)
} else {
res.insert(key, vec![value]);
}
};

let repo = repo(repo_path)?;

Expand All @@ -21,10 +28,50 @@ pub fn get_tags(repo_path: &str) -> Result<Tags> {
if let Some(tag) = obj.as_tag() {
let target_hash = tag.target_id().to_string();
let tag_name = String::from(name);
res.insert(target_hash, tag_name);
adder(target_hash, tag_name);
}
}
}

Ok(res)
}

#[cfg(test)]
mod tests {
use super::*;
use crate::sync::tests::repo_init;
use git2::ObjectType;

#[test]
fn test_smoke() {
let (_td, repo) = repo_init().unwrap();
let root = repo.path().parent().unwrap();
let repo_path = root.as_os_str().to_str().unwrap();

assert_eq!(get_tags(repo_path).unwrap().is_empty(), true);
}

#[test]
fn test_multitags() {
let (_td, repo) = repo_init().unwrap();
let root = repo.path().parent().unwrap();
let repo_path = root.as_os_str().to_str().unwrap();

let sig = repo.signature().unwrap();
let head_id = repo.head().unwrap().target().unwrap();
let target = repo
.find_object(
repo.head().unwrap().target().unwrap(),
Some(ObjectType::Commit),
)
.unwrap();

repo.tag("a", &target, &sig, "", false).unwrap();
repo.tag("b", &target, &sig, "", false).unwrap();

assert_eq!(
get_tags(repo_path).unwrap()[&head_id.to_string()],
vec!["a", "b"]
);
}
}
14 changes: 7 additions & 7 deletions src/tabs/revlog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Revlog {
e: &'a LogEntry,
selected: bool,
txt: &mut Vec<Text<'a>>,
tag: &'a str,
tags: Option<String>,
) {
let count_before = txt.len();

Expand Down Expand Up @@ -209,10 +209,10 @@ impl Revlog {
));
txt.push(splitter.clone());
txt.push(Text::Styled(
Cow::from(if tag.is_empty() {
String::from("")
Cow::from(if let Some(tags) = tags {
format!(" {}", tags)
} else {
format!(" {}", tag)
String::from("")
}),
if selected {
STYLE_TAG_SELECTED
Expand Down Expand Up @@ -250,10 +250,10 @@ impl DrawableComponent for Revlog {

let mut txt = Vec::new();
for (idx, e) in self.items.items.iter().enumerate() {
let tag = if let Some(tag_name) = self.tags.get(&e.hash) {
tag_name.as_str()
let tag = if let Some(tags) = self.tags.get(&e.hash) {
Some(tags.join(" "))
} else {
""
None
};
Self::add_entry(e, idx == selection, &mut txt, tag);
}
Expand Down

0 comments on commit 8b096fb

Please sign in to comment.