Skip to content

Rust1.46 and nightly ci #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [nightly, stable]

runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.rust == 'nightly' }}

steps:
- uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: ${{ matrix.rust }}
default: true
profile: minimal
components: clippy

Expand Down
8 changes: 7 additions & 1 deletion asyncgit/src/sync/hunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ pub fn unstage_hunk(

let diff = get_diff_raw(&repo, &file_path, true, true)?;

assert_eq!(diff.deltas().len(), diff_count_positive);
if diff.deltas().len() != diff_count_positive {
return Err(Error::Generic(format!(
"hunk error: {}!={}",
diff.deltas().len(),
diff_count_positive
)));
}

let mut count = 0;
{
Expand Down
2 changes: 1 addition & 1 deletion src/cmdbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl CommandBar {
self.refresh_list(self.width);
}

pub fn height(&self) -> u16 {
pub const fn height(&self) -> u16 {
if self.expandable && self.expanded {
self.lines
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/components/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,28 @@ impl CommandInfo {
order: 0,
}
}

///
pub const fn order(self, order: i8) -> Self {
let mut res = self;
res.order = order;
res
}

///
pub const fn hidden(self) -> Self {
let mut res = self;
res.quick_bar = false;
res
}

///
pub fn print(&self, out: &mut String) {
out.push_str(&self.text.name);
}

///
pub fn show_in_quickbar(&self) -> bool {
pub const fn show_in_quickbar(&self) -> bool {
self.quick_bar && self.available
}
}
9 changes: 4 additions & 5 deletions src/components/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,10 @@ impl CommitComponent {
return Ok(());
}

let res = if let Some(amend) = self.amend {
sync::amend(CWD, amend, &msg)
} else {
sync::commit(CWD, &msg)
};
let res =
self.amend.map_or(sync::commit(CWD, &msg), |amend| {
sync::amend(CWD, amend, &msg)
});
if let Err(e) = res {
log::error!("commit error: {}", &e);
self.queue.borrow_mut().push_back(
Expand Down
7 changes: 2 additions & 5 deletions src/components/commit_details/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ impl DetailsComponent {
) -> Result<()> {
self.tags.clear();

self.data = if let Some(id) = id {
sync::get_commit_details(CWD, id).ok()
} else {
None
};
self.data =
id.and_then(|id| sync::get_commit_details(CWD, id).ok());

self.scroll_top.set(0);

Expand Down
12 changes: 5 additions & 7 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,11 @@ impl CommitList {
.take(height)
.enumerate()
{
let tags = if let Some(tags) =
self.tags.as_ref().and_then(|t| t.get(&e.id))
{
Some(tags.join(" "))
} else {
None
};
let tags = self
.tags
.as_ref()
.and_then(|t| t.get(&e.id))
.map(|tags| tags.join(" "));

Self::add_entry(
e,
Expand Down
6 changes: 3 additions & 3 deletions src/components/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ enum Selection {
}

impl Selection {
fn get_start(&self) -> usize {
const fn get_start(&self) -> usize {
match self {
Self::Single(start) | Self::Multiple(start, _) => *start,
}
}

fn get_end(&self) -> usize {
const fn get_end(&self) -> usize {
match self {
Self::Single(end) | Self::Multiple(_, end) => *end,
}
Expand Down Expand Up @@ -447,7 +447,7 @@ impl DiffComponent {
));
}

fn hunk_visible(
const fn hunk_visible(
hunk_min: usize,
hunk_max: usize,
min: usize,
Expand Down
8 changes: 3 additions & 5 deletions src/components/filetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ impl FileTreeComponent {

///
pub fn is_file_seleted(&self) -> bool {
if let Some(item) = self.tree.selected_item() {
self.tree.selected_item().map_or(false, |item| {
match item.kind {
FileTreeItemKind::File(_) => true,
FileTreeItemKind::Path(..) => false,
}
} else {
false
}
})
}

fn move_selection(&mut self, dir: MoveSelection) -> bool {
Expand Down Expand Up @@ -207,7 +205,7 @@ impl FileTreeComponent {
}
}

fn item_status_char(item_type: StatusItemType) -> char {
const fn item_status_char(item_type: StatusItemType) -> char {
match item_type {
StatusItemType::Modified => 'M',
StatusItemType::New => '+',
Expand Down
9 changes: 3 additions & 6 deletions src/components/textinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,11 @@ impl TextInputComponent {
));
}

let cursor_str = if let Some(pos) = self.next_char_position()
{
&self.msg[self.cursor_position..pos]
} else {
let cursor_str = self
.next_char_position()
// if the cursor is at the end of the msg
// a whitespace is used to underline
" "
};
.map_or(" ", |pos| &self.msg[self.cursor_position..pos]);

if cursor_str == "\n" {
txt.push(Text::styled(
Expand Down
17 changes: 7 additions & 10 deletions src/components/utils/statustree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ impl StatusTree {
let last_selection_index = self.selection.unwrap_or(0);

self.tree = FileTreeItems::new(list, &last_collapsed)?;
self.selection =
if let Some(ref last_selection) = last_selection {
self.selection = last_selection.as_ref().map_or(
self.tree.items().first().map(|_| 0),
|last_selection| {
self.find_last_selection(
last_selection,
last_selection_index,
)
.or_else(|| self.tree.items().first().map(|_| 0))
} else {
// simply select first
self.tree.items().first().map(|_| 0)
};
},
);

self.update_visibility(None, 0, true);

Expand All @@ -80,7 +79,7 @@ impl StatusTree {

///
pub fn move_selection(&mut self, dir: MoveSelection) -> bool {
if let Some(selection) = self.selection {
self.selection.map_or(false, |selection| {
let selection_change = match dir {
MoveSelection::Up => {
self.selection_updown(selection, true)
Expand All @@ -102,9 +101,7 @@ impl StatusTree {
self.selection = Some(selection_change.new_index);

changed_index || selection_change.changes
} else {
false
}
})
}

///
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![deny(clippy::panic)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::multiple_crate_versions)]
#![warn(clippy::missing_const_for_fn)]

mod app;
mod cmdbar;
Expand Down
52 changes: 24 additions & 28 deletions src/tabs/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,7 @@ impl Revlog {
let tags = self.list.tags();

commit.and_then(|commit| {
if let Some(tags) = tags {
if let Some(tags) = tags.get(&commit) {
Some(tags.clone())
} else {
None
}
} else {
None
}
tags.and_then(|tags| tags.get(&commit).cloned())
})
}
}
Expand Down Expand Up @@ -213,28 +205,32 @@ impl Component for Revlog {
self.update()?;
return Ok(true);
} else if k == self.key_config.log_tag_commit {
return if let Some(id) = self.selected_commit() {
self.queue
.borrow_mut()
.push_back(InternalEvent::TagCommit(id));
Ok(true)
} else {
Ok(false)
};
return self.selected_commit().map_or(
Ok(false),
|id| {
self.queue.borrow_mut().push_back(
InternalEvent::TagCommit(id),
);
Ok(true)
},
);
} else if k == self.key_config.focus_right
&& self.commit_details.is_visible()
{
return if let Some(id) = self.selected_commit() {
self.queue.borrow_mut().push_back(
InternalEvent::InspectCommit(
id,
self.selected_commit_tags(&Some(id)),
),
);
Ok(true)
} else {
Ok(false)
};
return self.selected_commit().map_or(
Ok(false),
|id| {
self.queue.borrow_mut().push_back(
InternalEvent::InspectCommit(
id,
self.selected_commit_tags(&Some(
id,
)),
),
);
Ok(true)
},
);
} else {
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/ui/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ impl Theme {
self.apply_select(style, selected)
}

fn apply_select(&self, style: Style, selected: bool) -> Style {
const fn apply_select(
&self,
style: Style,
selected: bool,
) -> Style {
if selected {
style.bg(self.selection_bg)
} else {
Expand Down