2012-03-01 27 views
5

otrzymał changeset c i biorąc pod uwagę, że c zawiera operacje scalania, chciałbym uzyskać listę wszystkich Zestawienia zmian, które zostały połączone i zaowocowały c.TFS2010 - Track Scala

Na przykład:

  • changeset 1 zawiera pewne zmiany dla niektórych plików.
  • Zestaw zmian 2 zawiera pewne zmiany dla niektórych innych plików.
  • Zestaw zmian 3 jest połączeniem zestawów zmian 1 + 2 z odgałęzieniem nadrzędnym.

Teraz chciałabym otrzymać zestawy zmian 1 + 2 od zapytania o zestaw zmian 3, który zestaw zmian łączy.

Chcę to zrobić za pomocą interfejsu TFS API. Natknąłem się na metodę versionControlServer.TrackMerges, jednak nie rozumiem, jakie powinny być metody ItemIdentifiers oczekiwane przez metodę. Niestety nie mogę znaleźć przykładu użycia tej metody. Również nie jestem pewien, czy to naprawdę jest poprawne.

Odpowiedz

9

OK, zajęło mi to naprawdę dużo czasu, ale myślę, że dowiedziałem się, jak to zrobić. Jest to kod, który znajdzie wszystkie „rodzic” Zestawienia zmian:

/// <summary> 
/// Gets the changesets which have resulted in the given changeset due 
/// to a merge operation. 
/// </summary> 
/// <param name="changeset">The changeset.</param> 
/// <param name="versionControlServer">The version control server.</param> 
/// <returns> 
/// A list of all changesets that have resulted into the given changeset. 
/// </returns> 
public static List<Changeset> GetMergedChangesets(Changeset changeset, VersionControlServer versionControlServer) 
{ 
    // remember the already covered changeset id's 
    Dictionary<int, bool> alreadyCoveredChangesets = new Dictionary<int, bool>(); 

    // initialize list of parent changesets 
    List<Changeset> parentChangesets = new List<Changeset>(); 

    // go through each change inside the changeset 
    foreach(Change change in changeset.Changes) 
    { 
     // query for the items' history 
     var queryResults = versionControlServer.QueryMergesExtended(
           new ItemSpec(change.Item.ServerItem, RecursionType.Full), 
           new ChangesetVersionSpec(changeset.ChangesetId), 
           null, 
           null); 

     // go through each changeset in the history 
     foreach (var result in queryResults) 
     { 
      // only if the target-change is the given changeset, we have a hit 
      if (result.TargetChangeset.ChangesetId == changeset.ChangesetId) 
      { 
       // if that hit has already been processed elsewhere, then just skip it 
       if (!alreadyCoveredChangesets.ContainsKey(result.SourceChangeset.ChangesetId)) 
       { 
        // otherwise add it 
        alreadyCoveredChangesets.Add(result.SourceChangeset.ChangesetId, true); 
        parentChangesets.Add(versionControlServer.GetChangeset(result.SourceChangeset.ChangesetId)); 
       } 
      } 
     } 
    } 

    return parentChangesets; 
} 

Edit:

zdałem sobie sprawę, że istnieje małe „bug” w powyższym kodzie, kiedyś napisać " WersjaSpec.Latest "w zapytaniu jednak:" nowa opcja ChangesetVersionSpec (changeset.ChangesetId) "byłaby lepsza, ponieważ wtedy zestawy zmian byłyby również śledzone po usunięciu gałęzi źródłowej.

0

Myślę, że ta strona przez Ben Clark-Robinson odpowiada na pierwotne pytanie, jak korzystać z TrackMerges() API:

Oto zweryfikowana przykład:

using tfvcc = Microsoft.TeamFoundation.VersionControl.Client; 

var sourcePath = "$/projectName/branchObjectName1"; 
var targetPath = "$/projectName/branchObjectName2"; 

versionCtl.TrackMerges(
    sourceChangesetIds: new[] { 1000 }, 
    sourceItem: new tfvcc.ItemIdentifier(sourcePath), 
    targetItems: new[] { new tfvcc.ItemIdentifier(targetPath) }, 
    pathFilter: null) 
+0

Powyższy link jest martwy. –