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
50 commits
Select commit Hold shift + click to select a range
722395d
Removing chunks from tests that no longer make sense
StanleyGoldman Nov 8, 2017
eaa2c3e
Removing testing of Repository from testing of RepositoryManager
StanleyGoldman Nov 8, 2017
fff4d5a
Merge remote-tracking branch 'remotes/origin/enhancements/test-script…
StanleyGoldman Nov 8, 2017
b9e67e6
Fixing test
StanleyGoldman Nov 8, 2017
55bb468
Enabling console logging for integration tests
StanleyGoldman Nov 8, 2017
d6a9ebe
Should not receive busy change events
StanleyGoldman Nov 8, 2017
0f51485
Dumping file watcher events
StanleyGoldman Nov 9, 2017
2256998
Merge branch 'master' into fixes/repository-manager-tests
StanleyGoldman Nov 13, 2017
41dfc1b
Merge branch 'fixes/roll-back-patches' into enhancements/repository-w…
StanleyGoldman Nov 14, 2017
ccd296e
Merge remote-tracking branch 'remotes/origin/fixes/bump-sfw' into enh…
StanleyGoldman Nov 14, 2017
dbff0aa
Merge branch 'enhancements/git-client-cache' into enhancements/reposi…
StanleyGoldman Nov 14, 2017
dbd2b91
Removing large swaths of code
StanleyGoldman Nov 14, 2017
90c180a
Removing more code
StanleyGoldman Nov 14, 2017
6f14401
Removing unused constant
StanleyGoldman Nov 14, 2017
6fe73d8
Merge branch 'fixes/repository-manager-tests' into enhancements/repos…
StanleyGoldman Nov 14, 2017
da7b314
Adding events to RepositoryWatcher and fixing RepositoryWatcherTests
StanleyGoldman Nov 14, 2017
ac085ea
Being sure to fire the RepositoryCommitted event
StanleyGoldman Nov 14, 2017
6beaaeb
Removing RepositoryUpdated event
StanleyGoldman Nov 14, 2017
62c3d14
More code cleanup
StanleyGoldman Nov 14, 2017
a54f8d9
Starting to take away responsibility from Repository
StanleyGoldman Nov 14, 2017
bddb47d
Responding to RepositoryManager events
StanleyGoldman Nov 14, 2017
f7df0db
Merge branch 'fixes/update-repository-info' into enhancements/reposit…
StanleyGoldman Nov 14, 2017
de66fac
Merge branch 'fixes/repository-initialize-git-commands' into enhancem…
StanleyGoldman Nov 14, 2017
3f828db
Calling update methods on RepositoryManager from Repository
StanleyGoldman Nov 14, 2017
ff1860a
Removing unused code
StanleyGoldman Nov 14, 2017
222bd5a
Fixing ShouldDetectFileChanges
StanleyGoldman Nov 14, 2017
cded7db
Fixing ShouldAddAndCommitFiles
StanleyGoldman Nov 14, 2017
37c3706
Fixing ShouldAddAndCommitAllFiles
StanleyGoldman Nov 14, 2017
6f91f16
Making RepositoryManagerTests more stable by attaching a listener bef…
StanleyGoldman Nov 14, 2017
eb55f8f
We need to wait for the event apparently
StanleyGoldman Nov 14, 2017
32641cc
Merge branch 'fixes/repository-initialize-git-commands' into enhancem…
StanleyGoldman Nov 21, 2017
8447452
Merge branch 'fixes/stop-watcher-for-commit' into enhancements/reposi…
StanleyGoldman Nov 21, 2017
4d426e9
Merge branch 'fixes/stop-watcher-for-commit' into enhancements/reposi…
StanleyGoldman Nov 21, 2017
b8f7453
Fixes needed after merge
StanleyGoldman Nov 21, 2017
fd5de38
Merge branch 'fixes/appveyor-failed-test-logs' into enhancements/repo…
StanleyGoldman Nov 21, 2017
1df8842
Merge branch 'enhancements/repository-watcher-refactor-rollup' into e…
StanleyGoldman Nov 21, 2017
4ba9708
Merge branch 'fixes/appveyor-failed-test-logs' into enhancements/repo…
StanleyGoldman Nov 21, 2017
5822ece
Adding milliseconds to file log output
StanleyGoldman Nov 22, 2017
d97e7ff
Adding more logging information to RepositoryManagerTests
StanleyGoldman Nov 22, 2017
b68befc
Removing ignores of TimeSensitive tests
StanleyGoldman Nov 22, 2017
62e45fb
Adding more logging detail to RepositoryWatcherTests
StanleyGoldman Nov 22, 2017
2585ec6
Merge branch 'enhancements/repository-watcher-refactor-rollup' into e…
StanleyGoldman Nov 22, 2017
3c16139
Setting RepositoryManagerTests and RepositoryWatcherTests to not run …
StanleyGoldman Nov 22, 2017
c1e05c1
Removing this bleed events functionality
StanleyGoldman Nov 22, 2017
9bcbf09
Disable ConsoleLogAdapter in test output
StanleyGoldman Nov 22, 2017
caf6dcc
Disabling detailed RepositoryWatcher output
StanleyGoldman Nov 22, 2017
9bcd18e
The User object should not immediately force an update of user data
StanleyGoldman Nov 22, 2017
7592d24
Being sure InvalidateData if LastUpdatedAt or LastVerifiedAt is called
StanleyGoldman Nov 22, 2017
2b571f8
Checking if RepositoryManager is null if cache events come in before
StanleyGoldman Nov 22, 2017
f36b5a3
Changing funciton order
StanleyGoldman Nov 27, 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
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ test:
categories:
except:
- DoNotRunOnAppVeyor
- TimeSensitive
artifacts:
- path: unity\PackageProject
type: zip
Expand Down
219 changes: 36 additions & 183 deletions src/GitHub.Api/Events/RepositoryWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ interface IRepositoryWatcher : IDisposable
event Action HeadChanged;
event Action IndexChanged;
event Action ConfigChanged;
event Action<string> LocalBranchChanged;
event Action<string> LocalBranchCreated;
event Action<string> LocalBranchDeleted;
event Action RepositoryCommitted;
event Action RepositoryChanged;
event Action<string, string> RemoteBranchCreated;
event Action<string, string> RemoteBranchDeleted;
event Action LocalBranchesChanged;
event Action RemoteBranchesChanged;
void Initialize();
int CheckAndProcessEvents();
}
Expand All @@ -39,12 +37,10 @@ class RepositoryWatcher : IRepositoryWatcher
public event Action HeadChanged;
public event Action IndexChanged;
public event Action ConfigChanged;
public event Action<string> LocalBranchChanged;
public event Action<string> LocalBranchCreated;
public event Action<string> LocalBranchDeleted;
public event Action RepositoryCommitted;
public event Action RepositoryChanged;
public event Action<string, string> RemoteBranchCreated;
public event Action<string, string> RemoteBranchDeleted;
public event Action LocalBranchesChanged;
public event Action RemoteBranchesChanged;

public RepositoryWatcher(IPlatform platform, RepositoryPathConfiguration paths, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -193,118 +189,17 @@ private int ProcessEvents(Event[] fileEvents)
{
events.Add(EventType.IndexChanged, null);
}
else if (fileA.IsChildOf(paths.RemotesPath))
else if (!events.ContainsKey(EventType.RemoteBranchesChanged) && fileA.IsChildOf(paths.RemotesPath))
{
var relativePath = fileA.RelativeTo(paths.RemotesPath);
var relativePathElements = relativePath.Elements.ToArray();

if (!relativePathElements.Any())
{
continue;
}

var origin = relativePathElements[0];

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

var branch = string.Join(@"/", relativePathElements.Skip(1).ToArray());
AddOrUpdateEventData(events, EventType.RemoteBranchDeleted, new EventData { Origin = origin, Branch = branch });
}
else if (fileEvent.Type == sfw.net.EventType.RENAMED)
{
if (fileA.ExtensionWithDot != ".lock")
{
continue;
}

if (fileB != null && fileB.FileExists())
{
if (fileA.FileNameWithoutExtension == fileB.FileNameWithoutExtension)
{
var branchPathElement = relativePathElements
.Skip(1).Take(relativePathElements.Length - 2)
.Union(new[] { fileA.FileNameWithoutExtension }).ToArray();

var branch = string.Join(@"/", branchPathElement);
AddOrUpdateEventData(events, EventType.RemoteBranchCreated, new EventData { Origin = origin, Branch = branch });
}
}
}
events.Add(EventType.RemoteBranchesChanged, null);
}
else if (fileA.IsChildOf(paths.BranchesPath))
else if (!events.ContainsKey(EventType.LocalBranchesChanged) && fileA.IsChildOf(paths.BranchesPath))
{
if (fileEvent.Type == sfw.net.EventType.MODIFIED)
{
if (fileA.DirectoryExists())
{
continue;
}

if (fileA.ExtensionWithDot == ".lock")
{
continue;
}

var relativePath = fileA.RelativeTo(paths.BranchesPath);
var relativePathElements = relativePath.Elements.ToArray();

if (!relativePathElements.Any())
{
continue;
}

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

AddOrUpdateEventData(events, EventType.LocalBranchChanged, new EventData { Branch = branch });

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

var relativePath = fileA.RelativeTo(paths.BranchesPath);
var relativePathElements = relativePath.Elements.ToArray();

if (!relativePathElements.Any())
{
continue;
}

var branch = string.Join(@"/", relativePathElements.ToArray());
AddOrUpdateEventData(events, EventType.LocalBranchDeleted, new EventData { Branch = branch });
}
else if (fileEvent.Type == sfw.net.EventType.RENAMED)
{
if (fileA.ExtensionWithDot != ".lock")
{
continue;
}

if (fileB != null && fileB.FileExists())
{
if (fileA.FileNameWithoutExtension == fileB.FileNameWithoutExtension)
{
var relativePath = fileB.RelativeTo(paths.BranchesPath);
var relativePathElements = relativePath.Elements.ToArray();

if (!relativePathElements.Any())
{
continue;
}

var branch = string.Join(@"/", relativePathElements.ToArray());
AddOrUpdateEventData(events, EventType.LocalBranchCreated, new EventData { Branch = branch });
}
}
}
events.Add(EventType.LocalBranchesChanged, null);
}
else if (!events.ContainsKey(EventType.RepositoryCommitted) && fileA.IsChildOf(paths.DotGitCommitEditMsg))
{
events.Add(EventType.RepositoryCommitted, null);
}
}
else
Expand All @@ -320,13 +215,6 @@ private int ProcessEvents(Event[] fileEvents)
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;
Expand All @@ -344,74 +232,41 @@ private int FireEvents(Dictionary<EventType, List<EventData>> events)
eventsProcessed++;
}

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

