static void hash_fd(int fd, const char *type, int write_object, const char *path) { struct stat st; unsigned char sha1[20]; if (fstat(fd, &st) < 0 || index_fd(sha1, fd, &st, write_object, type_from_string(type), path)) die(write_object ? "Unable to add %s to database" : "Unable to hash %s", path); printf("%s\n", sha1_to_hex(sha1)); maybe_flush_or_die(stdout, "hash to stdout"); }
/** * \brief Set a field of type "string". * \param name The name of the field. * \param value The new value of the field. * \return false if the field "name" is unknow, true otherwise. */ bool rp::bonus::set_string_field ( const std::string& name, const std::string& value ) { bool result = true; if ( name == "bonus.type" ) m_type = type_from_string(value); else result = super::set_string_field( name, value ); return result; } // bonus::set_string_field()
static void _purple_desktop_item_set_string (PurpleDesktopItem *item, const char *attr, const char *value) { g_return_if_fail (item != NULL); g_return_if_fail (item->refcount > 0); g_return_if_fail (attr != NULL); set (item, attr, value); if (strcmp (attr, PURPLE_DESKTOP_ITEM_TYPE) == 0) item->type = type_from_string (value); }
/* * We refuse to tag something we can't verify. Just because. */ static int verify_object(unsigned char *sha1, const char *expected_type) { int ret = -1; enum object_type type; unsigned long size; void *buffer = read_sha1_file(sha1, &type, &size); if (buffer) { if (type == type_from_string(expected_type)) ret = check_sha1_signature(sha1, buffer, size, expected_type); free(buffer); } return ret; }
/* * We refuse to tag something we can't verify. Just because. */ static int verify_object(const struct object_id *oid, const char *expected_type) { int ret = -1; enum object_type type; unsigned long size; void *buffer = read_object_file(oid, &type, &size); const struct object_id *repl = lookup_replace_object(the_repository, oid); if (buffer) { if (type == type_from_string(expected_type)) ret = check_object_signature(repl, buffer, size, expected_type); free(buffer); } return ret; }
static void mktree_line(char *buf, size_t len, int line_termination, int allow_missing) { char *ptr, *ntr; unsigned mode; enum object_type mode_type; /* object type derived from mode */ enum object_type obj_type; /* object type derived from sha */ char *path; unsigned char sha1[20]; ptr = buf; /* * Read non-recursive ls-tree output format: * mode SP type SP sha1 TAB name */ mode = strtoul(ptr, &ntr, 8); if (ptr == ntr || !ntr || *ntr != ' ') die("input format error: %s", buf); ptr = ntr + 1; /* type */ ntr = strchr(ptr, ' '); if (!ntr || buf + len <= ntr + 40 || ntr[41] != '\t' || get_sha1_hex(ntr + 1, sha1)) die("input format error: %s", buf); /* It is perfectly normal if we do not have a commit from a submodule */ if (S_ISGITLINK(mode)) allow_missing = 1; *ntr++ = 0; /* now at the beginning of SHA1 */ path = ntr + 41; /* at the beginning of name */ if (line_termination && path[0] == '"') { struct strbuf p_uq = STRBUF_INIT; if (unquote_c_style(&p_uq, path, NULL)) die("invalid quoting"); path = strbuf_detach(&p_uq, NULL); } /* * Object type is redundantly derivable three ways. * These should all agree. */ mode_type = object_type(mode); if (mode_type != type_from_string(ptr)) { die("entry '%s' object type (%s) doesn't match mode type (%s)", path, ptr, typename(mode_type)); }
static void hash_fd(int fd, const char *type, const char *path, unsigned flags, int literally) { struct stat st; unsigned char sha1[20]; if (fstat(fd, &st) < 0 || (literally ? hash_literally(sha1, fd, type, flags) : index_fd(sha1, fd, &st, type_from_string(type), path, flags))) die((flags & HASH_WRITE_OBJECT) ? "Unable to add %s to database" : "Unable to hash %s", path); printf("%s\n", sha1_to_hex(sha1)); maybe_flush_or_die(stdout, "hash to stdout"); }
static void hash_fd(int fd, const char *type, const char *path, unsigned flags, int literally) { struct stat st; struct object_id oid; if (fstat(fd, &st) < 0 || (literally ? hash_literally(&oid, fd, type, flags) : index_fd(the_repository->index, &oid, fd, &st, type_from_string(type), path, flags))) die((flags & HASH_WRITE_OBJECT) ? "Unable to add %s to database" : "Unable to hash %s", path); printf("%s\n", oid_to_hex(&oid)); maybe_flush_or_die(stdout, "hash to stdout"); }
static void setup_type (PurpleDesktopItem *item, const char *uri) { const char *type = g_hash_table_lookup (item->main_hash, PURPLE_DESKTOP_ITEM_TYPE); if (type == NULL && uri != NULL) { char *base = g_path_get_basename (uri); if (base != NULL && strcmp (base, ".directory") == 0) { /* This gotta be a directory */ g_hash_table_replace (item->main_hash, g_strdup (PURPLE_DESKTOP_ITEM_TYPE), g_strdup ("Directory")); item->keys = g_list_prepend (item->keys, g_strdup (PURPLE_DESKTOP_ITEM_TYPE)); item->type = PURPLE_DESKTOP_ITEM_TYPE_DIRECTORY; } else { item->type = PURPLE_DESKTOP_ITEM_TYPE_NULL; } g_free (base); } else { item->type = type_from_string (type); } }
static int cat_one_file(int opt, const char *exp_type, const char *obj_name) { unsigned char sha1[20]; enum object_type type; char *buf; unsigned long size; struct object_context obj_context; if (get_sha1_with_context(obj_name, 0, sha1, &obj_context)) die("Not a valid object name %s", obj_name); buf = NULL; switch (opt) { case 't': type = sha1_object_info(sha1, NULL); if (type > 0) { printf("%s\n", typename(type)); return 0; } break; case 's': type = sha1_object_info(sha1, &size); if (type > 0) { printf("%lu\n", size); return 0; } break; case 'e': return !has_sha1_file(sha1); case 'p': type = sha1_object_info(sha1, NULL); if (type < 0) die("Not a valid object name %s", obj_name); /* custom pretty-print here */ if (type == OBJ_TREE) { const char *ls_args[3] = { NULL }; ls_args[0] = "ls-tree"; ls_args[1] = obj_name; return cmd_ls_tree(2, ls_args, NULL); } if (type == OBJ_BLOB) return stream_blob_to_fd(1, sha1, NULL, 0); buf = read_sha1_file(sha1, &type, &size); if (!buf) die("Cannot read object %s", obj_name); if (type == OBJ_TAG) { pprint_tag(sha1, buf, size); return 0; } /* otherwise just spit out the data */ break; case 'c': if (!obj_context.path[0]) die("git cat-file --textconv %s: <object> must be <sha1:path>", obj_name); if (!textconv_object(obj_context.path, obj_context.mode, sha1, 1, &buf, &size)) die("git cat-file --textconv: unable to run textconv on %s", obj_name); break; case 0: if (type_from_string(exp_type) == OBJ_BLOB) { unsigned char blob_sha1[20]; if (sha1_object_info(sha1, NULL) == OBJ_TAG) { enum object_type type; unsigned long size; char *buffer = read_sha1_file(sha1, &type, &size); if (memcmp(buffer, "object ", 7) || get_sha1_hex(buffer + 7, blob_sha1)) die("%s not a valid tag", sha1_to_hex(sha1)); free(buffer); } else hashcpy(blob_sha1, sha1); if (sha1_object_info(blob_sha1, NULL) == OBJ_BLOB) return stream_blob_to_fd(1, blob_sha1, NULL, 0); /* * we attempted to dereference a tag to a blob * and failed; there may be new dereference * mechanisms this code is not aware of. * fall-back to the usual case. */ } buf = read_object_with_reference(sha1, exp_type, &size, NULL); break; default: die("git cat-file: unknown option: %s", exp_type); }