Created
December 4, 2011 19:39
-
-
Save ssube/1431092 to your computer and use it in GitHub Desktop.
Changeset combinerer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PackageManifest m_Package; | |
List<String> m_File_Create, m_File_Remove; | |
public void CollateChanges(Version v_from, Version v_to) | |
{ | |
List<Version> versions = new List<Version>(m_Package.Versions); | |
// Find the first common parent | |
List<Version> searched = new List<Version>(); | |
Version c_from = v_from, c_to = v_to, c_check = c_from; | |
bool flip = true; | |
while (!searched.Contains(c_check)) | |
{ | |
searched.Add(c_check); | |
if (flip) | |
{ | |
if (c_from.Parent == null) | |
{ | |
c_check = null; | |
break; | |
} | |
c_from = versions.Find(v => v.Id == c_from.Parent); | |
c_check = c_to; | |
flip = false; | |
} else { | |
if (c_to.Parent == null) | |
{ | |
c_check = null; | |
break; | |
} | |
c_to = versions.Find(v => v.Id == c_to.Parent); | |
c_check = c_from; | |
flip = true; | |
} | |
} | |
String parent_id = null; | |
if (c_check != null) | |
{ | |
parent_id = c_check.Id; | |
} | |
// Get the change stack | |
Stack<Version> changechain = new Stack<Version>(); | |
for (c_check = c_to; c_check.Parent != parent_id; versions.Find(v => v.Id == c_check.Parent)) | |
{ | |
changechain.Push(c_check); | |
} | |
// Compile the stack into a final changeset | |
m_File_Create = new List<String>(); | |
m_File_Remove = new List<String>(); | |
while (changechain.Count > 0) | |
{ | |
Version c_change = changechain.Pop(); | |
foreach (String removal in c_change.Remove.File) | |
{ | |
if (m_File_Create.RemoveAll(s => s == removal) == 0) | |
{ | |
m_File_Remove.Add(removal); | |
} | |
} | |
m_File_Create.AddRange(c_change.Create.File); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment