Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ git_blame* git_blame__alloc(
return NULL;
}

if (opts.flags & GIT_BLAME_USE_MAILMAP)
git_mailmap_from_repository(&gbr->mailmap, repo);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ignoring the error was actually intended. In case where we're unable to load the mail map, we simply ignore it and output commits with their original author/committer. You could add a comment and cast to void, though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore the error even though I (the user) has asked for it ? I do not know if that's explicit, but I find this strange… How can I tell if the mailmap was applied when that happens ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, you're right. And in fact git_mailmap_from_repository also only errors out in case where git_mailmap_new fails, but never if getting the actual mailmap fails. So checking the error is the right thing to do, and our future warning API should then handle errors when loading the mailmap itself (as described in mailmap_add_from_repository)

if (opts.flags & GIT_BLAME_USE_MAILMAP &&
git_mailmap_from_repository(&gbr->mailmap, repo) < 0) {
git_blame_free(gbr);
return NULL;
}

return gbr;
}
Expand Down
3 changes: 2 additions & 1 deletion src/submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
git_strmap_insert(names, entry->value, git_buf_detach(&buf), &rval);
if (rval < 0) {
giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table");
return -1;
error = -1;
goto out;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually avoid freeing memory when we run in OOM situations. But as you cannot use GITERR_CHECK_ALLOC here I'm fine with this fix

}
}
if (error == GIT_ITEROVER)
Expand Down
38 changes: 21 additions & 17 deletions src/transports/smart.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,30 +279,34 @@ static int git_smart__connect(
return error;

/* Detect capabilities */
if (git_smart__detect_caps(first, &t->caps, &symrefs) < 0) {
free_symrefs(&symrefs);
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually find this commit a bit hard to digest, as it simultaneously moves around code and changes it at the same time. I'd welcome it if you split it up into multiple commits to make it easier to understand what is going on here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this seemed a simple fix, then memory-management happened. I'll try to split (the crux of the change is that git_smart__detect_caps returns GIT_ENOTFOUND if it stumble on a weird pkt, which allows its caller to know if the symrefs it got are valid or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully the commits are more separated now, which clarifies what is happening. Note that I erroneously said symref above, but my understanding of the issue is that it might (maliciously) happen that the remote sent back one ref (refs is a vector of git_pkt in this code 😮) but doesn't follow through, so this strcmp will segfault on a NULL.

Thinking back a bit more, I don't know if that's plausible protocol-wise, but at least coverity should be pleased…

if ((error = git_smart__detect_caps(first, &t->caps, &symrefs)) == 0) {
/* If the only ref in the list is capabilities^{} with OID_ZERO, remove it */
if (1 == t->refs.length && !strcmp(first->head.name, "capabilities^{}") &&
git_oid_iszero(&first->head.oid)) {
git_vector_clear(&t->refs);
git_pkt_free((git_pkt *)first);
}

/* If the only ref in the list is capabilities^{} with OID_ZERO, remove it */
if (1 == t->refs.length && !strcmp(first->head.name, "capabilities^{}") &&
git_oid_iszero(&first->head.oid)) {
git_vector_clear(&t->refs);
git_pkt_free((git_pkt *)first);
/* Keep a list of heads for _ls */
git_smart__update_heads(t, &symrefs);
} else if (error == GIT_ENOTFOUND) {
/* There was no ref packet received, or the cap list was empty */
error = 0;
} else {
giterr_set(GITERR_NET, "invalid response");
goto cleanup;
}

/* Keep a list of heads for _ls */
git_smart__update_heads(t, &symrefs);

free_symrefs(&symrefs);

if (t->rpc && git_smart__reset_stream(t, false) < 0)
return -1;
if (t->rpc && (error = git_smart__reset_stream(t, false)) < 0)
goto cleanup;

/* We're now logically connected. */
t->connected = 1;

return 0;
cleanup:
free_symrefs(&symrefs);

return error;
}

static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transport *transport)
Expand Down
2 changes: 1 addition & 1 deletion src/transports/smart_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec

/* No refs or capabilites, odd but not a problem */
if (pkt == NULL || pkt->capabilities == NULL)
return 0;
return GIT_ENOTFOUND;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, as there is only one caller of git_smart__detect_caps, which is the one you're adjusting in the same commit


ptr = pkt->capabilities;
while (ptr != NULL && *ptr != '\0') {
Expand Down
30 changes: 15 additions & 15 deletions tests/checkout/conflict.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void create_index(struct checkout_index_entry *entries, size_t entries_le
if (entries[i].stage == 3 && (i == 0 || strcmp(entries[i-1].path, entries[i].path) != 0 || entries[i-1].stage != 2))
p_unlink(git_buf_cstr(&path));

git_index_remove_bypath(g_index, entries[i].path);
cl_git_pass(git_index_remove_bypath(g_index, entries[i].path));
}

for (i = 0; i < entries_len; i++) {
Expand Down Expand Up @@ -133,7 +133,7 @@ static void create_conflicting_index(void)
};

create_index(checkout_index_entries, 3);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));
}

static void ensure_workdir_contents(const char *path, const char *contents)
Expand Down Expand Up @@ -271,7 +271,7 @@ void test_checkout_conflict__automerge(void)
};

create_index(checkout_index_entries, 3);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand Down Expand Up @@ -303,7 +303,7 @@ void test_checkout_conflict__directory_file(void)
opts.checkout_strategy |= GIT_CHECKOUT_SAFE;

create_index(checkout_index_entries, 12);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand Down Expand Up @@ -344,7 +344,7 @@ void test_checkout_conflict__directory_file_with_custom_labels(void)
opts.their_label = "branch";

create_index(checkout_index_entries, 12);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand Down Expand Up @@ -383,7 +383,7 @@ void test_checkout_conflict__link_file(void)
opts.checkout_strategy |= GIT_CHECKOUT_SAFE;

create_index(checkout_index_entries, 12);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand All @@ -410,7 +410,7 @@ void test_checkout_conflict__links(void)
opts.checkout_strategy |= GIT_CHECKOUT_SAFE;

create_index(checkout_index_entries, 5);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand All @@ -431,7 +431,7 @@ void test_checkout_conflict__add_add(void)
opts.checkout_strategy |= GIT_CHECKOUT_SAFE;

create_index(checkout_index_entries, 2);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand Down Expand Up @@ -472,7 +472,7 @@ void test_checkout_conflict__mode_change(void)
opts.checkout_strategy |= GIT_CHECKOUT_SAFE;

create_index(checkout_index_entries, 18);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand Down Expand Up @@ -604,7 +604,7 @@ void test_checkout_conflict__renames(void)

create_index(checkout_index_entries, 41);
create_index_names(checkout_name_entries, 9);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand Down Expand Up @@ -789,7 +789,7 @@ void test_checkout_conflict__rename_keep_ours(void)

create_index(checkout_index_entries, 41);
create_index_names(checkout_name_entries, 9);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand Down Expand Up @@ -922,7 +922,7 @@ void test_checkout_conflict__name_mangled_file_exists_in_workdir(void)

create_index(checkout_index_entries, 24);
create_index_names(checkout_name_entries, 6);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

/* Add some files on disk that conflict with the names that would be chosen
* for the files written for each side. */
Expand Down Expand Up @@ -1012,7 +1012,7 @@ void test_checkout_conflict__update_only(void)
opts.checkout_strategy |= GIT_CHECKOUT_UPDATE_ONLY;

create_index(checkout_index_entries, 3);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(p_mkdir("merge-resolve/directory_file-two", 0777));
cl_git_rewritefile("merge-resolve/directory_file-two/file", CONFLICTING_OURS_FILE);
Expand Down Expand Up @@ -1063,7 +1063,7 @@ void test_checkout_conflict__path_filters(void)
opts.paths = patharray;

create_index(checkout_index_entries, 12);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand Down Expand Up @@ -1120,7 +1120,7 @@ void test_checkout_conflict__report_progress(void)


create_index(checkout_index_entries, 12);
git_index_write(g_index);
cl_git_pass(git_index_write(g_index));

cl_git_pass(git_checkout_index(g_repo, g_index, &opts));

Expand Down
6 changes: 3 additions & 3 deletions tests/checkout/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ static void create_conflict(const char *path)
git_oid_fromstr(&entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863");
cl_git_pass(git_index_add(index, &entry));

git_index_write(index);
cl_git_pass(git_index_write(index));
git_index_free(index);
}

Expand Down Expand Up @@ -1127,7 +1127,7 @@ void test_checkout_tree__removes_conflicts(void)
create_conflict("other.txt");
cl_git_mkfile("testrepo/other.txt", "This is another conflict file.\n");

git_index_write(index);
cl_git_pass(git_index_write(index));

cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts));

Expand Down Expand Up @@ -1172,7 +1172,7 @@ void test_checkout_tree__removes_conflicts_only_by_pathscope(void)
create_conflict("other.txt");
cl_git_mkfile("testrepo/other.txt", "This is another conflict file.\n");

git_index_write(index);
cl_git_pass(git_index_write(index));

cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts));

Expand Down
4 changes: 2 additions & 2 deletions tests/describe/t6120.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ static void commit_and_tag(

cl_git_append2file("describe/file", "\n");

git_index_add_bypath(index, "describe/file");
git_index_write(index);
cl_git_pass(git_index_add_bypath(index, "file"));
cl_git_pass(git_index_write(index));

*time += 10;
cl_repo_commit_from_index(&commit_id, repo, NULL, *time, commit_msg);
Expand Down
4 changes: 2 additions & 2 deletions tests/diff/workdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ void test_diff_workdir__binary_detection(void)
cl_git_write2file(
b.ptr, data[i].ptr, data[i].size, O_WRONLY|O_TRUNC, 0664);
}
git_index_write(idx);
cl_git_pass(git_index_write(idx));

cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));

Expand Down Expand Up @@ -1938,7 +1938,7 @@ void test_diff_workdir__binary_detection(void)

cl_git_write2file(b.ptr, "baseline\n", 9, O_WRONLY|O_TRUNC, 0664);
}
git_index_write(idx);
cl_git_pass(git_index_write(idx));

cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));

Expand Down
2 changes: 1 addition & 1 deletion tests/mailmap/parsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void test_mailmap_parsing__windows_string(void)

/* Parse with windows-style line endings */
git_buf_attach_notowned(&unixbuf, string_mailmap, strlen(string_mailmap));
git_buf_text_lf_to_crlf(&winbuf, &unixbuf);
cl_git_pass(git_buf_text_lf_to_crlf(&winbuf, &unixbuf));

cl_git_pass(git_mailmap_from_buffer(&g_mailmap, winbuf.ptr, winbuf.size));
git_buf_dispose(&winbuf);
Expand Down
2 changes: 1 addition & 1 deletion tests/merge/workdir/dirty.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void test_merge_workdir_dirty__identical_staged_files_allowed(void)
for (i = 0, content = result_contents[i]; content[0]; content = result_contents[++i]) {
stage_content(content);

git_index_write(repo_index);
cl_git_pass(git_index_write(repo_index));
cl_git_pass(merge_branch());
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/stash/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void test_stash_apply__initialize(void)
cl_git_pass(git_index_add_bypath(repo_index, "who"));
cl_git_pass(git_index_add_bypath(repo_index, "why"));
cl_git_pass(git_index_add_bypath(repo_index, "where"));
git_index_write(repo_index);
cl_git_pass(git_index_write(repo_index));

cl_git_rewritefile("stash/where", "....\n");

Expand Down