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

Skip to content

Commit 4a0313b

Browse files
committed
Merge pull request libgit2#3269 from libgit2/cmn/release-fixups
Submodule and http fixes
2 parents ca2466f + 8b38006 commit 4a0313b

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

src/submodule.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,18 @@ int git_submodule_lookup(
168168
return error;
169169
}
170170

171-
/* If it's not configured, we need to check for the path */
171+
/* If it's not configured or we're looking by path */
172172
if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD) {
173173
git_config_backend *mods;
174174
const char *pattern = "submodule\\..*\\.path";
175-
fbp_data data = { name, NULL };
175+
git_buf path = GIT_BUF_INIT;
176+
fbp_data data = { NULL, NULL };
177+
178+
git_buf_puts(&path, name);
179+
while (path.ptr[path.size-1] == '/') {
180+
path.ptr[--path.size] = '\0';
181+
}
182+
data.path = path.ptr;
176183

177184
mods = open_gitmodules(repo, GITMODULES_EXISTING);
178185

@@ -189,15 +196,16 @@ int git_submodule_lookup(
189196
if (data.name) {
190197
git__free(sm->name);
191198
sm->name = data.name;
192-
sm->path = git__strdup(name);
193-
GITERR_CHECK_ALLOC(sm->path);
199+
sm->path = git_buf_detach(&path);
194200

195201
/* Try to load again with the right name */
196202
if ((error = git_submodule_reload(sm, false)) < 0) {
197203
git_submodule_free(sm);
198204
return error;
199205
}
200206
}
207+
208+
git_buf_free(&path);
201209
}
202210

203211
if ((error = git_submodule_location(&location, sm)) < 0) {
@@ -1691,28 +1699,9 @@ static int submodule_load_from_config(
16911699

16921700
/* Deregister under name being replaced */
16931701
if (replaced) {
1694-
git_submodule_free(sm);
16951702
git__free(replaced);
16961703
}
16971704

1698-
/* Insert under alternate key */
1699-
if (alternate) {
1700-
void *old_sm = NULL;
1701-
1702-
if (error < 0)
1703-
goto done;
1704-
if (error > 0)
1705-
error = 0;
1706-
1707-
GIT_REFCOUNT_INC(sm); /* increase refcount for new key */
1708-
1709-
/* if we replaced an old module under this key, release the old one */
1710-
if (old_sm && ((git_submodule *)old_sm) != sm) {
1711-
git_submodule_free(old_sm);
1712-
/* TODO: log warning about multiple submodules with same path */
1713-
}
1714-
}
1715-
17161705
/* TODO: Look up path in index and if it is present but not a GITLINK
17171706
* then this should be deleted (at least to match git's behavior)
17181707
*/

src/transports/http.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ static int on_headers_complete(http_parser *parser)
336336
if (!t->owner->cred_acquire_cb) {
337337
no_callback = 1;
338338
} else {
339-
if (allowed_auth_types &&
340-
(!t->cred || 0 == (t->cred->credtype & allowed_auth_types))) {
339+
if (allowed_auth_types) {
341340

342341
error = t->owner->cred_acquire_cb(&t->cred,
343342
t->owner->url,

tests/submodule/lookup.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ void test_submodule_lookup__simple_lookup(void)
3131

3232
/* lookup non-existent item */
3333
refute_submodule_exists(g_repo, "no_such_file", GIT_ENOTFOUND);
34+
35+
/* lookup a submodule by path with a trailing slash */
36+
assert_submodule_exists(g_repo, "sm_added_and_uncommited/");
3437
}
3538

3639
void test_submodule_lookup__accessors(void)

0 commit comments

Comments
 (0)