Skip to content

Commit 5910500

Browse files
committed
Update bundled libgit2 source code to v0.28.5
* Update libgit2 source code to commit 7a2b969d559b83798d93728f24d1729ffc97b717 Signed-off-by: Stefan Widgren <stefan.widgren@gmail.com>
1 parent d85d236 commit 5910500

31 files changed

+457
-207
lines changed

src/libgit2/include/git2/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#ifndef INCLUDE_git_version_h__
88
#define INCLUDE_git_version_h__
99

10-
#define LIBGIT2_VERSION "0.28.4"
10+
#define LIBGIT2_VERSION "0.28.5"
1111
#define LIBGIT2_VER_MAJOR 0
1212
#define LIBGIT2_VER_MINOR 28
13-
#define LIBGIT2_VER_REVISION 4
13+
#define LIBGIT2_VER_REVISION 5
1414
#define LIBGIT2_VER_PATCH 0
1515

1616
#define LIBGIT2_SOVERSION 28

src/libgit2/src/apply.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int patch_image_init_fromstr(
5959
git_pool_init(&out->pool, sizeof(git_diff_line));
6060

6161
for (start = in; start < in + in_len; start = end) {
62-
end = memchr(start, '\n', in_len);
62+
end = memchr(start, '\n', in_len - (start - in));
6363

6464
if (end == NULL)
6565
end = in + in_len;
@@ -199,23 +199,34 @@ static int apply_hunk(
199199

200200
for (i = 0; i < hunk->line_count; i++) {
201201
size_t linenum = hunk->line_start + i;
202-
git_diff_line *line = git_array_get(patch->lines, linenum);
202+
git_diff_line *line = git_array_get(patch->lines, linenum), *prev;
203203

204204
if (!line) {
205205
error = apply_err("preimage does not contain line %"PRIuZ, linenum);
206206
goto done;
207207
}
208208

209-
if (line->origin == GIT_DIFF_LINE_CONTEXT ||
210-
line->origin == GIT_DIFF_LINE_DELETION) {
211-
if ((error = git_vector_insert(&preimage.lines, line)) < 0)
212-
goto done;
213-
}
214-
215-
if (line->origin == GIT_DIFF_LINE_CONTEXT ||
216-
line->origin == GIT_DIFF_LINE_ADDITION) {
217-
if ((error = git_vector_insert(&postimage.lines, line)) < 0)
218-
goto done;
209+
switch (line->origin) {
210+
case GIT_DIFF_LINE_CONTEXT_EOFNL:
211+
case GIT_DIFF_LINE_DEL_EOFNL:
212+
case GIT_DIFF_LINE_ADD_EOFNL:
213+
prev = i ? git_array_get(patch->lines, linenum - 1) : NULL;
214+
if (prev && prev->content[prev->content_len - 1] == '\n')
215+
prev->content_len -= 1;
216+
break;
217+
case GIT_DIFF_LINE_CONTEXT:
218+
if ((error = git_vector_insert(&preimage.lines, line)) < 0 ||
219+
(error = git_vector_insert(&postimage.lines, line)) < 0)
220+
goto done;
221+
break;
222+
case GIT_DIFF_LINE_DELETION:
223+
if ((error = git_vector_insert(&preimage.lines, line)) < 0)
224+
goto done;
225+
break;
226+
case GIT_DIFF_LINE_ADDITION:
227+
if ((error = git_vector_insert(&postimage.lines, line)) < 0)
228+
goto done;
229+
break;
219230
}
220231
}
221232

@@ -631,9 +642,12 @@ int git_apply_to_tree(
631642
for (i = 0; i < git_diff_num_deltas(diff); i++) {
632643
delta = git_diff_get_delta(diff, i);
633644

634-
if ((error = git_index_remove(postimage,
635-
delta->old_file.path, 0)) < 0)
636-
goto done;
645+
if (delta->status == GIT_DELTA_DELETED ||
646+
delta->status == GIT_DELTA_RENAMED) {
647+
if ((error = git_index_remove(postimage,
648+
delta->old_file.path, 0)) < 0)
649+
goto done;
650+
}
637651
}
638652

639653
if ((error = apply_deltas(repo, pre_reader, NULL, post_reader, postimage, diff, &opts)) < 0)

src/libgit2/src/attrcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ int git_attr_cache__init(git_repository *repo)
413413
git_config_free(cfg);
414414

415415
/* insert default macros */
416-
return git_attr_add_macro(repo, "binary", "-diff -crlf -text");
416+
return git_attr_add_macro(repo, "binary", "-diff -merge -text -crlf");
417417

418418
cancel:
419419
attr_cache__free(cache);

src/libgit2/src/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ int git_blame_file(
408408

409409
static bool hunk_is_bufferblame(git_blame_hunk *hunk)
410410
{
411-
return git_oid_iszero(&hunk->final_commit_id);
411+
return hunk && git_oid_iszero(&hunk->final_commit_id);
412412
}
413413

414414
static int buffer_hunk_cb(

src/libgit2/src/buffer.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ char git_buf__initbuf[1];
1818
char git_buf__oom[1];
1919

2020
#define ENSURE_SIZE(b, d) \
21-
if ((d) > (b)->asize && git_buf_grow((b), (d)) < 0)\
21+
if ((b)->ptr == git_buf__oom || \
22+
((d) > (b)->asize && git_buf_grow((b), (d)) < 0))\
2223
return -1;
2324

2425

@@ -58,20 +59,26 @@ int git_buf_try_grow(
5859
new_ptr = NULL;
5960
} else {
6061
new_size = buf->asize;
62+
/*
63+
* Grow the allocated buffer by 1.5 to allow
64+
* re-use of memory holes resulting from the
65+
* realloc. If this is still too small, then just
66+
* use the target size.
67+
*/
68+
if ((new_size = (new_size << 1) - (new_size >> 1)) < target_size)
69+
new_size = target_size;
6170
new_ptr = buf->ptr;
6271
}
6372

64-
/* grow the buffer size by 1.5, until it's big enough
65-
* to fit our target size */
66-
while (new_size < target_size)
67-
new_size = (new_size << 1) - (new_size >> 1);
68-
6973
/* round allocation up to multiple of 8 */
7074
new_size = (new_size + 7) & ~7;
7175

7276
if (new_size < buf->size) {
73-
if (mark_oom)
77+
if (mark_oom) {
78+
if (buf->ptr && buf->ptr != git_buf__initbuf)
79+
git__free(buf->ptr);
7480
buf->ptr = git_buf__oom;
81+
}
7582

7683
git_error_set_oom();
7784
return -1;

src/libgit2/src/cherrypick.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static int write_cherrypick_head(
3030
int error = 0;
3131

3232
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
33-
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) >= 0 &&
33+
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_CHERRYPICK_FILE_MODE)) >= 0 &&
3434
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
3535
error = git_filebuf_commit(&file);
3636

@@ -51,7 +51,7 @@ static int write_merge_msg(
5151
int error = 0;
5252

5353
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
54-
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) < 0 ||
54+
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_CHERRYPICK_FILE_MODE)) < 0 ||
5555
(error = git_filebuf_printf(&file, "%s", commit_msg)) < 0)
5656
goto cleanup;
5757

src/libgit2/src/diff.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ static int file_cb(
443443
return error;
444444
}
445445

446-
static int line_cb(
446+
static int patchid_line_cb(
447447
const git_diff_delta *delta,
448448
const git_diff_hunk *hunk,
449449
const git_diff_line *line,
@@ -465,6 +465,14 @@ static int line_cb(
465465
break;
466466
case GIT_DIFF_LINE_CONTEXT:
467467
break;
468+
case GIT_DIFF_LINE_CONTEXT_EOFNL:
469+
case GIT_DIFF_LINE_ADD_EOFNL:
470+
case GIT_DIFF_LINE_DEL_EOFNL:
471+
/*
472+
* Ignore EOF without newlines for patch IDs as whitespace is
473+
* not supposed to be significant.
474+
*/
475+
return 0;
468476
default:
469477
git_error_set(GIT_ERROR_PATCH, "invalid line origin for patch");
470478
return -1;
@@ -501,7 +509,7 @@ int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opt
501509
if ((error = git_hash_ctx_init(&args.ctx)) < 0)
502510
goto out;
503511

504-
if ((error = git_diff_foreach(diff, file_cb, NULL, NULL, line_cb, &args)) < 0)
512+
if ((error = git_diff_foreach(diff, file_cb, NULL, NULL, patchid_line_cb, &args)) < 0)
505513
goto out;
506514

507515
if ((error = (flush_hunk(&args.result, &args.ctx))) < 0)

0 commit comments

Comments
 (0)