Ejemplo n.º 1
0
 private void PreprocessHeadDeletion(Commit existed, DeleteHeadBehavior deleteHeadBehavior)
 {
     if (deleteHeadBehavior == DeleteHeadBehavior.Deny)
     {
         throw new Exception("cannot remove head when DeleteHeadBehavior.Deny");
     }
     if (deleteHeadBehavior == DeleteHeadBehavior.Detach)
     {
         MappingInfo.Head = Const.DETACHEDHEAD;
     }
     else
     {
         if (existed.SourceType == CommitSourceType.Initial)
         {
             MappingInfo.Head = Const.DETACHEDHEAD;
         }
         else if (existed.SourceType == CommitSourceType.Single)
         {
             MappingInfo.Head = existed.Sources[0];
         }
         else
         {
             if (deleteHeadBehavior == DeleteHeadBehavior.AllowSingleDetachMerge)
             {
                 MappingInfo.Head = Const.DETACHEDHEAD;
             }
             else
             {
                 throw new Exception("cannot process deletion of merged head with DeleteHeadBehavior." + deleteHeadBehavior);
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Удаляет коммит и все его зависимости
        /// </summary>
        /// <param name="commitHash"></param>
        /// <param name="deleteHeadBehavior"></param>
        public void Delete(string commitHash, DeleteHeadBehavior deleteHeadBehavior = DeleteHeadBehavior.Deny)
        {
            var existed = MappingInfo.Resolve(commitHash);

            if (null == existed)
            {
                return;
            }
            if (MappingInfo.Head == existed.Hash)
            {
                PreprocessHeadDeletion(existed, deleteHeadBehavior);
            }
            MappingInfo.Changed = true;
            MappingInfo.Commits.Remove(existed.Hash);
            foreach (var c in MappingInfo.Commits.Values)
            {
                if (c.HasSources())
                {
                    if (c.Sources.Contains(existed.Hash))
                    {
                        c.MergeSources(existed);
                        c.Sources.Remove(existed.Hash);
                        c.Normalize();
                    }
                }
            }
            MappingInfo.Normalize();
        }