Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add RDoc for the core module

  • Loading branch information...
commit 68c2b6a107dc7ccfcce6e10efddbca85b344a150 1 parent 2cb831a
@vmg vmg authored
Showing with 61 additions and 0 deletions.
  1. +61 −0 ext/rugged/rugged.c
View
61 ext/rugged/rugged.c
@@ -27,6 +27,16 @@
VALUE rb_mRugged;
static VALUE rb_mShutdownHook;
+/*
+ * call-seq:
+ * Rugged.hex_to_raw(oid) -> raw_buffer
+ *
+ * Turn a string of 40 hexadecimal characters into the buffer of
+ * 20 bytes it represents.
+ *
+ * Rugged.hex_to_raw('d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f')
+ * #=> "\330xk\374\227H^\215{\031\262\037\270\214\216\361\361\231\374?"
+ */
static VALUE rb_git_hex_to_raw(VALUE self, VALUE hex)
{
git_oid oid;
@@ -37,6 +47,16 @@ static VALUE rb_git_hex_to_raw(VALUE self, VALUE hex)
return rugged_str_ascii(oid.id, 20);
}
+/*
+ * call-seq:
+ * Rugged.raw_to_hex(buffer) -> hex_oid
+ *
+ * Turn a buffer of 20 bytes (representing a SHA1 OID) into its
+ * readable hexadecimal representation.
+ *
+ * Rugged.raw_to_hex("\330xk\374\227H^\215{\031\262\037\270\214\216\361\361\231\374?")
+ * #=> "d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f"
+ */
static VALUE rb_git_raw_to_hex(VALUE self, VALUE raw)
{
git_oid oid;
@@ -67,6 +87,47 @@ static VALUE minimize_yield(VALUE rb_oid, VALUE *data)
return Qnil;
}
+/*
+ * call-seq:
+ * Rugged.minimize_oid(oid_iterator, min_length = 7) { |short_oid| block }
+ * Rugged.minimize_oid(oid_iterator, min_length = 7) -> min_length
+ *
+ * Iterate through +oid_iterator+, which should yield any number of SHA1 OIDs
+ * (represented as 40-character hexadecimal strings), and tries to minify them.
+ *
+ * Minifying a set of a SHA1 strings means finding the shortest root substring
+ * for each string that uniquely identifies it.
+ *
+ * If no +block+ is given, the function will return the minimal length as an
+ * integer value:
+ *
+ * oids = [
+ * 'd8786bfc974aaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
+ * 'd8786bfc974bbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
+ * 'd8786bfc974ccccccccccccccccccccccccccccc',
+ * '68d041ee999cb07c6496fbdd4f384095de6ca9e1',
+ * ]
+ *
+ * Rugged.minimize_oids(oids) #=> 12
+ *
+ * If a +block+ is given, it will be called with each OID from +iterator+
+ * in its minified form:
+ *
+ * Rugged.minimize_oids(oids) { |oid| puts oid }
+ *
+ * produces:
+ *
+ * d8786bfc974a
+ * d8786bfc974b
+ * d8786bfc974c
+ * 68d041ee999c
+ *
+ * The optional +min_length+ argument allows you to specify a lower bound for
+ * the minified strings; returned strings won't be shorter than the given value,
+ * even if they would still be uniquely represented.
+ *
+ * Rugged.minimize_oids(oids, 18) #=> 18
+ */
static VALUE rb_git_minimize_oid(int argc, VALUE *argv, VALUE self)
{
git_oid_shorten *shrt;
Please sign in to comment.
Something went wrong with that request. Please try again.