Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 059a0be

Browse files
committed
plumbing: improve documentation (Fix #242)
1 parent b5da4e9 commit 059a0be

File tree

7 files changed

+56
-11
lines changed

7 files changed

+56
-11
lines changed

plumbing/format/config/section.go

+38
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@ package config
22

33
import "strings"
44

5+
// Section is the representation of a section inside git configuration files.
6+
// Each Section contains Options that are used by both the Git plumbing
7+
// and the porcelains.
8+
// Sections can be further divided into subsections. To begin a subsection
9+
// put its name in double quotes, separated by space from the section name,
10+
// in the section header, like in the example below:
11+
//
12+
// [section "subsection"]
13+
//
14+
// All the other lines (and the remainder of the line after the section header)
15+
// are recognized as option variables, in the form "name = value" (or just name,
16+
// which is a short-hand to say that the variable is the boolean "true").
17+
// The variable names are case-insensitive, allow only alphanumeric characters
18+
// and -, and must start with an alphabetic character:
19+
//
20+
// [section "subsection1"]
21+
// option1 = value1
22+
// option2
23+
// [section "subsection2"]
24+
// option3 = value2
25+
//
526
type Section struct {
627
Name string
728
Options Options
@@ -17,29 +38,38 @@ type Sections []*Section
1738

1839
type Subsections []*Subsection
1940

41+
// IsName checks if the name provided is equals to the Section name, case insensitive.
2042
func (s *Section) IsName(name string) bool {
2143
return strings.ToLower(s.Name) == strings.ToLower(name)
2244
}
2345

46+
// Option return the value for the specified key. Empty string is returned if
47+
// key does not exists.
2448
func (s *Section) Option(key string) string {
2549
return s.Options.Get(key)
2650
}
2751

52+
// AddOption adds a new Option to the Section. The updated Section is returned.
2853
func (s *Section) AddOption(key string, value string) *Section {
2954
s.Options = s.Options.withAddedOption(key, value)
3055
return s
3156
}
3257

58+
// SetOption adds a new Option to the Section. If the option already exists, is replaced.
59+
// The updated Section is returned.
3360
func (s *Section) SetOption(key string, value string) *Section {
3461
s.Options = s.Options.withSettedOption(key, value)
3562
return s
3663
}
3764

65+
// Remove an option with the specified key. The updated Section is returned.
3866
func (s *Section) RemoveOption(key string) *Section {
3967
s.Options = s.Options.withoutOption(key)
4068
return s
4169
}
4270

71+
// Subsection returns a Subsection from the specified Section. If the
72+
// Subsection does not exists, new one is created and added to Section.
4373
func (s *Section) Subsection(name string) *Subsection {
4474
for i := len(s.Subsections) - 1; i >= 0; i-- {
4575
ss := s.Subsections[i]
@@ -53,6 +83,7 @@ func (s *Section) Subsection(name string) *Subsection {
5383
return ss
5484
}
5585

86+
// HasSubsection checks if the Section has a Subsection with the specified name.
5687
func (s *Section) HasSubsection(name string) bool {
5788
for _, ss := range s.Subsections {
5889
if ss.IsName(name) {
@@ -63,24 +94,31 @@ func (s *Section) HasSubsection(name string) bool {
6394
return false
6495
}
6596

97+
// IsName checks if the name of the subsection is exactly the specified name.
6698
func (s *Subsection) IsName(name string) bool {
6799
return s.Name == name
68100
}
69101

102+
// Option returns an option with the specified key. If the option does not exists,
103+
// empty spring will be returned.
70104
func (s *Subsection) Option(key string) string {
71105
return s.Options.Get(key)
72106
}
73107

108+
// AddOption adds a new Option to the Subsection. The updated Subsection is returned.
74109
func (s *Subsection) AddOption(key string, value string) *Subsection {
75110
s.Options = s.Options.withAddedOption(key, value)
76111
return s
77112
}
78113

114+
// SetOption adds a new Option to the Subsection. If the option already exists, is replaced.
115+
// The updated Subsection is returned.
79116
func (s *Subsection) SetOption(key string, value string) *Subsection {
80117
s.Options = s.Options.withSettedOption(key, value)
81118
return s
82119
}
83120

121+
// RemoveOption removes the option with the specified key. The updated Subsection is returned.
84122
func (s *Subsection) RemoveOption(key string) *Subsection {
85123
s.Options = s.Options.withoutOption(key)
86124
return s

plumbing/format/packfile/decoder.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,11 @@ func (d *Decoder) newObject() plumbing.EncodedObject {
300300
return d.o.NewEncodedObject()
301301
}
302302

303-
// DecodeObjectAt reads an object at the given location, if Decode wasn't called
304-
// previously objects offset should provided using the SetOffsets method
303+
// DecodeObjectAt reads an object at the given location. Every EncodedObject
304+
// returned is added into a internal index. This is intended to be able to regenerate
305+
// objects from deltas (offset deltas or reference deltas) without an package index
306+
// (.idx file). If Decode wasn't called previously objects offset should provided
307+
// using the SetOffsets method.
305308
func (d *Decoder) DecodeObjectAt(offset int64) (plumbing.EncodedObject, error) {
306309
if !d.s.IsSeekable {
307310
return nil, ErrNonSeekable

plumbing/format/packfile/diff_delta.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ const (
1414
maxCopyLen = 0xffff
1515
)
1616

17-
// GetDelta returns an offset delta that knows the way of how to transform
18-
// base object to target object
17+
// GetDelta returns an EncodedObject of type OFSDeltaObject. Base and Target object,
18+
// will be loaded into memory to be able to create the delta object.
19+
// To generate target again, you will need the obtained object and "base" one.
20+
// Error will be returned if base or target object cannot be read.
1921
func GetDelta(base, target plumbing.EncodedObject) (plumbing.EncodedObject, error) {
2022
br, err := base.Reader()
2123
if err != nil {

plumbing/format/packfile/encoder.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ type Encoder struct {
2323
}
2424

2525
// NewEncoder creates a new packfile encoder using a specific Writer and
26-
// EncodedObjectStorer
26+
// EncodedObjectStorer. By default deltas used to generate the packfile will be
27+
// OFSDeltaObject. To use Reference deltas, set useRefDeltas to true.
2728
func NewEncoder(w io.Writer, s storer.EncodedObjectStorer, useRefDeltas bool) *Encoder {
2829
h := plumbing.Hasher{
2930
Hash: sha1.New(),

plumbing/format/pktline/encoder.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ func (e *Encoder) EncodeString(payloads ...string) error {
116116
}
117117

118118
// Encodef encodes a single pkt-line with the payload formatted as
119-
// the format specifier and the rest of the arguments suggest.
119+
// the format specifier. The rest of the arguments will be used in
120+
// the format string.
120121
func (e *Encoder) Encodef(format string, a ...interface{}) error {
121122
return e.EncodeString(
122123
fmt.Sprintf(format, a...),

plumbing/storer/reference.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ const MaxResolveRecursion = 1024
1313
// is exceeded
1414
var ErrMaxResolveRecursion = errors.New("max. recursion level reached")
1515

16-
// ReferenceStorer generic storage of references
16+
// ReferenceStorer is a generic storage of references.
1717
type ReferenceStorer interface {
1818
SetReference(*plumbing.Reference) error
1919
Reference(plumbing.ReferenceName) (*plumbing.Reference, error)
2020
IterReferences() (ReferenceIter, error)
2121
RemoveReference(plumbing.ReferenceName) error
2222
}
2323

24-
// ReferenceIter is a generic closable interface for iterating over references
24+
// ReferenceIter is a generic closable interface for iterating over references.
2525
type ReferenceIter interface {
2626
Next() (*plumbing.Reference, error)
2727
ForEach(func(*plumbing.Reference) error) error
@@ -82,7 +82,7 @@ func (iter *ReferenceSliceIter) Close() {
8282
iter.pos = len(iter.series)
8383
}
8484

85-
// ResolveReference resolve a SymbolicReference to a HashReference
85+
// ResolveReference resolves a SymbolicReference to a HashReference.
8686
func ResolveReference(s ReferenceStorer, n plumbing.ReferenceName) (*plumbing.Reference, error) {
8787
r, err := s.Reference(n)
8888
if err != nil || r == nil {

plumbing/storer/shallow.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package storer
22

33
import "srcd.works/go-git.v4/plumbing"
44

5-
// ShallowStorer storage of references to shallow commits by hash, meaning that
6-
// these commits have missing parents because of a shallow fetch.
5+
// ShallowStorer is a storage of references to shallow commits by hash,
6+
// meaning that these commits have missing parents because of a shallow fetch.
77
type ShallowStorer interface {
88
SetShallow([]plumbing.Hash) error
99
Shallow() ([]plumbing.Hash, error)

0 commit comments

Comments
 (0)