int CGitIndexList::ReadIndex(CString dgitdir) { this->clear(); m_critRepoSec.Lock(); if (repository.Open(dgitdir)) { m_critRepoSec.Unlock(); return -1; } // add config files CAutoConfig config(true); CString projectConfig = dgitdir + _T("config"); CString globalConfig = g_Git.GetGitGlobalConfig(); CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig(); CString systemConfig(CRegString(REG_SYSTEM_GITCONFIGPATH, _T(""), FALSE)); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(projectConfig), GIT_CONFIG_LEVEL_LOCAL, FALSE); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(globalConfig), GIT_CONFIG_LEVEL_GLOBAL, FALSE); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(globalXDGConfig), GIT_CONFIG_LEVEL_XDG, FALSE); if (!systemConfig.IsEmpty()) git_config_add_file_ondisk(config, CGit::GetGitPathStringA(systemConfig), GIT_CONFIG_LEVEL_SYSTEM, FALSE); git_repository_set_config(repository, config); CAutoIndex index; // load index in order to enumerate files if (git_repository_index(index.GetPointer(), repository)) { repository.Free(); m_critRepoSec.Unlock(); return -1; } size_t ecount = git_index_entrycount(index); resize(ecount); for (size_t i = 0; i < ecount; ++i) { const git_index_entry *e = git_index_get_byindex(index, i); this->at(i).m_FileName.Empty(); this->at(i).m_FileName = CUnicodeUtils::GetUnicode(e->path); this->at(i).m_FileName.MakeLower(); this->at(i).m_ModifyTime = e->mtime.seconds; this->at(i).m_Flags = e->flags | e->flags_extended; this->at(i).m_IndexHash = e->id.id; this->at(i).m_Size = e->file_size; } g_Git.GetFileModifyTime(dgitdir + _T("index"), &this->m_LastModifyTime); std::sort(this->begin(), this->end(), SortIndex); m_critRepoSec.Unlock(); return 0; }
void test_odb_backend_nobackend__initialize(void) { git_config *config; git_odb *odb; git_refdb *refdb; cl_git_pass(git_repository_new(&_repo)); cl_git_pass(git_config_new(&config)); cl_git_pass(git_odb_new(&odb)); cl_git_pass(git_refdb_new(&refdb, _repo)); git_repository_set_config(_repo, config); git_repository_set_odb(_repo, odb); git_repository_set_refdb(_repo, refdb); /* The set increases the refcount and we don't want them anymore */ git_config_free(config); git_odb_free(odb); git_refdb_free(refdb); }
int create_repo(const char *repo_name) { int r; git_repository *repo; git_oid blob_id; git_oid oid; git_oid tree_id; git_signature *author; git_time_t time; git_config *config; git_index *index; git_tree *tree; git_treebuilder *tree_builder; git_treebuilder *empty_tree_builder; char global_config_path[GIT_PATH_MAX]; // create the repository r = git_repository_init(&repo, repo_name, 1); if (r) printf("error in creating repository\n"); printf("Repo created\n"); // set the repository config git_config_new(&config); git_config_find_global(global_config_path, GIT_PATH_MAX); git_config_add_file_ondisk(config, global_config_path, 1); //git_config_set_string(config, "name", "Varun Agrawal"); //git_config_set_string(config, "email", "*****@*****.**"); git_repository_set_config(repo, config); printf("Repo config set\n"); // create a treebuilder r = git_treebuilder_create(&tree_builder, NULL); if (r) printf("error in creting treebuilder\n"); printf("Tree builder created\n"); // ADDING FIRST FILE // create a blob r = git_blob_create_fromdisk(&blob_id, repo, "test1"); if (r) printf("error in creating blob from disk\n"); printf("Blob created\n"); // insert into tree r = git_treebuilder_insert(NULL, tree_builder, "test1", &blob_id, 0100644); if (r) printf("error in inserting into treebuilder\n"); printf("Insert into treebuilder successful\n"); // ADDING SECOND FILE // create a blob r = git_blob_create_fromdisk(&blob_id, repo, "test2"); if (r) printf("error in creating blob from disk\n"); printf("Blob created\n"); // insert into tree r = git_treebuilder_insert(NULL, tree_builder, "test2", &blob_id, 0100644); if (r) printf("error in inserting into treebuilder\n"); printf("Insert into treebuilder successful\n"); // ADDING A EMPTY FOLDER // create a empty tree r = git_treebuilder_create(&empty_tree_builder, NULL); if (r) printf("error in creting empty treebuilder\n"); printf("Empty Tree builder created\n"); // write the empty tree to the repo r = git_treebuilder_write(&tree_id, repo, empty_tree_builder); if (r) printf("error in writing the empty tree to the repo\n"); printf("Writing the empty tree to repo successful\n"); // insert empty tree into the tree r = git_treebuilder_insert(NULL, tree_builder, "test_dir", &tree_id, 0040000); if (r) printf("error in inserting into treebuilder\n"); printf("Insert into treebuilder successful\n"); // write the tree to the repo r = git_treebuilder_write(&oid, repo, tree_builder); if (r) printf("error in writing the tree to the repo\n"); printf("Writing the tree to repo successful\n"); // tree lookup r = git_tree_lookup(&tree, repo, &oid); if (r) printf("error in tree lookup\n"); printf("Tree lookup done\n"); // create a author time = get_time(); r = git_signature_new(&author, "Varun Agrawal", "*****@*****.**", time, -300); if (r) printf("error in creating signature\n"); printf("Author signature created\n"); // create a commit r = git_commit_create( &oid, // object id repo, // repository "HEAD", // update reference, this will update the HEAD to this commit author, // author author, // committer NULL, // message encoding, by default UTF-8 is used "first commit", // message for the commit tree, // the git_tree object which will be used as the tree for this commit. don't know if NULL is valid 0, // number of parents. Don't know what value should be used here NULL); // array of pointers to the parents(git_commit *parents[]) if (r) printf("error in creating a commit\n"); printf("Commit created\n"); git_repository_free(repo); return 0; }
int CGitIndexList::ReadIndex(CString dgitdir) { this->clear(); CAutoLocker lock(m_critRepoSec); if (repository.Open(dgitdir)) return -1; // add config files CAutoConfig config(true); CString projectConfig = dgitdir + _T("config"); CString globalConfig = g_Git.GetGitGlobalConfig(); CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig(); CString systemConfig(CRegString(REG_SYSTEM_GITCONFIGPATH, _T(""), FALSE)); CString programDataConfig(GetProgramDataGitConfig()); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(projectConfig), GIT_CONFIG_LEVEL_LOCAL, FALSE); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(globalConfig), GIT_CONFIG_LEVEL_GLOBAL, FALSE); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(globalXDGConfig), GIT_CONFIG_LEVEL_XDG, FALSE); if (!systemConfig.IsEmpty()) git_config_add_file_ondisk(config, CGit::GetGitPathStringA(systemConfig), GIT_CONFIG_LEVEL_SYSTEM, FALSE); if (!programDataConfig.IsEmpty()) git_config_add_file_ondisk(config, CGit::GetGitPathStringA(programDataConfig), GIT_CONFIG_LEVEL_PROGRAMDATA, FALSE); git_repository_set_config(repository, config); CAutoIndex index; // load index in order to enumerate files if (git_repository_index(index.GetPointer(), repository)) { repository.Free(); return -1; } m_bHasConflicts = FALSE; size_t ecount = git_index_entrycount(index); try { resize(ecount); } catch (const std::bad_alloc& ex) { repository.Free(); CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Could not resize index-vector: %s\n", ex.what()); return -1; } for (size_t i = 0; i < ecount; ++i) { const git_index_entry *e = git_index_get_byindex(index, i); this->at(i).m_FileName = CUnicodeUtils::GetUnicode(e->path); this->at(i).m_FileName.MakeLower(); this->at(i).m_ModifyTime = e->mtime.seconds; this->at(i).m_Flags = e->flags; this->at(i).m_FlagsExtended = e->flags_extended; this->at(i).m_IndexHash = e->id.id; this->at(i).m_Size = e->file_size; m_bHasConflicts |= GIT_IDXENTRY_STAGE(e); } CGit::GetFileModifyTime(dgitdir + _T("index"), &this->m_LastModifyTime); std::sort(this->begin(), this->end(), SortIndex); return 0; }
int CGitIndexList::ReadIndex(CString dgitdir) { this->clear(); CStringA gitdir = CUnicodeUtils::GetMulti(dgitdir, CP_UTF8); m_critRepoSec.Lock(); if (repository != NULL) { git_repository_free(repository); repository = NULL; } git_index *index = NULL; if (git_repository_open(&repository, gitdir)) { m_critRepoSec.Unlock(); return -1; } // add config files git_config * config; git_config_new(&config); CString projectConfig = dgitdir + _T("config"); CString globalConfig = g_Git.GetGitGlobalConfig(); CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig(); CString msysGitBinPath(CRegString(REG_MSYSGIT_PATH, _T(""), FALSE)); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(projectConfig), GIT_CONFIG_LEVEL_LOCAL, FALSE); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(globalConfig), GIT_CONFIG_LEVEL_GLOBAL, FALSE); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(globalXDGConfig), GIT_CONFIG_LEVEL_XDG, FALSE); if (!msysGitBinPath.IsEmpty()) git_config_add_file_ondisk(config, CGit::GetGitPathStringA(msysGitBinPath + _T("\\..\\etc\\gitconfig")), GIT_CONFIG_LEVEL_SYSTEM, FALSE); git_repository_set_config(repository, config); git_config_free(config); config = nullptr; // load index in order to enumerate files if (git_repository_index(&index, repository)) { git_repository_free(repository); repository = NULL; m_critRepoSec.Unlock(); return -1; } size_t ecount = git_index_entrycount(index); resize(ecount); for (size_t i = 0; i < ecount; ++i) { const git_index_entry *e = git_index_get_byindex(index, i); this->at(i).m_FileName.Empty(); g_Git.StringAppend(&this->at(i).m_FileName, (BYTE*)e->path, CP_UTF8); this->at(i).m_FileName.MakeLower(); this->at(i).m_ModifyTime = e->mtime.seconds; this->at(i).m_Flags = e->flags | e->flags_extended; this->at(i).m_IndexHash = (char *) e->oid.id; } git_index_free(index); g_Git.GetFileModifyTime(dgitdir + _T("index"), &this->m_LastModifyTime); std::sort(this->begin(), this->end(), SortIndex); m_critRepoSec.Unlock(); return 0; }