Skip to content
Browse files

minor changes to the classes Commit and Author

  • Loading branch information...
1 parent 8d8dc27 commit 157fd0cc6bf6c03dfd3f3ba155af20e6ed422181 @henon henon committed
Showing with 52 additions and 15 deletions.
  1. +5 −0 GitSharp/Author.cs
  2. +47 −15 GitSharp/Commit.cs
View
5 GitSharp/Author.cs
@@ -76,5 +76,10 @@ public static Author Anonymous
return new Author("anonymous", "anonymous@(none).com");
}
}
+
+ public static Author GetDefaultAuthor(Repository repo)
+ {
+ return new Author(repo.Config["user.name"], repo.Config["user.email"]);
+ }
}
}
View
62 GitSharp/Commit.cs
@@ -39,13 +39,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using GitSharp.Commands;
using GitSharp.Core;
using GitSharp.Core.RevWalk;
using GitSharp.Core.Util;
using GitSharp.Core.Util.JavaHelper;
using ObjectId = GitSharp.Core.ObjectId;
using CoreRef = GitSharp.Core.Ref;
-using CoreCommit = GitSharp.Core.Commit;
using CoreTree = GitSharp.Core.Tree;
using System.IO;
using GitSharp.Core.TreeWalk;
@@ -71,7 +71,7 @@ internal Commit(Repository repo, CoreRef @ref)
{
}
- internal Commit(Repository repo, CoreCommit internal_commit)
+ internal Commit(Repository repo, Core.Commit internal_commit)
: base(repo, internal_commit.CommitId)
{
_internal_commit = internal_commit;
@@ -82,9 +82,9 @@ internal Commit(Repository repo, ObjectId id)
{
}
- private CoreCommit _internal_commit;
+ private Core.Commit _internal_commit;
- private CoreCommit InternalCommit
+ private Core.Commit InternalCommit
{
get
{
@@ -101,11 +101,14 @@ private CoreCommit InternalCommit
}
}
+ #region --> Commit Properties
+
+
public bool IsValid
{
get
{
- return InternalCommit is CoreCommit;
+ return InternalCommit is Core.Commit;
}
}
@@ -281,6 +284,12 @@ public IEnumerable<Commit> Ancestors
}
}
+
+ #endregion
+
+ #region --> Checkout
+
+
/// <summary>
/// Checkout this commit into the working directory. Does not change HEAD.
/// <para/>
@@ -330,6 +339,12 @@ public void Checkout(params string[] paths)
}
}
+
+ #endregion
+
+ #region --> Diffing commits
+
+
/// <summary>
/// Compare reference commit against compared commit. You may pass in a null commit (i.e. for getting the changes of the first commit)
/// </summary>
@@ -455,12 +470,18 @@ public IEnumerable<Change> Changes
}
}
+
+ #endregion
+
+ #region --> Committing
+
+
public static Commit Create(string message, Commit parent, Tree tree)
{
if (tree == null)
throw new ArgumentException("tree must not be null");
var repo = tree.Repository;
- var author = new Author(repo.Config["user.name"], repo.Config["user.email"]);
+ var author = Author.GetDefaultAuthor(parent._repo);
return Create(message, parent, tree, author, author, DateTimeOffset.Now);
}
@@ -471,36 +492,47 @@ public static Commit Create(string message, Commit parent, Tree tree, Author aut
public static Commit Create(string message, Commit parent, Tree tree, Author author, Author committer, DateTimeOffset time)
{
+ return Create(message, (parent == null ? new Commit[0] : new[] { parent }), tree, author, committer, time);
+ }
+
+ public static Commit Create(string message, IEnumerable<Commit> parents, Tree tree, Author author, Author committer, DateTimeOffset time)
+ {
if (string.IsNullOrEmpty(message))
throw new ArgumentException("message must not be null or empty");
if (tree == null)
throw new ArgumentException("tree must not be null");
var repo = tree.Repository;
- var corecommit = new CoreCommit(repo._internal_repo);
- if (parent != null)
- corecommit.ParentIds = new GitSharp.Core.ObjectId[] { parent._id };
- corecommit.Author = new GitSharp.Core.PersonIdent(author.Name, author.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
- corecommit.Committer = new GitSharp.Core.PersonIdent(committer.Name, committer.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
+ var corecommit = new Core.Commit(repo._internal_repo);
+ if (parents != null)
+ corecommit.ParentIds = parents.Select(parent => parent._id).ToArray();
+ corecommit.Author = new Core.PersonIdent(author.Name, author.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
+ corecommit.Committer = new Core.PersonIdent(committer.Name, committer.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
corecommit.Message = message;
corecommit.TreeEntry = tree.InternalTree;
- corecommit.Encoding = ExtractOverridenEncodingCommitFromConfig(repo);
+ corecommit.Encoding = GetCommitEncoding(repo);
corecommit.Save();
return new Commit(repo, corecommit);
}
- private static Encoding ExtractOverridenEncodingCommitFromConfig(Repository repository)
+ private static Encoding GetCommitEncoding(Repository repository)
{
string encodingAlias = repository.Config["i18n.commitencoding"];
-
if (encodingAlias == null)
{
// No commitencoding has been specified in the config
return null;
}
-
return Charset.forName(encodingAlias);
}
+
+ #endregion
+
+ public static implicit operator Core.Commit(Commit c)
+ {
+ return c._internal_commit;
+ }
+
public override string ToString()
{
return "Commit[" + ShortHash + "]";

0 comments on commit 157fd0c

Please sign in to comment.
Something went wrong with that request. Please try again.