gitea icon indicating copy to clipboard operation
gitea copied to clipboard

Refactor submodule related code

Open lunny opened this issue 4 months ago • 5 comments

  1. Move the submodule cache from git.Commit to git.Tree. Submodule information is parsed from the .submodule file located in the commit’s tree.
  2. Rename CommitSubmoduleFile to SubmoduleFile.
  3. Remove TemplateSubmoduleCommit and replace it with SubmoduleFile. • Rename GetTemplateSubmoduleCommits to GetRepoSubmoduleFiles. • Rename AddTemplateSubmoduleIndexes to AddSubmodulesToRepoIndex.

lunny avatar Dec 05 '25 03:12 lunny

SubmoduleFile is a wrong name.

It is indeed a "commit"

wxiaoguang avatar Dec 05 '25 05:12 wxiaoguang

SubmoduleFile is a wrong name.

It is indeed a "commit"

A commit should not directly contain any files or path. Files belong to trees, and a submodule is represented as a special type of entry within a tree. A submodule could point to a commit.

         Commit
       /         \
      /           \
(parent SHA)     Tree
(author)         /   \
(committer)   Blob   Blob
(timestamps)
(etc)

lunny avatar Dec 05 '25 06:12 lunny

Files belong to trees, and a submodule is represented as a special type of entry within a tree. A submodule could point to a commit.

Yes, "files" belong to trees, but "submodule" is not a file. It is an entry pointing to a commit.

So SubmoduleFile is a wrong name: it is not a file.


Old name CommitSubmoduleFile is not right either, it was just a temp change for old SubModuleFile + NewSubModuleFile from 1ebb35b9 (even earlier from an external package) to clarify it is only for displaying the submodule commit on the UI.

wxiaoguang avatar Dec 05 '25 06:12 wxiaoguang

I can rename it to Submodule or gitlink. I can only find the two official names from git documentation.

lunny avatar Dec 05 '25 06:12 lunny

  1. Move the submodule cache from git.Commit to git.Tree. Submodule information is parsed from the .submodule file located in the commit’s tree.

Also, I don't think the proposed relation is right.

tree can also be a sub-tree.

But the submodules only belong to the commit's root tree, so belonging to the commit is right.

wxiaoguang avatar Dec 05 '25 06:12 wxiaoguang