Skip to content

json output forget command: added id's in snapshots within reasons object#4737

Merged
MichaelEischer merged 1 commit intorestic:masterfrom
stephan0307:3117
Mar 29, 2024
Merged

json output forget command: added id's in snapshots within reasons object#4737
MichaelEischer merged 1 commit intorestic:masterfrom
stephan0307:3117

Conversation

@stephan0307
Copy link
Copy Markdown
Contributor

@stephan0307 stephan0307 commented Mar 26, 2024

What does this PR change? What problem does it solve?

In order to evaluate the reasons for keep snapshots, there should be also
the id's within the snapshots in the reasons object to have exact reference.
(See also Issue #3117)

Was the change previously discussed in an issue or on the forum?

Checklist

  • I have read the contribution guidelines.
  • I have enabled maintainer edits.
  • I have added tests for all code changes.
  • I have added documentation for relevant changes (in the manual).
  • There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • I have run gofmt on the code in all commits.
  • All commit messages are formatted in the same style as the other commits in the repo.
  • I'm done! This pull request is ready for review.

Copy link
Copy Markdown
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I have a few small remarks, see below.

Matches []string `json:"matches"`
}

func addJSONKeeps(js *[]KeepReason, list []restic.KeepReason) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please change the function signature to addJSONKeeps(list []restic.KeepReason) []KeepReason. There's absolutely no need to use an output parameter here.

Copy link
Copy Markdown
Contributor Author

@stephan0307 stephan0307 Mar 27, 2024

Choose a reason for hiding this comment

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

With a focus on clean code and easy readability, I think it is more important to use the same solutions for the same requirements.
That's why I did it according to the following existing function only a few lines above:
func addJSONSnapshots(js *[]Snapshot, list restic.Snapshots)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I changed for both functions the signature as suggested:

  • asJSONSnapshots(list restic.Snapshots) []Snapshot
  • asJSONKeeps(list []restic.KeepReason) []KeepReason

It is the first time for me doing a PR, so i have a Questions:
Should i squash the fixes with the first commit?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't notice that addJSONSnapshots was doing strange things :-) . Thanks for cleaning it up!

Yes please squash the commits (whether or not commits are squashed and when usually differs a lot between open source projects). Btw, I've that you've used to different names/emails in the commits. You might want to check which one should get merged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

squash done and used correct e-mail (thanks for your notic)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fork syncronized and commit rebased on head

@@ -0,0 +1,3 @@
Enhancement: include snapshot id in reason field of forget JSON output
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The filename should be pull-4737

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

file renamed

@@ -0,0 +1,3 @@
Enhancement: include snapshot id in reason field of forget JSON output

The JSON output of the `forget` command now includes the `id` and `short_id` of a snapshot in the `reason` field. No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a link to this PR as the last line of the changelog:

https://github.com/restic/restic/pull/4737

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Link added

In order to evaluate the keep reasons for snapshots, there should be also the id's
to compare it with snapshots within the keep object. (See also Issue #3117)

In order to avoid output parameters also changed function addJSONSnapshots to asJSONSnapshots
Copy link
Copy Markdown
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@MichaelEischer MichaelEischer added this pull request to the merge queue Mar 29, 2024
Merged via the queue into restic:master with commit 831fc44 Mar 29, 2024
@stephan0307 stephan0307 deleted the 3117 branch March 29, 2024 13:57
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.

2 participants