Skip to content

Conversation

@racgoo
Copy link
Contributor

@racgoo racgoo commented Dec 27, 2025

Summary

  • Add 'reflog' feature with tests.

Changes

  • Implement reflog-like methods in 'Repository'
  • Add internal reflog features with 'ReflogEntry'
  • Add test code

Question

@seokju-na I have a small question regarding the error-handling pattern used here (also seen in 'tree.rs' and 'stash.rs').
In 'reflog.get' (reflog.rs:228), the error created by 'ok_or(Error::new(...))' seems to be discarded immediately because the result is converted with '.ok()', collapsing all errors into 'None'.
Since I couldn't find a better approach myself, I wanted to ask whether there is a more idiomatic way to express this without constructing an unused error.

Closes #171

@racgoo racgoo requested a review from seokju-na as a code owner December 27, 2025 11:50
@vercel
Copy link

vercel bot commented Dec 27, 2025

@racgoo is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

src/reflog.rs Outdated
/// ```
///
/// @returns Message bytes of this reflog entry. Returns `null` if no message is present.
pub fn message_bytes(&self) -> Option<Uint8Array> {
Copy link
Collaborator

@seokju-na seokju-na Dec 28, 2025

Choose a reason for hiding this comment

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

I think this method seems unnecessary, as it's rare case to handle messages as a uint8array.

Instead of returning a nullable message in message() method, how about throw an error if the message isn't UTF-8?

e.g.

pub fn message(&self) -> crate::Result<Option<String>> {
  // ... throw if message is not utf-8
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. Rather than fully exposing git2’s interface, I’ll adopt the more practical approach you suggested.

src/reflog.rs Outdated
/// @param {number} i - Index of the entry to remove.
/// @param {boolean} rewritePreviousEntry - Whether to rewrite the previous entry.
/// @throws Throws error if the index is invalid or if removal fails.
pub fn remove(&mut self, i: u32, rewrite_previous_entry: bool) -> crate::Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub fn remove(&mut self, i: u32, rewrite_previous_entry: bool) -> crate::Result<()> {
pub fn remove(&mut self, i: u32, rewrite_previous_entry: Option<bool>) -> crate::Result<()> {

Since libgit2 expect rewrite_previous_entry default value as 0, so how about receiving it as an optional value and handling the default value internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed that. I’ll change it to “Option” and handle the default internally to match git2’s behavior. Thanks!

@seokju-na
Copy link
Collaborator

About the question:

Since reflog.get() returns None for non-existent indices, I think the current implementation is fine as it is an error that is not exposed to the interface. 👍

@racgoo
Copy link
Contributor Author

racgoo commented Dec 28, 2025

@seokju-na I’ve addressed all the review comments and pushed an updated commit.
Please review when convenient.

@vercel
Copy link

vercel bot commented Dec 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
es-git Ready Ready Preview, Comment Dec 28, 2025 8:07am

Copy link
Collaborator

@seokju-na seokju-na left a comment

Choose a reason for hiding this comment

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

LGTM. thanks!

@seokju-na seokju-na merged commit f871f1e into toss:main Dec 28, 2025
27 checks passed
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.

reflog

2 participants