コード例 #1
0
ファイル: TreeDirectoryData.cs プロジェクト: Kuzq/gitter
 public TreeDirectoryData(string name, string shortName, TreeDirectoryData parent, FileStatus fileStatus, StagedStatus stagedStatus)
     : base(name, fileStatus, stagedStatus)
 {
     _parent = parent;
     ShortName = shortName;
     _files = new List<TreeFileData>();
     _directories = new List<TreeDirectoryData>();
 }
コード例 #2
0
 public TreeDirectoryData(string name, string shortName, TreeDirectoryData parent, FileStatus fileStatus, StagedStatus stagedStatus)
     : base(name, fileStatus, stagedStatus)
 {
     Parent      = parent;
     ShortName   = shortName;
     Files       = new List <TreeFileData>();
     Directories = new List <TreeDirectoryData>();
 }
コード例 #3
0
ファイル: ObjectFactories.cs プロジェクト: oqewok/gitter
        public static TreeDirectory CreateTreeDirectory(Repository repository, TreeDirectoryData treeDirectoryData)
        {
            Verify.Argument.IsNotNull(repository, "repository");
            Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");

            var directory = new TreeDirectory(repository, treeDirectoryData.Name, null, treeDirectoryData.ShortName)
            {
                StagedStatus = treeDirectoryData.StagedStatus,
            };

            foreach (var subDirectory in treeDirectoryData.Directories)
            {
                directory.AddDirectory(CreateTreeDirectory(repository, subDirectory));
            }
            foreach (var file in treeDirectoryData.Files)
            {
                directory.AddFile(ObjectFactories.CreateTreeFile(repository, file));
            }
            return(directory);
        }
コード例 #4
0
ファイル: Status.cs プロジェクト: oqewok/gitter
        private bool Merge(
            IDictionary <string, TreeFile> oldPlainList, TreeDirectory oldRoot,
            IDictionary <string, TreeFileData> newPlainList, TreeDirectoryData newRoot)
        {
            bool res        = false;
            var  removeList = new List <string>();

            foreach (var oldFileKvp in oldPlainList)
            {
                TreeFileData file;
                if (newPlainList.TryGetValue(oldFileKvp.Key, out file))
                {
                    newPlainList.Remove(oldFileKvp.Key);
                    ObjectFactories.UpdateTreeFile(oldFileKvp.Value, file);
                }
                else
                {
                    removeList.Add(oldFileKvp.Key);
                    res = true;
                }
            }

            foreach (var s in removeList)
            {
                oldPlainList.Remove(s);
            }

            if (newPlainList.Count != 0)
            {
                res = true;
                foreach (var newFileKvp in newPlainList)
                {
                    oldPlainList.Add(newFileKvp.Key, ObjectFactories.CreateTreeFile(Repository, newFileKvp.Value));
                }
            }

            Update(newRoot, oldRoot);
            return(res);
        }
コード例 #5
0
ファイル: Status.cs プロジェクト: oqewok/gitter
        private void Update(TreeDirectoryData sourceDirectory, TreeDirectory targetDirectory)
        {
            bool[] existance;
            bool[] matched;

            #region update subdirectories

            existance = new bool[targetDirectory.Directories.Count];
            matched   = new bool[sourceDirectory.Directories.Count];
            for (int i = 0; i < targetDirectory.Directories.Count; ++i)
            {
                var targetSubDirectory = targetDirectory.Directories[i];
                for (int j = 0; j < sourceDirectory.Directories.Count; ++j)
                {
                    if (!matched[j])
                    {
                        var sourceSubDirectory = sourceDirectory.Directories[j];
                        if (targetSubDirectory.Name == sourceSubDirectory.ShortName)
                        {
                            existance[i] = true;
                            matched[j]   = true;
                            Update(sourceSubDirectory, targetSubDirectory);
                            break;
                        }
                    }
                }
            }
            for (int i = targetDirectory.Directories.Count - 1; i >= 0; --i)
            {
                if (!existance[i])
                {
                    var directory = targetDirectory.Directories[i];
                    targetDirectory.RemoveDirectoryAt(i);
                    InvokeRemovedDirectory(directory);
                }
            }
            for (int i = 0; i < sourceDirectory.Directories.Count; ++i)
            {
                if (!matched[i])
                {
                    var directory = ObjectFactories.CreateTreeDirectory(Repository, sourceDirectory.Directories[i]);
                    targetDirectory.AddDirectory(directory);
                    InvokeAddedDirectory(directory);
                }
            }

            #endregion

            #region update files

            existance = new bool[targetDirectory.Files.Count];
            matched   = new bool[sourceDirectory.Files.Count];
            for (int i = 0; i < targetDirectory.Files.Count; ++i)
            {
                var targetFile = targetDirectory.Files[i];
                for (int j = 0; j < sourceDirectory.Files.Count; ++j)
                {
                    if (!matched[j])
                    {
                        var sourceFile = sourceDirectory.Files[j];
                        if (targetFile.Name == sourceFile.ShortName)
                        {
                            existance[i]      = true;
                            matched[j]        = true;
                            targetFile.Status = sourceFile.FileStatus;
                            break;
                        }
                    }
                }
            }
            for (int i = targetDirectory.Files.Count - 1; i >= 0; --i)
            {
                if (!existance[i])
                {
                    var file = targetDirectory.Files[i];
                    targetDirectory.RemoveFileAt(i);
                    InvokeRemovedFile(file);
                }
            }
            for (int i = 0; i < sourceDirectory.Files.Count; ++i)
            {
                if (!matched[i])
                {
                    var treeFile = ObjectFactories.CreateTreeFile(Repository, sourceDirectory.Files[i]);
                    targetDirectory.AddFile(treeFile);
                    InvokeNewFile(treeFile);
                }
            }

            #endregion
        }
コード例 #6
0
ファイル: Status.cs プロジェクト: oqewok/gitter
        private static TreeDirectoryData BreakIntoTree(IDictionary <string, TreeFileData> files, StagedStatus stagedStatus)
        {
            var root = new TreeDirectoryData("", "", null, FileStatus.Cached, stagedStatus);
            var dirs = new Dictionary <string, TreeDirectoryData>();
            var path = new StringBuilder();

            foreach (var tfinfo in files.Values)
            {
                var parent     = root;
                var name       = tfinfo.Name;
                var nameLength = name.Length;
                //if(name.EndsWith("/"))
                //{
                //    --nameLength;
                //    name = name.Substring(0, nameLength);
                //}
                int slashPos = 0;
                path.Clear();
                while (slashPos != -1 && slashPos < nameLength)
                {
                    bool isFile;
                    int  endOfPathName = name.IndexOf('/', slashPos);
                    if (endOfPathName == -1)
                    {
                        endOfPathName = nameLength;
                        isFile        = true;
                    }
                    else
                    {
                        isFile = false;
                    }
                    string partName;
                    if (isFile)
                    {
                        partName = slashPos == 0 ?
                                   name :
                                   name.Substring(slashPos, endOfPathName - slashPos);
                        tfinfo.ShortName = partName;
                        parent.AddFile(tfinfo);
                        break;
                    }
                    else
                    {
                        partName = name.Substring(slashPos, endOfPathName - slashPos);
                        path.Append(partName);
                        path.Append('/');
                        string            currentPath = path.ToString();
                        TreeDirectoryData wtDirectory;
                        if (!dirs.TryGetValue(currentPath, out wtDirectory))
                        {
                            wtDirectory = new TreeDirectoryData(currentPath, partName, parent, FileStatus.Cached, stagedStatus);
                            dirs.Add(currentPath, wtDirectory);
                            parent.AddDirectory(wtDirectory);
                        }
                        parent = wtDirectory;
                    }
                    slashPos = endOfPathName + 1;
                }
            }

            return(root);
        }
コード例 #7
0
ファイル: ObjectFactories.cs プロジェクト: oqewok/gitter
 public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData)
 {
     Verify.Argument.IsNotNull(treeDirectory, "treeDirectory");
     Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");
 }
コード例 #8
0
 public void AddDirectory(TreeDirectoryData directory)
 {
     Directories.Add(directory);
 }
コード例 #9
0
ファイル: ObjectFactories.cs プロジェクト: Kuzq/gitter
 public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData)
 {
     Verify.Argument.IsNotNull(treeDirectory, "treeDirectory");
     Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");
 }
コード例 #10
0
ファイル: ObjectFactories.cs プロジェクト: Kuzq/gitter
        public static TreeDirectory CreateTreeDirectory(Repository repository, TreeDirectoryData treeDirectoryData)
        {
            Verify.Argument.IsNotNull(repository, "repository");
            Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");

            var directory = new TreeDirectory(repository, treeDirectoryData.Name, null, treeDirectoryData.ShortName)
            {
                StagedStatus = treeDirectoryData.StagedStatus,
            };
            foreach(var subDirectory in treeDirectoryData.Directories)
            {
                directory.AddDirectory(CreateTreeDirectory(repository, subDirectory));
            }
            foreach(var file in treeDirectoryData.Files)
            {
                directory.AddFile(ObjectFactories.CreateTreeFile(repository, file));
            }
            return directory;
        }
コード例 #11
0
ファイル: ObjectFactories.cs プロジェクト: kiple/gitter
 public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData)
 {
     Verify.Argument.IsNotNull(treeDirectory, nameof(treeDirectory));
     Verify.Argument.IsNotNull(treeDirectoryData, nameof(treeDirectoryData));
 }
コード例 #12
0
ファイル: Status.cs プロジェクト: Kuzq/gitter
        private void Update(TreeDirectoryData sourceDirectory, TreeDirectory targetDirectory)
        {
            bool[] existance;
            bool[] matched;

            #region update subdirectories

            existance	= new bool[targetDirectory.Directories.Count];
            matched		= new bool[sourceDirectory.Directories.Count];
            for(int i = 0; i < targetDirectory.Directories.Count; ++i)
            {
                var targetSubDirectory = targetDirectory.Directories[i];
                for(int j = 0; j < sourceDirectory.Directories.Count; ++j)
                {
                    if(!matched[j])
                    {
                        var sourceSubDirectory = sourceDirectory.Directories[j];
                        if(targetSubDirectory.Name == sourceSubDirectory.ShortName)
                        {
                            existance[i]	= true;
                            matched[j]		= true;
                            Update(sourceSubDirectory, targetSubDirectory);
                            break;
                        }
                    }
                }
            }
            for(int i = targetDirectory.Directories.Count - 1; i >= 0; --i)
            {
                if(!existance[i])
                {
                    var directory = targetDirectory.Directories[i];
                    targetDirectory.RemoveDirectoryAt(i);
                    InvokeRemovedDirectory(directory);
                }
            }
            for(int i = 0; i < sourceDirectory.Directories.Count; ++i)
            {
                if(!matched[i])
                {
                    var directory = ObjectFactories.CreateTreeDirectory(Repository, sourceDirectory.Directories[i]);
                    targetDirectory.AddDirectory(directory);
                    InvokeAddedDirectory(directory);
                }
            }

            #endregion

            #region update files

            existance	= new bool[targetDirectory.Files.Count];
            matched		= new bool[sourceDirectory.Files.Count];
            for(int i = 0; i < targetDirectory.Files.Count; ++i)
            {
                var targetFile = targetDirectory.Files[i];
                for(int j = 0; j < sourceDirectory.Files.Count; ++j)
                {
                    if(!matched[j])
                    {
                        var sourceFile = sourceDirectory.Files[j];
                        if(targetFile.Name == sourceFile.ShortName)
                        {
                            existance[i]	= true;
                            matched[j]		= true;
                            targetFile.Status = sourceFile.FileStatus;
                            break;
                        }
                    }
                }
            }
            for(int i = targetDirectory.Files.Count - 1; i >= 0; --i)
            {
                if(!existance[i])
                {
                    var file = targetDirectory.Files[i];
                    targetDirectory.RemoveFileAt(i);
                    InvokeRemovedFile(file);
                }
            }
            for(int i = 0; i < sourceDirectory.Files.Count; ++i)
            {
                if(!matched[i])
                {
                    var treeFile = ObjectFactories.CreateTreeFile(Repository, sourceDirectory.Files[i]);
                    targetDirectory.AddFile(treeFile);
                    InvokeNewFile(treeFile);
                }
            }

            #endregion
        }
コード例 #13
0
ファイル: Status.cs プロジェクト: Kuzq/gitter
        private bool Merge(
            IDictionary<string, TreeFile>	  oldPlainList, TreeDirectory	  oldRoot,
            IDictionary<string, TreeFileData> newPlainList,	TreeDirectoryData newRoot)
        {
            bool res = false;
            var removeList = new List<string>();

            foreach(var oldFileKvp in oldPlainList)
            {
                TreeFileData file;
                if(newPlainList.TryGetValue(oldFileKvp.Key, out file))
                {
                    newPlainList.Remove(oldFileKvp.Key);
                    ObjectFactories.UpdateTreeFile(oldFileKvp.Value, file);
                }
                else
                {
                    removeList.Add(oldFileKvp.Key);
                    res = true;
                }
            }

            foreach(var s in removeList)
            {
                oldPlainList.Remove(s);
            }

            if(newPlainList.Count != 0)
            {
                res = true;
                foreach(var newFileKvp in newPlainList)
                {
                    oldPlainList.Add(newFileKvp.Key, ObjectFactories.CreateTreeFile(Repository, newFileKvp.Value));
                }
            }

            Update(newRoot, oldRoot);
            return res;
        }
コード例 #14
0
ファイル: Status.cs プロジェクト: Kuzq/gitter
        private static TreeDirectoryData BreakIntoTree(IDictionary<string, TreeFileData> files, StagedStatus stagedStatus)
        {
            var root = new TreeDirectoryData("", "", null, FileStatus.Cached, stagedStatus);
            var dirs = new Dictionary<string, TreeDirectoryData>();
            var path = new StringBuilder();

            foreach(var tfinfo in files.Values)
            {
                var parent = root;
                var name = tfinfo.Name;
                var nameLength = name.Length;
                //if(name.EndsWith("/"))
                //{
                //    --nameLength;
                //    name = name.Substring(0, nameLength);
                //}
                int slashPos = 0;
                path.Clear();
                while(slashPos != -1 && slashPos < nameLength)
                {
                    bool isFile;
                    int endOfPathName = name.IndexOf('/', slashPos);
                    if(endOfPathName == -1)
                    {
                        endOfPathName = nameLength;
                        isFile = true;
                    }
                    else
                    {
                        isFile = false;
                    }
                    string partName;
                    if(isFile)
                    {
                        partName = slashPos == 0 ?
                            name :
                            name.Substring(slashPos, endOfPathName - slashPos);
                        tfinfo.ShortName = partName;
                        parent.AddFile(tfinfo);
                        break;
                    }
                    else
                    {
                        partName = name.Substring(slashPos, endOfPathName - slashPos);
                        path.Append(partName);
                        path.Append('/');
                        string currentPath = path.ToString();
                        TreeDirectoryData wtDirectory;
                        if(!dirs.TryGetValue(currentPath, out wtDirectory))
                        {
                            wtDirectory = new TreeDirectoryData(currentPath, partName, parent, FileStatus.Cached, stagedStatus);
                            dirs.Add(currentPath, wtDirectory);
                            parent.AddDirectory(wtDirectory);
                        }
                        parent = wtDirectory;
                    }
                    slashPos = endOfPathName + 1;
                }
            }

            return root;
        }
コード例 #15
0
ファイル: TreeDirectoryData.cs プロジェクト: Kuzq/gitter
 public void AddDirectory(TreeDirectoryData directory)
 {
     _directories.Add(directory);
 }