Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here's how I show last commit & history of directories / files #16206

Closed
1 of 6 tasks
lchrennew opened this issue Jun 19, 2021 · 0 comments · Fixed by #17652
Closed
1 of 6 tasks

Here's how I show last commit & history of directories / files #16206

lchrennew opened this issue Jun 19, 2021 · 0 comments · Fixed by #17652
Labels
modifies/api This PR adds API routes or modifies them

Comments

@lchrennew
Copy link

  • Gitea version (or commit ref): 1.14.2
  • Git version:
  • Operating system:
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist:

Description

...

Hello there,

I'm sharing my implementation for showing last commit and commits of directories and files via api.

I do this by myself because the APIs of current version of Gitea not provide these. (expecting new version will).

I use redis to build indices:

  1. Build last commit sha index for all files of each commit.
  2. Build commit history index for each file changed in each commit.
  3. Build commit summary index for each commit.

last commit sha index

key:

`{files:${owner}:${repo}}:${ref}` // ref is sha of commit or refs/tags/... or refs/heads/...

value: Hash<filename, sha>, every path visible, including the root path, are tracked.

When a commit is pushed to a branch:

  1. if the branch does not exist before(the key doesn't exist), copy the files of the before commit to this branch. using redis COPY command.
  2. update all paths affected by files changed on the branch. using redis HMSET command.
  3. copy the files of the branch to the after commit. usinig redis COPY command.

To ls a path, you could combine the response of GET /repos/{owner}/{repo}/contents/{filepath} API and the result of HMGET command.

commit history index:

key:

`{commits:${owner}:${repo}}:${sha}:${filename}`

value: List<sha>, all commits' sha are tracked in newer to older order.

When a commit is pushed to a branch:

  1. if the branch does not exist before(the key doesn't exist), push the sha of the before commit to all paths affected by files changed on this branch. using redis LPUSH command.
  2. push the sha of the after commit to all paths affected by files changed on this branch. using redis LPUSH command.
  3. copy all paths updated on this branch to the after commit. using redis COPY command.
  4. create commit summary: HMSET {commit:$owner:$repo}:$sha message '$message' timestamp '$timestamp' author '$author'

To query history of a path, you could use LRANGE to get the SHA list and then use MGET to get commit summaries.

Screenshots

@noerw noerw added the modifies/api This PR adds API routes or modifies them label Jun 27, 2021
zeripath pushed a commit that referenced this issue Dec 22, 2021
Adds an API endpoint `api/v1/repos/{owner}/{repo}/git/history/{filepath}` to get the commits affecting the given file or directory.

Closes #16206 and closes #16703
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
Adds an API endpoint `api/v1/repos/{owner}/{repo}/git/history/{filepath}` to get the commits affecting the given file or directory.

Closes go-gitea#16206 and closes go-gitea#16703
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
modifies/api This PR adds API routes or modifies them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants