diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..b5f39e6a
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,364 @@
+root = true
+
+# All files
+[*]
+indent_style = space
+
+# Xml files
+[*.xml]
+indent_size = 2
+
+# C# files
+[*.cs]
+
+#### Core EditorConfig Options ####
+
+# Indentation and spacing
+indent_size = 4
+tab_width = 4
+
+# New line preferences
+end_of_line = crlf
+insert_final_newline = false
+
+#### .NET Coding Conventions ####
+[*.{cs,vb}]
+
+# Organize usings
+dotnet_separate_import_directive_groups = true
+dotnet_sort_system_directives_first = true
+file_header_template = unset
+
+# this. and Me. preferences
+dotnet_style_qualification_for_event = false:silent
+dotnet_style_qualification_for_field = false:silent
+dotnet_style_qualification_for_method = false:silent
+dotnet_style_qualification_for_property = false:silent
+
+# Language keywords vs BCL types preferences
+dotnet_style_predefined_type_for_locals_parameters_members = true:silent
+dotnet_style_predefined_type_for_member_access = true:silent
+
+# Parentheses preferences
+dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
+dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
+dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
+dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
+
+# Modifier preferences
+dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
+
+# Expression-level preferences
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_explicit_tuple_names = true:suggestion
+dotnet_style_null_propagation = true:suggestion
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
+dotnet_style_prefer_auto_properties = true:suggestion
+dotnet_style_prefer_compound_assignment = true:suggestion
+dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
+dotnet_style_prefer_conditional_expression_over_return = true:suggestion
+dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
+dotnet_style_prefer_inferred_tuple_names = true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
+dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
+dotnet_style_prefer_simplified_interpolation = true:suggestion
+
+# Field preferences
+dotnet_style_readonly_field = true:warning
+
+# Parameter preferences
+dotnet_code_quality_unused_parameters = all:suggestion
+
+# Suppression preferences
+dotnet_remove_unnecessary_suppression_exclusions = none
+
+#### C# Coding Conventions ####
+[*.cs]
+
+# var preferences
+csharp_style_var_elsewhere = false:silent
+csharp_style_var_for_built_in_types = false:silent
+csharp_style_var_when_type_is_apparent = false:silent
+
+# Expression-bodied members
+csharp_style_expression_bodied_accessors = true:silent
+csharp_style_expression_bodied_constructors = false:silent
+csharp_style_expression_bodied_indexers = true:silent
+csharp_style_expression_bodied_lambdas = true:suggestion
+csharp_style_expression_bodied_local_functions = false:silent
+csharp_style_expression_bodied_methods = false:silent
+csharp_style_expression_bodied_operators = false:silent
+csharp_style_expression_bodied_properties = true:silent
+
+# Pattern matching preferences
+csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
+csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
+csharp_style_prefer_not_pattern = true:suggestion
+csharp_style_prefer_pattern_matching = true:silent
+csharp_style_prefer_switch_expression = true:suggestion
+
+# Null-checking preferences
+csharp_style_conditional_delegate_call = true:suggestion
+
+# Modifier preferences
+csharp_prefer_static_local_function = true:warning
+csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
+
+# Code-block preferences
+csharp_prefer_braces = true:silent
+csharp_prefer_simple_using_statement = true:suggestion
+
+# Expression-level preferences
+csharp_prefer_simple_default_expression = true:suggestion
+csharp_style_deconstructed_variable_declaration = true:suggestion
+csharp_style_inlined_variable_declaration = true:suggestion
+csharp_style_pattern_local_over_anonymous_function = true:suggestion
+csharp_style_prefer_index_operator = true:suggestion
+csharp_style_prefer_range_operator = true:suggestion
+csharp_style_throw_expression = true:suggestion
+csharp_style_unused_value_assignment_preference = discard_variable:suggestion
+csharp_style_unused_value_expression_statement_preference = discard_variable:silent
+
+# 'using' directive preferences
+csharp_using_directive_placement = outside_namespace:silent
+
+#### C# Formatting Rules ####
+
+# New line preferences
+csharp_new_line_before_catch = true
+csharp_new_line_before_else = true
+csharp_new_line_before_finally = true
+csharp_new_line_before_members_in_anonymous_types = true
+csharp_new_line_before_members_in_object_initializers = true
+csharp_new_line_before_open_brace = all
+csharp_new_line_between_query_expression_clauses = true
+
+# Indentation preferences
+csharp_indent_block_contents = true
+csharp_indent_braces = false
+csharp_indent_case_contents = true
+csharp_indent_case_contents_when_block = true
+csharp_indent_labels = one_less_than_current
+csharp_indent_switch_labels = true
+
+# Space preferences
+csharp_space_after_cast = false
+csharp_space_after_colon_in_inheritance_clause = true
+csharp_space_after_comma = true
+csharp_space_after_dot = false
+csharp_space_after_keywords_in_control_flow_statements = true
+csharp_space_after_semicolon_in_for_statement = true
+csharp_space_around_binary_operators = before_and_after
+csharp_space_around_declaration_statements = false
+csharp_space_before_colon_in_inheritance_clause = true
+csharp_space_before_comma = false
+csharp_space_before_dot = false
+csharp_space_before_open_square_brackets = false
+csharp_space_before_semicolon_in_for_statement = false
+csharp_space_between_empty_square_brackets = false
+csharp_space_between_method_call_empty_parameter_list_parentheses = false
+csharp_space_between_method_call_name_and_opening_parenthesis = false
+csharp_space_between_method_call_parameter_list_parentheses = false
+csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
+csharp_space_between_method_declaration_name_and_open_parenthesis = false
+csharp_space_between_method_declaration_parameter_list_parentheses = false
+csharp_space_between_parentheses = false
+csharp_space_between_square_brackets = false
+
+# Wrapping preferences
+csharp_preserve_single_line_blocks = true
+csharp_preserve_single_line_statements = true
+
+#### Naming styles ####
+[*.{cs,vb}]
+
+# Naming rules
+
+dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.symbols = types_and_namespaces
+dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.interfaces_should_be_ipascalcase.severity = suggestion
+dotnet_naming_rule.interfaces_should_be_ipascalcase.symbols = interfaces
+dotnet_naming_rule.interfaces_should_be_ipascalcase.style = ipascalcase
+
+dotnet_naming_rule.type_parameters_should_be_tpascalcase.severity = suggestion
+dotnet_naming_rule.type_parameters_should_be_tpascalcase.symbols = type_parameters
+dotnet_naming_rule.type_parameters_should_be_tpascalcase.style = tpascalcase
+
+dotnet_naming_rule.methods_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.methods_should_be_pascalcase.symbols = methods
+dotnet_naming_rule.methods_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.properties_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.properties_should_be_pascalcase.symbols = properties
+dotnet_naming_rule.properties_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.events_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.events_should_be_pascalcase.symbols = events
+dotnet_naming_rule.events_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.local_variables_should_be_camelcase.severity = suggestion
+dotnet_naming_rule.local_variables_should_be_camelcase.symbols = local_variables
+dotnet_naming_rule.local_variables_should_be_camelcase.style = camelcase
+
+dotnet_naming_rule.local_constants_should_be_camelcase.severity = suggestion
+dotnet_naming_rule.local_constants_should_be_camelcase.symbols = local_constants
+dotnet_naming_rule.local_constants_should_be_camelcase.style = camelcase
+
+dotnet_naming_rule.parameters_should_be_camelcase.severity = suggestion
+dotnet_naming_rule.parameters_should_be_camelcase.symbols = parameters
+dotnet_naming_rule.parameters_should_be_camelcase.style = camelcase
+
+dotnet_naming_rule.public_fields_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.public_fields_should_be_pascalcase.symbols = public_fields
+dotnet_naming_rule.public_fields_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion
+dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields
+dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase
+
+dotnet_naming_rule.private_static_fields_should_be_s_camelcase.severity = suggestion
+dotnet_naming_rule.private_static_fields_should_be_s_camelcase.symbols = private_static_fields
+dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelcase
+
+dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields
+dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields
+dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields
+dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields
+dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums
+dotnet_naming_rule.enums_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.local_functions_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.local_functions_should_be_pascalcase.symbols = local_functions
+dotnet_naming_rule.local_functions_should_be_pascalcase.style = pascalcase
+
+dotnet_naming_rule.non_field_members_should_be_pascalcase.severity = suggestion
+dotnet_naming_rule.non_field_members_should_be_pascalcase.symbols = non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascalcase.style = pascalcase
+
+# Symbol specifications
+
+dotnet_naming_symbols.interfaces.applicable_kinds = interface
+dotnet_naming_symbols.interfaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.interfaces.required_modifiers =
+
+dotnet_naming_symbols.enums.applicable_kinds = enum
+dotnet_naming_symbols.enums.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.enums.required_modifiers =
+
+dotnet_naming_symbols.events.applicable_kinds = event
+dotnet_naming_symbols.events.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.events.required_modifiers =
+
+dotnet_naming_symbols.methods.applicable_kinds = method
+dotnet_naming_symbols.methods.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.methods.required_modifiers =
+
+dotnet_naming_symbols.properties.applicable_kinds = property
+dotnet_naming_symbols.properties.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.properties.required_modifiers =
+
+dotnet_naming_symbols.public_fields.applicable_kinds = field
+dotnet_naming_symbols.public_fields.applicable_accessibilities = public, internal
+dotnet_naming_symbols.public_fields.required_modifiers =
+
+dotnet_naming_symbols.private_fields.applicable_kinds = field
+dotnet_naming_symbols.private_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
+dotnet_naming_symbols.private_fields.required_modifiers =
+
+dotnet_naming_symbols.private_static_fields.applicable_kinds = field
+dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
+dotnet_naming_symbols.private_static_fields.required_modifiers = static
+
+dotnet_naming_symbols.types_and_namespaces.applicable_kinds = namespace, class, struct, interface, enum
+dotnet_naming_symbols.types_and_namespaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.types_and_namespaces.required_modifiers =
+
+dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.non_field_members.required_modifiers =
+
+dotnet_naming_symbols.type_parameters.applicable_kinds = namespace
+dotnet_naming_symbols.type_parameters.applicable_accessibilities = *
+dotnet_naming_symbols.type_parameters.required_modifiers =
+
+dotnet_naming_symbols.private_constant_fields.applicable_kinds = field
+dotnet_naming_symbols.private_constant_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
+dotnet_naming_symbols.private_constant_fields.required_modifiers = const
+
+dotnet_naming_symbols.local_variables.applicable_kinds = local
+dotnet_naming_symbols.local_variables.applicable_accessibilities = local
+dotnet_naming_symbols.local_variables.required_modifiers =
+
+dotnet_naming_symbols.local_constants.applicable_kinds = local
+dotnet_naming_symbols.local_constants.applicable_accessibilities = local
+dotnet_naming_symbols.local_constants.required_modifiers = const
+
+dotnet_naming_symbols.parameters.applicable_kinds = parameter
+dotnet_naming_symbols.parameters.applicable_accessibilities = *
+dotnet_naming_symbols.parameters.required_modifiers =
+
+dotnet_naming_symbols.public_constant_fields.applicable_kinds = field
+dotnet_naming_symbols.public_constant_fields.applicable_accessibilities = public, internal
+dotnet_naming_symbols.public_constant_fields.required_modifiers = const
+
+dotnet_naming_symbols.public_static_readonly_fields.applicable_kinds = field
+dotnet_naming_symbols.public_static_readonly_fields.applicable_accessibilities = public, internal
+dotnet_naming_symbols.public_static_readonly_fields.required_modifiers = readonly, static
+
+dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field
+dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
+dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = readonly, static
+
+dotnet_naming_symbols.local_functions.applicable_kinds = local_function
+dotnet_naming_symbols.local_functions.applicable_accessibilities = *
+dotnet_naming_symbols.local_functions.required_modifiers =
+
+# Naming styles
+
+dotnet_naming_style.pascalcase.required_prefix =
+dotnet_naming_style.pascalcase.required_suffix =
+dotnet_naming_style.pascalcase.word_separator =
+dotnet_naming_style.pascalcase.capitalization = pascal_case
+
+dotnet_naming_style.ipascalcase.required_prefix = I
+dotnet_naming_style.ipascalcase.required_suffix =
+dotnet_naming_style.ipascalcase.word_separator =
+dotnet_naming_style.ipascalcase.capitalization = pascal_case
+
+dotnet_naming_style.tpascalcase.required_prefix = T
+dotnet_naming_style.tpascalcase.required_suffix =
+dotnet_naming_style.tpascalcase.word_separator =
+dotnet_naming_style.tpascalcase.capitalization = pascal_case
+
+dotnet_naming_style._camelcase.required_prefix = _
+dotnet_naming_style._camelcase.required_suffix =
+dotnet_naming_style._camelcase.word_separator =
+dotnet_naming_style._camelcase.capitalization = camel_case
+
+dotnet_naming_style.camelcase.required_prefix =
+dotnet_naming_style.camelcase.required_suffix =
+dotnet_naming_style.camelcase.word_separator =
+dotnet_naming_style.camelcase.capitalization = camel_case
+
+dotnet_naming_style.s_camelcase.required_prefix = s_
+dotnet_naming_style.s_camelcase.required_suffix =
+dotnet_naming_style.s_camelcase.word_separator =
+dotnet_naming_style.s_camelcase.capitalization = camel_case
+
diff --git a/README.md b/README.md
index 10270300..e7e83eda 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,8 @@ Opensouce Git GUI client.
* Revision Diffs
* GitFlow support
+> **Linux** only tested on **Ubuntu 22.04** on **X11**.
+
## How to use
**To use this tool, you need to install Git first.**
@@ -43,7 +45,7 @@ For **macOS** users:
For **Linux** users:
* `xdg-open` must be installed to support open native file manager.
-* Only tested on `Ubuntu 22.04`.
+* Maybe you need to set environment variable `AVALONIA_SCREEN_SCALE_FACTORS`. See https://github.com/AvaloniaUI/Avalonia/wiki/Configuring-X11-per-monitor-DPI.
## Screen Shots
@@ -55,12 +57,10 @@ For **Linux** users:

