rugged 0.17.0.b6 → 0.17.0.b7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/README.md +3 -3
  2. data/Rakefile +3 -1
  3. data/ext/rugged/rugged.c +30 -0
  4. data/ext/rugged/rugged.h +9 -0
  5. data/ext/rugged/rugged_branch.c +306 -0
  6. data/ext/rugged/rugged_config.c +16 -13
  7. data/ext/rugged/rugged_index.c +25 -0
  8. data/ext/rugged/rugged_object.c +6 -2
  9. data/ext/rugged/rugged_reference.c +11 -18
  10. data/ext/rugged/rugged_revwalk.c +1 -1
  11. data/lib/rugged.rb +1 -0
  12. data/lib/rugged/branch.rb +28 -0
  13. data/lib/rugged/commit.rb +5 -5
  14. data/lib/rugged/repository.rb +32 -7
  15. data/lib/rugged/tag.rb +5 -1
  16. data/lib/rugged/version.rb +1 -1
  17. data/test/branch_test.rb +227 -0
  18. data/test/config_test.rb +1 -1
  19. data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  20. data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
  21. data/test/index_test.rb +31 -0
  22. data/test/index_test.rb~ +218 -0
  23. data/test/lib_test.rb +22 -0
  24. data/test/reference_test.rb +5 -3
  25. data/vendor/libgit2/Makefile.embed +1 -1
  26. data/vendor/libgit2/include/git2.h +1 -0
  27. data/vendor/libgit2/include/git2/branch.h +17 -13
  28. data/vendor/libgit2/include/git2/checkout.h +83 -22
  29. data/vendor/libgit2/include/git2/clone.h +6 -3
  30. data/vendor/libgit2/include/git2/common.h +1 -8
  31. data/vendor/libgit2/include/git2/config.h +185 -26
  32. data/vendor/libgit2/include/git2/diff.h +229 -17
  33. data/vendor/libgit2/include/git2/errors.h +39 -1
  34. data/vendor/libgit2/include/git2/ignore.h +6 -3
  35. data/vendor/libgit2/include/git2/indexer.h +1 -0
  36. data/vendor/libgit2/include/git2/merge.h +1 -1
  37. data/vendor/libgit2/include/git2/object.h +7 -4
  38. data/vendor/libgit2/include/git2/odb.h +4 -2
  39. data/vendor/libgit2/include/git2/odb_backend.h +6 -0
  40. data/vendor/libgit2/include/git2/oid.h +2 -0
  41. data/vendor/libgit2/include/git2/pack.h +89 -0
  42. data/vendor/libgit2/include/git2/refs.h +88 -0
  43. data/vendor/libgit2/include/git2/refspec.h +0 -8
  44. data/vendor/libgit2/include/git2/remote.h +34 -1
  45. data/vendor/libgit2/include/git2/repository.h +238 -6
  46. data/vendor/libgit2/include/git2/reset.h +4 -1
  47. data/vendor/libgit2/include/git2/revwalk.h +1 -1
  48. data/vendor/libgit2/include/git2/status.h +19 -14
  49. data/vendor/libgit2/include/git2/strarray.h +54 -0
  50. data/vendor/libgit2/include/git2/submodule.h +451 -45
  51. data/vendor/libgit2/include/git2/tag.h +16 -0
  52. data/vendor/libgit2/include/git2/tree.h +2 -2
  53. data/vendor/libgit2/include/git2/types.h +4 -0
  54. data/vendor/libgit2/src/amiga/map.c +4 -7
  55. data/vendor/libgit2/src/attr.c +21 -13
  56. data/vendor/libgit2/src/attr.h +3 -1
  57. data/vendor/libgit2/src/attr_file.c +14 -14
  58. data/vendor/libgit2/src/attr_file.h +6 -5
  59. data/vendor/libgit2/src/blob.c +22 -12
  60. data/vendor/libgit2/src/branch.c +62 -66
  61. data/vendor/libgit2/src/buffer.c +63 -14
  62. data/vendor/libgit2/src/buffer.h +4 -0
  63. data/vendor/libgit2/src/cache.c +5 -4
  64. data/vendor/libgit2/src/checkout.c +381 -159
  65. data/vendor/libgit2/src/clone.c +221 -94
  66. data/vendor/libgit2/src/common.h +13 -3
  67. data/vendor/libgit2/src/compress.c +53 -0
  68. data/vendor/libgit2/src/compress.h +16 -0
  69. data/vendor/libgit2/src/config.c +380 -175
  70. data/vendor/libgit2/src/config.h +2 -5
  71. data/vendor/libgit2/src/config_file.c +63 -46
  72. data/vendor/libgit2/src/config_file.h +16 -4
  73. data/vendor/libgit2/src/crlf.c +4 -3
  74. data/vendor/libgit2/src/delta.c +491 -0
  75. data/vendor/libgit2/src/delta.h +112 -0
  76. data/vendor/libgit2/src/diff.c +310 -67
  77. data/vendor/libgit2/src/diff.h +10 -1
  78. data/vendor/libgit2/src/diff_output.c +1030 -337
  79. data/vendor/libgit2/src/diff_output.h +86 -0
  80. data/vendor/libgit2/src/errors.c +10 -1
  81. data/vendor/libgit2/src/fetch.c +108 -24
  82. data/vendor/libgit2/src/filebuf.c +8 -2
  83. data/vendor/libgit2/src/fileops.c +342 -177
  84. data/vendor/libgit2/src/fileops.h +84 -7
  85. data/vendor/libgit2/src/filter.c +0 -35
  86. data/vendor/libgit2/src/filter.h +0 -12
  87. data/vendor/libgit2/src/{compat/fnmatch.c → fnmatch.c} +16 -4
  88. data/vendor/libgit2/src/{compat/fnmatch.h → fnmatch.h} +4 -3
  89. data/vendor/libgit2/src/global.c +4 -0
  90. data/vendor/libgit2/src/ignore.c +122 -23
  91. data/vendor/libgit2/src/ignore.h +1 -0
  92. data/vendor/libgit2/src/index.c +56 -10
  93. data/vendor/libgit2/src/index.h +2 -0
  94. data/vendor/libgit2/src/indexer.c +8 -9
  95. data/vendor/libgit2/src/iterator.c +244 -31
  96. data/vendor/libgit2/src/iterator.h +30 -1
  97. data/vendor/libgit2/src/message.c +1 -1
  98. data/vendor/libgit2/src/netops.c +44 -4
  99. data/vendor/libgit2/src/object.c +80 -69
  100. data/vendor/libgit2/src/object.h +39 -0
  101. data/vendor/libgit2/src/odb.c +79 -15
  102. data/vendor/libgit2/src/odb.h +20 -5
  103. data/vendor/libgit2/src/odb_pack.c +65 -33
  104. data/vendor/libgit2/src/oid.c +0 -3
  105. data/vendor/libgit2/src/pack-objects.c +1315 -0
  106. data/vendor/libgit2/src/pack-objects.h +87 -0
  107. data/vendor/libgit2/src/pack.c +36 -12
  108. data/vendor/libgit2/src/pack.h +1 -0
  109. data/vendor/libgit2/src/path.c +42 -9
  110. data/vendor/libgit2/src/path.h +14 -0
  111. data/vendor/libgit2/src/pkt.c +52 -2
  112. data/vendor/libgit2/src/pkt.h +10 -0
  113. data/vendor/libgit2/src/pool.h +11 -0
  114. data/vendor/libgit2/src/posix.h +8 -0
  115. data/vendor/libgit2/src/protocol.c +24 -2
  116. data/vendor/libgit2/src/protocol.h +4 -0
  117. data/vendor/libgit2/src/reflog.c +1 -1
  118. data/vendor/libgit2/src/refs.c +292 -124
  119. data/vendor/libgit2/src/refs.h +4 -2
  120. data/vendor/libgit2/src/refspec.c +117 -19
  121. data/vendor/libgit2/src/refspec.h +19 -0
  122. data/vendor/libgit2/src/remote.c +152 -48
  123. data/vendor/libgit2/src/remote.h +4 -1
  124. data/vendor/libgit2/src/repo_template.h +58 -0
  125. data/vendor/libgit2/src/repository.c +594 -179
  126. data/vendor/libgit2/src/repository.h +23 -22
  127. data/vendor/libgit2/src/reset.c +71 -29
  128. data/vendor/libgit2/src/revparse.c +26 -17
  129. data/vendor/libgit2/src/revwalk.c +36 -19
  130. data/vendor/libgit2/src/sha1.h +7 -0
  131. data/vendor/libgit2/src/{sha1.c → sha1/sha1.c} +0 -0
  132. data/vendor/libgit2/src/signature.c +12 -10
  133. data/vendor/libgit2/src/status.c +52 -6
  134. data/vendor/libgit2/src/submodule.c +1363 -255
  135. data/vendor/libgit2/src/submodule.h +102 -0
  136. data/vendor/libgit2/src/tag.c +42 -26
  137. data/vendor/libgit2/src/thread-utils.h +7 -7
  138. data/vendor/libgit2/src/transport.h +15 -1
  139. data/vendor/libgit2/src/transports/git.c +1 -1
  140. data/vendor/libgit2/src/transports/http.c +197 -36
  141. data/vendor/libgit2/src/tree.c +3 -3
  142. data/vendor/libgit2/src/unix/map.c +2 -0
  143. data/vendor/libgit2/src/unix/posix.h +1 -8
  144. data/vendor/libgit2/src/util.c +6 -1
  145. data/vendor/libgit2/src/util.h +7 -0
  146. data/vendor/libgit2/src/vector.c +16 -0
  147. data/vendor/libgit2/src/vector.h +1 -0
  148. data/vendor/libgit2/src/win32/dir.c +8 -21
  149. data/vendor/libgit2/src/win32/findfile.c +149 -0
  150. data/vendor/libgit2/src/win32/findfile.h +23 -0
  151. data/vendor/libgit2/src/win32/posix.h +3 -7
  152. data/vendor/libgit2/src/win32/posix_w32.c +44 -102
  153. data/vendor/libgit2/src/win32/pthread.c +68 -0
  154. data/vendor/libgit2/src/win32/pthread.h +7 -0
  155. data/vendor/libgit2/src/win32/utf-conv.c +60 -71
  156. data/vendor/libgit2/src/win32/utf-conv.h +4 -3
  157. metadata +70 -71
  158. data/vendor/libgit2/include/git2/windows.h +0 -59
@@ -180,9 +180,9 @@ void git_tree__free(git_tree *tree)
180
180
  git__free(tree);
181
181
  }
182
182
 
183
- const git_oid *git_tree_id(git_tree *c)
183
+ const git_oid *git_tree_id(const git_tree *c)
184
184
  {
185
- return git_object_id((git_object *)c);
185
+ return git_object_id((const git_object *)c);
186
186
  }
187
187
 
188
188
  git_filemode_t git_tree_entry_filemode(const git_tree_entry *entry)
@@ -286,7 +286,7 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
286
286
  return at_pos;
287
287
  }
288
288
 
289
- unsigned int git_tree_entrycount(git_tree *tree)
289
+ unsigned int git_tree_entrycount(const git_tree *tree)
290
290
  {
291
291
  assert(tree);
292
292
  return (unsigned int)tree->entries.length;
@@ -31,6 +31,8 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
31
31
  mflag = MAP_SHARED;
32
32
  else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE)
33
33
  mflag = MAP_PRIVATE;
34
+ else
35
+ mflag = MAP_SHARED;
34
36
 
35
37
  out->data = mmap(NULL, len, mprot, mflag, fd, offset);
36
38
 
@@ -7,19 +7,12 @@
7
7
  #ifndef INCLUDE_posix__w32_h__
8
8
  #define INCLUDE_posix__w32_h__
9
9
 
10
- #if !defined(__sun) && !defined(__amigaos4__)
11
- # include <fnmatch.h>
12
- # define p_fnmatch(p, s, f) fnmatch(p, s, f)
13
- #else
14
- # include "compat/fnmatch.h"
15
- #endif
16
-
17
10
  #include <stdio.h>
18
11
 
19
12
  #define p_lstat(p,b) lstat(p,b)
20
13
  #define p_readlink(a, b, c) readlink(a, b, c)
14
+ #define p_symlink(o,n) symlink(o, n)
21
15
  #define p_link(o,n) link(o, n)
22
- #define p_symlink(o,n) symlink(o,n)
23
16
  #define p_unlink(p) unlink(p)
24
17
  #define p_mkdir(p,m) mkdir(p, m)
25
18
  #define p_fsync(fd) fsync(fd)
@@ -28,7 +28,7 @@ int git_libgit2_capabilities()
28
28
  #ifdef GIT_THREADS
29
29
  | GIT_CAP_THREADS
30
30
  #endif
31
- #ifdef GIT_SSL
31
+ #if defined(GIT_SSL) || defined(GIT_WINHTTP)
32
32
  | GIT_CAP_HTTPS
33
33
  #endif
34
34
  ;
@@ -199,6 +199,11 @@ int git__prefixcmp(const char *str, const char *prefix)
199
199
  }
200
200
  }
201
201
 
202
+ int git__prefixcmp_icase(const char *str, const char *prefix)
203
+ {
204
+ return strncasecmp(str, prefix, strlen(prefix));
205
+ }
206
+
202
207
  int git__suffixcmp(const char *str, const char *suffix)
203
208
  {
204
209
  size_t a = strlen(str);
@@ -70,7 +70,14 @@ GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
70
70
 
71
71
  #define git__free(ptr) free(ptr)
72
72
 
73
+ #define STRCMP_CASESELECT(IGNORE_CASE, STR1, STR2) \
74
+ ((IGNORE_CASE) ? strcasecmp((STR1), (STR2)) : strcmp((STR1), (STR2)))
75
+
76
+ #define CASESELECT(IGNORE_CASE, ICASE, CASE) \
77
+ ((IGNORE_CASE) ? (ICASE) : (CASE))
78
+
73
79
  extern int git__prefixcmp(const char *str, const char *prefix);
80
+ extern int git__prefixcmp_icase(const char *str, const char *prefix);
74
81
  extern int git__suffixcmp(const char *str, const char *suffix);
75
82
 
76
83
  extern int git__strtol32(int32_t *n, const char *buff, const char **end_buf, int base);
@@ -24,6 +24,22 @@ static int resize_vector(git_vector *v)
24
24
  return 0;
25
25
  }
26
26
 
27
+ int git_vector_dup(git_vector *v, git_vector *src, git_vector_cmp cmp)
28
+ {
29
+ assert(v && src);
30
+
31
+ v->_alloc_size = src->length;
32
+ v->_cmp = cmp;
33
+ v->length = src->length;
34
+ v->sorted = src->sorted && cmp == src->_cmp;
35
+ v->contents = git__malloc(src->length * sizeof(void *));
36
+ GITERR_CHECK_ALLOC(v->contents);
37
+
38
+ memcpy(v->contents, src->contents, src->length * sizeof(void *));
39
+
40
+ return 0;
41
+ }
42
+
27
43
  void git_vector_free(git_vector *v)
28
44
  {
29
45
  assert(v);
@@ -24,6 +24,7 @@ typedef struct git_vector {
24
24
  int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp);
25
25
  void git_vector_free(git_vector *v);
26
26
  void git_vector_clear(git_vector *v);
27
+ int git_vector_dup(git_vector *v, git_vector *src, git_vector_cmp cmp);
27
28
  void git_vector_swap(git_vector *a, git_vector *b);
28
29
 
29
30
  void git_vector_sort(git_vector *v);
@@ -7,7 +7,6 @@
7
7
  #define GIT__WIN32_NO_WRAP_DIR
8
8
  #include "dir.h"
9
9
  #include "utf-conv.h"
10
- #include "git2/windows.h"
11
10
 
12
11
  static int init_filter(char *filter, size_t n, const char *dir)
13
12
  {
@@ -26,8 +25,8 @@ static int init_filter(char *filter, size_t n, const char *dir)
26
25
 
27
26
  git__DIR *git__opendir(const char *dir)
28
27
  {
29
- char filter[4096];
30
- wchar_t* filter_w = NULL;
28
+ char filter[GIT_WIN_PATH];
29
+ wchar_t filter_w[GIT_WIN_PATH];
31
30
  git__DIR *new = NULL;
32
31
 
33
32
  if (!dir || !init_filter(filter, sizeof(filter), dir))
@@ -41,12 +40,8 @@ git__DIR *git__opendir(const char *dir)
41
40
  if (!new->dir)
42
41
  goto fail;
43
42
 
44
- filter_w = gitwin_to_utf16(filter);
45
- if (!filter_w)
46
- goto fail;
47
-
43
+ git__utf8_to_16(filter_w, GIT_WIN_PATH, filter);
48
44
  new->h = FindFirstFileW(filter_w, &new->f);
49
- git__free(filter_w);
50
45
 
51
46
  if (new->h == INVALID_HANDLE_VALUE) {
52
47
  giterr_set(GITERR_OS, "Could not open directory '%s'", dir);
@@ -85,16 +80,9 @@ int git__readdir_ext(
85
80
  if (wcslen(d->f.cFileName) >= sizeof(entry->d_name))
86
81
  return -1;
87
82
 
83
+ git__utf16_to_8(entry->d_name, d->f.cFileName);
88
84
  entry->d_ino = 0;
89
85
 
90
- if (WideCharToMultiByte(
91
- gitwin_get_codepage(), 0, d->f.cFileName, -1,
92
- entry->d_name, GIT_PATH_MAX, NULL, NULL) == 0)
93
- {
94
- giterr_set(GITERR_OS, "Could not convert filename to UTF-8");
95
- return -1;
96
- }
97
-
98
86
  *result = entry;
99
87
 
100
88
  if (is_dir != NULL)
@@ -113,8 +101,8 @@ struct git__dirent *git__readdir(git__DIR *d)
113
101
 
114
102
  void git__rewinddir(git__DIR *d)
115
103
  {
116
- char filter[4096];
117
- wchar_t* filter_w;
104
+ char filter[GIT_WIN_PATH];
105
+ wchar_t filter_w[GIT_WIN_PATH];
118
106
 
119
107
  if (!d)
120
108
  return;
@@ -125,12 +113,11 @@ void git__rewinddir(git__DIR *d)
125
113
  d->first = 0;
126
114
  }
127
115
 
128
- if (!init_filter(filter, sizeof(filter), d->dir) ||
129
- (filter_w = gitwin_to_utf16(filter)) == NULL)
116
+ if (!init_filter(filter, sizeof(filter), d->dir))
130
117
  return;
131
118
 
119
+ git__utf8_to_16(filter_w, GIT_WIN_PATH, filter);
132
120
  d->h = FindFirstFileW(filter_w, &d->f);
133
- git__free(filter_w);
134
121
 
135
122
  if (d->h == INVALID_HANDLE_VALUE)
136
123
  giterr_set(GITERR_OS, "Could not open directory '%s'", d->dir);
@@ -0,0 +1,149 @@
1
+ /*
2
+ * Copyright (C) 2012 the libgit2 contributors
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "utf-conv.h"
9
+ #include "path.h"
10
+ #include "findfile.h"
11
+
12
+ #ifndef _WIN64
13
+ #define REG_MSYSGIT_INSTALL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
14
+ #else
15
+ #define REG_MSYSGIT_INSTALL L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
16
+ #endif
17
+
18
+ int win32_expand_path(struct win32_path *s_root, const wchar_t *templ)
19
+ {
20
+ s_root->len = ExpandEnvironmentStringsW(templ, s_root->path, MAX_PATH);
21
+ return s_root->len ? 0 : -1;
22
+ }
23
+
24
+ int win32_find_file(git_buf *path, const struct win32_path *root, const char *filename)
25
+ {
26
+ size_t len, alloc_len;
27
+ wchar_t *file_utf16 = NULL;
28
+ char file_utf8[GIT_PATH_MAX];
29
+
30
+ if (!root || !filename || (len = strlen(filename)) == 0)
31
+ return GIT_ENOTFOUND;
32
+
33
+ /* allocate space for wchar_t path to file */
34
+ alloc_len = root->len + len + 2;
35
+ file_utf16 = git__calloc(alloc_len, sizeof(wchar_t));
36
+ GITERR_CHECK_ALLOC(file_utf16);
37
+
38
+ /* append root + '\\' + filename as wchar_t */
39
+ memcpy(file_utf16, root->path, root->len * sizeof(wchar_t));
40
+
41
+ if (*filename == '/' || *filename == '\\')
42
+ filename++;
43
+
44
+ git__utf8_to_16(file_utf16 + root->len - 1, alloc_len, filename);
45
+
46
+ /* check access */
47
+ if (_waccess(file_utf16, F_OK) < 0) {
48
+ git__free(file_utf16);
49
+ return GIT_ENOTFOUND;
50
+ }
51
+
52
+ git__utf16_to_8(file_utf8, file_utf16);
53
+ git_path_mkposix(file_utf8);
54
+ git_buf_sets(path, file_utf8);
55
+
56
+ git__free(file_utf16);
57
+ return 0;
58
+ }
59
+
60
+ wchar_t* win32_nextpath(wchar_t *path, wchar_t *buf, size_t buflen)
61
+ {
62
+ wchar_t term, *base = path;
63
+
64
+ assert(path && buf && buflen);
65
+
66
+ term = (*path == L'"') ? *path++ : L';';
67
+
68
+ for (buflen--; *path && *path != term && buflen; buflen--)
69
+ *buf++ = *path++;
70
+
71
+ *buf = L'\0'; /* reserved a byte via initial subtract */
72
+
73
+ while (*path == term || *path == L';')
74
+ path++;
75
+
76
+ return (path != base) ? path : NULL;
77
+ }
78
+
79
+ int win32_find_system_file_using_path(git_buf *path, const char *filename)
80
+ {
81
+ wchar_t * env = NULL;
82
+ struct win32_path root;
83
+
84
+ env = _wgetenv(L"PATH");
85
+ if (!env)
86
+ return -1;
87
+
88
+ // search in all paths defined in PATH
89
+ while ((env = win32_nextpath(env, root.path, MAX_PATH - 1)) != NULL && *root.path)
90
+ {
91
+ wchar_t * pfin = root.path + wcslen(root.path) - 1; // last char of the current path entry
92
+
93
+ // ensure trailing slash
94
+ if (*pfin != L'/' && *pfin != L'\\')
95
+ wcscpy(++pfin, L"\\"); // we have enough space left, MAX_PATH - 1 is used in nextpath above
96
+
97
+ root.len = (DWORD)wcslen(root.path) + 1;
98
+
99
+ if (win32_find_file(path, &root, "git.cmd") == 0 || win32_find_file(path, &root, "git.exe") == 0) {
100
+ // we found the cmd or bin directory of a git installaton
101
+ if (root.len > 5) {
102
+ wcscpy(root.path + wcslen(root.path) - 4, L"etc\\");
103
+ if (win32_find_file(path, &root, filename) == 0)
104
+ return 0;
105
+ }
106
+ }
107
+ }
108
+
109
+ return GIT_ENOTFOUND;
110
+ }
111
+
112
+ int win32_find_system_file_using_registry(git_buf *path, const char *filename)
113
+ {
114
+ struct win32_path root;
115
+
116
+ HKEY hKey;
117
+ DWORD dwType = REG_SZ;
118
+ DWORD dwSize = MAX_PATH;
119
+
120
+ root.len = 0;
121
+ if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
122
+ {
123
+ if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType,(LPBYTE)&root.path, &dwSize) == ERROR_SUCCESS)
124
+ {
125
+ // InstallLocation points to the root of the msysgit directory
126
+ if (dwSize + 4 > MAX_PATH) // 4 = wcslen(L"etc\\")
127
+ {
128
+ giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory - path too long");
129
+ return -1;
130
+ }
131
+ wcscat(root.path, L"etc\\");
132
+ root.len = (DWORD)wcslen(root.path) + 1;
133
+ }
134
+ }
135
+ RegCloseKey(hKey);
136
+
137
+ if (!root.len) {
138
+ giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory");
139
+ return -1;
140
+ }
141
+
142
+ if (win32_find_file(path, &root, filename) < 0) {
143
+ giterr_set(GITERR_OS, "The system file '%s' doesn't exist", filename);
144
+ git_buf_clear(path);
145
+ return GIT_ENOTFOUND;
146
+ }
147
+
148
+ return 0;
149
+ }
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (C) 2012 the libgit2 contributors
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #ifndef INCLUDE_git_findfile_h__
9
+ #define INCLUDE_git_findfile_h__
10
+
11
+ struct win32_path {
12
+ wchar_t path[MAX_PATH];
13
+ DWORD len;
14
+ };
15
+
16
+ int win32_expand_path(struct win32_path *s_root, const wchar_t *templ);
17
+
18
+ int win32_find_file(git_buf *path, const struct win32_path *root, const char *filename);
19
+ int win32_find_system_file_using_path(git_buf *path, const char *filename);
20
+ int win32_find_system_file_using_registry(git_buf *path, const char *filename);
21
+
22
+ #endif
23
+
@@ -8,7 +8,6 @@
8
8
  #define INCLUDE_posix__w32_h__
9
9
 
10
10
  #include "common.h"
11
- #include "compat/fnmatch.h"
12
11
  #include "utf-conv.h"
13
12
 
14
13
  GIT_INLINE(int) p_link(const char *old, const char *new)
@@ -21,13 +20,10 @@ GIT_INLINE(int) p_link(const char *old, const char *new)
21
20
 
22
21
  GIT_INLINE(int) p_mkdir(const char *path, mode_t mode)
23
22
  {
24
- wchar_t* buf = gitwin_to_utf16(path);
25
- int ret = _wmkdir(buf);
26
-
23
+ wchar_t buf[GIT_WIN_PATH];
27
24
  GIT_UNUSED(mode);
28
-
29
- git__free(buf);
30
- return ret;
25
+ git__utf8_to_16(buf, GIT_WIN_PATH, path);
26
+ return _wmkdir(buf);
31
27
  }
32
28
 
33
29
  extern int p_unlink(const char *path);
@@ -15,16 +15,10 @@
15
15
 
16
16
  int p_unlink(const char *path)
17
17
  {
18
- int ret = 0;
19
- wchar_t* buf;
20
-
21
- if ((buf = gitwin_to_utf16(path)) != NULL) {
22
- _wchmod(buf, 0666);
23
- ret = _wunlink(buf);
24
- git__free(buf);
25
- }
26
-
27
- return ret;
18
+ wchar_t buf[GIT_WIN_PATH];
19
+ git__utf8_to_16(buf, GIT_WIN_PATH, path);
20
+ _wchmod(buf, 0666);
21
+ return _wunlink(buf);
28
22
  }
29
23
 
30
24
  int p_fsync(int fd)
@@ -61,10 +55,10 @@ GIT_INLINE(time_t) filetime_to_time_t(const FILETIME *ft)
61
55
  static int do_lstat(const char *file_name, struct stat *buf)
62
56
  {
63
57
  WIN32_FILE_ATTRIBUTE_DATA fdata;
58
+ wchar_t fbuf[GIT_WIN_PATH];
64
59
  DWORD last_error;
65
- wchar_t* fbuf = gitwin_to_utf16(file_name);
66
- if (!fbuf)
67
- return -1;
60
+
61
+ git__utf8_to_16(fbuf, GIT_WIN_PATH, file_name);
68
62
 
69
63
  if (GetFileAttributesExW(fbuf, GetFileExInfoStandard, &fdata)) {
70
64
  int fMode = S_IREAD;
@@ -90,8 +84,6 @@ static int do_lstat(const char *file_name, struct stat *buf)
90
84
  buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime));
91
85
  buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime));
92
86
  buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime));
93
-
94
- git__free(fbuf);
95
87
  return 0;
96
88
  }
97
89
 
@@ -101,7 +93,6 @@ static int do_lstat(const char *file_name, struct stat *buf)
101
93
  else if (last_error == ERROR_PATH_NOT_FOUND)
102
94
  errno = ENOTDIR;
103
95
 
104
- git__free(fbuf);
105
96
  return -1;
106
97
  }
107
98
 
@@ -143,7 +134,7 @@ int p_readlink(const char *link, char *target, size_t target_len)
143
134
  static fpath_func pGetFinalPath = NULL;
144
135
  HANDLE hFile;
145
136
  DWORD dwRet;
146
- wchar_t* link_w;
137
+ wchar_t link_w[GIT_WIN_PATH];
147
138
  wchar_t* target_w;
148
139
  int error = 0;
149
140
 
@@ -166,8 +157,7 @@ int p_readlink(const char *link, char *target, size_t target_len)
166
157
  }
167
158
  }
168
159
 
169
- link_w = gitwin_to_utf16(link);
170
- GITERR_CHECK_ALLOC(link_w);
160
+ git__utf8_to_16(link_w, GIT_WIN_PATH, link);
171
161
 
172
162
  hFile = CreateFileW(link_w, // file to open
173
163
  GENERIC_READ, // open for reading
@@ -177,8 +167,6 @@ int p_readlink(const char *link, char *target, size_t target_len)
177
167
  FILE_FLAG_BACKUP_SEMANTICS, // normal file
178
168
  NULL); // no attr. template
179
169
 
180
- git__free(link_w);
181
-
182
170
  if (hFile == INVALID_HANDLE_VALUE) {
183
171
  giterr_set(GITERR_OS, "Cannot open '%s' for reading", link);
184
172
  return -1;
@@ -235,16 +223,12 @@ int p_symlink(const char *old, const char *new)
235
223
 
236
224
  int p_open(const char *path, int flags, ...)
237
225
  {
238
- int fd;
239
- wchar_t* buf;
226
+ wchar_t buf[GIT_WIN_PATH];
240
227
  mode_t mode = 0;
241
228
 
242
- buf = gitwin_to_utf16(path);
243
- if (!buf)
244
- return -1;
229
+ git__utf8_to_16(buf, GIT_WIN_PATH, path);
245
230
 
246
- if (flags & O_CREAT)
247
- {
231
+ if (flags & O_CREAT) {
248
232
  va_list arg_list;
249
233
 
250
234
  va_start(arg_list, flags);
@@ -252,27 +236,20 @@ int p_open(const char *path, int flags, ...)
252
236
  va_end(arg_list);
253
237
  }
254
238
 
255
- fd = _wopen(buf, flags | _O_BINARY, mode);
256
-
257
- git__free(buf);
258
- return fd;
239
+ return _wopen(buf, flags | _O_BINARY, mode);
259
240
  }
260
241
 
261
242
  int p_creat(const char *path, mode_t mode)
262
243
  {
263
- int fd;
264
- wchar_t* buf = gitwin_to_utf16(path);
265
- if (!buf)
266
- return -1;
267
- fd = _wopen(buf, _O_WRONLY | _O_CREAT | _O_TRUNC | _O_BINARY, mode);
268
- git__free(buf);
269
- return fd;
244
+ wchar_t buf[GIT_WIN_PATH];
245
+ git__utf8_to_16(buf, GIT_WIN_PATH, path);
246
+ return _wopen(buf, _O_WRONLY | _O_CREAT | _O_TRUNC | _O_BINARY, mode);
270
247
  }
271
248
 
272
249
  int p_getcwd(char *buffer_out, size_t size)
273
250
  {
274
251
  int ret;
275
- wchar_t* buf;
252
+ wchar_t *buf;
276
253
 
277
254
  if ((size_t)((int)size) != size)
278
255
  return -1;
@@ -296,64 +273,43 @@ int p_stat(const char* path, struct stat* buf)
296
273
 
297
274
  int p_chdir(const char* path)
298
275
  {
299
- wchar_t* buf = gitwin_to_utf16(path);
300
- int ret;
301
- if (!buf)
302
- return -1;
303
- ret = _wchdir(buf);
304
- git__free(buf);
305
- return ret;
276
+ wchar_t buf[GIT_WIN_PATH];
277
+ git__utf8_to_16(buf, GIT_WIN_PATH, path);
278
+ return _wchdir(buf);
306
279
  }
307
280
 
308
281
  int p_chmod(const char* path, mode_t mode)
309
282
  {
310
- wchar_t* buf = gitwin_to_utf16(path);
311
- int ret;
312
- if (!buf)
313
- return -1;
314
- ret = _wchmod(buf, mode);
315
- git__free(buf);
316
- return ret;
283
+ wchar_t buf[GIT_WIN_PATH];
284
+ git__utf8_to_16(buf, GIT_WIN_PATH, path);
285
+ return _wchmod(buf, mode);
317
286
  }
318
287
 
319
288
  int p_rmdir(const char* path)
320
289
  {
321
- wchar_t* buf = gitwin_to_utf16(path);
322
- int ret;
323
- if (!buf)
324
- return -1;
325
- ret = _wrmdir(buf);
326
- git__free(buf);
327
- return ret;
290
+ wchar_t buf[GIT_WIN_PATH];
291
+ git__utf8_to_16(buf, GIT_WIN_PATH, path);
292
+ return _wrmdir(buf);
328
293
  }
329
294
 
330
295
  int p_hide_directory__w32(const char *path)
331
296
  {
332
- int res;
333
- wchar_t* buf = gitwin_to_utf16(path);
334
- if (!buf)
335
- return -1;
336
-
337
- res = SetFileAttributesW(buf, FILE_ATTRIBUTE_HIDDEN);
338
- git__free(buf);
339
-
340
- return (res != 0) ? 0 : -1; /* MSDN states a "non zero" value indicates a success */
297
+ wchar_t buf[GIT_WIN_PATH];
298
+ git__utf8_to_16(buf, GIT_WIN_PATH, path);
299
+ return (SetFileAttributesW(buf, FILE_ATTRIBUTE_HIDDEN) != 0) ? 0 : -1;
341
300
  }
342
301
 
343
302
  char *p_realpath(const char *orig_path, char *buffer)
344
303
  {
345
304
  int ret, buffer_sz = 0;
346
- wchar_t* orig_path_w = gitwin_to_utf16(orig_path);
347
- wchar_t* buffer_w = (wchar_t*)git__malloc(GIT_PATH_MAX * sizeof(wchar_t));
348
-
349
- if (!orig_path_w || !buffer_w)
350
- return NULL;
305
+ wchar_t orig_path_w[GIT_WIN_PATH];
306
+ wchar_t buffer_w[GIT_WIN_PATH];
351
307
 
352
- ret = GetFullPathNameW(orig_path_w, GIT_PATH_MAX, buffer_w, NULL);
353
- git__free(orig_path_w);
308
+ git__utf8_to_16(orig_path_w, GIT_WIN_PATH, orig_path);
309
+ ret = GetFullPathNameW(orig_path_w, GIT_WIN_PATH, buffer_w, NULL);
354
310
 
355
311
  /* According to MSDN, a return value equals to zero means a failure. */
356
- if (ret == 0 || ret > GIT_PATH_MAX) {
312
+ if (ret == 0 || ret > GIT_WIN_PATH) {
357
313
  buffer = NULL;
358
314
  goto done;
359
315
  }
@@ -376,8 +332,7 @@ char *p_realpath(const char *orig_path, char *buffer)
376
332
  }
377
333
  }
378
334
 
379
- if (!git_path_exists(buffer))
380
- {
335
+ if (!git_path_exists(buffer)) {
381
336
  if (buffer_sz > 0)
382
337
  git__free(buffer);
383
338
 
@@ -386,9 +341,9 @@ char *p_realpath(const char *orig_path, char *buffer)
386
341
  }
387
342
 
388
343
  done:
389
- git__free(buffer_w);
390
344
  if (buffer)
391
345
  git_path_mkposix(buffer);
346
+
392
347
  return buffer;
393
348
  }
394
349
 
@@ -443,32 +398,19 @@ int p_setenv(const char* name, const char* value, int overwrite)
443
398
 
444
399
  int p_access(const char* path, mode_t mode)
445
400
  {
446
- wchar_t *buf = gitwin_to_utf16(path);
447
- int ret;
448
- if (!buf)
449
- return -1;
450
-
451
- ret = _waccess(buf, mode);
452
- git__free(buf);
453
-
454
- return ret;
401
+ wchar_t buf[GIT_WIN_PATH];
402
+ git__utf8_to_16(buf, GIT_WIN_PATH, path);
403
+ return _waccess(buf, mode);
455
404
  }
456
405
 
457
406
  int p_rename(const char *from, const char *to)
458
407
  {
459
- wchar_t *wfrom = gitwin_to_utf16(from);
460
- wchar_t *wto = gitwin_to_utf16(to);
461
- int ret;
462
-
463
- if (!wfrom || !wto)
464
- return -1;
465
-
466
- ret = MoveFileExW(wfrom, wto, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) ? 0 : -1;
467
-
468
- git__free(wfrom);
469
- git__free(wto);
408
+ wchar_t wfrom[GIT_WIN_PATH];
409
+ wchar_t wto[GIT_WIN_PATH];
470
410
 
471
- return ret;
411
+ git__utf8_to_16(wfrom, GIT_WIN_PATH, from);
412
+ git__utf8_to_16(wto, GIT_WIN_PATH, to);
413
+ return MoveFileExW(wfrom, wto, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) ? 0 : -1;
472
414
  }
473
415
 
474
416
  int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags)