Skip to content

Commit

Permalink
Merge branch 'master' into feature/clean_working_tree_with_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
australiensun committed Jul 16, 2013
2 parents e0e2e54 + e6a7f24 commit ccf40fa
Show file tree
Hide file tree
Showing 20 changed files with 411 additions and 372 deletions.
2 changes: 1 addition & 1 deletion GitCommands/CommitData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public static CommitData CreateFromRevision(GitRevision revision)
CommitData data = new CommitData(revision.Guid, revision.TreeGuid, revision.ParentGuids.ToList().AsReadOnly(),
String.Format("{0} <{1}>", revision.Author, revision.AuthorEmail), revision.AuthorDate,
String.Format("{0} <{1}>", revision.Committer, revision.CommitterEmail), revision.CommitDate,
revision.Message);
revision.Body ?? revision.Message);
return data;
}

Expand Down
94 changes: 67 additions & 27 deletions GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,12 +931,76 @@ public string Init(bool bare, bool shared)

public bool IsMerge(string commit)
{
string output = RunGitCmd("log -n 1 --format=format:%P \"" + commit + "\"");
string[] parents = output.Split(' ');
string[] parents = GetParents(commit);
if (parents.Length > 1) return true;
return false;
}

private static string ProccessDiffNotes(int startIndex, string[] lines)
{
int endIndex = lines.Length - 1;
if (lines[endIndex] == "Notes:")
endIndex--;

var message = new StringBuilder();
bool bNotesStart = false;
for (int i = startIndex; i <= endIndex; i++)
{
string line = lines[i];
if (bNotesStart)
line = " " + line;
message.AppendLine(line);
if (lines[i] == "Notes:")
bNotesStart = true;
}

return message.ToString();
}

public GitRevision GetRevision(string commit, bool shortFormat = false)
{
const string formatString =
/* Hash */ "%H%n" +
/* Tree */ "%T%n" +
/* Parents */ "%P%n" +
/* Author Name */ "%aN%n" +
/* Author EMail */ "%aE%n" +
/* Author Date */ "%at%n" +
/* Committer Name */ "%cN%n" +
/* Committer EMail*/ "%cE%n" +
/* Committer Date */ "%ct%n";
const string messageFormat = "%e%n%B%nNotes:%n%-N";
string cmd = "log -n1 --format=format:" + formatString + (shortFormat ? "%e%n%s" : messageFormat) + " " + commit;
var revInfo = RunGitCmd(cmd);
string[] lines = revInfo.Split('\n');
var revision = new GitRevision(this, lines[0])
{
TreeGuid = lines[1],
ParentGuids = lines[2].Split(new[]{' '}),
Author = ReEncodeStringFromLossless(lines[3]),
AuthorEmail = ReEncodeStringFromLossless(lines[4]),
Committer = ReEncodeStringFromLossless(lines[6]),
CommitterEmail = ReEncodeStringFromLossless(lines[7])
};
revision.AuthorDate = DateTimeUtils.ParseUnixTime(lines[5]);
revision.CommitDate = DateTimeUtils.ParseUnixTime(lines[8]);
revision.MessageEncoding = lines[9];
if (shortFormat)
{
revision.Message = ReEncodeCommitMessage(lines[10], revision.MessageEncoding);
}
else
{
string message = ProccessDiffNotes(10, lines);

//commit message is not reencoded by git when format is given
revision.Body = ReEncodeCommitMessage(message, revision.MessageEncoding);
revision.Message = revision.Body.Substring(0, revision.Body.IndexOfAny(new[] {'\r', '\n'}));
}

return revision;
}

