Skip to content

Conversation

pmiossec
Copy link
Member

@pmiossec pmiossec commented May 25, 2024

Proposed changes

  • display type of data for blob in grid
  • perf: fetch ** dangling commit** metadata by batch (for my GE repo, for 1074 commits: 0.8s instead of 41.5s / only the long git fsck command --25s-- is now taking time. Overall: 1m5s before/ 25s after )
  • syntax highlighting also when opening in popup viewer
  • contextual shortcut are directly accessible (no need to open contextual menu first) & Ctrl-S added
  • support more file types & magic numbers
  • perf: don't do GUI costly processing twice

Before

image

image

image

After

image

image

image

Test methodology

  • Manual

Test environment(s)

  • Git Extensions 33.33.33
  • Build 3c8dd19 (Dirty)
  • Git 2.45.0.windows.1
  • Microsoft Windows NT 10.0.22631.0
  • .NET 8.0.1
  • DPI 96dpi (no scaling)
  • Portable: False

Merge strategy

I agree that the maintainer rebase merge this PR (if the commit message is clear).


✒️ I contribute this code under The Developer Certificate of Origin.

@pmiossec pmiossec force-pushed the improve_recovery branch from 78233dc to 167f698 Compare May 25, 2024 10:47
@@ -78,6 +78,30 @@ private LostObject(LostObjectType objectType, string rawType, ObjectId objectId)
ObjectId = objectId ?? throw new ArgumentNullException(nameof(objectId));
}

public static string[] GetCommitsMetadata(IGitModule module, string commits)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this method used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a comment (and changed a little the interface)

UpdateFilteredLostObjects();
}
}

private bool _typeDetected = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep fields at the top.
Initialisation is not required, it gets initialised implicitly.

@pmiossec pmiossec force-pushed the improve_recovery branch 3 times, most recently from 4778105 to d9df8d1 Compare May 25, 2024 19:57
@@ -32,9 +32,9 @@ private sealed partial class LostObject
/// %s - subject.
/// %ct - committer date, UNIX timestamp (easy to parse format).
/// </summary>
private static readonly string LogCommandArgumentsFormat = (ArgumentString)new GitArgumentBuilder("log")
private static readonly string LogsCommandArgumentsFormat = (ArgumentString)new GitArgumentBuilder("show")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static readonly string LogsCommandArgumentsFormat = (ArgumentString)new GitArgumentBuilder("show")
private static readonly string ShowCommandArgumentsFormat = (ArgumentString)new GitArgumentBuilder("show")

@@ -26,9 +27,12 @@ public sealed partial class FormVerify : GitModuleForm

private LostObject? _previewedItem;
private string _defaultFilename = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private string _defaultFilename = null;
private string? _defaultFilename;

Comment on lines 348 to 350
int currentBatch = 0;

while (currentBatch * batchSize < commits.Length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int currentBatch = 0;
while (currentBatch * batchSize < commits.Length)
for (int currentBatch = 0; currentBatch * batchSize < commits.Length; ++currentBatch )

@@ -18,6 +18,7 @@ public sealed partial class FormVerify : GitModuleForm
private readonly TranslationString _xTagsCreated = new("{0} Tags created." + Environment.NewLine + Environment.NewLine + "Do not forget to delete these tags when finished.");
private readonly TranslationString _selectLostObjectsToRestoreMessage = new("Select objects to restore.");
private readonly TranslationString _selectLostObjectsToRestoreCaption = new("Restore lost objects");
private readonly TranslationString _seems = new("seems");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private readonly TranslationString _seems = new("seems");
private readonly TranslationString _seems = new("seemingly");

item.RawType += $" ({_seems.Text}: {GuessFileTypeWithContent(content)})";
}

await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
await this.SwitchToMainThreadAsync();

Comment on lines 591 to 593
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
return mnuLostObjects.PreProcessMessage(ref msg) || base.ProcessCmdKey(ref msg, keyData);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment why this is needed.
Doesn't have Form an option like KeyPreview?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an expert on this but your comment made me reevaluate.
I made some changes...

@pmiossec pmiossec force-pushed the improve_recovery branch from d9df8d1 to 4d02ad1 Compare May 25, 2024 20:39
Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have not run

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid force push during pending reviews.

Comment on lines +590 to +593
protected override bool ProcessKeyPreview(ref Message msg)
{
// Check if keyboard shortcut is one provided by the contextual menu
return mnuLostObjects.PreProcessMessage(ref msg) || base.ProcessKeyPreview(ref msg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more elegant way, @RussKie?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the bothering you here @mstv?
Looks good to me. I don't think this dialog sees particularly high use, so I don't think it's worth spending too much time to try to super-optimise it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the bothering you here @mstv?

Because it is a workaround.

I don't think it's worth spending too much time to try to super-optimise it.

I agree.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this dialog sees particularly high use,

I wish everyone that this dialog will be the less used of the application but with this PR and the previous ones, GE is maybe now the best Git GUI to recover lost commits and especially mistakenly deleted staged files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid your thought was lost in translation, sorry... though I think I got the idea that this dialog could be useful in recovering accidentally discarded stages files. If this is correct, could you elaborate on this further please?

Copy link
Member Author

@pmiossec pmiossec May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have decrypted my bad English well to understand right.

In this screen, the checkbox "Show commits and tags" allows you to recover commits that are not in the reflog (and so that you can't retrieve easily with GE "Show all reflog references" or reflog features).

And "Show other objects" allows you to recover blobs that are not linked to a commit. And these blobs are contents that were added to the git objects database when you staged files (i.e. do a git add) but are no more pointed by a commit or the index.
So if you discard, by mistake, all the files after having staged these files, you are able to retrieve the contents (and only the content) with this recovery form.
Unfortunately, you can't retrieve the path of the files as the "tree" objects are still not stored in the git object database when you stage (they are stored in the .git\index file during the staging and will be stored only when you commit).
But the fact that now the form display the creation date of the blob ( #4882 ), try to determine the type of all the files based on there content ( #11727 and this PR) and display a content of the blob ( #8212 ) makes as convenient as possible to find the deleted content of the file you want to retrieve.

And I don't know a git GUI that provide such features that's why I said that maybe GE is the best tool to retrieve files in such case (before, as a last chance, having to try a recovery tool). Doing all that from the command line is also much more challenging.

The only missing feature is maybe the "search in blobs" feature but it should not be too difficult to do as everything is in place to be able to do it.

I think I will take some time later to add that to GE documentation ( or wiki?) later. At the moment, you could find some more explanation in stack overflow:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. @pmiossec you're a legend

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this PR is ready for rebase in order to resolve the MC and for merging.

Comment on lines +590 to +593
protected override bool ProcessKeyPreview(ref Message msg)
{
// Check if keyboard shortcut is one provided by the contextual menu
return mnuLostObjects.PreProcessMessage(ref msg) || base.ProcessKeyPreview(ref msg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the bothering you here @mstv?

Because it is a workaround.

I don't think it's worth spending too much time to try to super-optimise it.

I agree.

@pmiossec pmiossec force-pushed the improve_recovery branch from 45615a5 to 3ae292c Compare May 27, 2024 19:53
@pmiossec pmiossec merged commit d261313 into gitextensions:master May 27, 2024
pmiossec added a commit that referenced this pull request May 27, 2024
pmiossec added a commit that referenced this pull request May 27, 2024
for 1074 commits: 0.8s instead of 41.5s

PR #11753
pmiossec added a commit that referenced this pull request May 27, 2024
pmiossec added a commit that referenced this pull request May 27, 2024
without needing to open contextual menu first

PR #11753
@pmiossec pmiossec deleted the improve_recovery branch May 27, 2024 20:11
@RussKie RussKie added this to the vNext milestone Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants