Skip to content
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

add support for 'diff --json-lines', available in borg >= 1.1.16 #909

Merged
merged 5 commits into from
Mar 29, 2021

Conversation

rblenis
Copy link
Contributor

@rblenis rblenis commented Mar 2, 2021

fixes issue #901 (diff not handling CR/LF in filenames)

@Hofer-Julian
Copy link
Collaborator

Nice!
Did not know that borg diff supports json output now 😊

@rblenis
Copy link
Contributor Author

rblenis commented Mar 2, 2021

yes, hopefully my PR on borg will be completed soon. I think they're trying to get it in for the 1.1.16 release.

@m3nu m3nu mentioned this pull request Mar 3, 2021
@rblenis rblenis force-pushed the issue_#901 branch 2 times, most recently from 0ac07fc to 27e9986 Compare March 17, 2021 10:36
@rblenis rblenis marked this pull request as ready for review March 19, 2021 07:15
@rblenis rblenis force-pushed the issue_#901 branch 2 times, most recently from a5f81a4 to 834e627 Compare March 21, 2021 10:12
@rblenis rblenis changed the title add support for 'diff --json-lines' coming real soon to borg. add support for 'diff --json-lines', available in borg >= 1.1.16 Mar 23, 2021
@rblenis
Copy link
Contributor Author

rblenis commented Mar 23, 2021

borg 1.1.16 released with 'diff --json-lines' support.

@rblenis
Copy link
Contributor Author

rblenis commented Mar 23, 2021

@m3nu, should the test workflow also use several versions of borg, this way some features which behave differently depending on borg version (like this feature), will get moer thoroughly tested?

@m3nu
Copy link
Contributor

m3nu commented Mar 24, 2021

Most calls to Borg are mocked and it just uses pre-defined json output files in /tests/borg_json_output.

@m3nu
Copy link
Contributor

m3nu commented Mar 24, 2021

Yeah, let's get this feature out. I was waiting with merges until the Debian package is frozen. That should be done by now.

@m3nu m3nu self-requested a review March 24, 2021 00:21
@m3nu m3nu self-assigned this Mar 24, 2021
@rblenis
Copy link
Contributor Author

rblenis commented Mar 24, 2021

just realized, I didn't look at the test code for the diff command. I guess it is assuming pre 1.1.16 and just testing the non-json-lines output. I'll look at adding some test code for the json-lines, but not sure if I can get to it until this weekend.

@m3nu
Copy link
Contributor

m3nu commented Mar 25, 2021

That would be perfect. Thanks!

Robert Blenis added 2 commits March 25, 2021 10:07
@rblenis
Copy link
Contributor Author

rblenis commented Mar 25, 2021

I added some tests, copying the non-json-lines test. I also made small changes to report the changes in the tree dialog to match the non-json-lines. Later, I may look at improving the difference info displayed in the tree, especially when multiple types of changes occur to the same item.

@m3nu
Copy link
Contributor

m3nu commented Mar 27, 2021

Looks all good to me. This is ready to merge?

@rblenis
Copy link
Contributor Author

rblenis commented Mar 27, 2021

yes it's ready.

def pretty_bytes(size):
"""from https://stackoverflow.com/questions/12523586/
python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778"""
def pretty_bytes(size, metric=True, sign=False, precision=1):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice improvements to pretty_bytes(). But you don't use the new metric and sign args anywhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

I also removed the SO reference, since the function substantially changed.

Copy link
Contributor Author

@rblenis rblenis Mar 29, 2021

Choose a reason for hiding this comment

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

In an earlier version of my changes, I was using some of the enhancements to pretty_bytes, but after adding the test code and realizing the displayed tree did not match exactly with the non-json-lines version, I didn't use it, and forgot to revert those changes. There are two 'bug-fixes', but I don't think either one would be triggered. 1. better handling of something larger than 1000TB - my version with the loop index check will at least attempt to print the number using 'TB' units, instead of NaN (due to array index exception). 2. better handling of negative 'size' - print correct value with appropriate units instead of using base/unscaled units ('B'). Currently, I think the tree only shows the '+' change in file content, and ignores the '-' change in file content (which I plan to investigate and submit PR), so # 2 probably isn't currently triggered either. And then a 3rd 'issue', is when a number is close to the threshold of using the next larger units, but doesn't use them, but then due to rounding prints as '1000' ... Example: size = 999.95 KB -- it is not large enough to go through the loop twice and use 'MB' units, but when printed, it is rounded up and prints as '1000.0 KB' instead of '1.0 MB'. It seems like the preferred display would limit the significand to 4 total digits and not sometimes round up and display 5 digits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could split off the pretty_bytes changes as a separate PR and indicate the issues it addresses.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nah, it's fine. The new args might be useful in the future and it fixes some issues as you say.

ret['archive_name_newer'] = archive_name_2
ret['json_lines'] = False
if borg_compat.check('DIFF_JSON_LINES'):
ret['cmd'].insert(4, '--json-lines')
Copy link
Contributor

Choose a reason for hiding this comment

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

This is dangerous because the hard-coded position is often overlooked when someone makes changes later. Minor change to get rid of it.

@m3nu
Copy link
Contributor

m3nu commented Mar 29, 2021

Few administrative edits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants