Skip to content

Commit

Permalink
Update libgit2 source code (d11c4a1)
Browse files Browse the repository at this point in the history
* Update libgit2 source code to commit
  d11c4a1a464f10c69d5cc58824e980ea5045d439

Signed-off-by: Stefan Widgren <stefan.widgren@gmail.com>
  • Loading branch information
stewid committed Mar 10, 2018
1 parent d1d0d35 commit f9c2cf6
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/libgit2/include/git2/diff.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,18 @@ typedef enum {
/** Use the "patience diff" algorithm */
GIT_DIFF_PATIENCE = (1u << 28),
/** Take extra time to find minimal diff */
GIT_DIFF_MINIMAL = (1 << 29),
GIT_DIFF_MINIMAL = (1u << 29),

/** Include the necessary deflate / delta information so that `git-apply`
* can apply given diff information to binary files.
*/
GIT_DIFF_SHOW_BINARY = (1 << 30),
GIT_DIFF_SHOW_BINARY = (1u << 30),

/** Use a heuristic that takes indentation and whitespace into account
* which generally can produce better diffs when dealing with ambiguous
* diff hunks.
*/
GIT_DIFF_INDENT_HEURISTIC = (1 << 31),
GIT_DIFF_INDENT_HEURISTIC = (1u << 31),
} git_diff_option_t;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/libgit2/include/git2/worktree.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ GIT_EXTERN(int) git_worktree_add(git_worktree **out, git_repository *repo,
* @param reason Reason why the working tree is being locked
* @return 0 on success, non-zero otherwise
*/
GIT_EXTERN(int) git_worktree_lock(git_worktree *wt, char *reason);
GIT_EXTERN(int) git_worktree_lock(git_worktree *wt, const char *reason);

/**
* Unlock a locked worktree
Expand Down
34 changes: 21 additions & 13 deletions src/libgit2/src/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef struct {
git_buf tmp;
unsigned int strategy;
int can_symlink;
int respect_filemode;
bool reload_submodules;
size_t total_steps;
size_t completed_steps;
Expand Down Expand Up @@ -159,17 +160,20 @@ GIT_INLINE(bool) is_workdir_base_or_new(
git_oid__cmp(&newitem->id, workdir_id) == 0);
}

GIT_INLINE(bool) is_file_mode_changed(git_filemode_t a, git_filemode_t b)
GIT_INLINE(bool) is_filemode_changed(git_filemode_t a, git_filemode_t b, int respect_filemode)
{
#ifdef GIT_WIN32
/*
* On Win32 we do not support the executable bit; the file will
* always be 0100644 on disk, don't bother doing a test.
*/
return false;
#else
return (S_ISREG(a) && S_ISREG(b) && a != b);
#endif
/* If core.filemode = false, ignore links in the repository and executable bit changes */
if (!respect_filemode) {
if (a == S_IFLNK)
a = GIT_FILEMODE_BLOB;
if (b == S_IFLNK)
b = GIT_FILEMODE_BLOB;

a &= ~0111;
b &= ~0111;
}

return (a != b);
}

static bool checkout_is_workdir_modified(
Expand Down Expand Up @@ -217,11 +221,11 @@ static bool checkout_is_workdir_modified(
if (ie != NULL &&
git_index_time_eq(&wditem->mtime, &ie->mtime) &&
wditem->file_size == ie->file_size &&
!is_file_mode_changed(wditem->mode, ie->mode)) {
!is_filemode_changed(wditem->mode, ie->mode, data->respect_filemode)) {

/* The workdir is modified iff the index entry is modified */
return !is_workdir_base_or_new(&ie->id, baseitem, newitem) ||
is_file_mode_changed(baseitem->mode, ie->mode);
is_filemode_changed(baseitem->mode, ie->mode, data->respect_filemode);
}

/* depending on where base is coming from, we may or may not know
Expand All @@ -234,7 +238,7 @@ static bool checkout_is_workdir_modified(
if (S_ISDIR(wditem->mode))
return false;

if (is_file_mode_changed(baseitem->mode, wditem->mode))
if (is_filemode_changed(baseitem->mode, wditem->mode, data->respect_filemode))
return true;

if (git_diff__oid_for_entry(&oid, data->diff, wditem, wditem->mode, NULL) < 0)
Expand Down Expand Up @@ -2454,6 +2458,10 @@ static int checkout_data_init(
&data->can_symlink, repo, GIT_CVAR_SYMLINKS)) < 0)
goto cleanup;

if ((error = git_repository__cvar(
&data->respect_filemode, repo, GIT_CVAR_FILEMODE)) < 0)
goto cleanup;

if (!data->opts.baseline && !data->opts.baseline_index) {
data->opts_free_baseline = true;
error = 0;
Expand Down
18 changes: 10 additions & 8 deletions src/libgit2/src/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,13 @@ typedef struct {
/* mutex to coordinate accessing the values */
git_mutex values_mutex;
refcounted_strmap *values;
const git_repository *repo;
git_config_level_t level;
} diskfile_header;

typedef struct {
diskfile_header header;

git_config_level_t level;
const git_repository *repo;

git_array_t(git_config_parser) readers;

bool locked;
Expand Down Expand Up @@ -270,8 +269,8 @@ static int config_open(git_config_backend *cfg, git_config_level_t level, const
int res;
diskfile_backend *b = (diskfile_backend *)cfg;

b->level = level;
b->repo = repo;
b->header.level = level;
b->header.repo = repo;

if ((res = refcounted_strmap_alloc(&b->header.values)) < 0)
return res;
Expand Down Expand Up @@ -327,6 +326,9 @@ static int config_refresh(git_config_backend *cfg)
int error, modified;
uint32_t i;

if (b->header.parent.readonly)
return config_error_readonly();

error = config_is_modified(&modified, &b->file);
if (error < 0 && error != GIT_ENOTFOUND)
goto out;
Expand All @@ -343,7 +345,7 @@ static int config_refresh(git_config_backend *cfg)
}
git_array_clear(b->file.includes);

if ((error = config_read(values->values, b->repo, &b->file, b->level, 0)) < 0)
if ((error = config_read(values->values, b->header.repo, &b->file, b->header.level, 0)) < 0)
goto out;

if ((error = git_mutex_lock(&b->header.values_mutex)) < 0) {
Expand Down Expand Up @@ -417,13 +419,13 @@ static int config_iterator_new(
diskfile_header *h;
git_config_file_iter *it;
git_config_backend *snapshot;
diskfile_backend *b = (diskfile_backend *) backend;
diskfile_header *bh = (diskfile_header *) backend;
int error;

if ((error = config_snapshot(&snapshot, backend)) < 0)
return error;

if ((error = snapshot->open(snapshot, b->level, b->repo)) < 0)
if ((error = snapshot->open(snapshot, bh->level, bh->repo)) < 0)
return error;

it = git__calloc(1, sizeof(git_config_file_iter));
Expand Down
6 changes: 4 additions & 2 deletions src/libgit2/src/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "sysdir.h"
#include "filter.h"
#include "merge_driver.h"
#include "streams/curl.h"
#include "streams/openssl.h"
#include "thread-utils.h"
#include "git2/global.h"
Expand All @@ -23,7 +24,7 @@

git_mutex git__mwindow_mutex;

#define MAX_SHUTDOWN_CB 9
#define MAX_SHUTDOWN_CB 10

static git_global_shutdown_fn git__shutdown_callbacks[MAX_SHUTDOWN_CB];
static git_atomic git__n_shutdown_callbacks;
Expand Down Expand Up @@ -63,7 +64,8 @@ static int init_common(void)
(ret = git_filter_global_init()) == 0 &&
(ret = git_merge_driver_global_init()) == 0 &&
(ret = git_transport_ssh_global_init()) == 0 &&
(ret = git_openssl_stream_global_init()) == 0)
(ret = git_openssl_stream_global_init()) == 0 &&
(ret = git_curl_stream_global_init()) == 0)
ret = git_mwindow_global_init();

GIT_MEMORY_BARRIER;
Expand Down
2 changes: 1 addition & 1 deletion src/libgit2/src/ignore.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int does_negate_pattern(git_attr_fnmatch *rule, git_attr_fnmatch *neg)
if (neg->flags & GIT_ATTR_FNMATCH_ICASE)
cmp = git__strncasecmp;
else
cmp = strncmp;
cmp = git__strncmp;

/* If lengths match we need to have an exact match */
if (rule->length == neg->length) {
Expand Down
18 changes: 18 additions & 0 deletions src/libgit2/src/streams/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "stream.h"
#include "git2/transport.h"
#include "buffer.h"
#include "global.h"
#include "vector.h"
#include "proxy.h"

Expand All @@ -38,6 +39,18 @@ typedef struct {
git_cred *proxy_cred;
} curl_stream;

int git_curl_stream_global_init(void)
{
if (curl_global_init(CURL_GLOBAL_ALL) != 0) {
giterr_set(GITERR_NET, "could not initialize curl");
return -1;
}

/* `curl_global_cleanup` is provided by libcurl */
git__on_shutdown(curl_global_cleanup);
return 0;
}

static int seterr_curl(curl_stream *s)
{
giterr_set(GITERR_NET, "curl error: %s\n", s->curl_error);
Expand Down Expand Up @@ -353,6 +366,11 @@ int git_curl_stream_new(git_stream **out, const char *host, const char *port)

#include "stream.h"

int git_curl_stream_global_init(void)
{
return 0;
}

int git_curl_stream_new(git_stream **out, const char *host, const char *port)
{
GIT_UNUSED(out);
Expand Down
1 change: 1 addition & 0 deletions src/libgit2/src/streams/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "git2/sys/stream.h"

extern int git_curl_stream_global_init(void);
extern int git_curl_stream_new(git_stream **out, const char *host, const char *port);

#endif
22 changes: 22 additions & 0 deletions src/libgit2/src/transports/winhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
#define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0
#endif

#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS_1_1
# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 0x00000200
#endif

#ifndef WINHTTP_FLAG_SECURE_PROTOCOL_TLS_1_2
# define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 0x00000800
#endif

static const char *prefix_https = "https://";
static const char *upload_pack_service = "upload-pack";
static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack";
Expand Down Expand Up @@ -744,6 +752,10 @@ static int winhttp_connect(
int error = -1;
int default_timeout = TIMEOUT_INFINITE;
int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
DWORD protocols =
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 |
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;

t->session = NULL;
t->connection = NULL;
Expand Down Expand Up @@ -786,6 +798,16 @@ static int winhttp_connect(
goto on_error;
}

/*
* Do a best-effort attempt to enable TLS 1.2 but allow this to
* fail; if TLS 1.2 support is not available for some reason,
* ignore the failure (it will keep the default protocols).
*/
WinHttpSetOption(t->session,
WINHTTP_OPTION_SECURE_PROTOCOLS,
&protocols,
sizeof(protocols));

if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
giterr_set(GITERR_OS, "failed to set timeouts for WinHTTP");
goto on_error;
Expand Down
6 changes: 3 additions & 3 deletions src/libgit2/src/worktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
return err;
}

int git_worktree_lock(git_worktree *wt, char *creason)
int git_worktree_lock(git_worktree *wt, const char *reason)
{
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
int err;
Expand All @@ -396,8 +396,8 @@ int git_worktree_lock(git_worktree *wt, char *creason)
if ((err = git_buf_joinpath(&path, wt->gitdir_path, "locked")) < 0)
goto out;

if (creason)
git_buf_attach_notowned(&buf, creason, strlen(creason));
if (reason)
git_buf_attach_notowned(&buf, reason, strlen(reason));

if ((err = git_futils_writebuffer(&buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0)
goto out;
Expand Down

0 comments on commit f9c2cf6

Please sign in to comment.