Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
f9f2818
Starting to refactor
StanleyGoldman Sep 14, 2017
95be3e6
Tweaking spaces
StanleyGoldman Sep 15, 2017
8af8b26
Removing more spaces
StanleyGoldman Sep 15, 2017
45a0150
Restoring properties
StanleyGoldman Sep 15, 2017
c12bd65
Renaming some events and event handlers, making sure all events are h…
StanleyGoldman Sep 15, 2017
859bd85
Renaming events to machine other Repository events
StanleyGoldman Sep 15, 2017
0c2d806
Missing event raise
StanleyGoldman Sep 15, 2017
756389f
Renaming variables
StanleyGoldman Sep 15, 2017
7dd3a3b
Removing space
StanleyGoldman Sep 15, 2017
a3c60e6
Fixing the build of tests
StanleyGoldman Sep 15, 2017
e13bead
Merge branch 'master' into fixes/repository-refactor
StanleyGoldman Sep 15, 2017
74c8c11
Fixing tests
StanleyGoldman Sep 15, 2017
8e3663b
Merge branch 'fixes/batching-repository-watcher' into fixes/repositor…
StanleyGoldman Sep 15, 2017
398ae8d
Moving log message to external function
StanleyGoldman Sep 15, 2017
f96a81b
Merge branch 'fixes/batching-repository-watcher' into fixes/repositor…
StanleyGoldman Sep 15, 2017
1c52b6e
Merge branch 'fixes/batching-repository-watcher' into fixes/repositor…
StanleyGoldman Sep 15, 2017
b025c2c
Removing references from UnitTest project
StanleyGoldman Sep 15, 2017
b7076c3
Fixing up tests
StanleyGoldman Sep 15, 2017
db2d304
Last bit of test fixes
StanleyGoldman Sep 15, 2017
d6c22fe
Merge branch 'master' into fixes/repository-refactor
shana Sep 18, 2017
1756035
Adding tests for Repository
StanleyGoldman Sep 18, 2017
9b5088a
Properly updating repository info
StanleyGoldman Sep 18, 2017
d834e25
Merge branch 'master' into fixes/repository-refactor
StanleyGoldman Sep 18, 2017
e8fb83b
Uncommenting some code
StanleyGoldman Sep 18, 2017
090c54c
Removing ConsoleLogAdapter from SetUpFixtures
StanleyGoldman Sep 18, 2017
e47cfac
Merge branch 'fixes/integration-tests' into fixes/repository-refactor
StanleyGoldman Sep 18, 2017
cb17d01
Firing RepositoryWatcher events as soon as possible
StanleyGoldman Sep 18, 2017
2a06427
Changing the OnHeadUpdated handler
StanleyGoldman Sep 18, 2017
77ee03b
Removing extra call to OnHeadUpdated
StanleyGoldman Sep 18, 2017
bf4a04d
Updating with OnHeadUpdated signature
StanleyGoldman Sep 18, 2017
3439858
Updating test
StanleyGoldman Sep 18, 2017
85f5335
Merge branch 'fixes/repository-watcher-batching-fix' into fixes/repos…
StanleyGoldman Sep 18, 2017
8abdd38
Populating list of remotes
StanleyGoldman Sep 18, 2017
fac4159
Fixing tests
StanleyGoldman Sep 18, 2017
7ac8b04
Removing some commented out test code
StanleyGoldman Sep 18, 2017
9c34cdc
Merge branch 'fixes/repository-watcher-batching-fix' into fixes/repos…
StanleyGoldman Sep 18, 2017
0773af0
Removing unused test
StanleyGoldman Sep 18, 2017
6dcc6c7
Preventing exception for remotes without branches
StanleyGoldman Sep 18, 2017
7d4bd54
Adding more detail to tests
StanleyGoldman Sep 18, 2017
3b4d77e
Missing fix
StanleyGoldman Sep 18, 2017
4b6c178
Merge branch 'fixes/integration-tests' into fixes/repository-watcher-…
StanleyGoldman Sep 18, 2017
553c13b
Fixing tests
StanleyGoldman Sep 19, 2017
fdfe8f9
Merge branch 'fixes/repository-watcher-batching-fix' into fixes/repos…
StanleyGoldman Sep 19, 2017
9218b2c
Fixing the name casing of this file
StanleyGoldman Sep 19, 2017
eec0b47
Merge branch 'fixes/integration-tests' into fixes/repository-refactor
StanleyGoldman Sep 19, 2017
73c873e
Adding warning messages in the event that branch operations cannot be…
StanleyGoldman Sep 19, 2017
8602fba
Updating tests with value checks
StanleyGoldman Sep 19, 2017
ff3c8bf
Merge branch 'master' into fixes/repository-refactor
StanleyGoldman Sep 19, 2017
4efffc9
Moving head processing back to RepositoryManager
StanleyGoldman Sep 20, 2017
2dbfba2
Fixing more unit tests
StanleyGoldman Sep 20, 2017
c4aeec6
Merge branch 'master' into fixes/repository-refactor
StanleyGoldman Sep 20, 2017
7a5abbd
Merge branch 'master' into fixes/repository-refactor
StanleyGoldman Sep 21, 2017
c497641
Attempting to add a remotes list; Reordered file
StanleyGoldman Sep 21, 2017
6f0d6ab
Making all the unit tests pass
StanleyGoldman Sep 21, 2017
d3f6af9
Making Repository return GitBranch and GitRemote instead of ConfigBra…
StanleyGoldman Sep 21, 2017
a4ceed1
Stackoverflow bufix
StanleyGoldman Sep 21, 2017
c81e885
Fixing the update after removing a remote when it is active
StanleyGoldman Sep 21, 2017
de434cd
Removing unintentional change
StanleyGoldman Sep 21, 2017
1e83fe3
Fixing integration test
StanleyGoldman Sep 22, 2017
6e77812
Commenting out ConsoleLogAdapter in SetUpFixture
StanleyGoldman Sep 22, 2017
2238a80
Fixing branch selection when not named in config
StanleyGoldman Sep 22, 2017
76e6229
Merge branch 'master' into fixes/repository-refactor
StanleyGoldman Oct 10, 2017
955cb70
Updating branches after enabled
StanleyGoldman Oct 10, 2017
c09e081
Renaming method
StanleyGoldman Oct 10, 2017
cead15a
Fixing the reactions to events in the UI
StanleyGoldman Oct 10, 2017
185573c
Simplying branch updating
StanleyGoldman Oct 11, 2017
b6959c7
Putting UpdateLog back in Refresh Method; Removing from OnUpdated
StanleyGoldman Oct 11, 2017
b3639d8
Renaming methods
StanleyGoldman Oct 11, 2017
b06a737
Moving UpdateLog functionality to Window
StanleyGoldman Oct 11, 2017
1a65195
Refreshing the log cache properly
StanleyGoldman Oct 11, 2017
87d9811
Merge branch 'master' into fixes/repository-refactor
StanleyGoldman Oct 11, 2017
12eac94
Split event processing and process firing
Oct 16, 2017
a2e6a52
Put things in their proper place
Oct 16, 2017
9b776d1
Using TryGet to fire events
StanleyGoldman Oct 16, 2017
28af575
Merge pull request #369 from github-for-unity/stanley/queueing-watche…
shana Oct 17, 2017
6966e57
Remove unused event
shana Oct 17, 2017
0cd5b78
Merge pull request #368 from github-for-unity/shana/queueing-watcher-…
StanleyGoldman Oct 17, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 115 additions & 54 deletions src/GitHub.Api/Events/RepositoryWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface IRepositoryWatcher : IDisposable
{
void Start();
void Stop();
event Action<string> HeadChanged;
event Action HeadChanged;
event Action IndexChanged;
event Action ConfigChanged;
event Action<string> LocalBranchChanged;
Expand All @@ -38,7 +38,7 @@ class RepositoryWatcher : IRepositoryWatcher
private bool processingEvents;
private readonly ManualResetEventSlim signalProcessingEventsDone = new ManualResetEventSlim(false);

public event Action<string> HeadChanged;
public event Action HeadChanged;
public event Action IndexChanged;
public event Action ConfigChanged;
public event Action<string> LocalBranchChanged;
Expand Down Expand Up @@ -162,14 +162,7 @@ public int CheckAndProcessEvents()

private int ProcessEvents(Event[] fileEvents)
{
var eventsProcessed = 0;
var configChanged = false;
var headChanged = false;
var repositoryChanged = false;
var indexChanged = false;

string headContent = null;

Dictionary<EventType, List<EventData>> events = new Dictionary<EventType, List<EventData>>();
foreach (var fileEvent in fileEvents)
{
if (!running)
Expand Down Expand Up @@ -197,22 +190,17 @@ private int ProcessEvents(Event[] fileEvents)
// handling events in .git/*
if (fileA.IsChildOf(paths.DotGitPath))
{
if (!configChanged && fileA.Equals(paths.DotGitConfig))
if (!events.ContainsKey(EventType.ConfigChanged) && fileA.Equals(paths.DotGitConfig))
{
configChanged = true;
events.Add(EventType.ConfigChanged, null);
}
else if (!headChanged && fileA.Equals(paths.DotGitHead))
else if (!events.ContainsKey(EventType.HeadChanged) && fileA.Equals(paths.DotGitHead))
{
if (fileEvent.Type != EventType.DELETED)
{
headContent = paths.DotGitHead.ReadAllLines().FirstOrDefault();
}

headChanged = true;
events.Add(EventType.HeadChanged, null);
}
else if (!indexChanged && fileA.Equals(paths.DotGitIndex))
else if (!events.ContainsKey(EventType.IndexChanged) && fileA.Equals(paths.DotGitIndex))
{
indexChanged = true;
events.Add(EventType.IndexChanged, null);
}
else if (fileA.IsChildOf(paths.RemotesPath))
{
Expand All @@ -226,20 +214,17 @@ private int ProcessEvents(Event[] fileEvents)

var origin = relativePathElements[0];

if (fileEvent.Type == EventType.DELETED)
if (fileEvent.Type == sfw.net.EventType.DELETED)
{
if (fileA.ExtensionWithDot == ".lock")
{
continue;
}

var branch = string.Join(@"/", relativePathElements.Skip(1).ToArray());

Logger.Trace("RemoteBranchDeleted: {0}/{1}", origin, branch);
RemoteBranchDeleted?.Invoke(origin, branch);
eventsProcessed++;
AddOrUpdateEventData(events, EventType.RemoteBranchDeleted, new EventData { Origin = origin, Branch = branch });
}
else if (fileEvent.Type == EventType.RENAMED)
else if (fileEvent.Type == sfw.net.EventType.RENAMED)
{
if (fileA.ExtensionWithDot != ".lock")
{
Expand All @@ -255,17 +240,14 @@ private int ProcessEvents(Event[] fileEvents)
.Union(new[] { fileA.FileNameWithoutExtension }).ToArray();

var branch = string.Join(@"/", branchPathElement);

Logger.Trace("RemoteBranchCreated: {0}/{1}", origin, branch);
RemoteBranchCreated?.Invoke(origin, branch);
eventsProcessed++;
AddOrUpdateEventData(events, EventType.RemoteBranchCreated, new EventData { Origin = origin, Branch = branch });
}
}
}
}
else if (fileA.IsChildOf(paths.BranchesPath))
{
if (fileEvent.Type == EventType.MODIFIED)
if (fileEvent.Type == sfw.net.EventType.MODIFIED)
{
if (fileA.DirectoryExists())
{
Expand All @@ -287,11 +269,10 @@ private int ProcessEvents(Event[] fileEvents)

var branch = string.Join(@"/", relativePathElements.ToArray());

Logger.Trace("LocalBranchChanged: {0}", branch);
LocalBranchChanged?.Invoke(branch);
eventsProcessed++;
AddOrUpdateEventData(events, EventType.LocalBranchChanged, new EventData { Branch = branch });

}
else if (fileEvent.Type == EventType.DELETED)
else if (fileEvent.Type == sfw.net.EventType.DELETED)
{
if (fileA.ExtensionWithDot == ".lock")
{
Expand All @@ -307,12 +288,9 @@ private int ProcessEvents(Event[] fileEvents)
}

var branch = string.Join(@"/", relativePathElements.ToArray());

Logger.Trace("LocalBranchDeleted: {0}", branch);
LocalBranchDeleted?.Invoke(branch);
eventsProcessed++;
AddOrUpdateEventData(events, EventType.LocalBranchDeleted, new EventData { Branch = branch });
}
else if (fileEvent.Type == EventType.RENAMED)
else if (fileEvent.Type == sfw.net.EventType.RENAMED)
{
if (fileA.ExtensionWithDot != ".lock")
{
Expand All @@ -332,54 +310,117 @@ private int ProcessEvents(Event[] fileEvents)
}

var branch = string.Join(@"/", relativePathElements.ToArray());

Logger.Trace("LocalBranchCreated: {0}", branch);
LocalBranchCreated?.Invoke(branch);
eventsProcessed++;
AddOrUpdateEventData(events, EventType.LocalBranchCreated, new EventData { Branch = branch });
}
}
}
}
}
else
{
if (repositoryChanged || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
if (events.ContainsKey(EventType.RepositoryChanged) || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
{
continue;
}

repositoryChanged = true;
events.Add(EventType.RepositoryChanged, null);
}
}

if (configChanged)
return FireEvents(events);
}

private void AddOrUpdateEventData(Dictionary<EventType, List<EventData>> events, EventType type, EventData data)
{
if (!events.ContainsKey(type))
events.Add(type, new List<EventData>());
events[type].Add(data);
}

private int FireEvents(Dictionary<EventType, List<EventData>> events)
{
int eventsProcessed = 0;
if (events.ContainsKey(EventType.ConfigChanged))
{
Logger.Trace("ConfigChanged");
ConfigChanged?.Invoke();
eventsProcessed++;
}

if (headChanged)
if (events.ContainsKey(EventType.HeadChanged))
{
Logger.Trace("HeadChanged: {0}", headContent ?? "[null]");
HeadChanged?.Invoke(headContent);
Logger.Trace("HeadChanged");
HeadChanged?.Invoke();
eventsProcessed++;
}

if (indexChanged)
if (events.ContainsKey(EventType.IndexChanged))
{
Logger.Trace("IndexChanged");
IndexChanged?.Invoke();
eventsProcessed++;
}

if (repositoryChanged)
if (events.ContainsKey(EventType.RepositoryChanged))
{
Logger.Trace("RepositoryChanged");
RepositoryChanged?.Invoke();
eventsProcessed++;
}

List<EventData> localBranchesCreated;
if (events.TryGetValue(EventType.LocalBranchCreated, out localBranchesCreated))
{
foreach (var evt in localBranchesCreated)
{
Logger.Trace($"LocalBranchCreated: {evt.Branch}");
LocalBranchCreated?.Invoke(evt.Branch);
eventsProcessed++;
}
}

List<EventData> localBranchesChanged;
if (events.TryGetValue(EventType.LocalBranchChanged, out localBranchesChanged))
{
foreach (var evt in localBranchesChanged)
{
Logger.Trace($"LocalBranchChanged: {evt.Branch}");
LocalBranchChanged?.Invoke(evt.Branch);
eventsProcessed++;
}
}

List<EventData> localBranchesDeleted;
if (events.TryGetValue(EventType.LocalBranchDeleted, out localBranchesDeleted))
{
foreach (var evt in localBranchesDeleted)
{
Logger.Trace($"LocalBranchDeleted: {evt.Branch}");
LocalBranchDeleted?.Invoke(evt.Branch);
eventsProcessed++;
}
}

List<EventData> remoteBranchesCreated;
if (events.TryGetValue(EventType.RemoteBranchCreated, out remoteBranchesCreated))
{
foreach (var evt in remoteBranchesCreated)
{
Logger.Trace($"RemoteBranchCreated: {evt.Origin}/{evt.Branch}");
RemoteBranchCreated?.Invoke(evt.Origin, evt.Branch);
eventsProcessed++;
}
}

List<EventData> remoteBranchesDeleted;
if (events.TryGetValue(EventType.RemoteBranchDeleted, out remoteBranchesDeleted))
{
foreach (var evt in remoteBranchesDeleted)
{
Logger.Trace($"RemoteBranchDeleted: {evt.Origin}/{evt.Branch}");
RemoteBranchDeleted?.Invoke(evt.Origin, evt.Branch);
eventsProcessed++;
}
}
return eventsProcessed;
}

Expand Down Expand Up @@ -407,5 +448,25 @@ public void Dispose()
}

protected static ILogging Logger { get; } = Logging.GetLogger<RepositoryWatcher>();

private enum EventType
{
None,
ConfigChanged,
HeadChanged,
RepositoryChanged,
IndexChanged,
RemoteBranchDeleted,
RemoteBranchCreated,
LocalBranchDeleted,
LocalBranchCreated,
LocalBranchChanged
}

private class EventData
{
public string Origin;
public string Branch;
}
}
}
4 changes: 2 additions & 2 deletions src/GitHub.Api/Git/GitRemote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace GitHub.Unity
{
enum GitRemoteFunction
public enum GitRemoteFunction
{
Unknown,
Fetch,
Expand All @@ -12,7 +12,7 @@ enum GitRemoteFunction
}

[Serializable]
struct GitRemote
public struct GitRemote
{
public string Name;
public string Url;
Expand Down
20 changes: 11 additions & 9 deletions src/GitHub.Api/Git/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,26 @@ public interface IRepository : IEquatable<IRepository>
/// <summary>
/// Gets the current remote of the repository.
/// </summary>
ConfigRemote? CurrentRemote { get; set; }
GitRemote? CurrentRemote { get; }
/// <summary>
/// Gets the current branch of the repository.
/// </summary>
ConfigBranch? CurrentBranch { get; set; }
GitStatus CurrentStatus { get; set; }
GitBranch? CurrentBranch { get; }
GitStatus CurrentStatus { get; }
IList<GitRemote> Remotes { get; }
IEnumerable<GitBranch> LocalBranches { get; }
IEnumerable<GitBranch> RemoteBranches { get; }
IUser User { get; set; }
IEnumerable<GitLock> CurrentLocks { get; }
IList<GitLock> CurrentLocks { get; }
string CurrentBranchName { get; }

event Action<GitStatus> OnStatusUpdated;
event Action<string> OnActiveBranchChanged;
event Action<string> OnActiveRemoteChanged;
event Action<GitStatus> OnStatusChanged;
event Action<string> OnCurrentBranchChanged;
event Action<string> OnCurrentRemoteChanged;
event Action OnLocalBranchListChanged;
event Action OnHeadChanged;
event Action<IEnumerable<GitLock>> OnLocksUpdated;
event Action OnCurrentBranchUpdated;
event Action<IEnumerable<GitLock>> OnLocksChanged;
event Action OnRepositoryInfoChanged;
event Action OnRemoteBranchListChanged;
}
}
Loading