예제 #1
0
        public void GetVersion()
        {
            Version v  = directory.GetVersion("init", false);
            string  vh = v.Data.Hash;

            Assert.AreEqual(v.Hash, "init");
            VersionData  f1txt  = v.Data.Children["file1.txt"];
            StreamReader sr     = new StreamReader(f1txt.Data);
            string       result = sr.ReadToEnd();

            Assert.AreEqual(result, "file1 v1");
            sr.Dispose();
        }
예제 #2
0
        /// <summary>
        /// Converts this object to a Commit object
        /// </summary>
        /// <param name="directory">The directory dependency for proxies</param>
        /// <param name="loader">The loader object which specifies which objects to load</param>
        /// <returns></returns>
        public Commit GetCommit(DirectoryStructure directory, CommitDependencyLoader loader)
        {
            Commit[] parents = new Commit[Parents.Length];
            for (int i = 0; i < parents.Length; i++)
            {
                string p = Parents[i];
                if (loader.LoadParents && loader.ShouldLoadParent(p))
                {
                    parents[i] = directory.GetCommit(p, loader.GetParent(p));
                }
                else
                {
                    parents[i] = new CommitProxy(p, directory);
                }
            }

            Changelog changelog = loader.LoadChangelog ?
                                  directory.GetChangelog(Changelog) :
                                  new ChangelogProxy(Changelog, directory);

            Version version = loader.LoadVersion ?
                              directory.GetVersion(Hash, loader.LoadVersionData) :
                              new VersionProxy(Version, directory);

            CommitMetadata metadata = Metadata != null?Metadata.GetMetadata()
                                          : throw new FormatException("Commit must contain metadata");

            return(new Commit(parents, changelog, version, metadata, Hash));
        }
예제 #3
0
        /// <summary>
        /// Aggregates files from various Versions into one Version
        /// </summary>
        /// <param name="aggregated"></param>
        /// <param name="directory"></param>
        /// <returns></returns>
        public static Version AggregateVersion(AggregatedChangelog aggregated, DirectoryStructure directory)
        {
            var            versions = new Dictionary <string, Version>();
            VersionBuilder builder  = new VersionBuilder();
            Action <Dictionary <string, Tuple <string, Commit> > > build = vals =>
            {
                foreach (var val in vals)
                {
                    string  versionHash = val.Value.Item2.Version.Hash;
                    Version v;
                    if (versions.ContainsKey(versionHash))
                    {
                        v = versions[versionHash];
                    }
                    else
                    {
                        v = directory.GetVersion(versionHash);
                        versions.Add(v.Hash, v);
                    }
                    var vdata = v.GetVersionData(val.Key);
                    builder.AddVersionData(val.Key, vdata);
                }
            };

            build(aggregated.Added);
            build(aggregated.Modified);
            foreach (var pair in aggregated.Renamed)
            {
                builder.RenameVersionData(pair.Key, pair.Value);
            }
            return(builder.GetVersion());
        }
예제 #4
0
        public Build GetBuild(DirectoryStructure directory)
        {
            var parent    = directory.GetBuild(Parent);
            var changelog = directory.GetChangelog(Changelog);
            var version   = directory.GetVersion(Version);
            var metadata  = Metadata.GetBuildMetadata();

            return(new Build(parent, changelog, version, metadata));
        }
예제 #5
0
 /// <summary>
 /// Constructs a Version object from the specified hash, including all filenames
 /// </summary>
 /// <param name="hash">The hash identifier of the version</param>
 /// <param name="loadData">If true, will load VersionData objects instead of proxies</param>
 /// <returns></returns>
 public Version GetVersion(string hash, bool loadData = false)
 {
     return(directory.GetVersion(hash, loadData));
 }