public void Rename(SourceItemChange change, bool updatingForwardInTime)
        {
            ItemMetaData oldItem = sourceControlProvider.GetPreviousVersionOfItems(new SourceItem[] { change.Item }, change.Item.RemoteChangesetId)[0];

            string itemOldName;
            string itemNewName;

            if (updatingForwardInTime)
            {
                itemOldName = oldItem.Name;
                itemNewName = change.Item.RemoteName;
                ProcessDeletedItem(itemOldName, change);
                ProcessAddedOrUpdatedItem(itemNewName, change, false, false);
            }
            else
            {
                itemOldName = change.Item.RemoteName;
                itemNewName = oldItem.Name;
                ProcessAddedOrUpdatedItem(itemNewName, change, false, false);
                ProcessDeletedItem(itemOldName, change);
            }
            if (change.Item.ItemType == ItemType.Folder)
            {
                renamedItemsToBeCheckedForDeletedChildren.Add(itemNewName);
            }
        }
        private string GetRemoteNameOfPropertyChange(SourceItemChange change)
        {
            string remoteName = change.Item.RemoteName;

            if (remoteName.Contains("/" + Constants.PropFolder + "/"))
            {
                if (remoteName.EndsWith("/" + Constants.PropFolder + "/" + Constants.FolderPropFile))
                {
                    remoteName = remoteName.Substring(0, remoteName.Length - ("/" + Constants.PropFolder + "/" + Constants.FolderPropFile).Length);
                }
                else
                {
                    remoteName = remoteName.Replace("/" + Constants.PropFolder + "/", "/");
                }
            }
            else if (remoteName.StartsWith(Constants.PropFolder + "/"))
            {
                if (remoteName == Constants.PropFolder + "/" + Constants.FolderPropFile)
                {
                    remoteName = "";
                }
                else
                {
                    remoteName = remoteName.Substring(Constants.PropFolder.Length + 1);
                }
            }
            return(remoteName);
        }
Esempio n. 3
0
 private static bool IsDeleteOperation(SourceItemChange change, bool updatingForwardInTime)
 {
     if (updatingForwardInTime == false)
     {
         return(IsAddOperation(change, true));
     }
     return((change.ChangeType & ChangeType.Delete) == ChangeType.Delete);
 }
 public void Delete(SourceItemChange change)
 {
     // we ignore it here because this only happens when the related item
     // is delete, and at any rate, this is a SvnBridge implementation detail
     // which the client is not concerned about
     if (change.Item.RemoteName.StartsWith(Constants.PropFolder + "/") ||
         change.Item.RemoteName.EndsWith("/" + Constants.PropFolder) ||
         change.Item.RemoteName.Contains("/" + Constants.PropFolder + "/"))
     {
         return;
     }
     ProcessDeletedItem(change.Item.RemoteName, change);
 }
        private void ProcessDeletedItem(string remoteName, SourceItemChange change)
        {
            bool alreadyChangedInCurrentClientState = IsChangeAlreadyCurrentInClientState(ChangeType.Delete,
                                                                                          remoteName,
                                                                                          change.Item.RemoteChangesetId,
                                                                                          clientExistingFiles,
                                                                                          clientMissingFiles);

            if (alreadyChangedInCurrentClientState)
            {
                RemoveMissingItem(remoteName, _root);
                return;
            }

            string folderName      = _checkoutRootPath;
            string remoteNameStart = remoteName.StartsWith(_checkoutRootPath) ? _checkoutRootPath : folderName;

            string[] nameParts = remoteName.Substring(remoteNameStart.Length)
                                 .Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            FolderMetaData folder = _root;

            for (int i = 0; i < nameParts.Length; i++)
            {
                bool isLastNamePart = i == nameParts.Length - 1;

                if (folderName != "" && !folderName.EndsWith("/"))
                {
                    folderName += "/" + nameParts[i];
                }
                else
                {
                    folderName += nameParts[i];
                }

                bool fullyHandled = HandleDeleteItem(remoteName, change, folderName, ref folder, isLastNamePart);
                if (fullyHandled)
                {
                    break;
                }
            }
            if (nameParts.Length == 0)//we have to delete the checkout root itself
            {
                HandleDeleteItem(remoteName, change, folderName, ref folder, true);
            }
        }
        private void PerformAddOrUpdate(SourceItemChange change, bool edit)
        {
            if (sourceControlProvider.IsPropertyFolder(change.Item.RemoteName))
            {
                return;
            }

            string remoteName     = change.Item.RemoteName;
            bool   propertyChange = false;

            if (sourceControlProvider.IsPropertyFile(change.Item.RemoteName))
            {
                propertyChange = true;
                remoteName     = GetRemoteNameOfPropertyChange(change);
            }

            ProcessAddedOrUpdatedItem(remoteName, change, propertyChange, edit);
        }
Esempio n. 7
0
 private static bool IsEditOperation(SourceItemChange change)
 {
     return((change.ChangeType & ChangeType.Edit) == ChangeType.Edit);
 }
Esempio n. 8
0
 private static bool IsRenameOperation(SourceItemChange change)
 {
     return((change.ChangeType & ChangeType.Rename) == ChangeType.Rename);
 }
Esempio n. 9
0
        private void CalculateChangeBetweenVersions(string checkoutRootPath, string changePath, int changeVersion, FolderMetaData root, int sourceVersion, int targetVersion)
        {
            bool updatingForwardInTime = sourceVersion <= targetVersion;
            int  lastVersion           = sourceVersion;

            while (targetVersion != lastVersion)
            {
                int     previousLoopLastVersion = lastVersion;
                LogItem logItem = sourceControlProvider.GetLog(
                    changePath,
                    changeVersion,
                    Math.Min(lastVersion, targetVersion) + 1,
                    Math.Max(lastVersion, targetVersion),
                    Recursion.Full, 256);

                foreach (SourceItemHistory history in Helper.SortHistories(updatingForwardInTime, logItem.History))
                {
                    lastVersion = history.ChangeSetID;
                    if (updatingForwardInTime == false)
                    {
                        lastVersion -= 1;
                    }

                    // we need to go over the changeset in reverse order so we will process
                    // all the files first, and build the folder hierarchy that way
                    for (int i = history.Changes.Count - 1; i >= 0; i--)
                    {
                        UpdateDiffEngine engine = new UpdateDiffEngine(root, checkoutRootPath, targetVersion, sourceControlProvider, clientExistingFiles, clientMissingFiles, additionForPropertyChangeOnly, renamedItemsToBeCheckedForDeletedChildren);
                        SourceItemChange change = history.Changes[i];
                        if (ShouldBeIgnored(change.Item.RemoteName))
                        {
                            continue;
                        }
                        if (IsAddOperation(change, updatingForwardInTime))
                        {
                            engine.Add(change);
                        }
                        else if (IsDeleteOperation(change, updatingForwardInTime))
                        {
                            engine.Delete(change);
                        }
                        else if (IsEditOperation(change))
                        {
                            // We may have edit & rename operations
                            if (IsRenameOperation(change))
                            {
                                engine.Rename(change, updatingForwardInTime);
                            }
                            if (updatingForwardInTime == false)
                            {
                                change.Item.RemoteChangesetId -= 1; // we turn the edit around, basically
                            }
                            engine.Edit(change);
                        }
                        else if (IsRenameOperation(change))
                        {
                            engine.Rename(change, updatingForwardInTime);
                        }
                        else
                        {
                            throw new NotSupportedException("Unsupported change type " + change.ChangeType);
                        }
                    }
                }
                // No change was made, break out
                if (previousLoopLastVersion == lastVersion)
                {
                    break;
                }
            }
        }
 public void Edit(SourceItemChange change)
 {
     PerformAddOrUpdate(change, true);
 }
 public void Add(SourceItemChange change)
 {
     PerformAddOrUpdate(change, false);
 }
        private bool HandleDeleteItem(string remoteName, SourceItemChange change, string folderName, ref FolderMetaData folder, bool isLastNamePart)
        {
            ItemMetaData item = folder.FindItem(folderName);

            if (item is DeleteFolderMetaData || item is DeleteMetaData)
            {
                return(true);
            }

            if (item == null)
            {
                if (isLastNamePart)
                {
                    if (change.Item.ItemType == ItemType.File)
                    {
                        item = new DeleteMetaData();
                    }
                    else
                    {
                        item = new DeleteFolderMetaData();
                    }

                    item.Name         = remoteName;
                    item.ItemRevision = change.Item.RemoteChangesetId;
                }
                else
                {
                    item = sourceControlProvider.GetItemsWithoutProperties(_targetVersion, folderName, Recursion.None);
                    if (item == null)
                    {
                        item              = new DeleteFolderMetaData();
                        item.Name         = folderName;
                        item.ItemRevision = _targetVersion;
                    }
                }
                folder.Items.Add(item);
            }
            else if (isLastNamePart)        // we need to revert the item addition
            {
                if (item.OriginallyDeleted) // convert back into a delete
                {
                    folder.Items.Remove(item);
                    if (change.Item.ItemType == ItemType.File)
                    {
                        item = new DeleteMetaData();
                    }
                    else
                    {
                        item = new DeleteFolderMetaData();
                    }

                    item.Name         = remoteName;
                    item.ItemRevision = change.Item.RemoteChangesetId;
                    folder.Items.Add(item);
                }
                else if (item is StubFolderMetaData)
                {
                    DeleteFolderMetaData removeFolder = new DeleteFolderMetaData();
                    removeFolder.Name         = item.Name;
                    removeFolder.ItemRevision = _targetVersion;
                    folder.Items.Remove(item);
                    folder.Items.Add(removeFolder);
                }
                else if (additionForPropertyChangeOnly.ContainsKey(item) && additionForPropertyChangeOnly[item])
                {
                    ItemMetaData removeFolder = item is FolderMetaData
                                                    ? (ItemMetaData) new DeleteFolderMetaData()
                                                    : new DeleteMetaData();
                    removeFolder.Name         = item.Name;
                    removeFolder.ItemRevision = _targetVersion;
                    folder.Items.Remove(item);
                    folder.Items.Add(removeFolder);
                }
                else if (item is MissingItemMetaData && ((MissingItemMetaData)item).Edit == true)
                {
                    ItemMetaData removeFolder = new DeleteMetaData();
                    removeFolder.Name         = item.Name;
                    removeFolder.ItemRevision = _targetVersion;
                    folder.Items.Remove(item);
                    folder.Items.Add(removeFolder);
                }
                else
                {
                    folder.Items.Remove(item);
                }
            }
            folder = (item as FolderMetaData) ?? folder;
            return(false);
        }
 private static bool IsAddOperation(SourceItemChange change)
 {
     return(((change.ChangeType & ChangeType.Add) == ChangeType.Add) ||
            ((change.ChangeType & ChangeType.Branch) == ChangeType.Branch) ||
            ((change.ChangeType & ChangeType.Undelete) == ChangeType.Undelete));
 }
        private void ProcessAddedOrUpdatedItem(string remoteName, SourceItemChange change, bool propertyChange, bool edit)
        {
            bool alreadyInClientCurrentState = IsChangeAlreadyCurrentInClientState(ChangeType.Add,
                                                                                   remoteName,
                                                                                   change.Item.RemoteChangesetId,
                                                                                   clientExistingFiles,
                                                                                   clientMissingFiles);

            if (alreadyInClientCurrentState)
            {
                return;
            }

            if (string.Equals(remoteName, _checkoutRootPath, StringComparison.InvariantCultureIgnoreCase))
            {
                ItemMetaData item = sourceControlProvider.GetItems(_targetVersion, remoteName, Recursion.None);
                if (item != null)
                {
                    _root.Properties = item.Properties;
                }
            }
            else
            {
                FolderMetaData folder   = _root;
                string         itemName = _checkoutRootPath;
                string[]       nameParts;
                if (_checkoutRootPath != "")
                {
                    nameParts = remoteName.Substring(_checkoutRootPath.Length + 1).Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                }
                else
                {
                    nameParts = remoteName.Split('/');
                }

                for (int i = 0; i < nameParts.Length; i++)
                {
                    bool lastNamePart = false;
                    if (i == nameParts.Length - 1)
                    {
                        lastNamePart = true;
                    }

                    if (itemName != "" && !itemName.EndsWith("/"))
                    {
                        itemName += "/" + nameParts[i];
                    }
                    else
                    {
                        itemName += nameParts[i];
                    }

                    ItemMetaData item = folder.FindItem(itemName);
                    if (item == null ||
                        (
                            lastNamePart &&
                            item.Revision < change.Item.RemoteChangesetId &&
                            !(item is DeleteFolderMetaData) &&
                            !(item is DeleteMetaData)
                        )
                        )
                    {
                        if (item != null)
                        {
                            folder.Items.Remove(item);
                        }
                        item = sourceControlProvider.GetItems(_targetVersion, itemName, Recursion.None);
                        if (item == null)
                        {
                            // TFS will report renames even for deleted items,
                            // since TFS reported that this was renamed, but it doesn't exists
                            // in this revision, we know it is a case of renaming a deleted file.
                            // We can safely ignore this and any of its children.
                            if (IsRenameOperation(change))
                            {
                                return;
                            }
                            if (lastNamePart && propertyChange)
                            {
                                return;
                            }
                            item = new MissingItemMetaData(itemName, _targetVersion, edit);
                        }
                        if (!lastNamePart)
                        {
                            StubFolderMetaData stubFolder = new StubFolderMetaData();
                            stubFolder.RealFolder       = (FolderMetaData)item;
                            stubFolder.Name             = item.Name;
                            stubFolder.ItemRevision     = item.ItemRevision;
                            stubFolder.PropertyRevision = item.PropertyRevision;
                            stubFolder.LastModifiedDate = item.LastModifiedDate;
                            stubFolder.Author           = item.Author;
                            item = stubFolder;
                        }
                        folder.Items.Add(item);
                        SetAdditionForPropertyChangeOnly(item, propertyChange);
                    }
                    else if ((item is StubFolderMetaData) && lastNamePart)
                    {
                        folder.Items.Remove(item);
                        folder.Items.Add(((StubFolderMetaData)item).RealFolder);
                    }
                    else if (((item is DeleteFolderMetaData) || (item is DeleteMetaData)) && IsAddOperation(change))
                    {
                        if (!propertyChange)
                        {
                            folder.Items.Remove(item);
                            item = sourceControlProvider.GetItems(change.Item.RemoteChangesetId, itemName, Recursion.None);
                            item.OriginallyDeleted = true;
                            folder.Items.Add(item);
                        }
                    }
                    if (lastNamePart == false)
                    {
                        folder = (FolderMetaData)item;
                    }
                }
            }
        }
Esempio n. 15
0
        protected LogItem GetLog(string path, int versionFrom, int versionTo, Recursion recursion, int maxCount)
        {
            LogItem log = new LogItem();
            List <SourceItemHistory> lst = new List <SourceItemHistory>();

            log.ServerPath = path;
            List <SAWItemInfo> history = GetSDKObject().GetFileHistory(path);

            if (null == history)
            {
                return(log);
            }

            for (int i = 0; i < history.Count; i++)
            {
                SAWItemInfo item = history[i];
                var         his  = new SourceItemHistory(i, item.user, item.date, item.comment);
                if (item.version >= versionFrom && item.version <= versionTo)
                {
                    ChangeType type = ChangeType.Edit;
                    switch (item.type)
                    {
                    case EnumActionType.Enum_ActionTypeNull:
                        type = ChangeType.None;
                        break;

                    case EnumActionType.Enum_ActionTypeAdd:
                        type = ChangeType.Add;
                        break;

                    case EnumActionType.Enum_ActionTypeDelete:
                        type = ChangeType.Delete;
                        break;
                    }
                    SourceItem s = new SourceItem();

                    s.ItemType                  = item.isdir ? ItemType.Folder : ItemType.File;
                    s.RemoteName                = item.name;
                    s.RemoteSize                = item.size;
                    s.DownloadUrl               = "";
                    s.ItemId                    = 0;
                    s.LocalChangesetId          = item.version;
                    s.LocalConflictChangesetId  = 0;
                    s.LocalConflictTextBaseName = "";
                    s.LocalItemStatus           = SourceItemStatus.None; // TODO
                    s.LocalName                 = item.name;
                    s.LocalTextBaseName         = "";
                    s.OriginalLocalItemStatus   = SourceItemStatus.None;
                    s.RemoteChangesetId         = 0;
                    s.RemoteDate                = item.date;
                    s.RemoteItemStatus          = SourceItemStatus.None;


                    SourceItemChange change = new SourceItemChange(s, type);
                    his.Changes.Add(change);
                }

                lst.Add(his);
            }
            log.History = lst.ToArray();

            return(log);
        }