From 00353f6d93b86c0ca3c16c50ade33217928f542a Mon Sep 17 00:00:00 2001 From: John Gietzen Date: Thu, 2 May 2013 22:17:57 -0700 Subject: [PATCH] Style Fixes. --- WebGitNet.SharedLib/GitErrorException.cs | 3 - WebGitNet.SharedLib/GitRef.cs | 2 - WebGitNet.SharedLib/GitUtilities.cs | 103 +++++++++--------- WebGitNet.SharedLib/IRouteRegisterer.cs | 4 - WebGitNet.SharedLib/IgnoreFileParser.cs | 2 - WebGitNet.SharedLib/MimeUtilities.cs | 2 - WebGitNet.SharedLib/PathUtilities.cs | 2 - .../PluginContentController.cs | 2 - WebGitNet.SharedLib/RenameEntry.cs | 5 - WebGitNet/ActionResults/AtomActionResult.cs | 5 +- WebGitNet/Controllers/ManageController.cs | 1 + WebGitNet/Controllers/SearchController.cs | 7 +- .../Controllers/SyndicationController.cs | 5 +- WebGitNet/Global.asax.cs | 1 - WebGitNet/HtmlHelpers.cs | 1 - WebGitNet/ResourceRazorViewEngine.cs | 8 -- 16 files changed, 58 insertions(+), 95 deletions(-) diff --git a/WebGitNet.SharedLib/GitErrorException.cs b/WebGitNet.SharedLib/GitErrorException.cs index e0cd1aa..5228cf8 100644 --- a/WebGitNet.SharedLib/GitErrorException.cs +++ b/WebGitNet.SharedLib/GitErrorException.cs @@ -8,9 +8,6 @@ namespace WebGitNet { using System; - using System.Collections.Generic; - using System.Linq; - using System.Web; public class GitErrorException : Exception { diff --git a/WebGitNet.SharedLib/GitRef.cs b/WebGitNet.SharedLib/GitRef.cs index ec157bc..67bc52d 100644 --- a/WebGitNet.SharedLib/GitRef.cs +++ b/WebGitNet.SharedLib/GitRef.cs @@ -9,8 +9,6 @@ namespace WebGitNet { using System; using System.Collections.Generic; - using System.Linq; - using System.Web; public enum RefType { diff --git a/WebGitNet.SharedLib/GitUtilities.cs b/WebGitNet.SharedLib/GitUtilities.cs index 1029e0f..39296a9 100644 --- a/WebGitNet.SharedLib/GitUtilities.cs +++ b/WebGitNet.SharedLib/GitUtilities.cs @@ -15,9 +15,9 @@ namespace WebGitNet using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; + using System.Web; using System.Web.Configuration; using StackExchange.Profiling; - using System.Web; public static class GitUtilities { @@ -190,7 +190,7 @@ public static RepoInfo GetRepoInfo(string repoPath) File.Exists(Path.Combine(repoPath, "HEAD"))) ); - var isRepoBare = + var isRepoBare = isRepo && (!Directory.Exists(Path.Combine(repoPath, ".git"))); @@ -621,7 +621,7 @@ public static TreeView GetTreeInfo(string repoPath, string tree, string path = n { var gitmodules = Execute(string.Format("show {0}:{1}.gitmodules", Q(tree), Q(path)), repoPath, Encoding.UTF8, trustErrorCode: true); submodules = GetSubmoduleUrls(gitmodules); - } + } catch { // .gitmodules file does not exist @@ -633,7 +633,8 @@ public static TreeView GetTreeInfo(string repoPath, string tree, string path = n private static IDictionary GetSubmoduleUrls(string gitmodules) { var submoduleList = new Dictionary(); - if (gitmodules != null) { + if (gitmodules != null) + { using (var reader = new StringReader(gitmodules)) { Regex headerRegex = new Regex(@"\[(.*)\s""(.*)""\]"); @@ -646,58 +647,58 @@ private static IDictionary GetSubmoduleUrls(string gitmod { try { - var submodule = match.Groups[2].Value; - var items = new Dictionary(); - line = reader.ReadLine(); - while (line != null && (match = itemsRegex.Match(line)).Groups.Count == 3) - { - string key = match.Groups[1].Value; - string value = match.Groups[2].Value; - // parse url to make is useable - if (key == "url") - { - // scp-like syntax is valid for git, but does not conform to uri standards - // so we need to fix it up - Regex scpLikeRegex = new Regex(@"\w*@.*:(\d*).*"); - if ((match = scpLikeRegex.Match(value)).Groups.Count > 1 && match.Groups[1].Length == 0) - { - value = value.Replace(":", "/"); - } - // if the value does not start with a scheme, we assume that it is ssh, not that it really matters - Regex schemeRegex = new Regex(@"\w*://.*"); - if (!schemeRegex.Match(value).Success) - { - value = "ssh" + Uri.SchemeDelimiter + value; - } - var uri = new Uri(value); - // check to see if uri.Host is this server and fixup url - if (uri.GetLeftPart(UriPartial.Authority) == - HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)) - { - value = value.ToString().Replace("/git/", "/browse/"); - } - // fixup github urls so that we can link there - if (uri.Host.Equals("github.com", StringComparison.OrdinalIgnoreCase)) - { - value = Uri.UriSchemeHttps + Uri.SchemeDelimiter + uri.Host + uri.AbsolutePath; - // drop the .git if present - if (value.EndsWith(".git")) - { - value = value.Remove(value.Length - 4, 4); - } - } - // TODO support other sites? - } - items.Add(key, value); - line = reader.ReadLine(); - } - submoduleList.Add(submodule, new SubmoduleInfo(items["path"], items["url"])); + var submodule = match.Groups[2].Value; + var items = new Dictionary(); + line = reader.ReadLine(); + while (line != null && (match = itemsRegex.Match(line)).Groups.Count == 3) + { + string key = match.Groups[1].Value; + string value = match.Groups[2].Value; + // parse url to make is useable + if (key == "url") + { + // scp-like syntax is valid for git, but does not conform to uri standards + // so we need to fix it up + Regex scpLikeRegex = new Regex(@"\w*@.*:(\d*).*"); + if ((match = scpLikeRegex.Match(value)).Groups.Count > 1 && match.Groups[1].Length == 0) + { + value = value.Replace(":", "/"); + } + // if the value does not start with a scheme, we assume that it is ssh, not that it really matters + Regex schemeRegex = new Regex(@"\w*://.*"); + if (!schemeRegex.Match(value).Success) + { + value = "ssh" + Uri.SchemeDelimiter + value; + } + var uri = new Uri(value); + // check to see if uri.Host is this server and fixup url + if (uri.GetLeftPart(UriPartial.Authority) == + HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)) + { + value = value.ToString().Replace("/git/", "/browse/"); + } + // fixup github urls so that we can link there + if (uri.Host.Equals("github.com", StringComparison.OrdinalIgnoreCase)) + { + value = Uri.UriSchemeHttps + Uri.SchemeDelimiter + uri.Host + uri.AbsolutePath; + // drop the .git if present + if (value.EndsWith(".git")) + { + value = value.Remove(value.Length - 4, 4); + } + } + // TODO support other sites? + } + items.Add(key, value); + line = reader.ReadLine(); + } + submoduleList.Add(submodule, new SubmoduleInfo(items["path"], items["url"])); } catch { // ignore error } - } + } else { line = reader.ReadLine(); diff --git a/WebGitNet.SharedLib/IRouteRegisterer.cs b/WebGitNet.SharedLib/IRouteRegisterer.cs index c0441e7..277152b 100644 --- a/WebGitNet.SharedLib/IRouteRegisterer.cs +++ b/WebGitNet.SharedLib/IRouteRegisterer.cs @@ -7,10 +7,6 @@ namespace WebGitNet { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; using System.Web.Routing; public interface IRouteRegisterer diff --git a/WebGitNet.SharedLib/IgnoreFileParser.cs b/WebGitNet.SharedLib/IgnoreFileParser.cs index 80087b0..3344ff0 100644 --- a/WebGitNet.SharedLib/IgnoreFileParser.cs +++ b/WebGitNet.SharedLib/IgnoreFileParser.cs @@ -7,10 +7,8 @@ namespace WebGitNet { - using System; using System.Collections.Generic; using System.Linq; - using System.Web; public static class IgnoreFileParser { diff --git a/WebGitNet.SharedLib/MimeUtilities.cs b/WebGitNet.SharedLib/MimeUtilities.cs index d587ae1..3acdb93 100644 --- a/WebGitNet.SharedLib/MimeUtilities.cs +++ b/WebGitNet.SharedLib/MimeUtilities.cs @@ -10,9 +10,7 @@ namespace WebGitNet using System; using System.Collections.Generic; using System.IO; - using System.Linq; using System.Reflection; - using System.Text.RegularExpressions; using Microsoft.Win32; public class MimeUtilities diff --git a/WebGitNet.SharedLib/PathUtilities.cs b/WebGitNet.SharedLib/PathUtilities.cs index 5029f77..8c7e3e1 100644 --- a/WebGitNet.SharedLib/PathUtilities.cs +++ b/WebGitNet.SharedLib/PathUtilities.cs @@ -7,8 +7,6 @@ namespace WebGitNet { - using System; - using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; diff --git a/WebGitNet.SharedLib/PluginContentController.cs b/WebGitNet.SharedLib/PluginContentController.cs index efbe279..cf2fa03 100644 --- a/WebGitNet.SharedLib/PluginContentController.cs +++ b/WebGitNet.SharedLib/PluginContentController.cs @@ -8,9 +8,7 @@ namespace WebGitNet { using System; - using System.Collections.Generic; using System.Linq; - using System.Text; using System.Web.Mvc; public class PluginContentController : Controller diff --git a/WebGitNet.SharedLib/RenameEntry.cs b/WebGitNet.SharedLib/RenameEntry.cs index 5e117a1..0a416fa 100644 --- a/WebGitNet.SharedLib/RenameEntry.cs +++ b/WebGitNet.SharedLib/RenameEntry.cs @@ -7,11 +7,6 @@ namespace WebGitNet { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Web; - public enum RenameField { None = 0, diff --git a/WebGitNet/ActionResults/AtomActionResult.cs b/WebGitNet/ActionResults/AtomActionResult.cs index 7cb61ea..c4cf67e 100644 --- a/WebGitNet/ActionResults/AtomActionResult.cs +++ b/WebGitNet/ActionResults/AtomActionResult.cs @@ -8,11 +8,8 @@ namespace WebGitNet.ActionResults { using System; - using System.Collections.Generic; - using System.Linq; - using System.Web; - using System.Web.Mvc; using System.ServiceModel.Syndication; + using System.Web.Mvc; using System.Xml; public class AtomActionResult : ActionResult diff --git a/WebGitNet/Controllers/ManageController.cs b/WebGitNet/Controllers/ManageController.cs index 94136a8..1496c4b 100644 --- a/WebGitNet/Controllers/ManageController.cs +++ b/WebGitNet/Controllers/ManageController.cs @@ -12,6 +12,7 @@ namespace WebGitNet.Controllers using System.Web.Mvc; using System.Web.Routing; using WebGitNet.Models; + using io = System.IO; public class ManageController : SharedControllerBase diff --git a/WebGitNet/Controllers/SearchController.cs b/WebGitNet/Controllers/SearchController.cs index 190b683..5f553fa 100644 --- a/WebGitNet/Controllers/SearchController.cs +++ b/WebGitNet/Controllers/SearchController.cs @@ -7,15 +7,12 @@ namespace WebGitNet.Controllers { - using System; - using System.Collections.Generic; using System.Linq; - using System.Web; + using System.Threading.Tasks; using System.Web.Mvc; using System.Web.Routing; - using WebGitNet.Search; using Castle.Windsor; - using System.Threading.Tasks; + using WebGitNet.Search; public class SearchController : SharedControllerBase { diff --git a/WebGitNet/Controllers/SyndicationController.cs b/WebGitNet/Controllers/SyndicationController.cs index 1356ecd..a7674b2 100644 --- a/WebGitNet/Controllers/SyndicationController.cs +++ b/WebGitNet/Controllers/SyndicationController.cs @@ -10,12 +10,11 @@ namespace WebGitNet.Controllers using System; using System.Collections.Generic; using System.Linq; - using System.Web; + using System.ServiceModel.Syndication; using System.Web.Mvc; using System.Web.Routing; - using System.ServiceModel.Syndication; - using WebGitNet.ActionResults; using MarkdownSharp; + using WebGitNet.ActionResults; public class SyndicationController : SharedControllerBase { diff --git a/WebGitNet/Global.asax.cs b/WebGitNet/Global.asax.cs index 3f37129..d47570a 100644 --- a/WebGitNet/Global.asax.cs +++ b/WebGitNet/Global.asax.cs @@ -7,7 +7,6 @@ namespace WebGitNet { - using System.Linq; using System.Web.Hosting; using System.Web.Mvc; using System.Web.Routing; diff --git a/WebGitNet/HtmlHelpers.cs b/WebGitNet/HtmlHelpers.cs index 081025b..82eace6 100644 --- a/WebGitNet/HtmlHelpers.cs +++ b/WebGitNet/HtmlHelpers.cs @@ -7,7 +7,6 @@ namespace WebGitNet { - using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; diff --git a/WebGitNet/ResourceRazorViewEngine.cs b/WebGitNet/ResourceRazorViewEngine.cs index 47a82f6..268448c 100644 --- a/WebGitNet/ResourceRazorViewEngine.cs +++ b/WebGitNet/ResourceRazorViewEngine.cs @@ -7,15 +7,7 @@ namespace WebGitNet { - using System; - using System.Collections.Generic; - using System.IO; using System.Linq; - using System.Reflection; - using System.Security.Cryptography; - using System.Text; - using System.Threading; - using System.Web; using System.Web.Mvc; public class ResourceRazorViewEngine : RazorViewEngine