Skip to content

git: teach AllRefs()#2338

Merged
ttaylorr merged 5 commits intomasterfrom
git-list-all-refs
Jun 19, 2017
Merged

git: teach AllRefs()#2338
ttaylorr merged 5 commits intomasterfrom
git-list-all-refs

Conversation

@ttaylorr
Copy link
Contributor

This pull request teaches a new function to the git package, AllRefs() which returns a listing of all references in a repository.

This is required for the import subcommand of git-lfs-migrate(1) which needs a listing of all references in order to move references from the old graph onto the migrated one. Ideally this could come from git-rev-list(1) (which we already run to generate a listing of commits to migrate), but tricking the output to be machine readable is difficult to do without switching to git-log, which doesn't have great machine-readable output either.


/cc @git-lfs/core
/cc #2146

@ttaylorr ttaylorr added this to the v2.2.0 milestone Jun 19, 2017
@ttaylorr ttaylorr requested a review from technoweenie June 19, 2017 18:02
Copy link

@peff peff left a comment

Choose a reason for hiding this comment

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

FWIW, this looks fine from the Git side.

git/git.go Outdated
// those references could not be loaded.
func AllRefs() ([]*Ref, error) {
cmd := subprocess.ExecCommand("git",
"for-each-ref", "--format='%(objectname)%00%(refname)'")
Copy link

Choose a reason for hiding this comment

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

Using a NUL here is probably overkill. The objectname can't have any whitespace in it. It looks like splitting on NUL isn't any harder, so it's fine as an extra precaution.

The entries are still delimited by newlines, but that's OK, as newlines are forbidden in refnames.

@ttaylorr ttaylorr merged commit f6a566b into master Jun 19, 2017
@ttaylorr ttaylorr deleted the git-list-all-refs branch June 19, 2017 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants