Skip to content

Commit

Permalink
Wider use of ObjectId
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Jul 22, 2018
1 parent d4e9048 commit 6f7da7d
Show file tree
Hide file tree
Showing 102 changed files with 1,181 additions and 1,078 deletions.
12 changes: 6 additions & 6 deletions GitCommands/CommitData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ namespace GitCommands
public sealed class CommitData
{
public CommitData(
ObjectId guid,
ObjectId objectId,
ObjectId treeGuid,
IReadOnlyList<string> parentGuids,
IReadOnlyList<ObjectId> parentGuids,
string author,
DateTime authorDate,
string committer,
DateTime commitDate,
string body)
{
Guid = guid;
ObjectId = objectId;
TreeGuid = treeGuid;
ParentGuids = parentGuids;
Author = author;
Expand All @@ -27,9 +27,9 @@ public CommitData(
Body = body;
}

public ObjectId Guid { get; }
public ObjectId ObjectId { get; }
public ObjectId TreeGuid { get; }
public IReadOnlyList<string> ParentGuids { get; }
public IReadOnlyList<ObjectId> ParentGuids { get; }
public string Author { get; }
public DateTimeOffset AuthorDate { get; }
public string Committer { get; }
Expand All @@ -38,7 +38,7 @@ public CommitData(
// TODO mutable properties need review

[CanBeNull, ItemNotNull]
public IReadOnlyList<string> ChildrenGuids { get; set; }
public IReadOnlyList<ObjectId> ChildIds { get; set; }

/// <summary>
/// Gets and sets the commit message.
Expand Down
15 changes: 8 additions & 7 deletions GitCommands/CommitDataManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using GitCommands.Git.Extensions;
using GitUIPluginInterfaces;
Expand All @@ -20,7 +21,7 @@ public interface ICommitDataManager
/// <param name="revision">The <see cref="GitRevision"/> to convert from.</param>
/// <param name="children">The list of children to add to the returned object.</param>
[NotNull]
CommitData CreateFromRevision([NotNull] GitRevision revision, IReadOnlyList<string> children);
CommitData CreateFromRevision([NotNull] GitRevision revision, IReadOnlyList<ObjectId> children);

/// <summary>
/// Gets <see cref="CommitData"/> for the specified <paramref name="sha1"/>.
Expand Down Expand Up @@ -50,7 +51,7 @@ public CommitDataManager(Func<IGitModule> getModule)
/// <inheritdoc />
public void UpdateBody(CommitData commitData, out string error)
{
if (!TryGetCommitLog(commitData.Guid.ToString(), BodyAndNotesFormat, out error, out var data))
if (!TryGetCommitLog(commitData.ObjectId.ToString(), BodyAndNotesFormat, out error, out var data))
{
return;
}
Expand All @@ -76,7 +77,7 @@ public void UpdateBody(CommitData commitData, out string error)
var commitEncoding = lines[1];
var message = ProcessDiffNotes(startIndex: 2, lines);

Debug.Assert(commitData.Guid.ToString() == guid, "Guid in response doesn't match that of request");
Debug.Assert(commitData.ObjectId.ToString() == guid, "Guid in response doesn't match that of request");

// Commit message is not re-encoded by git when format is given
commitData.Body = GetModule().ReEncodeCommitMessage(message, commitEncoding);
Expand Down Expand Up @@ -139,7 +140,7 @@ internal CommitData CreateFromFormattedData([NotNull] string data)
var treeGuid = ObjectId.Parse(lines[1]);

// TODO: we can use this to add more relationship info like gitk does if wanted
var parentGuids = lines[2].Split(' ');
var parentGuids = lines[2].Split(' ').Select(id => ObjectId.Parse(id)).ToList();
var author = module.ReEncodeStringFromLossless(lines[3]);
var authorDate = DateTimeUtils.ParseUnixTime(lines[4]);
var committer = module.ReEncodeStringFromLossless(lines[5]);
Expand All @@ -154,7 +155,7 @@ internal CommitData CreateFromFormattedData([NotNull] string data)
}

/// <inheritdoc />
public CommitData CreateFromRevision(GitRevision revision, IReadOnlyList<string> children)
public CommitData CreateFromRevision(GitRevision revision, IReadOnlyList<ObjectId> children)
{
if (revision == null)
{
Expand All @@ -166,10 +167,10 @@ public CommitData CreateFromRevision(GitRevision revision, IReadOnlyList<string>
throw new ArgumentException($"Cannot have a null {nameof(GitRevision.ObjectId)}.", nameof(revision));
}

return new CommitData(revision.ObjectId, revision.TreeGuid, revision.ParentGuids,
return new CommitData(revision.ObjectId, revision.TreeGuid, revision.ParentIds,
string.Format("{0} <{1}>", revision.Author, revision.AuthorEmail), revision.AuthorDate,
string.Format("{0} <{1}>", revision.Committer, revision.CommitterEmail), revision.CommitDate,
revision.Body ?? revision.Subject) { ChildrenGuids = children };
revision.Body ?? revision.Subject) { ChildIds = children };
}

[NotNull]
Expand Down
2 changes: 1 addition & 1 deletion GitCommands/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static class FileHelper
".tiff",
};

public static bool IsBinaryFile(GitModule module, string fileName)
public static bool IsBinaryFileName(GitModule module, string fileName)
{
return IsBinaryAccordingToGitAttributes(module, fileName)
?? HasMatchingExtension(BinaryExtensions, fileName);
Expand Down
5 changes: 3 additions & 2 deletions GitCommands/Git/GitBlame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using GitUIPluginInterfaces;
using JetBrains.Annotations;

namespace GitCommands
Expand Down Expand Up @@ -36,7 +37,7 @@ public GitBlameLine([NotNull] GitBlameCommit commit, int finalLineNumber, int or

public sealed class GitBlameCommit
{
public string ObjectId { get; }
public ObjectId ObjectId { get; }
public string Author { get; }
public string AuthorMail { get; }
public DateTime AuthorTime { get; }
Expand All @@ -48,7 +49,7 @@ public sealed class GitBlameCommit
public string Summary { get; }
public string FileName { get; }

public GitBlameCommit(string objectId, string author, string authorMail, DateTime authorTime, string authorTimeZone, string committer, string committerMail, DateTime committerTime, string committerTimeZone, string summary, string fileName)
public GitBlameCommit(ObjectId objectId, string author, string authorMail, DateTime authorTime, string authorTimeZone, string committer, string committerMail, DateTime committerTime, string committerTimeZone, string summary, string fileName)
{
ObjectId = objectId;
Author = author;
Expand Down
4 changes: 2 additions & 2 deletions GitCommands/Git/GitCommandHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,9 @@ public static string CheckoutCmd(string branchOrRevisionName, LocalChangesAction
}

/// <summary>Create a new orphan branch from <paramref name="startPoint"/> and switch to it.</summary>
public static string CreateOrphanCmd(string newBranchName, string startPoint = null)
public static string CreateOrphanCmd(string newBranchName, ObjectId startPoint = null)
{
return string.Format("checkout --orphan {0} {1}", newBranchName, startPoint);
return $"checkout --orphan {newBranchName} {startPoint}";
}

/// <summary>Remove files from the working tree and from the index. <remarks>git rm</remarks></summary>
Expand Down
37 changes: 15 additions & 22 deletions GitCommands/Git/GitDescribeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IGitDescribeProvider
/// </summary>
/// <param name="revision">A revision to describe.</param>
/// <returns>Describe information.</returns>
(string precedingTag, string commitCount) Get(string revision);
(string precedingTag, string commitCount) Get(ObjectId revision);
}

public sealed class GitDescribeProvider : IGitDescribeProvider
Expand All @@ -25,35 +25,29 @@ public GitDescribeProvider(Func<IGitModule> getModule)
_getModule = getModule;
}

/// <summary>
/// Runs <c>git describe</c> to find the most recent tag that is reachable from a commit.
/// If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number
/// of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.
/// </summary>
/// <param name="revision">A revision to describe.</param>
/// <returns>Describe information.</returns>
public (string precedingTag, string commitCount) Get(string revision)
/// <inheritdoc />
public (string precedingTag, string commitCount) Get(ObjectId revision)
{
string description = GetModule().GetDescribe(revision);
if (string.IsNullOrEmpty(description))
{
return (string.Empty, string.Empty);
}

int commitHashPos = description.LastIndexOf("-g", description.Length - 1, StringComparison.OrdinalIgnoreCase);
int commitHashPos = description.LastIndexOf("-g", StringComparison.OrdinalIgnoreCase);
if (commitHashPos == -1)
{
return (description, string.Empty);
}

string commitHash = description.Substring(commitHashPos + 2);
if (commitHash.Length == 0 || !revision.StartsWith(commitHash, StringComparison.OrdinalIgnoreCase))
if (commitHash.Length == 0 || !revision.Equals(commitHash))
{
return (description, string.Empty);
}

description = description.Substring(0, commitHashPos);
int commitCountPos = description.LastIndexOf("-", description.Length - 1, StringComparison.Ordinal);
int commitCountPos = description.LastIndexOf("-", StringComparison.Ordinal);
if (commitCountPos == -1)
{
return (description, string.Empty);
Expand All @@ -62,19 +56,18 @@ public GitDescribeProvider(Func<IGitModule> getModule)
string commitCount = description.Substring(commitCountPos + 1);
description = description.Substring(0, commitCountPos);
return (description, commitCount);
}

[NotNull]
private IGitModule GetModule()
{
var module = _getModule();

if (module == null)
IGitModule GetModule()
{
throw new ArgumentException($"Require a valid instance of {nameof(IGitModule)}");
}
var module = _getModule();

if (module == null)
{
throw new ArgumentException($"Require a valid instance of {nameof(IGitModule)}");
}

return module;
return module;
}
}
}
}
Loading

0 comments on commit 6f7da7d

Please sign in to comment.