<commit_before>// Copyright 2014 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 (
	"bytes"
	"strconv"
	"time"
)

// Author and Committer information
type Signature struct {
	Email string
	Name  string
	When  time.Time
}

// Helper to get a signature from the commit line, which looks like this:
//     author <NAME> <<EMAIL>> 1378823654 +0200
// but without the "author " at the beginning (this method should)
// be used for author and committer.
//
// FIXME: include timezone!
func newSignatureFromCommitline(line []byte) (*Signature, error) {
	sig := new(Signature)
	emailstart := bytes.IndexByte(line, '<')
	sig.Name = string(line[:emailstart-1])
	emailstop := bytes.IndexByte(line, '>')
	sig.Email = string(line[emailstart+1 : emailstop])
	timestop := bytes.IndexByte(line[emailstop+2:], ' ')
	timestring := string(line[emailstop+2 : emailstop+2+timestop])
	seconds, err := strconv.ParseInt(timestring, 10, 64)
	if err != nil {
		return nil, err
	}
	sig.When = time.Unix(seconds, 0)
	return sig, nil
}
<commit_msg>modules/git: able to parse RFC1123Z date format #663<commit_after>// Copyright 2014 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 (
	"bytes"
	"strconv"
	"time"
)

// Author and Committer information
type Signature struct {
	Email string
	Name  string
	When  time.Time
}

// Helper to get a signature from the commit line, which looks like these:
//     author <NAME> <<EMAIL>> 1378823654 +0200
//     author <NAME> <<EMAIL>> Thu, 07 Apr 2005 22:13:13 +0200
// but without the "author " at the beginning (this method should)
// be used for author and committer.
//
// FIXME: include timezone for timestamp!
func newSignatureFromCommitline(line []byte) (_ *Signature, err error) {
	sig := new(Signature)
	emailstart := bytes.IndexByte(line, '<')
	sig.Name = string(line[:emailstart-1])
	emailstop := bytes.IndexByte(line, '>')
	sig.Email = string(line[emailstart+1 : emailstop])

	// Check date format.
	firstChar := line[emailstop+2]
	if firstChar >= 48 && firstChar <= 57 {
		timestop := bytes.IndexByte(line[emailstop+2:], ' ')
		timestring := string(line[emailstop+2 : emailstop+2+timestop])
		seconds, err := strconv.ParseInt(timestring, 10, 64)
		if err != nil {
			return nil, err
		}
		sig.When = time.Unix(seconds, 0)
	} else {
		sig.When, err = time.Parse(time.RFC1123Z, string(line[emailstop+2:]))
		if err != nil {
			return nil, err
		}
	}
	return sig, nil
}

{'fraction_non_alphanumeric': 0.12962256957682045, 'fraction_numerical': 0.03393061380099123, 'mean_word_length': 3.923076923076923, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3709518', 'n_tokens_mistral': 944, 'n_tokens_neox': 867, 'n_words': 284}