@@ -14,12 +14,10 @@ interface IRepositoryWatcher : IDisposable
1414 event Action HeadChanged ;
1515 event Action IndexChanged ;
1616 event Action ConfigChanged ;
17- event Action < string > LocalBranchChanged ;
18- event Action < string > LocalBranchCreated ;
19- event Action < string > LocalBranchDeleted ;
17+ event Action RepositoryCommitted ;
2018 event Action RepositoryChanged ;
21- event Action < string , string > RemoteBranchCreated ;
22- event Action < string , string > RemoteBranchDeleted ;
19+ event Action LocalBranchesChanged ;
20+ event Action RemoteBranchesChanged ;
2321 void Initialize ( ) ;
2422 int CheckAndProcessEvents ( ) ;
2523 }
@@ -39,12 +37,10 @@ class RepositoryWatcher : IRepositoryWatcher
3937 public event Action HeadChanged ;
4038 public event Action IndexChanged ;
4139 public event Action ConfigChanged ;
42- public event Action < string > LocalBranchChanged ;
43- public event Action < string > LocalBranchCreated ;
44- public event Action < string > LocalBranchDeleted ;
40+ public event Action RepositoryCommitted ;
4541 public event Action RepositoryChanged ;
46- public event Action < string , string > RemoteBranchCreated ;
47- public event Action < string , string > RemoteBranchDeleted ;
42+ public event Action LocalBranchesChanged ;
43+ public event Action RemoteBranchesChanged ;
4844
4945 public RepositoryWatcher ( IPlatform platform , RepositoryPathConfiguration paths , CancellationToken cancellationToken )
5046 {
@@ -193,118 +189,17 @@ private int ProcessEvents(Event[] fileEvents)
193189 {
194190 events . Add ( EventType . IndexChanged , null ) ;
195191 }
196- else if ( fileA . IsChildOf ( paths . RemotesPath ) )
192+ else if ( ! events . ContainsKey ( EventType . RemoteBranchesChanged ) && fileA . IsChildOf ( paths . RemotesPath ) )
197193 {
198- var relativePath = fileA . RelativeTo ( paths . RemotesPath ) ;
199- var relativePathElements = relativePath . Elements . ToArray ( ) ;
200-
201- if ( ! relativePathElements . Any ( ) )
202- {
203- continue ;
204- }
205-
206- var origin = relativePathElements [ 0 ] ;
207-
208- if ( fileEvent . Type == sfw . net . EventType . DELETED )
209- {
210- if ( fileA . ExtensionWithDot == ".lock" )
211- {
212- continue ;
213- }
214-
215- var branch = string . Join ( @"/" , relativePathElements . Skip ( 1 ) . ToArray ( ) ) ;
216- AddOrUpdateEventData ( events , EventType . RemoteBranchDeleted , new EventData { Origin = origin , Branch = branch } ) ;
217- }
218- else if ( fileEvent . Type == sfw . net . EventType . RENAMED )
219- {
220- if ( fileA . ExtensionWithDot != ".lock" )
221- {
222- continue ;
223- }
224-
225- if ( fileB != null && fileB . FileExists ( ) )
226- {
227- if ( fileA . FileNameWithoutExtension == fileB . FileNameWithoutExtension )
228- {
229- var branchPathElement = relativePathElements
230- . Skip ( 1 ) . Take ( relativePathElements . Length - 2 )
231- . Union ( new [ ] { fileA . FileNameWithoutExtension } ) . ToArray ( ) ;
232-
233- var branch = string . Join ( @"/" , branchPathElement ) ;
234- AddOrUpdateEventData ( events , EventType . RemoteBranchCreated , new EventData { Origin = origin , Branch = branch } ) ;
235- }
236- }
237- }
194+ events . Add ( EventType . RemoteBranchesChanged , null ) ;
238195 }
239- else if ( fileA . IsChildOf ( paths . BranchesPath ) )
196+ else if ( ! events . ContainsKey ( EventType . LocalBranchesChanged ) && fileA . IsChildOf ( paths . BranchesPath ) )
240197 {
241- if ( fileEvent . Type == sfw . net . EventType . MODIFIED )
242- {
243- if ( fileA . DirectoryExists ( ) )
244- {
245- continue ;
246- }
247-
248- if ( fileA . ExtensionWithDot == ".lock" )
249- {
250- continue ;
251- }
252-
253- var relativePath = fileA . RelativeTo ( paths . BranchesPath ) ;
254- var relativePathElements = relativePath . Elements . ToArray ( ) ;
255-
256- if ( ! relativePathElements . Any ( ) )
257- {
258- continue ;
259- }
260-
261- var branch = string . Join ( @"/" , relativePathElements . ToArray ( ) ) ;
262-
263- AddOrUpdateEventData ( events , EventType . LocalBranchChanged , new EventData { Branch = branch } ) ;
264-
265- }
266- else if ( fileEvent . Type == sfw . net . EventType . DELETED )
267- {
268- if ( fileA . ExtensionWithDot == ".lock" )
269- {
270- continue ;
271- }
272-
273- var relativePath = fileA . RelativeTo ( paths . BranchesPath ) ;
274- var relativePathElements = relativePath . Elements . ToArray ( ) ;
275-
276- if ( ! relativePathElements . Any ( ) )
277- {
278- continue ;
279- }
280-
281- var branch = string . Join ( @"/" , relativePathElements . ToArray ( ) ) ;
282- AddOrUpdateEventData ( events , EventType . LocalBranchDeleted , new EventData { Branch = branch } ) ;
283- }
284- else if ( fileEvent . Type == sfw . net . EventType . RENAMED )
285- {
286- if ( fileA . ExtensionWithDot != ".lock" )
287- {
288- continue ;
289- }
290-
291- if ( fileB != null && fileB . FileExists ( ) )
292- {
293- if ( fileA . FileNameWithoutExtension == fileB . FileNameWithoutExtension )
294- {
295- var relativePath = fileB . RelativeTo ( paths . BranchesPath ) ;
296- var relativePathElements = relativePath . Elements . ToArray ( ) ;
297-
298- if ( ! relativePathElements . Any ( ) )
299- {
300- continue ;
301- }
302-
303- var branch = string . Join ( @"/" , relativePathElements . ToArray ( ) ) ;
304- AddOrUpdateEventData ( events , EventType . LocalBranchCreated , new EventData { Branch = branch } ) ;
305- }
306- }
307- }
198+ events . Add ( EventType . LocalBranchesChanged , null ) ;
199+ }
200+ else if ( ! events . ContainsKey ( EventType . RepositoryCommitted ) && fileA . IsChildOf ( paths . DotGitCommitEditMsg ) )
201+ {
202+ events . Add ( EventType . RepositoryCommitted , null ) ;
308203 }
309204 }
310205 else
@@ -320,13 +215,6 @@ private int ProcessEvents(Event[] fileEvents)
320215 return FireEvents ( events ) ;
321216 }
322217
323- private void AddOrUpdateEventData ( Dictionary < EventType , List < EventData > > events , EventType type , EventData data )
324- {
325- if ( ! events . ContainsKey ( type ) )
326- events . Add ( type , new List < EventData > ( ) ) ;
327- events [ type ] . Add ( data ) ;
328- }
329-
330218 private int FireEvents ( Dictionary < EventType , List < EventData > > events )
331219 {
332220 int eventsProcessed = 0 ;
@@ -344,74 +232,41 @@ private int FireEvents(Dictionary<EventType, List<EventData>> events)
344232 eventsProcessed ++ ;
345233 }
346234
347- if ( events . ContainsKey ( EventType . IndexChanged ) )
235+ if ( events . ContainsKey ( EventType . LocalBranchesChanged ) )
348236 {
349- Logger . Trace ( "IndexChanged " ) ;
350- IndexChanged ? . Invoke ( ) ;
237+ Logger . Trace ( "LocalBranchesChanged " ) ;
238+ LocalBranchesChanged ? . Invoke ( ) ;
351239 eventsProcessed ++ ;
352240 }
353241
354- if ( events . ContainsKey ( EventType . RepositoryChanged ) )
242+ if ( events . ContainsKey ( EventType . RemoteBranchesChanged ) )
355243 {
356- Logger . Trace ( "RepositoryChanged " ) ;
357- RepositoryChanged ? . Invoke ( ) ;
244+ Logger . Trace ( "RemoteBranchesChanged " ) ;
245+ RemoteBranchesChanged ? . Invoke ( ) ;
358246 eventsProcessed ++ ;
359247 }
360248
361- List < EventData > localBranchesCreated ;
362- if ( events . TryGetValue ( EventType . LocalBranchCreated , out localBranchesCreated ) )
363- {
364- foreach ( var evt in localBranchesCreated )
365- {
366- Logger . Trace ( $ "LocalBranchCreated: { evt . Branch } ") ;
367- LocalBranchCreated ? . Invoke ( evt . Branch ) ;
368- eventsProcessed ++ ;
369- }
370- }
371-
372- List < EventData > localBranchesChanged ;
373- if ( events . TryGetValue ( EventType . LocalBranchChanged , out localBranchesChanged ) )
249+ if ( events . ContainsKey ( EventType . IndexChanged ) )
374250 {
375- foreach ( var evt in localBranchesChanged )
376- {
377- Logger . Trace ( $ "LocalBranchChanged: { evt . Branch } ") ;
378- LocalBranchChanged ? . Invoke ( evt . Branch ) ;
379- eventsProcessed ++ ;
380- }
251+ Logger . Trace ( "IndexChanged" ) ;
252+ IndexChanged ? . Invoke ( ) ;
253+ eventsProcessed ++ ;
381254 }
382255
383- List < EventData > localBranchesDeleted ;
384- if ( events . TryGetValue ( EventType . LocalBranchDeleted , out localBranchesDeleted ) )
256+ if ( events . ContainsKey ( EventType . RepositoryChanged ) )
385257 {
386- foreach ( var evt in localBranchesDeleted )
387- {
388- Logger . Trace ( $ "LocalBranchDeleted: { evt . Branch } ") ;
389- LocalBranchDeleted ? . Invoke ( evt . Branch ) ;
390- eventsProcessed ++ ;
391- }
258+ Logger . Trace ( "RepositoryChanged" ) ;
259+ RepositoryChanged ? . Invoke ( ) ;
260+ eventsProcessed ++ ;
392261 }
393262
394- List < EventData > remoteBranchesCreated ;
395- if ( events . TryGetValue ( EventType . RemoteBranchCreated , out remoteBranchesCreated ) )
263+ if ( events . ContainsKey ( EventType . RepositoryCommitted ) )
396264 {
397- foreach ( var evt in remoteBranchesCreated )
398- {
399- Logger . Trace ( $ "RemoteBranchCreated: { evt . Origin } /{ evt . Branch } ") ;
400- RemoteBranchCreated ? . Invoke ( evt . Origin , evt . Branch ) ;
401- eventsProcessed ++ ;
402- }
265+ Logger . Trace ( "RepositoryCommitted" ) ;
266+ RepositoryCommitted ? . Invoke ( ) ;
267+ eventsProcessed ++ ;
403268 }
404269
405- List < EventData > remoteBranchesDeleted ;
406- if ( events . TryGetValue ( EventType . RemoteBranchDeleted , out remoteBranchesDeleted ) )
407- {
408- foreach ( var evt in remoteBranchesDeleted )
409- {
410- Logger . Trace ( $ "RemoteBranchDeleted: { evt . Origin } /{ evt . Branch } ") ;
411- RemoteBranchDeleted ? . Invoke ( evt . Origin , evt . Branch ) ;
412- eventsProcessed ++ ;
413- }
414- }
415270 return eventsProcessed ;
416271 }
417272
@@ -445,13 +300,11 @@ private enum EventType
445300 None ,
446301 ConfigChanged ,
447302 HeadChanged ,
448- RepositoryChanged ,
449303 IndexChanged ,
450- RemoteBranchDeleted ,
451- RemoteBranchCreated ,
452- LocalBranchDeleted ,
453- LocalBranchCreated ,
454- LocalBranchChanged
304+ LocalBranchesChanged ,
305+ RemoteBranchesChanged ,
306+ RepositoryChanged ,
307+ RepositoryCommitted
455308 }
456309
457310 private class EventData
0 commit comments