Add tracking info for log subcommand by SandrineP · Pull Request #106 · QuantStack/git2cpp · GitHub
Skip to content

Add tracking info for log subcommand#106

Merged
ianthomas23 merged 3 commits into
QuantStack:mainfrom
SandrineP:log_tracking
Feb 27, 2026
Merged

Add tracking info for log subcommand#106
ianthomas23 merged 3 commits into
QuantStack:mainfrom
SandrineP:log_tracking

Conversation

@SandrineP

@SandrineP SandrineP commented Feb 25, 2026

Copy link
Copy Markdown
Collaborator

Fix #90
Add tracking info for log subcommand

@SandrineP SandrineP marked this pull request as ready for review February 25, 2026 15:54
@codecov

codecov Bot commented Feb 25, 2026

Copy link
Copy Markdown

@ianthomas23

Copy link
Copy Markdown
Member

The tag and branch information looks really good, and the whitespace between commits is different but not the same as in real git:

Screenshot 2026-02-26 at 10 40 42

@SandrineP

Copy link
Copy Markdown
Collaborator Author

The tag and branch information looks really good, and the whitespace between commits is different but not the same as in real git:

I looked at the extra newlines, and I thought that there was always a trailing one at the end of the message in git2cpp. So I changed the code a bit and in the tests I made, there was only a newline at the very end that is not there with git. The rest was identical. So I thought it was fine, but apparently not ! I'll have another look.

@SandrineP SandrineP changed the title Add tracking info Add tracking info for log subcommand Feb 26, 2026
Comment thread src/subcommand/log_subcommand.cpp Outdated
}
}

git_strarray_dispose(&tag_names);

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 is not exception-safe. However, we cannot use the git_strarray_wrapper here, since this class actually wraps a git_strarray whose elements point to already allocating strings (and thus, git_strarray_dispose is not called in the destructor to avoid double deletion).

Which leads me to think that the current git_strarray_wrapper is probably badly named. And that we should have a git_strarray_wrapper that frees both git_strarray elements and the array itself.

But this implies refactoring and goes beyond the scope of this PR, so let's add a TODO here and open an issue to track it when we merge this PR.

Comment thread src/subcommand/log_subcommand.cpp Outdated
Comment on lines +110 to +111
std::string branch_name;
branch_name = branch->name();

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.

Suggested change
std::string branch_name;
branch_name = branch->name();
std::string branch_name = branch->name();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I wrote it this way because it's not happy with the one line option:
error: conversion from 'std::string_view' {aka 'std::basic_string_view<char>'} to non-scalar type 'std::string' {aka 'std::__cxx11::basic_string<char>'} requested

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

std::string branch_name(branch->name());

instead, which works for me on macos?

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.

I missed that the return type of branch::name was std::string_view. In that case the correct solution is the line from Ian.

Comment thread src/subcommand/log_subcommand.cpp Outdated
return tags;
}

std::vector<std::string> get_branches_for_commit(repository_wrapper& repo, git_branch_t type, const git_oid* commit_oid, const std::string exclude_branch)

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.

commit_oid should be passed by reference insteadof pointer.

Comment thread src/subcommand/log_subcommand.cpp Outdated
}
};

commit_refs get_refs_for_commit(repository_wrapper& repo, const git_oid* commit_oid)

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.

commit_oid should be passed by reference instead of pointer.

Comment thread src/subcommand/log_subcommand.cpp Outdated
return refs;
}

void print_refs(commit_refs refs)

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.

refs should be passed by constant reference.

@ianthomas23 ianthomas23 left a comment

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.

The whitespace looks excellent now thanks, and I've checked all of Johan's comments too and this is ready to merge.

I've left the one comment about the branch_name string, feel free to make that change or not.

Comment thread src/subcommand/log_subcommand.cpp Outdated
}

void print_commit(const commit_wrapper& commit, std::string m_format_flag)
std::vector<std::string> get_tags_for_commit(repository_wrapper& repo, const git_oid* commit_oid)

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.

The commit_oid parameter should be passed by reference.

@ianthomas23

Copy link
Copy Markdown
Member

@ianthomas23 ianthomas23 merged commit 1ba9701 into QuantStack:main Feb 27, 2026
7 of 8 checks passed
@SandrineP SandrineP deleted the log_tracking branch February 27, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce whitespace in log subcommand

3 participants