mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	add pure go git lib to instead cgo git lib
This commit is contained in:
		| @@ -9,7 +9,6 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
| 	"os" | 	"os" | ||||||
| 	"path" |  | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" | 	"time" | ||||||
| @@ -262,11 +261,7 @@ func GetRepositoryCount(user *User) (int64, error) { | |||||||
| 	return orm.Count(&Repository{OwnerId: user.Id}) | 	return orm.Count(&Repository{OwnerId: user.Id}) | ||||||
| } | } | ||||||
|  |  | ||||||
| const ( | /* | ||||||
| 	RFile = iota + 1 |  | ||||||
| 	RDir |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| type RepoFile struct { | type RepoFile struct { | ||||||
| 	Id      *git.Oid | 	Id      *git.Oid | ||||||
| 	Type    int | 	Type    int | ||||||
| @@ -282,15 +277,19 @@ func (f *RepoFile) IsFile() bool { | |||||||
|  |  | ||||||
| func (f *RepoFile) IsDir() bool { | func (f *RepoFile) IsDir() bool { | ||||||
| 	return f.Type == git.FilemodeTree | 	return f.Type == git.FilemodeTree | ||||||
| } | }*/ | ||||||
|  |  | ||||||
|  | /* | ||||||
| func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { | func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { | ||||||
| 	f := RepoPath(userName, reposName) | 	f := RepoPath(userName, reposName) | ||||||
|  |  | ||||||
| 	repo, err := git.OpenRepository(f) | 	repo, err := git.OpenRepository(f) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	repo.LookupReference("refs/heads/" + branchName) | ||||||
|  |  | ||||||
| 	obj, err := repo.RevparseSingle("HEAD") | 	obj, err := repo.RevparseSingle("HEAD") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @@ -322,20 +321,8 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, | |||||||
| 		return 0 | 		return 0 | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
| 	/*for ; i < tree.EntryCount(); i++ { |  | ||||||
| 		entry := tree.EntryByIndex(i) |  | ||||||
|  |  | ||||||
| 		repofiles = append(repofiles, &RepoFile{ |  | ||||||
| 			entry.Id, |  | ||||||
| 			entry.Filemode, |  | ||||||
| 			entry.Name, |  | ||||||
| 			lastCommit.Message(), |  | ||||||
| 			lastCommit.Committer().When, |  | ||||||
| 		}) |  | ||||||
| 	}*/ |  | ||||||
|  |  | ||||||
| 	return repofiles, nil | 	return repofiles, nil | ||||||
| } | }*/ | ||||||
|  |  | ||||||
| func StarReposiory(user *User, repoName string) error { | func StarReposiory(user *User, repoName string) error { | ||||||
| 	return nil | 	return nil | ||||||
|   | |||||||
							
								
								
									
										61
									
								
								models/repo2.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								models/repo2.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | |||||||
|  | package models | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"path" | ||||||
|  | 	"time" | ||||||
|  |  | ||||||
|  | 	git "github.com/speedata/gogit" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | type RepoFile struct { | ||||||
|  | 	Id      *git.Oid | ||||||
|  | 	Type    int | ||||||
|  | 	Name    string | ||||||
|  | 	Path    string | ||||||
|  | 	Message string | ||||||
|  | 	Created time.Time | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (f *RepoFile) IsFile() bool { | ||||||
|  | 	return f.Type == git.FileModeBlob || f.Type == git.FileModeBlobExec | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (f *RepoFile) IsDir() bool { | ||||||
|  | 	return f.Type == git.FileModeTree | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) { | ||||||
|  | 	f := RepoPath(userName, reposName) | ||||||
|  |  | ||||||
|  | 	repo, err := git.OpenRepository(f) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	ref, err := repo.LookupReference("refs/heads/" + branchName) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	lastCommit, err := repo.LookupCommit(ref.Oid) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	var repofiles []*RepoFile | ||||||
|  | 	lastCommit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int { | ||||||
|  | 		if dirname == rpath { | ||||||
|  | 			repofiles = append(repofiles, &RepoFile{ | ||||||
|  | 				entry.Id, | ||||||
|  | 				entry.Filemode, | ||||||
|  | 				entry.Name, | ||||||
|  | 				path.Join(dirname, entry.Name), | ||||||
|  | 				lastCommit.Message(), | ||||||
|  | 				lastCommit.Committer.When, | ||||||
|  | 			}) | ||||||
|  | 		} | ||||||
|  | 		return 0 | ||||||
|  | 	}) | ||||||
|  |  | ||||||
|  | 	return repofiles, nil | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user