First;
Op op = revision.Second;
if (!userConflicts.Contains(file) &&
currentVersion < Repository.FileVersion(file) &&
Repository.FileExists(file, currentVersion) &&
op != Op.Delete)
userConflicts = userConflicts.Add(file);
}
conflicts = conflicts.Override(user, userConflicts);
}
}
When checking for conflicts, two helper methods are used to detect whether the
repository has seen an update that conflicts with the currently edited version in the
client.
The FileVersion method returns the version number of the most recent checkin
of a given file:
partial static class Repository
{
176 Modeling Systems with Structured State
public static int FileVersion(string file)
{
Sequence
revisions;
return (db.TryGetValue(file, out revisions) ?
revisions.Head.revisionNumber : -1);
}
}
The FileExists method checks whether a given file is in the repository, and if
so, whether the last operation for that file was Add or Change.
partial static class Repository
{
public static bool FileExists(string file, int version)
{
Sequence revisions;
if (db.TryGetValue(file, out revisions))
foreach (Revision r in revisions)
if (r.revisionNumber <= version)
return (r.op != Op.Delete);
return false;
}
}
Edit action
The Edit action represents a local, pending change created on the client. Edits do
not affect the state of the repository until a Commit action occurs.
Pages:
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246