rugged 0.24.0b4 → 0.24.0b5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1a251ffaf27a3d8447d1c970d5e537a3b36cf31
4
- data.tar.gz: 432c8fee3c8af31b9878a98f243d2257b8b81208
3
+ metadata.gz: bc796cda2006fded0d97c4defe401f810e34f19f
4
+ data.tar.gz: f0d1d335923bb6ca15116e10404046fb9a18a339
5
5
  SHA512:
6
- metadata.gz: 23b487a868376093f2ef9c60e3b771c51b88fd9b40b2b5ff335462950be29833b1bbc197760fad7c25d3ed66bac5988faae145e5a3eb2be15288ae777c9e0c5a
7
- data.tar.gz: 9d648ed4cf886ad0c217561519dfb74f7a665ac9c3be75719fafd23b2a911ed367ba4a82a162b8c7467ff5fd4cde178e657a778e1fa9dd3daf26bb3aed526cd2
6
+ metadata.gz: 30f6c194e1863b2a946d7b5ed52b5fa911717e1fc0dd5d55f1d4d992dacfc0af567715a2abe86a3c366bda619d0377fed896ac48e2da5c73b8e07486a179a831
7
+ data.tar.gz: 4b636574374df656c945b44a2e03d23c401fae824bb3f9b0e07da1418853268ee188e3e4e53756d8bfce80dedf9dc475397d5ecc8a9fc4a82dcb5fddad570c62
@@ -620,6 +620,10 @@ void rugged_parse_merge_options(git_merge_options *opts, VALUE rb_options)
620
620
  if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("fail_on_conflict")))) {
621
621
  opts->tree_flags |= GIT_MERGE_TREE_FAIL_ON_CONFLICT;
622
622
  }
623
+
624
+ if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("skip_reuc")))) {
625
+ opts->tree_flags |= GIT_MERGE_TREE_SKIP_REUC;
626
+ }
623
627
  }
624
628
  }
625
629
 
@@ -1,3 +1,3 @@
1
1
  module Rugged
2
- Version = VERSION = '0.24.0b4'
2
+ Version = VERSION = '0.24.0b5'
3
3
  end
@@ -137,13 +137,13 @@ FUNCTION(TARGET_OS_LIBRARIES target)
137
137
  ENDIF()
138
138
  ENDFUNCTION()
139
139
 
140
- # For the MSVC IDE, this function splits up the source files like windows
141
- # explorer does. This is esp. useful with the libgit2_clar project, were
142
- # usually 2 or more files share the same name. Sadly, this file grouping
143
- # is a per-directory option in cmake and not per-target, resulting in
144
- # empty virtual folders "tests" for the git2.dll
145
- FUNCTION(MSVC_SPLIT_SOURCES target)
146
- IF(MSVC_IDE)
140
+ # This function splits the sources files up into their appropriate
141
+ # subdirectories. This is especially useful for IDEs like Xcode and
142
+ # Visual Studio, so that you can navigate into the libgit2_clar project,
143
+ # and see the folders within the tests folder (instead of just seeing all
144
+ # source and tests in a single folder.)
145
+ FUNCTION(IDE_SPLIT_SOURCES target)
146
+ IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode)
147
147
  GET_TARGET_PROPERTY(sources ${target} SOURCES)
148
148
  FOREACH(source ${sources})
149
149
  IF(source MATCHES ".*/")
@@ -560,7 +560,7 @@ IF(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS)
560
560
  SET_TARGET_PROPERTIES(git2 PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64")
561
561
  ENDIF()
562
562
 
563
- MSVC_SPLIT_SOURCES(git2)
563
+ IDE_SPLIT_SOURCES(git2)
564
564
 
565
565
  IF (SONAME)
566
566
  SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
@@ -629,7 +629,7 @@ IF (BUILD_CLAR)
629
629
  TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES})
630
630
  TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES})
631
631
  TARGET_OS_LIBRARIES(libgit2_clar)
632
- MSVC_SPLIT_SOURCES(libgit2_clar)
632
+ IDE_SPLIT_SOURCES(libgit2_clar)
633
633
 
634
634
  IF (MSVC_IDE)
635
635
  # Precompiled headers
@@ -20,7 +20,7 @@
20
20
  # define GIT_END_DECL /* empty */
21
21
  #endif
22
22
 
23
- #ifdef _MSC_VER
23
+ #if defined(_MSC_VER) && _MSC_VER < 1800
24
24
  GIT_BEGIN_DECL
25
25
  # include "inttypes.h"
26
26
  GIT_END_DECL
@@ -79,6 +79,11 @@ typedef enum {
79
79
  * GIT_EMERGECONFLICT and no index will be returned.
80
80
  */
81
81
  GIT_MERGE_TREE_FAIL_ON_CONFLICT = (1 << 1),
82
+
83
+ /**
84
+ * Do not write the REUC extension on the generated index
85
+ */
86
+ GIT_MERGE_TREE_SKIP_REUC = (1 << 2),
82
87
  } git_merge_tree_flag_t;
83
88
 
84
89
  /**
@@ -35,11 +35,7 @@ int git_attr_file__new(
35
35
  return -1;
36
36
  }
37
37
 
38
- if (git_pool_init(&attrs->pool, 1, 0) < 0) {
39
- attr_file_free(attrs);
40
- return -1;
41
- }
42
-
38
+ git_pool_init(&attrs->pool, 1);
43
39
  GIT_REFCOUNT_INC(attrs);
44
40
  attrs->entry = entry;
45
41
  attrs->source = source;
@@ -388,10 +388,11 @@ int git_attr_cache__do_init(git_repository *repo)
388
388
  * hashtable for attribute macros, and string pool
389
389
  */
390
390
  if ((ret = git_strmap_alloc(&cache->files)) < 0 ||
391
- (ret = git_strmap_alloc(&cache->macros)) < 0 ||
392
- (ret = git_pool_init(&cache->pool, 1, 0)) < 0)
391
+ (ret = git_strmap_alloc(&cache->macros)) < 0)
393
392
  goto cancel;
394
393
 
394
+ git_pool_init(&cache->pool, 1);
395
+
395
396
  cache = git__compare_and_swap(&repo->attrcache, NULL, cache);
396
397
  if (cache)
397
398
  goto cancel; /* raced with another thread, free this but no error */
@@ -1255,11 +1255,13 @@ static int checkout_get_actions(
1255
1255
  int error = 0, act;
1256
1256
  const git_index_entry *wditem;
1257
1257
  git_vector pathspec = GIT_VECTOR_INIT, *deltas;
1258
- git_pool pathpool = GIT_POOL_INIT_STRINGPOOL;
1258
+ git_pool pathpool;
1259
1259
  git_diff_delta *delta;
1260
1260
  size_t i, *counts = NULL;
1261
1261
  uint32_t *actions = NULL;
1262
1262
 
1263
+ git_pool_init(&pathpool, 1);
1264
+
1263
1265
  if (data->opts.paths.count > 0 &&
1264
1266
  git_pathspec__vinit(&pathspec, &data->opts.paths, &pathpool) < 0)
1265
1267
  return -1;
@@ -2439,10 +2441,11 @@ static int checkout_data_init(
2439
2441
  git_config_entry_free(conflict_style);
2440
2442
  }
2441
2443
 
2444
+ git_pool_init(&data->pool, 1);
2445
+
2442
2446
  if ((error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
2443
2447
  (error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 ||
2444
2448
  (error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 ||
2445
- (error = git_pool_init(&data->pool, 1, 0)) < 0 ||
2446
2449
  (error = git_buf_puts(&data->path, data->opts.target_directory)) < 0 ||
2447
2450
  (error = git_path_to_dir(&data->path)) < 0 ||
2448
2451
  (error = git_strmap_alloc(&data->mkdir_map)) < 0)
@@ -47,7 +47,7 @@ git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_
47
47
 
48
48
  git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk)
49
49
  {
50
- return (git_commit_list_node *)git_pool_malloc(&walk->commit_pool, COMMIT_ALLOC);
50
+ return (git_commit_list_node *)git_pool_mallocz(&walk->commit_pool, 1);
51
51
  }
52
52
 
53
53
  static int commit_error(git_commit_list_node *commit, const char *msg)
@@ -430,8 +430,9 @@ static git_diff *diff_list_alloc(
430
430
  diff->new_src = new_iter->type;
431
431
  memcpy(&diff->opts, &dflt, sizeof(diff->opts));
432
432
 
433
- if (git_vector_init(&diff->deltas, 0, git_diff_delta__cmp) < 0 ||
434
- git_pool_init(&diff->pool, 1, 0) < 0) {
433
+ git_pool_init(&diff->pool, 1);
434
+
435
+ if (git_vector_init(&diff->deltas, 0, git_diff_delta__cmp) < 0) {
435
436
  git_diff_free(diff);
436
437
  return NULL;
437
438
  }
@@ -134,11 +134,11 @@ int git_diff__merge(
134
134
  return -1;
135
135
  }
136
136
 
137
- if (git_vector_init(
138
- &onto_new, onto->deltas.length, git_diff_delta__cmp) < 0 ||
139
- git_pool_init(&onto_pool, 1, 0) < 0)
137
+ if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0)
140
138
  return -1;
141
139
 
140
+ git_pool_init(&onto_pool, 1);
141
+
142
142
  for (i = 0, j = 0; i < onto->deltas.length || j < from->deltas.length; ) {
143
143
  git_diff_delta *o = GIT_VECTOR_GET(&onto->deltas, i);
144
144
  const git_diff_delta *f = GIT_VECTOR_GET(&from->deltas, j);
@@ -439,7 +439,7 @@ int git_index_open(git_index **index_out, const char *index_path)
439
439
  return -1;
440
440
  }
441
441
 
442
- git_pool_init(&index->tree_pool, 1, 0);
442
+ git_pool_init(&index->tree_pool, 1);
443
443
 
444
444
  if (index_path != NULL) {
445
445
  index->index_file_path = git__strdup(index_path);
@@ -2000,27 +2000,24 @@ size_t git_index_reuc_entrycount(git_index *index)
2000
2000
  return index->reuc.length;
2001
2001
  }
2002
2002
 
2003
+ static int index_reuc_on_dup(void **old, void *new)
2004
+ {
2005
+ index_entry_reuc_free(*old);
2006
+ *old = new;
2007
+ return GIT_EEXISTS;
2008
+ }
2009
+
2003
2010
  static int index_reuc_insert(
2004
2011
  git_index *index,
2005
- git_index_reuc_entry *reuc,
2006
- int replace)
2012
+ git_index_reuc_entry *reuc)
2007
2013
  {
2008
- git_index_reuc_entry **existing = NULL;
2009
- size_t position;
2014
+ int res;
2010
2015
 
2011
2016
  assert(index && reuc && reuc->path != NULL);
2017
+ assert(git_vector_is_sorted(&index->reuc));
2012
2018
 
2013
- if (!git_index_reuc_find(&position, index, reuc->path))
2014
- existing = (git_index_reuc_entry **)&index->reuc.contents[position];
2015
-
2016
- if (!replace || !existing)
2017
- return git_vector_insert(&index->reuc, reuc);
2018
-
2019
- /* exists, replace it */
2020
- git__free(*existing);
2021
- *existing = reuc;
2022
-
2023
- return 0;
2019
+ res = git_vector_insert_sorted(&index->reuc, reuc, &index_reuc_on_dup);
2020
+ return res == GIT_EEXISTS ? 0 : res;
2024
2021
  }
2025
2022
 
2026
2023
  int git_index_reuc_add(git_index *index, const char *path,
@@ -2035,7 +2032,7 @@ int git_index_reuc_add(git_index *index, const char *path,
2035
2032
 
2036
2033
  if ((error = index_entry_reuc_init(&reuc, path, ancestor_mode,
2037
2034
  ancestor_oid, our_mode, our_oid, their_mode, their_oid)) < 0 ||
2038
- (error = index_reuc_insert(index, reuc, 1)) < 0)
2035
+ (error = index_reuc_insert(index, reuc)) < 0)
2039
2036
  index_entry_reuc_free(reuc);
2040
2037
 
2041
2038
  return error;
@@ -2055,7 +2052,7 @@ const git_index_reuc_entry *git_index_reuc_get_bypath(
2055
2052
  if (!index->reuc.length)
2056
2053
  return NULL;
2057
2054
 
2058
- git_vector_sort(&index->reuc);
2055
+ assert(git_vector_is_sorted(&index->reuc));
2059
2056
 
2060
2057
  if (git_index_reuc_find(&pos, index, path) < 0)
2061
2058
  return NULL;
@@ -2067,8 +2064,8 @@ const git_index_reuc_entry *git_index_reuc_get_byindex(
2067
2064
  git_index *index, size_t n)
2068
2065
  {
2069
2066
  assert(index);
2067
+ assert(git_vector_is_sorted(&index->reuc));
2070
2068
 
2071
- git_vector_sort(&index->reuc);
2072
2069
  return git_vector_get(&index->reuc, n);
2073
2070
  }
2074
2071
 
@@ -2077,7 +2074,7 @@ int git_index_reuc_remove(git_index *index, size_t position)
2077
2074
  int error;
2078
2075
  git_index_reuc_entry *reuc;
2079
2076
 
2080
- git_vector_sort(&index->reuc);
2077
+ assert(git_vector_is_sorted(&index->reuc));
2081
2078
 
2082
2079
  reuc = git_vector_get(&index->reuc, position);
2083
2080
  error = git_vector_remove(&index->reuc, position);
@@ -567,7 +567,7 @@ static bool tree_iterator__pop_frame(tree_iterator *ti, bool final)
567
567
  tree_iterator__move_to_next(ti, tf);
568
568
 
569
569
  if (!final) { /* if final, don't bother to clean up */
570
- git_pool_free_array(&ti->pool, tf->n_entries, (void **)tf->entries);
570
+ // TODO: maybe free the pool so far?
571
571
  git_buf_rtruncate_at_char(&ti->path, '/');
572
572
  }
573
573
 
@@ -822,8 +822,9 @@ int git_iterator_for_tree(
822
822
  if ((error = iterator__update_ignore_case((git_iterator *)ti, options ? options->flags : 0)) < 0)
823
823
  goto fail;
824
824
 
825
- if ((error = git_pool_init(&ti->pool, sizeof(tree_iterator_entry),0)) < 0 ||
826
- (error = tree_iterator__create_root_frame(ti, tree)) < 0 ||
825
+ git_pool_init(&ti->pool, sizeof(tree_iterator_entry));
826
+
827
+ if ((error = tree_iterator__create_root_frame(ti, tree)) < 0 ||
827
828
  (error = tree_iterator__push_frame(ti)) < 0) /* expand root now */
828
829
  goto fail;
829
830
 
@@ -626,7 +626,7 @@ static int merge_conflict_resolve_one_renamed(
626
626
  git_oid__cmp(&conflict->our_entry.id, &conflict->their_entry.id) != 0)
627
627
  return 0;
628
628
 
629
- if ((merged = git_pool_malloc(&diff_list->pool, sizeof(git_index_entry))) == NULL)
629
+ if ((merged = git_pool_mallocz(&diff_list->pool, sizeof(git_index_entry))) == NULL)
630
630
  return -1;
631
631
 
632
632
  if (ours_changed)
@@ -711,7 +711,7 @@ static int merge_conflict_resolve_automerge(
711
711
  (error = git_odb_write(&automerge_oid, odb, result.ptr, result.len, GIT_OBJ_BLOB)) < 0)
712
712
  goto done;
713
713
 
714
- if ((index_entry = git_pool_malloc(&diff_list->pool, sizeof(git_index_entry))) == NULL)
714
+ if ((index_entry = git_pool_mallocz(&diff_list->pool, sizeof(git_index_entry))) == NULL)
715
715
  GITERR_CHECK_ALLOC(index_entry);
716
716
 
717
717
  index_entry->path = git_pool_strdup(&diff_list->pool, result.path);
@@ -1307,7 +1307,6 @@ GIT_INLINE(int) index_entry_dup_pool(
1307
1307
  {
1308
1308
  if (src != NULL) {
1309
1309
  memcpy(out, src, sizeof(git_index_entry));
1310
-
1311
1310
  if ((out->path = git_pool_strdup(pool, src->path)) == NULL)
1312
1311
  return -1;
1313
1312
  }
@@ -1343,7 +1342,7 @@ static git_merge_diff *merge_diff_from_index_entries(
1343
1342
  git_merge_diff *conflict;
1344
1343
  git_pool *pool = &diff_list->pool;
1345
1344
 
1346
- if ((conflict = git_pool_malloc(pool, sizeof(git_merge_diff))) == NULL)
1345
+ if ((conflict = git_pool_mallocz(pool, sizeof(git_merge_diff))) == NULL)
1347
1346
  return NULL;
1348
1347
 
1349
1348
  if (index_entry_dup_pool(&conflict->ancestor_entry, pool, entries[TREE_IDX_ANCESTOR]) < 0 ||
@@ -1384,7 +1383,7 @@ static int merge_diff_list_insert_unmodified(
1384
1383
  int error = 0;
1385
1384
  git_index_entry *entry;
1386
1385
 
1387
- entry = git_pool_malloc(&diff_list->pool, sizeof(git_index_entry));
1386
+ entry = git_pool_mallocz(&diff_list->pool, sizeof(git_index_entry));
1388
1387
  GITERR_CHECK_ALLOC(entry);
1389
1388
 
1390
1389
  if ((error = index_entry_dup_pool(entry, &diff_list->pool, tree_items[0])) >= 0)
@@ -1442,10 +1441,11 @@ git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo)
1442
1441
 
1443
1442
  diff_list->repo = repo;
1444
1443
 
1444
+ git_pool_init(&diff_list->pool, 1);
1445
+
1445
1446
  if (git_vector_init(&diff_list->staged, 0, NULL) < 0 ||
1446
1447
  git_vector_init(&diff_list->conflicts, 0, NULL) < 0 ||
1447
- git_vector_init(&diff_list->resolved, 0, NULL) < 0 ||
1448
- git_pool_init(&diff_list->pool, 1, 0) < 0) {
1448
+ git_vector_init(&diff_list->resolved, 0, NULL) < 0) {
1449
1449
  git_merge_diff_list__free(diff_list);
1450
1450
  return NULL;
1451
1451
  }
@@ -1541,7 +1541,45 @@ static int merge_index_insert_reuc(
1541
1541
  mode[0], oid[0], mode[1], oid[1], mode[2], oid[2]);
1542
1542
  }
1543
1543
 
1544
- int index_from_diff_list(git_index **out, git_merge_diff_list *diff_list)
1544
+ static int index_update_reuc(git_index *index, git_merge_diff_list *diff_list)
1545
+ {
1546
+ int error;
1547
+ size_t i;
1548
+ git_merge_diff *conflict;
1549
+
1550
+ /* Add each entry in the resolved conflict to the REUC independently, since
1551
+ * the paths may differ due to renames. */
1552
+ git_vector_foreach(&diff_list->resolved, i, conflict) {
1553
+ const git_index_entry *ancestor =
1554
+ GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry) ?
1555
+ &conflict->ancestor_entry : NULL;
1556
+
1557
+ const git_index_entry *ours =
1558
+ GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) ?
1559
+ &conflict->our_entry : NULL;
1560
+
1561
+ const git_index_entry *theirs =
1562
+ GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry) ?
1563
+ &conflict->their_entry : NULL;
1564
+
1565
+ if (ancestor != NULL &&
1566
+ (error = merge_index_insert_reuc(index, TREE_IDX_ANCESTOR, ancestor)) < 0)
1567
+ return error;
1568
+
1569
+ if (ours != NULL &&
1570
+ (error = merge_index_insert_reuc(index, TREE_IDX_OURS, ours)) < 0)
1571
+ return error;
1572
+
1573
+ if (theirs != NULL &&
1574
+ (error = merge_index_insert_reuc(index, TREE_IDX_THEIRS, theirs)) < 0)
1575
+ return error;
1576
+ }
1577
+
1578
+ return 0;
1579
+ }
1580
+
1581
+ static int index_from_diff_list(git_index **out,
1582
+ git_merge_diff_list *diff_list, bool skip_reuc)
1545
1583
  {
1546
1584
  git_index *index;
1547
1585
  size_t i;
@@ -1600,31 +1638,8 @@ int index_from_diff_list(git_index **out, git_merge_diff_list *diff_list)
1600
1638
  }
1601
1639
  }
1602
1640
 
1603
- /* Add each entry in the resolved conflict to the REUC independently, since
1604
- * the paths may differ due to renames. */
1605
- git_vector_foreach(&diff_list->resolved, i, conflict) {
1606
- const git_index_entry *ancestor =
1607
- GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry) ?
1608
- &conflict->ancestor_entry : NULL;
1609
-
1610
- const git_index_entry *ours =
1611
- GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->our_entry) ?
1612
- &conflict->our_entry : NULL;
1613
-
1614
- const git_index_entry *theirs =
1615
- GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->their_entry) ?
1616
- &conflict->their_entry : NULL;
1617
-
1618
- if (ancestor != NULL &&
1619
- (error = merge_index_insert_reuc(index, TREE_IDX_ANCESTOR, ancestor)) < 0)
1620
- goto on_error;
1621
-
1622
- if (ours != NULL &&
1623
- (error = merge_index_insert_reuc(index, TREE_IDX_OURS, ours)) < 0)
1624
- goto on_error;
1625
-
1626
- if (theirs != NULL &&
1627
- (error = merge_index_insert_reuc(index, TREE_IDX_THEIRS, theirs)) < 0)
1641
+ if (!skip_reuc) {
1642
+ if ((error = index_update_reuc(index, diff_list)) < 0)
1628
1643
  goto on_error;
1629
1644
  }
1630
1645
 
@@ -1633,7 +1648,6 @@ int index_from_diff_list(git_index **out, git_merge_diff_list *diff_list)
1633
1648
 
1634
1649
  on_error:
1635
1650
  git_index_free(index);
1636
-
1637
1651
  return error;
1638
1652
  }
1639
1653
 
@@ -1712,12 +1726,13 @@ int git_merge__iterators(
1712
1726
  }
1713
1727
  }
1714
1728
 
1729
+ error = index_from_diff_list(out, diff_list,
1730
+ (opts.tree_flags & GIT_MERGE_TREE_SKIP_REUC));
1731
+
1732
+ done:
1715
1733
  if (!given_opts || !given_opts->metric)
1716
1734
  git__free(opts.metric);
1717
1735
 
1718
- error = index_from_diff_list(out, diff_list);
1719
-
1720
- done:
1721
1736
  git_merge_diff_list__free(diff_list);
1722
1737
  git_iterator_free(empty_ancestor);
1723
1738
  git_iterator_free(empty_ours);
@@ -135,8 +135,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
135
135
  if (!pb->walk_objects)
136
136
  goto on_error;
137
137
 
138
- if (git_pool_init(&pb->object_pool, sizeof(git_walk_object), 0) < 0)
139
- goto on_error;
138
+ git_pool_init(&pb->object_pool, sizeof(git_walk_object));
140
139
 
141
140
  pb->repo = repo;
142
141
  pb->nr_threads = 1; /* do not spawn any thread by default */
@@ -237,9 +237,9 @@ int git_pathspec__init(git_pathspec *ps, const git_strarray *paths)
237
237
  memset(ps, 0, sizeof(*ps));
238
238
 
239
239
  ps->prefix = git_pathspec_prefix(paths);
240
+ git_pool_init(&ps->pool, 1);
240
241
 
241
- if ((error = git_pool_init(&ps->pool, 1, 0)) < 0 ||
242
- (error = git_pathspec__vinit(&ps->pathspec, paths, &ps->pool)) < 0)
242
+ if ((error = git_pathspec__vinit(&ps->pathspec, paths, &ps->pool)) < 0)
243
243
  git_pathspec__clear(ps);
244
244
 
245
245
  return error;
@@ -312,15 +312,11 @@ static git_pathspec_match_list *pathspec_match_alloc(
312
312
  git_pathspec *ps, int datatype)
313
313
  {
314
314
  git_pathspec_match_list *m = git__calloc(1, sizeof(git_pathspec_match_list));
315
-
316
- if (m != NULL && git_pool_init(&m->pool, 1, 0) < 0) {
317
- pathspec_match_free(m);
318
- m = NULL;
319
- }
320
-
321
315
  if (!m)
322
316
  return NULL;
323
317
 
318
+ git_pool_init(&m->pool, 1);
319
+
324
320
  /* need to keep reference to pathspec and increment refcount because
325
321
  * failures array stores pointers to the pattern strings of the
326
322
  * pathspec that had no matches
@@ -8,67 +8,49 @@ struct git_pool_page {
8
8
  git_pool_page *next;
9
9
  uint32_t size;
10
10
  uint32_t avail;
11
- GIT_ALIGN(char data[GIT_FLEX_ARRAY], 8);
11
+ char data[GIT_FLEX_ARRAY];
12
12
  };
13
13
 
14
- struct pool_freelist {
15
- struct pool_freelist *next;
16
- };
14
+ static void *pool_alloc_page(git_pool *pool, uint32_t size);
17
15
 
18
- #define GIT_POOL_MIN_USABLE 4
19
- #define GIT_POOL_MIN_PAGESZ 2 * sizeof(void*)
16
+ uint32_t git_pool__system_page_size(void)
17
+ {
18
+ static uint32_t size = 0;
20
19
 
21
- static void *pool_alloc_page(git_pool *pool, uint32_t size);
22
- static void pool_insert_page(git_pool *pool, git_pool_page *page);
20
+ if (!size) {
21
+ size_t page_size;
22
+ if (git__page_size(&page_size) < 0)
23
+ page_size = 4096;
24
+ /* allow space for malloc overhead */
25
+ size = page_size - (2 * sizeof(void *)) - sizeof(git_pool_page);
26
+ }
23
27
 
24
- int git_pool_init(
25
- git_pool *pool, uint32_t item_size, uint32_t items_per_page)
28
+ return size;
29
+ }
30
+
31
+ void git_pool_init(git_pool *pool, uint32_t item_size)
26
32
  {
33
+ const uint32_t align_size = sizeof(void *) - 1;
27
34
  assert(pool);
28
35
 
29
- if (!item_size)
30
- item_size = 1;
31
- /* round up item_size for decent object alignment */
32
- if (item_size > 4)
33
- item_size = (item_size + 7) & ~7;
34
- else if (item_size == 3)
35
- item_size = 4;
36
-
37
- if (!items_per_page)
38
- items_per_page = git_pool__suggest_items_per_page(item_size);
39
- if (item_size * items_per_page < GIT_POOL_MIN_PAGESZ)
40
- items_per_page = (GIT_POOL_MIN_PAGESZ + item_size - 1) / item_size;
36
+ if (item_size > 1)
37
+ item_size = (item_size + align_size) & ~align_size;
41
38
 
42
39
  memset(pool, 0, sizeof(git_pool));
43
40
  pool->item_size = item_size;
44
- pool->page_size = item_size * items_per_page;
45
-
46
- return 0;
41
+ pool->page_size = git_pool__system_page_size();
47
42
  }
48
43
 
49
44
  void git_pool_clear(git_pool *pool)
50
45
  {
51
46
  git_pool_page *scan, *next;
52
47
 
53
- for (scan = pool->open; scan != NULL; scan = next) {
48
+ for (scan = pool->pages; scan != NULL; scan = next) {
54
49
  next = scan->next;
55
50
  git__free(scan);
56
51
  }
57
- pool->open = NULL;
58
52
 
59
- for (scan = pool->full; scan != NULL; scan = next) {
60
- next = scan->next;
61
- git__free(scan);
62
- }
63
- pool->full = NULL;
64
-
65
- pool->free_list = NULL;
66
-
67
- pool->items = 0;
68
-
69
- pool->has_string_alloc = 0;
70
- pool->has_multi_item_alloc = 0;
71
- pool->has_large_page_alloc = 0;
53
+ pool->pages = NULL;
72
54
  }
73
55
 
74
56
  void git_pool_swap(git_pool *a, git_pool *b)
@@ -83,110 +65,51 @@ void git_pool_swap(git_pool *a, git_pool *b)
83
65
  memcpy(b, &temp, sizeof(temp));
84
66
  }
85
67
 
86
- static void pool_insert_page(git_pool *pool, git_pool_page *page)
87
- {
88
- git_pool_page *scan;
89
-
90
- /* If there are no open pages or this page has the most open space,
91
- * insert it at the beginning of the list. This is the common case.
92
- */
93
- if (pool->open == NULL || pool->open->avail < page->avail) {
94
- page->next = pool->open;
95
- pool->open = page;
96
- return;
97
- }
98
-
99
- /* Otherwise insert into sorted position. */
100
- for (scan = pool->open;
101
- scan->next && scan->next->avail > page->avail;
102
- scan = scan->next);
103
- page->next = scan->next;
104
- scan->next = page;
105
- }
106
-
107
68
  static void *pool_alloc_page(git_pool *pool, uint32_t size)
108
69
  {
109
70
  git_pool_page *page;
110
- uint32_t new_page_size;
71
+ const uint32_t new_page_size = (size <= pool->page_size) ? pool->page_size : size;
111
72
  size_t alloc_size;
112
73
 
113
- if (size <= pool->page_size)
114
- new_page_size = pool->page_size;
115
- else {
116
- new_page_size = size;
117
- pool->has_large_page_alloc = 1;
118
- }
119
-
120
74
  if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, new_page_size, sizeof(git_pool_page)) ||
121
- !(page = git__calloc(1, alloc_size)))
75
+ !(page = git__malloc(alloc_size)))
122
76
  return NULL;
123
77
 
124
- page->size = new_page_size;
78
+ page->size = new_page_size;
125
79
  page->avail = new_page_size - size;
80
+ page->next = pool->pages;
126
81
 
127
- if (page->avail > 0)
128
- pool_insert_page(pool, page);
129
- else {
130
- page->next = pool->full;
131
- pool->full = page;
132
- }
133
-
134
- pool->items++;
82
+ pool->pages = page;
135
83
 
136
84
  return page->data;
137
85
  }
138
86
 
139
- GIT_INLINE(void) pool_remove_page(
140
- git_pool *pool, git_pool_page *page, git_pool_page *prev)
87
+ static void *pool_alloc(git_pool *pool, uint32_t size)
141
88
  {
142
- if (prev == NULL)
143
- pool->open = page->next;
144
- else
145
- prev->next = page->next;
146
- }
147
-
148
- void *git_pool_malloc(git_pool *pool, uint32_t items)
149
- {
150
- git_pool_page *scan = pool->open, *prev;
151
- uint32_t size = ((items * pool->item_size) + 7) & ~7;
89
+ git_pool_page *page = pool->pages;
152
90
  void *ptr = NULL;
153
91
 
154
- pool->has_string_alloc = 0;
155
- if (items > 1)
156
- pool->has_multi_item_alloc = 1;
157
- else if (pool->free_list != NULL) {
158
- ptr = pool->free_list;
159
- pool->free_list = ((struct pool_freelist *)pool->free_list)->next;
160
- return ptr;
161
- }
162
-
163
- /* just add a block if there is no open one to accommodate this */
164
- if (size >= pool->page_size || !scan || scan->avail < size)
92
+ if (!page || page->avail < size)
165
93
  return pool_alloc_page(pool, size);
166
94
 
167
- pool->items++;
168
-
169
- /* find smallest block in free list with space */
170
- for (scan = pool->open, prev = NULL;
171
- scan->next && scan->next->avail >= size;
172
- prev = scan, scan = scan->next);
95
+ ptr = &page->data[page->size - page->avail];
96
+ page->avail -= size;
173
97
 
174
- /* allocate space from the block */
175
- ptr = &scan->data[scan->size - scan->avail];
176
- scan->avail -= size;
98
+ return ptr;
99
+ }
177
100
 
178
- /* move to full list if there is almost no space left */
179
- if (scan->avail < pool->item_size || scan->avail < GIT_POOL_MIN_USABLE) {
180
- pool_remove_page(pool, scan, prev);
181
- scan->next = pool->full;
182
- pool->full = scan;
183
- }
184
- /* reorder list if block is now smaller than the one after it */
185
- else if (scan->next != NULL && scan->next->avail > scan->avail) {
186
- pool_remove_page(pool, scan, prev);
187
- pool_insert_page(pool, scan);
188
- }
101
+ void *git_pool_malloc(git_pool *pool, uint32_t items)
102
+ {
103
+ const uint32_t size = items * pool->item_size;
104
+ return pool_alloc(pool, size);
105
+ }
189
106
 
107
+ void *git_pool_mallocz(git_pool *pool, uint32_t items)
108
+ {
109
+ const uint32_t size = items * pool->item_size;
110
+ void *ptr = pool_alloc(pool, size);
111
+ if (ptr)
112
+ memset(ptr, 0x0, size);
190
113
  return ptr;
191
114
  }
192
115
 
@@ -204,15 +127,12 @@ char *git_pool_strndup(git_pool *pool, const char *str, size_t n)
204
127
  ptr[n] = '\0';
205
128
  }
206
129
 
207
- pool->has_string_alloc = 1;
208
-
209
130
  return ptr;
210
131
  }
211
132
 
212
133
  char *git_pool_strdup(git_pool *pool, const char *str)
213
134
  {
214
135
  assert(pool && str && pool->item_size == sizeof(char));
215
-
216
136
  return git_pool_strndup(pool, str, strlen(str));
217
137
  }
218
138
 
@@ -238,88 +158,23 @@ char *git_pool_strcat(git_pool *pool, const char *a, const char *b)
238
158
  memcpy(((char *)ptr) + len_a, b, len_b);
239
159
  *(((char *)ptr) + len_a + len_b) = '\0';
240
160
  }
241
- pool->has_string_alloc = 1;
242
-
243
161
  return ptr;
244
162
  }
245
163
 
246
- void git_pool_free(git_pool *pool, void *ptr)
247
- {
248
- struct pool_freelist *item = ptr;
249
-
250
- assert(pool && pool->item_size >= sizeof(void*));
251
-
252
- if (item) {
253
- item->next = pool->free_list;
254
- pool->free_list = item;
255
- }
256
- }
257
-
258
- void git_pool_free_array(git_pool *pool, size_t count, void **ptrs)
259
- {
260
- struct pool_freelist **items = (struct pool_freelist **)ptrs;
261
- size_t i;
262
-
263
- assert(pool && ptrs && pool->item_size >= sizeof(void*));
264
-
265
- if (!count)
266
- return;
267
-
268
- for (i = count - 1; i > 0; --i)
269
- items[i]->next = items[i - 1];
270
-
271
- items[i]->next = pool->free_list;
272
- pool->free_list = items[count - 1];
273
- }
274
-
275
164
  uint32_t git_pool__open_pages(git_pool *pool)
276
165
  {
277
166
  uint32_t ct = 0;
278
167
  git_pool_page *scan;
279
- for (scan = pool->open; scan != NULL; scan = scan->next) ct++;
280
- return ct;
281
- }
282
-
283
- uint32_t git_pool__full_pages(git_pool *pool)
284
- {
285
- uint32_t ct = 0;
286
- git_pool_page *scan;
287
- for (scan = pool->full; scan != NULL; scan = scan->next) ct++;
168
+ for (scan = pool->pages; scan != NULL; scan = scan->next) ct++;
288
169
  return ct;
289
170
  }
290
171
 
291
172
  bool git_pool__ptr_in_pool(git_pool *pool, void *ptr)
292
173
  {
293
174
  git_pool_page *scan;
294
- for (scan = pool->open; scan != NULL; scan = scan->next)
295
- if ((void *)scan->data <= ptr &&
296
- (void *)(((char *)scan->data) + scan->size) > ptr)
297
- return true;
298
- for (scan = pool->full; scan != NULL; scan = scan->next)
175
+ for (scan = pool->pages; scan != NULL; scan = scan->next)
299
176
  if ((void *)scan->data <= ptr &&
300
177
  (void *)(((char *)scan->data) + scan->size) > ptr)
301
178
  return true;
302
179
  return false;
303
180
  }
304
-
305
- uint32_t git_pool__system_page_size(void)
306
- {
307
- static uint32_t size = 0;
308
-
309
- if (!size) {
310
- size_t page_size;
311
- if (git__page_size(&page_size) < 0)
312
- page_size = 4096;
313
- size = page_size - 2 * sizeof(void *); /* allow space for malloc overhead */
314
- }
315
-
316
- return size;
317
- }
318
-
319
- uint32_t git_pool__suggest_items_per_page(uint32_t item_size)
320
- {
321
- uint32_t page_bytes =
322
- git_pool__system_page_size() - sizeof(git_pool_page);
323
- return page_bytes / item_size;
324
- }
325
-
@@ -28,19 +28,11 @@ typedef struct git_pool_page git_pool_page;
28
28
  * For examples of how to set up a `git_pool` see `git_pool_init`.
29
29
  */
30
30
  typedef struct {
31
- git_pool_page *open; /* pages with space left */
32
- git_pool_page *full; /* pages with no space left */
33
- void *free_list; /* optional: list of freed blocks */
31
+ git_pool_page *pages; /* pages with space left */
34
32
  uint32_t item_size; /* size of single alloc unit in bytes */
35
33
  uint32_t page_size; /* size of page in bytes */
36
- uint32_t items;
37
- unsigned has_string_alloc : 1; /* was the strdup function used */
38
- unsigned has_multi_item_alloc : 1; /* was items ever > 1 in malloc */
39
- unsigned has_large_page_alloc : 1; /* are any pages > page_size */
40
34
  } git_pool;
41
35
 
42
- #define GIT_POOL_INIT_STRINGPOOL { 0, 0, 0, 1, 4000, 0, 0, 0, 0 }
43
-
44
36
  /**
45
37
  * Initialize a pool.
46
38
  *
@@ -57,8 +49,7 @@ typedef struct {
57
49
  * Of course, you can use this in other ways, but those are the
58
50
  * two most common patterns.
59
51
  */
60
- extern int git_pool_init(
61
- git_pool *pool, uint32_t item_size, uint32_t items_per_page);
52
+ extern void git_pool_init(git_pool *pool, uint32_t item_size);
62
53
 
63
54
  /**
64
55
  * Free all items in pool
@@ -74,17 +65,7 @@ extern void git_pool_swap(git_pool *a, git_pool *b);
74
65
  * Allocate space for one or more items from a pool.
75
66
  */
76
67
  extern void *git_pool_malloc(git_pool *pool, uint32_t items);
77
-
78
- /**
79
- * Allocate space and zero it out.
80
- */
81
- GIT_INLINE(void *) git_pool_mallocz(git_pool *pool, uint32_t items)
82
- {
83
- void *ptr = git_pool_malloc(pool, items);
84
- if (ptr)
85
- memset(ptr, 0, (size_t)items * (size_t)pool->item_size);
86
- return ptr;
87
- }
68
+ extern void *git_pool_mallocz(git_pool *pool, uint32_t items);
88
69
 
89
70
  /**
90
71
  * Allocate space and duplicate string data into it.
@@ -114,35 +95,10 @@ extern char *git_pool_strdup_safe(git_pool *pool, const char *str);
114
95
  */
115
96
  extern char *git_pool_strcat(git_pool *pool, const char *a, const char *b);
116
97
 
117
- /**
118
- * Push a block back onto the free list for the pool.
119
- *
120
- * This is allowed only if the item_size is >= sizeof(void*).
121
- *
122
- * In some cases, it is helpful to "release" an allocated block
123
- * for reuse. Pools don't support a general purpose free, but
124
- * they will keep a simple free blocks linked list provided the
125
- * native block size is large enough to hold a void pointer
126
- */
127
- extern void git_pool_free(git_pool *pool, void *ptr);
128
-
129
- /**
130
- * Push an array of pool allocated blocks efficiently onto the free list.
131
- *
132
- * This has the same constraints as `git_pool_free()` above.
133
- */
134
- extern void git_pool_free_array(git_pool *pool, size_t count, void **ptrs);
135
-
136
98
  /*
137
99
  * Misc utilities
138
100
  */
139
-
140
101
  extern uint32_t git_pool__open_pages(git_pool *pool);
141
-
142
- extern uint32_t git_pool__full_pages(git_pool *pool);
143
-
144
102
  extern bool git_pool__ptr_in_pool(git_pool *pool, void *ptr);
145
103
 
146
- extern uint32_t git_pool__suggest_items_per_page(uint32_t item_size);
147
-
148
104
  #endif
@@ -626,8 +626,9 @@ static int refdb_fs_backend__iterator(
626
626
  iter = git__calloc(1, sizeof(refdb_fs_iter));
627
627
  GITERR_CHECK_ALLOC(iter);
628
628
 
629
- if (git_pool_init(&iter->pool, 1, 0) < 0 ||
630
- git_vector_init(&iter->loose, 8, NULL) < 0)
629
+ git_pool_init(&iter->pool, 1);
630
+
631
+ if (git_vector_init(&iter->loose, 8, NULL) < 0)
631
632
  goto fail;
632
633
 
633
634
  if (glob != NULL &&
@@ -689,6 +689,7 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
689
689
  git_buf_free(&global_buf);
690
690
  git_buf_free(&xdg_buf);
691
691
  git_buf_free(&system_buf);
692
+ git_buf_free(&programdata_buf);
692
693
  }
693
694
 
694
695
  *out = repo->_config;
@@ -535,12 +535,10 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
535
535
  walk->commits = git_oidmap_alloc();
536
536
  GITERR_CHECK_ALLOC(walk->commits);
537
537
 
538
- if (git_pqueue_init(
539
- &walk->iterator_time, 0, 8, git_commit_list_time_cmp) < 0 ||
540
- git_pool_init(&walk->commit_pool, 1,
541
- git_pool__suggest_items_per_page(COMMIT_ALLOC) * COMMIT_ALLOC) < 0)
538
+ if (git_pqueue_init(&walk->iterator_time, 0, 8, git_commit_list_time_cmp) < 0)
542
539
  return -1;
543
540
 
541
+ git_pool_init(&walk->commit_pool, COMMIT_ALLOC);
544
542
  walk->get_next = &revwalk_next_unsorted;
545
543
  walk->enqueue = &revwalk_enqueue_unsorted;
546
544
 
@@ -20,8 +20,9 @@ int git_sortedcache_new(
20
20
  sc = git__calloc(1, alloclen);
21
21
  GITERR_CHECK_ALLOC(sc);
22
22
 
23
- if (git_pool_init(&sc->pool, 1, 0) < 0 ||
24
- git_vector_init(&sc->items, 4, item_cmp) < 0 ||
23
+ git_pool_init(&sc->pool, 1);
24
+
25
+ if (git_vector_init(&sc->items, 4, item_cmp) < 0 ||
25
26
  git_strmap_alloc(&sc->map) < 0)
26
27
  goto fail;
27
28
 
@@ -77,8 +77,7 @@ int git_transaction_new(git_transaction **out, git_repository *repo)
77
77
 
78
78
  assert(out && repo);
79
79
 
80
- if ((error = git_pool_init(&pool, 1, 0)) < 0)
81
- return error;
80
+ git_pool_init(&pool, 1);
82
81
 
83
82
  tx = git_pool_mallocz(&pool, sizeof(git_transaction));
84
83
  if (!tx) {
@@ -20,7 +20,7 @@
20
20
  *
21
21
  */
22
22
 
23
- #include "util.h"
23
+ #include "../util.h"
24
24
 
25
25
  #if !defined(XDIFF_H)
26
26
  #define XDIFF_H
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugged
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0b4
4
+ version: 0.24.0b5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-23 00:00:00.000000000 Z
12
+ date: 2015-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler