/// <summary>
		/// 
		/// </summary>
		/// <param name="op"></param>
		/// <param name="hash"></param>
		/// <param name="commiter"></param>
		/// <param name="behavior"></param>
		/// <param name="sources"></param>
		/// <returns></returns>
		public static Commit Commit(this IMappingOperator op, string hash, string commiter, CommitHeadBehavior behavior, params string[] sources) {
			var commit = new Commit {Hash = hash, Author = new CommitAuthorInfo {Commiter = commiter, Time = DateTime.Now}};
			if (null != sources && 0 != sources.Length) {
				foreach (var s in sources) {
					commit.Sources.Add(s);
				}
			}
			return op.Commit(commit,behavior);
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Мержит новый коммит в структуру
        /// </summary>
        /// <param name="commit"></param>
        /// <param name="commitHeadBehavior"></param>
        /// <returns></returns>
        public Commit Commit(Commit commit, CommitHeadBehavior commitHeadBehavior = CommitHeadBehavior.Auto)
        {
            MappingInfo.Changed = true;
            commit.MappingInfo  = MappingInfo;
            commit.Normalize();
            var target = MappingInfo.Resolve(commit.Hash);

            if (null == target)
            {
                target = commit;
                MappingInfo.Commits[commit.Hash] = commit;
            }
            else
            {
                target.Merge(commit);
            }
            if (target.Hash != MappingInfo.Head)
            {
                ProcessHead(target, commitHeadBehavior);
            }
            MappingInfo.Normalize();
            return(target);
        }
Ejemplo n.º 3
0
 private void ProcessHead(Commit target, CommitHeadBehavior commitHeadBehavior)
 {
     if (commitHeadBehavior != CommitHeadBehavior.Deny)
     {
         if (target.MappingInfo.Head == Const.DETACHEDHEAD)
         {
             target.MappingInfo.Head = target.Hash;
         }
         else if (commitHeadBehavior == CommitHeadBehavior.Direct)
         {
             target.MappingInfo.Head = target.Hash;
         }
         else if (commitHeadBehavior == CommitHeadBehavior.Auto)
         {
             if (target.GetAllSources().Any(_ => _ == target.MappingInfo.Head))
             {
                 target.MappingInfo.Head = target.Hash;
             }
         }
         else if (commitHeadBehavior == CommitHeadBehavior.Override)
         {
             if (target.GetAllSources().All(_ => _ != target.MappingInfo.Head))
             {
                 if (target.SourceType == CommitSourceType.Initial)
                 {
                     target.SourceType = CommitSourceType.Single;
                 }
                 else if (target.SourceType == CommitSourceType.Single)
                 {
                     target.SourceType = CommitSourceType.Merged;
                 }
                 target.Sources.Add(target.MappingInfo.Head);
             }
             target.MappingInfo.Head = target.Hash;
         }
     }
 }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="op"></param>
		/// <param name="hash"></param>
		/// <param name="behavior"></param>
		/// <param name="sources"></param>
		/// <returns></returns>
		public static Commit Commit(this IMappingOperator op, string hash, CommitHeadBehavior behavior, params string[] sources) {
			return Commit(op, hash, null, behavior, sources);
		}
        /// <summary>
        ///
        /// </summary>
        /// <param name="op"></param>
        /// <param name="hash"></param>
        /// <param name="commiter"></param>
        /// <param name="behavior"></param>
        /// <param name="sources"></param>
        /// <returns></returns>
        public static Commit Commit(this IMappingOperator op, string hash, string commiter, CommitHeadBehavior behavior, params string[] sources)
        {
            var commit = new Commit {
                Hash = hash, Author = new CommitAuthorInfo {
                    Commiter = commiter, Time = DateTime.Now
                }
            };

            if (null != sources && 0 != sources.Length)
            {
                foreach (var s in sources)
                {
                    commit.Sources.Add(s);
                }
            }
            return(op.Commit(commit, behavior));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="op"></param>
 /// <param name="hash"></param>
 /// <param name="behavior"></param>
 /// <param name="sources"></param>
 /// <returns></returns>
 public static Commit Commit(this IMappingOperator op, string hash, CommitHeadBehavior behavior, params string[] sources)
 {
     return(Commit(op, hash, null, behavior, sources));
 }