Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Patch: Fetch changes #1102

Closed
dmigwi opened this issue Apr 2, 2019 · 4 comments
Closed

Patch: Fetch changes #1102

dmigwi opened this issue Apr 2, 2019 · 4 comments

Comments

@dmigwi
Copy link

dmigwi commented Apr 2, 2019

How can I be able to implement git log -p --reverse using this tool?

@dmigwi
Copy link
Author

dmigwi commented Apr 6, 2019

I have made progress in implementing git log -p. The pending bit is now how to fetch changes in the first commit made i.e. without a parent commit.

This implementation has been quite helpful.

func (c *Commit) Stats() (FileStats, error) {
	// Get the previous commit.
	ci := c.Parents()
	parentCommit, err := ci.Next()
	if err != nil {
		if err == io.EOF {
			emptyNoder := treeNoder{}
			parentCommit = &Commit{
				Hash: emptyNoder.hash,
				// TreeHash: emptyNoder.parent.Hash,
				s: c.s,
			}
		} else {
			return nil, err
		}
	}

	patch, err := parentCommit.Patch(c)
	if err != nil {
		return nil, err
	}

	return getFileStatsFromFilePatches(patch.FilePatches()), nil
}

Sadly stats for the first commit (without a parent) returns Object not found error.

Also creating a dummy parent commit outside the package is quite difficult because storer.EncodedObjectStorer Commit field is unexported.

So how can I fetch stats/changes in a commit without a parent?

@chappjc
Copy link

chappjc commented Apr 8, 2019

It's interesting that (*Commit).Stats does not work for the initial commit. I can't work out how to get the patch for the initial commit either.

@chappjc
Copy link

chappjc commented Apr 15, 2019

@mcuadros Sorry for the direct mention, but it seems like there must be a simple way to get the initial commit patch diff that I'm just not seeing. How would you suggest handling this?

@mcuadros
Copy link
Contributor

This was solved here: #1115

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

No branches or pull requests

3 participants