rename fields

This commit is contained in:
Unknwon 2015-11-03 22:49:06 -05:00
parent 6f0a41b8b2
commit 3a81fdf092
20 changed files with 67 additions and 46 deletions

View File

@ -258,7 +258,7 @@ func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string, maxline
cmd = exec.Command("git", "show", afterCommitId) cmd = exec.Command("git", "show", afterCommitId)
} else { } else {
c, _ := commit.Parent(0) c, _ := commit.Parent(0)
cmd = exec.Command("git", "diff", "-M", c.Id.String(), afterCommitId) cmd = exec.Command("git", "diff", "-M", c.ID.String(), afterCommitId)
} }
} else { } else {
cmd = exec.Command("git", "diff", "-M", beforeCommitId, afterCommitId) cmd = exec.Command("git", "diff", "-M", beforeCommitId, afterCommitId)

View File

@ -64,7 +64,7 @@ func createTag(gitRepo *git.Repository, rel *Release) error {
return err return err
} }
if err = gitRepo.CreateTag(rel.TagName, commit.Id.String()); err != nil { if err = gitRepo.CreateTag(rel.TagName, commit.ID.String()); err != nil {
return err return err
} }
} else { } else {

View File

@ -140,7 +140,7 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
actEmail = commit.Committer.Email actEmail = commit.Committer.Email
} }
commits = append(commits, commits = append(commits,
&base.PushCommit{commit.Id.String(), &base.PushCommit{commit.ID.String(),
commit.Message(), commit.Message(),
commit.Author.Email, commit.Author.Email,
commit.Author.Name, commit.Author.Name,

View File

@ -18,7 +18,7 @@ type Blob struct {
} }
func (b *Blob) Data() (io.Reader, error) { func (b *Blob) Data() (io.Reader, error) {
stdout, stderr, err := com.ExecCmdDirBytes(b.repo.Path, "git", "show", b.Id.String()) stdout, stderr, err := com.ExecCmdDirBytes(b.repo.Path, "git", "show", b.ID.String())
if err != nil { if err != nil {
return nil, errors.New(string(stderr)) return nil, errors.New(string(stderr))
} }

View File

@ -14,7 +14,7 @@ import (
// Commit represents a git commit. // Commit represents a git commit.
type Commit struct { type Commit struct {
Tree Tree
Id sha1 // The id of this commit object ID sha1 // The id of this commit object
Author *Signature Author *Signature
Committer *Signature Committer *Signature
CommitMessage string CommitMessage string
@ -35,7 +35,7 @@ func (c *Commit) Summary() string {
// Return oid of the parent number n (0-based index). Return nil if no such parent exists. // Return oid of the parent number n (0-based index). Return nil if no such parent exists.
func (c *Commit) ParentId(n int) (id sha1, err error) { func (c *Commit) ParentId(n int) (id sha1, err error) {
if n >= len(c.parents) { if n >= len(c.parents) {
err = IdNotExist err = IDNotExist
return return
} }
return c.parents[n], nil return c.parents[n], nil
@ -61,7 +61,7 @@ func (c *Commit) ParentCount() int {
} }
func (c *Commit) CommitsBefore() (*list.List, error) { func (c *Commit) CommitsBefore() (*list.List, error) {
return c.repo.getCommitsBefore(c.Id) return c.repo.getCommitsBefore(c.ID)
} }
func (c *Commit) CommitsBeforeUntil(commitId string) (*list.List, error) { func (c *Commit) CommitsBeforeUntil(commitId string) (*list.List, error) {
@ -73,19 +73,19 @@ func (c *Commit) CommitsBeforeUntil(commitId string) (*list.List, error) {
} }
func (c *Commit) CommitsCount() (int, error) { func (c *Commit) CommitsCount() (int, error) {
return c.repo.commitsCount(c.Id) return c.repo.commitsCount(c.ID)
} }
func (c *Commit) SearchCommits(keyword string) (*list.List, error) { func (c *Commit) SearchCommits(keyword string) (*list.List, error) {
return c.repo.searchCommits(c.Id, keyword) return c.repo.searchCommits(c.ID, keyword)
} }
func (c *Commit) CommitsByRange(page int) (*list.List, error) { func (c *Commit) CommitsByRange(page int) (*list.List, error) {
return c.repo.commitsByRange(c.Id, page) return c.repo.commitsByRange(c.ID, page)
} }
func (c *Commit) GetCommitOfRelPath(relPath string) (*Commit, error) { func (c *Commit) GetCommitOfRelPath(relPath string) (*Commit, error) {
return c.repo.getCommitOfRelPath(c.Id, relPath) return c.repo.getCommitOfRelPath(c.ID, relPath)
} }
func (c *Commit) GetSubModule(entryname string) (*SubModule, error) { func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {

View File

@ -28,7 +28,7 @@ func (c *Commit) CreateArchive(path string, archiveType ArchiveType) error {
return fmt.Errorf("unknown format: %v", archiveType) return fmt.Errorf("unknown format: %v", archiveType)
} }
_, stderr, err := com.ExecCmdDir(c.repo.Path, "git", "archive", "--format="+format, "-o", path, c.Id.String()) _, stderr, err := com.ExecCmdDir(c.repo.Path, "git", "archive", "--format="+format, "-o", path, c.ID.String())
if err != nil { if err != nil {
return fmt.Errorf("%s", stderr) return fmt.Errorf("%s", stderr)
} }

View File

@ -70,7 +70,7 @@ l:
if err != nil { if err != nil {
return nil, err return nil, err
} }
commit.Tree.Id = id commit.Tree.ID = id
case "parent": case "parent":
// A commit can have one or more parents // A commit can have one or more parents
oid, err := NewIdFromString(string(line[spacepos+1:])) oid, err := NewIdFromString(string(line[spacepos+1:]))
@ -121,7 +121,7 @@ func (repo *Repository) getCommit(id sha1) (*Commit, error) {
return nil, err return nil, err
} }
commit.repo = repo commit.repo = repo
commit.Id = id commit.ID = id
repo.commitCache[id] = commit repo.commitCache[id] = commit
return commit, nil return commit, nil
@ -211,7 +211,7 @@ func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List
var err error var err error
cur := last cur := last
for { for {
if cur.Id.Equal(before.Id) { if cur.ID.Equal(before.ID) {
break break
} }
l.PushBack(cur) l.PushBack(cur)
@ -240,7 +240,7 @@ func (repo *Repository) commitsBefore(lock *sync.Mutex, l *list.List, parent *li
for { for {
if in == nil { if in == nil {
break break
} else if in.Value.(*Commit).Id.Equal(commit.Id) { } else if in.Value.(*Commit).ID.Equal(commit.ID) {
return nil return nil
} else { } else {
if in.Next() == nil { if in.Next() == nil {

View File

@ -69,7 +69,7 @@ func (repo *Repository) getTag(id sha1) (*Tag, error) {
// Tag is a commit. // Tag is a commit.
if ObjectType(tp) == COMMIT { if ObjectType(tp) == COMMIT {
tag := &Tag{ tag := &Tag{
Id: id, ID: id,
Object: id, Object: id,
Type: string(COMMIT), Type: string(COMMIT),
repo: repo, repo: repo,
@ -89,7 +89,7 @@ func (repo *Repository) getTag(id sha1) (*Tag, error) {
return nil, err return nil, err
} }
tag.Id = id tag.ID = id
tag.repo = repo tag.repo = repo
repo.tagCache[id] = tag repo.tagCache[id] = tag

View File

@ -12,7 +12,7 @@ import (
) )
var ( var (
IdNotExist = errors.New("sha1 id not exist") IDNotExist = errors.New("sha1 ID does not exist")
) )
type sha1 [20]byte type sha1 [20]byte

View File

@ -26,23 +26,23 @@ type Signature struct {
// FIXME: include timezone for timestamp! // FIXME: include timezone for timestamp!
func newSignatureFromCommitline(line []byte) (_ *Signature, err error) { func newSignatureFromCommitline(line []byte) (_ *Signature, err error) {
sig := new(Signature) sig := new(Signature)
emailstart := bytes.IndexByte(line, '<') emailStart := bytes.IndexByte(line, '<')
sig.Name = string(line[:emailstart-1]) sig.Name = string(line[:emailStart-1])
emailstop := bytes.IndexByte(line, '>') emailEnd := bytes.IndexByte(line, '>')
sig.Email = string(line[emailstart+1 : emailstop]) sig.Email = string(line[emailStart+1 : emailEnd])
// Check date format. // Check date format.
firstChar := line[emailstop+2] firstChar := line[emailEnd+2]
if firstChar >= 48 && firstChar <= 57 { if firstChar >= 48 && firstChar <= 57 {
timestop := bytes.IndexByte(line[emailstop+2:], ' ') timestop := bytes.IndexByte(line[emailEnd+2:], ' ')
timestring := string(line[emailstop+2 : emailstop+2+timestop]) timestring := string(line[emailEnd+2 : emailEnd+2+timestop])
seconds, err := strconv.ParseInt(timestring, 10, 64) seconds, err := strconv.ParseInt(timestring, 10, 64)
if err != nil { if err != nil {
return nil, err return nil, err
} }
sig.When = time.Unix(seconds, 0) sig.When = time.Unix(seconds, 0)
} else { } else {
sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailstop+2:])) sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:]))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -0,0 +1,20 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package git
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_newSignatureFromCommitline(t *testing.T) {
Convey("Parse signature from commit line", t, func() {
line := "Intern <intern@macbook-intern.(none)> 1445412825 +0200"
sig, err := newSignatureFromCommitline([]byte(line))
So(err, ShouldBeNil)
So(sig, ShouldNotBeNil)
})
}

View File

@ -6,6 +6,7 @@ package git
import ( import (
"strings" "strings"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -53,7 +54,7 @@ func (sf *SubModuleFile) RefUrl() string {
j := strings.LastIndex(url, ":") j := strings.LastIndex(url, ":")
if i > -1 && j > -1 { if i > -1 && j > -1 {
// fix problem with reverse proxy works only with local server // fix problem with reverse proxy works only with local server
if strings.Contains(setting.AppUrl,url[i+1:j]) { if strings.Contains(setting.AppUrl, url[i+1:j]) {
return setting.AppUrl + url[j+1:] return setting.AppUrl + url[j+1:]
} else { } else {
return "http://" + url[i+1:j] + "/" + url[j+1:] return "http://" + url[i+1:j] + "/" + url[j+1:]

View File

@ -11,7 +11,7 @@ import (
// Tag represents a Git tag. // Tag represents a Git tag.
type Tag struct { type Tag struct {
Name string Name string
Id sha1 ID sha1
repo *Repository repo *Repository
Object sha1 // The id of this commit object Object sha1 // The id of this commit object
Type string Type string

View File

@ -18,7 +18,7 @@ var (
// A tree is a flat directory listing. // A tree is a flat directory listing.
type Tree struct { type Tree struct {
Id sha1 ID sha1
repo *Repository repo *Repository
// parent tree // parent tree
@ -66,7 +66,7 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
entry.Id = id entry.ID = id
pos += step + 1 // Skip half of sha1. pos += step + 1 // Skip half of sha1.
step = bytes.IndexByte(data[pos:], '\n') step = bytes.IndexByte(data[pos:], '\n')
@ -100,7 +100,7 @@ func (t *Tree) SubTree(rpath string) (*Tree, error) {
return nil, err return nil, err
} }
g, err = t.repo.getTree(te.Id) g, err = t.repo.getTree(te.ID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -117,7 +117,7 @@ func (t *Tree) ListEntries(relpath string) (Entries, error) {
t.entriesParsed = true t.entriesParsed = true
stdout, stderr, err := com.ExecCmdDirBytes(t.repo.Path, stdout, stderr, err := com.ExecCmdDirBytes(t.repo.Path,
"git", "ls-tree", t.Id.String()) "git", "ls-tree", t.ID.String())
if err != nil { if err != nil {
if strings.Contains(err.Error(), "exit status 128") { if strings.Contains(err.Error(), "exit status 128") {
return nil, errors.New(strings.TrimSpace(string(stderr))) return nil, errors.New(strings.TrimSpace(string(stderr)))
@ -130,7 +130,7 @@ func (t *Tree) ListEntries(relpath string) (Entries, error) {
func NewTree(repo *Repository, id sha1) *Tree { func NewTree(repo *Repository, id sha1) *Tree {
tree := new(Tree) tree := new(Tree)
tree.Id = id tree.ID = id
tree.repo = repo tree.repo = repo
return tree return tree
} }

View File

@ -13,7 +13,7 @@ import (
func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) { func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
if len(relpath) == 0 { if len(relpath) == 0 {
return &TreeEntry{ return &TreeEntry{
Id: t.Id, ID: t.ID,
Type: TREE, Type: TREE,
mode: ModeTree, mode: ModeTree,
}, nil }, nil

View File

@ -24,7 +24,7 @@ const (
) )
type TreeEntry struct { type TreeEntry struct {
Id sha1 ID sha1
Type ObjectType Type ObjectType
mode EntryMode mode EntryMode
@ -51,7 +51,7 @@ func (te *TreeEntry) Size() int64 {
return te.size return te.size
} }
stdout, _, err := com.ExecCmdDir(te.ptree.repo.Path, "git", "cat-file", "-s", te.Id.String()) stdout, _, err := com.ExecCmdDir(te.ptree.repo.Path, "git", "cat-file", "-s", te.ID.String())
if err != nil { if err != nil {
return 0 return 0
} }

View File

@ -118,7 +118,7 @@ func RepoRef() macaron.Handler {
ctx.Handle(500, "GetCommitOfBranch", err) ctx.Handle(500, "GetCommitOfBranch", err)
return return
} }
ctx.Repo.CommitID = ctx.Repo.Commit.Id.String() ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
ctx.Repo.IsBranch = true ctx.Repo.IsBranch = true
} else { } else {
@ -149,7 +149,7 @@ func RepoRef() macaron.Handler {
ctx.Handle(500, "GetCommitOfBranch", err) ctx.Handle(500, "GetCommitOfBranch", err)
return return
} }
ctx.Repo.CommitID = ctx.Repo.Commit.Id.String() ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
} else if ctx.Repo.GitRepo.IsTagExist(refName) { } else if ctx.Repo.GitRepo.IsTagExist(refName) {
ctx.Repo.IsTag = true ctx.Repo.IsTag = true
@ -158,7 +158,7 @@ func RepoRef() macaron.Handler {
ctx.Handle(500, "GetCommitOfTag", err) ctx.Handle(500, "GetCommitOfTag", err)
return return
} }
ctx.Repo.CommitID = ctx.Repo.Commit.Id.String() ctx.Repo.CommitID = ctx.Repo.Commit.ID.String()
} else if len(refName) == 40 { } else if len(refName) == 40 {
ctx.Repo.IsCommit = true ctx.Repo.IsCommit = true
ctx.Repo.CommitID = refName ctx.Repo.CommitID = refName

View File

@ -88,10 +88,10 @@ func Releases(ctx *middleware.Context) {
tags[i] = &models.Release{ tags[i] = &models.Release{
Title: rawTag, Title: rawTag,
TagName: rawTag, TagName: rawTag,
Sha1: commit.Id.String(), Sha1: commit.ID.String(),
} }
tags[i].NumCommits, err = ctx.Repo.GitRepo.CommitsCount(commit.Id.String()) tags[i].NumCommits, err = ctx.Repo.GitRepo.CommitsCount(commit.ID.String())
if err != nil { if err != nil {
ctx.Handle(500, "CommitsCount", err) ctx.Handle(500, "CommitsCount", err)
return return
@ -190,7 +190,7 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
Title: form.Title, Title: form.Title,
TagName: form.TagName, TagName: form.TagName,
Target: form.Target, Target: form.Target,
Sha1: commit.Id.String(), Sha1: commit.ID.String(),
NumCommits: commitsCount, NumCommits: commitsCount,
Note: form.Content, Note: form.Content,
IsDraft: len(form.Draft) > 0, IsDraft: len(form.Draft) > 0,

View File

@ -317,7 +317,7 @@ func Download(ctx *middleware.Context) {
return return
} }
archivePath = path.Join(archivePath, base.ShortSha(commit.Id.String())+ext) archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext)
if !com.IsFile(archivePath) { if !com.IsFile(archivePath) {
if err := commit.CreateArchive(archivePath, archiveType); err != nil { if err := commit.CreateArchive(archivePath, archiveType); err != nil {
ctx.Handle(500, "Download -> CreateArchive "+archivePath, err) ctx.Handle(500, "Download -> CreateArchive "+archivePath, err)
@ -325,5 +325,5 @@ func Download(ctx *middleware.Context) {
} }
} }
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+"-"+base.ShortSha(commit.Id.String())+ext) ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+"-"+base.ShortSha(commit.ID.String())+ext)
} }

View File

@ -151,7 +151,7 @@ func Home(ctx *middleware.Context) {
ctx.Handle(500, "GetCommitOfRelPath", err) ctx.Handle(500, "GetCommitOfRelPath", err)
return return
} }
files = append(files, []interface{}{te, git.NewSubModuleFile(c, smUrl, te.Id.String())}) files = append(files, []interface{}{te, git.NewSubModuleFile(c, smUrl, te.ID.String())})
} }
} }
ctx.Data["Files"] = files ctx.Data["Files"] = files