if (events.ContainsKey(EventType.RepositoryChanged))
if (events.ContainsKey(EventType.RemoteBranchesChanged))
{
Logger.Trace("RepositoryChanged");
RepositoryChanged?.Invoke();
Logger.Trace("RemoteBranchesChanged");
RemoteBranchesChanged?.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))
if (events.ContainsKey(EventType.IndexChanged))
{
foreach (var evt in localBranchesChanged)
{
Logger.Trace($"LocalBranchChanged: {evt.Branch}");
LocalBranchChanged?.Invoke(evt.Branch);
eventsProcessed++;
}
Logger.Trace("IndexChanged");
IndexChanged?.Invoke();
eventsProcessed++;
}

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

List<EventData> remoteBranchesCreated;
if (events.TryGetValue(EventType.RemoteBranchCreated, out remoteBranchesCreated))
if (events.ContainsKey(EventType.RepositoryCommitted))
{
foreach (var evt in remoteBranchesCreated)
{
Logger.Trace($"RemoteBranchCreated: {evt.Origin}/{evt.Branch}");
RemoteBranchCreated?.Invoke(evt.Origin, evt.Branch);
eventsProcessed++;
}
Logger.Trace("RepositoryCommitted");
RepositoryCommitted?.Invoke();
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 @@ -445,13 +300,11 @@ private enum EventType
None,
ConfigChanged,
HeadChanged,
RepositoryChanged,
IndexChanged,
RemoteBranchDeleted,
RemoteBranchCreated,
LocalBranchDeleted,
LocalBranchCreated,
LocalBranchChanged
LocalBranchesChanged,
RemoteBranchesChanged,
RepositoryChanged,
RepositoryCommitted
}

private class EventData
Expand Down
Loading