Class: Rugged::Object
- Inherits:
-
Object
- Object
- Rugged::Object
- Defined in:
- lib/rugged/object.rb,
ext/rugged/rugged_object.c
Direct Known Subclasses
Class Method Summary collapse
-
.lookup(rb_repo, rb_hex) ⇒ Object
Find and return the git object inside
repo
with the givenoid
. -
.new(rb_repo, rb_hex) ⇒ Object
Find and return the git object inside
repo
with the givenoid
. -
.rev_parse(repo, str) ⇒ Object
Find and return a single object inside
repo
as specified by the git revision stringstr
. -
.rev_parse_oid(repo, str) ⇒ Object
Find and return the id of the object inside
repo
as specified by the git revision stringstr
.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#==(other) ⇒ Object
Returns true only if
object
and other are both instances or subclasses of Rugged::Object and have the same object id, false otherwise. -
#create_note(data = {}) ⇒ Object
Write a new
note
toobject
, with the givendata
arguments, passed as aHash
:. -
#notes(notes_ref = 'refs/notes/commits') ⇒ Hash
Lookup a note for
obj
fromnotes_ref
: -notes_ref
: (optional): canonical name of the reference to use, defaults to “refs/notes/commits”. -
#oid ⇒ Object
Return the Object ID (a 40 character SHA1 hash) for
object
. -
#read_raw ⇒ Object
Returns the git object as a Rugged::OdbObject instance.
-
#remove_note(data = {}) ⇒ Boolean
Removes a
note
fromobject
, with the givendata
arguments, passed as aHash
:. -
#type ⇒ Object
Returns the object’s type.
Class Method Details
.new(repo, oid) ⇒ Object .lookup(repo, oid) ⇒ Object
Find and return the git object inside repo
with the given oid
.
oid
can either have be the complete, 40 character string or any unique prefix.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'ext/rugged/rugged_object.c', line 247
VALUE rb_git_object_lookup(VALUE klass, VALUE rb_repo, VALUE rb_hex)
{
git_object *object;
git_otype type;
git_oid oid;
int error;
int oid_length;
git_repository *repo;
type = class2otype(klass);
if (type == GIT_OBJ_BAD)
type = GIT_OBJ_ANY;
Check_Type(rb_hex, T_STRING);
oid_length = (int)RSTRING_LEN(rb_hex);
rugged_check_repo(rb_repo);
if (oid_length > GIT_OID_HEXSZ)
rb_raise(rb_eTypeError, "The given OID is too long");
Data_Get_Struct(rb_repo, git_repository, repo);
error = git_oid_fromstrn(&oid, RSTRING_PTR(rb_hex), oid_length);
rugged_exception_check(error);
if (oid_length < GIT_OID_HEXSZ)
error = git_object_lookup_prefix(&object, repo, &oid, oid_length, type);
else
error = git_object_lookup(&object, repo, &oid, type);
rugged_exception_check(error);
return rugged_object_new(rb_repo, object);
}
|
.new(repo, oid) ⇒ Object .lookup(repo, oid) ⇒ Object
Find and return the git object inside repo
with the given oid
.
oid
can either have be the complete, 40 character string or any unique prefix.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'ext/rugged/rugged_object.c', line 247
VALUE rb_git_object_lookup(VALUE klass, VALUE rb_repo, VALUE rb_hex)
{
git_object *object;
git_otype type;
git_oid oid;
int error;
int oid_length;
git_repository *repo;
type = class2otype(klass);
if (type == GIT_OBJ_BAD)
type = GIT_OBJ_ANY;
Check_Type(rb_hex, T_STRING);
oid_length = (int)RSTRING_LEN(rb_hex);
rugged_check_repo(rb_repo);
if (oid_length > GIT_OID_HEXSZ)
rb_raise(rb_eTypeError, "The given OID is too long");
Data_Get_Struct(rb_repo, git_repository, repo);
error = git_oid_fromstrn(&oid, RSTRING_PTR(rb_hex), oid_length);
rugged_exception_check(error);
if (oid_length < GIT_OID_HEXSZ)
error = git_object_lookup_prefix(&object, repo, &oid, oid_length, type);
else
error = git_object_lookup(&object, repo, &oid, type);
rugged_exception_check(error);
return rugged_object_new(rb_repo, object);
}
|
.rev_parse(repo, str) ⇒ Object
Find and return a single object inside repo
as specified by the git revision string str
.
See git-scm.com/docs/git-rev-parse.html#_specifying_revisions or man gitrevisions
for information on the accepted syntax.
Raises a Rugged::InvalidError if str
does not contain a valid revision string.
323 324 325 326 |
# File 'ext/rugged/rugged_object.c', line 323
VALUE rb_git_object_rev_parse(VALUE klass, VALUE rb_repo, VALUE rb_spec)
{
return rugged_object_rev_parse(rb_repo, rb_spec, 1);
}
|
.rev_parse_oid(repo, str) ⇒ Object
Find and return the id of the object inside repo
as specified by the git revision string str
.
See git-scm.com/docs/git-rev-parse.html#_specifying_revisions or man gitrevisions
for information on the accepted syntax.
Raises a Rugged::InvalidError if str
does not contain a valid revision string.
339 340 341 342 |
# File 'ext/rugged/rugged_object.c', line 339
VALUE rb_git_object_rev_parse_oid(VALUE klass, VALUE rb_repo, VALUE rb_spec)
{
return rugged_object_rev_parse(rb_repo, rb_spec, 0);
}
|
Instance Method Details
#<=>(other) ⇒ Object
8 9 10 |
# File 'lib/rugged/object.rb', line 8 def <=>(other) self.oid <=> other.oid end |
#==(other) ⇒ Object
Returns true only if object
and other are both instances or subclasses of Rugged::Object and have the same object id, false otherwise.
350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'ext/rugged/rugged_object.c', line 350
static VALUE rb_git_object_equal(VALUE self, VALUE other)
{
git_object *a, *b;
if (!rb_obj_is_kind_of(other, rb_cRuggedObject))
return Qfalse;
TypedData_Get_Struct(self, git_object, &rugged_object_type, a);
TypedData_Get_Struct(other, git_object, &rugged_object_type, b);
return git_oid_cmp(git_object_id(a), git_object_id(b)) == 0 ? Qtrue : Qfalse;
}
|
#create_note(data = {}) ⇒ Object
Write a new note
to object
, with the given data
arguments, passed as a Hash
:
-
:message
: the content of the note to add to the object -
:committer
: (optional) a hash with the signature for the committer defaults to the signature from the configuration -
:author
: (optional) a hash with the signature for the author defaults to the signature from the configuration -
:ref
: (optional): canonical name of the reference to use, defaults to “refs/notes/commits” -
:force
: (optional): overwrite existing note (disabled by default)
When the note is successfully written to disk, its oid
will be returned as a hex String
.
= {:email=>"[email protected]", :time=>Time.now, :name=>"Vicent Mart\303\255"}
obj.create_note(
:author => ,
:committer => ,
:message => "Hello world\n\n",
:ref => 'refs/notes/builds'
)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'ext/rugged/rugged_note.c', line 112
static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
{
VALUE rb_ref, rb_message, rb_force;
git_repository *repo = NULL;
const char *notes_ref = NULL;
VALUE owner;
git_signature *author, *committer;
git_oid note_oid;
git_object *target = NULL;
int error = 0;
int force = 0;
Check_Type(rb_data, T_HASH);
TypedData_Get_Struct(self, git_object, &rugged_object_type, target);
owner = rugged_owner(self);
Data_Get_Struct(owner, git_repository, repo);
rb_ref = rb_hash_aref(rb_data, CSTR2SYM("ref"));
rb_force = rb_hash_aref(rb_data, CSTR2SYM("force"));
if (!NIL_P(rb_force))
force = rugged_parse_bool(rb_force);
if (!NIL_P(rb_ref)) {
Check_Type(rb_ref, T_STRING);
notes_ref = StringValueCStr(rb_ref);
}
rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
Check_Type(rb_message, T_STRING);
committer = rugged_signature_get(
rb_hash_aref(rb_data, CSTR2SYM("committer")), repo
);
author = rugged_signature_get(
rb_hash_aref(rb_data, CSTR2SYM("author")), repo
);
error = git_note_create(
¬e_oid,
repo,
notes_ref,
author,
committer,
git_object_id(target),
StringValueCStr(rb_message),
force);
git_signature_free(author);
git_signature_free(committer);
rugged_exception_check(error);
return rugged_create_oid(¬e_oid);
}
|
#notes(notes_ref = 'refs/notes/commits') ⇒ Hash
Lookup a note for obj
from notes_ref
:
-
notes_ref
: (optional): canonical name of the reference to use, defaults to “refs/notes/commits”
Returns a new Hash object.
obj.notes #=> {:message=>"note text\n", :oid=>"94eca2de348d5f672faf56b0decafa5937e3235e"}
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'ext/rugged/rugged_note.c', line 46
static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self)
{
git_repository *repo;
const char *notes_ref = NULL;
VALUE rb_notes_ref;
VALUE rb_note_hash;
VALUE owner;
git_note *note;
git_object *object;
int error;
rb_scan_args(argc, argv, "01", &rb_notes_ref);
if (!NIL_P(rb_notes_ref)) {
Check_Type(rb_notes_ref, T_STRING);
notes_ref = StringValueCStr(rb_notes_ref);
}
TypedData_Get_Struct(self, git_object, &rugged_object_type, object);
owner = rugged_owner(self);
Data_Get_Struct(owner, git_repository, repo);
error = git_note_read(¬e, repo, notes_ref, git_object_id(object));
if (error == GIT_ENOTFOUND)
return Qnil;
rugged_exception_check(error);
rb_note_hash = rb_hash_new();
rb_hash_aset(rb_note_hash, CSTR2SYM("message"), rugged_git_note_message(note));
rb_hash_aset(rb_note_hash, CSTR2SYM("oid"), rugged_git_note_oid(note));
git_note_free(note);
return rb_note_hash;
}
|
#oid ⇒ Object
Return the Object ID (a 40 character SHA1 hash) for object
.
368 369 370 371 372 373 |
# File 'ext/rugged/rugged_object.c', line 368
static VALUE rb_git_object_oid_GET(VALUE self)
{
git_object *object;
TypedData_Get_Struct(self, git_object, &rugged_object_type, object);
return rugged_create_oid(git_object_id(object));
}
|
#read_raw ⇒ Object
Returns the git object as a Rugged::OdbObject instance.
393 394 395 396 397 398 399 |
# File 'ext/rugged/rugged_object.c', line 393
static VALUE rb_git_object_read_raw(VALUE self)
{
git_object *object;
TypedData_Get_Struct(self, git_object, &rugged_object_type, object);
return rugged_raw_read(git_object_owner(object), git_object_id(object));
}
|
#remove_note(data = {}) ⇒ Boolean
Removes a note
from object
, with the given data
arguments, passed as a Hash
:
-
:committer
(optional): a hash with the signature for the committer, defaults to the signature from the configuration -
:author
(optional): a hash with the signature for the author, defaults to the signature from the configuration -
:ref
: (optional): canonical name of the reference to use, defaults to “refs/notes/commits”
When the note is successfully removed true
will be returned as a Boolean
.
= {:email=>"[email protected]", :time=>Time.now, :name=>"Vicent Mart\303\255"}
obj.remove_note(
:author => ,
:committer => ,
:ref => 'refs/notes/builds'
)
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'ext/rugged/rugged_note.c', line 199
static VALUE rb_git_note_remove(int argc, VALUE *argv, VALUE self)
{
int error = 0;
const char *notes_ref = NULL;
git_repository *repo = NULL;
git_signature *author, *committer;
git_object *target = NULL;
VALUE rb_data;
VALUE rb_ref = Qnil;
VALUE rb_author = Qnil;
VALUE rb_committer = Qnil;
VALUE owner;
TypedData_Get_Struct(self, git_object, &rugged_object_type, target);
owner = rugged_owner(self);
Data_Get_Struct(owner, git_repository, repo);
rb_scan_args(argc, argv, "01", &rb_data);
if (!NIL_P(rb_data)) {
Check_Type(rb_data, T_HASH);
rb_ref = rb_hash_aref(rb_data, CSTR2SYM("ref"));
if (!NIL_P(rb_ref)) {
Check_Type(rb_ref, T_STRING);
notes_ref = StringValueCStr(rb_ref);
}
rb_committer = rb_hash_aref(rb_data, CSTR2SYM("committer"));
rb_author = rb_hash_aref(rb_data, CSTR2SYM("author"));
}
committer = rugged_signature_get(rb_committer, repo);
author = rugged_signature_get(rb_author, repo);
error = git_note_remove(
repo,
notes_ref,
author,
committer,
git_object_id(target));
git_signature_free(author);
git_signature_free(committer);
if (error == GIT_ENOTFOUND)
return Qfalse;
rugged_exception_check(error);
return Qtrue;
}
|
#type ⇒ Object
Returns the object’s type. Can be one of :commit
, :tag
, :tree
or :blob
.
380 381 382 383 384 385 386 |
# File 'ext/rugged/rugged_object.c', line 380
static VALUE rb_git_object_type_GET(VALUE self)
{
git_object *object;
TypedData_Get_Struct(self, git_object, &rugged_object_type, object);
return rugged_otype_new(git_object_type(object));
}
|