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

Commit 4fea552

Browse files
author
Eduardo Lezcano
committed
Better to implement Describe without variadics... That is for the CLI!
Signed-off-by: Eduardo Lezcano <[email protected]>
1 parent 3431da0 commit 4fea552

File tree

1 file changed

+39
-44
lines changed

1 file changed

+39
-44
lines changed

repository.go

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,55 +1270,50 @@ func (d *Describe) String() string {
12701270
d.Dirty)
12711271
}
12721272

1273-
func (r *Repository) Describe(options *DescribeOptions, hashes ...*plumbing.Hash) ([]Describe, error) {
1273+
// Describe just like the `git describe` command will return a Describe struct for the hash passed.
1274+
// Describe struct implements String interface so it can be easily printed out.
1275+
func (r *Repository) Describe(options *DescribeOptions, hash *plumbing.Hash) (*Describe, error) {
1276+
1277+
// Fetch the reference log
1278+
commitIterator, err := r.Log(&LogOptions{
1279+
From: *hash,
1280+
Order: LogOrderCommitterTime,
1281+
})
1282+
if err != nil {
1283+
return nil, err
1284+
}
12741285

1275-
var describes []Describe
1286+
// Tag map for rapid (?) query
1287+
tagIterator, err := r.Tags()
1288+
if err != nil {
1289+
return nil, err
1290+
}
1291+
tags := make(map[plumbing.Hash]*plumbing.Reference)
1292+
tagIterator.ForEach(func(t *plumbing.Reference) error {
1293+
tags[t.Hash()] = t
1294+
return nil
1295+
})
12761296

1277-
for _, hash := range hashes {
12781297

1279-
// Fetch the reference log
1280-
commitIterator, err := r.Log(&LogOptions{
1281-
From: *hash,
1282-
Order: LogOrderCommitterTime,
1283-
})
1284-
if err != nil {
1285-
return nil, err
1298+
// Search the tag
1299+
var tag *plumbing.Reference
1300+
var count int
1301+
err = commitIterator.ForEach(func(c *object.Commit) error {
1302+
if t, ok := tags[c.Hash]; ok {
1303+
tag = t
12861304
}
1287-
1288-
// Tag map for rapid (?) query
1289-
tagIterator, err := r.Tags()
1290-
if err != nil {
1291-
return nil, err
1305+
if tag != nil {
1306+
return storer.ErrStop
12921307
}
1293-
tags := make(map[plumbing.Hash]*plumbing.Reference)
1294-
tagIterator.ForEach(func(t *plumbing.Reference) error {
1295-
tags[t.Hash()] = t
1296-
return nil
1297-
})
1298-
1299-
1300-
// Search the tag
1301-
var tag *plumbing.Reference
1302-
var count int
1303-
err = commitIterator.ForEach(func(c *object.Commit) error {
1304-
if t, ok := tags[c.Hash]; ok {
1305-
tag = t
1306-
}
1307-
if tag != nil {
1308-
return storer.ErrStop
1309-
}
1310-
count++
1311-
return nil
1312-
})
1313-
1314-
describes = append(describes, Describe{
1315-
hash,
1316-
tag,
1317-
count,
1318-
options.Dirty,
1319-
})
1308+
count++
1309+
return nil
1310+
})
13201311

1321-
}
1312+
return &Describe{
1313+
hash,
1314+
tag,
1315+
count,
1316+
options.Dirty,
1317+
}, nil
13221318

1323-
return describes, nil
13241319
}

0 commit comments

Comments
 (0)