Skip to content

Commit 8eaae8e

Browse files
committed
Merge branch 'master' of https://github.com/yysun/Git-Source-Control-Provider into v0.9.5
Conflicts: GitUI/Resources/Microsoft.Windows.Shell.dll.CodeAnalysisLog.xml PendingChangesView.xaml PkgCmd.vsct source.extension.vsixmanifest
2 parents d5a3909 + bf94ea6 commit 8eaae8e

32 files changed

+2281
-660
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ _ReSharper*/
2929
[Tt]est[Rr]esult*
3030
Publish*/
3131
GitUI/Resources/*.dll
32+
GitUI/Resources/*.xml
3233
*.pkg

BasicSccProvider.Tests/GitFileStatusTrackerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void AmendCommitTest()
242242

243243
File.WriteAllText(tempFile, "changed text");
244244
tracker.StageFile(tempFile);
245-
tracker.AmendCommit("new message");
245+
tracker.Commit("new message", true);
246246
Assert.IsTrue(tracker.LastCommitMessage.StartsWith("new message"));
247247
}
248248

BasicSccProvider.Tests/RepositoryGraphTest.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using System;
44
using System.Collections.Generic;
5-
using NGit.Api;
65

76
namespace BasicSccProvider.Tests
87
{
98

10-
119
/// <summary>
1210
///This is a test class for RepositoryGraphTest and is intended
1311
///to contain all RepositoryGraphTest Unit Tests
1412
///</summary>
1513
[TestClass()]
1614
public class RepositoryGraphTest
1715
{
18-
16+
private const string repodir = @"D:\Users\Public\My Projects Tryout\gitsharp\";
1917

2018
private TestContext testContextInstance;
2119

@@ -68,8 +66,7 @@ public TestContext TestContext
6866
//[TestMethod()]
6967
//public void TreeTest()
7068
//{
71-
// var git = Git.Open(@"D:\Users\Public\My Projects Tryout\gitsharp\").GetRepository();
72-
// RepositoryGraph repo = new RepositoryGraph(git);
69+
// RepositoryGraph repo = new RepositoryGraph(repodir);
7370
// var tree = repo.GetTree("master");
7471
// foreach (var t in tree.Trees)
7572
// {
@@ -84,8 +81,7 @@ public TestContext TestContext
8481
[TestMethod()]
8582
public void TreeDiffTest()
8683
{
87-
var git = Git.Open(@"D:\Users\Public\My Projects Tryout\gitsharp\").GetRepository();
88-
RepositoryGraph repo = new RepositoryGraph(git);
84+
RepositoryGraph repo = new RepositoryGraph(repodir);
8985
var changes = repo.GetChanges("master", "HEAD");
9086
foreach (var change in changes)
9187
{
@@ -96,8 +92,7 @@ public void TreeDiffTest()
9692
[TestMethod()]
9793
public void TreeDiffTest1()
9894
{
99-
var git = Git.Open(@"D:\Users\Public\My Projects Tryout\gitsharp\").GetRepository();
100-
RepositoryGraph repo = new RepositoryGraph(git);
95+
RepositoryGraph repo = new RepositoryGraph(repodir);
10196
var changes = repo.GetChanges("master");
10297
foreach (var change in changes)
10398
{

BasicSccProvider.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,23 @@ private void ShowHistoryWindow(object sender, EventArgs e)
447447
path = Path.Combine(path, "Dragon.pkg");
448448
var tmpPath = Path.Combine(Path.GetTempPath(), "Dragon.exe");
449449

450-
try
450+
var needCopy = !File.Exists(tmpPath);
451+
if(!needCopy)
451452
{
452-
File.Copy(path, tmpPath, true);
453+
var date1 = File.GetLastWriteTimeUtc(path);
454+
var date2 = File.GetLastWriteTimeUtc(tmpPath);
455+
needCopy = (date1>date2);
453456
}
454-
catch // try copy file silently
457+
458+
if (needCopy)
455459
{
460+
try
461+
{
462+
File.Copy(path, tmpPath, true);
463+
}
464+
catch // try copy file silently
465+
{
466+
}
456467
}
457468

458469
if (File.Exists(tmpPath))

GitApi/DataServices/Change.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public enum ChangeType
1818
Modified,
1919
TypeChanged,
2020
Renamed,
21-
Copied
21+
Copied,
22+
Unknown
2223
}
2324
}
2425

GitApi/DataServices/Commit.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public class Commit
1010
public string Id { get; set; }
1111
public IList<string> ParentIds { get; set; }
1212
public IList<string> ChildIds { get; set; }
13+
public string Subject { get; set; }
1314
public string Message { get; set; }
15+
public string TreeId { get; set; }
1416
public string CommitterName { get; set; }
1517
public string CommitterEmail { get; set; }
1618
public DateTime CommitDate { get; set; }
@@ -19,7 +21,7 @@ public class Commit
1921

2022
public override string ToString()
2123
{
22-
return string.Format("[{0}] {1}", ShortId, Message.Replace("\r", ""));
24+
return string.Format("[{0}] {1}", ShortId, Subject.Replace("\r", ""));
2325
}
2426

2527
public string ShortId { get { return Id.Substring(0, 7); } } }

GitApi/DataServices/GitTreeObject.cs

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,34 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Web;
5-
using NGit;
6-
using NGit.Treewalk;
75
using System.ComponentModel;
6+
using System.IO;
87

98
namespace GitScc.DataServices
109
{
1110
public class GitTreeObject : INotifyPropertyChanged
1211
{
1312
public string Id { get; internal set; }
1413
public string Name { get; internal set; }
15-
public Repository repository { get; internal set; }
16-
public bool IsTree { get; set; }
14+
public string FullName { get; internal set; }
15+
public string Type { get; set; }
16+
public string Mode { get; set; }
17+
public string Repository { get; internal set; }
18+
19+
public bool IsBlob
20+
{
21+
get { return Type == "blob"; }
22+
}
23+
24+
public bool IsCommit
25+
{
26+
get { return Type == "commit"; }
27+
}
28+
29+
public bool IsTree
30+
{
31+
get { return Type == "tree"; }
32+
}
1733

1834
private bool isExpanded;
1935
private IEnumerable<GitTreeObject> children;
@@ -26,25 +42,45 @@ public IEnumerable<GitTreeObject> Children
2642
if (children == null)
2743
{
2844
if (!IsTree) return null;
29-
3045
if (!IsExpanded) return new List<GitTreeObject> { new GitTreeObject() }; // a place holder
3146

32-
var treeId = ObjectId.FromString(this.Id);
33-
34-
var tree = new Tree(repository, treeId, repository.Open(treeId).GetBytes());
35-
children = (from t in tree.Members()
36-
select new GitTreeObject
37-
{
38-
Id = t.GetId().Name,
39-
Name = t.GetName(),
40-
repository = this.repository,
41-
IsTree = t.GetMode().GetObjectType() == Constants.OBJ_TREE
42-
}).ToList();
47+
try
48+
{
49+
var tree = GitBash.Run("ls-tree -z \"" + Id + "\"", this.Repository);
50+
children = tree.Split(new char[] { '\0', '\n' })
51+
.Select(t=>ParseString(t))
52+
.OfType<GitTreeObject>();
53+
}
54+
catch (Exception ex)
55+
{
56+
Log.WriteLine("GitTreeObject.Children: {0} - {1}\r\n{2}", Id, this.Repository, ex.ToString());
57+
}
58+
4359
}
4460
return children;
4561
}
4662
}
4763

64+
private GitTreeObject ParseString(string itemsString)
65+
{
66+
if (string.IsNullOrWhiteSpace(itemsString) || (itemsString.Length <= 53))
67+
return null;
68+
69+
var guidStart = itemsString.IndexOf(' ', 7);
70+
var name = itemsString.Substring(guidStart + 42).Trim();
71+
var fullName = this.FullName.Length == 0 ? name : this.FullName + "/" + name;
72+
73+
return new GitTreeObject
74+
{
75+
Mode = itemsString.Substring(0, 6),
76+
Type = itemsString.Substring(7, guidStart - 7).ToLower(),
77+
Id = itemsString.Substring(guidStart + 1, 40),
78+
Name = name,
79+
FullName = fullName,
80+
Repository = this.Repository,
81+
};
82+
}
83+
4884
public bool IsExpanded
4985
{
5086
get { return isExpanded; }
@@ -59,14 +95,22 @@ public byte[] Content
5995
{
6096
get
6197
{
62-
if (!IsTree && content == null)
98+
if (IsBlob && content == null)
6399
{
64100
try
65101
{
66-
var blob = this.repository.Open(ObjectId.FromString(this.Id));
67-
if (blob != null) content = blob.GetCachedBytes();
102+
var fileName = Path.GetTempFileName();
103+
104+
GitBash.RunCmd(string.Format("cat-file blob {0} > {1}", this.Id, fileName), this.Repository);
105+
106+
content = File.ReadAllBytes(fileName);
107+
108+
if (File.Exists(fileName)) File.Delete(fileName);
109+
}
110+
catch (Exception ex)
111+
{
112+
Log.WriteLine("GitTreeObject.Content: {0} - {1}\r\n{2}", Id, this.Repository, ex.ToString());
68113
}
69-
catch { } //better than crash
70114
}
71115
return content;
72116
}

0 commit comments

Comments
 (0)