public string[] GetParents(string commit)
{
string output = RunGitCmd("log -n 1 --format=format:%P \"" + commit + "\"");
Expand All @@ -948,31 +1012,7 @@ public GitRevision[] GetParentsRevisions(string commit)
string[] parents = GetParents(commit);
var parentsRevisions = new GitRevision[parents.Length];
for (int i = 0; i < parents.Length; i++)
{
const string formatString =
/* Tree */ "%T%n" +
/* Author Name */ "%aN%n" +
/* Author Date */ "%ai%n" +
/* Committer Name */ "%cN%n" +
/* Committer Date */ "%ci%n" +
/* Commit Message */ "%s";
string cmd = "log -n 1 --format=format:" + formatString + " " + parents[i];
var revInfo = RunGitCmd(cmd);
string[] infos = revInfo.Split('\n');
var revision = new GitRevision(this, parents[i])
{
TreeGuid = infos[0],
Author = infos[1],
Committer = infos[3],
Message = infos[5]
};
DateTime date;
DateTime.TryParse(infos[2], out date);
revision.AuthorDate = date;
DateTime.TryParse(infos[4], out date);
revision.CommitDate = date;
parentsRevisions[i] = revision;
}
parentsRevisions[i] = GetRevision(parents[i], true);
return parentsRevisions;
}

Expand Down
6 changes: 2 additions & 4 deletions GitCommands/Git/GitRevision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public sealed class GitRevision : IGitItem
public const string Sha1HashPattern = @"[a-f\d]{40}";
public static readonly Regex Sha1HashRegex = new Regex("^" + Sha1HashPattern + "$", RegexOptions.Compiled);


public string[] ParentGuids;
private IList<IGitItem> _subItems;
private readonly List<GitRef> _refs = new List<GitRef>();
Expand Down Expand Up @@ -71,9 +70,8 @@ public bool MatchesSearchString(string searchString)
if ((searchString.Length > 2) && Guid.StartsWith(searchString, StringComparison.CurrentCultureIgnoreCase))
return true;

return
(Author != null && Author.StartsWith(searchString, StringComparison.CurrentCultureIgnoreCase)) ||
Message.ToLower().Contains(searchString);
return (Author != null && Author.StartsWith(searchString, StringComparison.CurrentCultureIgnoreCase)) ||
Message.ToLower().Contains(searchString);
}

public bool IsArtificial()
Expand Down
6 changes: 5 additions & 1 deletion GitCommands/RevisionGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public enum RefsFiltringOptions
Stashes = 8, //
All = 15, // --all
Boundary = 16, // --boundary
ShowGitNotes = 32 // --not --glob=notes --not
ShowGitNotes = 32, // --not --glob=notes --not
NoMerges = 64 // --no-merges
}

public abstract class RevisionGraphInMemFilter
Expand Down Expand Up @@ -180,6 +181,9 @@ private void ProccessGitLog(CancellationToken taskState)
if ((RefsOptions & RefsFiltringOptions.ShowGitNotes) == RefsFiltringOptions.ShowGitNotes)
logParam += " --not --glob=notes --not";

if ((RefsOptions & RefsFiltringOptions.NoMerges) == RefsFiltringOptions.NoMerges)
logParam += " --no-merges";

string branchFilter = BranchFilter;
if ((!string.IsNullOrWhiteSpace(BranchFilter)) &&
(BranchFilter.IndexOfAny(ShellGlobCharacters) >= 0))
Expand Down
6 changes: 6 additions & 0 deletions GitCommands/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ public static bool ShowGitNotes
set { SetBool("showgitnotes", value); }
}

public static bool ShowMergeCommits
{
get { return GetBool("showmergecommits", true); }
set { SetBool("showmergecommits", value); }
}

