Commit 8d89e409 authored by Carlos Martín Nieto's avatar Carlos Martín Nieto Committed by GitHub

Merge pull request #4192 from libgit2/ethomson/win32_posix

Refactor some of the win32 POSIX emulation
parents f9d3b0d0 86536c7e
......@@ -9,6 +9,10 @@ v0.25 + 1
### API additions
* You can now set the default share mode on Windows for opening files using
`GIT_OPT_SET_WINDOWS_SHAREMODE` option with `git_libgit2_opts()`.
You can query the current share mode with `GIT_OPT_GET_WINDOWS_SHAREMODE`.
### API removals
### Breaking API changes
......
......@@ -180,6 +180,8 @@ typedef enum {
GIT_OPT_GET_USER_AGENT,
GIT_OPT_ENABLE_OFS_DELTA,
GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION,
GIT_OPT_GET_WINDOWS_SHAREMODE,
GIT_OPT_SET_WINDOWS_SHAREMODE,
} git_libgit2_opt_t;
/**
......@@ -284,6 +286,17 @@ typedef enum {
* > - `user_agent` is the value that will be delivered as the
* > User-Agent header on HTTP requests.
*
* * opts(GIT_OPT_SET_WINDOWS_SHAREMODE, unsigned long value)
*
* > Set the share mode used when opening files on Windows.
* > For more information, see the documentation for CreateFile.
* > The default is: FILE_SHARE_READ | FILE_SHARE_WRITE. This is
* > ignored and unused on non-Windows platforms.
*
* * opts(GIT_OPT_GET_WINDOWS_SHAREMODE, unsigned long *value)
*
* > Get the share mode used when opening files on Windows.
*
* * opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, int enabled)
*
* > Enable strict input validation when creating new objects
......
......@@ -53,6 +53,7 @@ typedef enum {
GIT_PASSTHROUGH = -30, /**< Internal only */
GIT_ITEROVER = -31, /**< Signals end of iteration with iterator */
GIT_RETRY = -32, /**< Internal only */
} git_error_code;
/**
......
......@@ -24,6 +24,10 @@
#define _S_IFLNK S_IFLNK
#endif
#ifndef S_IWUSR
#define S_IWUSR 00200
#endif
#ifndef S_IXUSR
#define S_IXUSR 00100
#endif
......
......@@ -231,6 +231,18 @@ int git_libgit2_opts(int key, ...)
git_object__synchronous_writing = (va_arg(ap, int) != 0);
break;
case GIT_OPT_GET_WINDOWS_SHAREMODE:
#ifdef GIT_WIN32
*(va_arg(ap, unsigned long *)) = git_win32__createfile_sharemode;
#endif
break;
case GIT_OPT_SET_WINDOWS_SHAREMODE:
#ifdef GIT_WIN32
git_win32__createfile_sharemode = va_arg(ap, unsigned long);
#endif
break;
default:
giterr_set(GITERR_INVALID, "invalid option key");
error = -1;
......
......@@ -14,6 +14,9 @@
#include "utf-conv.h"
#include "dir.h"
extern unsigned long git_win32__createfile_sharemode;
extern int git_win32__retries;
typedef SOCKET GIT_SOCKET;
#define p_lseek(f,n,w) _lseeki64(f, n, w)
......
This diff is collapsed.
......@@ -55,6 +55,31 @@ void test_odb_freshen__loose_blob(void)
cl_assert(before.st_mtime < after.st_mtime);
}
#define UNIQUE_STR "doesnt exist in the odb yet\n"
#define UNIQUE_BLOB_ID "78a87d0b8878c5953b9a63015ff4e22a3d898826"
#define UNIQUE_BLOB_FN "78/a87d0b8878c5953b9a63015ff4e22a3d898826"
void test_odb_freshen__readonly_object(void)
{
git_oid expected_id, id;
struct stat before, after;
cl_git_pass(git_oid_fromstr(&expected_id, UNIQUE_BLOB_ID));
cl_git_pass(git_blob_create_frombuffer(&id, repo, UNIQUE_STR, CONST_STRLEN(UNIQUE_STR)));
cl_assert_equal_oid(&expected_id, &id);
set_time_wayback(&before, UNIQUE_BLOB_FN);
cl_assert((before.st_mode & S_IWUSR) == 0);
cl_git_pass(git_blob_create_frombuffer(&id, repo, UNIQUE_STR, CONST_STRLEN(UNIQUE_STR)));
cl_assert_equal_oid(&expected_id, &id);
cl_must_pass(p_lstat("testrepo.git/objects/" UNIQUE_BLOB_FN, &after));
cl_assert(before.st_atime < after.st_atime);
cl_assert(before.st_mtime < after.st_mtime);
}
#define LOOSE_TREE_ID "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"
#define LOOSE_TREE_FN "94/4c0f6e4dfa41595e6eb3ceecdb14f50fe18162"
......
......@@ -19,12 +19,25 @@ static git_repository *_repo;
static git_tree *_a, *_b;
static git_atomic _counts[4];
static int _check_counts;
static int _retries;
#define THREADS 20
void test_threads_diff__initialize(void)
{
#ifdef GIT_WIN32
_retries = git_win32__retries;
git_win32__retries = 1;
#endif
}
void test_threads_diff__cleanup(void)
{
cl_git_sandbox_cleanup();
#ifdef GIT_WIN32
git_win32__retries = _retries;
#endif
}
static void setup_trees(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment