void SG_dagfrag__alloc(SG_context * pCtx, SG_dagfrag ** ppNew, const char* psz_repo_id, const char* psz_admin_id, SG_uint32 iDagNum) { SG_dagfrag * pFrag = NULL; SG_NULLARGCHECK_RETURN(ppNew); SG_ARGCHECK_RETURN( (iDagNum != SG_DAGNUM__NONE), iDagNum ); SG_ERR_CHECK_RETURN( SG_gid__argcheck(pCtx, psz_repo_id) ); SG_ERR_CHECK_RETURN( SG_gid__argcheck(pCtx, psz_admin_id) ); SG_ERR_CHECK( SG_alloc(pCtx, 1, sizeof(SG_dagfrag), &pFrag) ); SG_ERR_CHECK( SG_strcpy(pCtx, pFrag->m_sz_repo_id, sizeof(pFrag->m_sz_repo_id), psz_repo_id) ); SG_ERR_CHECK( SG_strcpy(pCtx, pFrag->m_sz_admin_id, sizeof(pFrag->m_sz_admin_id), psz_admin_id) ); pFrag->m_iDagNum = iDagNum; SG_ERR_CHECK( SG_RBTREE__ALLOC(pCtx,&pFrag->m_pRB_Cache) ); pFrag->m_pRB_GenerationSortedMemberCache = NULL; // only create this if needed *ppNew = pFrag; return; fail: SG_DAGFRAG_NULLFREE(pCtx, pFrag); }
JS_END_EXTERN_C #endif static JSBool GetLine(SG_context *pCtx, JSContext *cx, char *bufp, SG_uint32 bufremaining, FILE *file, const char *prompt) { #ifndef EDITLINE SG_UNUSED(cx); #endif #ifdef EDITLINE /* * Use readline only if file is stdin, because there's no way to specify * another handle. Are other filehandles interactive? */ if (file == stdin) { char *linep = readline(prompt); if (!linep) return JS_FALSE; if (linep[0] != '\0') add_history(linep); SG_strcpy(pCtx, bufp, bufremaining, linep); if(SG_context__has_err(pCtx)) { SG_context__err_reset(pCtx); return JS_FALSE; } JS_free(cx, linep); bufp += strlen(bufp); *bufp++ = '\n'; *bufp = '\0'; } else #endif { char line[256]; fprintf(gOutFile, "%s", prompt); fflush(gOutFile); if (!fgets(line, sizeof line, file)) return JS_FALSE; SG_strcpy(pCtx, bufp, bufremaining, line); if(SG_context__has_err(pCtx)) { SG_context__err_reset(pCtx); return JS_FALSE; } } return JS_TRUE; }
void u0048_multidag_test__1(SG_context * pCtx) { char bufName[SG_TID_MAX_BUFFER_LENGTH + u0048_multidag__MY_LABEL_LENGTH]; SG_repo* pRepo = NULL; SG_rbtree* prb = NULL; SG_uint32 count; char* pid1 = NULL; char* pid1a = NULL; char* pid1b = NULL; char* pid1c = NULL; char* pid2 = NULL; char* pid2a = NULL; char* pid2b = NULL; VERIFY_ERR_CHECK( SG_strcpy(pCtx, bufName, sizeof(bufName), u0048_multidag__MY_LABEL) ); VERIFY_ERR_CHECK( SG_tid__generate2(pCtx, &bufName[u0048_multidag__MY_LABEL_LENGTH], (sizeof(bufName) - u0048_multidag__MY_LABEL_LENGTH), 32) ); /* create the repo */ VERIFY_ERR_CHECK( u0048_multidag__new_repo(pCtx, bufName, &pRepo) ); VERIFY_ERR_CHECK( u0048_multidag__add_dagnode(pCtx, &pid1, NULL, SG_DAGNUM__TESTING__NOTHING, pRepo) ); VERIFY_ERR_CHECK( u0048_multidag__add_dagnode(pCtx, &pid1a, pid1, SG_DAGNUM__TESTING__NOTHING, pRepo) ); VERIFY_ERR_CHECK( u0048_multidag__add_dagnode(pCtx, &pid1b, pid1, SG_DAGNUM__TESTING__NOTHING, pRepo) ); VERIFY_ERR_CHECK( u0048_multidag__add_dagnode(pCtx, &pid1c, pid1, SG_DAGNUM__TESTING__NOTHING, pRepo) ); VERIFY_ERR_CHECK( u0048_multidag__add_dagnode(pCtx, &pid2, NULL, SG_DAGNUM__TESTING2__NOTHING, pRepo) ); VERIFY_ERR_CHECK( u0048_multidag__add_dagnode(pCtx, &pid2a, pid2, SG_DAGNUM__TESTING2__NOTHING, pRepo) ); VERIFY_ERR_CHECK( u0048_multidag__add_dagnode(pCtx, &pid2b, pid2, SG_DAGNUM__TESTING2__NOTHING, pRepo) ); SG_NULLFREE(pCtx, pid1); SG_NULLFREE(pCtx, pid1a); SG_NULLFREE(pCtx, pid1b); SG_NULLFREE(pCtx, pid1c); SG_NULLFREE(pCtx, pid2); SG_NULLFREE(pCtx, pid2a); SG_NULLFREE(pCtx, pid2b); VERIFY_ERR_CHECK( SG_repo__fetch_dag_leaves(pCtx, pRepo, SG_DAGNUM__TESTING__NOTHING, &prb) ); VERIFY_ERR_CHECK( SG_rbtree__count(pCtx, prb, &count) ); SG_RBTREE_NULLFREE(pCtx, prb); VERIFY_COND("count", (3 == count)); VERIFY_ERR_CHECK( SG_repo__fetch_dag_leaves(pCtx, pRepo, SG_DAGNUM__TESTING2__NOTHING, &prb) ); VERIFY_ERR_CHECK( SG_rbtree__count(pCtx, prb, &count) ); SG_RBTREE_NULLFREE(pCtx, prb); VERIFY_COND("count", (2 == count)); SG_REPO_NULLFREE(pCtx, pRepo); return; fail: SG_REPO_NULLFREE(pCtx, pRepo); }
void u0051_hidlookup_test__1(SG_context * pCtx, SG_pathname* pPathTopDir) { char bufName[SG_TID_MAX_BUFFER_LENGTH]; SG_pathname* pPathWorkingDir = NULL; SG_pathname* pPathFile = NULL; SG_dagnode* pdn = NULL; const char* psz_hid_cs = NULL; SG_repo* pRepo = NULL; char buf_partial[256]; char* psz_result = NULL; SG_audit q; VERIFY_ERR_CHECK( SG_tid__generate2(pCtx, bufName, sizeof(bufName), 32) ); /* create the working dir */ VERIFY_ERR_CHECK( SG_PATHNAME__ALLOC__PATHNAME_SZ(pCtx, &pPathWorkingDir, pPathTopDir, bufName) ); VERIFY_ERR_CHECK( SG_fsobj__mkdir__pathname(pCtx, pPathWorkingDir) ); /* add stuff */ VERIFY_ERR_CHECK( u0051_hidlookup__create_file__numbers(pCtx, pPathWorkingDir, "aaa", 20) ); /* create the repo */ VERIFY_ERR_CHECK( _ut_pt__new_repo(pCtx, bufName, pPathWorkingDir) ); VERIFY_ERR_CHECK( _ut_pt__addremove(pCtx, pPathWorkingDir) ); VERIFY_ERR_CHECK( u0051_hidlookup__commit_all(pCtx, pPathWorkingDir, &pdn) ); VERIFY_ERR_CHECK( SG_dagnode__get_id_ref(pCtx, pdn, &psz_hid_cs) ); VERIFY_ERR_CHECK( SG_repo__open_repo_instance(pCtx, bufName, &pRepo) ); VERIFY_ERR_CHECK( SG_audit__init(pCtx, &q, pRepo, SG_AUDIT__WHEN__NOW, SG_AUDIT__WHO__FROM_SETTINGS) ); VERIFY_ERR_CHECK( SG_vc_tags__add(pCtx, pRepo, psz_hid_cs, "remember", &q) ); VERIFY_ERR_CHECK( SG_strcpy(pCtx, buf_partial, sizeof(buf_partial), psz_hid_cs) ); buf_partial[10] = 0; VERIFY_ERR_CHECK( SG_repo__hidlookup__dagnode(pCtx, pRepo, SG_DAGNUM__VERSION_CONTROL, buf_partial, &psz_result) ); VERIFY_COND("found", (0 == strcmp(psz_result, psz_hid_cs))); SG_NULLFREE(pCtx, psz_result); VERIFY_ERR_CHECK( SG_repo__hidlookup__blob(pCtx, pRepo, buf_partial, &psz_result) ); VERIFY_COND("found", (0 == strcmp(psz_result, psz_hid_cs))); SG_NULLFREE(pCtx, psz_result); VERIFY_ERR_CHECK( SG_vc_tags__lookup__tag(pCtx, pRepo, "remember", &psz_result) ); VERIFY_COND("found", (0 == strcmp(psz_result, psz_hid_cs))); SG_NULLFREE(pCtx, psz_result); fail: SG_NULLFREE(pCtx, psz_result); SG_REPO_NULLFREE(pCtx, pRepo); SG_DAGNODE_NULLFREE(pCtx, pdn); SG_PATHNAME_NULLFREE(pCtx, pPathWorkingDir); SG_PATHNAME_NULLFREE(pCtx, pPathFile); }
static void _vv_verbs__init_new_repo__get_admin_id( SG_context * pCtx, const char * psz_shared_users, char* buf_admin_id ) { SG_sync_client* pSyncClient = NULL; SG_vhash* pvhRepoInfo = NULL; const char* pszRefAdminId = NULL; SG_ERR_CHECK( SG_sync_client__open(pCtx, psz_shared_users, NULL, NULL, &pSyncClient) ); SG_ERR_CHECK( SG_sync_client__get_repo_info(pCtx, pSyncClient, SG_FALSE, SG_FALSE, &pvhRepoInfo) ); SG_ERR_CHECK( SG_vhash__get__sz(pCtx, pvhRepoInfo, SG_SYNC_REPO_INFO_KEY__ADMIN_ID, &pszRefAdminId) ); SG_ERR_CHECK( SG_strcpy(pCtx, buf_admin_id, SG_GID_BUFFER_LENGTH, pszRefAdminId) ); fail: SG_SYNC_CLIENT_NULLFREE(pCtx, pSyncClient); SG_VHASH_NULLFREE(pCtx, pvhRepoInfo); }
void SG_dagquery__find_single_descendant_head(SG_context * pCtx, SG_repo * pRepo, SG_uint64 dagnum, const char * pszHidStart, SG_dagquery_find_head_status * pdqfhs, char * bufHidHead, SG_uint32 lenBufHidHead) { SG_rbtree * prbHeads = NULL; const char * pszKey_0; SG_dagquery_find_head_status dqfhs; SG_bool b; SG_NULLARGCHECK_RETURN(pRepo); SG_NONEMPTYCHECK_RETURN(pszHidStart); SG_NULLARGCHECK_RETURN(pdqfhs); SG_NULLARGCHECK_RETURN(bufHidHead); SG_ERR_CHECK( SG_dagquery__find_descendant_heads(pCtx, pRepo, dagnum, pszHidStart, SG_TRUE, &dqfhs, &prbHeads) ); switch (dqfhs) { case SG_DAGQUERY_FIND_HEAD_STATUS__IS_LEAF: case SG_DAGQUERY_FIND_HEAD_STATUS__UNIQUE: SG_ERR_CHECK( SG_rbtree__iterator__first(pCtx, NULL, prbHeads, &b, &pszKey_0, NULL) ); SG_ASSERT( (b) ); SG_ERR_CHECK( SG_strcpy(pCtx, bufHidHead, lenBufHidHead, pszKey_0) ); break; case SG_DAGQUERY_FIND_HEAD_STATUS__MULTIPLE: default: // don't throw, just return the status bufHidHead[0] = 0; break; } *pdqfhs = dqfhs; fail: SG_RBTREE_NULLFREE(pCtx, prbHeads); }