resolveHashPrefix returns a list of potential hashes that the given string is a prefix of. It quietly swallows errors, returning nil.
(hashStr string)
| 1689 | // resolveHashPrefix returns a list of potential hashes that the given string |
| 1690 | // is a prefix of. It quietly swallows errors, returning nil. |
| 1691 | func (r *Repository) resolveHashPrefix(hashStr string) []plumbing.Hash { |
| 1692 | // Handle complete and partial hashes. |
| 1693 | // plumbing.NewHash forces args into a full 20 byte hash, which isn't suitable |
| 1694 | // for partial hashes since they will become zero-filled. |
| 1695 | |
| 1696 | if hashStr == "" { |
| 1697 | return nil |
| 1698 | } |
| 1699 | if len(hashStr) == len(plumbing.ZeroHash)*2 { |
| 1700 | // Only a full hash is possible. |
| 1701 | hexb, err := hex.DecodeString(hashStr) |
| 1702 | if err != nil { |
| 1703 | return nil |
| 1704 | } |
| 1705 | var h plumbing.Hash |
| 1706 | copy(h[:], hexb) |
| 1707 | return []plumbing.Hash{h} |
| 1708 | } |
| 1709 | |
| 1710 | // Partial hash. |
| 1711 | // hex.DecodeString only decodes to complete bytes, so only works with pairs of hex digits. |
| 1712 | evenHex := hashStr[:len(hashStr)&^1] |
| 1713 | hexb, err := hex.DecodeString(evenHex) |
| 1714 | if err != nil { |
| 1715 | return nil |
| 1716 | } |
| 1717 | candidates := expandPartialHash(r.Storer, hexb) |
| 1718 | if len(evenHex) == len(hashStr) { |
| 1719 | // The prefix was an exact number of bytes. |
| 1720 | return candidates |
| 1721 | } |
| 1722 | // Do another prefix check to ensure the dangling nybble is correct. |
| 1723 | var hashes []plumbing.Hash |
| 1724 | for _, h := range candidates { |
| 1725 | if strings.HasPrefix(h.String(), hashStr) { |
| 1726 | hashes = append(hashes, h) |
| 1727 | } |
| 1728 | } |
| 1729 | return hashes |
| 1730 | } |
| 1731 | |
| 1732 | type RepackConfig struct { |
| 1733 | // UseRefDeltas configures whether packfile encoder will use reference deltas. |
no test coverage detected