~edwargix/git.sr.ht

ac98efce24d1efcf16efb1373c1425f750cfb05f — Drew DeVault 5 years ago cda8fa2
api: simplify repository.revspec_single

This should always return a commit object
3 files changed, 14 insertions(+), 9 deletions(-)

M api/graph/generated/generated.go
M api/graph/schema.graphqls
M api/graph/schema.resolvers.go
M api/graph/generated/generated.go => api/graph/generated/generated.go +5 -5
@@ 239,7 239,7 @@ type RepositoryResolver interface {

	Log(ctx context.Context, obj *model.Repository, cursor *model.Cursor) ([]*model.Commit, error)
	Path(ctx context.Context, obj *model.Repository, revspec *string, path string) (*model.TreeEntry, error)
	RevparseSingle(ctx context.Context, obj *model.Repository, revspec string) (model.Object, error)
	RevparseSingle(ctx context.Context, obj *model.Repository, revspec string) (*model.Commit, error)
}
type TreeResolver interface {
	Entries(ctx context.Context, obj *model.Tree, cursor *model.Cursor) ([]*model.TreeEntry, error)


@@ 1265,9 1265,9 @@ type Repository {
  # Returns a tree entry for a given path and revspec
  path(revspec: String = "HEAD", path: String!): TreeEntry

  # Returns the object for a given revspec. Useful, for example, to turn
  # Returns the commit for a given revspec. Useful, for example, to turn
  # something ambiuguous like "9790b10" into a commit object
  revparse_single(revspec: String!): Object
  revparse_single(revspec: String!): Commit
}

# A cursor for enumerating a list of repositories


@@ 4167,9 4167,9 @@ func (ec *executionContext) _Repository_revparse_single(ctx context.Context, fie
	if resTmp == nil {
		return graphql.Null
	}
	res := resTmp.(model.Object)
	res := resTmp.(*model.Commit)
	fc.Result = res
	return ec.marshalOObject2gitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐObject(ctx, field.Selections, res)
	return ec.marshalOCommit2ᚖgitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐCommit(ctx, field.Selections, res)
}

func (ec *executionContext) _RepositoryCursor_results(ctx context.Context, field graphql.CollectedField, obj *model.RepositoryCursor) (ret graphql.Marshaler) {

M api/graph/schema.graphqls => api/graph/schema.graphqls +2 -2
@@ 103,9 103,9 @@ type Repository {
  # Returns a tree entry for a given path and revspec
  path(revspec: String = "HEAD", path: String!): TreeEntry

  # Returns the object for a given revspec. Useful, for example, to turn
  # Returns the commit for a given revspec. Useful, for example, to turn
  # something ambiuguous like "9790b10" into a commit object
  revparse_single(revspec: String!): Object
  revparse_single(revspec: String!): Commit
}

# A cursor for enumerating a list of repositories

M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +7 -2
@@ 237,7 237,7 @@ func (r *repositoryResolver) Path(ctx context.Context, obj *model.Repository, re
	return tree.Entry(path), nil
}

func (r *repositoryResolver) RevparseSingle(ctx context.Context, obj *model.Repository, revspec string) (model.Object, error) {
func (r *repositoryResolver) RevparseSingle(ctx context.Context, obj *model.Repository, revspec string) (*model.Commit, error) {
	rev := plumbing.Revision(revspec)
	hash, err := obj.Repo().ResolveRevision(rev)
	if err != nil {


@@ 246,7 246,12 @@ func (r *repositoryResolver) RevparseSingle(ctx context.Context, obj *model.Repo
	if hash == nil {
		return nil, fmt.Errorf("No such object")
	}
	return model.LookupObject(obj.Repo(), *hash)
	o, err := model.LookupObject(obj.Repo(), *hash)
	if err != nil {
		return nil, err
	}
	commit, _ := o.(*model.Commit)
	return commit, nil
}

func (r *treeResolver) Entries(ctx context.Context, obj *model.Tree, cursor *model.Cursor) ([]*model.TreeEntry, error) {