public static bool ShowTags
{
get { return GetBool("showtags", true); }
Expand Down
2 changes: 1 addition & 1 deletion GitExtensionsTest
Submodule GitExtensionsTest updated from eab5b2 to ba4eb5
53 changes: 1 addition & 52 deletions GitUI/CommandsDialogs/BrowseDialog/FormBrowseMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace GitUI.CommandsDialogs
{
class FormBrowseMenuCommands : MenuCommandsBase
{
private readonly TranslationString _noRevisionFoundError =
new TranslationString("No revision found.");

RevisionGrid RevisionGrid;
FormBrowse _formBrowse;
GitUICommands UICommands { get { return _formBrowse.UICommands; } }
Expand All @@ -32,30 +29,6 @@ public FormBrowseMenuCommands(FormBrowse formBrowse, RevisionGrid revisionGrid)
RevisionGrid = revisionGrid;
}

public void SelectCurrentRevisionExecute()
{
_formBrowse.ExecuteCommand(GitUI.CommandsDialogs.FormBrowse.Commands.SelectCurrentRevision);
}

public void GotoCommitExcecute()
{
using (FormGoToCommit formGoToCommit = new FormGoToCommit(UICommands))
{
if (formGoToCommit.ShowDialog(_formBrowse) != DialogResult.OK)
return;

string revisionGuid = formGoToCommit.ValidateAndGetSelectedRevision();
if (!string.IsNullOrEmpty(revisionGuid))
{
RevisionGrid.SetSelectedRevision(new GitRevision(Module, revisionGuid));
}
else
{
MessageBox.Show(_formBrowse, _noRevisionFoundError.Text);
}
}
}

public IEnumerable<MenuCommand> GetNavigateMenuCommands()
{
if (_navigateMenuCommands == null)
Expand All @@ -70,31 +43,7 @@ private IEnumerable<MenuCommand> CreateNavigateMenuCommands()
{
var resultList = new List<MenuCommand>();

{
var menuCommand = new MenuCommand();
menuCommand.Name = "GotoCurrentRevision";
menuCommand.Text = "Go to current revision";
menuCommand.Image = global::GitUI.Properties.Resources.IconGotoCurrentRevision;
if (_formBrowse != null) // null when TranslationApp is called
{
menuCommand.ShortcutKeyDisplayString = _formBrowse.GetShortcutKeys(GitUI.CommandsDialogs.FormBrowse.Commands.SelectCurrentRevision).ToShortcutKeyDisplayString();
}
menuCommand.ExecuteAction = SelectCurrentRevisionExecute;

resultList.Add(menuCommand);
}

{
var menuCommand = new MenuCommand();
menuCommand.Name = "GotoCommit";
menuCommand.Text = "Go to commit...";
menuCommand.Image = global::GitUI.Properties.Resources.IconGotoCommit;
menuCommand.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift)
| System.Windows.Forms.Keys.G)));
menuCommand.ExecuteAction = GotoCommitExcecute;

resultList.Add(menuCommand);
}
// no additional MenuCommands that are not defined in the RevisionGrid

return resultList;
}
Expand Down
3 changes: 1 addition & 2 deletions GitUI/CommandsDialogs/FormArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private GitRevision DiffSelectedRevision
//commitSummaryUserControl2.Revision = _diffSelectedRevision;
if (_diffSelectedRevision == null)
{
var defaultString = "...";
const string defaultString = "...";
labelDateCaption.Text = String.Format("{0}:", Strings.GetCommitDateText());
labelAuthor.Text = defaultString;
gbDiffRevision.Text = defaultString;
Expand All @@ -59,7 +59,6 @@ private GitRevision DiffSelectedRevision
gbDiffRevision.Text = _diffSelectedRevision.Guid.Substring(0, 10);
labelMessage.Text = _diffSelectedRevision.Message;
}

}
}

Expand Down
3 changes: 2 additions & 1 deletion GitUI/CommandsDialogs/FormBlame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public FormBlame(GitUICommands aCommands, string fileName, GitRevision revision)
if (string.IsNullOrEmpty(fileName))
return;

FileName = fileName;
if (revision == null)
revision = new GitRevision(Module, "Head");
revision = Module.GetRevision("Head");

blameControl1.LoadBlame(revision, null, fileName, null, null, Module.FilesEncoding);
}
Expand Down
4 changes: 1 addition & 3 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ private void InternalInitialize(bool hard)
{
// add Navigate and View menu
_formBrowseMenus.ResetMenuCommandSets();
_formBrowseMenus.AddMenuCommandSet(MainMenuItem.NavigateMenu, _formBrowseMenuCommands.GetNavigateMenuCommands());
//// _formBrowseMenus.AddMenuCommandSet(MainMenuItem.NavigateMenu, _formBrowseMenuCommands.GetNavigateMenuCommands()); // not used at the moment
_formBrowseMenus.AddMenuCommandSet(MainMenuItem.NavigateMenu, RevisionGrid.MenuCommands.GetNavigateMenuCommands());
_formBrowseMenus.AddMenuCommandSet(MainMenuItem.ViewMenu, RevisionGrid.MenuCommands.GetViewMenuCommands());

Expand Down Expand Up @@ -2178,7 +2178,6 @@ internal enum Commands
Commit,
AddNotes,
FindFileInSelectedCommit,
SelectCurrentRevision,
CheckoutBranch,
QuickFetch,
QuickPull,
Expand Down Expand Up @@ -2220,7 +2219,6 @@ protected override bool ExecuteCommand(int cmd)
case Commands.Commit: CommitToolStripMenuItemClick(null, null); break;
case Commands.AddNotes: AddNotes(); break;
case Commands.FindFileInSelectedCommit: FindFileInSelectedCommit(); break;
case Commands.SelectCurrentRevision: RevisionGrid.SetSelectedRevision(new GitRevision(Module, RevisionGrid.CurrentCheckout)); break;
case Commands.CheckoutBranch: CheckoutBranchToolStripMenuItemClick(null, null); break;
case Commands.QuickFetch: QuickFetch(); break;
case Commands.QuickPull:
Expand Down
32 changes: 8 additions & 24 deletions GitUI/CommitInfo/CommitInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,10 @@ private void RevisionInfoLinkClicked(object sender, LinkClickedEventArgs e)
}

private GitRevision _revision;
private string _revisionGuid;
private List<string> _children;
public void SetRevisionWithChildren(GitRevision revision, List<string> children)
{
_revision = revision;
_revisionGuid = revision.Guid;
_children = children;
ReloadCommitInfo();
}
public void SetRevisionWithChildren(string revision, List<string> children)
{
_revision = null;
_revisionGuid = revision;
_children = children;
ReloadCommitInfo();
}
Expand All @@ -116,11 +107,7 @@ public string RevisionGuid
{
get
{
return _revisionGuid;
}
set
{
SetRevisionWithChildren(value, null);
return _revision.Guid;
}
}

Expand All @@ -138,24 +125,21 @@ private void ReloadCommitInfo()

ResetTextAndImage();

if (string.IsNullOrEmpty(_revisionGuid))
if (string.IsNullOrEmpty(_revision.Guid))
return; //is it regular case or should throw an exception

_RevisionHeader.SelectionTabs = GetRevisionHeaderTabStops();
_RevisionHeader.Text = string.Empty;
_RevisionHeader.Refresh();

string error = "";
CommitData data;
if (_revision != null)
CommitData data = CommitData.CreateFromRevision(_revision);
if (_revision.Body == null)
{
data = CommitData.CreateFromRevision(_revision);
CommitData.UpdateCommitMessage(data, Module, _revisionGuid, ref error);
CommitData.UpdateCommitMessage(data, Module, _revision.Guid, ref error);
_revision.Body = data.Body;
ThreadPool.QueueUserWorkItem(_ => loadLinksForRevision(_revision));
}
else
data = CommitData.GetCommitData(Module, _revisionGuid, ref error);
data.ChildrenGuids = _children;
CommitInformation commitInformation = CommitInformation.GetCommitInfo(data, CommandClick != null);

Expand All @@ -166,10 +150,10 @@ private void ReloadCommitInfo()
LoadAuthorImage(data.Author ?? data.Committer);

if (AppSettings.CommitInfoShowContainedInBranches)
ThreadPool.QueueUserWorkItem(_ => loadBranchInfo(_revisionGuid));
ThreadPool.QueueUserWorkItem(_ => loadBranchInfo(_revision.Guid));

if (AppSettings.CommitInfoShowContainedInTags)
ThreadPool.QueueUserWorkItem(_ => loadTagInfo(_revisionGuid));
ThreadPool.QueueUserWorkItem(_ => loadTagInfo(_revision.Guid));
}

private int[] _revisionHeaderTabStops;
Expand Down Expand Up @@ -346,7 +330,7 @@ private void showContainedInBranchesRemoteIfNoLocalToolStripMenuItem_Click(objec

private void addNoteToolStripMenuItem_Click(object sender, EventArgs e)
{
Module.EditNotes(_revisionGuid);
Module.EditNotes(_revision.Guid);
ReloadCommitInfo();
}
}
Expand Down
Loading

0 comments on commit ccf40fa

Please sign in to comment.