Example #1
0
        public override IEnumerable <SnapshotItem> GetSnapshotItems(SnapshotId snapshotId)
        {
            var commit = CommitFromSnapshotId(snapshotId);
            var tstamp = commit.Author.When;

            return(FromTree("", commit.Tree, ignored => tstamp));
        }
Example #2
0
 virtual public void UpdateDirectoryFromSnapshot(SnapshotId currentId, SnapshotId targetId, DirectoryInfo dirRoot)
 {
     if (currentId.Equals(targetId))
     {
         return;
     }
     PopulateDirectoryFromSnapshot(targetId, dirRoot);
     ProcessDeletionsBetweenSnapshot(currentId, targetId, dirRoot);
 }
Example #3
0
        public override SnapshotId GetPreviousSnapshotId(SnapshotId snapshotId)
        {
            var commit = CommitFromSnapshotId(snapshotId);

            if (commit != null)
            {
                var previousCommit = GetPreviousCommit(commit);
                if (previousCommit != null)
                {
                    return(new GitCommitId(previousCommit.Id));
                }
            }
            return(null);
        }
Example #4
0
        /// <summary>
        /// List snapshots between first id and last id inclusive.
        /// </summary>
        /// <param name="firstId">A more recently created snapshot.</param>
        /// <param name="lastId">An id older than first Id</param>
        /// <returns>Empty set on error</returns>
        virtual public IEnumerable <SnapshotInfo> ListSnapshotsBetween(SnapshotId firstId, SnapshotId lastId)
        {
            List <SnapshotInfo> ret = new List <SnapshotInfo>();
            var curr = GetLatestSnapshotId();

            while (curr != null && !curr.Equals(firstId))
            {
                curr = GetPreviousSnapshotId(curr);
            }
            // ran out of ids
            if (curr == null)
            {
                LogEvent.SnapshotIdNotFound(firstId);
                // on error case return an empty enumeration.
                ret.Clear();
                return(ret);
            }
            else
            {
                // add first id
                ret.Add(GetSnapshotInfo(curr));
            }
            // if first is equal to last we are done.
            if (firstId.Equals(lastId))
            {
                return(ret);
            }
            // keep adding till we hit last.
            while (curr != null && !curr.Equals(lastId))
            {
                ret.Add(GetSnapshotInfo(curr));
                curr = GetPreviousSnapshotId(curr);
            }
            // ran out of ids.
            if (curr == null)
            {
                LogEvent.SnapshotIdNotFound(lastId);
                // on error case return an empty enumeration.
                ret.Clear();
                return(ret);
            }
            else
            {
                // add last id
                ret.Add(GetSnapshotInfo(curr));
            }
            return(ret);
        }
Example #5
0
        virtual public IEnumerable <SnapshotItem> GetDeletedItemsBetweenSnapshots(SnapshotId currentId, SnapshotId targetId)
        {
            //TODO: Allow for case sensitive compare if we ever port to Linux
            HashSet <string> newPaths = new  HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var item in GetSnapshotItems(targetId))
            {
                newPaths.Add(item.RelativePath);
            }
            foreach (var item in GetSnapshotItems(currentId))
            {
                if (!newPaths.Contains(item.RelativePath))
                {
                    // this is missing in the newer snapshot, so it is a deletion.
                    yield return(item);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Copies files from snapshot to dirRoot.
        /// </summary>
        /// <param name="snapshotId">The snapshot id</param>
        /// <param name="dirRoot">Root to extract</param>
        /// <remarks>
        /// Doesn't delete any data, only adds or modifies data under dirRoot.
        /// </remarks>
        virtual public void PopulateDirectoryFromSnapshot(SnapshotId snapshotId, DirectoryInfo dirRoot)
        {
            if (snapshotId == null)
            {
                throw new ArgumentNullException("snapshotId");
            }
            if (dirRoot == null)
            {
                throw new ArgumentNullException("dirRoot");
            }
            var snapshotItems = GetSnapshotItems(snapshotId);

            Parallel.ForEach(snapshotItems, item =>
            {
                var fullPath = SafeCombinePath(dirRoot, item.RelativePath);
                if (fullPath == null)
                {
                    LogEvent.UpdateOfItemSkipedBecauseOfError(item.RelativePath);
                }
                else
                {
                    try
                    {
                        var itemDir = Path.GetDirectoryName(fullPath);
                        Directory.CreateDirectory(itemDir);
                        using (FileStream fs = new FileStream(fullPath, FileMode.Create))
                        {
                            item.ReadContent(content =>
                            {
                                content.CopyTo(fs);
                                content.Close();
                            });
                            fs.Close();
                        }
                        File.SetLastWriteTimeUtc(fullPath, item.LastModifiedTime.UtcDateTime);
                        LogEvent.ExtractedSnapshotContentTo(fullPath, item.Size, item.LastModifiedTime);
                    }
                    catch (Exception ex)
                    {
                        LogEvent.UnexpectedExceptionDuringPopulate(fullPath, ex);
                    }
                }
            });
        }
Example #7
0
        virtual public void ProcessDeletionsBetweenSnapshot(SnapshotId currentId, SnapshotId targetId, DirectoryInfo dirRoot)
        {
            if (currentId.Equals(targetId))
            {
                return;
            }
            var deletions = GetDeletedItemsBetweenSnapshots(currentId, targetId);

            foreach (var item in deletions)
            {
                var fullPath = SafeCombinePath(dirRoot, item.RelativePath);
                if (fullPath == null)
                {
                    LogEvent.DeleteOfItemSkipedBecauseOfError(item.RelativePath);
                }
                else
                {
                    TryDeleteFile(fullPath);
                }
            }
        }
Example #8
0
 abstract public IEnumerable <SnapshotItem> GetSnapshotItems(SnapshotId token);
Example #9
0
 abstract public SnapshotInfo GetSnapshotInfo(SnapshotId snapshotId);
Example #10
0
 abstract public SnapshotId GetPreviousSnapshotId(SnapshotId snapshotId);
Example #11
0
 virtual public IEnumerable <SnapshotItem> GetAddedItemsBetweenSnapshots(SnapshotId currentId, SnapshotId targetId)
 {
     // just swap the order to get additions.
     return(GetDeletedItemsBetweenSnapshots(targetId, currentId));
 }
Example #12
0
        private Commit CommitFromSnapshotId(SnapshotId id)
        {
            var gitCommitId = (GitCommitId)id;

            return((Commit)GitRepo.Lookup(gitCommitId.CommitId, ObjectType.Commit));
        }
Example #13
0
        public void ResetWorkingDirectoryTo(SnapshotId id)
        {
            var commit = CommitFromSnapshotId(id);

            GitRepo.Reset(ResetOptions.Hard, commit.Sha);
        }
Example #14
0
        public override SnapshotInfo GetSnapshotInfo(SnapshotId snapshotId)
        {
            var commit = CommitFromSnapshotId(snapshotId);

            return(new SnapshotInfo(commit.Message, commit.Author.When, snapshotId));
        }
Example #15
0
 public SnapshotInfo(string comment, DateTimeOffset time, SnapshotId snapshotId)
 {
     Comment    = comment;
     Time       = time;
     SnapshotId = snapshotId;
 }