-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix Hexa editor display of binary files #11747
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch!
Looks sensible, have not run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pending mstv comments
have not run
561d355
to
ea49c0d
Compare
I have added a little refactoring. |
ea49c0d
to
de1c508
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits
GitUI/Editor/FileViewer.cs
Outdated
.AppendLine(); | ||
|
||
double mb = text.Length / (1024d * 1024); | ||
if (mb > 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (mb > 1) | |
if (mb >= 0.1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (mb > 1) | |
if (text.Length > (1024 * 1024) / 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending mstv approval
9f53da7
to
5a3e1fd
Compare
by: * reading file and blob with a better encoding * not touching/altering *blob* content (i.e not breaking content by reencoding) * not converting in ASCII before doing the Hexa editor display (it breaks char > 0x80) As a result, display is **exactly** the same obtained by using an external Hexa Editor: * Hexa value are accurate * string display is the same (except some cheating done by hexa editor for example with char 0x99 displayed as ™)
* DRY * add display in MB (more human friendly) & translated
5a3e1fd
to
c15e105
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have not run
by:
As a result, display is exactly the same obtained by using an external Hexa Editor:
for example with char 0x99 displayed as ™)
Kind of followup to #11727 as it was not always working well because beginning of some files (ex: jpegs) were badly altered when reading blob content.
Screenshots
Before
In commit window
Goal (Hex editor):
Recover jpeg blob:
before:
![image](https://private-user-images.githubusercontent.com/460196/332790887-023925d3-194c-4fc0-abff-08ad56f83d48.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg5MDA1ODMsIm5iZiI6MTcxODkwMDI4MywicGF0aCI6Ii80NjAxOTYvMzMyNzkwODg3LTAyMzkyNWQzLTE5NGMtNGZjMC1hYmZmLTA4YWQ1NmY4M2Q0OC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjIwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYyMFQxNjE4MDNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hNzhhNTg4NjIwNWRjZjVmMjQ0NWY5YTQ0OWVlNTI3NWIzZDZlZmMwYzQ4ODNhZDUzNjJhYTVjMGI3OTIwYjQwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.KjJD6XqqviJtkxWAO8Kwg6_Eyr9B3WSvzANlm5ZYC8s)
after (because content is not corrupted, type of file is well recognized):
Test methodology
Test environment(s)
Merge strategy
I agree that the maintainer squash merge this PR (if the commit message is clear).
✒️ I contribute this code under The Developer Certificate of Origin.