Skip to content

Reflog completionism#2081

Merged
vmg merged 15 commits intodevelopmentfrom
bs/reflog
Jan 31, 2014
Merged

Reflog completionism#2081
vmg merged 15 commits intodevelopmentfrom
bs/reflog

Conversation

@ben
Copy link
Copy Markdown
Member

@ben ben commented Jan 27, 2014

I found some issues when writing libgit2/libgit2sharp#612.

  • Add signature and log_message parameters to git_repository_set_head
  • Add signature and log_message parameters to git_repository_set_head_detached
  • Test that updating or creating HEAD updates the reflog properly
  • Add signature and log_message parameters to git_branch_create
  • Test that creating a branch updates the reflog properly
  • Add signature parameter to git_clone_options and git_clone_into
  • Test that cloning updates the reflog properly
  • Reflog params for git_branch_move (+tests)
  • Add signature and log_message parameters to git_reference_rename (+tests)
  • Branch API has reasonable default log messages

@ben
Copy link
Copy Markdown
Member Author

ben commented Jan 27, 2014

I think this does everything I set out to do. I think all the APIs that move or create references now have the ability to update the reflog in an appropriate way. Did I miss anything? /cc @carlosmn

@carlosmn
Copy link
Copy Markdown
Member

Re, test_refs_branches_create__recreation_updates_existing_reflog, did you check against git? I'm not sure that this isn't an oversight in the reflog code.

EDIT: get the right name

@nulltoken
Copy link
Copy Markdown
Member

@ben you rock! BTW, shouldn't we also consider passing a signature to git_branch_move()?

@try1morex
Copy link
Copy Markdown

How do I see the information?

@nulltoken
Copy link
Copy Markdown
Member

@try1morex I'm not sure I completely understand your question. Could you please refine it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should read cl_assert_equal_i(1, git_reflog_entrycount(log)). Removing a ref removes its reflog as well. If we don't, that's a bug in our implementation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently, you have to call git_reflog_delete to remove the reflog of a deleted branch.

I'm not exactly sure if that's a bug, though. I like that we're making sure the reflog gets updated, but the fact that there's no way to recover the data makes me want to give the caller the option (and mention this in the docs).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two branches having the same name doesn't mean that they're the same, and giving it the reflog history of something else is going to cause confusion at best.

Or consider git branch foo && git branch -d foo && git branch foo/bar (or their update-ref equivalents. If we don't remove the reflog in the second command, we can't create the reflog for the third.

Losing the reflog information is indeed something that can be a bit troublesome, but we can't fix it by keeping it in the normal reflog namespace. We'd need an attic where the names/keys don't behave like files and directories.

EDIT: there's been some discussion about this in the git ML, the term there is "reflog graveyard"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Okay, you've convinced me. It shall be fixed.

@carlosmn
Copy link
Copy Markdown
Member

I think @nulltoken is right and git_branch_move() should also get a signature+message. In case of the git_branch namespace, we could consider a NULL message to mean to use a sane default (i.e. what git-core uses) since they're higher-level functions and we know what the action is that we're performing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This technically differs from what git provides, but I'm not sure how we can fix this without extra context:

$ git branch temp4 HEAD~
$ git reflog temp4
b2eb7ec temp4@{0}: branch: Created from HEAD~

I think it's reasonable to deviate a bit here; if the caller wants to provide this context, they are free to.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about adding to oid to the message? eg. branch: Created from deadbeefcafe...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmmm. Might not be worth it as the target oid is already part of the reflog entry... Although that may be a little easier to parse for a user.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Git in this case has more context than we do, but it's not too bad, you can only do so much. If bindings want to optionally take rev-parse-like strings instead of oids, then they could fill in a better default message.

The 'created from X' part seems to be as a way of figuring out what command you run, but as we don't have commands in that sense, I wouldn't worry too much about not having 1-to-1 messages.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I went ahead and started the work to port this to libgit2sharp, and one of the overloads there does the right thing, which makes sense, since it has all the info necessary to do so. This seems like a sensible pattern, so I think I'll just make a stronger recommendation in the doc-comments.

@ben
Copy link
Copy Markdown
Member Author

ben commented Jan 28, 2014

I think I might be done here?

@arthurschreiber
Copy link
Copy Markdown
Member

@ben 👍 Really looking forward to seeing this merged. :)

@vmg
Copy link
Copy Markdown
Member

vmg commented Jan 28, 2014

Looks good to me. Somebody else wants to approve?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When NULL, a default log message will be generated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How's this? b3558d8

@nulltoken
Copy link
Copy Markdown
Member

😍

src/clone.c Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have a user-provided signature here, shouldn't we be passing it to the function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

😊 I suppose I should write tests for all of those, shouldn't I?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

@ben
Copy link
Copy Markdown
Member Author

ben commented Jan 31, 2014

Rebased and (I think) ready to go.

vmg pushed a commit that referenced this pull request Jan 31, 2014
@vmg vmg merged commit f9500b4 into development Jan 31, 2014
@ben ben deleted the bs/reflog branch January 31, 2014 17:57
phatblat pushed a commit to phatblat/libgit2 that referenced this pull request Sep 13, 2014
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.

6 participants