mirror of
https://github.com/imjasonh/infinite-git
synced 2026-07-10 01:48:35 +00:00
Implement infinite Git HTTP server
This server generates a new commit every time someone pulls from it. Features: - Pure Go implementation of Git object format and protocols - No dependency on git CLI commands - Thread-safe commit generation - Read-only Git HTTP smart protocol support - Comprehensive test suite Each pull creates a new commit with a unique file containing a timestamp and counter, making the repository grow infinitely with each pull operation. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
fefad053a8
commit
30ca57dae3
19 changed files with 2172 additions and 0 deletions
75
internal/object/commit.go
Normal file
75
internal/object/commit.go
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package object
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Commit represents a Git commit object.
|
||||
type Commit struct {
|
||||
Tree string // SHA-1 hash of the tree object
|
||||
Parent string // SHA-1 hash of the parent commit (empty for initial commit)
|
||||
Author string // Author name and email
|
||||
AuthorDate time.Time // Author timestamp
|
||||
Committer string // Committer name and email
|
||||
CommitDate time.Time // Commit timestamp
|
||||
Message string // Commit message
|
||||
}
|
||||
|
||||
// NewCommit creates a new commit object.
|
||||
func NewCommit(tree, parent, author, committer, message string) *Commit {
|
||||
now := time.Now()
|
||||
return &Commit{
|
||||
Tree: tree,
|
||||
Parent: parent,
|
||||
Author: author,
|
||||
AuthorDate: now,
|
||||
Committer: committer,
|
||||
CommitDate: now,
|
||||
Message: message,
|
||||
}
|
||||
}
|
||||
|
||||
// Type returns the object type.
|
||||
func (c *Commit) Type() Type {
|
||||
return TypeCommit
|
||||
}
|
||||
|
||||
// Serialize returns the commit content in Git format.
|
||||
func (c *Commit) Serialize() []byte {
|
||||
var buf bytes.Buffer
|
||||
|
||||
// Tree reference
|
||||
fmt.Fprintf(&buf, "tree %s\n", c.Tree)
|
||||
|
||||
// Parent reference (if exists)
|
||||
if c.Parent != "" {
|
||||
fmt.Fprintf(&buf, "parent %s\n", c.Parent)
|
||||
}
|
||||
|
||||
// Author
|
||||
fmt.Fprintf(&buf, "author %s %d %s\n",
|
||||
c.Author,
|
||||
c.AuthorDate.Unix(),
|
||||
c.AuthorDate.Format("-0700"))
|
||||
|
||||
// Committer
|
||||
fmt.Fprintf(&buf, "committer %s %d %s\n",
|
||||
c.Committer,
|
||||
c.CommitDate.Unix(),
|
||||
c.CommitDate.Format("-0700"))
|
||||
|
||||
// Empty line before message
|
||||
buf.WriteByte('\n')
|
||||
|
||||
// Commit message
|
||||
buf.WriteString(c.Message)
|
||||
|
||||
// Ensure message ends with newline
|
||||
if len(c.Message) > 0 && c.Message[len(c.Message)-1] != '\n' {
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue