@@ -14,12 +14,10 @@ interface IRepositoryWatcher : IDisposable
14
14
event Action HeadChanged ;
15
15
event Action IndexChanged ;
16
16
event Action ConfigChanged ;
17
- event Action < string > LocalBranchChanged ;
18
- event Action < string > LocalBranchCreated ;
19
- event Action < string > LocalBranchDeleted ;
17
+ event Action RepositoryCommitted ;
20
18
event Action RepositoryChanged ;
21
- event Action < string , string > RemoteBranchCreated ;
22
- event Action < string , string > RemoteBranchDeleted ;
19
+ event Action LocalBranchesChanged ;
20
+ event Action RemoteBranchesChanged ;
23
21
void Initialize ( ) ;
24
22
int CheckAndProcessEvents ( ) ;
25
23
}
@@ -39,12 +37,10 @@ class RepositoryWatcher : IRepositoryWatcher
39
37
public event Action HeadChanged ;
40
38
public event Action IndexChanged ;
41
39
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 ;
45
41
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 ;
48
44
49
45
public RepositoryWatcher ( IPlatform platform , RepositoryPathConfiguration paths , CancellationToken cancellationToken )
50
46
{
@@ -193,118 +189,17 @@ private int ProcessEvents(Event[] fileEvents)
193
189
{
194
190
events . Add ( EventType . IndexChanged , null ) ;
195
191
}
196
- else if ( fileA . IsChildOf ( paths . RemotesPath ) )
192
+ else if ( ! events . ContainsKey ( EventType . RemoteBranchesChanged ) && fileA . IsChildOf ( paths . RemotesPath ) )
197
193
{
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 ) ;
238
195
}
239
- else if ( fileA . IsChildOf ( paths . BranchesPath ) )
196
+ else if ( ! events . ContainsKey ( EventType . LocalBranchesChanged ) && fileA . IsChildOf ( paths . BranchesPath ) )
240
197
{
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 ) ;
308
203
}
309
204
}
310
205
else
@@ -320,13 +215,6 @@ private int ProcessEvents(Event[] fileEvents)
320
215
return FireEvents ( events ) ;
321
216
}
322
217
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
-
330
218
private int FireEvents ( Dictionary < EventType , List < EventData > > events )
331
219
{
332
220
int eventsProcessed = 0 ;
@@ -344,74 +232,41 @@ private int FireEvents(Dictionary<EventType, List<EventData>> events)
344
232
eventsProcessed ++ ;
345
233
}
346
234
347
- if ( events . ContainsKey ( EventType . IndexChanged ) )
235
+ if ( events . ContainsKey ( EventType . LocalBranchesChanged ) )
348
236
{
349
- Logger . Trace ( "IndexChanged " ) ;
350
- IndexChanged ? . Invoke ( ) ;
237
+ Logger . Trace ( "LocalBranchesChanged " ) ;
238
+ LocalBranchesChanged ? . Invoke ( ) ;
351
239
eventsProcessed ++ ;
352
240
}
353
241
354
- if ( events . ContainsKey ( EventType . RepositoryChanged ) )
242
+ if ( events . ContainsKey ( EventType . RemoteBranchesChanged ) )
355
243
{
356
- Logger . Trace ( "RepositoryChanged " ) ;
357
- RepositoryChanged ? . Invoke ( ) ;
244
+ Logger . Trace ( "RemoteBranchesChanged " ) ;
245
+ RemoteBranchesChanged ? . Invoke ( ) ;
358
246
eventsProcessed ++ ;
359
247
}
360
248
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 ) )
374
250
{
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 ++ ;
381
254
}
382
255
383
- List < EventData > localBranchesDeleted ;
384
- if ( events . TryGetValue ( EventType . LocalBranchDeleted , out localBranchesDeleted ) )
256
+ if ( events . ContainsKey ( EventType . RepositoryChanged ) )
385
257
{
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 ++ ;
392
261
}
393
262
394
- List < EventData > remoteBranchesCreated ;
395
- if ( events . TryGetValue ( EventType . RemoteBranchCreated , out remoteBranchesCreated ) )
263
+ if ( events . ContainsKey ( EventType . RepositoryCommitted ) )
396
264
{
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 ++ ;
403
268
}
404
269
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
- }
415
270
return eventsProcessed ;
416
271
}
417
272
@@ -445,13 +300,11 @@ private enum EventType
445
300
None ,
446
301
ConfigChanged ,
447
302
HeadChanged ,
448
- RepositoryChanged ,
449
303
IndexChanged ,
450
- RemoteBranchDeleted ,
451
- RemoteBranchCreated ,
452
- LocalBranchDeleted ,
453
- LocalBranchCreated ,
454
- LocalBranchChanged
304
+ LocalBranchesChanged ,
305
+ RemoteBranchesChanged ,
306
+ RepositoryChanged ,
307
+ RepositoryCommitted
455
308
}
456
309
457
310
private class EventData
0 commit comments