-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathElementBranch.cs
63 lines (53 loc) · 1.99 KB
/
ElementBranch.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
using System;
using System.Collections.Generic;
using System.Linq;
using ProtoBuf;
namespace GitImporter
{
[Serializable]
[ProtoContract]
public class ElementBranch
{
private string _fullName;
public Element Element { get; private set; }
[ProtoMember(1, AsReference = true)]
public string BranchName { get; private set; }
public ElementVersion BranchingPoint { get; private set; }
[ProtoMember(2)] private ElementVersion.Reference _branchingPointReference;
[ProtoMember(3)]
public List<ElementVersion> Versions { get; private set; }
public string FullName
{
get { return _fullName ?? (_fullName = (BranchingPoint == null ? "" : BranchingPoint.Branch.FullName + "\\") + BranchName); }
}
public ElementBranch(Element element, string branchName, ElementVersion branchingPoint)
{
Element = element;
BranchName = branchName;
BranchingPoint = branchingPoint;
Versions = new List<ElementVersion>();
}
// for Protobuf deserialization
public ElementBranch()
{}
public override string ToString()
{
return Element.Name + "@@\\" + FullName;
}
[ProtoBeforeSerialization]
private void BeforeProtobufSerialization()
{
if (BranchingPoint != null)
_branchingPointReference = new ElementVersion.Reference(BranchingPoint);
}
public void Fixup(Element element)
{
Element = element;
if (BranchingPoint == null && _branchingPointReference != null)
BranchingPoint = Element.Branches[_branchingPointReference.BranchName].Versions
.First(v => v.VersionNumber == _branchingPointReference.VersionNumber);
foreach (var version in Versions)
version.Fixup(this);
}
}
}