resolveHashPrefix returns a list of potential hashes that the given string is a prefix of. It quietly swallows errors, returning nil.
(hashStr string)
| 1709 | // resolveHashPrefix returns a list of potential hashes that the given string |
| 1710 | // is a prefix of. It quietly swallows errors, returning nil. |
| 1711 | func (r *Repository) resolveHashPrefix(hashStr string) []plumbing.Hash { |
| 1712 | // Handle complete and partial hashes. |
| 1713 | // plumbing.NewHash forces args into a full 20 byte hash, which isn't suitable |
| 1714 | // for partial hashes since they will become zero-filled. |
| 1715 | |
| 1716 | if hashStr == "" { |
| 1717 | return nil |
| 1718 | } |
| 1719 | if len(hashStr) == len(plumbing.ZeroHash)*2 { |
| 1720 | // Only a full hash is possible. |
| 1721 | hexb, err := hex.DecodeString(hashStr) |
| 1722 | if err != nil { |
| 1723 | return nil |
| 1724 | } |
| 1725 | var h plumbing.Hash |
| 1726 | copy(h[:], hexb) |
| 1727 | return []plumbing.Hash{h} |
| 1728 | } |
| 1729 | |
| 1730 | // Partial hash. |
| 1731 | // hex.DecodeString only decodes to complete bytes, so only works with pairs of hex digits. |
| 1732 | evenHex := hashStr[:len(hashStr)&^1] |
| 1733 | hexb, err := hex.DecodeString(evenHex) |
| 1734 | if err != nil { |
| 1735 | return nil |
| 1736 | } |
| 1737 | candidates := expandPartialHash(r.Storer, hexb) |
| 1738 | if len(evenHex) == len(hashStr) { |
| 1739 | // The prefix was an exact number of bytes. |
| 1740 | return candidates |
| 1741 | } |
| 1742 | // Do another prefix check to ensure the dangling nybble is correct. |
| 1743 | var hashes []plumbing.Hash |
| 1744 | for _, h := range candidates { |
| 1745 | if strings.HasPrefix(h.String(), hashStr) { |
| 1746 | hashes = append(hashes, h) |
| 1747 | } |
| 1748 | } |
| 1749 | return hashes |
| 1750 | } |
| 1751 | |
| 1752 | type RepackConfig struct { |
| 1753 | // UseRefDeltas configures whether packfile encoder will use reference deltas. |
no test coverage detected