static void assert_content_in_index( git_strarray *pathspecs, bool should_exist, git_strarray *expected_shas) { size_t i, pos; int error; for (i = 0; i < pathspecs->count; i++) { error = git_index_find(&pos, _index, pathspecs->strings[i]); if (should_exist) { const git_index_entry *entry; cl_assert(error != GIT_ENOTFOUND); entry = git_index_get_byindex(_index, pos); cl_assert(entry != NULL); if (!expected_shas) continue; cl_git_pass(git_oid_streq(&entry->oid, expected_shas->strings[i])); } else cl_assert_equal_i(should_exist, error != GIT_ENOTFOUND); } }
/* This is an internal function, used by Index_getitem and Index_setitem */ int Index_get_position(Index *self, PyObject *value) { char *path; int idx; /* Case 1: integer */ if (PyInt_Check(value)) { idx = (int)PyInt_AsLong(value); if (idx == -1 && PyErr_Occurred()) return -1; if (idx < 0) { PyErr_SetObject(PyExc_ValueError, value); return -1; } return idx; } /* Case 2: byte or text string */ path = py_path_to_c_str(value); if (!path) return -1; idx = git_index_find(self->index, path); if (idx < 0) { Error_set_str(idx, path); free(path); return -1; } free(path); return idx; }
void test_index_rename__single_file(void) { git_repository *repo; git_index *index; size_t position; git_oid expected; const git_index_entry *entry; p_mkdir("rename", 0700); cl_git_pass(git_repository_init(&repo, "./rename", 0)); cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); cl_git_mkfile("./rename/lame.name.txt", "new_file\n"); /* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */ cl_git_pass(git_index_add_bypath(index, "lame.name.txt")); cl_assert(git_index_entrycount(index) == 1); cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a")); cl_assert(!git_index_find(&position, index, "lame.name.txt")); entry = git_index_get_byindex(index, position); cl_assert_equal_oid(&expected, &entry->id); /* This removes the entry from the index, but not from the object database */ cl_git_pass(git_index_remove(index, "lame.name.txt", 0)); cl_assert(git_index_entrycount(index) == 0); p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt"); cl_git_pass(git_index_add_bypath(index, "fancy.name.txt")); cl_assert(git_index_entrycount(index) == 1); cl_assert(!git_index_find(&position, index, "fancy.name.txt")); entry = git_index_get_byindex(index, position); cl_assert_equal_oid(&expected, &entry->id); git_index_free(index); git_repository_free(repo); cl_fixture_cleanup("rename"); }
static void add_entry_and_check_mode_( git_index *index, bool from_file, git_filemode_t mode, const char *file, int line) { size_t pos; const git_index_entry* entry; git_index_entry new_entry; /* If old_filename exists, we copy that to the new file, and test * git_index_add(), otherwise create a new entry testing git_index_add_frombuffer */ if (from_file) { clar__assert(!git_index_find(&pos, index, "exec_off"), file, line, "Cannot find original index entry", NULL, 1); entry = git_index_get_byindex(index, pos); memcpy(&new_entry, entry, sizeof(new_entry)); } else memset(&new_entry, 0x0, sizeof(git_index_entry)); new_entry.path = "filemodes/explicit_test"; new_entry.mode = mode; if (from_file) { clar__assert(!git_index_add(index, &new_entry), file, line, "Cannot add index entry", NULL, 1); } else { const char *content = "hey there\n"; clar__assert(!git_index_add_frombuffer(index, &new_entry, content, strlen(content)), file, line, "Cannot add index entry from buffer", NULL, 1); } clar__assert(!git_index_find(&pos, index, "filemodes/explicit_test"), file, line, "Cannot find new index entry", NULL, 1); entry = git_index_get_byindex(index, pos); clar__assert_equal(file, line, "Expected mode does not match index", 1, "%07o", (unsigned int)entry->mode, (unsigned int)mode); }
static VALUE rb_git_index_get(VALUE self, VALUE entry) { git_index *index; Data_Get_Struct(self, git_index, index); if (TYPE(entry) == T_STRING) entry = INT2FIX(git_index_find(index, RSTRING_PTR(entry))); Check_Type(entry, T_FIXNUM); return rb_git_indexentry_new(git_index_get(index, FIX2INT(entry))); }
void test_index_tests__find_in_empty(void) { git_index *index; unsigned int i; cl_git_pass(git_index_open(&index, "fake-index")); for (i = 0; i < ARRAY_SIZE(test_entries); ++i) { cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path)); } git_index_free(index); }
static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha) { size_t index_pos; const git_index_entry *entry; add_to_workdir(filename, CONTENT); cl_git_pass(git_index_add_bypath(index, filename)); cl_assert(!git_index_find(&index_pos, index, filename)); entry = git_index_get_byindex(index, index_pos); cl_assert_equal_i(0, git_oid_streq(&entry->oid, expected_sha)); }
static int update_index_cb( const git_diff_delta *delta, float progress, void *payload) { struct cb_data *data = (struct cb_data *)payload; const char *add_path = NULL; GIT_UNUSED(progress); switch (delta->status) { case GIT_DELTA_IGNORED: if (data->include_ignored) add_path = delta->new_file.path; break; case GIT_DELTA_UNTRACKED: if (data->include_untracked) add_path = delta->new_file.path; break; case GIT_DELTA_ADDED: case GIT_DELTA_MODIFIED: if (data->include_changed) add_path = delta->new_file.path; break; case GIT_DELTA_DELETED: if (!data->include_changed) break; if (git_index_find(NULL, data->index, delta->old_file.path) == 0) data->error = git_index_remove( data->index, delta->old_file.path, 0); break; default: /* Unimplemented */ giterr_set( GITERR_INVALID, "Cannot update index. Unimplemented status (%d)", delta->status); data->error = -1; break; } if (add_path != NULL) data->error = git_index_add_bypath(data->index, add_path); return data->error; }
static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha) { int index_pos; git_index_entry *entry; add_to_workdir(filename, CONTENT); cl_git_pass(git_index_add_from_workdir(index, filename)); index_pos = git_index_find(index, filename); cl_assert(index_pos >= 0); entry = git_index_get_byindex(index, index_pos); cl_assert_equal_i(0, git_oid_streq(&entry->oid, expected_sha)); }
void test_index_tests__find_in_existing(void) { git_index *index; unsigned int i; cl_git_pass(git_index_open(&index, TEST_INDEX_PATH)); for (i = 0; i < ARRAY_SIZE(test_entries); ++i) { int idx = git_index_find(index, test_entries[i].path); cl_assert(idx == test_entries[i].index); } git_index_free(index); }
PyObject * Index_find(Index *self, PyObject *py_path) { char *path; long idx; path = PyString_AsString(py_path); if (!path) return NULL; idx = (long)git_index_find(self->index, path); if (idx < 0) return Error_set_str(idx, path); return PyInt_FromLong(idx); }
static VALUE rb_git_index_remove(VALUE self, VALUE entry) { git_index *index; int error; Data_Get_Struct(self, git_index, index); if (TYPE(entry) == T_STRING) entry = INT2FIX(git_index_find(index, RSTRING_PTR(entry))); Check_Type(entry, T_FIXNUM); error = git_index_remove(index, FIX2INT(entry)); rugged_exception_check(error); return Qnil; }
static void add_and_check_mode_( git_index *index, const char *filename, unsigned int expect_mode, const char *file, int line) { size_t pos; const git_index_entry *entry; cl_git_pass(git_index_add_bypath(index, filename)); clar__assert(!git_index_find(&pos, index, filename), file, line, "Cannot find index entry", NULL, 1); entry = git_index_get_byindex(index, pos); clar__assert_equal(file, line, "Expected mode does not match index", 1, "%07o", (unsigned int)entry->mode, (unsigned int)expect_mode); }
PyObject * Index__find(Index *self, PyObject *py_path) { char *path; size_t idx; int err; path = PyBytes_AsString(py_path); if (!path) return NULL; err = git_index_find(&idx, self->index, path); if (err < 0) return Error_set_str(err, path); return PyLong_FromSize_t(idx); }
int Index_contains(Index *self, PyObject *value) { char *path; int idx; path = py_path_to_c_str(value); if (!path) return -1; idx = git_index_find(self->index, path); if (idx == GIT_ENOTFOUND) return 0; if (idx < 0) { Error_set_str(idx, path); free(path); return -1; } return 1; }
int Index_contains(Index *self, PyObject *value) { char *path; int err; path = py_path_to_c_str(value); if (!path) return -1; err = git_index_find(NULL, self->index, path); if (err == GIT_ENOTFOUND) { free(path); return 0; } if (err < 0) { Error_set_str(err, path); free(path); return -1; } free(path); return 1; }
static int index_insert(git_index *index, const git_index_entry *source_entry, int replace) { git_index_entry *entry; size_t path_length; int position; git_index_entry **entry_array; assert(index && source_entry); if (source_entry->path == NULL) return git__throw(GIT_EMISSINGOBJDATA, "Failed to insert into index. Entry has no path"); entry = git__malloc(sizeof(git_index_entry)); if (entry == NULL) return GIT_ENOMEM; memcpy(entry, source_entry, sizeof(git_index_entry)); /* duplicate the path string so we own it */ entry->path = git__strdup(entry->path); if (entry->path == NULL) return GIT_ENOMEM; /* make sure that the path length flag is correct */ path_length = strlen(entry->path); entry->flags &= ~GIT_IDXENTRY_NAMEMASK; if (path_length < GIT_IDXENTRY_NAMEMASK) entry->flags |= path_length & GIT_IDXENTRY_NAMEMASK; else entry->flags |= GIT_IDXENTRY_NAMEMASK;; /* * replacing is not requested: just insert entry at the end; * the index is no longer sorted */ if (!replace) { if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS) goto cleanup_oom; return GIT_SUCCESS; } /* look if an entry with this path already exists */ position = git_index_find(index, source_entry->path); /* * if no entry exists add the entry at the end; * the index is no longer sorted */ if (position == GIT_ENOTFOUND) { if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS) goto cleanup_oom; return GIT_SUCCESS; } /* exists, replace it */ entry_array = (git_index_entry **) index->entries.contents; free((char *)entry_array[position]->path); free(entry_array[position]); entry_array[position] = entry; return GIT_SUCCESS; cleanup_oom: free((char *)entry->path); free(entry); return GIT_ENOMEM;; }
int git_index_insert(git_index *index, const git_index_entry *source_entry) { git_index_entry *offset; size_t path_length; int position; assert(index && source_entry); if (source_entry->path == NULL) return GIT_EMISSINGOBJDATA; position = git_index_find(index, source_entry->path); if (position == GIT_ENOTFOUND) { /* Resize the entries array */ if (index->entry_count + 1 > index->entries_size) { git_index_entry *new_entries; size_t new_size; new_size = (unsigned int)(index->entries_size * 1.5f); if (new_size < 8) new_size = 8; if ((new_entries = git__malloc(new_size * sizeof(git_index_entry))) == NULL) return GIT_ENOMEM; memcpy(new_entries, index->entries, index->entry_count * sizeof(git_index_entry)); free(index->entries); index->entries_size = new_size; index->entries = new_entries; } offset = &index->entries[index->entry_count]; index->entry_count++; index->sorted = 0; } else { offset = &index->entries[position]; free(offset->path); } memcpy(offset, source_entry, sizeof(git_index_entry)); /* duplicate the path string so we own it */ offset->path = git__strdup(offset->path); if (offset->path == NULL) return GIT_ENOMEM; /* make sure that the path length flag is correct */ path_length = strlen(offset->path); offset->flags &= ~GIT_IDXENTRY_NAMEMASK; if (path_length < GIT_IDXENTRY_NAMEMASK) offset->flags |= path_length & GIT_IDXENTRY_NAMEMASK; else offset->flags |= GIT_IDXENTRY_NAMEMASK;; /* TODO: force the extended index entry flag? */ assert(offset->path); return GIT_SUCCESS; }
void test_submodule_status__ignore_none(void) { unsigned int status; git_submodule *sm; git_buf path = GIT_BUF_INIT; cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged")); cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES)); cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_dir")); cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, g_repo, "not-submodule")); cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, g_repo, "not")); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED) != 0); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED) != 0); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNTRACKED) != 0); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0); /* removed sm_unchanged for deleted workdir */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0); /* now mkdir sm_unchanged to test uninitialized */ cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0)); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged")); cl_git_pass(git_submodule_reload(sm)); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0); /* update sm_changed_head in index */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); cl_git_pass(git_submodule_add_to_index(sm, true)); /* reload is not needed because add_to_index updates the submodule data */ cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0); /* remove sm_changed_head from index */ { git_index *index; size_t pos; cl_git_pass(git_repository_index(&index, g_repo)); cl_assert(!git_index_find(&pos, index, "sm_changed_head")); cl_git_pass(git_index_remove(index, "sm_changed_head", 0)); cl_git_pass(git_index_write(index)); git_index_free(index); } cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); cl_git_pass(git_submodule_reload(sm)); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_DELETED) != 0); git_buf_free(&path); }
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); }
static int checkout_action_wd_only( checkout_data *data, git_iterator *workdir, const git_index_entry *wd, git_vector *pathspec) { bool remove = false; git_checkout_notify_t notify = GIT_CHECKOUT_NOTIFY_NONE; if (!git_pathspec_match_path( pathspec, wd->path, (data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0, git_iterator_ignore_case(workdir), NULL)) return 0; /* check if item is tracked in the index but not in the checkout diff */ if (data->index != NULL) { if (wd->mode != GIT_FILEMODE_TREE) { int error; if ((error = git_index_find(NULL, data->index, wd->path)) == 0) { notify = GIT_CHECKOUT_NOTIFY_DIRTY; remove = ((data->strategy & GIT_CHECKOUT_FORCE) != 0); } else if (error != GIT_ENOTFOUND) return error; } else { /* for tree entries, we have to see if there are any index * entries that are contained inside that tree */ size_t pos = git_index__prefix_position(data->index, wd->path); const git_index_entry *e = git_index_get_byindex(data->index, pos); if (e != NULL && data->diff->pfxcomp(e->path, wd->path) == 0) { notify = GIT_CHECKOUT_NOTIFY_DIRTY; remove = ((data->strategy & GIT_CHECKOUT_FORCE) != 0); } } } if (notify != GIT_CHECKOUT_NOTIFY_NONE) /* found in index */; else if (git_iterator_current_is_ignored(workdir)) { notify = GIT_CHECKOUT_NOTIFY_IGNORED; remove = ((data->strategy & GIT_CHECKOUT_REMOVE_IGNORED) != 0); } else { notify = GIT_CHECKOUT_NOTIFY_UNTRACKED; remove = ((data->strategy & GIT_CHECKOUT_REMOVE_UNTRACKED) != 0); } if (checkout_notify(data, notify, NULL, wd)) return GIT_EUSER; if (remove) { char *path = git_pool_strdup(&data->pool, wd->path); GITERR_CHECK_ALLOC(path); if (git_vector_insert(&data->removes, path) < 0) return -1; } return 0; }
BOOL CGitPropertyPage::PageProc (HWND /*hwnd*/, UINT uMessage, WPARAM wParam, LPARAM lParam) { switch (uMessage) { case WM_INITDIALOG: { InitWorkfileView(); return TRUE; } case WM_NOTIFY: { LPNMHDR point = (LPNMHDR)lParam; int code = point->code; // // Respond to notifications. // if (code == PSN_APPLY && m_bChanged) { do { CTGitPath path(filenames.front().c_str()); CString projectTopDir; if(!path.HasAdminDir(&projectTopDir) || path.IsDirectory()) break; int stripLength = projectTopDir.GetLength(); if (projectTopDir[stripLength - 1] != _T('\\')) ++stripLength; CAutoRepository repository(CUnicodeUtils::GetUTF8(projectTopDir)); if (!repository) break; CAutoIndex index; if (git_repository_index(index.GetPointer(), repository)) break; BOOL assumeValid = (BOOL)SendMessage(GetDlgItem(m_hwnd, IDC_ASSUMEVALID), BM_GETCHECK, 0, 0); BOOL skipWorktree = (BOOL)SendMessage(GetDlgItem(m_hwnd, IDC_SKIPWORKTREE), BM_GETCHECK, 0, 0); BOOL executable = (BOOL)SendMessage(GetDlgItem(m_hwnd, IDC_EXECUTABLE), BM_GETCHECK, 0, 0); BOOL symlink = (BOOL)SendMessage(GetDlgItem(m_hwnd, IDC_SYMLINK), BM_GETCHECK, 0, 0); bool changed = false; 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)) { git_index_entry *e = const_cast<git_index_entry *>(git_index_get_byindex(index, idx)); // HACK if (assumeValid == BST_CHECKED) { if (!(e->flags & GIT_IDXENTRY_VALID)) { e->flags |= GIT_IDXENTRY_VALID; changed = true; } } else if (assumeValid != BST_INDETERMINATE) { if (e->flags & GIT_IDXENTRY_VALID) { e->flags &= ~GIT_IDXENTRY_VALID; changed = true; } } if (skipWorktree == BST_CHECKED) { if (!(e->flags_extended & GIT_IDXENTRY_SKIP_WORKTREE)) { e->flags_extended |= GIT_IDXENTRY_SKIP_WORKTREE; changed = true; } } else if (skipWorktree != BST_INDETERMINATE) { if (e->flags_extended & GIT_IDXENTRY_SKIP_WORKTREE) { e->flags_extended &= ~GIT_IDXENTRY_SKIP_WORKTREE; changed = true; } } if (executable == BST_CHECKED) { if (!(e->mode & 0111)) { e->mode |= 0111; changed = true; } } else if (executable != BST_INDETERMINATE) { if (e->mode & 0111) { e->mode &= ~0111; changed = true; } } if (symlink == BST_CHECKED) { if ((e->mode & GIT_FILEMODE_LINK) != GIT_FILEMODE_LINK) { e->mode |= GIT_FILEMODE_LINK; changed = true; } } else if (symlink != BST_INDETERMINATE) { if ((e->mode & GIT_FILEMODE_LINK) == GIT_FILEMODE_LINK) { e->mode &= ~GIT_FILEMODE_LINK; changed = true; } } if (changed) git_index_add(index, e); } } if (changed) { if (!git_index_write(index)) m_bChanged = false; } } while (0); } SetWindowLongPtr (m_hwnd, DWLP_MSGRESULT, FALSE); return TRUE; } case WM_DESTROY: return TRUE; case WM_COMMAND: PageProcOnCommand(wParam); break; } // switch (uMessage) if (uMessage == m_UpdateLastCommit) { DisplayCommit((git_commit *)lParam, IDC_LAST_HASH, IDC_LAST_SUBJECT, IDC_LAST_AUTHOR, IDC_LAST_DATE); return TRUE; } return FALSE; }
int cmd_checkout(int argc, const char **argv) { /* Delete the following line once gits tests pass please_git_do_it_for_me(); if (argc != 1) please_git_do_it_for_me(); */ git_index *index; git_repository *repo; git_index_entry *index_entry; git_oid id; /* Open the repository */ if (git_repository_open(&repo, ".git")) { libgit_error(); } /* Get the Index file of a Git repository */ if (git_repository_index(&index,repo)) { libgit_error(); } /* Find the first index of any entries which point to given path in the Git index */ if (git_index_find (index, ".git")) { libgit_error(); } int i = 0; /* get a pointer to one of the entries in the index */ index_entry = git_index_get(index, i); if (index_entry == NULL) printf("Out of bound"); else id = index_entry->oid; (void)id; git_reference *symbolic_ref; if (git_reference_lookup(&symbolic_ref, repo, "HEAD")) libgit_error(); git_reference *direct_ref; if (git_reference_resolve(&direct_ref, symbolic_ref)) libgit_error(); const git_oid *oid; oid = git_reference_oid(direct_ref); if (oid == NULL) { printf("Internal error: reference is not direct\n"); return EXIT_FAILURE; } git_tree *tree; /* Lookup a tree object from the repository */ if (git_tree_lookup(&tree, repo, oid)) libgit_error(); /* Update the index ?? */ if (git_index_read(index)) libgit_error(); git_index_free(index); git_tree_close(tree); return EXIT_SUCCESS; }
bool Index::find(const std::string& path) { return git_index_find(NULL, data(), path.c_str()) >= 0; }