Skip to content

Conversation

@redsun82
Copy link
Contributor

@redsun82 redsun82 commented Jan 21, 2025

This adds a --json option to fetch, which is done on top of #5973.

It turned out there was a minor bug in --dry-run, where the same object was being reported fetched multiple times from different references, which diverged from non-dry-run behaviour, where the object being fetched for one ref prevented refetching for the other. This has been fixed by keeping a set of virtually fetched OIDs. This and gathering the transfers across references required sharing a fetchWatcher object across fetch* calls.

Additionally, this PR also harmonizes the --json flag occurring in different commands:

  • all now accept -j as a shorcut (previously only status did)
  • all now have the same documentation

@redsun82 redsun82 changed the title Fetch json Add --json option to fetch Jan 21, 2025
@redsun82 redsun82 marked this pull request as ready for review February 18, 2025 12:12
@redsun82 redsun82 requested a review from a team as a code owner February 18, 2025 12:12
Copy link
Member

@chrisd8088 chrisd8088 left a comment

Choose a reason for hiding this comment

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

This looks awesome. Thank you so much!

I've left a few comments and suggestions, but nothing major, I think. If it's easier for you, I can push a commit or two with those minor revisions and then merge the PR; just let me know what you prefer.

I should also say, thanks very much for straightening up all the --json and -j options and their documentation!

Comment on lines +48 to +54
if d.transfers != nil {
d.transfers = append(d.transfers, t)
}
if d.virtuallyFetched != nil {
d.virtuallyFetched[t.Oid] = true
}
if fetchDryRunArg {
Copy link
Member

Choose a reason for hiding this comment

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

I hemmed and hawed a bit over this, because append() will accept a nil slice and just allocate a backing array, so we could drop the make([]*tq.Transfer, 0) in the newFetchWatcher() function above, and then do something like:

	if fetchJsonArg {
		d.transfers = append(d.transfers, t)
	}
	if fetchDryRunArg {
		d.virtuallyFetched[t.Oid] = true
		printProgress("%s %s => %s", tr.Tr.Get("fetch"), t.Oid, t.Name)
	}

However, since in your next PR #5975 you're adding another flag whose state affects both functions, I think it's probably more elegant to leave it as you've written it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point, I'll mull it over when I get back to that PR, maybe I can indeed move choosing the behaviour from the constructor to this function. For now, I left it like it was.

@redsun82 redsun82 requested a review from chrisd8088 February 25, 2025 08:10
Copy link
Member

@chrisd8088 chrisd8088 left a comment

Choose a reason for hiding this comment

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

Fantastic, thank you!

@chrisd8088 chrisd8088 merged commit aa0ca91 into git-lfs:main Feb 25, 2025
10 checks passed
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.

2 participants