Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 015b5c1

Browse files
authored
Merge branch 'master' into feature/inline-reviews-commentbubble
2 parents 6776488 + 88821ed commit 015b5c1

File tree

17 files changed

+202
-109
lines changed

17 files changed

+202
-109
lines changed

src/GitHub.App/Factories/HostCacheFactory.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
using System;
22
using System.ComponentModel.Composition;
33
using System.IO;
4+
using System.Reactive.Linq;
45
using Akavache;
56
using GitHub.Primitives;
67
using Rothko;
78
using GitHub.Extensions;
9+
using System.Threading.Tasks;
810

911
namespace GitHub.Factories
1012
{
1113
[Export(typeof(IHostCacheFactory))]
1214
[PartCreationPolicy(CreationPolicy.Shared)]
1315
public class HostCacheFactory : IHostCacheFactory
1416
{
17+
const int CacheVersion = 1;
18+
const string CacheVersionKey = "cacheVersion";
19+
1520
readonly Lazy<IBlobCacheFactory> blobCacheFactory;
1621
readonly Lazy<IOperatingSystem> operatingSystem;
1722

@@ -22,7 +27,7 @@ public HostCacheFactory(Lazy<IBlobCacheFactory> blobCacheFactory, Lazy<IOperatin
2227
this.operatingSystem = operatingSystem;
2328
}
2429

25-
public IBlobCache Create(HostAddress hostAddress)
30+
public async Task<IBlobCache> Create(HostAddress hostAddress)
2631
{
2732
var environment = OperatingSystem.Environment;
2833
// For GitHub.com, the cache file name should be "api.github.com.cache.db"
@@ -34,7 +39,17 @@ public IBlobCache Create(HostAddress hostAddress)
3439

3540
// CreateDirectory is a noop if the directory already exists.
3641
OperatingSystem.Directory.CreateDirectory(Path.GetDirectoryName(userAccountPath));
37-
return BlobCacheFactory.CreateBlobCache(userAccountPath);
42+
43+
var cache = BlobCacheFactory.CreateBlobCache(userAccountPath);
44+
var version = await cache.GetOrCreateObject<int>(CacheVersionKey, () => 0);
45+
46+
if (version != CacheVersion)
47+
{
48+
await cache.InvalidateAll();
49+
await cache.InsertObject(CacheVersionKey, CacheVersion);
50+
}
51+
52+
return cache;
3853
}
3954

4055
IOperatingSystem OperatingSystem { get { return operatingSystem.Value; } }
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using Akavache;
22
using GitHub.Primitives;
33
using System;
4+
using System.Threading.Tasks;
45

56
namespace GitHub.Factories
67
{
78
public interface IHostCacheFactory : IDisposable
89
{
9-
IBlobCache Create(HostAddress hostAddress);
10+
Task<IBlobCache> Create(HostAddress hostAddress);
1011
}
1112
}

src/GitHub.App/Factories/RepositoryHostFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public RepositoryHostFactory(
4444
public async Task<IRepositoryHost> Create(HostAddress hostAddress)
4545
{
4646
var apiClient = await apiClientFactory.Create(hostAddress);
47-
var hostCache = hostCacheFactory.Create(hostAddress);
47+
var hostCache = await hostCacheFactory.Create(hostAddress);
4848
var modelService = new ModelService(apiClient, hostCache, avatarProvider);
4949
var host = new RepositoryHost(apiClient, modelService, loginManager, loginCache, usage);
5050
hosts.Add(host);

src/GitHub.App/Services/GitClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public Task<string> ExtractFile(IRepository repository, string commitSha, string
296296
return Task.Factory.StartNew(() =>
297297
{
298298
var commit = repository.Lookup<Commit>(commitSha);
299-
if(commit == null)
299+
if (commit == null)
300300
{
301301
throw new FileNotFoundException("Couldn't find '" + fileName + "' at commit " + commitSha + ".");
302302
}

src/GitHub.Extensions/StringExtensions.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,6 @@ public static string Wrap(this string text, int maxLength = 72)
180180
return sb.ToString();
181181
}
182182

183-
public static bool EqualsIgnoringLineEndings(this string a, string b)
184-
{
185-
if (ReferenceEquals(a, b))
186-
return true;
187-
188-
if (a == null || b == null)
189-
return false;
190-
191-
// TODO: Write a non-allocating comparison.
192-
a = a.Replace("\r\n", "\n");
193-
b = b.Replace("\r\n", "\n");
194-
195-
return a == b;
196-
}
197-
198183
public static Uri ToUriSafe(this string url)
199184
{
200185
Uri uri;

src/GitHub.InlineReviews/Commands/InlineCommentNavigationCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public override bool IsEnabled
4949
get
5050
{
5151
var tags = GetTags(GetCurrentTextViews());
52-
return tags.Count > 1;
52+
return tags.Count > 0;
5353
}
5454
}
5555

src/GitHub.InlineReviews/Glyph/GlyphData.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
namespace GitHub.InlineReviews.Glyph.Implementation
77
{
8+
/// <summary>
9+
/// Information about the position of a glyph.
10+
/// </summary>
11+
/// <typeparam name="TGlyphTag">The type of glyph tag we're dealing with.</typeparam>
812
internal class GlyphData<TGlyphTag>
913
{
1014
double deltaY;

src/GitHub.InlineReviews/Glyph/GlyphMargin.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
namespace GitHub.InlineReviews.Glyph
1414
{
15+
/// <summary>
16+
/// Responsibe for updating the margin when tags change.
17+
/// </summary>
18+
/// <typeparam name="TGlyphTag">The type of glyph tag we're managing.</typeparam>
1519
public sealed class GlyphMargin<TGlyphTag> : IWpfTextViewMargin, ITextViewMargin, IDisposable where TGlyphTag: ITag
1620
{
1721
bool handleZoom;

src/GitHub.InlineReviews/Glyph/GlyphMarginVisualManager.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
namespace GitHub.InlineReviews.Glyph.Implementation
1414
{
15+
/// <summary>
16+
/// Manage the MarginVisual element.
17+
/// </summary>
18+
/// <typeparam name="TGlyphTag">The type of tag we're managing.</typeparam>
1519
internal class GlyphMarginVisualManager<TGlyphTag> where TGlyphTag: ITag
1620
{
1721
readonly IEditorFormatMap editorFormatMap;
@@ -52,8 +56,6 @@ public GlyphMarginVisualManager(IWpfTextView textView, IGlyphFactory<TGlyphTag>
5256
}
5357
}
5458

55-
public FrameworkElement MarginVisual => glyphMarginGrid;
56-
5759
public void AddGlyph(TGlyphTag tag, SnapshotSpan span)
5860
{
5961
var textViewLines = textView.TextViewLines;
@@ -132,6 +134,7 @@ public void SetSnapshotAndUpdate(ITextSnapshot snapshot, IList<ITextViewLine> ne
132134
glyphs = dictionary;
133135
}
134136
}
137+
135138
static ITextViewLine GetStartingLine(IList<ITextViewLine> lines, Span span)
136139
{
137140
if (lines.Count > 0)
@@ -191,6 +194,8 @@ void UpdateBackgroundColor()
191194
ImageThemingUtilities.SetImageBackgroundColor(glyphMarginGrid, backgroundColor);
192195
}
193196
}
197+
198+
public FrameworkElement MarginVisual => glyphMarginGrid;
194199
}
195200
}
196201

src/GitHub.InlineReviews/Glyph/IGlyphFactory.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@
66

77
namespace GitHub.InlineReviews.Glyph
88
{
9+
/// <summary>
10+
/// A factory for a type of tag (or multiple subtypes).
11+
/// </summary>
12+
/// <typeparam name="TGlyphTag"></typeparam>
913
public interface IGlyphFactory<TGlyphTag> where TGlyphTag : ITag
1014
{
15+
/// <summary>
16+
/// Create a glyph element for a particular line and tag.
17+
/// </summary>
18+
/// <param name="line">The line.</param>
19+
/// <param name="tag">The tag.</param>
20+
/// <returns></returns>
1121
UIElement GenerateGlyph(IWpfTextViewLine line, TGlyphTag tag);
1222

23+
/// <summary>
24+
/// A list of tag subtypes this is a factory for.
25+
/// </summary>
26+
/// <returns></returns>
1327
IEnumerable<Type> GetTagTypes();
1428
}
1529
}

0 commit comments

Comments
 (0)