rugged 0.24.0b8 → 0.24.0b9

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_tree.c +7 -3
  3. data/lib/rugged/version.rb +1 -1
  4. data/vendor/libgit2/CMakeLists.txt +27 -1
  5. data/vendor/libgit2/include/git2/common.h +12 -7
  6. data/vendor/libgit2/include/git2/diff.h +24 -5
  7. data/vendor/libgit2/include/git2/merge.h +31 -13
  8. data/vendor/libgit2/include/git2/repository.h +2 -0
  9. data/vendor/libgit2/include/git2/submodule.h +12 -1
  10. data/vendor/libgit2/include/git2/sys/stream.h +13 -0
  11. data/vendor/libgit2/include/git2/sys/transport.h +1 -0
  12. data/vendor/libgit2/src/annotated_commit.c +71 -18
  13. data/vendor/libgit2/src/annotated_commit.h +26 -1
  14. data/vendor/libgit2/src/checkout.c +1 -2
  15. data/vendor/libgit2/src/commit.c +25 -10
  16. data/vendor/libgit2/src/common.h +1 -0
  17. data/vendor/libgit2/src/config_file.c +5 -10
  18. data/vendor/libgit2/src/diff.c +18 -21
  19. data/vendor/libgit2/src/diff.h +0 -1
  20. data/vendor/libgit2/src/diff_file.c +25 -0
  21. data/vendor/libgit2/src/filebuf.c +6 -0
  22. data/vendor/libgit2/src/fileops.c +54 -29
  23. data/vendor/libgit2/src/fileops.h +3 -2
  24. data/vendor/libgit2/src/global.c +5 -0
  25. data/vendor/libgit2/src/global.h +2 -0
  26. data/vendor/libgit2/src/index.c +105 -58
  27. data/vendor/libgit2/src/index.h +39 -0
  28. data/vendor/libgit2/src/merge.c +303 -104
  29. data/vendor/libgit2/src/merge.h +2 -2
  30. data/vendor/libgit2/src/object.c +0 -2
  31. data/vendor/libgit2/src/pool.c +16 -8
  32. data/vendor/libgit2/src/refdb_fs.c +15 -5
  33. data/vendor/libgit2/src/refs.h +5 -0
  34. data/vendor/libgit2/src/repository.c +10 -3
  35. data/vendor/libgit2/src/reset.c +6 -6
  36. data/vendor/libgit2/src/settings.c +31 -3
  37. data/vendor/libgit2/src/stream.h +3 -0
  38. data/vendor/libgit2/src/submodule.c +19 -25
  39. data/vendor/libgit2/src/tls_stream.c +13 -0
  40. data/vendor/libgit2/src/transports/http.c +12 -1
  41. data/vendor/libgit2/src/transports/winhttp.c +34 -2
  42. data/vendor/libgit2/src/tree.c +75 -21
  43. data/vendor/libgit2/src/tree.h +5 -2
  44. data/vendor/libgit2/src/win32/mingw-compat.h +0 -6
  45. data/vendor/libgit2/src/win32/msvc-compat.h +0 -3
  46. data/vendor/libgit2/src/win32/w32_util.h +14 -8
  47. data/vendor/libgit2/src/win32/win32-compat.h +42 -0
  48. metadata +3 -2
@@ -19,8 +19,8 @@
19
19
  #define GIT_MERGE_MODE_FILE "MERGE_MODE"
20
20
  #define GIT_MERGE_FILE_MODE 0666
21
21
 
22
- #define GIT_MERGE_TREE_RENAME_THRESHOLD 50
23
- #define GIT_MERGE_TREE_TARGET_LIMIT 1000
22
+ #define GIT_MERGE_DEFAULT_RENAME_THRESHOLD 50
23
+ #define GIT_MERGE_DEFAULT_TARGET_LIMIT 1000
24
24
 
25
25
  /** Types of changes when files are merged from branch to branch. */
26
26
  typedef enum {
@@ -14,8 +14,6 @@
14
14
  #include "blob.h"
15
15
  #include "tag.h"
16
16
 
17
- static const int OBJECT_BASE_SIZE = 4096;
18
-
19
17
  typedef struct {
20
18
  const char *str; /* type name string */
21
19
  size_t size; /* size in bytes of the object structure */
@@ -8,7 +8,7 @@ struct git_pool_page {
8
8
  git_pool_page *next;
9
9
  uint32_t size;
10
10
  uint32_t avail;
11
- char data[GIT_FLEX_ARRAY];
11
+ GIT_ALIGN(char data[GIT_FLEX_ARRAY], 8);
12
12
  };
13
13
 
14
14
  static void *pool_alloc_page(git_pool *pool, uint32_t size);
@@ -30,11 +30,8 @@ uint32_t git_pool__system_page_size(void)
30
30
 
31
31
  void git_pool_init(git_pool *pool, uint32_t item_size)
32
32
  {
33
- const uint32_t align_size = sizeof(void *) - 1;
34
33
  assert(pool);
35
-
36
- if (item_size > 1)
37
- item_size = (item_size + align_size) & ~align_size;
34
+ assert(item_size >= 1);
38
35
 
39
36
  memset(pool, 0, sizeof(git_pool));
40
37
  pool->item_size = item_size;
@@ -98,15 +95,26 @@ static void *pool_alloc(git_pool *pool, uint32_t size)
98
95
  return ptr;
99
96
  }
100
97
 
98
+ static uint32_t alloc_size(git_pool *pool, uint32_t count)
99
+ {
100
+ const uint32_t align = sizeof(void *) - 1;
101
+
102
+ if (pool->item_size > 1) {
103
+ const uint32_t item_size = (pool->item_size + align) & ~align;
104
+ return item_size * count;
105
+ }
106
+
107
+ return (count + align) & ~align;
108
+ }
109
+
101
110
  void *git_pool_malloc(git_pool *pool, uint32_t items)
102
111
  {
103
- const uint32_t size = items * pool->item_size;
104
- return pool_alloc(pool, size);
112
+ return pool_alloc(pool, alloc_size(pool, items));
105
113
  }
106
114
 
107
115
  void *git_pool_mallocz(git_pool *pool, uint32_t items)
108
116
  {
109
- const uint32_t size = items * pool->item_size;
117
+ const uint32_t size = alloc_size(pool, items);
110
118
  void *ptr = pool_alloc(pool, size);
111
119
  if (ptr)
112
120
  memset(ptr, 0x0, size);
@@ -733,8 +733,11 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
733
733
 
734
734
  error = git_filebuf_open(file, ref_path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE);
735
735
 
736
+ if (error == GIT_EDIRECTORY)
737
+ giterr_set(GITERR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
738
+
736
739
  git_buf_free(&ref_path);
737
- return error;
740
+ return error;
738
741
  }
739
742
 
740
743
  static int loose_commit(git_filebuf *file, const git_reference *ref)
@@ -1785,10 +1788,17 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1785
1788
  /* If the new branch matches part of the namespace of a previously deleted branch,
1786
1789
  * there maybe an obsolete/unused directory (or directory hierarchy) in the way.
1787
1790
  */
1788
- if (git_path_isdir(git_buf_cstr(&path)) &&
1789
- (git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
1790
- error = -1;
1791
- goto cleanup;
1791
+ if (git_path_isdir(git_buf_cstr(&path))) {
1792
+ if ((git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0))
1793
+ error = -1;
1794
+ else if (git_path_isdir(git_buf_cstr(&path))) {
1795
+ giterr_set(GITERR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder",
1796
+ ref->name);
1797
+ error = GIT_EDIRECTORY;
1798
+ }
1799
+
1800
+ if (error != 0)
1801
+ goto cleanup;
1792
1802
  }
1793
1803
 
1794
1804
  error = git_futils_writebuffer(&buf, git_buf_cstr(&path), O_WRONLY|O_CREAT|O_APPEND, GIT_REFLOG_FILE_MODE);
@@ -44,6 +44,11 @@
44
44
  #define GIT_REBASE_APPLY_APPLYING_FILE GIT_REBASE_APPLY_DIR "applying"
45
45
  #define GIT_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master"
46
46
 
47
+ #define GIT_SEQUENCER_DIR "sequencer/"
48
+ #define GIT_SEQUENCER_HEAD_FILE GIT_SEQUENCER_DIR "head"
49
+ #define GIT_SEQUENCER_OPTIONS_FILE GIT_SEQUENCER_DIR "options"
50
+ #define GIT_SEQUENCER_TODO_FILE GIT_SEQUENCER_DIR "todo"
51
+
47
52
  #define GIT_STASH_FILE "stash"
48
53
  #define GIT_REFS_STASH_FILE GIT_REFS_DIR GIT_STASH_FILE
49
54
 
@@ -2222,11 +2222,17 @@ int git_repository_state(git_repository *repo)
2222
2222
  state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE;
2223
2223
  else if (git_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
2224
2224
  state = GIT_REPOSITORY_STATE_MERGE;
2225
- else if(git_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE))
2225
+ else if (git_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
2226
2226
  state = GIT_REPOSITORY_STATE_REVERT;
2227
- else if(git_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE))
2227
+ if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
2228
+ state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE;
2229
+ }
2230
+ } else if (git_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
2228
2231
  state = GIT_REPOSITORY_STATE_CHERRYPICK;
2229
- else if(git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
2232
+ if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
2233
+ state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE;
2234
+ }
2235
+ } else if (git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
2230
2236
  state = GIT_REPOSITORY_STATE_BISECT;
2231
2237
 
2232
2238
  git_buf_free(&repo_path);
@@ -2271,6 +2277,7 @@ static const char *state_files[] = {
2271
2277
  GIT_BISECT_LOG_FILE,
2272
2278
  GIT_REBASE_MERGE_DIR,
2273
2279
  GIT_REBASE_APPLY_DIR,
2280
+ GIT_SEQUENCER_DIR,
2274
2281
  };
2275
2282
 
2276
2283
  int git_repository_state_cleanup(git_repository *repo)
@@ -145,19 +145,19 @@ static int reset(
145
145
  if ((error = git_buf_printf(&log_message, "reset: moving to %s", to)) < 0)
146
146
  return error;
147
147
 
148
- /* move HEAD to the new target */
149
- if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE,
150
- git_object_id(commit), NULL, git_buf_cstr(&log_message))) < 0)
151
- goto cleanup;
152
-
153
148
  if (reset_type == GIT_RESET_HARD) {
154
- /* overwrite working directory with HEAD */
149
+ /* overwrite working directory with the new tree */
155
150
  opts.checkout_strategy = GIT_CHECKOUT_FORCE;
156
151
 
157
152
  if ((error = git_checkout_tree(repo, (git_object *)tree, &opts)) < 0)
158
153
  goto cleanup;
159
154
  }
160
155
 
156
+ /* move HEAD to the new target */
157
+ if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE,
158
+ git_object_id(commit), NULL, git_buf_cstr(&log_message))) < 0)
159
+ goto cleanup;
160
+
161
161
  if (reset_type > GIT_RESET_SOFT) {
162
162
  /* reset index to the target content */
163
163
 
@@ -33,6 +33,9 @@ int git_libgit2_features()
33
33
  #endif
34
34
  #if defined(GIT_SSH)
35
35
  | GIT_FEATURE_SSH
36
+ #endif
37
+ #if defined(GIT_USE_NSEC)
38
+ | GIT_FEATURE_NSEC
36
39
  #endif
37
40
  ;
38
41
  }
@@ -46,9 +49,18 @@ static int config_level_to_sysdir(int config_level)
46
49
  int val = -1;
47
50
 
48
51
  switch (config_level) {
49
- case GIT_CONFIG_LEVEL_SYSTEM: val = GIT_SYSDIR_SYSTEM; break;
50
- case GIT_CONFIG_LEVEL_XDG: val = GIT_SYSDIR_XDG; break;
51
- case GIT_CONFIG_LEVEL_GLOBAL: val = GIT_SYSDIR_GLOBAL; break;
52
+ case GIT_CONFIG_LEVEL_SYSTEM:
53
+ val = GIT_SYSDIR_SYSTEM;
54
+ break;
55
+ case GIT_CONFIG_LEVEL_XDG:
56
+ val = GIT_SYSDIR_XDG;
57
+ break;
58
+ case GIT_CONFIG_LEVEL_GLOBAL:
59
+ val = GIT_SYSDIR_GLOBAL;
60
+ break;
61
+ case GIT_CONFIG_LEVEL_PROGRAMDATA:
62
+ val = GIT_SYSDIR_PROGRAMDATA;
63
+ break;
52
64
  default:
53
65
  giterr_set(
54
66
  GITERR_INVALID, "Invalid config path selector %d", config_level);
@@ -57,6 +69,13 @@ static int config_level_to_sysdir(int config_level)
57
69
  return val;
58
70
  }
59
71
 
72
+ extern char *git__user_agent;
73
+
74
+ const char *git_libgit2__user_agent()
75
+ {
76
+ return git__user_agent;
77
+ }
78
+
60
79
  int git_libgit2_opts(int key, ...)
61
80
  {
62
81
  int error = 0;
@@ -152,6 +171,15 @@ int git_libgit2_opts(int key, ...)
152
171
  giterr_set(GITERR_NET, "Cannot set certificate locations: OpenSSL is not enabled");
153
172
  error = -1;
154
173
  #endif
174
+ break;
175
+ case GIT_OPT_SET_USER_AGENT:
176
+ git__free(git__user_agent);
177
+ git__user_agent = git__strdup(va_arg(ap, const char *));
178
+ if (!git__user_agent) {
179
+ giterr_set_oom();
180
+ error = -1;
181
+ }
182
+
155
183
  break;
156
184
  }
157
185
 
@@ -62,6 +62,9 @@ GIT_INLINE(int) git_stream_close(git_stream *st)
62
62
 
63
63
  GIT_INLINE(void) git_stream_free(git_stream *st)
64
64
  {
65
+ if (!st)
66
+ return;
67
+
65
68
  st->free(st);
66
69
  }
67
70
 
@@ -495,7 +495,7 @@ cleanup:
495
495
 
496
496
  int git_submodule_foreach(
497
497
  git_repository *repo,
498
- int (*callback)(git_submodule *sm, const char *name, void *payload),
498
+ git_submodule_cb callback,
499
499
  void *payload)
500
500
  {
501
501
  git_vector snapshot = GIT_VECTOR_INIT;
@@ -1423,7 +1423,6 @@ static int submodule_update_head(git_submodule *submodule)
1423
1423
  return 0;
1424
1424
  }
1425
1425
 
1426
-
1427
1426
  int git_submodule_reload(git_submodule *sm, int force)
1428
1427
  {
1429
1428
  int error = 0;
@@ -1433,35 +1432,30 @@ int git_submodule_reload(git_submodule *sm, int force)
1433
1432
 
1434
1433
  assert(sm);
1435
1434
 
1436
- /* refresh index data */
1437
- if ((error = submodule_update_index(sm)) < 0)
1438
- return error;
1439
-
1440
- /* refresh HEAD tree data */
1441
- if ((error = submodule_update_head(sm)) < 0)
1442
- return error;
1435
+ if (!git_repository_is_bare(sm->repo)) {
1436
+ /* refresh config data */
1437
+ mods = gitmodules_snapshot(sm->repo);
1438
+ if (mods != NULL) {
1439
+ error = submodule_read_config(sm, mods);
1440
+ git_config_free(mods);
1443
1441
 
1444
- /* done if bare */
1445
- if (git_repository_is_bare(sm->repo))
1446
- return error;
1442
+ if (error < 0)
1443
+ return error;
1444
+ }
1447
1445
 
1448
- /* refresh config data */
1449
- mods = gitmodules_snapshot(sm->repo);
1450
- if (mods != NULL) {
1451
- error = submodule_read_config(sm, mods);
1452
- git_config_free(mods);
1446
+ /* refresh wd data */
1447
+ sm->flags &=
1448
+ ~(GIT_SUBMODULE_STATUS_IN_WD |
1449
+ GIT_SUBMODULE_STATUS__WD_OID_VALID |
1450
+ GIT_SUBMODULE_STATUS__WD_FLAGS);
1453
1451
 
1454
- if (error < 0) {
1455
- return error;
1456
- }
1452
+ error = submodule_load_from_wd_lite(sm);
1457
1453
  }
1458
1454
 
1459
- /* refresh wd data */
1460
- sm->flags &=
1461
- ~(GIT_SUBMODULE_STATUS_IN_WD | GIT_SUBMODULE_STATUS__WD_OID_VALID |
1462
- GIT_SUBMODULE_STATUS__WD_FLAGS);
1455
+ if (error == 0 && (error = submodule_update_index(sm)) == 0)
1456
+ error = submodule_update_head(sm);
1463
1457
 
1464
- return submodule_load_from_wd_lite(sm);
1458
+ return error;
1465
1459
  }
1466
1460
 
1467
1461
  static void submodule_copy_oid_maybe(
@@ -11,8 +11,21 @@
11
11
  #include "openssl_stream.h"
12
12
  #include "stransport_stream.h"
13
13
 
14
+ static git_stream_cb tls_ctor;
15
+
16
+ int git_stream_register_tls(git_stream_cb ctor)
17
+ {
18
+ tls_ctor = ctor;
19
+
20
+ return 0;
21
+ }
22
+
14
23
  int git_tls_stream_new(git_stream **out, const char *host, const char *port)
15
24
  {
25
+
26
+ if (tls_ctor)
27
+ return tls_ctor(out, host, port);
28
+
16
29
  #ifdef GIT_SECURE_TRANSPORT
17
30
  return git_stransport_stream_new(out, host, port);
18
31
  #elif defined(GIT_OPENSSL)
@@ -10,6 +10,7 @@
10
10
  #include "http_parser.h"
11
11
  #include "buffer.h"
12
12
  #include "netops.h"
13
+ #include "global.h"
13
14
  #include "remote.h"
14
15
  #include "smart.h"
15
16
  #include "auth.h"
@@ -186,6 +187,16 @@ static int apply_credentials(git_buf *buf, http_subtransport *t)
186
187
  return context->next_token(buf, context, cred);
187
188
  }
188
189
 
190
+ static const char *user_agent(void)
191
+ {
192
+ const char *custom = git_libgit2__user_agent();
193
+
194
+ if (custom)
195
+ return custom;
196
+
197
+ return "libgit2 " LIBGIT2_VERSION;
198
+ }
199
+
189
200
  static int gen_request(
190
201
  git_buf *buf,
191
202
  http_stream *s,
@@ -197,7 +208,7 @@ static int gen_request(
197
208
 
198
209
  git_buf_printf(buf, "%s %s%s HTTP/1.1\r\n", s->verb, path, s->service_url);
199
210
 
200
- git_buf_puts(buf, "User-Agent: git/1.0 (libgit2 " LIBGIT2_VERSION ")\r\n");
211
+ git_buf_printf(buf, "User-Agent: git/1.0 (%s)\r\n", user_agent());
201
212
  git_buf_printf(buf, "Host: %s\r\n", t->connection_data.host);
202
213
 
203
214
  if (s->chunked || content_length > 0) {
@@ -15,6 +15,7 @@
15
15
  #include "smart.h"
16
16
  #include "remote.h"
17
17
  #include "repository.h"
18
+ #include "global.h"
18
19
 
19
20
  #include <wincrypt.h>
20
21
  #include <winhttp.h>
@@ -567,12 +568,28 @@ static int winhttp_close_connection(winhttp_subtransport *t)
567
568
  return ret;
568
569
  }
569
570
 
571
+ static int user_agent(git_buf *ua)
572
+ {
573
+ const char *custom = git_libgit2__user_agent();
574
+
575
+ git_buf_clear(ua);
576
+ git_buf_PUTS(ua, "git/1.0 (");
577
+
578
+ if (custom)
579
+ git_buf_puts(ua, custom);
580
+ else
581
+ git_buf_PUTS(ua, "libgit2 " LIBGIT2_VERSION);
582
+
583
+ return git_buf_putc(ua, ')');
584
+ }
585
+
570
586
  static int winhttp_connect(
571
587
  winhttp_subtransport *t)
572
588
  {
573
- wchar_t *ua = L"git/1.0 (libgit2 " WIDEN(LIBGIT2_VERSION) L")";
574
589
  wchar_t *wide_host;
575
590
  int32_t port;
591
+ wchar_t *wide_ua;
592
+ git_buf ua = GIT_BUF_INIT;
576
593
  int error = -1;
577
594
  int default_timeout = TIMEOUT_INFINITE;
578
595
  int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
@@ -590,9 +607,23 @@ static int winhttp_connect(
590
607
  return -1;
591
608
  }
592
609
 
610
+ if ((error = user_agent(&ua)) < 0) {
611
+ git__free(wide_host);
612
+ return error;
613
+ }
614
+
615
+ if (git__utf8_to_16_alloc(&wide_ua, git_buf_cstr(&ua)) < 0) {
616
+ giterr_set(GITERR_OS, "Unable to convert host to wide characters");
617
+ git__free(wide_host);
618
+ git_buf_free(&ua);
619
+ return -1;
620
+ }
621
+
622
+ git_buf_free(&ua);
623
+
593
624
  /* Establish session */
594
625
  t->session = WinHttpOpen(
595
- ua,
626
+ wide_ua,
596
627
  WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
597
628
  WINHTTP_NO_PROXY_NAME,
598
629
  WINHTTP_NO_PROXY_BYPASS,
@@ -628,6 +659,7 @@ on_error:
628
659
  winhttp_close_connection(t);
629
660
 
630
661
  git__free(wide_host);
662
+ git__free(wide_ua);
631
663
 
632
664
  return error;
633
665
  }