-## Thanks
+## Contributing
-* [gigi81](https://github.com/gigi81) Github actions integration
-* [kekekeks](https://github.com/kekekeks) Way to stage/unstage/discard selected changes in a file.
-* [XiaoLinger](https://gitee.com/LingerNN) Hotkey: `CTRL + Enter` to commit
-* [carterl](https://gitee.com/carterl) Supports Windows Terminal; Rewrite way to find git executable
-* [PUMA](https://gitee.com/whgfu) Configure for default user
-* [Rwing](https://gitee.com/rwing) GitFlow: add an option to keep branch after finish
-* [XiaoLinger](https://gitee.com/LingerNN) Fix localizations in popup panel
+Thanks to all the people who contribute.
+
+
+
+
diff --git a/src/App.axaml.cs b/src/App.axaml.cs
index 5014cea4..36c29f64 100644
--- a/src/App.axaml.cs
+++ b/src/App.axaml.cs
@@ -1,3 +1,12 @@
+using System;
+using System.IO;
+using System.Reflection;
+using System.Text;
+using System.Globalization;
+using System.Linq;
+using System.Reflection;
+using System.Threading;
+
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
@@ -6,22 +15,21 @@ using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Media.Fonts;
using Avalonia.Styling;
-using System;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Threading;
-namespace SourceGit {
- public partial class App : Application {
+namespace SourceGit
+{
+ public partial class App : Application
+ {
[STAThread]
- public static void Main(string[] args) {
- try {
+ public static void Main(string[] args)
+ {
+ try
+ {
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
var builder = new StringBuilder();
builder.Append("Crash: ");
builder.Append(ex.Message);
@@ -39,40 +47,48 @@ namespace SourceGit {
"SourceGit",
$"crash_{time}.log");
File.WriteAllText(file, builder.ToString());
- }
+ }
}
- public static AppBuilder BuildAvaloniaApp() {
+ public static AppBuilder BuildAvaloniaApp()
+ {
var builder = AppBuilder.Configure();
builder.UsePlatformDetect();
builder.LogToTrace();
- builder.ConfigureFonts(manager => {
+ builder.ConfigureFonts(manager =>
+ {
var monospace = new EmbeddedFontCollection(
new Uri("fonts:SourceGit", UriKind.Absolute),
new Uri("avares://SourceGit/Resources/Fonts", UriKind.Absolute));
manager.AddFontCollection(monospace);
});
- Native.OS.SetupFonts(builder);
+ Native.OS.SetupApp(builder);
return builder;
}
- public static void RaiseException(string context, string message) {
- if (Current is App app && app._notificationReceiver != null) {
+ public static void RaiseException(string context, string message)
+ {
+ if (Current is App app && app._notificationReceiver != null)
+ {
var notice = new Models.Notification() { IsError = true, Message = message };
app._notificationReceiver.OnReceiveNotification(context, notice);
}
}
- public static void SendNotification(string context, string message) {
- if (Current is App app && app._notificationReceiver != null) {
+ public static void SendNotification(string context, string message)
+ {
+ if (Current is App app && app._notificationReceiver != null)
+ {
var notice = new Models.Notification() { IsError = false, Message = message };
app._notificationReceiver.OnReceiveNotification(context, notice);
}
}
- public static void SetLocale(string localeKey) {
+ public static void SetLocale(string localeKey)
+ {
var app = Current as App;
+
localeKey = localeKey.Replace("_", "-");
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(localeKey);
@@ -92,7 +108,8 @@ namespace SourceGit {
return;
}
- if (app._activeLocale != null) {
+ if (app._activeLocale != null)
+ {
app.Resources.MergedDictionaries.Remove(app._activeLocale);
}
@@ -100,31 +117,42 @@ namespace SourceGit {
app._activeLocale = targetLocale;
}
- public static void SetTheme(string theme) {
- if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase)) {
+ public static void SetTheme(string theme)
+ {
+ if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
+ {
Current.RequestedThemeVariant = ThemeVariant.Light;
- } else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase)) {
+ }
+ else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase))
+ {
Current.RequestedThemeVariant = ThemeVariant.Dark;
- } else {
+ }
+ else
+ {
Current.RequestedThemeVariant = ThemeVariant.Default;
}
}
- public static async void CopyText(string data) {
- if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
- if (desktop.MainWindow.Clipboard is { } clipbord) {
+ public static async void CopyText(string data)
+ {
+ if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+ {
+ if (desktop.MainWindow.Clipboard is { } clipbord)
+ {
await clipbord.SetTextAsync(data);
}
}
}
- public static string Text(string key, params object[] args) {
+ public static string Text(string key, params object[] args)
+ {
var fmt = Current.FindResource($"Text.{key}") as string;
if (string.IsNullOrWhiteSpace(fmt)) return $"Text.{key}";
return string.Format(fmt, args);
}
- public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
+ public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key)
+ {
var icon = new Avalonia.Controls.Shapes.Path();
icon.Width = 12;
icon.Height = 12;
@@ -133,29 +161,36 @@ namespace SourceGit {
return icon;
}
- public static TopLevel GetTopLevel() {
- if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
+ public static TopLevel GetTopLevel()
+ {
+ if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+ {
return desktop.MainWindow;
}
return null;
}
- public static void Quit() {
- if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
+ public static void Quit()
+ {
+ if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+ {
desktop.MainWindow.Close();
desktop.Shutdown();
}
}
- public override void Initialize() {
+ public override void Initialize()
+ {
AvaloniaXamlLoader.Load(this);
SetLocale(ViewModels.Preference.Instance.Locale);
SetTheme(ViewModels.Preference.Instance.Theme);
}
- public override void OnFrameworkInitializationCompleted() {
- if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
+ public override void OnFrameworkInitializationCompleted()
+ {
+ if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+ {
BindingPlugins.DataValidators.RemoveAt(0);
var launcher = new Views.Launcher();
diff --git a/src/Commands/Add.cs b/src/Commands/Add.cs
index c83c330d..b5f02089 100644
--- a/src/Commands/Add.cs
+++ b/src/Commands/Add.cs
@@ -1,18 +1,25 @@
using System.Collections.Generic;
using System.Text;
-namespace SourceGit.Commands {
- public class Add : Command {
- public Add(string repo, List changes = null) {
+namespace SourceGit.Commands
+{
+ public class Add : Command
+ {
+ public Add(string repo, List changes = null)
+ {
WorkingDirectory = repo;
Context = repo;
- if (changes == null || changes.Count == 0) {
+ if (changes == null || changes.Count == 0)
+ {
Args = "add .";
- } else {
+ }
+ else
+ {
var builder = new StringBuilder();
builder.Append("add --");
- foreach (var c in changes) {
+ foreach (var c in changes)
+ {
builder.Append(" \"");
builder.Append(c.Path);
builder.Append("\"");
@@ -21,4 +28,4 @@ namespace SourceGit.Commands {
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Apply.cs b/src/Commands/Apply.cs
index 1f550de4..e98ec601 100644
--- a/src/Commands/Apply.cs
+++ b/src/Commands/Apply.cs
@@ -1,6 +1,9 @@
-namespace SourceGit.Commands {
- public class Apply : Command {
- public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, string extra) {
+namespace SourceGit.Commands
+{
+ public class Apply : Command
+ {
+ public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, string extra)
+ {
WorkingDirectory = repo;
Context = repo;
Args = "apply ";
@@ -10,4 +13,4 @@
Args += $"\"{file}\"";
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Archive.cs b/src/Commands/Archive.cs
index ac748653..065b9900 100644
--- a/src/Commands/Archive.cs
+++ b/src/Commands/Archive.cs
@@ -1,8 +1,11 @@
using System;
-namespace SourceGit.Commands {
- public class Archive : Command {
- public Archive(string repo, string revision, string saveTo, Action outputHandler) {
+namespace SourceGit.Commands
+{
+ public class Archive : Command
+ {
+ public Archive(string repo, string revision, string saveTo, Action outputHandler)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"archive --format=zip --verbose --output=\"{saveTo}\" {revision}";
@@ -10,10 +13,11 @@ namespace SourceGit.Commands {
_outputHandler = outputHandler;
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_outputHandler?.Invoke(line);
}
- private Action _outputHandler;
+ private readonly Action _outputHandler;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/AssumeUnchanged.cs b/src/Commands/AssumeUnchanged.cs
index d7dc4c06..936242b5 100644
--- a/src/Commands/AssumeUnchanged.cs
+++ b/src/Commands/AssumeUnchanged.cs
@@ -1,36 +1,47 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class AssumeUnchanged {
- class ViewCommand : Command {
- private static readonly Regex REG = new Regex(@"^(\w)\s+(.+)$");
+namespace SourceGit.Commands
+{
+ public partial class AssumeUnchanged
+ {
+ partial class ViewCommand : Command
+ {
- public ViewCommand(string repo) {
+ [GeneratedRegex(@"^(\w)\s+(.+)$")]
+ private static partial Regex REG();
+
+ public ViewCommand(string repo)
+ {
WorkingDirectory = repo;
Args = "ls-files -v";
RaiseError = false;
}
- public List Result() {
+ public List Result()
+ {
Exec();
return _outs;
}
- protected override void OnReadline(string line) {
- var match = REG.Match(line);
+ protected override void OnReadline(string line)
+ {
+ var match = REG().Match(line);
if (!match.Success) return;
- if (match.Groups[1].Value == "h") {
+ if (match.Groups[1].Value == "h")
+ {
_outs.Add(match.Groups[2].Value);
}
}
- private List _outs = new List();
+ private readonly List _outs = new List();
}
- class ModCommand : Command {
- public ModCommand(string repo, string file, bool bAdd) {
+ class ModCommand : Command
+ {
+ public ModCommand(string repo, string file, bool bAdd)
+ {
var mode = bAdd ? "--assume-unchanged" : "--no-assume-unchanged";
WorkingDirectory = repo;
@@ -39,22 +50,26 @@ namespace SourceGit.Commands {
}
}
- public AssumeUnchanged(string repo) {
+ public AssumeUnchanged(string repo)
+ {
_repo = repo;
}
- public List View() {
+ public List View()
+ {
return new ViewCommand(_repo).Result();
}
- public void Add(string file) {
+ public void Add(string file)
+ {
new ModCommand(_repo, file, true).Exec();
}
- public void Remove(string file) {
+ public void Remove(string file)
+ {
new ModCommand(_repo, file, false).Exec();
}
- private string _repo;
+ private readonly string _repo;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Blame.cs b/src/Commands/Blame.cs
index 0598fa0f..ef3324e3 100644
--- a/src/Commands/Blame.cs
+++ b/src/Commands/Blame.cs
@@ -2,12 +2,17 @@
using System.Text;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class Blame : Command {
- private static readonly Regex REG_FORMAT = new Regex(@"^\^?([0-9a-f]+)\s+.*\((.*)\s+(\d+)\s+[\-\+]?\d+\s+\d+\) (.*)");
+namespace SourceGit.Commands
+{
+ public partial class Blame : Command
+ {
+
+ [GeneratedRegex(@"^\^?([0-9a-f]+)\s+.*\((.*)\s+(\d+)\s+[\-\+]?\d+\s+\d+\) (.*)")]
+ private static partial Regex REG_FORMAT();
private static readonly DateTime UTC_START = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
- public Blame(string repo, string file, string revision) {
+ public Blame(string repo, string file, string revision)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"blame -t {revision} -- \"{file}\"";
@@ -16,15 +21,20 @@ namespace SourceGit.Commands {
_result.File = file;
}
- public Models.BlameData Result() {
+ public Models.BlameData Result()
+ {
var succ = Exec();
- if (!succ) {
+ if (!succ)
+ {
return new Models.BlameData();
}
- if (_needUnifyCommitSHA) {
- foreach (var line in _result.LineInfos) {
- if (line.CommitSHA.Length > _minSHALen) {
+ if (_needUnifyCommitSHA)
+ {
+ foreach (var line in _result.LineInfos)
+ {
+ if (line.CommitSHA.Length > _minSHALen)
+ {
line.CommitSHA = line.CommitSHA.Substring(0, _minSHALen);
}
}
@@ -34,27 +44,30 @@ namespace SourceGit.Commands {
return _result;
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
if (_result.IsBinary) return;
if (string.IsNullOrEmpty(line)) return;
- if (line.IndexOf('\0') >= 0) {
+ if (line.IndexOf('\0', StringComparison.Ordinal) >= 0)
+ {
_result.IsBinary = true;
_result.LineInfos.Clear();
return;
}
- var match = REG_FORMAT.Match(line);
+ var match = REG_FORMAT().Match(line);
if (!match.Success) return;
_content.AppendLine(match.Groups[4].Value);
- var commit = match.Groups[1].Value;
+ var commit = match.Groups[1].Value;
var author = match.Groups[2].Value;
var timestamp = int.Parse(match.Groups[3].Value);
var when = UTC_START.AddSeconds(timestamp).ToString("yyyy/MM/dd");
- var info = new Models.BlameLineInfo() {
+ var info = new Models.BlameLineInfo()
+ {
IsFirstInGroup = commit != _lastSHA,
CommitSHA = commit,
Author = author,
@@ -64,16 +77,17 @@ namespace SourceGit.Commands {
_result.LineInfos.Add(info);
_lastSHA = commit;
- if (line[0] == '^') {
+ if (line[0] == '^')
+ {
_needUnifyCommitSHA = true;
_minSHALen = Math.Min(_minSHALen, commit.Length);
}
}
- private Models.BlameData _result = new Models.BlameData();
- private StringBuilder _content = new StringBuilder();
+ private readonly Models.BlameData _result = new Models.BlameData();
+ private readonly StringBuilder _content = new StringBuilder();
private string _lastSHA = string.Empty;
private bool _needUnifyCommitSHA = false;
private int _minSHALen = 64;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Branch.cs b/src/Commands/Branch.cs
index f109d1e4..aa3990c9 100644
--- a/src/Commands/Branch.cs
+++ b/src/Commands/Branch.cs
@@ -1,6 +1,9 @@
-namespace SourceGit.Commands {
- public static class Branch {
- public static bool Create(string repo, string name, string basedOn) {
+namespace SourceGit.Commands
+{
+ public static class Branch
+ {
+ public static bool Create(string repo, string name, string basedOn)
+ {
var cmd = new Command();
cmd.WorkingDirectory = repo;
cmd.Context = repo;
@@ -8,7 +11,8 @@
return cmd.Exec();
}
- public static bool Rename(string repo, string name, string to) {
+ public static bool Rename(string repo, string name, string to)
+ {
var cmd = new Command();
cmd.WorkingDirectory = repo;
cmd.Context = repo;
@@ -16,19 +20,24 @@
return cmd.Exec();
}
- public static bool SetUpstream(string repo, string name, string upstream) {
+ public static bool SetUpstream(string repo, string name, string upstream)
+ {
var cmd = new Command();
cmd.WorkingDirectory = repo;
cmd.Context = repo;
- if (string.IsNullOrEmpty(upstream)) {
+ if (string.IsNullOrEmpty(upstream))
+ {
cmd.Args = $"branch {name} --unset-upstream";
- } else {
+ }
+ else
+ {
cmd.Args = $"branch {name} -u {upstream}";
}
return cmd.Exec();
}
- public static bool Delete(string repo, string name) {
+ public static bool Delete(string repo, string name)
+ {
var cmd = new Command();
cmd.WorkingDirectory = repo;
cmd.Context = repo;
@@ -36,4 +45,4 @@
return cmd.Exec();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Checkout.cs b/src/Commands/Checkout.cs
index 14121fab..d6a9aba4 100644
--- a/src/Commands/Checkout.cs
+++ b/src/Commands/Checkout.cs
@@ -2,46 +2,58 @@
using System.Collections.Generic;
using System.Text;
-namespace SourceGit.Commands {
- public class Checkout : Command {
- public Checkout(string repo) {
+namespace SourceGit.Commands
+{
+ public class Checkout : Command
+ {
+ public Checkout(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
}
- public bool Branch(string branch, Action onProgress) {
+ public bool Branch(string branch, Action onProgress)
+ {
Args = $"checkout --progress {branch}";
TraitErrorAsOutput = true;
_outputHandler = onProgress;
return Exec();
}
- public bool Branch(string branch, string basedOn, Action onProgress) {
+ public bool Branch(string branch, string basedOn, Action onProgress)
+ {
Args = $"checkout --progress -b {branch} {basedOn}";
TraitErrorAsOutput = true;
_outputHandler = onProgress;
return Exec();
}
- public bool File(string file, bool useTheirs) {
- if (useTheirs) {
+ public bool File(string file, bool useTheirs)
+ {
+ if (useTheirs)
+ {
Args = $"checkout --theirs -- \"{file}\"";
- } else {
+ }
+ else
+ {
Args = $"checkout --ours -- \"{file}\"";
}
return Exec();
}
- public bool FileWithRevision(string file, string revision) {
+ public bool FileWithRevision(string file, string revision)
+ {
Args = $"checkout {revision} -- \"{file}\"";
return Exec();
}
- public bool Files(List files) {
+ public bool Files(List files)
+ {
StringBuilder builder = new StringBuilder();
builder.Append("checkout -f -q --");
- foreach (var f in files) {
+ foreach (var f in files)
+ {
builder.Append(" \"");
builder.Append(f);
builder.Append("\"");
@@ -50,10 +62,11 @@ namespace SourceGit.Commands {
return Exec();
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_outputHandler?.Invoke(line);
}
private Action _outputHandler;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/CherryPick.cs b/src/Commands/CherryPick.cs
index 6160ebac..622202b4 100644
--- a/src/Commands/CherryPick.cs
+++ b/src/Commands/CherryPick.cs
@@ -1,10 +1,13 @@
-namespace SourceGit.Commands {
- public class CherryPick : Command {
- public CherryPick(string repo, string commit, bool noCommit) {
+namespace SourceGit.Commands
+{
+ public class CherryPick : Command
+ {
+ public CherryPick(string repo, string commit, bool noCommit)
+ {
var mode = noCommit ? "-n" : "--ff";
WorkingDirectory = repo;
Context = repo;
Args = $"cherry-pick {mode} {commit}";
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Clean.cs b/src/Commands/Clean.cs
index 56a56a6c..5ef4570f 100644
--- a/src/Commands/Clean.cs
+++ b/src/Commands/Clean.cs
@@ -1,18 +1,23 @@
using System.Collections.Generic;
using System.Text;
-namespace SourceGit.Commands {
- public class Clean : Command {
- public Clean(string repo) {
+namespace SourceGit.Commands
+{
+ public class Clean : Command
+ {
+ public Clean(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
Args = "clean -qfd";
}
- public Clean(string repo, List files) {
+ public Clean(string repo, List files)
+ {
StringBuilder builder = new StringBuilder();
builder.Append("clean -qfd --");
- foreach (var f in files) {
+ foreach (var f in files)
+ {
builder.Append(" \"");
builder.Append(f);
builder.Append("\"");
@@ -23,4 +28,4 @@ namespace SourceGit.Commands {
Args = builder.ToString();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Clone.cs b/src/Commands/Clone.cs
index a6228e20..a8709138 100644
--- a/src/Commands/Clone.cs
+++ b/src/Commands/Clone.cs
@@ -1,17 +1,23 @@
using System;
-namespace SourceGit.Commands {
- public class Clone : Command {
- private Action _notifyProgress;
+namespace SourceGit.Commands
+{
+ public class Clone : Command
+ {
+ private readonly Action _notifyProgress;
- public Clone(string ctx, string path, string url, string localName, string sshKey, string extraArgs, Action ouputHandler) {
+ public Clone(string ctx, string path, string url, string localName, string sshKey, string extraArgs, Action ouputHandler)
+ {
Context = ctx;
WorkingDirectory = path;
TraitErrorAsOutput = true;
- if (string.IsNullOrEmpty(sshKey)) {
+ if (string.IsNullOrEmpty(sshKey))
+ {
Args = "-c credential.helper=manager ";
- } else {
+ }
+ else
+ {
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
}
@@ -24,8 +30,9 @@ namespace SourceGit.Commands {
_notifyProgress = ouputHandler;
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_notifyProgress?.Invoke(line);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs
index cf79841d..2fa42b1a 100644
--- a/src/Commands/Command.cs
+++ b/src/Commands/Command.cs
@@ -1,17 +1,22 @@
-using Avalonia.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class Command {
- public class CancelToken {
+using Avalonia.Threading;
+
+namespace SourceGit.Commands
+{
+ public partial class Command
+ {
+ public class CancelToken
+ {
public bool Requested { get; set; } = false;
}
- public class ReadToEndResult {
+ public class ReadToEndResult
+ {
public bool IsSuccess { get; set; }
public string StdOut { get; set; }
public string StdErr { get; set; }
@@ -24,7 +29,8 @@ namespace SourceGit.Commands {
public bool RaiseError { get; set; } = true;
public bool TraitErrorAsOutput { get; set; } = false;
- public bool Exec() {
+ public bool Exec()
+ {
var start = new ProcessStartInfo();
start.FileName = Native.OS.GitInstallPath;
start.Arguments = "--no-pager -c core.quotepath=off " + Args;
@@ -41,8 +47,10 @@ namespace SourceGit.Commands {
var proc = new Process() { StartInfo = start };
var isCancelled = false;
- proc.OutputDataReceived += (_, e) => {
- if (Cancel != null && Cancel.Requested) {
+ proc.OutputDataReceived += (_, e) =>
+ {
+ if (Cancel != null && Cancel.Requested)
+ {
isCancelled = true;
proc.CancelErrorRead();
proc.CancelOutputRead();
@@ -53,8 +61,10 @@ namespace SourceGit.Commands {
if (e.Data != null) OnReadline(e.Data);
};
- proc.ErrorDataReceived += (_, e) => {
- if (Cancel != null && Cancel.Requested) {
+ proc.ErrorDataReceived += (_, e) =>
+ {
+ if (Cancel != null && Cancel.Requested)
+ {
isCancelled = true;
proc.CancelErrorRead();
proc.CancelOutputRead();
@@ -70,15 +80,20 @@ namespace SourceGit.Commands {
if (e.Data.StartsWith("remote: Counting objects:", StringComparison.Ordinal)) return;
if (e.Data.StartsWith("remote: Compressing objects:", StringComparison.Ordinal)) return;
if (e.Data.StartsWith("Filtering content:", StringComparison.Ordinal)) return;
- if (_progressRegex.IsMatch(e.Data)) return;
+ if (_progressRegex().IsMatch(e.Data)) return;
errs.Add(e.Data);
};
- try {
+ try
+ {
proc.Start();
- } catch (Exception e) {
- if (RaiseError) {
- Dispatcher.UIThread.Invoke(() => {
+ }
+ catch (Exception e)
+ {
+ if (RaiseError)
+ {
+ Dispatcher.UIThread.Invoke(() =>
+ {
App.RaiseException(Context, e.Message);
});
}
@@ -92,19 +107,25 @@ namespace SourceGit.Commands {
int exitCode = proc.ExitCode;
proc.Close();
- if (!isCancelled && exitCode != 0 && errs.Count > 0) {
- if (RaiseError) {
- Dispatcher.UIThread.Invoke(() => {
+ if (!isCancelled && exitCode != 0 && errs.Count > 0)
+ {
+ if (RaiseError)
+ {
+ Dispatcher.UIThread.Invoke(() =>
+ {
App.RaiseException(Context, string.Join("\n", errs));
});
}
return false;
- } else {
+ }
+ else
+ {
return true;
}
}
- public ReadToEndResult ReadToEnd() {
+ public ReadToEndResult ReadToEnd()
+ {
var start = new ProcessStartInfo();
start.FileName = Native.OS.GitInstallPath;
start.Arguments = "--no-pager -c core.quotepath=off " + Args;
@@ -118,17 +139,22 @@ namespace SourceGit.Commands {
if (!string.IsNullOrEmpty(WorkingDirectory)) start.WorkingDirectory = WorkingDirectory;
var proc = new Process() { StartInfo = start };
- try {
+ try
+ {
proc.Start();
- } catch (Exception e) {
- return new ReadToEndResult() {
+ }
+ catch (Exception e)
+ {
+ return new ReadToEndResult()
+ {
IsSuccess = false,
StdOut = string.Empty,
StdErr = e.Message,
};
}
- var rs = new ReadToEndResult() {
+ var rs = new ReadToEndResult()
+ {
StdOut = proc.StandardOutput.ReadToEnd(),
StdErr = proc.StandardError.ReadToEnd(),
};
@@ -142,6 +168,7 @@ namespace SourceGit.Commands {
protected virtual void OnReadline(string line) { }
- private static readonly Regex _progressRegex = new Regex(@"\d+%");
+ [GeneratedRegex(@"\d+%")]
+ private static partial Regex _progressRegex();
}
}
\ No newline at end of file
diff --git a/src/Commands/Commit.cs b/src/Commands/Commit.cs
index 2733590c..faa941c3 100644
--- a/src/Commands/Commit.cs
+++ b/src/Commands/Commit.cs
@@ -1,8 +1,11 @@
using System.IO;
-namespace SourceGit.Commands {
- public class Commit : Command {
- public Commit(string repo, string message, bool amend, bool allowEmpty = false) {
+namespace SourceGit.Commands
+{
+ public class Commit : Command
+ {
+ public Commit(string repo, string message, bool amend, bool allowEmpty = false)
+ {
var file = Path.GetTempFileName();
File.WriteAllText(file, message);
@@ -13,4 +16,4 @@ namespace SourceGit.Commands {
if (allowEmpty) Args += " --allow-empty";
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/CompareRevisions.cs b/src/Commands/CompareRevisions.cs
index 2b10adab..7938df8e 100644
--- a/src/Commands/CompareRevisions.cs
+++ b/src/Commands/CompareRevisions.cs
@@ -1,38 +1,45 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class CompareRevisions : Command {
- private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$");
+namespace SourceGit.Commands
+{
+ public partial class CompareRevisions : Command
+ {
+ [GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
+ private static partial Regex REG_FORMAT();
- public CompareRevisions(string repo, string start, string end) {
+ public CompareRevisions(string repo, string start, string end)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"diff --name-status {start} {end}";
}
- public List Result() {
+ public List Result()
+ {
Exec();
_changes.Sort((l, r) => l.Path.CompareTo(r.Path));
return _changes;
}
- protected override void OnReadline(string line) {
- var match = REG_FORMAT.Match(line);
+ protected override void OnReadline(string line)
+ {
+ var match = REG_FORMAT().Match(line);
if (!match.Success) return;
var change = new Models.Change() { Path = match.Groups[2].Value };
var status = match.Groups[1].Value;
- switch (status[0]) {
- case 'M': change.Set(Models.ChangeState.Modified); _changes.Add(change); break;
- case 'A': change.Set(Models.ChangeState.Added); _changes.Add(change); break;
- case 'D': change.Set(Models.ChangeState.Deleted); _changes.Add(change); break;
- case 'R': change.Set(Models.ChangeState.Renamed); _changes.Add(change); break;
- case 'C': change.Set(Models.ChangeState.Copied); _changes.Add(change); break;
+ switch (status[0])
+ {
+ case 'M': change.Set(Models.ChangeState.Modified); _changes.Add(change); break;
+ case 'A': change.Set(Models.ChangeState.Added); _changes.Add(change); break;
+ case 'D': change.Set(Models.ChangeState.Deleted); _changes.Add(change); break;
+ case 'R': change.Set(Models.ChangeState.Renamed); _changes.Add(change); break;
+ case 'C': change.Set(Models.ChangeState.Copied); _changes.Add(change); break;
}
}
- private List _changes = new List();
+ private readonly List _changes = new List();
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Config.cs b/src/Commands/Config.cs
index 4a0ebb30..43723839 100644
--- a/src/Commands/Config.cs
+++ b/src/Commands/Config.cs
@@ -1,31 +1,41 @@
using System;
using System.Collections.Generic;
-namespace SourceGit.Commands {
- public class Config : Command {
- public Config(string repository) {
+namespace SourceGit.Commands
+{
+ public class Config : Command
+ {
+ public Config(string repository)
+ {
WorkingDirectory = repository;
Context = repository;
RaiseError = false;
}
- public Dictionary ListAll() {
+ public Dictionary ListAll()
+ {
Args = "config -l";
var output = ReadToEnd();
var rs = new Dictionary();
- if (output.IsSuccess) {
+ if (output.IsSuccess)
+ {
var lines = output.StdOut.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (var line in lines) {
- var idx = line.IndexOf('=');
- if (idx != -1) {
+ foreach (var line in lines)
+ {
+ var idx = line.IndexOf('=', StringComparison.Ordinal);
+ if (idx != -1)
+ {
var key = line.Substring(0, idx).Trim();
- var val = line.Substring(idx+1).Trim();
- if (rs.ContainsKey(key)) {
+ var val = line.Substring(idx + 1).Trim();
+ if (rs.ContainsKey(key))
+ {
rs[key] = val;
- } else {
+ }
+ else
+ {
rs.Add(key, val);
- }
+ }
}
}
}
@@ -33,22 +43,33 @@ namespace SourceGit.Commands {
return rs;
}
- public string Get(string key) {
+ public string Get(string key)
+ {
Args = $"config {key}";
return ReadToEnd().StdOut.Trim();
}
- public bool Set(string key, string value, bool allowEmpty = false) {
- if (!allowEmpty && string.IsNullOrWhiteSpace(value)) {
- if (string.IsNullOrEmpty(WorkingDirectory)) {
+ public bool Set(string key, string value, bool allowEmpty = false)
+ {
+ if (!allowEmpty && string.IsNullOrWhiteSpace(value))
+ {
+ if (string.IsNullOrEmpty(WorkingDirectory))
+ {
Args = $"config --global --unset {key}";
- } else {
+ }
+ else
+ {
Args = $"config --unset {key}";
}
- } else {
- if (string.IsNullOrWhiteSpace(WorkingDirectory)) {
+ }
+ else
+ {
+ if (string.IsNullOrWhiteSpace(WorkingDirectory))
+ {
Args = $"config --global {key} \"{value}\"";
- } else {
+ }
+ else
+ {
Args = $"config {key} \"{value}\"";
}
}
@@ -56,4 +77,4 @@ namespace SourceGit.Commands {
return Exec();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Diff.cs b/src/Commands/Diff.cs
index 611bb9a2..a35bd6e7 100644
--- a/src/Commands/Diff.cs
+++ b/src/Commands/Diff.cs
@@ -2,65 +2,89 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class Diff : Command {
- private static readonly Regex REG_INDICATOR = new Regex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@");
+namespace SourceGit.Commands
+{
+ public partial class Diff : Command
+ {
+ [GeneratedRegex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@")]
+ private static partial Regex REG_INDICATOR();
private static readonly string PREFIX_LFS_NEW = "+version https://git-lfs.github.com/spec/";
private static readonly string PREFIX_LFS_DEL = "-version https://git-lfs.github.com/spec/";
private static readonly string PREFIX_LFS_MODIFY = " version https://git-lfs.github.com/spec/";
- public Diff(string repo, Models.DiffOption opt) {
+ public Diff(string repo, Models.DiffOption opt)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"diff --ignore-cr-at-eol --unified=4 {opt}";
}
- public Models.DiffResult Result() {
+ public Models.DiffResult Result()
+ {
Exec();
- if (_result.IsBinary || _result.IsLFS) {
+ if (_result.IsBinary || _result.IsLFS)
+ {
_result.TextDiff = null;
- } else {
+ }
+ else
+ {
ProcessInlineHighlights();
- if (_result.TextDiff.Lines.Count == 0) {
+ if (_result.TextDiff.Lines.Count == 0)
+ {
_result.TextDiff = null;
- } else {
+ }
+ else
+ {
_result.TextDiff.MaxLineNumber = Math.Max(_newLine, _oldLine);
- }
+ }
}
return _result;
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
if (_result.IsBinary) return;
- if (_result.IsLFS) {
+ if (_result.IsLFS)
+ {
var ch = line[0];
- if (ch == '-') {
- line = line.Substring(1);
- if (line.StartsWith("oid sha256:")) {
- _result.LFSDiff.Old.Oid = line.Substring(11);
- } else if (line.StartsWith("size ")) {
- _result.LFSDiff.Old.Size = long.Parse(line.Substring(5));
+ if (ch == '-')
+ {
+ if (line.StartsWith("-oid sha256:", StringComparison.Ordinal))
+ {
+ _result.LFSDiff.Old.Oid = line.Substring(12);
}
- } else if (ch == '+') {
- line = line.Substring(1);
- if (line.StartsWith("oid sha256:")) {
- _result.LFSDiff.New.Oid = line.Substring(11);
- } else if (line.StartsWith("size ")) {
- _result.LFSDiff.New.Size = long.Parse(line.Substring(5));
+ else if (line.StartsWith("-size ", StringComparison.Ordinal))
+ {
+ _result.LFSDiff.Old.Size = long.Parse(line.Substring(6));
}
- } else if (line.StartsWith(" size ")) {
+ }
+ else if (ch == '+')
+ {
+ if (line.StartsWith("+oid sha256:", StringComparison.Ordinal))
+ {
+ _result.LFSDiff.New.Oid = line.Substring(12);
+ }
+ else if (line.StartsWith("+size ", StringComparison.Ordinal))
+ {
+ _result.LFSDiff.New.Size = long.Parse(line.Substring(6));
+ }
+ }
+ else if (line.StartsWith(" size ", StringComparison.Ordinal))
+ {
_result.LFSDiff.New.Size = _result.LFSDiff.Old.Size = long.Parse(line.Substring(6));
}
return;
}
- if (_result.TextDiff.Lines.Count == 0) {
- var match = REG_INDICATOR.Match(line);
- if (!match.Success) {
+ if (_result.TextDiff.Lines.Count == 0)
+ {
+ var match = REG_INDICATOR().Match(line);
+ if (!match.Success)
+ {
if (line.StartsWith("Binary", StringComparison.Ordinal)) _result.IsBinary = true;
return;
}
@@ -68,8 +92,11 @@ namespace SourceGit.Commands {
_oldLine = int.Parse(match.Groups[1].Value);
_newLine = int.Parse(match.Groups[2].Value);
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
- } else {
- if (line.Length == 0) {
+ }
+ else
+ {
+ if (line.Length == 0)
+ {
ProcessInlineHighlights();
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Normal, "", _oldLine, _newLine));
_oldLine++;
@@ -78,8 +105,10 @@ namespace SourceGit.Commands {
}
var ch = line[0];
- if (ch == '-') {
- if (_oldLine == 1 && _newLine == 0 && line.StartsWith(PREFIX_LFS_DEL, StringComparison.Ordinal)) {
+ if (ch == '-')
+ {
+ if (_oldLine == 1 && _newLine == 0 && line.StartsWith(PREFIX_LFS_DEL, StringComparison.Ordinal))
+ {
_result.IsLFS = true;
_result.LFSDiff = new Models.LFSDiff();
return;
@@ -87,8 +116,11 @@ namespace SourceGit.Commands {
_deleted.Add(new Models.TextDiffLine(Models.TextDiffLineType.Deleted, line.Substring(1), _oldLine, 0));
_oldLine++;
- } else if (ch == '+') {
- if (_oldLine == 0 && _newLine == 1 && line.StartsWith(PREFIX_LFS_NEW, StringComparison.Ordinal)) {
+ }
+ else if (ch == '+')
+ {
+ if (_oldLine == 0 && _newLine == 1 && line.StartsWith(PREFIX_LFS_NEW, StringComparison.Ordinal))
+ {
_result.IsLFS = true;
_result.LFSDiff = new Models.LFSDiff();
return;
@@ -96,15 +128,21 @@ namespace SourceGit.Commands {
_added.Add(new Models.TextDiffLine(Models.TextDiffLineType.Added, line.Substring(1), 0, _newLine));
_newLine++;
- } else if (ch != '\\') {
+ }
+ else if (ch != '\\')
+ {
ProcessInlineHighlights();
- var match = REG_INDICATOR.Match(line);
- if (match.Success) {
+ var match = REG_INDICATOR().Match(line);
+ if (match.Success)
+ {
_oldLine = int.Parse(match.Groups[1].Value);
_newLine = int.Parse(match.Groups[2].Value);
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
- } else {
- if (_oldLine == 1 && _newLine == 1 && line.StartsWith(PREFIX_LFS_MODIFY, StringComparison.Ordinal)) {
+ }
+ else
+ {
+ if (_oldLine == 1 && _newLine == 1 && line.StartsWith(PREFIX_LFS_MODIFY, StringComparison.Ordinal))
+ {
_result.IsLFS = true;
_result.LFSDiff = new Models.LFSDiff();
return;
@@ -118,10 +156,14 @@ namespace SourceGit.Commands {
}
}
- private void ProcessInlineHighlights() {
- if (_deleted.Count > 0) {
- if (_added.Count == _deleted.Count) {
- for (int i = _added.Count - 1; i >= 0; i--) {
+ private void ProcessInlineHighlights()
+ {
+ if (_deleted.Count > 0)
+ {
+ if (_added.Count == _deleted.Count)
+ {
+ for (int i = _added.Count - 1; i >= 0; i--)
+ {
var left = _deleted[i];
var right = _added[i];
@@ -130,12 +172,15 @@ namespace SourceGit.Commands {
var chunks = Models.TextInlineChange.Compare(left.Content, right.Content);
if (chunks.Count > 4) continue;
- foreach (var chunk in chunks) {
- if (chunk.DeletedCount > 0) {
+ foreach (var chunk in chunks)
+ {
+ if (chunk.DeletedCount > 0)
+ {
left.Highlights.Add(new Models.TextInlineRange(chunk.DeletedStart, chunk.DeletedCount));
}
- if (chunk.AddedCount > 0) {
+ if (chunk.AddedCount > 0)
+ {
right.Highlights.Add(new Models.TextInlineRange(chunk.AddedStart, chunk.AddedCount));
}
}
@@ -146,16 +191,17 @@ namespace SourceGit.Commands {
_deleted.Clear();
}
- if (_added.Count > 0) {
+ if (_added.Count > 0)
+ {
_result.TextDiff.Lines.AddRange(_added);
_added.Clear();
}
}
- private Models.DiffResult _result = new Models.DiffResult() { TextDiff = new Models.TextDiff() };
- private List _deleted = new List();
- private List _added = new List();
+ private readonly Models.DiffResult _result = new Models.DiffResult() { TextDiff = new Models.TextDiff() };
+ private readonly List _deleted = new List();
+ private readonly List _added = new List();
private int _oldLine = 0;
private int _newLine = 0;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Discard.cs b/src/Commands/Discard.cs
index 95f118c9..11f174d6 100644
--- a/src/Commands/Discard.cs
+++ b/src/Commands/Discard.cs
@@ -1,38 +1,50 @@
using System;
using System.Collections.Generic;
-namespace SourceGit.Commands {
- public static class Discard {
- public static void All(string repo) {
+namespace SourceGit.Commands
+{
+ public static class Discard
+ {
+ public static void All(string repo)
+ {
new Reset(repo, "HEAD", "--hard").Exec();
new Clean(repo).Exec();
}
- public static void ChangesInWorkTree(string repo, List changes) {
+ public static void ChangesInWorkTree(string repo, List changes)
+ {
var needClean = new List();
var needCheckout = new List();
- foreach (var c in changes) {
- if (c.WorkTree == Models.ChangeState.Untracked || c.WorkTree == Models.ChangeState.Added) {
+ foreach (var c in changes)
+ {
+ if (c.WorkTree == Models.ChangeState.Untracked || c.WorkTree == Models.ChangeState.Added)
+ {
needClean.Add(c.Path);
- } else {
+ }
+ else
+ {
needCheckout.Add(c.Path);
}
}
- for (int i = 0; i < needClean.Count; i += 10) {
+ for (int i = 0; i < needClean.Count; i += 10)
+ {
var count = Math.Min(10, needClean.Count - i);
new Clean(repo, needClean.GetRange(i, count)).Exec();
}
- for (int i = 0; i < needCheckout.Count; i += 10) {
+ for (int i = 0; i < needCheckout.Count; i += 10)
+ {
var count = Math.Min(10, needCheckout.Count - i);
new Checkout(repo).Files(needCheckout.GetRange(i, count));
}
}
- public static void ChangesInStaged(string repo, List changes) {
- for (int i = 0; i < changes.Count; i += 10) {
+ public static void ChangesInStaged(string repo, List changes)
+ {
+ for (int i = 0; i < changes.Count; i += 10)
+ {
var count = Math.Min(10, changes.Count - i);
var files = new List();
for (int j = 0; j < count; j++) files.Add(changes[i + j].Path);
@@ -40,4 +52,4 @@ namespace SourceGit.Commands {
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs
index 1c5acebb..3b068d2d 100644
--- a/src/Commands/Fetch.cs
+++ b/src/Commands/Fetch.cs
@@ -3,18 +3,24 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
-namespace SourceGit.Commands {
- public class Fetch : Command {
- public Fetch(string repo, string remote, bool prune, Action outputHandler) {
+namespace SourceGit.Commands
+{
+ public class Fetch : Command
+ {
+ public Fetch(string repo, string remote, bool prune, Action outputHandler)
+ {
_outputHandler = outputHandler;
WorkingDirectory = repo;
Context = repo;
TraitErrorAsOutput = true;
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
- if (!string.IsNullOrEmpty(sshKey)) {
+ if (!string.IsNullOrEmpty(sshKey))
+ {
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
- } else {
+ }
+ else
+ {
Args = "-c credential.helper=manager ";
}
@@ -25,59 +31,75 @@ namespace SourceGit.Commands {
AutoFetch.MarkFetched(repo);
}
- public Fetch(string repo, string remote, string localBranch, string remoteBranch, Action outputHandler) {
+ public Fetch(string repo, string remote, string localBranch, string remoteBranch, Action outputHandler)
+ {
_outputHandler = outputHandler;
WorkingDirectory = repo;
Context = repo;
TraitErrorAsOutput = true;
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
- if (!string.IsNullOrEmpty(sshKey)) {
+ if (!string.IsNullOrEmpty(sshKey))
+ {
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
- } else {
+ }
+ else
+ {
Args = "-c credential.helper=manager ";
}
Args += $"fetch --progress --verbose {remote} {remoteBranch}:{localBranch}";
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_outputHandler?.Invoke(line);
}
- private Action _outputHandler;
+ private readonly Action _outputHandler;
}
- public class AutoFetch {
- public static bool IsEnabled {
+ public class AutoFetch
+ {
+ public static bool IsEnabled
+ {
get;
set;
} = false;
- class Job {
+ class Job
+ {
public Fetch Cmd = null;
public DateTime NextRunTimepoint = DateTime.MinValue;
}
- static AutoFetch() {
- Task.Run(() => {
- while (true) {
- if (!IsEnabled) {
+ static AutoFetch()
+ {
+ Task.Run(() =>
+ {
+ while (true)
+ {
+ if (!IsEnabled)
+ {
Thread.Sleep(10000);
continue;
}
var now = DateTime.Now;
var uptodate = new List();
- lock (_lock) {
- foreach (var job in _jobs) {
- if (job.Value.NextRunTimepoint.Subtract(now).TotalSeconds <= 0) {
+ lock (_lock)
+ {
+ foreach (var job in _jobs)
+ {
+ if (job.Value.NextRunTimepoint.Subtract(now).TotalSeconds <= 0)
+ {
uptodate.Add(job.Value);
}
}
}
- foreach (var job in uptodate) {
+ foreach (var job in uptodate)
+ {
job.Cmd.Exec();
job.NextRunTimepoint = DateTime.Now.AddSeconds(_fetchInterval);
}
@@ -87,37 +109,48 @@ namespace SourceGit.Commands {
});
}
- public static void AddRepository(string repo) {
- var job = new Job {
+ public static void AddRepository(string repo)
+ {
+ var job = new Job
+ {
Cmd = new Fetch(repo, "--all", true, null) { RaiseError = false },
NextRunTimepoint = DateTime.Now.AddSeconds(_fetchInterval),
};
- lock (_lock) {
- if (_jobs.ContainsKey(repo)) {
+ lock (_lock)
+ {
+ if (_jobs.ContainsKey(repo))
+ {
_jobs[repo] = job;
- } else {
+ }
+ else
+ {
_jobs.Add(repo, job);
}
}
}
- public static void RemoveRepository(string repo) {
- lock (_lock) {
+ public static void RemoveRepository(string repo)
+ {
+ lock (_lock)
+ {
_jobs.Remove(repo);
}
}
- public static void MarkFetched(string repo) {
- lock (_lock) {
- if (_jobs.ContainsKey(repo)) {
+ public static void MarkFetched(string repo)
+ {
+ lock (_lock)
+ {
+ if (_jobs.ContainsKey(repo))
+ {
_jobs[repo].NextRunTimepoint = DateTime.Now.AddSeconds(_fetchInterval);
}
}
}
- private static Dictionary _jobs = new Dictionary();
- private static object _lock = new object();
- private static double _fetchInterval = 10 * 60;
+ private static readonly Dictionary _jobs = new Dictionary();
+ private static readonly object _lock = new object();
+ private static readonly double _fetchInterval = 10 * 60;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/FormatPatch.cs b/src/Commands/FormatPatch.cs
index c139c477..5310115c 100644
--- a/src/Commands/FormatPatch.cs
+++ b/src/Commands/FormatPatch.cs
@@ -1,9 +1,12 @@
-namespace SourceGit.Commands {
- public class FormatPatch : Command {
- public FormatPatch(string repo, string commit, string saveTo) {
+namespace SourceGit.Commands
+{
+ public class FormatPatch : Command
+ {
+ public FormatPatch(string repo, string commit, string saveTo)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"format-patch {commit} -1 -o \"{saveTo}\"";
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/GC.cs b/src/Commands/GC.cs
index 0c9d5761..a38f6147 100644
--- a/src/Commands/GC.cs
+++ b/src/Commands/GC.cs
@@ -1,8 +1,11 @@
using System;
-namespace SourceGit.Commands {
- public class GC : Command {
- public GC(string repo, Action outputHandler) {
+namespace SourceGit.Commands
+{
+ public class GC : Command
+ {
+ public GC(string repo, Action outputHandler)
+ {
_outputHandler = outputHandler;
WorkingDirectory = repo;
Context = repo;
@@ -10,10 +13,11 @@ namespace SourceGit.Commands {
Args = "gc";
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_outputHandler?.Invoke(line);
}
- private Action _outputHandler;
+ private readonly Action _outputHandler;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/GitFlow.cs b/src/Commands/GitFlow.cs
index 0d277f58..3a52ed83 100644
--- a/src/Commands/GitFlow.cs
+++ b/src/Commands/GitFlow.cs
@@ -1,14 +1,19 @@
-using Avalonia.Threading;
-using System.Collections.Generic;
+using System.Collections.Generic;
-namespace SourceGit.Commands {
- public class GitFlow : Command {
- public GitFlow(string repo) {
+using Avalonia.Threading;
+
+namespace SourceGit.Commands
+{
+ public class GitFlow : Command
+ {
+ public GitFlow(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
}
- public bool Init(List branches, string master, string develop, string feature, string release, string hotfix, string version) {
+ public bool Init(List branches, string master, string develop, string feature, string release, string hotfix, string version)
+ {
var current = branches.Find(x => x.IsCurrent);
var masterBranch = branches.Find(x => x.Name == master);
@@ -31,47 +36,53 @@ namespace SourceGit.Commands {
return Exec();
}
- public bool Start(Models.GitFlowBranchType type, string name) {
- switch (type) {
- case Models.GitFlowBranchType.Feature:
- Args = $"flow feature start {name}";
- break;
- case Models.GitFlowBranchType.Release:
- Args = $"flow release start {name}";
- break;
- case Models.GitFlowBranchType.Hotfix:
- Args = $"flow hotfix start {name}";
- break;
- default:
- Dispatcher.UIThread.Invoke(() => {
- App.RaiseException(Context, "Bad branch type!!!");
- });
- return false;
+ public bool Start(Models.GitFlowBranchType type, string name)
+ {
+ switch (type)
+ {
+ case Models.GitFlowBranchType.Feature:
+ Args = $"flow feature start {name}";
+ break;
+ case Models.GitFlowBranchType.Release:
+ Args = $"flow release start {name}";
+ break;
+ case Models.GitFlowBranchType.Hotfix:
+ Args = $"flow hotfix start {name}";
+ break;
+ default:
+ Dispatcher.UIThread.Invoke(() =>
+ {
+ App.RaiseException(Context, "Bad branch type!!!");
+ });
+ return false;
}
return Exec();
}
- public bool Finish(Models.GitFlowBranchType type, string name, bool keepBranch) {
+ public bool Finish(Models.GitFlowBranchType type, string name, bool keepBranch)
+ {
var option = keepBranch ? "-k" : string.Empty;
- switch (type) {
- case Models.GitFlowBranchType.Feature:
- Args = $"flow feature finish {option} {name}";
- break;
- case Models.GitFlowBranchType.Release:
- Args = $"flow release finish {option} {name} -m \"RELEASE_DONE\"";
- break;
- case Models.GitFlowBranchType.Hotfix:
- Args = $"flow hotfix finish {option} {name} -m \"HOTFIX_DONE\"";
- break;
- default:
- Dispatcher.UIThread.Invoke(() => {
- App.RaiseException(Context, "Bad branch type!!!");
- });
- return false;
+ switch (type)
+ {
+ case Models.GitFlowBranchType.Feature:
+ Args = $"flow feature finish {option} {name}";
+ break;
+ case Models.GitFlowBranchType.Release:
+ Args = $"flow release finish {option} {name} -m \"RELEASE_DONE\"";
+ break;
+ case Models.GitFlowBranchType.Hotfix:
+ Args = $"flow hotfix finish {option} {name} -m \"HOTFIX_DONE\"";
+ break;
+ default:
+ Dispatcher.UIThread.Invoke(() =>
+ {
+ App.RaiseException(Context, "Bad branch type!!!");
+ });
+ return false;
}
return Exec();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Init.cs b/src/Commands/Init.cs
index f009ebe0..f0c03149 100644
--- a/src/Commands/Init.cs
+++ b/src/Commands/Init.cs
@@ -1,9 +1,12 @@
-namespace SourceGit.Commands {
- public class Init : Command {
- public Init(string ctx, string dir) {
+namespace SourceGit.Commands
+{
+ public class Init : Command
+ {
+ public Init(string ctx, string dir)
+ {
Context = ctx;
WorkingDirectory = dir;
Args = "init -q";
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/IsBinary.cs b/src/Commands/IsBinary.cs
index d9096aa2..ef97eefc 100644
--- a/src/Commands/IsBinary.cs
+++ b/src/Commands/IsBinary.cs
@@ -1,18 +1,23 @@
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class IsBinary : Command {
- private static readonly Regex REG_TEST = new Regex(@"^\-\s+\-\s+.*$");
+namespace SourceGit.Commands
+{
+ public partial class IsBinary : Command
+ {
+ [GeneratedRegex(@"^\-\s+\-\s+.*$")]
+ private static partial Regex REG_TEST();
- public IsBinary(string repo, string commit, string path) {
+ public IsBinary(string repo, string commit, string path)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 {commit} --numstat -- \"{path}\"";
RaiseError = false;
}
- public bool Result() {
- return REG_TEST.IsMatch(ReadToEnd().StdOut);
+ public bool Result()
+ {
+ return REG_TEST().IsMatch(ReadToEnd().StdOut);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/IsLFSFiltered.cs b/src/Commands/IsLFSFiltered.cs
index 39e24654..33f9abfb 100644
--- a/src/Commands/IsLFSFiltered.cs
+++ b/src/Commands/IsLFSFiltered.cs
@@ -1,15 +1,19 @@
-namespace SourceGit.Commands {
- public class IsLFSFiltered : Command {
- public IsLFSFiltered(string repo, string path) {
+namespace SourceGit.Commands
+{
+ public class IsLFSFiltered : Command
+ {
+ public IsLFSFiltered(string repo, string path)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"check-attr -a -z \"{path}\"";
RaiseError = false;
}
- public bool Result() {
+ public bool Result()
+ {
var rs = ReadToEnd();
return rs.IsSuccess && rs.StdOut.Contains("filter\0lfs");
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/LFS.cs b/src/Commands/LFS.cs
index d632a25b..1b94ad75 100644
--- a/src/Commands/LFS.cs
+++ b/src/Commands/LFS.cs
@@ -1,10 +1,14 @@
using System;
using System.IO;
-namespace SourceGit.Commands {
- public class LFS {
- class PruneCmd : Command {
- public PruneCmd(string repo, Action onProgress) {
+namespace SourceGit.Commands
+{
+ public class LFS
+ {
+ class PruneCmd : Command
+ {
+ public PruneCmd(string repo, Action onProgress)
+ {
WorkingDirectory = repo;
Context = repo;
Args = "lfs prune";
@@ -12,18 +16,21 @@ namespace SourceGit.Commands {
_outputHandler = onProgress;
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_outputHandler?.Invoke(line);
}
- private Action _outputHandler;
+ private readonly Action _outputHandler;
}
- public LFS(string repo) {
+ public LFS(string repo)
+ {
_repo = repo;
}
- public bool IsEnabled() {
+ public bool IsEnabled()
+ {
var path = Path.Combine(_repo, ".git", "hooks", "pre-push");
if (!File.Exists(path)) return false;
@@ -31,10 +38,11 @@ namespace SourceGit.Commands {
return content.Contains("git lfs pre-push");
}
- public void Prune(Action outputHandler) {
+ public void Prune(Action outputHandler)
+ {
new PruneCmd(_repo, outputHandler).Exec();
}
- private string _repo;
+ private readonly string _repo;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Merge.cs b/src/Commands/Merge.cs
index 9854e8c5..6c3eb934 100644
--- a/src/Commands/Merge.cs
+++ b/src/Commands/Merge.cs
@@ -1,8 +1,11 @@
using System;
-namespace SourceGit.Commands {
- public class Merge : Command {
- public Merge(string repo, string source, string mode, Action outputHandler) {
+namespace SourceGit.Commands
+{
+ public class Merge : Command
+ {
+ public Merge(string repo, string source, string mode, Action outputHandler)
+ {
_outputHandler = outputHandler;
WorkingDirectory = repo;
Context = repo;
@@ -10,10 +13,11 @@ namespace SourceGit.Commands {
Args = $"merge --progress {source} {mode}";
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_outputHandler?.Invoke(line);
}
- private Action _outputHandler = null;
+ private readonly Action _outputHandler = null;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/MergeTool.cs b/src/Commands/MergeTool.cs
index d1857636..6701eb4b 100644
--- a/src/Commands/MergeTool.cs
+++ b/src/Commands/MergeTool.cs
@@ -1,20 +1,28 @@
-using Avalonia.Threading;
-using System.IO;
+using System.IO;
-namespace SourceGit.Commands {
- public static class MergeTool {
- public static bool OpenForMerge(string repo, string tool, string mergeCmd, string file) {
- if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(mergeCmd)) {
- Dispatcher.UIThread.Invoke(() => {
+using Avalonia.Threading;
+
+namespace SourceGit.Commands
+{
+ public static class MergeTool
+ {
+ public static bool OpenForMerge(string repo, string tool, string mergeCmd, string file)
+ {
+ if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(mergeCmd))
+ {
+ Dispatcher.UIThread.Invoke(() =>
+ {
App.RaiseException(repo, "Invalid external merge tool settings!");
});
return false;
}
- if (!File.Exists(tool)) {
- Dispatcher.UIThread.Invoke(() => {
+ if (!File.Exists(tool))
+ {
+ Dispatcher.UIThread.Invoke(() =>
+ {
App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!");
- });
+ });
return false;
}
@@ -25,16 +33,21 @@ namespace SourceGit.Commands {
return cmd.Exec();
}
- public static bool OpenForDiff(string repo, string tool, string diffCmd, Models.DiffOption option) {
- if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(diffCmd)) {
- Dispatcher.UIThread.Invoke(() => {
+ public static bool OpenForDiff(string repo, string tool, string diffCmd, Models.DiffOption option)
+ {
+ if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(diffCmd))
+ {
+ Dispatcher.UIThread.Invoke(() =>
+ {
App.RaiseException(repo, "Invalid external merge tool settings!");
- });
+ });
return false;
}
- if (!File.Exists(tool)) {
- Dispatcher.UIThread.Invoke(() => {
+ if (!File.Exists(tool))
+ {
+ Dispatcher.UIThread.Invoke(() =>
+ {
App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!");
});
return false;
@@ -42,9 +55,9 @@ namespace SourceGit.Commands {
var cmd = new Command();
cmd.WorkingDirectory = repo;
- cmd.RaiseError = false;
+ cmd.RaiseError = false;
cmd.Args = $"-c difftool.sourcegit.cmd=\"\\\"{tool}\\\" {diffCmd}\" difftool --tool=sourcegit --no-prompt {option}";
return cmd.Exec();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Pull.cs b/src/Commands/Pull.cs
index f9112206..1381e0fe 100644
--- a/src/Commands/Pull.cs
+++ b/src/Commands/Pull.cs
@@ -1,17 +1,23 @@
using System;
-namespace SourceGit.Commands {
- public class Pull : Command {
- public Pull(string repo, string remote, string branch, bool useRebase, Action outputHandler) {
+namespace SourceGit.Commands
+{
+ public class Pull : Command
+ {
+ public Pull(string repo, string remote, string branch, bool useRebase, Action outputHandler)
+ {
_outputHandler = outputHandler;
WorkingDirectory = repo;
Context = repo;
TraitErrorAsOutput = true;
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
- if (!string.IsNullOrEmpty(sshKey)) {
+ if (!string.IsNullOrEmpty(sshKey))
+ {
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
- } else {
+ }
+ else
+ {
Args = "-c credential.helper=manager ";
}
@@ -20,10 +26,11 @@ namespace SourceGit.Commands {
Args += $"{remote} {branch}";
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_outputHandler?.Invoke(line);
}
- private Action _outputHandler;
+ private readonly Action _outputHandler;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Push.cs b/src/Commands/Push.cs
index 8839666b..a15591f3 100644
--- a/src/Commands/Push.cs
+++ b/src/Commands/Push.cs
@@ -1,17 +1,23 @@
using System;
-namespace SourceGit.Commands {
- public class Push : Command {
- public Push(string repo, string local, string remote, string remoteBranch, bool withTags, bool force, bool track, Action onProgress) {
+namespace SourceGit.Commands
+{
+ public class Push : Command
+ {
+ public Push(string repo, string local, string remote, string remoteBranch, bool withTags, bool force, bool track, Action onProgress)
+ {
WorkingDirectory = repo;
Context = repo;
TraitErrorAsOutput = true;
_outputHandler = onProgress;
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
- if (!string.IsNullOrEmpty(sshKey)) {
+ if (!string.IsNullOrEmpty(sshKey))
+ {
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
- } else {
+ }
+ else
+ {
Args = "-c credential.helper=manager ";
}
@@ -30,29 +36,37 @@ namespace SourceGit.Commands {
///
///
///
- public Push(string repo, string remote, string branch) {
+ public Push(string repo, string remote, string branch)
+ {
WorkingDirectory = repo;
Context = repo;
TraitErrorAsOutput = true;
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
- if (!string.IsNullOrEmpty(sshKey)) {
+ if (!string.IsNullOrEmpty(sshKey))
+ {
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
- } else {
+ }
+ else
+ {
Args = "-c credential.helper=manager ";
}
Args += $"push {remote} --delete {branch}";
}
- public Push(string repo, string remote, string tag, bool isDelete) {
+ public Push(string repo, string remote, string tag, bool isDelete)
+ {
WorkingDirectory = repo;
Context = repo;
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
- if (!string.IsNullOrEmpty(sshKey)) {
+ if (!string.IsNullOrEmpty(sshKey))
+ {
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
- } else {
+ }
+ else
+ {
Args = "-c credential.helper=manager ";
}
@@ -61,10 +75,11 @@ namespace SourceGit.Commands {
Args += $"{remote} refs/tags/{tag}";
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_outputHandler?.Invoke(line);
}
- private Action _outputHandler = null;
+ private readonly Action _outputHandler = null;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryBranches.cs b/src/Commands/QueryBranches.cs
index 630ba8c3..3b993831 100644
--- a/src/Commands/QueryBranches.cs
+++ b/src/Commands/QueryBranches.cs
@@ -2,26 +2,37 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QueryBranches : Command {
+namespace SourceGit.Commands
+{
+ public partial class QueryBranches : Command
+ {
private static readonly string PREFIX_LOCAL = "refs/heads/";
private static readonly string PREFIX_REMOTE = "refs/remotes/";
- private static readonly Regex REG_AHEAD_BEHIND = new Regex(@"^(\d+)\s(\d+)$");
- public QueryBranches(string repo) {
+ [GeneratedRegex(@"^(\d+)\s(\d+)$")]
+ private static partial Regex REG_AHEAD_BEHIND();
+
+ public QueryBranches(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
Args = "branch -l --all -v --format=\"%(refname)$%(objectname)$%(HEAD)$%(upstream)$%(upstream:trackshort)\"";
}
- public List Result() {
+ public List Result()
+ {
Exec();
- foreach (var b in _branches) {
- if (b.IsLocal && !string.IsNullOrEmpty(b.UpstreamTrackStatus)) {
- if (b.UpstreamTrackStatus == "=") {
+ foreach (var b in _branches)
+ {
+ if (b.IsLocal && !string.IsNullOrEmpty(b.UpstreamTrackStatus))
+ {
+ if (b.UpstreamTrackStatus == "=")
+ {
b.UpstreamTrackStatus = string.Empty;
- } else {
+ }
+ else
+ {
b.UpstreamTrackStatus = ParseTrackStatus(b.Name, b.Upstream);
}
}
@@ -30,26 +41,32 @@ namespace SourceGit.Commands {
return _branches;
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
var parts = line.Split('$');
if (parts.Length != 5) return;
var branch = new Models.Branch();
var refName = parts[0];
- if (refName.EndsWith("/HEAD")) return;
+ if (refName.EndsWith("/HEAD", StringComparison.Ordinal)) return;
- if (refName.StartsWith(PREFIX_LOCAL, StringComparison.Ordinal)) {
+ if (refName.StartsWith(PREFIX_LOCAL, StringComparison.Ordinal))
+ {
branch.Name = refName.Substring(PREFIX_LOCAL.Length);
branch.IsLocal = true;
- } else if (refName.StartsWith(PREFIX_REMOTE, StringComparison.Ordinal)) {
+ }
+ else if (refName.StartsWith(PREFIX_REMOTE, StringComparison.Ordinal))
+ {
var name = refName.Substring(PREFIX_REMOTE.Length);
- var shortNameIdx = name.IndexOf('/');
+ var shortNameIdx = name.IndexOf('/', StringComparison.Ordinal);
if (shortNameIdx < 0) return;
branch.Remote = name.Substring(0, shortNameIdx);
branch.Name = name.Substring(branch.Remote.Length + 1);
branch.IsLocal = false;
- } else {
+ }
+ else
+ {
branch.Name = refName;
branch.IsLocal = true;
}
@@ -62,7 +79,8 @@ namespace SourceGit.Commands {
_branches.Add(branch);
}
- private string ParseTrackStatus(string local, string upstream) {
+ private string ParseTrackStatus(string local, string upstream)
+ {
var cmd = new Command();
cmd.WorkingDirectory = WorkingDirectory;
cmd.Context = Context;
@@ -71,7 +89,7 @@ namespace SourceGit.Commands {
var rs = cmd.ReadToEnd();
if (!rs.IsSuccess) return string.Empty;
- var match = REG_AHEAD_BEHIND.Match(rs.StdOut);
+ var match = REG_AHEAD_BEHIND().Match(rs.StdOut);
if (!match.Success) return string.Empty;
var ahead = int.Parse(match.Groups[1].Value);
@@ -82,6 +100,6 @@ namespace SourceGit.Commands {
return track.Trim();
}
- private List _branches = new List();
+ private readonly List _branches = new List();
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryCommitChanges.cs b/src/Commands/QueryCommitChanges.cs
index 7b252efd..b2edfdff 100644
--- a/src/Commands/QueryCommitChanges.cs
+++ b/src/Commands/QueryCommitChanges.cs
@@ -1,38 +1,45 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QueryCommitChanges : Command {
- private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$");
+namespace SourceGit.Commands
+{
+ public partial class QueryCommitChanges : Command
+ {
+ [GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
+ private static partial Regex REG_FORMAT();
- public QueryCommitChanges(string repo, string commitSHA) {
+ public QueryCommitChanges(string repo, string commitSHA)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"show --name-status {commitSHA}";
}
- public List Result() {
+ public List Result()
+ {
Exec();
_changes.Sort((l, r) => l.Path.CompareTo(r.Path));
return _changes;
}
- protected override void OnReadline(string line) {
- var match = REG_FORMAT.Match(line);
+ protected override void OnReadline(string line)
+ {
+ var match = REG_FORMAT().Match(line);
if (!match.Success) return;
var change = new Models.Change() { Path = match.Groups[2].Value };
var status = match.Groups[1].Value;
- switch (status[0]) {
- case 'M': change.Set(Models.ChangeState.Modified); _changes.Add(change); break;
- case 'A': change.Set(Models.ChangeState.Added); _changes.Add(change); break;
- case 'D': change.Set(Models.ChangeState.Deleted); _changes.Add(change); break;
- case 'R': change.Set(Models.ChangeState.Renamed); _changes.Add(change); break;
- case 'C': change.Set(Models.ChangeState.Copied); _changes.Add(change); break;
+ switch (status[0])
+ {
+ case 'M': change.Set(Models.ChangeState.Modified); _changes.Add(change); break;
+ case 'A': change.Set(Models.ChangeState.Added); _changes.Add(change); break;
+ case 'D': change.Set(Models.ChangeState.Deleted); _changes.Add(change); break;
+ case 'R': change.Set(Models.ChangeState.Renamed); _changes.Add(change); break;
+ case 'C': change.Set(Models.ChangeState.Copied); _changes.Add(change); break;
}
}
- private List _changes = new List();
+ private readonly List _changes = new List();
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryCommits.cs b/src/Commands/QueryCommits.cs
index 0d6c31e2..e8c421f9 100644
--- a/src/Commands/QueryCommits.cs
+++ b/src/Commands/QueryCommits.cs
@@ -1,49 +1,61 @@
using System;
using System.Collections.Generic;
-namespace SourceGit.Commands {
- public class QueryCommits : Command {
+namespace SourceGit.Commands
+{
+ public class QueryCommits : Command
+ {
private static readonly string GPGSIG_START = "gpgsig -----BEGIN PGP SIGNATURE-----";
private static readonly string GPGSIG_END = " -----END PGP SIGNATURE-----";
- private List commits = new List();
+ private readonly List commits = new List();
private Models.Commit current = null;
private bool isSkipingGpgsig = false;
private bool isHeadFounded = false;
- private bool findFirstMerged = true;
+ private readonly bool findFirstMerged = true;
- public QueryCommits(string repo, string limits, bool needFindHead = true) {
+ public QueryCommits(string repo, string limits, bool needFindHead = true)
+ {
WorkingDirectory = repo;
Args = "log --date-order --decorate=full --pretty=raw " + limits;
findFirstMerged = needFindHead;
}
- public List Result() {
+ public List Result()
+ {
Exec();
- if (current != null) {
+ if (current != null)
+ {
current.Message = current.Message.Trim();
commits.Add(current);
}
- if (findFirstMerged && !isHeadFounded && commits.Count > 0) {
+ if (findFirstMerged && !isHeadFounded && commits.Count > 0)
+ {
MarkFirstMerged();
}
return commits;
}
- protected override void OnReadline(string line) {
- if (isSkipingGpgsig) {
+ protected override void OnReadline(string line)
+ {
+ if (isSkipingGpgsig)
+ {
if (line.StartsWith(GPGSIG_END, StringComparison.Ordinal)) isSkipingGpgsig = false;
return;
- } else if (line.StartsWith(GPGSIG_START, StringComparison.Ordinal)) {
+ }
+ else if (line.StartsWith(GPGSIG_START, StringComparison.Ordinal))
+ {
isSkipingGpgsig = true;
return;
}
- if (line.StartsWith("commit ", StringComparison.Ordinal)) {
- if (current != null) {
+ if (line.StartsWith("commit ", StringComparison.Ordinal))
+ {
+ if (current != null)
+ {
current.Message = current.Message.Trim();
commits.Add(current);
}
@@ -51,10 +63,13 @@ namespace SourceGit.Commands {
current = new Models.Commit();
line = line.Substring(7);
- var decoratorStart = line.IndexOf('(');
- if (decoratorStart < 0) {
+ var decoratorStart = line.IndexOf('(', StringComparison.Ordinal);
+ if (decoratorStart < 0)
+ {
current.SHA = line.Trim();
- } else {
+ }
+ else
+ {
current.SHA = line.Substring(0, decoratorStart).Trim();
current.IsMerged = ParseDecorators(current.Decorators, line.Substring(decoratorStart + 1));
if (!isHeadFounded) isHeadFounded = current.IsMerged;
@@ -65,65 +80,95 @@ namespace SourceGit.Commands {
if (current == null) return;
- if (line.StartsWith("tree ", StringComparison.Ordinal)) {
+ if (line.StartsWith("tree ", StringComparison.Ordinal))
+ {
return;
- } else if (line.StartsWith("parent ", StringComparison.Ordinal)) {
+ }
+ else if (line.StartsWith("parent ", StringComparison.Ordinal))
+ {
current.Parents.Add(line.Substring("parent ".Length));
- } else if (line.StartsWith("author ", StringComparison.Ordinal)) {
+ }
+ else if (line.StartsWith("author ", StringComparison.Ordinal))
+ {
Models.User user = Models.User.Invalid;
ulong time = 0;
Models.Commit.ParseUserAndTime(line.Substring(7), ref user, ref time);
current.Author = user;
current.AuthorTime = time;
- } else if (line.StartsWith("committer ", StringComparison.Ordinal)) {
+ }
+ else if (line.StartsWith("committer ", StringComparison.Ordinal))
+ {
Models.User user = Models.User.Invalid;
ulong time = 0;
Models.Commit.ParseUserAndTime(line.Substring(10), ref user, ref time);
current.Committer = user;
current.CommitterTime = time;
- } else if (string.IsNullOrEmpty(current.Subject)) {
+ }
+ else if (string.IsNullOrEmpty(current.Subject))
+ {
current.Subject = line.Trim();
- } else {
+ }
+ else
+ {
current.Message += (line.Trim() + "\n");
}
}
- private bool ParseDecorators(List decorators, string data) {
+ private bool ParseDecorators(List decorators, string data)
+ {
bool isHeadOfCurrent = false;
var subs = data.Split(new char[] { ',', ')', '(' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (var sub in subs) {
+ foreach (var sub in subs)
+ {
var d = sub.Trim();
- if (d.StartsWith("tag: refs/tags/", StringComparison.Ordinal)) {
- decorators.Add(new Models.Decorator() {
+ if (d.StartsWith("tag: refs/tags/", StringComparison.Ordinal))
+ {
+ decorators.Add(new Models.Decorator()
+ {
Type = Models.DecoratorType.Tag,
Name = d.Substring(15).Trim(),
});
- } else if (d.EndsWith("/HEAD", StringComparison.Ordinal)) {
+ }
+ else if (d.EndsWith("/HEAD", StringComparison.Ordinal))
+ {
continue;
- } else if (d.StartsWith("HEAD -> refs/heads/", StringComparison.Ordinal)) {
+ }
+ else if (d.StartsWith("HEAD -> refs/heads/", StringComparison.Ordinal))
+ {
isHeadOfCurrent = true;
- decorators.Add(new Models.Decorator() {
+ decorators.Add(new Models.Decorator()
+ {
Type = Models.DecoratorType.CurrentBranchHead,
Name = d.Substring(19).Trim(),
});
- } else if (d.StartsWith("refs/heads/", StringComparison.Ordinal)) {
- decorators.Add(new Models.Decorator() {
+ }
+ else if (d.StartsWith("refs/heads/", StringComparison.Ordinal))
+ {
+ decorators.Add(new Models.Decorator()
+ {
Type = Models.DecoratorType.LocalBranchHead,
Name = d.Substring(11).Trim(),
});
- } else if (d.StartsWith("refs/remotes/", StringComparison.Ordinal)) {
- decorators.Add(new Models.Decorator() {
+ }
+ else if (d.StartsWith("refs/remotes/", StringComparison.Ordinal))
+ {
+ decorators.Add(new Models.Decorator()
+ {
Type = Models.DecoratorType.RemoteBranchHead,
Name = d.Substring(13).Trim(),
});
}
}
- decorators.Sort((l, r) => {
- if (l.Type != r.Type) {
+ decorators.Sort((l, r) =>
+ {
+ if (l.Type != r.Type)
+ {
return (int)l.Type - (int)r.Type;
- } else {
+ }
+ else
+ {
return l.Name.CompareTo(r.Name);
}
});
@@ -131,7 +176,8 @@ namespace SourceGit.Commands {
return isHeadOfCurrent;
}
- private void MarkFirstMerged() {
+ private void MarkFirstMerged()
+ {
Args = $"log --since=\"{commits[commits.Count - 1].CommitterTimeStr}\" --format=\"%H\"";
var rs = ReadToEnd();
@@ -141,12 +187,14 @@ namespace SourceGit.Commands {
var set = new HashSet();
foreach (var sha in shas) set.Add(sha);
- foreach (var c in commits) {
- if (set.Contains(c.SHA)) {
+ foreach (var c in commits)
+ {
+ if (set.Contains(c.SHA))
+ {
c.IsMerged = true;
break;
}
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryFileContent.cs b/src/Commands/QueryFileContent.cs
index 172134c5..e0898105 100644
--- a/src/Commands/QueryFileContent.cs
+++ b/src/Commands/QueryFileContent.cs
@@ -1,23 +1,28 @@
using System.Text;
-namespace SourceGit.Commands {
- public class QueryFileContent : Command {
- public QueryFileContent(string repo, string revision, string file) {
+namespace SourceGit.Commands
+{
+ public class QueryFileContent : Command
+ {
+ public QueryFileContent(string repo, string revision, string file)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"show {revision}:\"{file}\"";
}
- public string Result() {
+ public string Result()
+ {
Exec();
return _builder.ToString();
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_builder.Append(line);
_builder.Append('\n');
}
- private StringBuilder _builder = new StringBuilder();
+ private readonly StringBuilder _builder = new StringBuilder();
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryFileSize.cs b/src/Commands/QueryFileSize.cs
index e16bf9e6..c2c031c6 100644
--- a/src/Commands/QueryFileSize.cs
+++ b/src/Commands/QueryFileSize.cs
@@ -1,22 +1,30 @@
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QueryFileSize : Command {
- private static readonly Regex REG_FORMAT = new Regex(@"^\d+\s+\w+\s+[0-9a-f]+\s+(\d+)\s+.*$");
+namespace SourceGit.Commands
+{
+ public partial class QueryFileSize : Command
+ {
- public QueryFileSize(string repo, string file, string revision) {
+ [GeneratedRegex(@"^\d+\s+\w+\s+[0-9a-f]+\s+(\d+)\s+.*$")]
+ private static partial Regex REG_FORMAT();
+
+ public QueryFileSize(string repo, string file, string revision)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"ls-tree {revision} -l -- {file}";
}
- public long Result() {
+ public long Result()
+ {
if (_result != 0) return _result;
var rs = ReadToEnd();
- if (rs.IsSuccess) {
- var match = REG_FORMAT.Match(rs.StdOut);
- if (match.Success) {
+ if (rs.IsSuccess)
+ {
+ var match = REG_FORMAT().Match(rs.StdOut);
+ if (match.Success)
+ {
return long.Parse(match.Groups[1].Value);
}
}
@@ -24,6 +32,6 @@ namespace SourceGit.Commands {
return 0;
}
- private long _result = 0;
+ private readonly long _result = 0;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryGitDir.cs b/src/Commands/QueryGitDir.cs
index dcdc216b..f7ed0cc0 100644
--- a/src/Commands/QueryGitDir.cs
+++ b/src/Commands/QueryGitDir.cs
@@ -1,14 +1,18 @@
using System.IO;
-namespace SourceGit.Commands {
- public class QueryGitDir : Command {
- public QueryGitDir(string workDir) {
+namespace SourceGit.Commands
+{
+ public class QueryGitDir : Command
+ {
+ public QueryGitDir(string workDir)
+ {
WorkingDirectory = workDir;
Args = "rev-parse --git-dir";
RaiseError = false;
}
- public string Result() {
+ public string Result()
+ {
var rs = ReadToEnd().StdOut;
if (string.IsNullOrEmpty(rs)) return null;
@@ -17,4 +21,4 @@ namespace SourceGit.Commands {
return Path.GetFullPath(Path.Combine(WorkingDirectory, rs));
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryLocalChanges.cs b/src/Commands/QueryLocalChanges.cs
index 260885d5..943f3a72 100644
--- a/src/Commands/QueryLocalChanges.cs
+++ b/src/Commands/QueryLocalChanges.cs
@@ -2,65 +2,72 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QueryLocalChanges : Command {
- private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$");
- private static readonly string[] UNTRACKED = [ "no", "all" ];
+namespace SourceGit.Commands
+{
+ public partial class QueryLocalChanges : Command
+ {
+ [GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
+ private static partial Regex REG_FORMAT();
+ private static readonly string[] UNTRACKED = ["no", "all"];
- public QueryLocalChanges(string repo, bool includeUntracked = true) {
+ public QueryLocalChanges(string repo, bool includeUntracked = true)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"status -u{UNTRACKED[includeUntracked ? 1 : 0]} --ignore-submodules=dirty --porcelain";
}
- public List Result() {
+ public List Result()
+ {
Exec();
return _changes;
}
- protected override void OnReadline(string line) {
- var match = REG_FORMAT.Match(line);
+ protected override void OnReadline(string line)
+ {
+ var match = REG_FORMAT().Match(line);
if (!match.Success) return;
if (line.EndsWith("/", StringComparison.Ordinal)) return; // Ignore changes with git-worktree
var change = new Models.Change() { Path = match.Groups[2].Value };
var status = match.Groups[1].Value;
- switch (status) {
- case " M": change.Set(Models.ChangeState.None, Models.ChangeState.Modified); break;
- case " A": change.Set(Models.ChangeState.None, Models.ChangeState.Added); break;
- case " D": change.Set(Models.ChangeState.None, Models.ChangeState.Deleted); break;
- case " R": change.Set(Models.ChangeState.None, Models.ChangeState.Renamed); break;
- case " C": change.Set(Models.ChangeState.None, Models.ChangeState.Copied); break;
- case "M": change.Set(Models.ChangeState.Modified, Models.ChangeState.None); break;
- case "MM": change.Set(Models.ChangeState.Modified, Models.ChangeState.Modified); break;
- case "MD": change.Set(Models.ChangeState.Modified, Models.ChangeState.Deleted); break;
- case "A": change.Set(Models.ChangeState.Added, Models.ChangeState.None); break;
- case "AM": change.Set(Models.ChangeState.Added, Models.ChangeState.Modified); break;
- case "AD": change.Set(Models.ChangeState.Added, Models.ChangeState.Deleted); break;
- case "D": change.Set(Models.ChangeState.Deleted, Models.ChangeState.None); break;
- case "R": change.Set(Models.ChangeState.Renamed, Models.ChangeState.None); break;
- case "RM": change.Set(Models.ChangeState.Renamed, Models.ChangeState.Modified); break;
- case "RD": change.Set(Models.ChangeState.Renamed, Models.ChangeState.Deleted); break;
- case "C": change.Set(Models.ChangeState.Copied, Models.ChangeState.None); break;
- case "CM": change.Set(Models.ChangeState.Copied, Models.ChangeState.Modified); break;
- case "CD": change.Set(Models.ChangeState.Copied, Models.ChangeState.Deleted); break;
- case "DR": change.Set(Models.ChangeState.Deleted, Models.ChangeState.Renamed); break;
- case "DC": change.Set(Models.ChangeState.Deleted, Models.ChangeState.Copied); break;
- case "DD": change.Set(Models.ChangeState.Deleted, Models.ChangeState.Deleted); break;
- case "AU": change.Set(Models.ChangeState.Added, Models.ChangeState.Unmerged); break;
- case "UD": change.Set(Models.ChangeState.Unmerged, Models.ChangeState.Deleted); break;
- case "UA": change.Set(Models.ChangeState.Unmerged, Models.ChangeState.Added); break;
- case "DU": change.Set(Models.ChangeState.Deleted, Models.ChangeState.Unmerged); break;
- case "AA": change.Set(Models.ChangeState.Added, Models.ChangeState.Added); break;
- case "UU": change.Set(Models.ChangeState.Unmerged, Models.ChangeState.Unmerged); break;
- case "??": change.Set(Models.ChangeState.Untracked, Models.ChangeState.Untracked); break;
- default: return;
+ switch (status)
+ {
+ case " M": change.Set(Models.ChangeState.None, Models.ChangeState.Modified); break;
+ case " A": change.Set(Models.ChangeState.None, Models.ChangeState.Added); break;
+ case " D": change.Set(Models.ChangeState.None, Models.ChangeState.Deleted); break;
+ case " R": change.Set(Models.ChangeState.None, Models.ChangeState.Renamed); break;
+ case " C": change.Set(Models.ChangeState.None, Models.ChangeState.Copied); break;
+ case "M": change.Set(Models.ChangeState.Modified, Models.ChangeState.None); break;
+ case "MM": change.Set(Models.ChangeState.Modified, Models.ChangeState.Modified); break;
+ case "MD": change.Set(Models.ChangeState.Modified, Models.ChangeState.Deleted); break;
+ case "A": change.Set(Models.ChangeState.Added, Models.ChangeState.None); break;
+ case "AM": change.Set(Models.ChangeState.Added, Models.ChangeState.Modified); break;
+ case "AD": change.Set(Models.ChangeState.Added, Models.ChangeState.Deleted); break;
+ case "D": change.Set(Models.ChangeState.Deleted, Models.ChangeState.None); break;
+ case "R": change.Set(Models.ChangeState.Renamed, Models.ChangeState.None); break;
+ case "RM": change.Set(Models.ChangeState.Renamed, Models.ChangeState.Modified); break;
+ case "RD": change.Set(Models.ChangeState.Renamed, Models.ChangeState.Deleted); break;
+ case "C": change.Set(Models.ChangeState.Copied, Models.ChangeState.None); break;
+ case "CM": change.Set(Models.ChangeState.Copied, Models.ChangeState.Modified); break;
+ case "CD": change.Set(Models.ChangeState.Copied, Models.ChangeState.Deleted); break;
+ case "DR": change.Set(Models.ChangeState.Deleted, Models.ChangeState.Renamed); break;
+ case "DC": change.Set(Models.ChangeState.Deleted, Models.ChangeState.Copied); break;
+ case "DD": change.Set(Models.ChangeState.Deleted, Models.ChangeState.Deleted); break;
+ case "AU": change.Set(Models.ChangeState.Added, Models.ChangeState.Unmerged); break;
+ case "UD": change.Set(Models.ChangeState.Unmerged, Models.ChangeState.Deleted); break;
+ case "UA": change.Set(Models.ChangeState.Unmerged, Models.ChangeState.Added); break;
+ case "DU": change.Set(Models.ChangeState.Deleted, Models.ChangeState.Unmerged); break;
+ case "AA": change.Set(Models.ChangeState.Added, Models.ChangeState.Added); break;
+ case "UU": change.Set(Models.ChangeState.Unmerged, Models.ChangeState.Unmerged); break;
+ case "??": change.Set(Models.ChangeState.Untracked, Models.ChangeState.Untracked); break;
+ default: return;
}
_changes.Add(change);
}
- private List _changes = new List();
+ private readonly List _changes = new List();
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryRemotes.cs b/src/Commands/QueryRemotes.cs
index e8e21b4a..ed2a26e6 100644
--- a/src/Commands/QueryRemotes.cs
+++ b/src/Commands/QueryRemotes.cs
@@ -1,26 +1,33 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QueryRemotes : Command {
- private static readonly Regex REG_REMOTE = new Regex(@"^([\w\.\-]+)\s*(\S+).*$");
+namespace SourceGit.Commands
+{
+ public partial class QueryRemotes : Command
+ {
+ [GeneratedRegex(@"^([\w\.\-]+)\s*(\S+).*$")]
+ private static partial Regex REG_REMOTE();
- public QueryRemotes(string repo) {
+ public QueryRemotes(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
Args = "remote -v";
}
- public List Result() {
+ public List Result()
+ {
Exec();
return _loaded;
}
- protected override void OnReadline(string line) {
- var match = REG_REMOTE.Match(line);
+ protected override void OnReadline(string line)
+ {
+ var match = REG_REMOTE().Match(line);
if (!match.Success) return;
- var remote = new Models.Remote() {
+ var remote = new Models.Remote()
+ {
Name = match.Groups[1].Value,
URL = match.Groups[2].Value,
};
@@ -29,6 +36,6 @@ namespace SourceGit.Commands {
_loaded.Add(remote);
}
- private List _loaded = new List();
+ private readonly List _loaded = new List();
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryRepositoryRootPath.cs b/src/Commands/QueryRepositoryRootPath.cs
index 51a1a15a..fad9fe34 100644
--- a/src/Commands/QueryRepositoryRootPath.cs
+++ b/src/Commands/QueryRepositoryRootPath.cs
@@ -1,15 +1,19 @@
-namespace SourceGit.Commands {
- public class QueryRepositoryRootPath : Command {
- public QueryRepositoryRootPath(string path) {
+namespace SourceGit.Commands
+{
+ public class QueryRepositoryRootPath : Command
+ {
+ public QueryRepositoryRootPath(string path)
+ {
WorkingDirectory = path;
Args = "rev-parse --show-toplevel";
RaiseError = false;
}
- public string Result() {
+ public string Result()
+ {
var rs = ReadToEnd().StdOut;
if (string.IsNullOrEmpty(rs)) return null;
return rs.Trim();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryRevisionObjects.cs b/src/Commands/QueryRevisionObjects.cs
index b0c48f2a..5c97b5bf 100644
--- a/src/Commands/QueryRevisionObjects.cs
+++ b/src/Commands/QueryRevisionObjects.cs
@@ -1,24 +1,31 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QueryRevisionObjects : Command {
- private static readonly Regex REG_FORMAT = new Regex(@"^\d+\s+(\w+)\s+([0-9a-f]+)\s+(.*)$");
- private List objects = new List();
+namespace SourceGit.Commands
+{
+ public partial class QueryRevisionObjects : Command
+ {
- public QueryRevisionObjects(string repo, string sha) {
+ [GeneratedRegex(@"^\d+\s+(\w+)\s+([0-9a-f]+)\s+(.*)$")]
+ private static partial Regex REG_FORMAT();
+ private readonly List objects = new List();
+
+ public QueryRevisionObjects(string repo, string sha)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"ls-tree -r {sha}";
}
- public List Result() {
+ public List Result()
+ {
Exec();
return objects;
}
- protected override void OnReadline(string line) {
- var match = REG_FORMAT.Match(line);
+ protected override void OnReadline(string line)
+ {
+ var match = REG_FORMAT().Match(line);
if (!match.Success) return;
var obj = new Models.Object();
@@ -26,14 +33,15 @@ namespace SourceGit.Commands {
obj.Type = Models.ObjectType.Blob;
obj.Path = match.Groups[3].Value;
- switch (match.Groups[1].Value) {
- case "blob": obj.Type = Models.ObjectType.Blob; break;
- case "tree": obj.Type = Models.ObjectType.Tree; break;
- case "tag": obj.Type = Models.ObjectType.Tag; break;
- case "commit": obj.Type = Models.ObjectType.Commit; break;
+ switch (match.Groups[1].Value)
+ {
+ case "blob": obj.Type = Models.ObjectType.Blob; break;
+ case "tree": obj.Type = Models.ObjectType.Tree; break;
+ case "tag": obj.Type = Models.ObjectType.Tag; break;
+ case "commit": obj.Type = Models.ObjectType.Commit; break;
}
objects.Add(obj);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryStagedFileBlobGuid.cs b/src/Commands/QueryStagedFileBlobGuid.cs
index 4a1c30e2..5fa56dd6 100644
--- a/src/Commands/QueryStagedFileBlobGuid.cs
+++ b/src/Commands/QueryStagedFileBlobGuid.cs
@@ -1,23 +1,29 @@
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QueryStagedFileBlobGuid : Command {
- private static readonly Regex REG_FORMAT = new Regex(@"^\d+\s+([0-9a-f]+)\s+.*$");
+namespace SourceGit.Commands
+{
+ public partial class QueryStagedFileBlobGuid : Command
+ {
+ [GeneratedRegex(@"^\d+\s+([0-9a-f]+)\s+.*$")]
+ private static partial Regex REG_FORMAT();
- public QueryStagedFileBlobGuid(string repo, string file) {
+ public QueryStagedFileBlobGuid(string repo, string file)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"ls-files -s -- \"{file}\"";
}
- public string Result() {
+ public string Result()
+ {
var rs = ReadToEnd();
- var match = REG_FORMAT.Match(rs.StdOut.Trim());
- if (match.Success) {
+ var match = REG_FORMAT().Match(rs.StdOut.Trim());
+ if (match.Success)
+ {
return match.Groups[1].Value;
}
return string.Empty;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryStashChanges.cs b/src/Commands/QueryStashChanges.cs
index c2d50d45..ad02ef00 100644
--- a/src/Commands/QueryStashChanges.cs
+++ b/src/Commands/QueryStashChanges.cs
@@ -1,37 +1,45 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QueryStashChanges : Command {
- private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$");
+namespace SourceGit.Commands
+{
+ public partial class QueryStashChanges : Command
+ {
- public QueryStashChanges(string repo, string sha) {
+ [GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
+ private static partial Regex REG_FORMAT();
+
+ public QueryStashChanges(string repo, string sha)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"diff --name-status --pretty=format: {sha}^ {sha}";
}
- public List Result() {
+ public List Result()
+ {
Exec();
return _changes;
}
- protected override void OnReadline(string line) {
- var match = REG_FORMAT.Match(line);
+ protected override void OnReadline(string line)
+ {
+ var match = REG_FORMAT().Match(line);
if (!match.Success) return;
var change = new Models.Change() { Path = match.Groups[2].Value };
var status = match.Groups[1].Value;
- switch (status[0]) {
- case 'M': change.Set(Models.ChangeState.Modified); _changes.Add(change); break;
- case 'A': change.Set(Models.ChangeState.Added); _changes.Add(change); break;
- case 'D': change.Set(Models.ChangeState.Deleted); _changes.Add(change); break;
- case 'R': change.Set(Models.ChangeState.Renamed); _changes.Add(change); break;
- case 'C': change.Set(Models.ChangeState.Copied); _changes.Add(change); break;
+ switch (status[0])
+ {
+ case 'M': change.Set(Models.ChangeState.Modified); _changes.Add(change); break;
+ case 'A': change.Set(Models.ChangeState.Added); _changes.Add(change); break;
+ case 'D': change.Set(Models.ChangeState.Deleted); _changes.Add(change); break;
+ case 'R': change.Set(Models.ChangeState.Renamed); _changes.Add(change); break;
+ case 'C': change.Set(Models.ChangeState.Copied); _changes.Add(change); break;
}
}
- private List _changes = new List();
+ private readonly List _changes = new List();
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryStashes.cs b/src/Commands/QueryStashes.cs
index 7e159500..e9023574 100644
--- a/src/Commands/QueryStashes.cs
+++ b/src/Commands/QueryStashes.cs
@@ -2,24 +2,32 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QueryStashes : Command {
- private static readonly Regex REG_STASH = new Regex(@"^Reflog: refs/(stash@\{\d+\}).*$");
-
- public QueryStashes(string repo) {
+namespace SourceGit.Commands
+{
+ public partial class QueryStashes : Command
+ {
+
+ [GeneratedRegex(@"^Reflog: refs/(stash@\{\d+\}).*$")]
+ private static partial Regex REG_STASH();
+
+ public QueryStashes(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
Args = "stash list --pretty=raw";
}
- public List Result() {
+ public List Result()
+ {
Exec();
if (_current != null) _stashes.Add(_current);
return _stashes;
}
- protected override void OnReadline(string line) {
- if (line.StartsWith("commit ", StringComparison.Ordinal)) {
+ protected override void OnReadline(string line)
+ {
+ if (line.StartsWith("commit ", StringComparison.Ordinal))
+ {
if (_current != null && !string.IsNullOrEmpty(_current.Name)) _stashes.Add(_current);
_current = new Models.Stash() { SHA = line.Substring(7, 8) };
return;
@@ -27,12 +35,17 @@ namespace SourceGit.Commands {
if (_current == null) return;
- if (line.StartsWith("Reflog: refs/stash@", StringComparison.Ordinal)) {
- var match = REG_STASH.Match(line);
+ if (line.StartsWith("Reflog: refs/stash@", StringComparison.Ordinal))
+ {
+ var match = REG_STASH().Match(line);
if (match.Success) _current.Name = match.Groups[1].Value;
- } else if (line.StartsWith("Reflog message: ", StringComparison.Ordinal)) {
+ }
+ else if (line.StartsWith("Reflog message: ", StringComparison.Ordinal))
+ {
_current.Message = line.Substring(16);
- } else if (line.StartsWith("author ", StringComparison.Ordinal)) {
+ }
+ else if (line.StartsWith("author ", StringComparison.Ordinal))
+ {
Models.User user = Models.User.Invalid;
ulong time = 0;
Models.Commit.ParseUserAndTime(line.Substring(7), ref user, ref time);
@@ -41,7 +54,7 @@ namespace SourceGit.Commands {
}
}
- private List _stashes = new List();
+ private readonly List _stashes = new List();
private Models.Stash _current = null;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QuerySubmodules.cs b/src/Commands/QuerySubmodules.cs
index 8a581f93..58c858d4 100644
--- a/src/Commands/QuerySubmodules.cs
+++ b/src/Commands/QuerySubmodules.cs
@@ -1,35 +1,44 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace SourceGit.Commands {
- public class QuerySubmodules : Command {
- private readonly Regex REG_FORMAT1 = new Regex(@"^[\-\+ ][0-9a-f]+\s(.*)\s\(.*\)$");
- private readonly Regex REG_FORMAT2 = new Regex(@"^[\-\+ ][0-9a-f]+\s(.*)$");
+namespace SourceGit.Commands
+{
+ public partial class QuerySubmodules : Command
+ {
+ [GeneratedRegex(@"^[\-\+ ][0-9a-f]+\s(.*)\s\(.*\)$")]
+ private static partial Regex REG_FORMAT1();
+ [GeneratedRegex(@"^[\-\+ ][0-9a-f]+\s(.*)$")]
+ private static partial Regex REG_FORMAT2();
- public QuerySubmodules(string repo) {
+ public QuerySubmodules(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
Args = "submodule status";
}
- public List Result() {
+ public List Result()
+ {
Exec();
return _submodules;
}
- protected override void OnReadline(string line) {
- var match = REG_FORMAT1.Match(line);
- if (match.Success) {
+ protected override void OnReadline(string line)
+ {
+ var match = REG_FORMAT1().Match(line);
+ if (match.Success)
+ {
_submodules.Add(match.Groups[1].Value);
return;
}
-
- match = REG_FORMAT2.Match(line);
- if (match.Success) {
+
+ match = REG_FORMAT2().Match(line);
+ if (match.Success)
+ {
_submodules.Add(match.Groups[1].Value);
}
}
- private List _submodules = new List();
+ private readonly List _submodules = new List();
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/QueryTags.cs b/src/Commands/QueryTags.cs
index 470301a3..a4d5a65d 100644
--- a/src/Commands/QueryTags.cs
+++ b/src/Commands/QueryTags.cs
@@ -1,34 +1,44 @@
using System;
using System.Collections.Generic;
-namespace SourceGit.Commands {
- public class QueryTags : Command {
- public QueryTags(string repo) {
+namespace SourceGit.Commands
+{
+ public class QueryTags : Command
+ {
+ public QueryTags(string repo)
+ {
Context = repo;
WorkingDirectory = repo;
Args = "for-each-ref --sort=-creatordate --format=\"$%(refname:short)$%(objectname)$%(*objectname)\" refs/tags";
}
- public List Result() {
+ public List Result()
+ {
Exec();
return _loaded;
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
var subs = line.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries);
- if (subs.Length == 2) {
- _loaded.Add(new Models.Tag() {
+ if (subs.Length == 2)
+ {
+ _loaded.Add(new Models.Tag()
+ {
Name = subs[0],
SHA = subs[1],
});
- } else if (subs.Length == 3) {
- _loaded.Add(new Models.Tag() {
+ }
+ else if (subs.Length == 3)
+ {
+ _loaded.Add(new Models.Tag()
+ {
Name = subs[0],
SHA = subs[2],
});
}
}
- private List _loaded = new List();
+ private readonly List _loaded = new List();
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Rebase.cs b/src/Commands/Rebase.cs
index 88d304aa..faa4f5c5 100644
--- a/src/Commands/Rebase.cs
+++ b/src/Commands/Rebase.cs
@@ -1,6 +1,9 @@
-namespace SourceGit.Commands {
- public class Rebase : Command {
- public Rebase(string repo, string basedOn, bool autoStash) {
+namespace SourceGit.Commands
+{
+ public class Rebase : Command
+ {
+ public Rebase(string repo, string basedOn, bool autoStash)
+ {
WorkingDirectory = repo;
Context = repo;
Args = "rebase ";
@@ -8,4 +11,4 @@
Args += basedOn;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Remote.cs b/src/Commands/Remote.cs
index 1a526045..d669b0a3 100644
--- a/src/Commands/Remote.cs
+++ b/src/Commands/Remote.cs
@@ -1,33 +1,41 @@
-namespace SourceGit.Commands {
- public class Remote : Command {
- public Remote(string repo) {
+namespace SourceGit.Commands
+{
+ public class Remote : Command
+ {
+ public Remote(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
}
- public bool Add(string name, string url) {
+ public bool Add(string name, string url)
+ {
Args = $"remote add {name} {url}";
return Exec();
}
- public bool Delete(string name) {
+ public bool Delete(string name)
+ {
Args = $"remote remove {name}";
return Exec();
}
- public bool Rename(string name, string to) {
+ public bool Rename(string name, string to)
+ {
Args = $"remote rename {name} {to}";
return Exec();
}
- public bool Prune(string name) {
+ public bool Prune(string name)
+ {
Args = $"remote prune {name}";
return Exec();
}
- public bool SetURL(string name, string url) {
+ public bool SetURL(string name, string url)
+ {
Args = $"remote set-url {name} {url}";
return Exec();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Reset.cs b/src/Commands/Reset.cs
index 445890bd..c44eae12 100644
--- a/src/Commands/Reset.cs
+++ b/src/Commands/Reset.cs
@@ -1,21 +1,26 @@
using System.Collections.Generic;
using System.Text;
-namespace SourceGit.Commands {
- public class Reset : Command {
- public Reset(string repo) {
+namespace SourceGit.Commands
+{
+ public class Reset : Command
+ {
+ public Reset(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
Args = "reset";
}
- public Reset(string repo, List changes) {
+ public Reset(string repo, List changes)
+ {
WorkingDirectory = repo;
Context = repo;
var builder = new StringBuilder();
builder.Append("reset --");
- foreach (var c in changes) {
+ foreach (var c in changes)
+ {
builder.Append(" \"");
builder.Append(c.Path);
builder.Append("\"");
@@ -23,10 +28,11 @@ namespace SourceGit.Commands {
Args = builder.ToString();
}
- public Reset(string repo, string revision, string mode) {
+ public Reset(string repo, string revision, string mode)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"reset {mode} {revision}";
- }
+ }
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Restore.cs b/src/Commands/Restore.cs
index c0aeafd5..f55f6b70 100644
--- a/src/Commands/Restore.cs
+++ b/src/Commands/Restore.cs
@@ -1,9 +1,12 @@
using System.Collections.Generic;
using System.Text;
-namespace SourceGit.Commands {
- public class Restore : Command {
- public Restore(string repo, List files, string extra) {
+namespace SourceGit.Commands
+{
+ public class Restore : Command
+ {
+ public Restore(string repo, List files, string extra)
+ {
WorkingDirectory = repo;
Context = repo;
@@ -13,6 +16,6 @@ namespace SourceGit.Commands {
builder.Append("--");
foreach (var f in files) builder.Append(' ').Append('"').Append(f).Append('"');
Args = builder.ToString();
- }
+ }
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Revert.cs b/src/Commands/Revert.cs
index 6b9549f5..12149c97 100644
--- a/src/Commands/Revert.cs
+++ b/src/Commands/Revert.cs
@@ -1,10 +1,13 @@
-namespace SourceGit.Commands {
- public class Revert : Command {
- public Revert(string repo, string commit, bool autoCommit) {
+namespace SourceGit.Commands
+{
+ public class Revert : Command
+ {
+ public Revert(string repo, string commit, bool autoCommit)
+ {
WorkingDirectory = repo;
Context = repo;
Args = $"revert {commit} --no-edit";
if (!autoCommit) Args += " --no-commit";
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/SaveChangesAsPatch.cs b/src/Commands/SaveChangesAsPatch.cs
index 8a2a7bc6..25003059 100644
--- a/src/Commands/SaveChangesAsPatch.cs
+++ b/src/Commands/SaveChangesAsPatch.cs
@@ -1,14 +1,20 @@
-using Avalonia.Threading;
-using System;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
-namespace SourceGit.Commands {
- public static class SaveChangesAsPatch {
- public static bool Exec(string repo, List changes, bool isUnstaged, string saveTo) {
- using (var sw = File.Create(saveTo)) {
- foreach (var change in changes) {
+using Avalonia.Threading;
+
+namespace SourceGit.Commands
+{
+ public static class SaveChangesAsPatch
+ {
+ public static bool Exec(string repo, List changes, bool isUnstaged, string saveTo)
+ {
+ using (var sw = File.Create(saveTo))
+ {
+ foreach (var change in changes)
+ {
if (!ProcessSingleChange(repo, new Models.DiffOption(change, isUnstaged), sw)) return false;
}
}
@@ -16,7 +22,8 @@ namespace SourceGit.Commands {
return true;
}
- private static bool ProcessSingleChange(string repo, Models.DiffOption opt, FileStream writer) {
+ private static bool ProcessSingleChange(string repo, Models.DiffOption opt, FileStream writer)
+ {
var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo;
starter.FileName = Native.OS.GitInstallPath;
@@ -26,7 +33,8 @@ namespace SourceGit.Commands {
starter.WindowStyle = ProcessWindowStyle.Hidden;
starter.RedirectStandardOutput = true;
- try {
+ try
+ {
var proc = new Process() { StartInfo = starter };
proc.Start();
proc.StandardOutput.BaseStream.CopyTo(writer);
@@ -35,12 +43,15 @@ namespace SourceGit.Commands {
proc.Close();
return rs;
- } catch (Exception e) {
- Dispatcher.UIThread.Invoke(() => {
+ }
+ catch (Exception e)
+ {
+ Dispatcher.UIThread.Invoke(() =>
+ {
App.RaiseException(repo, "Save change to patch failed: " + e.Message);
- });
+ });
return false;
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/SaveRevisionFile.cs b/src/Commands/SaveRevisionFile.cs
index bd38b617..a19a4397 100644
--- a/src/Commands/SaveRevisionFile.cs
+++ b/src/Commands/SaveRevisionFile.cs
@@ -1,24 +1,33 @@
-using Avalonia.Threading;
-using System;
+using System;
using System.Diagnostics;
using System.IO;
-namespace SourceGit.Commands {
- public static class SaveRevisionFile {
- public static void Run(string repo, string revision, string file, string saveTo) {
+using Avalonia.Threading;
+
+namespace SourceGit.Commands
+{
+ public static class SaveRevisionFile
+ {
+ public static void Run(string repo, string revision, string file, string saveTo)
+ {
var isLFSFiltered = new IsLFSFiltered(repo, file).Result();
- if (isLFSFiltered) {
+ if (isLFSFiltered)
+ {
var tmpFile = saveTo + ".tmp";
- if (ExecCmd(repo, $"show {revision}:\"{file}\"", tmpFile)) {
+ if (ExecCmd(repo, $"show {revision}:\"{file}\"", tmpFile))
+ {
ExecCmd(repo, $"lfs smudge", saveTo, tmpFile);
- }
+ }
File.Delete(tmpFile);
- } else {
+ }
+ else
+ {
ExecCmd(repo, $"show {revision}:\"{file}\"", saveTo);
}
}
-
- private static bool ExecCmd(string repo, string args, string outputFile, string inputFile = null) {
+
+ private static bool ExecCmd(string repo, string args, string outputFile, string inputFile = null)
+ {
var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo;
starter.FileName = Native.OS.GitInstallPath;
@@ -30,14 +39,19 @@ namespace SourceGit.Commands {
starter.RedirectStandardOutput = true;
starter.RedirectStandardError = true;
- using (var sw = File.OpenWrite(outputFile)) {
- try {
+ using (var sw = File.OpenWrite(outputFile))
+ {
+ try
+ {
var proc = new Process() { StartInfo = starter };
proc.Start();
- if (inputFile != null) {
- using (StreamReader sr = new StreamReader(inputFile)) {
- while (true) {
+ if (inputFile != null)
+ {
+ using (StreamReader sr = new StreamReader(inputFile))
+ {
+ while (true)
+ {
var line = sr.ReadLine();
if (line == null) break;
proc.StandardInput.WriteLine(line);
@@ -51,13 +65,16 @@ namespace SourceGit.Commands {
proc.Close();
return rs;
- } catch (Exception e) {
- Dispatcher.UIThread.Invoke(() => {
+ }
+ catch (Exception e)
+ {
+ Dispatcher.UIThread.Invoke(() =>
+ {
App.RaiseException(repo, "Save file failed: " + e.Message);
- });
+ });
return false;
}
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Stash.cs b/src/Commands/Stash.cs
index 720129a7..cb0c18e7 100644
--- a/src/Commands/Stash.cs
+++ b/src/Commands/Stash.cs
@@ -1,36 +1,45 @@
using System.Collections.Generic;
using System.IO;
-namespace SourceGit.Commands {
- public class Stash : Command {
- public Stash(string repo) {
+namespace SourceGit.Commands
+{
+ public class Stash : Command
+ {
+ public Stash(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
}
- public bool Push(string message) {
+ public bool Push(string message)
+ {
Args = $"stash push -m \"{message}\"";
return Exec();
}
- public bool Push(List changes, string message) {
+ public bool Push(List changes, string message)
+ {
var temp = Path.GetTempFileName();
var stream = new FileStream(temp, FileMode.Create);
var writer = new StreamWriter(stream);
var needAdd = new List();
- foreach (var c in changes) {
+ foreach (var c in changes)
+ {
writer.WriteLine(c.Path);
- if (c.WorkTree == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked) {
+ if (c.WorkTree == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked)
+ {
needAdd.Add(c);
- if (needAdd.Count > 10) {
+ if (needAdd.Count > 10)
+ {
new Add(WorkingDirectory, needAdd).Exec();
needAdd.Clear();
}
}
}
- if (needAdd.Count > 0) {
+ if (needAdd.Count > 0)
+ {
new Add(WorkingDirectory, needAdd).Exec();
needAdd.Clear();
}
@@ -46,24 +55,28 @@ namespace SourceGit.Commands {
return succ;
}
- public bool Apply(string name) {
+ public bool Apply(string name)
+ {
Args = $"stash apply -q {name}";
return Exec();
}
- public bool Pop(string name) {
+ public bool Pop(string name)
+ {
Args = $"stash pop -q {name}";
return Exec();
}
- public bool Drop(string name) {
+ public bool Drop(string name)
+ {
Args = $"stash drop -q {name}";
return Exec();
}
- public bool Clear() {
+ public bool Clear()
+ {
Args = "stash clear";
return Exec();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Statistics.cs b/src/Commands/Statistics.cs
index fb0e7ee0..36a048a7 100644
--- a/src/Commands/Statistics.cs
+++ b/src/Commands/Statistics.cs
@@ -1,8 +1,11 @@
using System;
-namespace SourceGit.Commands {
- public class Statistics : Command {
- public Statistics(string repo) {
+namespace SourceGit.Commands
+{
+ public class Statistics : Command
+ {
+ public Statistics(string repo)
+ {
_statistics = new Models.Statistics();
WorkingDirectory = repo;
@@ -10,13 +13,15 @@ namespace SourceGit.Commands {
Args = $"log --date-order --branches --remotes --since=\"{_statistics.Since()}\" --pretty=format:\"%ct$%cn\"";
}
- public Models.Statistics Result() {
+ public Models.Statistics Result()
+ {
Exec();
_statistics.Complete();
return _statistics;
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
var dateEndIdx = line.IndexOf('$', StringComparison.Ordinal);
if (dateEndIdx == -1) return;
@@ -27,6 +32,6 @@ namespace SourceGit.Commands {
_statistics.AddCommit(line.Substring(dateEndIdx + 1), date);
}
- private Models.Statistics _statistics = null;
+ private readonly Models.Statistics _statistics = null;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Submodule.cs b/src/Commands/Submodule.cs
index a6aeee83..e5c385c3 100644
--- a/src/Commands/Submodule.cs
+++ b/src/Commands/Submodule.cs
@@ -1,32 +1,41 @@
using System;
-namespace SourceGit.Commands {
- public class Submodule : Command {
- public Submodule(string repo) {
+namespace SourceGit.Commands
+{
+ public class Submodule : Command
+ {
+ public Submodule(string repo)
+ {
WorkingDirectory = repo;
Context = repo;
}
- public bool Add(string url, string relativePath, bool recursive, Action outputHandler) {
+ public bool Add(string url, string relativePath, bool recursive, Action outputHandler)
+ {
_outputHandler = outputHandler;
Args = $"submodule add {url} {relativePath}";
if (!Exec()) return false;
- if (recursive) {
+ if (recursive)
+ {
Args = $"submodule update --init --recursive -- {relativePath}";
return Exec();
- } else {
+ }
+ else
+ {
Args = $"submodule update --init -- {relativePath}";
return true;
}
}
- public bool Update() {
+ public bool Update()
+ {
Args = $"submodule update --rebase --remote";
return Exec();
}
- public bool Delete(string relativePath) {
+ public bool Delete(string relativePath)
+ {
Args = $"submodule deinit -f {relativePath}";
if (!Exec()) return false;
@@ -34,10 +43,11 @@ namespace SourceGit.Commands {
return Exec();
}
- protected override void OnReadline(string line) {
+ protected override void OnReadline(string line)
+ {
_outputHandler?.Invoke(line);
}
private Action _outputHandler;
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Tag.cs b/src/Commands/Tag.cs
index d0ab3bcb..3b49deba 100644
--- a/src/Commands/Tag.cs
+++ b/src/Commands/Tag.cs
@@ -1,34 +1,43 @@
using System.Collections.Generic;
using System.IO;
-namespace SourceGit.Commands {
- public static class Tag {
- public static bool Add(string repo, string name, string basedOn, string message) {
+namespace SourceGit.Commands
+{
+ public static class Tag
+ {
+ public static bool Add(string repo, string name, string basedOn, string message)
+ {
var cmd = new Command();
cmd.WorkingDirectory = repo;
cmd.Context = repo;
cmd.Args = $"tag -a {name} {basedOn} ";
- if (!string.IsNullOrEmpty(message)) {
+ if (!string.IsNullOrEmpty(message))
+ {
string tmp = Path.GetTempFileName();
File.WriteAllText(tmp, message);
cmd.Args += $"-F \"{tmp}\"";
- } else {
+ }
+ else
+ {
cmd.Args += $"-m {name}";
}
return cmd.Exec();
}
- public static bool Delete(string repo, string name, List remotes) {
+ public static bool Delete(string repo, string name, List remotes)
+ {
var cmd = new Command();
cmd.WorkingDirectory = repo;
cmd.Context = repo;
cmd.Args = $"tag --delete {name}";
if (!cmd.Exec()) return false;
- if (remotes != null) {
- foreach (var r in remotes) {
+ if (remotes != null)
+ {
+ foreach (var r in remotes)
+ {
new Push(repo, r.Name, name, true).Exec();
}
}
@@ -36,4 +45,4 @@ namespace SourceGit.Commands {
return true;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Commands/Version.cs b/src/Commands/Version.cs
index 54a937f7..7b368b04 100644
--- a/src/Commands/Version.cs
+++ b/src/Commands/Version.cs
@@ -1,14 +1,18 @@
-namespace SourceGit.Commands {
- public class Version : Command {
- public Version() {
+namespace SourceGit.Commands
+{
+ public class Version : Command
+ {
+ public Version()
+ {
Args = "--version";
RaiseError = false;
}
- public string Query() {
+ public string Query()
+ {
var rs = ReadToEnd();
if (!rs.IsSuccess || string.IsNullOrWhiteSpace(rs.StdOut)) return string.Empty;
return rs.StdOut.Trim().Substring("git version ".Length);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Converters/BookmarkConverters.cs b/src/Converters/BookmarkConverters.cs
index 1eca567b..01da5475 100644
--- a/src/Converters/BookmarkConverters.cs
+++ b/src/Converters/BookmarkConverters.cs
@@ -1,12 +1,14 @@
using Avalonia.Data.Converters;
using Avalonia.Media;
-namespace SourceGit.Converters {
- public static class BookmarkConverters {
+namespace SourceGit.Converters
+{
+ public static class BookmarkConverters
+ {
public static FuncValueConverter ToBrush =
new FuncValueConverter(bookmark => Models.Bookmarks.Brushes[bookmark]);
public static FuncValueConverter ToStrokeThickness =
new FuncValueConverter(bookmark => bookmark == 0 ? 1.0 : 0);
}
-}
+}
\ No newline at end of file
diff --git a/src/Converters/BoolConverters.cs b/src/Converters/BoolConverters.cs
index 65593f8f..31f56499 100644
--- a/src/Converters/BoolConverters.cs
+++ b/src/Converters/BoolConverters.cs
@@ -1,8 +1,10 @@
using Avalonia.Data.Converters;
-namespace SourceGit.Converters {
- public static class BoolConverters {
+namespace SourceGit.Converters
+{
+ public static class BoolConverters
+ {
public static FuncValueConverter ToCommitOpacity =
new FuncValueConverter(x => x ? 1 : 0.5);
}
-}
+}
\ No newline at end of file
diff --git a/src/Converters/BranchConverters.cs b/src/Converters/BranchConverters.cs
index c067a481..66675eca 100644
--- a/src/Converters/BranchConverters.cs
+++ b/src/Converters/BranchConverters.cs
@@ -1,8 +1,10 @@
using Avalonia.Data.Converters;
-namespace SourceGit.Converters {
- public static class BranchConverters {
+namespace SourceGit.Converters
+{
+ public static class BranchConverters
+ {
public static FuncValueConverter ToName =
new FuncValueConverter(v => v.IsLocal ? v.Name : $"{v.Remote}/{v.Name}");
}
-}
+}
\ No newline at end of file
diff --git a/src/Converters/ChangeViewModeConverters.cs b/src/Converters/ChangeViewModeConverters.cs
index 8bfb0898..90a0828f 100644
--- a/src/Converters/ChangeViewModeConverters.cs
+++ b/src/Converters/ChangeViewModeConverters.cs
@@ -2,17 +2,21 @@
using Avalonia.Data.Converters;
using Avalonia.Media;
-namespace SourceGit.Converters {
- public static class ChangeViewModeConverters {
+namespace SourceGit.Converters
+{
+ public static class ChangeViewModeConverters
+ {
public static FuncValueConverter ToIcon =
- new FuncValueConverter(v => {
- switch (v) {
- case Models.ChangeViewMode.List:
- return App.Current?.FindResource("Icons.List") as StreamGeometry;
- case Models.ChangeViewMode.Grid:
- return App.Current?.FindResource("Icons.Grid") as StreamGeometry;
- default:
- return App.Current?.FindResource("Icons.Tree") as StreamGeometry;
+ new FuncValueConverter(v =>
+ {
+ switch (v)
+ {
+ case Models.ChangeViewMode.List:
+ return App.Current?.FindResource("Icons.List") as StreamGeometry;
+ case Models.ChangeViewMode.Grid:
+ return App.Current?.FindResource("Icons.Grid") as StreamGeometry;
+ default:
+ return App.Current?.FindResource("Icons.Tree") as StreamGeometry;
}
});
@@ -25,4 +29,4 @@ namespace SourceGit.Converters {
public static FuncValueConverter IsTree =
new FuncValueConverter(v => v == Models.ChangeViewMode.Tree);
}
-}
+}
\ No newline at end of file
diff --git a/src/Converters/DecoratorTypeConverters.cs b/src/Converters/DecoratorTypeConverters.cs
index 2e9460c9..10d6f0a7 100644
--- a/src/Converters/DecoratorTypeConverters.cs
+++ b/src/Converters/DecoratorTypeConverters.cs
@@ -3,32 +3,37 @@ using Avalonia.Controls;
using Avalonia.Data.Converters;
using Avalonia.Media;
-namespace SourceGit.Converters {
- public static class DecoratorTypeConverters {
+namespace SourceGit.Converters
+{
+ public static class DecoratorTypeConverters
+ {
public static FuncValueConverter ToBackground =
- new FuncValueConverter(v => {
+ new FuncValueConverter(v =>
+ {
if (v == Models.DecoratorType.Tag) return Models.DecoratorResources.Backgrounds[0];
return Models.DecoratorResources.Backgrounds[1];
});
public static FuncValueConverter ToIcon =
- new FuncValueConverter(v => {
+ new FuncValueConverter(v =>
+ {
var key = "Icons.Tag";
- switch (v) {
- case Models.DecoratorType.CurrentBranchHead:
- key = "Icons.Check";
- break;
- case Models.DecoratorType.RemoteBranchHead:
- key = "Icons.Remote";
- break;
- case Models.DecoratorType.LocalBranchHead:
- key = "Icons.Branch";
- break;
- default:
- break;
+ switch (v)
+ {
+ case Models.DecoratorType.CurrentBranchHead:
+ key = "Icons.Check";
+ break;
+ case Models.DecoratorType.RemoteBranchHead:
+ key = "Icons.Remote";
+ break;
+ case Models.DecoratorType.LocalBranchHead:
+ key = "Icons.Branch";
+ break;
+ default:
+ break;
}
return Application.Current?.FindResource(key) as StreamGeometry;
});
}
-}
+}
\ No newline at end of file
diff --git a/src/Converters/IntConverters.cs b/src/Converters/IntConverters.cs
index 4a97a90d..f595505e 100644
--- a/src/Converters/IntConverters.cs
+++ b/src/Converters/IntConverters.cs
@@ -1,7 +1,9 @@
using Avalonia.Data.Converters;
-namespace SourceGit.Converters {
- public static class IntConverters {
+namespace SourceGit.Converters
+{
+ public static class IntConverters
+ {
public static FuncValueConverter IsGreaterThanZero =
new FuncValueConverter(v => v > 0);
@@ -11,4 +13,4 @@ namespace SourceGit.Converters {
public static FuncValueConverter IsOne =
new FuncValueConverter(v => v == 1);
}
-}
+}
\ No newline at end of file
diff --git a/src/Converters/LauncherPageConverters.cs b/src/Converters/LauncherPageConverters.cs
index 6ba2a0a4..88d21d51 100644
--- a/src/Converters/LauncherPageConverters.cs
+++ b/src/Converters/LauncherPageConverters.cs
@@ -1,11 +1,15 @@
-using Avalonia.Collections;
-using Avalonia.Data.Converters;
-using System.Collections.Generic;
+using System.Collections.Generic;
-namespace SourceGit.Converters {
- public static class LauncherPageConverters {
+using Avalonia.Collections;
+using Avalonia.Data.Converters;
+
+namespace SourceGit.Converters
+{
+ public static class LauncherPageConverters
+ {
public static FuncMultiValueConverter