25 Object IDs
(require libgit2/include/oid) | package: libgit2 |
procedure
(git_oid_fromstr str) → git_oid?
str : git-oid-string/c
procedure
v : any/c
value
value
The function git_oid_fromstr parses a string into an object ID value, case-insensitively. The string form of an OID must be GIT_OID_HEXSZ characters long, which is enforced by the contract git-oid-string/c.
> (git_oid_fromstr "555c0bd2b220e74e77a2d4ead659ffad79175dfa") #<cpointer+offset>
; too short > (git_oid_fromstr "bda0839") git_oid_fromstr: contract violation;
given string is the wrong length
length: 7
expected: 40
given string: "bda0839"
in: the 1st argument of
(-> git-oid-string/c git_oid?)
contract from:
<pkgs>/libgit2/include/oid.rkt
blaming: top-level
(assuming the contract is correct)
at: <pkgs>/libgit2/include/oid.rkt:20:24
; not a hex string > (git_oid_fromstr (make-string GIT_OID_HEXSZ #\z)) git_oid_fromstr:
error code: 'GIT_ERROR
error class: 'GIT_ERROR_NONE
procedure
(git_oid_cpy src) → git_oid?
src : git_oid?
> (define a (git_oid_fromstr "555c0bd2b220e74e77a2d4ead659ffad79175dfa")) > (git_oid_equal a (git_oid_cpy a)) #t
25.1 Object ID Comparisons
procedure
(git_oid_is_zero id) → boolean?
id : git_oid?
> (git_oid_is_zero (git_oid_fromstr (make-string GIT_OID_HEXSZ #\0))) #t
> (git_oid_is_zero (git_oid_fromstr "555c0bd2b220e74e77a2d4ead659ffad79175dfa")) #f
procedure
(git_oid_equal a b) → boolean?
a : git_oid? b : git_oid?
procedure
(git_oid_streq a b) → boolean?
a : git_oid? b : git-oid-string/c
> (define str "7b70fdd9970245505229ef2127586350aaa8ad38") > (git_oid_equal (git_oid_fromstr str) (git_oid_fromstr str)) #t
> (git_oid_streq (git_oid_fromstr str) str) #t
> (git_oid_streq (git_oid_fromstr str) "ad1b3cc099b788dcb066c56346fc8854e70e821c") #f
procedure
(git_oid_cmp a b) → (or/c '< '= '>)
a : git_oid? b : git_oid?
procedure
(git_oid_strcmp id str) → (or/c '< '= '>)
id : git_oid? str : git-oid-string/c
procedure
(git_oid_ncmp a b n) → (or/c '= #f)
a : git_oid? b : git_oid? n : (integer-in 0 GIT_OID_HEXSZ)
25.2 Formatting Object IDs
procedure
(git_oid_fmt id) → (and/c string? immutable?)
id : git_oid?
> (git_oid_fmt (git_oid_fromstr "AD1B3CC099B788DCB066C56346FC8854E70E821C")) "ad1b3cc099b788dcb066c56346fc8854e70e821c"
procedure
(git_oid_nfmt id n) → (and/c string? immutable?)
id : git_oid? n : (integer-in 0 GIT_OID_HEXSZ)
> (define id (git_oid_fromstr "AD1B3CC099B788DCB066C56346FC8854E70E821C")) > (git_oid_nfmt id 6) "ad1b3c"
procedure
(git_oid_pathfmt id) → path?
id : git_oid?
The first two hexidecimal digits of id are used as a directory name, and the remaining 38 digits are treated as a path within that directory.
> (git_oid_pathfmt (git_oid_fromstr "40dc88bde003670bae6df1f0cffb1ffb5d93dee4")) #<path:40/dc88bde003670bae6df1f0cffb1ffb5d93dee4>
25.3 Short Object IDs
procedure
(git_oid_shorten_new [min-length]) → git_oid_shorten?
min-length : (integer-in 0 GIT_OID_HEXSZ) = 0
procedure
(git_oid_shorten? v) → boolean?
v : any/c
procedure
(git_oid_shorten_add shortener oid-str) → natural-number/c
shortener : git_oid_shorten? oid-str : git-oid-string/c
Calling git_oid_shorten_add with a hex string OID oid-str returns the minimum number of digits needed to distinguish all of the strings that have been supplied to git_oid_shorten_add so far with the same shortener argument. If the OID shortener is created with a non-zero min-length, git_oid_shorten_add will never return a length less than min-length.
Calling git_oid_shorten_add more than once with the same shortener and equivalent oid-str arguments will produce unhelpful results.
Note that, “for performance reasons, [libgit2 imposes] a hard limit of how many OIDs can be added to a single set (around 32000, assuming a mostly randomized distribution), which should be enough for any kind of program, and keeps the algorithm fast and memory-efficient.”
> (define oid-strings (set "ad1b3cc099b788dcb066c56346fc8854e70e821c" "db775d20c1655c72a95dd40d1a75c0ad4f243461" "821ac0038a6b196a93c48182bdde5ac42c6f5b6e" "0000000000000000000000000000000000000000" "db785d20c1655c72a95dd40d1a75c0ad4f243461" "ad1b3cc099c788dcb066c56346fc8854e70e821c"))
> (define min-length (let ([shortener (git_oid_shorten_new)]) (for/last ([str (in-set oid-strings)]) (git_oid_shorten_add shortener str))))
> (sort (for/list ([str (in-set oid-strings)]) (substring str 0 min-length)) string<?)
'("00000000000"
"821ac0038a6"
"ad1b3cc099b"
"ad1b3cc099c"
"db775d20c16"
"db785d20c16")