forked from gdevic/GitForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassCommit.cs
79 lines (71 loc) · 2.35 KB
/
ClassCommit.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
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GitForce
{
/// <summary>
/// Class describing and working on one commit
/// A commit is a set of files grouped together under one node
/// </summary>
[Serializable]
public class ClassCommit
{
/// <summary>
/// List of git files stored under this commit.
/// Files have a path relative to the repo root.
/// </summary>
public List<string> Files = new List<string>();
/// <summary>
/// User description text of a commit
/// </summary>
public string Description;
/// <summary>
/// Is this commit a default one (not a user added)
/// Default commit cannot be deleted.
/// </summary>
public bool IsDefault;
/// <summary>
/// Create a commit with the given description
/// </summary>
public ClassCommit(string desc)
{
Description = desc;
}
/// <summary>
/// ToString override returns the commit description
/// </summary>
public override string ToString()
{
return Description;
}
/// <summary>
/// Add a set of files to the commit list.
/// Do not create any duplicates!
/// </summary>
public void AddFiles(List<string> newFiles)
{
Files = Files.Union(newFiles).ToList();
Files.Sort(); // Keep the list sorted
}
/// <summary>
/// Remove all files listed from our list of files.
/// Any file on that list may or may not appear on this commit list.
/// </summary>
public void Prune(List<string> outlaws)
{
Files = Files.Except(outlaws).ToList();
Files.Sort(); // Keep the list sorted
}
/// <summary>
/// Renew the existing list of files by keeping only those that exist in the
/// given list. Return the given list trimmed by files which are now "taken".
/// </summary>
public List<string> Renew(List<string> allFiles)
{
Files = Files.Intersect(allFiles).ToList();
Files.Sort(); // Keep the list sorted
return allFiles.Except(Files).ToList();
}
}
}