void GetMovementInfos(NodeAtTime node, long toRevision, ref IList <MovementInfo> list, NodeAtTime initialNode = null)
        {
            // TODO document what initial node means
            if (initialNode == null)
            {
                initialNode = node;
            }
            else if (initialNode == node)
            {
                return;
            }
            if (node.DeleteRevision.HasValue && node.DeleteRevision.Value <= toRevision)
            {
                list.Add(new MovementInfo(MovementAction.Delete, node.Path, node.Path, node.DeleteRevision.Value, node.DeleteRevision.Value));
            }

            if (node.Ancestor == null)
            {
                list.Add(new MovementInfo(MovementAction.Add, node.Path, node.Path, node.AddRevision, node.AddRevision));
            }
            else
            {
                if (node.Ancestor.Ancestor.DeleteRevision.HasValue && node.Ancestor.Ancestor.DeleteRevision.Value == node.AddRevision)
                {
                    list.Add(new MovementInfo(MovementAction.Move, node.Ancestor.Ancestor.Path, node.Path, node.Ancestor.CopiedAtRevision, node.AddRevision));
                }
                else
                {
                    list.Add(new MovementInfo(MovementAction.Copy, node.Ancestor.Ancestor.Path, node.Path, node.Ancestor.CopiedAtRevision, node.AddRevision));
                }

                GetMovementInfos(node.Ancestor.Ancestor, node.Ancestor.CopiedAtRevision, ref list, initialNode);
            }
        }
        // used for search by filename
        IList <DiffInfo> GetFileHistory(NodeAtTime nod, long startRevision, long endRevision, ICollection <long> ignoreRevisions, bool stopOnCopy)
        {
            IList <DiffInfo> result = new List <DiffInfo>();

            if (nod != null)
            {
                GetFileHistory(nod, startRevision, endRevision, ref result, ignoreRevisions, stopOnCopy);
            }

            return(result);
        }
        public DiffInfo GetCreation(NodeAtTime nodeAtTime)
        {
            if (this.Disposed)
            {
                Progress.DebugLog("GetCreation called on closed SubversionSearcher");
                return(null);
            }

            if (nodeAtTime.IsFolder)
            {
                return(null);
            }

            long revA = 0;
            long revC = nodeAtTime.DeleteRevision.HasValue ? nodeAtTime.DeleteRevision.Value - 1 : long.MaxValue;

            if (nodeAtTime.Actions.Count > 1)
            {
                revC = nodeAtTime.Actions[1].Revision - 1;
            }

            IList <NodeAtTime> li;

            if (nodes.TryGetValue(nodeAtTime.Path, out li))
            {
                for (int i = li.Count - 1; i >= 0; i--)
                {
                    if (li[i] != nodeAtTime)
                    {
                        continue;
                    }

                    if (i > 0)
                    {
                        i--;
                        if (li[i].DeleteRevision.HasValue)
                        {
                            revA = li[i].DeleteRevision.Value;
                        }
                        else
                        {
                            Progress.DebugLog("DeleteRevision is null for {0}@{1}", li[i].Path, li[i].AddRevision);
                        }
                    }
                    break;
                }
            }
            var newDI = new DiffInfo(nodeAtTime.Path, revA, nodeAtTime.AddRevision, revC);

            newDI.SetNodeAtTime(nodeAtTime);
            return(newDI);
        }
 void GetFileHistory(NodeAtTime node, long startRevision, long endRevision, ref IList <DiffInfo> history, ICollection <long> ignoreRevisions, bool stopOnCopy)
 {
     if (stopOnCopy || node.Ancestor == null)
     {
         // adding creation as diff
         AddDiffsForNode(node, startRevision, endRevision, ref history, ignoreRevisions);
     }
     else
     {
         // follow node to creation
         AddDiffsForNode(node, startRevision, endRevision, ref history, ignoreRevisions);
         GetFileHistory(node.Ancestor.Ancestor, startRevision, node.Ancestor.CopiedAtRevision, ref history, ignoreRevisions, false);
     }
 }
        private int GetNodeChecksum(NodeAtTime node, long revision)
        {
            int result = 0;

            foreach (NodeAtTime n in node.Children)
            {
                if (n.ExistsAtRevision(revision))
                {
                    result += GetNodeChecksum(n, revision);
                }
            }

            return(result);
        }
        public IList <MovementInfo> GetMovementInfos(NodeAtTime node)
        {
            if (this.Disposed)
            {
                Progress.DebugLog("GetMovementInfos called on closed SubversionSearcher");
                return(null);
            }

            if (node != null)
            {
                IList <MovementInfo> result = new List <MovementInfo>();
                GetMovementInfos(node, HeadRevision, ref result);
                return(result);
            }
            else
            {
                return(null);
            }
        }
        private void AddModification(string nodePath, long revision, bool removeFromSameAdds = false)
        {
            NodeAtTime node = GetNodeAtTime(nodePath, revision);

            if (node != null)
            {
                if (removeFromSameAdds)
                {
                    ISet <NodeAtTime> set;
                    if (equalAdds.TryGetValue(node, out set))
                    {
                        set.Remove(node);
                        equalAdds.Remove(node);
                    }
                }

                node.AddModification(revision);
            }
            else
            {
                Progress.DebugLog("Did not find {0}@{1} to add modification to it", nodePath, revision);
            }
        }
Example #8
0
 public void SetNodeAtTime(NodeAtTime node)
 {
     this._nodeAtTime = node;
 }
        void AddDiffsForNode(NodeAtTime node, long startRevision, long endRevision, ref IList <DiffInfo> diffs, ICollection <long> ignoreRevsions)
        {
            if (node.IsFolder)
            {
                return;
            }

            long prevRev = 0;
            long nextRev;


            // finding delete revision of previous node that existed here
            IList <NodeAtTime> li;

            if (nodes.TryGetValue(node.Path, out li))
            {
                for (int j = li.Count - 1; j >= 0; j--)
                {
                    if (li[j] != node)
                    {
                        continue;
                    }
                    if (j-- > 0)
                    {
                        prevRev = li[j].DeleteRevision == null ? long.MaxValue : li[j].DeleteRevision.Value;
                    }
                    break;
                }
            }

            for (int i = 0; i < node.Actions.Count; i++)
            {
                var na = node.Actions[i];

                // revision span
                if (na.Revision < startRevision)
                {
                    continue;
                }
                else if (na.Revision > endRevision)
                {
                    break;
                }


                // ignoring delete revision because we don't diff deletes
                if (ignoreRevsions.Contains(na.Revision) || node.DeleteRevision.HasValue && na.Revision == node.DeleteRevision)
                {
                    continue;
                }

                // finding maximum upper revision
                if (i < node.Actions.Count - 1)
                {
                    nextRev = node.Actions[i + 1].Revision - 1;
                }
                else
                {
                    nextRev = node.DeleteRevision.HasValue ? node.DeleteRevision.Value - 1 : HeadRevision;
                }

                DiffInfo newDI = null;

                if (prevRev != na.Revision)
                {
                    diffs.Add(newDI = new DiffInfo(node.Path, prevRev, na.Revision, nextRev));
                }

                if (newDI != null)
                {
                    newDI.SetNodeAtTime(node);
                }

                prevRev = na.Revision;
            }
        }
        // creates a new copy of NodeAtTime in this tree an links them  // has to be directory
        private NodeAtTime AddCopy(
            string path, NodeAtTime previousNode, NodeAtTime parent,
            long currentRevision, long previousRevision,
            ref ISet <string> filesCopiedThisRevision)
        {
            NodeAtTime currentNode;

            currentNode = new NodeAtTime(path, currentRevision, new AncestorRelation(previousNode, previousRevision));

            if (previousNode.IsFolder)
            {
                currentNode.SetIsFolder(false);

                foreach (var c in previousNode.Children)
                {
                    if (c.ExistsAtRevision(previousRevision))
                    {
                        string relpath;

                        if (previousNode.Path == "")
                        {
                            relpath = "/" + c.Path;
                        }
                        else
                        {
                            relpath = c.Path.Substring(previousNode.Path.Length);
                        }

                        string newPath = path + relpath;

                        AddCopy(newPath, c, currentNode, currentRevision, previousRevision, ref filesCopiedThisRevision);
                    }
                }
            }
            else
            {
                if (previousNode.IsFile)
                {
                    currentNode.SetIsFile(false);
                }

                // gets put into this list so it can be deleted from the equalAdds list if it's modified in the same revision it's copied
                filesCopiedThisRevision.Add(currentNode.Path);

                if (previousNode.Actions.Count == 1 || previousNode.Actions[1].Revision > previousRevision)
                {
                    // if our first content is the same as our parents

                    ISet <NodeAtTime> eqli;
                    if (!equalAdds.TryGetValue(previousNode, out eqli))
                    {
                        equalAdds[previousNode] = eqli = new HashSet <NodeAtTime>();
                        eqli.Add(previousNode);
                    }
                    equalAdds[currentNode] = eqli;
                    eqli.Add(currentNode);
                }
            }

            if (parent != null)
            {
                parent.AddChild(currentNode);
            }

            IList <NodeAtTime> nodesWithSamePath;

            if (!nodes.TryGetValue(currentNode.Path, out nodesWithSamePath))
            {
                nodes[currentNode.Path] = nodesWithSamePath = new List <NodeAtTime>();
            }
            nodesWithSamePath.Add(currentNode);

            return(currentNode);
        }
        private void AddAddition(string nodePath, SimplifiedSvnChangeItem changeItem, long revision, ref ISet <string> filesCopiedThisRevision)
        {
            NodeAtTime parent = null;
            // get parent
            int t = 0;

            for (int k = nodePath.Length - 1; k >= 0; k--)
            {
                if (nodePath[k] == '/')
                {
                    t = k;
                    break;
                }
            }
            string             parentPath = nodePath.Substring(0, t);
            IList <NodeAtTime> parli;

            if (nodes.TryGetValue(parentPath, out parli))
            {
                if (parli.Count > 0)
                {
                    parent = parli[parli.Count - 1];
                }
            }
            else if (!String.IsNullOrEmpty(parentPath))
            {
                Progress.DebugLog("Could not find Parent \"{0}\"", parentPath);
            }
            //-------

            if (changeItem.CopyFromPath != null)
            {
                string cpFromPath = changeItem.CopyFromPath.Length > 1 ? changeItem.CopyFromPath.Substring(1) : "";

                var previousNode = GetNodeAtTime(cpFromPath, changeItem.CopyFromRevision);
                if (previousNode != null)
                {
                    AddCopy(nodePath, previousNode, parent, revision, changeItem.CopyFromRevision, ref filesCopiedThisRevision);
                }
                else
                {
                    Progress.DebugLog("Ancestor of {0}@{1} not found: {2}@{3}", nodePath, revision, cpFromPath, changeItem.CopyFromRevision);
                    return;
                }
            }
            else
            {
                NodeAtTime newlyAdded;

                IList <NodeAtTime> nodesWithSamePath;
                if (!nodes.TryGetValue(nodePath, out nodesWithSamePath))
                {
                    nodes[nodePath] = nodesWithSamePath = new List <NodeAtTime>();
                }

                newlyAdded = new NodeAtTime(nodePath, revision);

                if (parent != null)
                {
                    parent.AddChild(newlyAdded);
                }

                if (changeItem.NodeKind == SvnNodeKind.Directory)
                {
                    newlyAdded.SetIsFolder();
                }
                else if (changeItem.NodeKind == SvnNodeKind.File)
                {
                    newlyAdded.SetIsFile();
                }

                nodesWithSamePath.Add(newlyAdded);
            }
        }
Example #12
0
 public AncestorRelation(NodeAtTime ancestor, long copiedAtRevision)
 {
     Ancestor         = ancestor;
     CopiedAtRevision = copiedAtRevision;
 }
Example #13
0
 public void AddChild(NodeAtTime child)
 {
     Children.Add(child);
     SetIsFolder();
 }