@@ -43,7 +43,7 @@ class HistoryView : Subview
43
43
[ NonSerialized ] private float scrollOffset ;
44
44
[ NonSerialized ] private DateTimeOffset scrollTime = DateTimeOffset . Now ;
45
45
[ NonSerialized ] private int selectionIndex ;
46
- [ NonSerialized ] private bool updated = true ;
46
+ [ NonSerialized ] private bool logHasChanged ;
47
47
[ NonSerialized ] private bool useScrollTime ;
48
48
[ NonSerialized ] private bool isBusy ;
49
49
@@ -74,6 +74,7 @@ public override void OnEnable()
74
74
{
75
75
base . OnEnable ( ) ;
76
76
AttachHandlers ( Repository ) ;
77
+ UpdateLog ( ) ;
77
78
}
78
79
79
80
public override void OnDisable ( )
@@ -94,21 +95,13 @@ public override void OnRepositoryChanged(IRepository oldRepository)
94
95
95
96
DetachHandlers ( oldRepository ) ;
96
97
AttachHandlers ( Repository ) ;
97
- Refresh ( ) ;
98
- }
99
-
100
- public override void Refresh ( )
101
- {
102
- base . Refresh ( ) ;
103
- RefreshLog ( ) ;
104
98
}
105
99
106
100
public override void OnSelectionChange ( )
107
101
{
108
102
if ( ! string . IsNullOrEmpty ( AssetDatabase . GetAssetPath ( Selection . activeObject ) ) )
109
103
{
110
104
historyTarget = Selection . activeObject ;
111
- Refresh ( ) ;
112
105
}
113
106
}
114
107
@@ -123,8 +116,8 @@ private void AttachHandlers(IRepository repository)
123
116
return ;
124
117
repository . OnLocalBranchChanged += Refresh ;
125
118
repository . OnStatusChanged += UpdateStatusOnMainThread ;
126
- repository . OnCurrentBranchChanged += s => Refresh ( ) ;
127
- repository . OnCurrentRemoteChanged += s => Refresh ( ) ;
119
+ repository . OnCurrentBranchChanged += Repository_OnCurrentBranchChanged ( ) ;
120
+ repository . OnCurrentRemoteChanged += Repository_OnCurrentRemoteChanged ( ) ;
128
121
}
129
122
130
123
private void DetachHandlers ( IRepository repository )
@@ -133,8 +126,18 @@ private void DetachHandlers(IRepository repository)
133
126
return ;
134
127
repository . OnLocalBranchChanged -= Refresh ;
135
128
repository . OnStatusChanged -= UpdateStatusOnMainThread ;
136
- repository . OnCurrentBranchChanged -= s => Refresh ( ) ;
137
- repository . OnCurrentRemoteChanged -= s => Refresh ( ) ;
129
+ repository . OnCurrentBranchChanged -= Repository_OnCurrentBranchChanged ( ) ;
130
+ repository . OnCurrentRemoteChanged -= Repository_OnCurrentRemoteChanged ( ) ;
131
+ }
132
+
133
+ private Action < string > Repository_OnCurrentRemoteChanged ( )
134
+ {
135
+ return s => Refresh ( ) ;
136
+ }
137
+
138
+ private Action < string > Repository_OnCurrentBranchChanged ( )
139
+ {
140
+ return s => Refresh ( ) ;
138
141
}
139
142
140
143
private void UpdateStatusOnMainThread ( GitStatus status )
@@ -149,68 +152,68 @@ private void UpdateStatus(GitStatus status)
149
152
statusBehind = status . Behind ;
150
153
}
151
154
152
- private void RefreshLog ( )
155
+ private void UpdateLog ( )
153
156
{
154
157
if ( Repository != null )
155
158
{
156
159
Repository . Log ( ) . ThenInUI ( ( success , log ) => {
157
- if ( success ) OnLogUpdate ( log ) ;
160
+ if ( success )
161
+ {
162
+ Logger . Trace ( "OnLogUpdate" ) ;
163
+ GitLogCache . Instance . Log = log ;
164
+ logHasChanged = true ;
165
+ Redraw ( ) ;
166
+ }
158
167
} ) . Start ( ) ;
159
168
}
160
169
}
161
170
162
- private void OnLogUpdate ( List < GitLogEntry > entries )
163
- {
164
- Logger . Trace ( "OnLogUpdate" ) ;
165
- GitLogCache . Instance . Log = entries ;
166
- updated = true ;
167
- Redraw ( ) ;
168
- }
169
-
170
171
private void MaybeUpdateData ( )
171
172
{
172
173
isPublished = Repository != null && Repository . CurrentRemote . HasValue ;
173
174
currentRemote = isPublished ? Repository . CurrentRemote . Value . Name : "placeholder" ;
174
175
175
- if ( ! updated )
176
- return ;
177
- updated = false ;
176
+ if ( logHasChanged )
177
+ {
178
+ logHasChanged = false ;
178
179
179
- history = GitLogCache . Instance . Log ;
180
+ history = GitLogCache . Instance . Log ;
180
181
181
- if ( history . Any ( ) )
182
- {
183
- // Make sure that scroll as much as possible focuses the same time period in the new entry list
184
- if ( useScrollTime )
182
+ if ( history . Any ( ) )
185
183
{
186
- var closestIndex = - 1 ;
187
- double closestDifference = Mathf . Infinity ;
188
- for ( var index = 0 ; index < history . Count ; ++ index )
184
+ // Make sure that scroll as much as possible focuses the same time period in the new entry list
185
+ if ( useScrollTime )
189
186
{
190
- var diff = Math . Abs ( ( history [ index ] . Time - scrollTime ) . TotalSeconds ) ;
191
- if ( diff < closestDifference )
187
+ var closestIndex = - 1 ;
188
+ double closestDifference = Mathf . Infinity ;
189
+ for ( var index = 0 ; index < history . Count ; ++ index )
192
190
{
193
- closestDifference = diff ;
194
- closestIndex = index ;
191
+ var diff = Math . Abs ( ( history [ index ] . Time - scrollTime ) . TotalSeconds ) ;
192
+ if ( diff < closestDifference )
193
+ {
194
+ closestDifference = diff ;
195
+ closestIndex = index ;
196
+ }
195
197
}
198
+
199
+ ScrollTo ( closestIndex , scrollOffset ) ;
196
200
}
197
201
198
- ScrollTo ( closestIndex , scrollOffset ) ;
202
+ CullHistory ( ) ;
199
203
}
200
204
201
- CullHistory ( ) ;
202
- }
203
-
204
- // Restore selection index or clear it
205
- newSelectionIndex = - 1 ;
206
- if ( ! string . IsNullOrEmpty ( selectionID ) )
207
- {
208
- selectionIndex =
209
- Enumerable . Range ( 1 , history . Count + 1 ) . FirstOrDefault ( index => history [ index - 1 ] . CommitID . Equals ( selectionID ) ) - 1 ;
210
-
211
- if ( selectionIndex < 0 )
205
+ // Restore selection index or clear it
206
+ newSelectionIndex = - 1 ;
207
+ if ( ! string . IsNullOrEmpty ( selectionID ) )
212
208
{
213
- selectionID = string . Empty ;
209
+ selectionIndex = Enumerable . Range ( 1 , history . Count + 1 )
210
+ . FirstOrDefault (
211
+ index => history [ index - 1 ] . CommitID . Equals ( selectionID ) ) - 1 ;
212
+
213
+ if ( selectionIndex < 0 )
214
+ {
215
+ selectionID = string . Empty ;
216
+ }
214
217
}
215
218
}
216
219
}
@@ -305,7 +308,7 @@ public void OnEmbeddedGUI()
305
308
// Only update time scroll
306
309
var lastScroll = scroll ;
307
310
scroll = GUILayout . BeginScrollView ( scroll ) ;
308
- if ( lastScroll != scroll && ! updated )
311
+ if ( lastScroll != scroll && ! logHasChanged )
309
312
{
310
313
scrollTime = history [ historyStartIndex ] . Time ;
311
314
scrollOffset = scroll . y - historyStartIndex * EntryHeight ;
@@ -411,7 +414,7 @@ public void OnEmbeddedGUI()
411
414
if ( Event . current . type == EventType . Repaint )
412
415
{
413
416
CullHistory ( ) ;
414
- updated = false ;
417
+ logHasChanged = false ;
415
418
416
419
if ( newSelectionIndex >= 0 || newSelectionIndex == - 2 )
417
420
{
0 commit comments