Skip to content

Acquire last effected commit for a git object #2217

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

Closed
wants to merge 2 commits into from
Closed

Acquire last effected commit for a git object #2217

wants to merge 2 commits into from

Conversation

Aimeast
Copy link
Contributor

@Aimeast Aimeast commented Mar 29, 2014

As discussed at #495 (Retrieve history for given file), libgit2/pygit2#231 (Show last commits for Tree or Blob) and libgit2/libgit2sharp#89 (Question: How to get the last commit that affected a given file), I'd like introduce two functions may named as git_commit_entry_last_commit_id and git_commit_tree_last_commit_id.

  • introduce git_commit_entry_last_commit_id
  • introduce git_commit_tree_last_commit_id
  • document
  • test cases
  • rebase and squash

@linquize
Copy link
Contributor

Can you squash the two commits as one?

@Aimeast
Copy link
Contributor Author

Aimeast commented Mar 29, 2014

Can you squash the two commits as one?

Thanks for point out. but the PR not finished that I will rebase and squash after PR finished.

@@ -12,6 +12,8 @@
#include "oid.h"
#include "object.h"

#define VISITED (1 << 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this #define be private and moved into the .c file?

Copy link
Member

Choose a reason for hiding this comment

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

Flags should go with the other ones in src/commit_list.h, and it should not override the meaning of existing ones.

@arrbee
Copy link
Member

arrbee commented Mar 29, 2014

Hmm. I don't think this belongs in the git_commit part of the API.

To me, something like this feels like an addition to the git_revwalk API (something like git_revwalk_next_for_path that finds the next revision in the walk where the OID for the given path changed), or maybe even as something that could be done as an extension of the work that started in #2181 to make it easier to do more complex searches with revwalks.

Alternatively, something like this could conceptually be grouped with the git_blame API, but I'm not sure about that. From what I can tell, there is no code from the blame that could be reused for this.

I'm curious what @carlosmn thinks (and, of course, what @vmg thinks if he has an opinion).

@Aimeast
Copy link
Contributor Author

Aimeast commented Mar 30, 2014

something like this feels like an addition to the git_revwalk API (something like git_revwalk_next_for_path that finds the next revision in the walk where the OID for the given path changed)

OK for the function xxx_entry_last_commit_id, but for the function xxx_tree_last_commit_id(not pushed yet) which compute last effected commit of all children of tree(most like the tree view on the github). How return a list of commits via git_revwalk_next_xxx?

something like this could conceptually be grouped with the git_blame API

I think this is a good proposal.

@carlosmn
Copy link
Member

This feels like something that should be in snippets, rather than integrated directly into the library. It's a very specific wrapping of the revision walker. Why go inside the revwalk's guts instead of using it?

@arrbee
Copy link
Member

arrbee commented Mar 30, 2014

This feels like something that should be in snippets, rather than integrated directly into the library. It's a very specific wrapping of the revision walker. Why go inside the revwalk's guts instead of using it?

That makes sense to me, although I think this feature is asked for frequently enough that making it super simple to walk to the last commit to modify a file would be a nice helper to add.

I'm also wondering what we can do to make it easier to write code like this without feeling like we need to expose internal APIs. When we discussed the callback function for the revwalk, one idea was exposing the commit list node - I'm wondering if this is a use case for that so that you can more easily get the list of parents.

Actually, I guess there is not much advantage to that because since you need to get the tree and the parent trees, you'll need to do the full lookups anyhow. There isn't much efficiency to be gained by exposing revwalk internals.

As for labeling every blob in a tree with the latest commit to change it, it seems like that's mostly a bookkeeping exercise as you do a revwalk, yes? If you want, you can use git_diff_tree_to_tree with a git_diff_notify_callback to do the changed blob marking (just return 1 all the time and you can avoid all the allocations, so that will be pretty efficient, I think).

@carlosmn
Copy link
Member

It's a common request, but it doesn't represent the underlying work that would be done. Getting the last commit is a special case of filtering by path. We can add that to the revwalk as long as we make sure to advertise the limitation that it's not history simplification at all and the resulting history will be disconnected.

If we're adding that, then we should should start by adding filtering for a single path, rather than something like git_revwalk_next_for_path which would require book-keeping for every path we might have ever seen in case the user ever changes their mind on what path they want to use.

As for the whole-tree one, that would be something like git_blame_tree, as that's what the git script is called, which would do it all at once using the revwalk. But I think that should be a different PR, as it refers to something that's orthogonal to this.

@Aimeast
Copy link
Contributor Author

Aimeast commented Mar 31, 2014

So, in summary,

  • In the cases of finding the last effected commit for single blob/tree/link, implement it in the namespace git_revwalk_xxx
  • In the cases of whole-tree search, implement it in the namepsace git_blame_xxx (should open a new issue)

right? It's OK for me. I'd like continue to complete it.

@carlosmn
Copy link
Member

Yeah, it should be in git_revwalk, but not just in that namespace, but as an option to the revwalk, just like the first-parent choice or where to start and stop.

@carlosmn
Copy link
Member

I've opened issue #3041 to keep track of the interface which would allow for use-cases such as this one in a way which doesn't assume knowledge of the internals.

@carlosmn carlosmn closed this Apr 13, 2015
tbeu added a commit to tbeu/WDX_GitCommander that referenced this pull request Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants