MCPcopy Create free account
hub / github.com/GCWing/BitFun / compareStates

Function compareStates

src/web-ui/src/tools/git/state/types.ts:194–252  ·  view source on GitHub ↗
(
  prevState: GitState | null,
  newState: GitState
)

Source from the content-addressed store, hash-verified

192}
193
194export function compareStates(
195 prevState: GitState | null,
196 newState: GitState
197): StateComparison {
198 if (!prevState) {
199 return {
200 hasChanges: true,
201 changedLayers: ['basic', 'status', 'detailed'],
202 changedFields: Object.keys(newState) as (keyof GitState)[],
203 };
204 }
205
206 const changedLayers: GitStateLayer[] = [];
207 const changedFields: (keyof GitState)[] = [];
208
209 const basicFields: (keyof GitState)[] = [
210 'isRepository', 'currentBranch', 'ahead', 'behind', 'hasChanges'
211 ];
212 for (const field of basicFields) {
213 if (prevState[field] !== newState[field]) {
214 changedFields.push(field);
215 if (!changedLayers.includes('basic')) {
216 changedLayers.push('basic');
217 }
218 }
219 }
220
221
222 const statusFields: (keyof GitState)[] = ['staged', 'unstaged', 'untracked', 'conflicts'];
223 for (const field of statusFields) {
224 const prevVal = JSON.stringify(prevState[field]);
225 const newVal = JSON.stringify(newState[field]);
226 if (prevVal !== newVal) {
227 changedFields.push(field);
228 if (!changedLayers.includes('status')) {
229 changedLayers.push('status');
230 }
231 }
232 }
233
234
235 const detailedFields: (keyof GitState)[] = ['branches', 'commits'];
236 for (const field of detailedFields) {
237 const prevVal = JSON.stringify(prevState[field]);
238 const newVal = JSON.stringify(newState[field]);
239 if (prevVal !== newVal) {
240 changedFields.push(field);
241 if (!changedLayers.includes('detailed')) {
242 changedLayers.push('detailed');
243 }
244 }
245 }
246
247 return {
248 hasChanges: changedLayers.length > 0,
249 changedLayers,
250 changedFields,
251 };

Callers 1

doRefreshMethod · 0.90

Calls 3

includesMethod · 0.80
stringifyMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected