Search Commits via Commit Hash #7400
Labels
No Label
backport/done
backport/v1.0
backport/v1.1
backport/v1.10
backport/v1.11
backport/v1.12
backport/v1.13
backport/v1.14
backport/v1.15
backport/v1.2
backport/v1.3
backport/v1.4
backport/v1.5
backport/v1.6
backport/v1.7
backport/v1.8
backport/v1.9
bounty
changelog
dependencies
frontport/done
frontport/main
good first issue
Hacktoberfest
hacktoberfest-accepted
in progress
kind/api
kind/breaking
kind/bug
kind/build
kind/deployment
kind/deprecated
kind/docs
kind/enhancement
kind/feature
kind/lint
kind/misc
kind/moderation
kind/package
kind/proposal
kind/question
kind/refactor
kind/regression
kind/security
kind/summary
kind/testing
kind/translation
kind/ui
kind/upstream-related
kind/usability
kind/ux
lgtm/done
lgtm/need 1
lgtm/need 2
performance/bigrepo
performance/cpu
performance/memory
performance/speed
priority/critical
priority/low
priority/maybe
priority/medium
proposal/rejected
reviewed/confirmed
reviewed/duplicate
reviewed/fixed
reviewed/invalid
reviewed/not-a-bug
reviewed/wontfix
skip-changelog
stale
status/blocked
status/needs-feedback
status/wip
theme/2fa
theme/authentication
theme/avatar
theme/backup-restore
theme/docker
theme/federation
theme/issues
theme/kanban
theme/markdown
theme/migration
theme/mobile
theme/pr
theme/signing
theme/sqlite
theme/timetracker
theme/webhook
theme/wiki
No Milestone
No project
No Assignees
1 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: lunny/gitea#7400
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "enh/7395/search-via-commit-hash"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #7395
Commit history can now be searched with commit hash.
EDIT: whoops, slight mistake in the test case. I'll fix it in a bit.
EDIT2: should be fixed now.
Codecov Report
54% <92.85%> (+2.71%)
62.16% <0%> (-5.41%)
73.17% <0%> (-0.98%)
65.64% <0%> (+1.02%)
Continue to review full report at Codecov.
@ -223,3 +219,3 @@
for _, v := range opts.Committers {
cmd.AddArguments("--committer=" + v)
args = append(args, "--committer="+v)
}
I don't think this is right, because there is a prameter
-100
before.Maybe we could add an extra
git log <keyword> -1
to get all output whenkeyword
didn't containers:
and then merge the output with original.Wouldn't that only match a single commit hash? In Gitea's commit history, there are 4 hashes that start with
46d3
so doinggit log 46d3 -1
only outputs the most recent one or errors, I don't remember which. Also, do we want this matching only from the start or from the middle of the commit hash as well?EDIT: Okay, not
46d3
but I do remember finding a two commit hashes that had the same first 4 characters.@ -223,3 +219,3 @@
for _, v := range opts.Committers {
cmd.AddArguments("--committer=" + v)
args = append(args, "--committer="+v)
}
I didn't think about that. The commit hash search would not go back as far as the grep search.
@gary-kim I think we should only match prefix what is the
git log
does.@lunny Okay, done.
@ -30,1 +30,4 @@
func TestRepoCommitsSearch(t *testing.T) {
testRepoCommitsSearch(t, "e8eabd", "")
testRepoCommitsSearch(t, "38a9cb", "")
testRepoCommitsSearch(t, "6e8e", "6e8eabd9a7")
Could we have a failed test.
@gary-kim Good work! Two small things we may need to consider:
git
command, so why we useprettyLogFormat
parameter? Just parse the full commit information may give us better performance.Of course this issue is out of this PR. I just found that there.
@ -30,1 +30,4 @@
func TestRepoCommitsSearch(t *testing.T) {
testRepoCommitsSearch(t, "e8eabd", "")
testRepoCommitsSearch(t, "38a9cb", "")
testRepoCommitsSearch(t, "6e8e", "6e8eabd9a7")
Sorry, I'm not sure what you mean by that.
I just pushed a commit that should solve this issue.
I did find that strange as well. Could I open a PR after this to try and address that?
@ -30,1 +30,4 @@
func TestRepoCommitsSearch(t *testing.T) {
testRepoCommitsSearch(t, "e8eabd", "")
testRepoCommitsSearch(t, "38a9cb", "")
testRepoCommitsSearch(t, "6e8e", "6e8eabd9a7")
I think to have a search that should not match anything, to test that it works right when there is nothing to match also.
So if there is no commit
58f73d1a78
then do a search for that and make sure it returns empty and not something else.@ -30,1 +30,4 @@
func TestRepoCommitsSearch(t *testing.T) {
testRepoCommitsSearch(t, "e8eabd", "")
testRepoCommitsSearch(t, "38a9cb", "")
testRepoCommitsSearch(t, "6e8e", "6e8eabd9a7")
Okay, sounds good.
@ -30,1 +30,4 @@
func TestRepoCommitsSearch(t *testing.T) {
testRepoCommitsSearch(t, "e8eabd", "")
testRepoCommitsSearch(t, "38a9cb", "")
testRepoCommitsSearch(t, "6e8e", "6e8eabd9a7")
Alright, added a few.
Yes, please.
I just took a better look at how
parsePrettyFormatLogToList
works and I think I'll need some time to understand this codebase a little more before working on this. If someone else would like to work on this, great, please go ahead! If not, I'll get back to this later.@gary-kim There seems to be a more straightforward approach.
hashes
, for example).hashes
slice to the end of the command.git log
only uses the first commit hash in the command so I don't think appending hashes to the end of the command is going to do anything.Also, there would need to be a check to make sure it is actually a commit first anyways because
parsePrettyFormatLogToList
returns an error if any of the given commits are not actual commits.@gary-kim Yeah, that does not work as I expected :(
My rationale is that it would be nice if the seemingly duplicate code paths (
cmd
andargs
) can be unified into one.It is probably not easy though.
By the way, what is the expected behavior of the hash keyword? Do they OR or AND with other conditions?
They will act similarly to the keywords. The commit needs to match all the given conditions such as
author:
and at least one of the keywords/hashes. From a user's standpoint, it's as if the hash has become part of the commit message.That is possible. Although, personally, I'd rather keep it as it is. Essentially, the original command can also built using the
args
slice at the end. The slight issue is what the command needs to run starts to really diverge before the command can be run which will make the last little bit of the function kind of messy.@lunny What do you think?
@gary-kim I think it's enough for this PR. @typeless is the original author of this feature. :)
Thank you @typeless for this feature and everyone else who has contributed to Gogs/Gitea.
@gary-kim you're welcome. I am a user benefited from this project too.
I am not going to block the PR if there is no clear way to improve it. But it still needs another maintainer's review & approval.
@typeless I got rid of the duplicate code paths. What do you think?
The constant 6 here is a little bit mysterious.
Why does it have to trim the ‘\n’?
My bad, I kind of changed that without thinking about it. Changed it back to 4. The idea is it's probably not worth checking strings that are too short.
New commits are added on by appending new hashes and a new line but you make a good point. Could just move the new line to before the hash.
EDIT: Done
EDIT2: Turns out that was needed to prevent 500 errors. I put it back in.
Okay, it looks like a problem of how parsePrettyFormatLogToList handles its input.
@gary-kim LGTM
I think the constant 4 or 6 deserves a comment. I can figure that it is related to how
git
recognize the shortest allowed input hash. But it is not apparent simply looking at the code.CI failed.
Fixed.
@typeless you are not a maintainer yet but you have satisfied the condition, please send a PR to apply for that. Otherwise your approval will not be counted.
@ -241,0 +246,4 @@
for _, v := range opts.Keywords {
if len(v) >= 4 {
hashCmd := NewCommand("log", "-1", prettyLogFormat)
hashCmd.AddArguments(args...)
If I'm getting this code right, you always add the first
'\n'
and then always remove the last one withTrimSuffix()
. Perhaps it would be easier to prepend'\n'
when required? e.g. change:stdout = append(stdout, hashMatching...)
into
stdout = append(stdout, '\n', hashMatching...)
and remove the other appends & TrimSuffix?
Check for simplification on
'\n'
handling.@ -241,0 +246,4 @@
for _, v := range opts.Keywords {
if len(v) >= 4 {
hashCmd := NewCommand("log", "-1", prettyLogFormat)
hashCmd.AddArguments(args...)
The issue with prepending is that
repo.parsePrettyFormatLogToList
is a very picky function. Having any empty line will result in a 500 error. By prepending, if the first command did not return any results, you could end up with an empty line at the start. You could check for if the line is empty beforehand but then you have an extra if statement that runs very time during the loop.The important part is that the first
'\n'
is only added if the original command did not return anything.Also, the multiple appends were needed because Go does not let you use
...
as a part, not the whole of a variadic function parameter.@ -241,0 +246,4 @@
for _, v := range opts.Keywords {
if len(v) >= 4 {
hashCmd := NewCommand("log", "-1", prettyLogFormat)
hashCmd.AddArguments(args...)
OK, I see it now.