/** * ggit_ref_get_shorthand: * @ref: a #GgitRef * * Gets the shorthand name of @ref. * * Returns: the shorthand name of a reference. */ const gchar * ggit_ref_get_shorthand (GgitRef *ref) { g_return_val_if_fail (ref != NULL, NULL); return git_reference_shorthand (_ggit_native_get (ref)); }
void assert_shorthand(git_repository *repo, const char *refname, const char *shorthand) { git_reference *ref; cl_git_pass(git_reference_lookup(&ref, repo, refname)); cl_assert_equal_s(git_reference_shorthand(ref), shorthand); git_reference_free(ref); }
PyObject * Repository_listall_branches(Repository *self, PyObject *args) { git_branch_t list_flags = GIT_BRANCH_LOCAL; git_branch_iterator *iter; git_reference *ref = NULL; int err; git_branch_t type; PyObject *list; /* 1- Get list_flags */ if (!PyArg_ParseTuple(args, "|I", &list_flags)) return NULL; list = PyList_New(0); if (list == NULL) return NULL; if ((err = git_branch_iterator_new(&iter, self->repo, list_flags)) < 0) return Error_set(err); while ((err = git_branch_next(&ref, &type, iter)) == 0) { PyObject *py_branch_name = to_path(git_reference_shorthand(ref)); git_reference_free(ref); if (py_branch_name == NULL) goto error; err = PyList_Append(list, py_branch_name); Py_DECREF(py_branch_name); if (err < 0) goto error; } git_branch_iterator_free(iter); if (err == GIT_ITEROVER) err = 0; if (err < 0) { Py_CLEAR(list); return Error_set(err); } return list; error: git_branch_iterator_free(iter); Py_CLEAR(list); return NULL; }
static VALUE each_branch(int argc, VALUE *argv, VALUE self, int branch_names_only) { VALUE rb_repo = rugged_owner(self), rb_filter; git_repository *repo; git_branch_iterator *iter; int error, exception = 0; git_branch_t filter = (GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE), branch_type; rb_scan_args(argc, argv, "01", &rb_filter); if (!rb_block_given_p()) { VALUE symbol = branch_names_only ? CSTR2SYM("each_name") : CSTR2SYM("each"); return rb_funcall(self, rb_intern("to_enum"), 2, symbol, rb_filter); } rugged_check_repo(rb_repo); if (!NIL_P(rb_filter)) filter = parse_branch_type(rb_filter); Data_Get_Struct(rb_repo, git_repository, repo); error = git_branch_iterator_new(&iter, repo, filter); rugged_exception_check(error); if (branch_names_only) { git_reference *branch; while (!exception && (error = git_branch_next(&branch, &branch_type, iter)) == GIT_OK) { rb_protect(rb_yield, rb_str_new_utf8(git_reference_shorthand(branch)), &exception); } } else { git_reference *branch; while (!exception && (error = git_branch_next(&branch, &branch_type, iter)) == GIT_OK) { rb_protect(rb_yield, rugged_branch_new(rb_repo, branch), &exception); } } git_branch_iterator_free(iter); if (exception) rb_jump_tag(exception); if (error != GIT_ITEROVER) rugged_exception_check(error); return Qnil; }
/** * If the user asked for the branch, let's show the short name of the * branch. */ static void show_branch(git_repository *repo, int format) { int error = 0; const char *branch = NULL; git_reference *head = NULL; error = git_repository_head(&head, repo); if (error == GIT_EUNBORNBRANCH || error == GIT_ENOTFOUND) branch = NULL; else if (!error) { branch = git_reference_shorthand(head); } else check_lg2(error, "failed to get current branch", NULL); if (format == FORMAT_LONG) printf("# On branch %s\n", branch ? branch : "Not currently on any branch."); else printf("## %s\n", branch ? branch : "HEAD (no branch)"); git_reference_free(head); }
void CGitStatus::Load() { GitStatus status; CriticalSection lock(this->m_critSec); status = this->GetStatus(); if (status == GS_NOTLOADED || status == GS_INVALIDATED) { this->m_waitHandle = CreateEvent(NULL, TRUE, FALSE, NULL); SetStatus(GS_LOADING); } lock.Unlock(); if (status == GS_LOADED || status == GS_ERROR) { return; } // If it is loading just wait for it to complete. if (status == GS_LOADING) { _ASSERT(this->m_waitHandle.IsValid()); WaitForSingleObject(this->m_waitHandle, INFINITE); return; } git_buf buf; git_repository *repo = NULL; wstring_convert<codecvt_utf8<wchar_t>> converter; InitState(); if (!GetRepoRootInternal(this->m_startDir, this->m_repoRoot, buf, repo)) { Logger::LogWarning(_T("Unable to open git repository")); SetStatus(GS_ERROR); ::SetEvent(this->m_waitHandle); return; } // This is temporary. CMutexLock mutexLock(&m_mutex); this->m_gitDir = MyUtils::NormalizePath(converter.from_bytes(buf.ptr)); // Get current state of repo. (merge/rebase in progress etc) this->m_repoState = git_repository_state(repo); // Get branch info. git_reference *ref; if (git_repository_head(&ref, repo)) { Logger::LogError(_T("Unable to retrieve branch")); SetStatus(GS_ERROR); ::SetEvent(this->m_waitHandle); return; } const char* headName = git_reference_shorthand(ref); this->m_branch = converter.from_bytes(headName); // Get the status of the repo. git_status_options opts; git_status_init_options(&opts, GIT_STATUS_OPTIONS_VERSION); opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_EXCLUDE_SUBMODULES; git_status_foreach_ext(repo, &opts, &GitStatus_Callack, this); // Free stuff git_buf_free(&buf); git_repository_free(repo); this->SetStatus(GS_LOADED); ::SetEvent(this->m_waitHandle); // Start monitoring for changes. this->MonitorForChanges(); return; }
PyObject * Reference_shorthand__get__(Reference *self) { CHECK_REFERENCE(self); return to_path(git_reference_shorthand(self->reference)); }
void CGitPropertyPage::InitWorkfileView() { if (filenames.empty()) return; CTGitPath path(filenames.front().c_str()); CString ProjectTopDir; if(!path.HasAdminDir(&ProjectTopDir)) return; CAutoRepository repository(CUnicodeUtils::GetUTF8(ProjectTopDir)); if (!repository) return; CString username; CString useremail; CString autocrlf; CString safecrlf; CAutoConfig config(repository); if (config) { config.GetString(L"user.name", username); config.GetString(L"user.email", useremail); config.GetString(L"core.autocrlf", autocrlf); config.GetString(L"core.safecrlf", safecrlf); } CString branch; CString remotebranch; if (!git_repository_head_detached(repository)) { CAutoReference head; if (git_repository_head_unborn(repository)) { git_reference_lookup(head.GetPointer(), repository, "HEAD"); branch = CUnicodeUtils::GetUnicode(git_reference_symbolic_target(head)); if (branch.Find(_T("refs/heads/")) == 0) branch = branch.Mid(11); // 11 = len("refs/heads/") } else if (!git_repository_head(head.GetPointer(), repository)) { const char * branchChar = git_reference_shorthand(head); branch = CUnicodeUtils::GetUnicode(branchChar); const char * branchFullChar = git_reference_name(head); CAutoBuf upstreambranchname; if (!git_branch_upstream_name(upstreambranchname, repository, branchFullChar)) { remotebranch = CUnicodeUtils::GetUnicode(CStringA(upstreambranchname->ptr, (int)upstreambranchname->size)); remotebranch = remotebranch.Mid(13); // 13=len("refs/remotes/") } } } else branch = _T("detached HEAD"); if (autocrlf.Trim().IsEmpty()) autocrlf = _T("false"); if (safecrlf.Trim().IsEmpty()) safecrlf = _T("false"); SetDlgItemText(m_hwnd,IDC_CONFIG_USERNAME,username.Trim()); SetDlgItemText(m_hwnd,IDC_CONFIG_USEREMAIL,useremail.Trim()); SetDlgItemText(m_hwnd,IDC_CONFIG_AUTOCRLF,autocrlf.Trim()); SetDlgItemText(m_hwnd,IDC_CONFIG_SAFECRLF,safecrlf.Trim()); SetDlgItemText(m_hwnd,IDC_SHELL_CURRENT_BRANCH,branch.Trim()); SetDlgItemText(m_hwnd,IDC_SHELL_REMOTE_BRANCH, remotebranch); git_oid oid; CAutoCommit HEADcommit; if (!git_reference_name_to_id(&oid, repository, "HEAD") && !git_commit_lookup(HEADcommit.GetPointer(), repository, &oid) && HEADcommit) DisplayCommit(HEADcommit, IDC_HEAD_HASH, IDC_HEAD_SUBJECT, IDC_HEAD_AUTHOR, IDC_HEAD_DATE); { int stripLength = ProjectTopDir.GetLength(); if (ProjectTopDir[stripLength - 1] != _T('\\')) ++stripLength; bool allAreFiles = true; for (auto it = filenames.cbegin(); it < filenames.cend(); ++it) { if (PathIsDirectory(it->c_str())) { allAreFiles = false; break; } } if (allAreFiles) { size_t assumevalid = 0; size_t skipworktree = 0; size_t executable = 0; size_t symlink = 0; do { CAutoIndex index; if (git_repository_index(index.GetPointer(), repository)) break; for (auto it = filenames.cbegin(); it < filenames.cend(); ++it) { CTGitPath file; file.SetFromWin(CString(it->c_str()).Mid(stripLength)); CStringA pathA = CUnicodeUtils::GetMulti(file.GetGitPathString(), CP_UTF8); size_t idx; if (!git_index_find(&idx, index, pathA)) { const git_index_entry *e = git_index_get_byindex(index, idx); if (e->flags & GIT_IDXENTRY_VALID) ++assumevalid; if (e->flags_extended & GIT_IDXENTRY_SKIP_WORKTREE) ++skipworktree; if (e->mode & 0111) ++executable; if ((e->mode & GIT_FILEMODE_LINK) == GIT_FILEMODE_LINK) ++symlink; } else { // do not show checkboxes for unversioned files ShowWindow(GetDlgItem(m_hwnd, IDC_ASSUMEVALID), SW_HIDE); ShowWindow(GetDlgItem(m_hwnd, IDC_SKIPWORKTREE), SW_HIDE); ShowWindow(GetDlgItem(m_hwnd, IDC_EXECUTABLE), SW_HIDE); ShowWindow(GetDlgItem(m_hwnd, IDC_SYMLINK), SW_HIDE); break; } } } while (0); if (assumevalid != 0 && assumevalid != filenames.size()) { SendMessage(GetDlgItem(m_hwnd, IDC_ASSUMEVALID), BM_SETSTYLE, (DWORD)GetWindowLong(GetDlgItem(m_hwnd, IDC_ASSUMEVALID), GWL_STYLE) & ~BS_AUTOCHECKBOX | BS_AUTO3STATE, 0); SendMessage(GetDlgItem(m_hwnd, IDC_ASSUMEVALID), BM_SETCHECK, BST_INDETERMINATE, 0); } else SendMessage(GetDlgItem(m_hwnd, IDC_ASSUMEVALID), BM_SETCHECK, (assumevalid == 0) ? BST_UNCHECKED : BST_CHECKED, 0); if (skipworktree != 0 && skipworktree != filenames.size()) { SendMessage(GetDlgItem(m_hwnd, IDC_SKIPWORKTREE), BM_SETSTYLE, (DWORD)GetWindowLong(GetDlgItem(m_hwnd, IDC_SKIPWORKTREE), GWL_STYLE) & ~BS_AUTOCHECKBOX | BS_AUTO3STATE, 0); SendMessage(GetDlgItem(m_hwnd, IDC_SKIPWORKTREE), BM_SETCHECK, BST_INDETERMINATE, 0); } else SendMessage(GetDlgItem(m_hwnd, IDC_SKIPWORKTREE), BM_SETCHECK, (skipworktree == 0) ? BST_UNCHECKED : BST_CHECKED, 0); if (executable != 0 && executable != filenames.size()) { SendMessage(GetDlgItem(m_hwnd, IDC_EXECUTABLE), BM_SETSTYLE, (DWORD)GetWindowLong(GetDlgItem(m_hwnd, IDC_EXECUTABLE), GWL_STYLE) & ~BS_AUTOCHECKBOX | BS_AUTO3STATE, 0); SendMessage(GetDlgItem(m_hwnd, IDC_EXECUTABLE), BM_SETCHECK, BST_INDETERMINATE, 0); EnableWindow(GetDlgItem(m_hwnd, IDC_SYMLINK), TRUE); } else { SendMessage(GetDlgItem(m_hwnd, IDC_EXECUTABLE), BM_SETCHECK, (executable == 0) ? BST_UNCHECKED : BST_CHECKED, 0); EnableWindow(GetDlgItem(m_hwnd, IDC_SYMLINK), (executable == 0) ? TRUE : FALSE); } if (symlink != 0 && symlink != filenames.size()) { SendMessage(GetDlgItem(m_hwnd, IDC_SYMLINK), BM_SETSTYLE, (DWORD)GetWindowLong(GetDlgItem(m_hwnd, IDC_SYMLINK), GWL_STYLE) & ~BS_AUTOCHECKBOX | BS_AUTO3STATE, 0); SendMessage(GetDlgItem(m_hwnd, IDC_SYMLINK), BM_SETCHECK, BST_INDETERMINATE, 0); EnableWindow(GetDlgItem(m_hwnd, IDC_EXECUTABLE), TRUE); } else { SendMessage(GetDlgItem(m_hwnd, IDC_SYMLINK), BM_SETCHECK, (symlink == 0) ? BST_UNCHECKED : BST_CHECKED, 0); EnableWindow(GetDlgItem(m_hwnd, IDC_EXECUTABLE), (symlink == 0) ? TRUE : FALSE); } } else { ShowWindow(GetDlgItem(m_hwnd, IDC_ASSUMEVALID), SW_HIDE); ShowWindow(GetDlgItem(m_hwnd, IDC_SKIPWORKTREE), SW_HIDE); ShowWindow(GetDlgItem(m_hwnd, IDC_EXECUTABLE), SW_HIDE); ShowWindow(GetDlgItem(m_hwnd, IDC_SYMLINK), SW_HIDE); } } if (filenames.size() == 1 && !PathIsDirectory(filenames[0].c_str())) { SetDlgItemText(m_hwnd, IDC_LAST_SUBJECT, CString(MAKEINTRESOURCE(IDS_LOADING))); _beginthread(LogThreadEntry, 0, this); } else ShowWindow(GetDlgItem(m_hwnd, IDC_STATIC_LASTMODIFIED), SW_HIDE); }
int luagi_reference_gen_shorthand( lua_State *L, const char *tablename ) { git_reference **ref = luaL_checkudata( L, 1, tablename ); lua_pushstring( L, git_reference_shorthand( *ref ) ); return 1; }