rugged 0.21.1b1 → 0.21.1b2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ed02879508a982b7b663a4f5231c57547e41fae
4
- data.tar.gz: d37846bf7d551e08dfea3e9d85df6c7728e6b9c5
3
+ metadata.gz: 6c7f700c66a544556cd950109a76174c81bc1051
4
+ data.tar.gz: cc1d7bdc3d29de80c9dd7e851c6b6661c8b7aa04
5
5
  SHA512:
6
- metadata.gz: 69c90b7d81884a885b6ce51a3343b6220b16e3161b67da4b90c651a8f7cf0a220c9dd4ff9a39b4de976a359479abae266e0f23b80cac35382fd4f7ad9c00134f
7
- data.tar.gz: 42ecdf50faf6fac65888223902d763753df78095af2eeb6d010297541f6d03d1d9ffdf55ec8f786232321fdff4221c25df0c26a7d8f8d5b654a550b04a14d131
6
+ metadata.gz: 544b7008795e5066b76a1fe45345ef2a4f3ed6f9c2e5f387823b8cbbc12bacb1408c99e56a514c800477a3d436e6beccb7c9217fe1b2995977a6938b6a09a13b
7
+ data.tar.gz: fd71862f8cd20de77fd0aff0df25fc2463231e4f179ed735aac142ca0d277178faaab582f9ce58c83bdf718af1eb4ff9f406a97fa1b6ed889bd1f9229febf1ae
@@ -24,6 +24,7 @@
24
24
 
25
25
  #include "rugged.h"
26
26
  #include <ctype.h>
27
+ #include <git2/sys/hashsig.h>
27
28
 
28
29
  extern VALUE rb_mRugged;
29
30
  extern VALUE rb_cRuggedObject;
@@ -31,6 +32,7 @@ extern VALUE rb_cRuggedRepo;
31
32
  static ID id_read;
32
33
 
33
34
  VALUE rb_cRuggedBlob;
35
+ VALUE rb_cRuggedBlobSig;
34
36
 
35
37
  /*
36
38
  * call-seq:
@@ -520,6 +522,57 @@ static VALUE rb_git_blob_to_buffer(int argc, VALUE *argv, VALUE self)
520
522
  return rb_ret;
521
523
  }
522
524
 
525
+ static VALUE rb_git_blob_sig_new(int argc, VALUE *argv, VALUE klass)
526
+ {
527
+ int error, opts = 0;
528
+ git_hashsig *sig;
529
+ VALUE rb_blob, rb_options;
530
+
531
+ if (rb_scan_args(argc, argv, "11", &rb_blob, &rb_options) == 2) {
532
+ Check_Type(rb_options, T_FIXNUM);
533
+ opts = FIX2INT(rb_options);
534
+ }
535
+
536
+ if (rb_obj_is_kind_of(rb_blob, rb_cRuggedBlob)) {
537
+ git_blob *blob;
538
+ Data_Get_Struct(rb_blob, git_blob, blob);
539
+
540
+ error = git_hashsig_create(&sig,
541
+ git_blob_rawcontent(blob),
542
+ git_blob_rawsize(blob),
543
+ opts);
544
+ } else {
545
+ Check_Type(rb_blob, T_STRING);
546
+ error = git_hashsig_create(&sig, RSTRING_PTR(rb_blob), RSTRING_LEN(rb_blob), opts);
547
+ }
548
+
549
+ rugged_exception_check(error);
550
+
551
+ return Data_Wrap_Struct(klass, NULL, &git_hashsig_free, sig);
552
+ }
553
+
554
+ static VALUE rb_git_blob_sig_compare(VALUE self, VALUE rb_sig_a, VALUE rb_sig_b)
555
+ {
556
+ git_hashsig *sig_a;
557
+ git_hashsig *sig_b;
558
+ int result;
559
+
560
+ if (!rb_obj_is_kind_of(rb_sig_a, rb_cRuggedBlobSig) ||
561
+ !rb_obj_is_kind_of(rb_sig_b, rb_cRuggedBlobSig)) {
562
+ rb_raise(rb_eTypeError, "Expected Rugged::Blob::HashSignature");
563
+ }
564
+
565
+ Data_Get_Struct(rb_sig_a, git_hashsig, sig_a);
566
+ Data_Get_Struct(rb_sig_b, git_hashsig, sig_b);
567
+
568
+ result = git_hashsig_compare(sig_a, sig_b);
569
+
570
+ if (result < 0)
571
+ rugged_exception_check(result);
572
+
573
+ return INT2FIX(result);
574
+ }
575
+
523
576
  void Init_rugged_blob(void)
524
577
  {
525
578
  id_read = rb_intern("read");
@@ -539,4 +592,8 @@ void Init_rugged_blob(void)
539
592
  rb_define_singleton_method(rb_cRuggedBlob, "from_io", rb_git_blob_from_io, -1);
540
593
 
541
594
  rb_define_singleton_method(rb_cRuggedBlob, "to_buffer", rb_git_blob_to_buffer, -1);
595
+
596
+ rb_cRuggedBlobSig = rb_define_class_under(rb_cRuggedBlob, "HashSignature", rb_cObject);
597
+ rb_define_singleton_method(rb_cRuggedBlobSig, "new", rb_git_blob_sig_new, -1);
598
+ rb_define_singleton_method(rb_cRuggedBlobSig, "compare", rb_git_blob_sig_compare, 2);
542
599
  }
@@ -19,3 +19,4 @@ require 'rugged/patch'
19
19
  require 'rugged/remote'
20
20
  require 'rugged/credentials'
21
21
  require 'rugged/attributes'
22
+ require 'rugged/blob'
@@ -0,0 +1,28 @@
1
+ module Rugged
2
+ class Blob
3
+ class HashSignature
4
+ WHITESPACE_DEFAULT = 0
5
+ WHITESPACE_IGNORE = 1
6
+ WHITESPACE_SMART = 2
7
+ end
8
+
9
+ def hashsig(options = 0)
10
+ @hashsig ||= HashSignature.new(self, options)
11
+ end
12
+
13
+ def similarity(other)
14
+ other_sig = case other
15
+ when HashSignature
16
+ other
17
+ when String
18
+ HashSignature.new(other)
19
+ when Blob
20
+ other.hashsig
21
+ else
22
+ raise TypeError, "Expected a Rugged::Blob, String or Rugged::Blob::HashSignature"
23
+ end
24
+
25
+ HashSignature.compare(self.hashsig, other_sig)
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Rugged
2
- Version = VERSION = '0.21.1b1'
2
+ Version = VERSION = '0.21.1b2'
3
3
  end
@@ -32,6 +32,7 @@
32
32
  #include "git2/notes.h"
33
33
  #include "git2/object.h"
34
34
  #include "git2/odb.h"
35
+ #include "git2/odb_backend.h"
35
36
  #include "git2/oid.h"
36
37
  #include "git2/pack.h"
37
38
  #include "git2/patch.h"
@@ -4,10 +4,12 @@
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
- #ifndef INCLUDE_hashsig_h__
8
- #define INCLUDE_hashsig_h__
7
+ #ifndef INCLUDE_sys_hashsig_h__
8
+ #define INCLUDE_sys_hashsig_h__
9
9
 
10
- #include "common.h"
10
+ #include "git2/common.h"
11
+
12
+ GIT_BEGIN_DECL
11
13
 
12
14
  /**
13
15
  * Similarity signature of line hashes for a buffer
@@ -35,7 +37,7 @@ typedef enum {
35
37
  * @param buflen The length of the data at `buf`
36
38
  * @param generate_pairwise_hashes Should pairwise runs be hashed
37
39
  */
38
- extern int git_hashsig_create(
40
+ GIT_EXTERN(int) git_hashsig_create(
39
41
  git_hashsig **out,
40
42
  const char *buf,
41
43
  size_t buflen,
@@ -50,7 +52,7 @@ extern int git_hashsig_create(
50
52
  * This will return an error if the file doesn't contain enough data to
51
53
  * compute a valid signature.
52
54
  */
53
- extern int git_hashsig_create_fromfile(
55
+ GIT_EXTERN(int) git_hashsig_create_fromfile(
54
56
  git_hashsig **out,
55
57
  const char *path,
56
58
  git_hashsig_option_t opts);
@@ -58,15 +60,17 @@ extern int git_hashsig_create_fromfile(
58
60
  /**
59
61
  * Release memory for a content similarity signature
60
62
  */
61
- extern void git_hashsig_free(git_hashsig *sig);
63
+ GIT_EXTERN(void) git_hashsig_free(git_hashsig *sig);
62
64
 
63
65
  /**
64
66
  * Measure similarity between two files
65
67
  *
66
68
  * @return <0 for error, [0 to 100] as similarity score
67
69
  */
68
- extern int git_hashsig_compare(
70
+ GIT_EXTERN(int) git_hashsig_compare(
69
71
  const git_hashsig *a,
70
72
  const git_hashsig *b);
71
73
 
74
+ GIT_END_DECL
75
+
72
76
  #endif
@@ -35,6 +35,14 @@
35
35
  # define GIT_TYPEOF(x)
36
36
  #endif
37
37
 
38
+ #if defined(__GNUC__)
39
+ # define GIT_ALIGN(x,size) x __attribute__ ((aligned(size)))
40
+ #elif defined(_MSC_VER)
41
+ # define GIT_ALIGN(x,size) __declspec(align(size)) x
42
+ #else
43
+ # define GIT_ALIGN(x,size) x
44
+ #endif
45
+
38
46
  #define GIT_UNUSED(x) ((void)(x))
39
47
 
40
48
  /* Define the printf format specifer to use for size_t output */
@@ -274,6 +274,7 @@ int git_diff_foreach(
274
274
  return error;
275
275
 
276
276
  memset(&xo, 0, sizeof(xo));
277
+ memset(&patch, 0, sizeof(patch));
277
278
  diff_output_init(
278
279
  &xo.output, &diff->opts, file_cb, hunk_cb, data_cb, payload);
279
280
  git_xdiff_init(&xo, &diff->opts);
@@ -8,9 +8,9 @@
8
8
 
9
9
  #include "git2/config.h"
10
10
  #include "git2/blob.h"
11
+ #include "git2/sys/hashsig.h"
11
12
 
12
13
  #include "diff.h"
13
- #include "hashsig.h"
14
14
  #include "path.h"
15
15
  #include "fileops.h"
16
16
  #include "config.h"
@@ -223,6 +223,9 @@ int init_error = 0;
223
223
 
224
224
  static void cb__free_status(void *st)
225
225
  {
226
+ git_global_st *state = (git_global_st *) st;
227
+ git__free(state->error_t.message);
228
+
226
229
  git__free(st);
227
230
  }
228
231
 
@@ -7,13 +7,14 @@
7
7
  #ifndef INCLUDE_global_h__
8
8
  #define INCLUDE_global_h__
9
9
 
10
+ #include "common.h"
10
11
  #include "mwindow.h"
11
12
  #include "hash.h"
12
13
 
13
14
  typedef struct {
14
15
  git_error *last_error;
15
16
  git_error error_t;
16
- char oid_fmt[41];
17
+ char oid_fmt[GIT_OID_HEXSZ+1];
17
18
  } git_global_st;
18
19
 
19
20
  #ifdef GIT_SSL
@@ -4,7 +4,7 @@
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
- #include "hashsig.h"
7
+ #include "git2/sys/hashsig.h"
8
8
  #include "fileops.h"
9
9
  #include "util.h"
10
10
 
@@ -1767,35 +1767,42 @@ static size_t read_entry(
1767
1767
  git_index_entry **out, const void *buffer, size_t buffer_size)
1768
1768
  {
1769
1769
  size_t path_length, entry_size;
1770
- uint16_t flags_raw;
1771
1770
  const char *path_ptr;
1772
- const struct entry_short *source = buffer;
1771
+ struct entry_short source;
1773
1772
  git_index_entry entry = {{0}};
1774
1773
 
1775
1774
  if (INDEX_FOOTER_SIZE + minimal_entry_size > buffer_size)
1776
1775
  return 0;
1777
1776
 
1778
- entry.ctime.seconds = (git_time_t)ntohl(source->ctime.seconds);
1779
- entry.ctime.nanoseconds = ntohl(source->ctime.nanoseconds);
1780
- entry.mtime.seconds = (git_time_t)ntohl(source->mtime.seconds);
1781
- entry.mtime.nanoseconds = ntohl(source->mtime.nanoseconds);
1782
- entry.dev = ntohl(source->dev);
1783
- entry.ino = ntohl(source->ino);
1784
- entry.mode = ntohl(source->mode);
1785
- entry.uid = ntohl(source->uid);
1786
- entry.gid = ntohl(source->gid);
1787
- entry.file_size = ntohl(source->file_size);
1788
- git_oid_cpy(&entry.id, &source->oid);
1789
- entry.flags = ntohs(source->flags);
1777
+ /* buffer is not guaranteed to be aligned */
1778
+ memcpy(&source, buffer, sizeof(struct entry_short));
1779
+
1780
+ entry.ctime.seconds = (git_time_t)ntohl(source.ctime.seconds);
1781
+ entry.ctime.nanoseconds = ntohl(source.ctime.nanoseconds);
1782
+ entry.mtime.seconds = (git_time_t)ntohl(source.mtime.seconds);
1783
+ entry.mtime.nanoseconds = ntohl(source.mtime.nanoseconds);
1784
+ entry.dev = ntohl(source.dev);
1785
+ entry.ino = ntohl(source.ino);
1786
+ entry.mode = ntohl(source.mode);
1787
+ entry.uid = ntohl(source.uid);
1788
+ entry.gid = ntohl(source.gid);
1789
+ entry.file_size = ntohl(source.file_size);
1790
+ git_oid_cpy(&entry.id, &source.oid);
1791
+ entry.flags = ntohs(source.flags);
1790
1792
 
1791
1793
  if (entry.flags & GIT_IDXENTRY_EXTENDED) {
1792
- const struct entry_long *source_l = (const struct entry_long *)source;
1793
- path_ptr = source_l->path;
1794
+ uint16_t flags_raw;
1795
+ size_t flags_offset;
1794
1796
 
1795
- flags_raw = ntohs(source_l->flags_extended);
1796
- memcpy(&entry.flags_extended, &flags_raw, 2);
1797
+ flags_offset = offsetof(struct entry_long, flags_extended);
1798
+ memcpy(&flags_raw, (const char *) buffer + flags_offset,
1799
+ sizeof(flags_raw));
1800
+ flags_raw = ntohs(flags_raw);
1801
+
1802
+ memcpy(&entry.flags_extended, &flags_raw, sizeof(flags_raw));
1803
+ path_ptr = (const char *) buffer + offsetof(struct entry_long, path);
1797
1804
  } else
1798
- path_ptr = source->path;
1805
+ path_ptr = (const char *) buffer + offsetof(struct entry_short, path);
1799
1806
 
1800
1807
  path_length = entry.flags & GIT_IDXENTRY_NAMEMASK;
1801
1808
 
@@ -1846,14 +1853,12 @@ static int read_header(struct index_header *dest, const void *buffer)
1846
1853
 
1847
1854
  static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size)
1848
1855
  {
1849
- const struct index_extension *source;
1850
1856
  struct index_extension dest;
1851
1857
  size_t total_size;
1852
1858
 
1853
- source = (const struct index_extension *)(buffer);
1854
-
1855
- memcpy(dest.signature, source->signature, 4);
1856
- dest.extension_size = ntohl(source->extension_size);
1859
+ /* buffer is not guaranteed to be aligned */
1860
+ memcpy(&dest, buffer, sizeof(struct index_extension));
1861
+ dest.extension_size = ntohl(dest.extension_size);
1857
1862
 
1858
1863
  total_size = dest.extension_size + sizeof(struct index_extension);
1859
1864
 
@@ -22,7 +22,6 @@
22
22
  #include "tree.h"
23
23
  #include "merge_file.h"
24
24
  #include "blob.h"
25
- #include "hashsig.h"
26
25
  #include "oid.h"
27
26
  #include "index.h"
28
27
  #include "filebuf.h"
@@ -42,6 +41,7 @@
42
41
  #include "git2/tree.h"
43
42
  #include "git2/oidarray.h"
44
43
  #include "git2/sys/index.h"
44
+ #include "git2/sys/hashsig.h"
45
45
 
46
46
  #define GIT_MERGE_INDEX_ENTRY_EXISTS(X) ((X).mode != 0)
47
47
  #define GIT_MERGE_INDEX_ENTRY_ISFILE(X) S_ISREG((X).mode)
@@ -458,7 +458,7 @@ int gitno_connect(gitno_socket *s_out, const char *host, const char *port, int f
458
458
  hints.ai_socktype = SOCK_STREAM;
459
459
  hints.ai_family = AF_UNSPEC;
460
460
 
461
- if ((ret = p_getaddrinfo(host, port, &hints, &info)) < 0) {
461
+ if ((ret = p_getaddrinfo(host, port, &hints, &info)) != 0) {
462
462
  giterr_set(GITERR_NET,
463
463
  "Failed to resolve address for %s: %s", host, p_gai_strerror(ret));
464
464
  return -1;
@@ -714,7 +714,7 @@ struct foreach_state {
714
714
  GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr)
715
715
  {
716
716
  int v, i = 0;
717
- if (strlen(ptr) != 41)
717
+ if (strlen(ptr) != GIT_OID_HEXSZ+1)
718
718
  return -1;
719
719
 
720
720
  if (ptr[2] != '/') {
@@ -620,7 +620,7 @@ int git_packfile_unpack(
620
620
  struct pack_chain_elem *elem = NULL, *stack;
621
621
  git_pack_cache_entry *cached = NULL;
622
622
  struct pack_chain_elem small_stack[SMALL_STACK_SIZE];
623
- size_t stack_size, elem_pos;
623
+ size_t stack_size = 0, elem_pos;
624
624
  git_otype base_type;
625
625
 
626
626
  /*
@@ -768,7 +768,7 @@ int git_path_cmp(
768
768
  int git_path_make_relative(git_buf *path, const char *parent)
769
769
  {
770
770
  const char *p, *q, *p_dirsep, *q_dirsep;
771
- size_t plen = path->size, newlen, depth = 1, i;
771
+ size_t plen = path->size, newlen, depth = 1, i, offset;
772
772
 
773
773
  for (p_dirsep = p = path->ptr, q_dirsep = q = parent; *p && *q; p++, q++) {
774
774
  if (*p == '/' && *q == '/') {
@@ -808,8 +808,11 @@ int git_path_make_relative(git_buf *path, const char *parent)
808
808
 
809
809
  newlen = (depth * 3) + plen;
810
810
 
811
+ /* save the offset as we might realllocate the pointer */
812
+ offset = p - path->ptr;
811
813
  if (git_buf_try_grow(path, newlen + 1, 1, 0) < 0)
812
814
  return -1;
815
+ p = path->ptr + offset;
813
816
 
814
817
  memmove(path->ptr + (depth * 3), p, plen + 1);
815
818
 
@@ -7,7 +7,7 @@ struct git_pool_page {
7
7
  git_pool_page *next;
8
8
  uint32_t size;
9
9
  uint32_t avail;
10
- char data[GIT_FLEX_ARRAY];
10
+ GIT_ALIGN(char data[GIT_FLEX_ARRAY], 8);
11
11
  };
12
12
 
13
13
  struct pool_freelist {
@@ -232,7 +232,8 @@ static int build_untracked_tree(
232
232
  }
233
233
 
234
234
  if (flags & GIT_STASH_INCLUDE_IGNORED) {
235
- opts.flags |= GIT_DIFF_INCLUDE_IGNORED;
235
+ opts.flags |= GIT_DIFF_INCLUDE_IGNORED |
236
+ GIT_DIFF_RECURSE_IGNORED_DIRS;
236
237
  data.include_ignored = true;
237
238
  }
238
239
 
@@ -447,10 +448,11 @@ static int ensure_there_are_changes_to_stash(
447
448
 
448
449
  if (include_untracked_files)
449
450
  opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED |
450
- GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
451
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
451
452
 
452
453
  if (include_ignored_files)
453
- opts.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED;
454
+ opts.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED |
455
+ GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
454
456
 
455
457
  error = git_status_foreach_ext(repo, &opts, is_dirty_cb, NULL);
456
458
 
@@ -640,9 +640,9 @@ static int gen_pktline(git_buf *buf, git_push *push)
640
640
  {
641
641
  push_spec *spec;
642
642
  size_t i, len;
643
- char old_id[41], new_id[41];
643
+ char old_id[GIT_OID_HEXSZ+1], new_id[GIT_OID_HEXSZ+1];
644
644
 
645
- old_id[40] = '\0'; new_id[40] = '\0';
645
+ old_id[GIT_OID_HEXSZ] = '\0'; new_id[GIT_OID_HEXSZ] = '\0';
646
646
 
647
647
  git_vector_foreach(&push->specs, i, spec) {
648
648
  len = 2*GIT_OID_HEXSZ + 7 + strlen(spec->rref);
@@ -963,7 +963,7 @@ int git_smart__push(git_transport *transport, git_push *push)
963
963
  #ifdef PUSH_DEBUG
964
964
  {
965
965
  git_remote_head *head;
966
- char hex[41]; hex[40] = '\0';
966
+ char hex[GIT_OID_HEXSZ+1]; hex[GIT_OID_HEXSZ] = '\0';
967
967
 
968
968
  git_vector_foreach(&push->remote->refs, i, head) {
969
969
  git_oid_fmt(hex, &head->oid);
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.21.1b1
4
+ version: 0.21.1b2
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: 2014-09-17 00:00:00.000000000 Z
12
+ date: 2014-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
@@ -95,6 +95,7 @@ files:
95
95
  - ext/rugged/rugged_tree.c
96
96
  - lib/rugged.rb
97
97
  - lib/rugged/attributes.rb
98
+ - lib/rugged/blob.rb
98
99
  - lib/rugged/branch.rb
99
100
  - lib/rugged/commit.rb
100
101
  - lib/rugged/console.rb
@@ -205,6 +206,7 @@ files:
205
206
  - vendor/libgit2/include/git2/sys/config.h
206
207
  - vendor/libgit2/include/git2/sys/diff.h
207
208
  - vendor/libgit2/include/git2/sys/filter.h
209
+ - vendor/libgit2/include/git2/sys/hashsig.h
208
210
  - vendor/libgit2/include/git2/sys/index.h
209
211
  - vendor/libgit2/include/git2/sys/mempack.h
210
212
  - vendor/libgit2/include/git2/sys/odb_backend.h
@@ -303,7 +305,6 @@ files:
303
305
  - vendor/libgit2/src/hash/hash_win32.c
304
306
  - vendor/libgit2/src/hash/hash_win32.h
305
307
  - vendor/libgit2/src/hashsig.c
306
- - vendor/libgit2/src/hashsig.h
307
308
  - vendor/libgit2/src/ident.c
308
309
  - vendor/libgit2/src/ignore.c
309
310
  - vendor/libgit2/src/ignore.h