mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 12:45:00 +00:00
enhance: improve Repository.Open()
performance (#1121)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
0a877c6730
commit
fc85dd3269
1 changed files with 36 additions and 11 deletions
|
@ -275,22 +275,16 @@ namespace SourceGit.ViewModels
|
|||
|
||||
if (!Path.Exists(node.Id))
|
||||
{
|
||||
var ctx = page == null ? ActivePage.Node.Id : page.Node.Id;
|
||||
App.RaiseException(ctx, "Repository does NOT exists any more. Please remove it.");
|
||||
App.RaiseException(node.Id, "Repository does NOT exists any more. Please remove it.");
|
||||
return;
|
||||
}
|
||||
|
||||
var isBare = new Commands.IsBareRepository(node.Id).Result();
|
||||
var gitDir = node.Id;
|
||||
if (!isBare)
|
||||
var gitDir = isBare ? node.Id : GetRepositoryGitDir(node.Id);
|
||||
if (string.IsNullOrEmpty(gitDir))
|
||||
{
|
||||
gitDir = new Commands.QueryGitDir(node.Id).Result();
|
||||
if (string.IsNullOrEmpty(gitDir))
|
||||
{
|
||||
var ctx = page == null ? ActivePage.Node.Id : page.Node.Id;
|
||||
App.RaiseException(ctx, "Given path is not a valid git repository!");
|
||||
return;
|
||||
}
|
||||
App.RaiseException(node.Id, "Given path is not a valid git repository!");
|
||||
return;
|
||||
}
|
||||
|
||||
var repo = new Repository(isBare, node.Id, gitDir);
|
||||
|
@ -469,6 +463,37 @@ namespace SourceGit.ViewModels
|
|||
return menu;
|
||||
}
|
||||
|
||||
private string GetRepositoryGitDir(string repo)
|
||||
{
|
||||
var fullpath = Path.Combine(repo, ".git");
|
||||
if (Directory.Exists(fullpath))
|
||||
{
|
||||
if (Directory.Exists(Path.Combine(fullpath, "refs")) &&
|
||||
Directory.Exists(Path.Combine(fullpath, "objects")) &&
|
||||
File.Exists(Path.Combine(fullpath, "HEAD")))
|
||||
return fullpath;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (File.Exists(fullpath))
|
||||
{
|
||||
var redirect = File.ReadAllText(fullpath).Trim();
|
||||
if (redirect.StartsWith("gitdir: ", StringComparison.Ordinal))
|
||||
redirect = redirect.Substring(8);
|
||||
|
||||
if (!Path.IsPathRooted(redirect))
|
||||
redirect = Path.GetFullPath(Path.Combine(repo, redirect));
|
||||
|
||||
if (Directory.Exists(redirect))
|
||||
return redirect;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Commands.QueryGitDir(repo).Result();
|
||||
}
|
||||
|
||||
private void SwitchWorkspace(Workspace to)
|
||||
{
|
||||
foreach (var one in Pages)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue