Exemplo n.º 1
0
        /// <summary>
        /// Returns a VersionData that contains only those children contained in a changelog
        /// </summary>
        /// <param name="changelog"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        public VersionData Trim(Changelog changelog, string prefix = "")
        {
            if (Filetype != FileType.Directory)
            {
                throw new InvalidOperationException("Trim cannot operate on a FileType.File");
            }
            var vdcollection = new VDKeyedCollection();

            foreach (var vd in children)
            {
                string fpath = PrefixFilename(prefix, vd.Filename);
                if (changelog.Added.ContainsKey(fpath) || changelog.Modified.ContainsKey(fpath))
                {
                    if (vd.Filetype == FileType.Directory)
                    {
                        vdcollection.Add(vd.Trim(changelog, fpath));
                    }
                    else
                    {
                        vdcollection.Add(new VersionData(vd.Filename, vd.Data));
                    }
                }
            }
            return(new VersionData(Filename, vdcollection));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Selects all files that were altered in some way (added, modified, removed, or renamed)
 /// </summary>
 /// <param name="thisVD"></param>
 /// <param name="otherVD"></param>
 /// <param name="byName"></param>
 /// <param name="byHash"></param>
 private static void AddAlteredFiles(VDKeyedCollection thisVD, VDKeyedCollection otherVD, VDKeyedCollection
                                     byName, Dictionary <string, LinkedList <string> > byHash)
 {
     foreach (var pair in thisVD)
     {
         string name     = pair.Filename;
         string hash     = pair.Hash;
         bool   contains = false;
         if (otherVD.Contains(name)) //if the file has not been altered
         {
             contains = true;
             if (hash == otherVD[name].Hash)
             {
                 continue;
             }
         }
         if (!byHash.ContainsKey(hash))
         {
             byHash[hash] = new LinkedList <string>();
         }
         if (contains) //prioritize renaming files with no counterpart
         {
             byHash[hash].AddLast(name);
         }
         else
         {
             byHash[hash].AddFirst(name);
         }
         byName.Add(pair);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Converts a DataNode and all descendants to a VersionData
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private VersionData GetDirectoryData(DataNode node)
        {
            VDKeyedCollection children = new VDKeyedCollection();

            foreach (var childNode in node.children)
            {
                if (childNode.data == null)
                {
                    continue;
                }
                if (childNode.data.Filetype == VersionData.FileType.Directory)
                {
                    children.Add(GetDirectoryData(childNode));
                }
                else
                {
                    var vd = childNode.data;
                    children.Add(new VersionData(childNode.filename, vd.Data, vd.Hash));
                }
            }
            return(new VersionData(node.filename, children));
        }