-
Notifications
You must be signed in to change notification settings - Fork 6
/
VobDB.cs
73 lines (65 loc) · 2.33 KB
/
VobDB.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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ProtoBuf;
namespace GitImporter
{
[Serializable]
[ProtoContract]
public class VobDB
{
public Dictionary<string, Element> ElementsByOid { get; private set; }
public VobDB(Dictionary<string, Element> elementsByOid)
{
ElementsByOid = elementsByOid;
}
public VobDB()
{
ElementsByOid = new Dictionary<string, Element>();
}
public void Add(VobDB other)
{
foreach (var pair in other.ElementsByOid)
{
Element existing;
if (!ElementsByOid.TryGetValue(pair.Key, out existing))
{
ElementsByOid.Add(pair.Key, pair.Value);
continue;
}
// TODO : we should keep the one with the most versions/branches
if (existing.Name != pair.Value.Name)
Program.Logger.TraceData(TraceEventType.Information, 0,
string.Format("element with oid {0} has a different name : keeping {1}, ignoring {2}", existing.Oid, existing.Name, pair.Value.Name));
}
}
[ProtoMember(1)]
private List<Element> _rawElements;
[ProtoBeforeSerialization]
private void BeforeProtobufSerialization()
{
_rawElements = new List<Element>(ElementsByOid.Values);
}
[ProtoAfterDeserialization]
private void AfterProtobufDeserialization()
{
if (_rawElements == null)
{
ElementsByOid = new Dictionary<string, Element>();
return;
}
ElementsByOid = _rawElements.ToDictionary(e => e.Oid);
foreach (var element in _rawElements)
{
var symlink = element as SymLinkElement;
if (symlink != null)
symlink.Fixup(ElementsByOid);
foreach (var branch in element.Branches.Values)
foreach (var version in branch.Versions.OfType<DirectoryVersion>())
version.FixContent(ElementsByOid);
}
_rawElements = null;
}
}
}