forked from gdevic/GitForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassCommits.cs
68 lines (60 loc) · 2.09 KB
/
ClassCommits.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GitForce
{
/// <summary>
/// Class describing and working on a set of commits.
/// </summary>
[Serializable]
public class ClassCommits
{
/// <summary>
/// A bundle is a list of commits.
/// </summary>
public readonly List<ClassCommit> Bundle = new List<ClassCommit>();
/// <summary>
/// Constructor for list of commits - always create at least one (empty) commit named "Default"
/// </summary>
public ClassCommits()
{
Bundle.Add(new ClassCommit("Default"));
Bundle[0].IsDefault = true;
}
/// <summary>
/// Add a new commit bundle to the list
/// </summary>
public void NewBundle(string description, List<string> files)
{
// Remove all files listed from every bundle
foreach (var c in Bundle)
c.Prune(files);
// Add a new bundle with these files
ClassCommit commit = new ClassCommit(description);
commit.AddFiles(files);
Bundle.Add(commit);
}
/// <summary>
/// Move or add each file in the list of files to a specified bundle.
/// Files in that list that are present in any other bundle will be moved.
/// </summary>
public void MoveOrAdd(ClassCommit bundle, List<string> files)
{
// Remove all listed files from any bundle in which they might appear
foreach (var c in Bundle)
c.Prune(files);
// Add listed files to a named bundle
bundle.AddFiles(files);
}
/// <summary>
/// Rebuild the list of files by using only the files from the given list
/// </summary>
public void Rebuild(List<string> files)
{
files = Bundle.Aggregate(files, (current, c) => c.Renew(current));
// Assign the remaining files to the first commit ("Default")
Bundle[0].AddFiles(files);
}
}
}