Skip to content

feat(timeout): add "timeout_ms" and "max_parent_commits" options#297

Open
linrongbin16 wants to merge 11 commits intomasterfrom
timeout
Open

feat(timeout): add "timeout_ms" and "max_parent_commits" options#297
linrongbin16 wants to merge 11 commits intomasterfrom
timeout

Conversation

@linrongbin16
Copy link
Copy Markdown
Owner

@linrongbin16 linrongbin16 commented Apr 1, 2026

Close #296

Adds a "timeout_ms" (in milliseconds) option, by default it is 1000ms (1 sec).

As this plugin will run multiple git commands in a local git repository to find out all the correct remote git host information it needs to construct a remote git permlink. If running commands cost too long time, which is greater than "timeout_ms", then it will directly return an error message.

Also adds a "max_parent_commits" (count) option, by default it is 10.

This plugin will try to find the correct commit ID to match between local git repo and remote git repo, with following method:

  1. First try git rev-parse @{u}, in a correctly remote-url configured git repo, this should work.
  2. Then try git rev-parse HEAD to find out the latest remote repo commit ID.
  3. At last, try git rev-parse HEAD~{1,10} to find out a closest compatible commit ID in remote git repo. In this case, the 10 is the maximum parent commits we will try. In previous implement, this max value is 50, which can cost a long time. In this PR, I add this "max_parent_commits" option to let user decide how many commits they want to find.

Test Platforms

  • windows
  • macOS
  • linux

Test Hosts

Test Functions

  • Use GitLink(!) to copy git link (or open in browser).
  • Use GitLink(!) blame to copy the /blame link (or open in browser).
  • Use GitLink(!) default_branch to open the /main//master link in browser (or open in browser).
  • Use GitLink(!) current_branch to open the current branch link in browser (or open in browser).
  • Copy git link in a symlink directory of git repo.
  • Copy git link in an un-pushed git branch, and receive an expected error.
  • Copy git link in a pushed git branch but edited file, and receive a warning says the git link could be wrong.
  • Copy git link with 'file' and 'rev' parameters.

Comment thread lua/gitlinker/git.lua
end
else
for i = 1, 50 do
for i = 1, max_parent_commits do
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I guess the "super long commands running time" is mostly caused by here.

Because in worst case, it will run some git commands for 50 times, which of course cost too long time. I reduced this parameter to 5. Usually in a correctly remote-url configured git repository, it should be called for only once.

@linrongbin16 linrongbin16 changed the title feat(timeout): add "timeout_ms" option to set max git commands running time feat(timeout): add "timeout_ms" and "max_parent_commits" options Apr 1, 2026
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.

Add a timeout setting for open operations

1 participant