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

getObject #50

Closed
billiegoose opened this issue Jan 15, 2018 · 5 comments
Closed

getObject #50

billiegoose opened this issue Jan 15, 2018 · 5 comments

Comments

@billiegoose
Copy link
Member

billiegoose commented Jan 15, 2018

So as nice as the high-level API is, there are times where you want to get your hands dirty, and do specialized batch operations without wasting time doing a full "git.checkout".

To that end, I'm thinking about adding an API function that would provide some of the benefits of using the GitObjectManager directly.

await git.getObject({
  oid: string,
  format: string
})

values for format:

  • 'raw' - returns raw deflate-compressed file. Useful for manually unpacking objects from packfiles or efficiently shuffling around loose objects - whenever you don't care about the contents you can save time by not unzipping them
  • 'plain' - returns deflated object as Buffer. Useful for calculating SHA object ids
  • 'content' - returns object content, minus the git header
  • 'parsed' - default. parse the object and return a JavaScript object using one of the schemas (CommitDescription, BlobDescription, TreeDescription, TagDescription)

Example usage:

let sha = await git.resolveRef({fs, dir, ref: 'mybranch'})
let commit = await git.getObject({fs, dir, ref: sha})
let tree = await git.getObject({fs, dir, ref: commit.tree})
for (let file of tree.entries) {
  if (file.path === 'package.json') {
    let blob = await git.getObject({fs, dir, ref: file.oid})
    console.log(blob.toString('utf8'))
  }
}
@billiegoose billiegoose created this issue from a note in Planning (v0.9.0-development) Jan 15, 2018
@billiegoose
Copy link
Member Author

@mojavelinux thoughts?

@mojavelinux
Copy link
Contributor

mojavelinux commented Jan 18, 2018

I like the fact that you're using the same function to get each object in succession since that reflects how git actually works.

I would think you'd need to specify the type/format for the last call in your example:

let blob = await git.getObject({fs, dir, ref: file.oid, type: 'content'})

right? otherwise, I'd expect to get a BlobDescription based on your proposal.

I'm worried we're overloading the meaning of "type" (see https://git-scm.com/docs/git-cat-file). Type is already used for the object type (tree, blob, etc). Perhaps format instead?

@billiegoose
Copy link
Member Author

billiegoose commented Jan 18, 2018

otherwise, I'd expect to get a BlobDescription based on your proposal.

True! It would probably be blob.data.toString() or something.

Perhaps format instead?

I thought I did call it format... no worries! I agree that 'type' already has a meaning. I definitely won't call it type. :)

@mojavelinux
Copy link
Contributor

👍

@billiegoose
Copy link
Member Author

I changed the names for more consistency / descriptiveness. Instead of getObject it is readObject (because presumably we will add a writeObject at some point) and instead of 'raw' and 'plain' I called them 'deflated' and 'wrapped'. Soon as the CI tests pass it should be published!

https://isomorphic-git.github.io/docs/readObject.html

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

No branches or pull requests

2 participants