rugged 0.23.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_remote.c +1 -8
  3. data/ext/rugged/rugged_submodule_collection.c +3 -3
  4. data/lib/rugged/version.rb +1 -1
  5. data/vendor/libgit2/CMakeLists.txt +3 -1
  6. data/vendor/libgit2/include/git2/diff.h +19 -0
  7. data/vendor/libgit2/include/git2/errors.h +1 -12
  8. data/vendor/libgit2/include/git2/remote.h +9 -1
  9. data/vendor/libgit2/include/git2/repository.h +1 -1
  10. data/vendor/libgit2/include/git2/sys/config.h +1 -1
  11. data/vendor/libgit2/include/git2/sys/diff.h +4 -4
  12. data/vendor/libgit2/include/git2/sys/filter.h +4 -1
  13. data/vendor/libgit2/include/git2/sys/odb_backend.h +1 -1
  14. data/vendor/libgit2/include/git2/sys/refdb_backend.h +4 -3
  15. data/vendor/libgit2/include/git2/transport.h +14 -21
  16. data/vendor/libgit2/src/blame_git.c +10 -15
  17. data/vendor/libgit2/src/blob.c +6 -0
  18. data/vendor/libgit2/src/branch.c +1 -12
  19. data/vendor/libgit2/src/cache.c +4 -4
  20. data/vendor/libgit2/src/checkout.c +2 -2
  21. data/vendor/libgit2/src/clone.c +2 -2
  22. data/vendor/libgit2/src/common.h +13 -4
  23. data/vendor/libgit2/src/curl_stream.c +7 -7
  24. data/vendor/libgit2/src/describe.c +1 -1
  25. data/vendor/libgit2/src/diff.c +25 -0
  26. data/vendor/libgit2/src/errors.c +75 -40
  27. data/vendor/libgit2/src/filebuf.c +6 -1
  28. data/vendor/libgit2/src/filebuf.h +2 -0
  29. data/vendor/libgit2/src/filter.c +14 -9
  30. data/vendor/libgit2/src/global.c +25 -9
  31. data/vendor/libgit2/src/global.h +1 -0
  32. data/vendor/libgit2/src/index.c +75 -2
  33. data/vendor/libgit2/src/indexer.c +1 -1
  34. data/vendor/libgit2/src/iterator.c +6 -3
  35. data/vendor/libgit2/src/khash.h +1 -1
  36. data/vendor/libgit2/src/merge.c +3 -3
  37. data/vendor/libgit2/src/openssl_stream.c +5 -2
  38. data/vendor/libgit2/src/pack-objects.c +1 -1
  39. data/vendor/libgit2/src/pack.c +2 -2
  40. data/vendor/libgit2/src/path.c +25 -4
  41. data/vendor/libgit2/src/path.h +6 -1
  42. data/vendor/libgit2/src/push.h +3 -1
  43. data/vendor/libgit2/src/rebase.c +2 -2
  44. data/vendor/libgit2/src/refdb_fs.c +7 -0
  45. data/vendor/libgit2/src/remote.c +18 -9
  46. data/vendor/libgit2/src/revwalk.c +1 -1
  47. data/vendor/libgit2/src/stash.c +1 -1
  48. data/vendor/libgit2/src/stransport_stream.c +1 -1
  49. data/vendor/libgit2/src/submodule.c +12 -1
  50. data/vendor/libgit2/src/sysdir.c +22 -8
  51. data/vendor/libgit2/src/thread-utils.c +2 -0
  52. data/vendor/libgit2/src/transports/git.c +2 -0
  53. data/vendor/libgit2/src/transports/http.c +2 -2
  54. data/vendor/libgit2/src/transports/smart_pkt.c +1 -1
  55. data/vendor/libgit2/src/transports/ssh.c +4 -2
  56. data/vendor/libgit2/src/transports/winhttp.c +1 -1
  57. data/vendor/libgit2/src/util.c +48 -0
  58. data/vendor/libgit2/src/util.h +13 -5
  59. data/vendor/libgit2/src/win32/posix_w32.c +2 -0
  60. data/vendor/libgit2/src/win32/{buffer.c → w32_buffer.c} +1 -2
  61. data/vendor/libgit2/src/win32/{buffer.h → w32_buffer.h} +0 -0
  62. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +343 -0
  63. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +93 -0
  64. data/vendor/libgit2/src/win32/w32_stack.c +192 -0
  65. data/vendor/libgit2/src/win32/w32_stack.h +138 -0
  66. data/vendor/libgit2/src/xdiff/xdiff.h +10 -6
  67. data/vendor/libgit2/src/xdiff/xdiffi.c +46 -4
  68. data/vendor/libgit2/src/xdiff/xdiffi.h +1 -0
  69. data/vendor/libgit2/src/xdiff/xemit.c +43 -6
  70. data/vendor/libgit2/src/xdiff/xemit.h +1 -1
  71. data/vendor/libgit2/src/xdiff/xhistogram.c +1 -1
  72. data/vendor/libgit2/src/xdiff/xmerge.c +2 -2
  73. data/vendor/libgit2/src/xdiff/xpatience.c +1 -1
  74. data/vendor/libgit2/src/xdiff/xprepare.c +10 -11
  75. data/vendor/libgit2/src/xdiff/xutils.c +13 -29
  76. data/vendor/libgit2/src/xdiff/xutils.h +1 -0
  77. metadata +84 -80
@@ -46,6 +46,10 @@
46
46
  # ifdef GIT_THREADS
47
47
  # include "win32/pthread.h"
48
48
  # endif
49
+ # if defined(GIT_MSVC_CRTDBG)
50
+ # include "win32/w32_stack.h"
51
+ # include "win32/w32_crtdbg_stacktrace.h"
52
+ # endif
49
53
 
50
54
  #else
51
55
 
@@ -137,20 +141,25 @@ void giterr_system_set(int code);
137
141
  * Structure to preserve libgit2 error state
138
142
  */
139
143
  typedef struct {
140
- int error_code;
144
+ int error_code;
145
+ unsigned int oom : 1;
141
146
  git_error error_msg;
142
147
  } git_error_state;
143
148
 
144
149
  /**
145
150
  * Capture current error state to restore later, returning error code.
146
- * If `error_code` is zero, this does nothing and returns zero.
151
+ * If `error_code` is zero, this does not clear the current error state.
152
+ * You must either restore this error state, or free it.
147
153
  */
148
- int giterr_capture(git_error_state *state, int error_code);
154
+ extern int giterr_state_capture(git_error_state *state, int error_code);
149
155
 
150
156
  /**
151
157
  * Restore error state to a previous value, returning saved error code.
152
158
  */
153
- int giterr_restore(git_error_state *state);
159
+ extern int giterr_state_restore(git_error_state *state);
160
+
161
+ /** Free an error state. */
162
+ extern void giterr_state_free(git_error_state *state);
154
163
 
155
164
  /**
156
165
  * Check a versioned structure for validity
@@ -67,9 +67,9 @@ static int curls_certificate(git_cert **out, git_stream *stream)
67
67
 
68
68
  /* No information is available, can happen with SecureTransport */
69
69
  if (certinfo->num_of_certs == 0) {
70
- s->cert_info.cert_type = GIT_CERT_NONE;
71
- s->cert_info.data = NULL;
72
- s->cert_info.len = 0;
70
+ s->cert_info.parent.cert_type = GIT_CERT_NONE;
71
+ s->cert_info.data = NULL;
72
+ s->cert_info.len = 0;
73
73
  return 0;
74
74
  }
75
75
 
@@ -85,11 +85,11 @@ static int curls_certificate(git_cert **out, git_stream *stream)
85
85
  s->cert_info_strings.strings = (char **) strings.contents;
86
86
  s->cert_info_strings.count = strings.length;
87
87
 
88
- s->cert_info.cert_type = GIT_CERT_STRARRAY;
89
- s->cert_info.data = &s->cert_info_strings;
90
- s->cert_info.len = strings.length;
88
+ s->cert_info.parent.cert_type = GIT_CERT_STRARRAY;
89
+ s->cert_info.data = &s->cert_info_strings;
90
+ s->cert_info.len = strings.length;
91
91
 
92
- *out = (git_cert *) &s->cert_info;
92
+ *out = &s->cert_info.parent;
93
93
 
94
94
  return 0;
95
95
  }
@@ -19,7 +19,7 @@
19
19
  #include "vector.h"
20
20
  #include "repository.h"
21
21
 
22
- GIT__USE_OIDMAP;
22
+ GIT__USE_OIDMAP
23
23
 
24
24
  /* Ported from https://github.com/git/git/blob/89dde7882f71f846ccd0359756d27bebc31108de/builtin/describe.c */
25
25
 
@@ -1421,6 +1421,31 @@ int git_diff_tree_to_workdir_with_index(
1421
1421
  return error;
1422
1422
  }
1423
1423
 
1424
+ int git_diff_index_to_index(
1425
+ git_diff **diff,
1426
+ git_repository *repo,
1427
+ git_index *old_index,
1428
+ git_index *new_index,
1429
+ const git_diff_options *opts)
1430
+ {
1431
+ int error = 0;
1432
+
1433
+ assert(diff && old_index && new_index);
1434
+
1435
+ DIFF_FROM_ITERATORS(
1436
+ git_iterator_for_index(
1437
+ &a, old_index, GIT_ITERATOR_DONT_IGNORE_CASE, pfx, pfx),
1438
+ git_iterator_for_index(
1439
+ &b, new_index, GIT_ITERATOR_DONT_IGNORE_CASE, pfx, pfx)
1440
+ );
1441
+
1442
+ /* if index is in case-insensitive order, re-sort deltas to match */
1443
+ if (!error && (old_index->ignore_case || new_index->ignore_case))
1444
+ diff_set_ignore_case(*diff, true);
1445
+
1446
+ return error;
1447
+ }
1448
+
1424
1449
  size_t git_diff_num_deltas(const git_diff *diff)
1425
1450
  {
1426
1451
  assert(diff);
@@ -18,19 +18,30 @@ static git_error g_git_oom_error = {
18
18
  GITERR_NOMEMORY
19
19
  };
20
20
 
21
- static void set_error(int error_class, char *string)
21
+ static void set_error_from_buffer(int error_class)
22
22
  {
23
23
  git_error *error = &GIT_GLOBAL->error_t;
24
+ git_buf *buf = &GIT_GLOBAL->error_buf;
24
25
 
25
- if (error->message != string)
26
- git__free(error->message);
27
-
28
- error->message = string;
26
+ error->message = buf->ptr;
29
27
  error->klass = error_class;
30
28
 
31
29
  GIT_GLOBAL->last_error = error;
32
30
  }
33
31
 
32
+ static void set_error(int error_class, char *string)
33
+ {
34
+ git_buf *buf = &GIT_GLOBAL->error_buf;
35
+
36
+ git_buf_clear(buf);
37
+ if (string) {
38
+ git_buf_puts(buf, string);
39
+ git__free(string);
40
+ }
41
+
42
+ set_error_from_buffer(error_class);
43
+ }
44
+
34
45
  void giterr_set_oom(void)
35
46
  {
36
47
  GIT_GLOBAL->last_error = &g_git_oom_error;
@@ -38,27 +49,28 @@ void giterr_set_oom(void)
38
49
 
39
50
  void giterr_set(int error_class, const char *string, ...)
40
51
  {
41
- git_buf buf = GIT_BUF_INIT;
42
52
  va_list arglist;
43
53
  #ifdef GIT_WIN32
44
54
  DWORD win32_error_code = (error_class == GITERR_OS) ? GetLastError() : 0;
45
55
  #endif
46
56
  int error_code = (error_class == GITERR_OS) ? errno : 0;
57
+ git_buf *buf = &GIT_GLOBAL->error_buf;
47
58
 
59
+ git_buf_clear(buf);
48
60
  if (string) {
49
61
  va_start(arglist, string);
50
- git_buf_vprintf(&buf, string, arglist);
62
+ git_buf_vprintf(buf, string, arglist);
51
63
  va_end(arglist);
52
64
 
53
65
  if (error_class == GITERR_OS)
54
- git_buf_PUTS(&buf, ": ");
66
+ git_buf_PUTS(buf, ": ");
55
67
  }
56
68
 
57
69
  if (error_class == GITERR_OS) {
58
70
  #ifdef GIT_WIN32
59
71
  char * win32_error = git_win32_get_error_message(win32_error_code);
60
72
  if (win32_error) {
61
- git_buf_puts(&buf, win32_error);
73
+ git_buf_puts(buf, win32_error);
62
74
  git__free(win32_error);
63
75
 
64
76
  SetLastError(0);
@@ -66,26 +78,29 @@ void giterr_set(int error_class, const char *string, ...)
66
78
  else
67
79
  #endif
68
80
  if (error_code)
69
- git_buf_puts(&buf, strerror(error_code));
81
+ git_buf_puts(buf, strerror(error_code));
70
82
 
71
83
  if (error_code)
72
84
  errno = 0;
73
85
  }
74
86
 
75
- if (!git_buf_oom(&buf))
76
- set_error(error_class, git_buf_detach(&buf));
87
+ if (!git_buf_oom(buf))
88
+ set_error_from_buffer(error_class);
77
89
  }
78
90
 
79
91
  void giterr_set_str(int error_class, const char *string)
80
92
  {
81
- char *message;
93
+ git_buf *buf = &GIT_GLOBAL->error_buf;
82
94
 
83
95
  assert(string);
84
96
 
85
- message = git__strdup(string);
97
+ if (!string)
98
+ return;
86
99
 
87
- if (message)
88
- set_error(error_class, message);
100
+ git_buf_clear(buf);
101
+ git_buf_puts(buf, string);
102
+ if (!git_buf_oom(buf))
103
+ set_error_from_buffer(error_class);
89
104
  }
90
105
 
91
106
  int giterr_set_regex(const regex_t *regex, int error_code)
@@ -116,45 +131,65 @@ void giterr_clear(void)
116
131
  #endif
117
132
  }
118
133
 
119
- int giterr_detach(git_error *cpy)
134
+ const git_error *giterr_last(void)
135
+ {
136
+ return GIT_GLOBAL->last_error;
137
+ }
138
+
139
+ int giterr_state_capture(git_error_state *state, int error_code)
120
140
  {
121
141
  git_error *error = GIT_GLOBAL->last_error;
142
+ git_buf *error_buf = &GIT_GLOBAL->error_buf;
122
143
 
123
- assert(cpy);
144
+ memset(state, 0, sizeof(git_error_state));
124
145
 
125
- if (!error)
126
- return -1;
146
+ if (!error_code)
147
+ return 0;
127
148
 
128
- cpy->message = error->message;
129
- cpy->klass = error->klass;
149
+ state->error_code = error_code;
150
+ state->oom = (error == &g_git_oom_error);
130
151
 
131
- error->message = NULL;
132
- giterr_clear();
152
+ if (error) {
153
+ state->error_msg.klass = error->klass;
133
154
 
134
- return 0;
135
- }
155
+ if (state->oom)
156
+ state->error_msg.message = g_git_oom_error.message;
157
+ else
158
+ state->error_msg.message = git_buf_detach(error_buf);
159
+ }
136
160
 
137
- const git_error *giterr_last(void)
138
- {
139
- return GIT_GLOBAL->last_error;
161
+ giterr_clear();
162
+ return error_code;
140
163
  }
141
164
 
142
- int giterr_capture(git_error_state *state, int error_code)
165
+ int giterr_state_restore(git_error_state *state)
143
166
  {
144
- state->error_code = error_code;
145
- if (error_code)
146
- giterr_detach(&state->error_msg);
147
- return error_code;
167
+ int ret = 0;
168
+
169
+ giterr_clear();
170
+
171
+ if (state && state->error_msg.message) {
172
+ if (state->oom)
173
+ giterr_set_oom();
174
+ else
175
+ set_error(state->error_msg.klass, state->error_msg.message);
176
+
177
+ ret = state->error_code;
178
+ memset(state, 0, sizeof(git_error_state));
179
+ }
180
+
181
+ return ret;
148
182
  }
149
183
 
150
- int giterr_restore(git_error_state *state)
184
+ void giterr_state_free(git_error_state *state)
151
185
  {
152
- if (state && state->error_code && state->error_msg.message)
153
- set_error(state->error_msg.klass, state->error_msg.message);
154
- else
155
- giterr_clear();
186
+ if (!state)
187
+ return;
188
+
189
+ if (!state->oom)
190
+ git__free(state->error_msg.message);
156
191
 
157
- return state ? state->error_code : 0;
192
+ memset(state, 0, sizeof(git_error_state));
158
193
  }
159
194
 
160
195
  int giterr_system_last(void)
@@ -101,7 +101,7 @@ void git_filebuf_cleanup(git_filebuf *file)
101
101
  if (file->fd_is_open && file->fd >= 0)
102
102
  p_close(file->fd);
103
103
 
104
- if (file->fd_is_open && file->path_lock && git_path_exists(file->path_lock))
104
+ if (file->created_lock && !file->did_rename && file->path_lock && git_path_exists(file->path_lock))
105
105
  p_unlink(file->path_lock);
106
106
 
107
107
  if (file->compute_digest) {
@@ -258,6 +258,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags, mode_t mode
258
258
  goto cleanup;
259
259
  }
260
260
  file->fd_is_open = true;
261
+ file->created_lock = true;
261
262
 
262
263
  /* No original path */
263
264
  file->path_original = NULL;
@@ -281,6 +282,8 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags, mode_t mode
281
282
  /* open the file for locking */
282
283
  if ((error = lock_file(file, flags, mode)) < 0)
283
284
  goto cleanup;
285
+
286
+ file->created_lock = true;
284
287
  }
285
288
 
286
289
  return 0;
@@ -340,6 +343,8 @@ int git_filebuf_commit(git_filebuf *file)
340
343
  goto on_error;
341
344
  }
342
345
 
346
+ file->did_rename = true;
347
+
343
348
  git_filebuf_cleanup(file);
344
349
  return 0;
345
350
 
@@ -44,6 +44,8 @@ struct git_filebuf {
44
44
  size_t buf_size, buf_pos;
45
45
  git_file fd;
46
46
  bool fd_is_open;
47
+ bool created_lock;
48
+ bool did_rename;
47
49
  bool do_not_buffer;
48
50
  int last_error;
49
51
  };
@@ -433,8 +433,11 @@ static int filter_list_check_attributes(
433
433
  want_type = git_attr_value(want);
434
434
  found_type = git_attr_value(strs[i]);
435
435
 
436
- if (want_type != found_type ||
437
- (want_type == GIT_ATTR_VALUE_T && strcmp(want, strs[i])))
436
+ if (want_type != found_type)
437
+ error = GIT_ENOTFOUND;
438
+ else if (want_type == GIT_ATTR_VALUE_T &&
439
+ strcmp(want, strs[i]) &&
440
+ strcmp(want, "*"))
438
441
  error = GIT_ENOTFOUND;
439
442
  }
440
443
 
@@ -947,18 +950,20 @@ int git_filter_list_stream_data(
947
950
  {
948
951
  git_vector filter_streams = GIT_VECTOR_INIT;
949
952
  git_writestream *stream_start;
950
- int error = 0;
953
+ int error = 0, close_error;
951
954
 
952
955
  git_buf_sanitize(data);
953
956
 
954
- if ((error = stream_list_init(
955
- &stream_start, &filter_streams, filters, target)) == 0 &&
956
- (error =
957
- stream_start->write(stream_start, data->ptr, data->size)) == 0)
958
- error = stream_start->close(stream_start);
957
+ if ((error = stream_list_init(&stream_start, &filter_streams, filters, target)) < 0)
958
+ goto out;
959
+
960
+ error = stream_start->write(stream_start, data->ptr, data->size);
959
961
 
962
+ out:
963
+ close_error = stream_start->close(stream_start);
960
964
  stream_list_free(&filter_streams);
961
- return error;
965
+ /* propagate the stream init or write error */
966
+ return error < 0 ? error : close_error;
962
967
  }
963
968
 
964
969
  int git_filter_list_stream_blob(
@@ -11,7 +11,10 @@
11
11
  #include "git2/global.h"
12
12
  #include "git2/sys/openssl.h"
13
13
  #include "thread-utils.h"
14
-
14
+ #if defined(GIT_MSVC_CRTDBG)
15
+ #include "win32/w32_stack.h"
16
+ #include "win32/w32_crtdbg_stacktrace.h"
17
+ #endif
15
18
 
16
19
  git_mutex git__mwindow_mutex;
17
20
 
@@ -225,6 +228,11 @@ int git_libgit2_init(void)
225
228
 
226
229
  /* Only do work on a 0 -> 1 transition of the refcount */
227
230
  if ((ret = git_atomic_inc(&git__n_inits)) == 1) {
231
+ #if defined(GIT_MSVC_CRTDBG)
232
+ git_win32__crtdbg_stacktrace_init();
233
+ git_win32__stack_init();
234
+ #endif
235
+
228
236
  if (synchronized_threads_init() < 0)
229
237
  ret = -1;
230
238
  }
@@ -254,9 +262,15 @@ int git_libgit2_shutdown(void)
254
262
  while (InterlockedCompareExchange(&_mutex, 1, 0)) { Sleep(0); }
255
263
 
256
264
  /* Only do work on a 1 -> 0 transition of the refcount */
257
- if ((ret = git_atomic_dec(&git__n_inits)) == 0)
265
+ if ((ret = git_atomic_dec(&git__n_inits)) == 0) {
258
266
  synchronized_threads_shutdown();
259
267
 
268
+ #if defined(GIT_MSVC_CRTDBG)
269
+ git_win32__crtdbg_stacktrace_cleanup();
270
+ git_win32__stack_cleanup();
271
+ #endif
272
+ }
273
+
260
274
  /* Exit the lock */
261
275
  InterlockedExchange(&_mutex, 0);
262
276
 
@@ -265,18 +279,19 @@ int git_libgit2_shutdown(void)
265
279
 
266
280
  git_global_st *git__global_state(void)
267
281
  {
268
- void *ptr;
282
+ git_global_st *ptr;
269
283
 
270
284
  assert(git_atomic_get(&git__n_inits) > 0);
271
285
 
272
286
  if ((ptr = TlsGetValue(_tls_index)) != NULL)
273
287
  return ptr;
274
288
 
275
- ptr = git__malloc(sizeof(git_global_st));
289
+ ptr = git__calloc(1, sizeof(git_global_st));
276
290
  if (!ptr)
277
291
  return NULL;
278
292
 
279
- memset(ptr, 0x0, sizeof(git_global_st));
293
+ git_buf_init(&ptr->error_buf, 0);
294
+
280
295
  TlsSetValue(_tls_index, ptr);
281
296
  return ptr;
282
297
  }
@@ -330,8 +345,8 @@ int git_libgit2_init(void)
330
345
  {
331
346
  int ret;
332
347
 
333
- pthread_once(&_once_init, init_once);
334
348
  ret = git_atomic_inc(&git__n_inits);
349
+ pthread_once(&_once_init, init_once);
335
350
 
336
351
  return init_error ? init_error : ret;
337
352
  }
@@ -364,18 +379,18 @@ int git_libgit2_shutdown(void)
364
379
 
365
380
  git_global_st *git__global_state(void)
366
381
  {
367
- void *ptr;
382
+ git_global_st *ptr;
368
383
 
369
384
  assert(git_atomic_get(&git__n_inits) > 0);
370
385
 
371
386
  if ((ptr = pthread_getspecific(_tls_key)) != NULL)
372
387
  return ptr;
373
388
 
374
- ptr = git__malloc(sizeof(git_global_st));
389
+ ptr = git__calloc(1, sizeof(git_global_st));
375
390
  if (!ptr)
376
391
  return NULL;
377
392
 
378
- memset(ptr, 0x0, sizeof(git_global_st));
393
+ git_buf_init(&ptr->error_buf, 0);
379
394
  pthread_setspecific(_tls_key, ptr);
380
395
  return ptr;
381
396
  }
@@ -393,6 +408,7 @@ int git_libgit2_init(void)
393
408
  ssl_inited = 1;
394
409
  }
395
410
 
411
+ git_buf_init(&__state.error_buf, 0);
396
412
  return git_atomic_inc(&git__n_inits);
397
413
  }
398
414