Skip to content

Commit 928b4ca

Browse files
committed
Merge pull request libgit2#3005 from libgit2/cmn/maint-update
Backports for the maint branch
2 parents 79010d0 + 1f726d0 commit 928b4ca

File tree

27 files changed

+243
-36
lines changed

27 files changed

+243
-36
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ OPTION( VALGRIND "Configure build for valgrind" OFF )
4242

4343
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
4444
SET( USE_ICONV ON )
45-
ADD_DEFINITIONS(-DGIT_COMMON_CRYPTO)
4645
ENDIF()
4746

4847
IF(MSVC)
@@ -172,6 +171,8 @@ ENDIF()
172171
IF (WIN32 AND NOT MINGW AND NOT SHA1_TYPE STREQUAL "builtin")
173172
ADD_DEFINITIONS(-DWIN32_SHA1)
174173
FILE(GLOB SRC_SHA1 src/hash/hash_win32.c)
174+
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
175+
ADD_DEFINITIONS(-DGIT_COMMON_CRYPTO)
175176
ELSEIF (OPENSSL_FOUND AND NOT SHA1_TYPE STREQUAL "builtin")
176177
ADD_DEFINITIONS(-DOPENSSL_SHA1)
177178
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
@@ -217,7 +218,8 @@ IF (USE_SSH)
217218
ENDIF()
218219
IF (LIBSSH2_FOUND)
219220
ADD_DEFINITIONS(-DGIT_SSH)
220-
INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIR})
221+
INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIRS})
222+
LINK_DIRECTORIES(${LIBSSH2_LIBRARY_DIRS})
221223
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} libssh2")
222224
SET(SSH_LIBRARIES ${LIBSSH2_LIBRARIES})
223225
ENDIF()

include/git2/repository.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ GIT_EXTERN(int) git_repository_head_unborn(git_repository *repo);
342342
/**
343343
* Check if a repository is empty
344344
*
345-
* An empty repository has just been initialized and contains
346-
* no references.
345+
* An empty repository has just been initialized and contains no references
346+
* apart from HEAD, which must be pointing to the unborn master branch.
347347
*
348348
* @param repo Repo to test
349349
* @return 1 if the repository is empty, 0 if it isn't, error code

include/git2/sys/repository.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#ifndef INCLUDE_sys_git_repository_h__
88
#define INCLUDE_sys_git_repository_h__
99

10+
#include "git2/common.h"
11+
#include "git2/types.h"
12+
1013
/**
1114
* @file git2/sys/repository.h
1215
* @brief Git repository custom implementation routines
@@ -53,7 +56,7 @@ GIT_EXTERN(void) git_repository__cleanup(git_repository *repo);
5356
*
5457
* @param repo A repository object
5558
* @param recurse_submodules Should submodules be updated recursively
56-
* @returrn 0 on success, < 0 on error
59+
* @return 0 on success, < 0 on error
5760
*/
5861
GIT_EXTERN(int) git_repository_reinit_filesystem(
5962
git_repository *repo,

src/branch.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,13 @@ int git_branch_delete(git_reference *branch)
138138
if (git_reference_delete(branch) < 0)
139139
goto on_error;
140140

141-
if (git_reflog_delete(git_reference_owner(branch), git_reference_name(branch)) < 0)
141+
if ((error = git_reflog_delete(git_reference_owner(branch), git_reference_name(branch))) < 0) {
142+
if (error == GIT_ENOTFOUND) {
143+
giterr_clear();
144+
error = 0;
145+
}
142146
goto on_error;
147+
}
143148

144149
error = 0;
145150

src/buf_text.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ bool git_buf_text_is_binary(const git_buf *buf)
191191
while (scan < end) {
192192
unsigned char c = *scan++;
193193

194-
if (c > 0x1F && c < 0x7F)
194+
/* Printable characters are those above SPACE (0x1F) excluding DEL,
195+
* and including BS, ESC and FF.
196+
*/
197+
if ((c > 0x1F && c != 127) || c == '\b' || c == '\033' || c == '\014')
195198
printable++;
196199
else if (c == '\0')
197200
return true;

src/checkout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,7 @@ static void checkout_data_clear(checkout_data *data)
22122212
git__free(data->pfx);
22132213
data->pfx = NULL;
22142214

2215+
git_buf_free(&data->last_mkdir);
22152216
git_buf_free(&data->path);
22162217
git_buf_free(&data->tmp);
22172218

src/config_file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ static int config_parse(git_strmap *values, diskfile_backend *cfg_file, struct r
12841284
if (result == 0) {
12851285
result = config_parse(values, cfg_file, r, level, depth+1);
12861286
r = git_array_get(cfg_file->readers, index);
1287+
reader = git_array_get(cfg_file->readers, reader_idx);
12871288
}
12881289
else if (result == GIT_ENOTFOUND) {
12891290
giterr_clear();

src/diff_patch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,8 @@ int git_patch__invoke_callbacks(
822822
for (i = 0; !error && i < git_array_size(patch->hunks); ++i) {
823823
diff_patch_hunk *h = git_array_get(patch->hunks, i);
824824

825-
error = hunk_cb(patch->delta, &h->hunk, payload);
825+
if (hunk_cb)
826+
error = hunk_cb(patch->delta, &h->hunk, payload);
826827

827828
if (!line_cb)
828829
continue;

src/fileops.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ int git_futils_mkdir_withperf(
330330
{
331331
int error = -1;
332332
git_buf make_path = GIT_BUF_INIT;
333-
ssize_t root = 0, min_root_len;
333+
ssize_t root = 0, min_root_len, root_len;
334334
char lastch = '/', *tail;
335335
struct stat st;
336336

@@ -343,22 +343,29 @@ int git_futils_mkdir_withperf(
343343
goto done;
344344
}
345345

346-
/* remove trailing slashes on path */
347-
while (make_path.ptr[make_path.size - 1] == '/') {
348-
make_path.size--;
349-
make_path.ptr[make_path.size] = '\0';
350-
}
346+
/* Trim trailing slashes (except the root) */
347+
if ((root_len = git_path_root(make_path.ptr)) < 0)
348+
root_len = 0;
349+
else
350+
root_len++;
351+
352+
while (make_path.size > (size_t)root_len &&
353+
make_path.ptr[make_path.size - 1] == '/')
354+
make_path.ptr[--make_path.size] = '\0';
351355

352356
/* if we are not supposed to made the last element, truncate it */
353357
if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) {
354-
git_buf_rtruncate_at_char(&make_path, '/');
358+
git_path_dirname_r(&make_path, make_path.ptr);
355359
flags |= GIT_MKDIR_SKIP_LAST;
356360
}
357-
if ((flags & GIT_MKDIR_SKIP_LAST) != 0)
358-
git_buf_rtruncate_at_char(&make_path, '/');
361+
if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
362+
git_path_dirname_r(&make_path, make_path.ptr);
363+
}
359364

360-
/* if nothing left after truncation, then we're done! */
361-
if (!make_path.size) {
365+
/* We were either given the root path (or trimmed it to
366+
* the root), we don't have anything to do.
367+
*/
368+
if (make_path.size <= (size_t)root_len) {
362369
error = 0;
363370
goto done;
364371
}

src/index.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ static void index_entry_reuc_free(git_index_reuc_entry *reuc)
292292

293293
static void index_entry_free(git_index_entry *entry)
294294
{
295+
if (!entry)
296+
return;
297+
295298
memset(&entry->id, 0, sizeof(entry->id));
296299
git__free(entry);
297300
}

0 commit comments

Comments
 (0)