int git_index_add(git_index *index, const char *rel_path, int stage) { git_index_entry entry; char full_path[GIT_PATH_MAX]; struct stat st; int error; if (index->repository == NULL) return GIT_EBAREINDEX; strcpy(full_path, index->repository->path_workdir); strcat(full_path, rel_path); if (gitfo_exists(full_path) < 0) return GIT_ENOTFOUND; if (gitfo_stat(full_path, &st) < 0) return GIT_EOSERR; if (stage < 0 || stage > 3) return GIT_ERROR; memset(&entry, 0x0, sizeof(git_index_entry)); entry.ctime.seconds = st.st_ctime; entry.mtime.seconds = st.st_mtime; /* entry.mtime.nanoseconds = st.st_mtimensec; */ /* entry.ctime.nanoseconds = st.st_ctimensec; */ entry.dev= st.st_rdev; entry.ino = st.st_ino; entry.mode = st.st_mode; entry.uid = st.st_uid; entry.gid = st.st_gid; entry.file_size = st.st_size; /* write the blob to disk and get the oid */ if ((error = git_blob_writefile(&entry.oid, index->repository, full_path)) < 0) return error; entry.flags |= (stage << GIT_IDXENTRY_STAGESHIFT); entry.path = (char *)rel_path; /* do not duplicate; index_insert already does this */ return git_index_insert(index, &entry); }
static VALUE rb_git_index_add(VALUE self, VALUE rb_entry) { git_index *index; git_index_entry *entry; int error; Data_Get_Struct(self, git_index, index); if (rb_obj_is_kind_of(rb_entry, rb_cRuggedIndexEntry)) { Data_Get_Struct(rb_entry, git_index_entry, entry); error = git_index_insert(index, entry); } else if (TYPE(rb_entry) == T_STRING) { error = git_index_add(index, RSTRING_PTR(rb_entry), 0); } else { rb_raise(rb_eTypeError, "index_entry must be an existing IndexEntry object or a path to a file in the repository"); } rugged_exception_check(error); return Qnil; }