mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-21 21:05:34 +03:00
fix: Proper paring of date for git commits
- Properly parse the date of the git commit and pass that around.
This commit is contained in:
parent
7e1aa8a5cd
commit
a1762a6f9b
3 changed files with 11 additions and 5 deletions
|
@ -16,7 +16,7 @@ import (
|
|||
|
||||
// GetCommitGraph return a list of commit (GraphItems) from all branches
|
||||
func GetCommitGraph(r *git.Repository, page, maxAllowedColors int, hidePRRefs bool, branches, files []string) (*Graph, error) {
|
||||
format := "DATA:%D|%H|%ad|%h|%s"
|
||||
format := "DATA:%D|%H|%aD|%h|%s"
|
||||
|
||||
if page == 0 {
|
||||
page = 1
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
|
@ -198,6 +199,11 @@ func NewCommit(row, column int, line []byte) (*Commit, error) {
|
|||
if len(data) < 5 {
|
||||
return nil, fmt.Errorf("malformed data section on line %d with commit: %s", row, string(line))
|
||||
}
|
||||
// Format is a slight modifcation from RFC1123Z
|
||||
t, err := time.Parse("Mon, _2 Jan 2006 15:04:05 -0700", string(data[2]))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse date of commit: %w", err)
|
||||
}
|
||||
return &Commit{
|
||||
Row: row,
|
||||
Column: column,
|
||||
|
@ -205,8 +211,8 @@ func NewCommit(row, column int, line []byte) (*Commit, error) {
|
|||
Refs: newRefsFromRefNames(data[0]),
|
||||
// 1 matches git log --pretty=format:%H => commit hash
|
||||
Rev: string(data[1]),
|
||||
// 2 matches git log --pretty=format:%ad => author date (format respects --date= option)
|
||||
Date: string(data[2]),
|
||||
// 2 matches git log --pretty=format:%aD => author date, RFC2822 style
|
||||
Date: t,
|
||||
// 3 matches git log --pretty=format:%h => abbreviated commit hash
|
||||
ShortRev: string(data[3]),
|
||||
// 4 matches git log --pretty=format:%s => subject
|
||||
|
@ -245,7 +251,7 @@ type Commit struct {
|
|||
Column int
|
||||
Refs []git.Reference
|
||||
Rev string
|
||||
Date string
|
||||
Date time.Time
|
||||
ShortRev string
|
||||
Subject string
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ func TestParseGlyphs(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCommitStringParsing(t *testing.T) {
|
||||
dataFirstPart := "* DATA:|4e61bacab44e9b4730e44a6615d04098dd3a8eaf|2016-12-20 21:10:41 +0100|4e61bac|"
|
||||
dataFirstPart := "* DATA:|4e61bacab44e9b4730e44a6615d04098dd3a8eaf|Tue, 20 Dec 2016 21:10:41 +0100|4e61bac|"
|
||||
tests := []struct {
|
||||
shouldPass bool
|
||||
testName string
|
||||
|
|
Loading…
Reference in a new issue