Skip to content

Commit

Permalink
Updated for rustfmt and to add MSVC helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser999 committed Aug 19, 2017
1 parent e64f373 commit a21f965
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Cargo.lock
target
*.sublime-workspace
*.sln
*/.vs
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Fraser Hutchison <[email protected]>"]
description = "An interactive CLI tool to add a remote fork to a local Git repository."
license = "GPL-3.0"
license = "MIT/Apache-2.0"
name = "add-remote"
readme = "README.md"
version = "0.8.0"
Expand Down
20 changes: 20 additions & 0 deletions MSVC/Add-Remote.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{911E67C6-3D85-4FCE-B560-20A9C3E3FF48}") = "add_remote", "Add-Remote\target\stable\debug\add_remote.exe", "{00000000-0000-0000-0000-000000000000}"
ProjectSection(DebuggerProjectSystem) = preProject
Executable = Add-Remote\target\stable\debug\add_remote.exe
Arguments =
StartingDirectory = Add-Remote\target\stable\debug
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Natvis", "Natvis", "{00000000-0000-0000-0000-000000000000}"
ProjectSection(SolutionItems) = preProject
liballoc.natvis = liballoc.natvis
libcollections.natvis = libcollections.natvis
libcore.natvis = libcore.natvis
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{00000000-0000-0000-0000-000000000000}"
ProjectSection(SolutionItems) = preProject
..\src\main.rs = ..\src\main.rs
EndProjectSection
EndProject
55 changes: 55 additions & 0 deletions MSVC/liballoc.natvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="alloc::vec::Vec&lt;*&gt;">
<DisplayString>{{ size={len} }}</DisplayString>
<Expand>
<Item Name="[size]" ExcludeView="simple">len</Item>
<Item Name="[capacity]" ExcludeView="simple">buf.cap</Item>
<ArrayItems>
<Size>len</Size>
<ValuePointer>buf.ptr.pointer.__0</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="alloc::vec_deque::VecDeque&lt;*&gt;">
<DisplayString>{{ size={tail &lt;= head ? head - tail : buf.cap - tail + head} }}</DisplayString>
<Expand>
<Item Name="[size]" ExcludeView="simple">tail &lt;= head ? head - tail : buf.cap - tail + head</Item>
<Item Name="[capacity]" ExcludeView="simple">buf.cap</Item>
<CustomListItems>
<Variable Name="i" InitialValue="tail" />
<Size>tail &lt;= head ? head - tail : buf.cap - tail + head</Size>
<Loop>
<If Condition="i == head">
<Break/>
</If>
<Item>buf.ptr.pointer.__0 + i</Item>
<Exec>i = (i + 1 == buf.cap ? 0 : i + 1)</Exec>
</Loop>
</CustomListItems>
</Expand>
</Type>
<Type Name="alloc::linked_list::LinkedList&lt;*&gt;">
<DisplayString>{{ size={len} }}</DisplayString>
<Expand>
<LinkedListItems>
<Size>len</Size>
<HeadPointer>*(alloc::linked_list::Node&lt;$T1&gt; **)&amp;head</HeadPointer>
<NextPointer>*(alloc::linked_list::Node&lt;$T1&gt; **)&amp;next</NextPointer>
<ValueNode>element</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="alloc::string::String">
<DisplayString>{*(char**)this,[vec.len]}</DisplayString>
<StringView>*(char**)this,[vec.len]</StringView>
<Expand>
<Item Name="[size]" ExcludeView="simple">vec.len</Item>
<Item Name="[capacity]" ExcludeView="simple">vec.buf.cap</Item>
<ArrayItems>
<Size>vec.len</Size>
<ValuePointer>*(char**)this</ValuePointer>
</ArrayItems>
</Expand>
</Type>
</AutoVisualizer>
55 changes: 55 additions & 0 deletions MSVC/libcollections.natvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="collections::vec::Vec&lt;*&gt;">
<DisplayString>{{ size={len} }}</DisplayString>
<Expand>
<Item Name="[size]" ExcludeView="simple">len</Item>
<Item Name="[capacity]" ExcludeView="simple">buf.cap</Item>
<ArrayItems>
<Size>len</Size>
<ValuePointer>buf.ptr.pointer.__0</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="collections::vec_deque::VecDeque&lt;*&gt;">
<DisplayString>{{ size={tail &lt;= head ? head - tail : buf.cap - tail + head} }}</DisplayString>
<Expand>
<Item Name="[size]" ExcludeView="simple">tail &lt;= head ? head - tail : buf.cap - tail + head</Item>
<Item Name="[capacity]" ExcludeView="simple">buf.cap</Item>
<CustomListItems>
<Variable Name="i" InitialValue="tail" />
<Size>tail &lt;= head ? head - tail : buf.cap - tail + head</Size>
<Loop>
<If Condition="i == head">
<Break/>
</If>
<Item>buf.ptr.pointer.__0 + i</Item>
<Exec>i = (i + 1 == buf.cap ? 0 : i + 1)</Exec>
</Loop>
</CustomListItems>
</Expand>
</Type>
<Type Name="collections::linked_list::LinkedList&lt;*&gt;">
<DisplayString>{{ size={len} }}</DisplayString>
<Expand>
<LinkedListItems>
<Size>len</Size>
<HeadPointer>*(collections::linked_list::Node&lt;$T1&gt; **)&amp;head</HeadPointer>
<NextPointer>*(collections::linked_list::Node&lt;$T1&gt; **)&amp;next</NextPointer>
<ValueNode>element</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="collections::string::String">
<DisplayString>{*(char**)this,[vec.len]}</DisplayString>
<StringView>*(char**)this,[vec.len]</StringView>
<Expand>
<Item Name="[size]" ExcludeView="simple">vec.len</Item>
<Item Name="[capacity]" ExcludeView="simple">vec.buf.cap</Item>
<ArrayItems>
<Size>vec.len</Size>
<ValuePointer>*(char**)this</ValuePointer>
</ArrayItems>
</Expand>
</Type>
</AutoVisualizer>
39 changes: 39 additions & 0 deletions MSVC/libcore.natvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="core::ptr::Unique&lt;*&gt;">
<DisplayString>{{ Unique {*pointer.__0} }}</DisplayString>
<Expand>
<Item Name="[ptr]">pointer.__0</Item>
</Expand>
</Type>
<Type Name="core::ptr::Shared&lt;*&gt;">
<DisplayString>{{ Shared {*pointer.__0} }}</DisplayString>
<Expand>
<Item Name="[ptr]">pointer.__0</Item>
</Expand>
</Type>
<Type Name="core::option::Option&lt;*&gt;">
<DisplayString Condition="RUST$ENUM$DISR == 0x0">{{ None }}</DisplayString>
<DisplayString Condition="RUST$ENUM$DISR == 0x1">{{ Some {__0} }}</DisplayString>
<Expand>
<Item Name="[size]" ExcludeView="simple">(ULONG)(RUST$ENUM$DISR != 0)</Item>
<Item Name="[value]" ExcludeView="simple">__0</Item>
<ArrayItems>
<Size>(ULONG)(RUST$ENUM$DISR != 0)</Size>
<ValuePointer>&amp;__0</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="core::option::Option&lt;*&gt;" Priority="MediumLow">
<DisplayString Condition="*(PVOID *)this == nullptr">{{ None }}</DisplayString>
<DisplayString>{{ Some {($T1 *)this} }}</DisplayString>
<Expand>
<Item Name="[size]" ExcludeView="simple">(ULONG)(*(PVOID *)this != nullptr)</Item>
<Item Name="[value]" ExcludeView="simple" Condition="*(PVOID *)this != nullptr">($T1 *)this</Item>
<ArrayItems>
<Size>(ULONG)(*(PVOID *)this != nullptr)</Size>
<ValuePointer>($T1 *)this</ValuePointer>
</ArrayItems>
</Expand>
</Type>
</AutoVisualizer>
8 changes: 8 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
array_layout = "Visual"
combine_control_expr = false
condense_wildcard_suffices = true
control_style = "Legacy"
fn_args_layout = "Visual"
fn_args_paren_newline = true
fn_call_style = "Visual"
fn_call_width = 100
fn_single_line = true
generics_indent = "Visual"
ideal_width = 100
newline_style = "Native"
reorder_imports = true
Expand All @@ -9,4 +16,5 @@ single_line_if_else_max_width = 100
struct_lit_width = 100
struct_variant_width = 100
use_try_shorthand = true
where_style = "Legacy"
write_mode = "Overwrite"
23 changes: 11 additions & 12 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Repo {
} else {
yellow!("Choose fork (enter index number): ");
}
#[cfg_attr(feature="cargo-clippy", allow(cast_possible_truncation))]
#[cfg_attr(feature = "cargo-clippy", allow(cast_possible_truncation))]
match get_uint(&mut self.stdin.lock(), default) {
Err(error) => {
red_ln!("{}", error);
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Repo {

/// Process the user's choices, i.e. add the new remote. Also calls `git fetch` for the new
/// remote and displays the remotes when complete.
#[cfg_attr(feature="cargo-clippy", allow(use_debug))]
#[cfg_attr(feature = "cargo-clippy", allow(use_debug))]
pub fn set_remote(&self) {
prnt_ln!("");
let remotes_before = self.git_remote_verbose_output();
Expand Down Expand Up @@ -247,9 +247,8 @@ impl Repo {
/// not being executed from within a Git repository, so we print an error message to that effect
/// exit with a non-zero code.
fn populate_local_remotes(&mut self) {
let local_remotes_output = unwrap!(Command::new(&self.git)
.args(&["remote", "show"])
.output());
let local_remotes_output =
unwrap!(Command::new(&self.git).args(&["remote", "show"]).output());
// Get list of local remotes.
if !local_remotes_output.status.success() {
red_ln!("Failed to execute 'git remote show'. Execute this program from inside a Git \
Expand Down Expand Up @@ -343,14 +342,16 @@ impl Repo {
}
// Choose the main fork/source owner if available.
if let Ok(index) = self.available_forks
.binary_search_by_key(&self.main_fork_owner.0.to_lowercase(),
|&(ref owner, _)| owner.0.to_lowercase()) {
.binary_search_by_key(&self.main_fork_owner.0.to_lowercase(), |&(ref owner, _)| {
owner.0.to_lowercase()
}) {
return Some(index as u64);
}
// Next look for "maidsafe".
if let Ok(index) = self.available_forks
.binary_search_by_key(&"maidsafe".to_string(),
|&(ref owner, _)| owner.0.to_lowercase()) {
.binary_search_by_key(&"maidsafe".to_string(), |&(ref owner, _)| {
owner.0.to_lowercase()
}) {
return Some(index as u64);
}
None
Expand All @@ -369,9 +370,7 @@ impl Repo {
.args(&["config", &alias_arg])
.output());
if output.status.success() {
String::from_utf8_lossy(&output.stdout)
.trim()
.to_string()
String::from_utf8_lossy(&output.stdout).trim().to_string()
} else {
chosen_owner.0.clone()
}
Expand Down

0 comments on commit a21f965

Please sign in to comment.