data

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2023 License: ISC Imports: 8 Imported by: 0

Documentation

Overview

Package data implements data types that are passed to the various templates.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LogPageSize is the number of log entries presented per
	// page.
	LogPageSize = 20
	// DiffContext is t he number of context lines presented on
	// either side of a diff
	DiffContext = 3
)

Functions

This section is empty.

Types

type Blob

type Blob struct {
	// The blob hash
	Hash string
	// The size of the blob
	Size int64
	// The contents of the blob
	Lines []BlobLine
}

Blob is information related to a Git blob.

type BlobData

type BlobData struct {
	RequestData
	// Commit information related to the blob.
	Commit Commit
	// The Blob itself.
	Blob Blob
}

BlobData extends RequestData and is provided to the blob template when executed and becomes dot within the template.

The data in TreeData is, properly speaking, a conglomeration of both commit and tree data. The data is combined here for ease of presentation.

type BlobLine

type BlobLine struct {
	Number  int
	Content string
}

Blob line contains the line number and contents of a single line in a Git blob.

type Chunk

type Chunk struct {
	Content string
	Type    Operation
}

Chunk represents the content and type of a file patch.

type Commit

type Commit struct {
	// Hash of the commit object.
	Hash Hash
	// Author is the original author of the commit.
	Author string
	// Committer is the one performing the commit, might be different from
	// Author.
	Committer string
	// Message is the commit message, contains arbitrary text.
	Message string
	// ParentHashes are the hash(es) of the parent commit(s)
	ParentHashes []Hash
	// Time is the commit timestamp
	Time time.Time
}

Commit contains information related to a Git commit.

func (Commit) HasParents

func (c Commit) HasParents() bool

HasParents returns true when c has one or more parents. Otherwise it returns false.

type CommitData

type CommitData struct {
	// The repository
	Repo Repo
	// The revision
	Revision string
	// The commit
	Commit Commit
	// The commit diffstat, populated from [object.FileStats.String].
	Diffstat string
	// A slice of file patches
	FilePatches []FilePatch
}

CommitData is provided to the commit template when executed and becomes dot within the template.

type DiffData

type DiffData struct {
	// The repository
	Repo Repo
	// The source (from) and destination (to) revision
	From, To string
	// The diffstat
	Diffstat string
	// File patches
	FilePatches []FilePatch
}

DiffData is provided to the diff template when executed and becomes dot within the template.

type FileMode

type FileMode uint8

FileMode contains the encoded type of a Git tree entry.

const (
	// Empty or uninitialized
	Empty FileMode = iota
	// A directory
	Dir
	// A regular file
	File
	// An executable file
	Executable
	// A symbolic link
	Symlink
	// A Git submodule
	Submodule
)

These are recognized FileMode values.

func (FileMode) String

func (f FileMode) String() string

String returns the string representation of f. The string representation is similar to the output of the "ls" command on Unix systems.

type FilePatch

type FilePatch struct {
	// True if the file is binary, otherwise false.
	IsBinary bool
	// The file name
	File string
	// A slice of chunks representing changes to the file
	Chunks []Chunk
}

FilePatch represents the changes to an individual file.

func (FilePatch) Info

func (fp FilePatch) Info() ([]PatchInfo, error)

Info converts fp to a slice of PatchInfo, ideal for display within an HTML table.

func (FilePatch) String

func (fp FilePatch) String() string

String implements the fmt.Stringer interface for FilePatch.

type Hash

type Hash string

Hash is a Git hash.

func (Hash) Short

func (h Hash) Short() string

Short returns a short version of the Git hash.

type IndexData

type IndexData struct {
	// Repos is a slice of repositories
	Repos []*Repo
}

IndexData is provided to the index template when executed and becomes dot within the template.

type LogData

type LogData struct {
	// The repository
	Repo Repo
	// The revision
	Revision string
	// The hash from which to begin displaying the log
	FromHash Hash
	// A slice of Git commit information
	Commits []Commit
	// The hash of the first commit for the next page
	NextPage Hash
}

LogData is provided to the log template when executed and becomes dot within the template.

func (LogData) HasNext

func (l LogData) HasNext() bool

HasNext returns true of l.NextPage is not empty.

type Operation

type Operation int

Operation describes the type of patch operation.

const (
	// The chunk is equal within both files
	Equal Operation = iota
	// Content is added to the old file to make the new one
	Add
	// Content is deleted from the old file to make the new one
	Delete
)

type PatchInfo

type PatchInfo struct {
	// The line numbers in the left (old) and right (new) files
	Left, Right string
	// The operation being performed in the current line
	Operation Operation
	// The content of the current line
	Content string
}

PatchInfo represents a single line of a file patch, structured for display within an HTML table.

type PathElem

type PathElem struct {
	// Repo is the repository slug.
	Repo string
	// Revision is the Git revision.
	Revision string
	// Path is the path within the repository, excluding the
	// current path element and any following it.
	Path string
	// Base is the current path element.
	Base string
}

The PathElem struct contains information for a repository path element.

type Reference

type Reference struct {
	// The name of the reference
	Name string
	// The time the reference was created or last updated
	// (whichever is most recent)
	Time time.Time
}

Reference contains information pertaining to a Git repository reference.

type RefsData

type RefsData struct {
	// The repository
	Repo Repo
	// A slice containing all branch references
	Branches []Reference
	// A slice containing all tag references
	Tags []Reference
}

RefsData is provided to the refs template when executed and becomes dot within the template.

type Repo

type Repo struct {
	// Slug is the URL path to the repository, relative to the
	// DGit root URL.
	Slug string
	// Owner is the repository owner as read from the gitweb.owner
	// Git config key.
	Owner string
	// Description is the repository description as read from the
	// gitweb.description Git config key.
	Description string
	// LastModified records the timestamp of the most recent
	// commit as read from info/web/last-modified within the
	// repository's Git directory.
	LastModified time.Time
}

The Repo struct contains data for a single repository.

type RequestData

type RequestData struct {
	// The repository
	Repo Repo
	// The base name of the Git reference, or the commit hash.
	Revision string
	// The path of the tree within the repository.
	Path string
}

RequestData is the base type for several of the other data types.

func (RequestData) PathBase

func (r RequestData) PathBase() string

PathBase returns the base name of the request path. Returned data has the property requestData.RequestBase() = path.Base(requestData.Path).

func (RequestData) PathElems

func (r RequestData) PathElems() []PathElem

PathElems returns a slice of PathElem objects for each directory in [RequestData.Path]. This is useful to build a breadcrumb, which might look like:

{{ for range .PathElems -}}
	<a href="/{{ .Repo }}/-/tree/{{ .Revision }}{{ .Path }}">{{ .Base }}</a>
{{- end }}

type Tree

type Tree struct {
	// Entries describes the entries in the current tree.
	Entries []TreeEntry
	// Hash is the hash of the current tree.
	Hash Hash
}

Tree contains information related to a Git tree.

type TreeData

type TreeData struct {
	RequestData
	// Commit information related to the tree.
	Commit Commit
	// The Tree itself.
	Tree Tree
	// Tree README contents.
	Readme string
}

TreeData extends RequestData and is provided to the head and tree templates when executed and becomes dot within the template.

The data in TreeData is, properly speaking, a conglomeration of both commit and tree data. The data is combined here for ease of presentation.

func (TreeData) HasReadme

func (t TreeData) HasReadme() bool

HasReadme returns true if the tree has a file named README. When true, the README contents are available in TreeData.Readme.

func (TreeData) IsEmpty

func (t TreeData) IsEmpty() bool

IsEmpty returns true if the Tree is empty.

type TreeEntry

type TreeEntry struct {
	// The file name.
	Name string
	// The file mode. See [FileMode].
	Mode FileMode
	// The file hash.
	Hash Hash
	// The link (href) to view the file.
	Href string
}

TreeEntry contains information related to a tree entry. For purposes of a TreeEntry, "file" should be understood to mean blob or tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL