rugged 0.21.1b2 → 0.21.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -12
- data/ext/rugged/extconf.rb +8 -8
- data/ext/rugged/rugged.h +1 -1
- data/ext/rugged/rugged_blob.c +0 -57
- data/ext/rugged/rugged_cred.c +0 -23
- data/ext/rugged/rugged_index.c +2 -6
- data/ext/rugged/rugged_remote.c +1 -69
- data/ext/rugged/rugged_repo.c +5 -287
- data/ext/rugged/rugged_tag_collection.c +2 -70
- data/ext/rugged/rugged_tree.c +10 -29
- data/lib/rugged.rb +0 -2
- data/lib/rugged/diff.rb +1 -0
- data/lib/rugged/diff/line.rb +3 -1
- data/lib/rugged/patch.rb +2 -12
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +0 -11
- data/vendor/libgit2/deps/http-parser/http_parser.h +0 -2
- data/vendor/libgit2/deps/zlib/adler32.c +29 -39
- data/vendor/libgit2/deps/zlib/crc32.c +50 -33
- data/vendor/libgit2/deps/zlib/crc32.h +1 -1
- data/vendor/libgit2/deps/zlib/deflate.c +65 -198
- data/vendor/libgit2/deps/zlib/deflate.h +4 -8
- data/vendor/libgit2/deps/zlib/inffast.c +3 -3
- data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
- data/vendor/libgit2/deps/zlib/inflate.c +52 -84
- data/vendor/libgit2/deps/zlib/inftrees.c +39 -15
- data/vendor/libgit2/deps/zlib/trees.c +36 -18
- data/vendor/libgit2/deps/zlib/zconf.h +0 -4
- data/vendor/libgit2/deps/zlib/zlib.h +95 -250
- data/vendor/libgit2/deps/zlib/zutil.c +10 -13
- data/vendor/libgit2/deps/zlib/zutil.h +62 -41
- data/vendor/libgit2/include/git2/attr.h +13 -16
- data/vendor/libgit2/include/git2/buffer.h +0 -16
- data/vendor/libgit2/include/git2/checkout.h +12 -12
- data/vendor/libgit2/include/git2/cherrypick.h +15 -15
- data/vendor/libgit2/include/git2/clone.h +69 -77
- data/vendor/libgit2/include/git2/diff.h +0 -7
- data/vendor/libgit2/include/git2/errors.h +0 -2
- data/vendor/libgit2/include/git2/merge.h +0 -16
- data/vendor/libgit2/include/git2/oid.h +4 -8
- data/vendor/libgit2/include/git2/remote.h +32 -13
- data/vendor/libgit2/include/git2/repository.h +1 -4
- data/vendor/libgit2/include/git2/reset.h +0 -4
- data/vendor/libgit2/include/git2/revert.h +1 -1
- data/vendor/libgit2/include/git2/status.h +14 -17
- data/vendor/libgit2/include/git2/submodule.h +0 -18
- data/vendor/libgit2/include/git2/sys/repository.h +0 -13
- data/vendor/libgit2/include/git2/transport.h +313 -79
- data/vendor/libgit2/include/git2/tree.h +2 -4
- data/vendor/libgit2/include/git2/types.h +6 -54
- data/vendor/libgit2/include/git2/version.h +2 -2
- data/vendor/libgit2/src/attr.c +4 -8
- data/vendor/libgit2/src/attr_file.c +1 -14
- data/vendor/libgit2/src/blame.c +1 -0
- data/vendor/libgit2/src/buf_text.c +5 -9
- data/vendor/libgit2/src/buf_text.h +2 -3
- data/vendor/libgit2/src/buffer.c +10 -67
- data/vendor/libgit2/src/buffer.h +2 -4
- data/vendor/libgit2/src/cache.c +9 -9
- data/vendor/libgit2/src/cache.h +1 -1
- data/vendor/libgit2/src/checkout.c +44 -121
- data/vendor/libgit2/src/cherrypick.c +44 -41
- data/vendor/libgit2/src/clone.c +56 -94
- data/vendor/libgit2/src/config_file.c +7 -2
- data/vendor/libgit2/src/crlf.c +1 -2
- data/vendor/libgit2/src/diff.c +0 -21
- data/vendor/libgit2/src/diff_file.c +0 -1
- data/vendor/libgit2/src/diff_print.c +9 -11
- data/vendor/libgit2/src/diff_tform.c +2 -4
- data/vendor/libgit2/src/errors.c +7 -9
- data/vendor/libgit2/src/filebuf.c +2 -0
- data/vendor/libgit2/src/fileops.c +7 -9
- data/vendor/libgit2/src/filter.c +11 -2
- data/vendor/libgit2/src/global.c +20 -3
- data/vendor/libgit2/src/global.h +0 -2
- data/vendor/libgit2/src/graph.c +2 -2
- data/vendor/libgit2/src/hashsig.c +1 -1
- data/vendor/libgit2/{include/git2/sys → src}/hashsig.h +7 -11
- data/vendor/libgit2/src/ignore.c +2 -2
- data/vendor/libgit2/src/indexer.c +1 -13
- data/vendor/libgit2/src/merge.c +145 -99
- data/vendor/libgit2/src/merge.h +1 -1
- data/vendor/libgit2/src/mwindow.c +8 -117
- data/vendor/libgit2/src/mwindow.h +1 -9
- data/vendor/libgit2/src/netops.c +7 -6
- data/vendor/libgit2/src/netops.h +4 -0
- data/vendor/libgit2/src/odb_loose.c +1 -1
- data/vendor/libgit2/src/odb_pack.c +3 -6
- data/vendor/libgit2/src/oid.c +0 -8
- data/vendor/libgit2/src/oid.h +0 -11
- data/vendor/libgit2/src/pack.c +6 -20
- data/vendor/libgit2/src/pack.h +0 -3
- data/vendor/libgit2/src/path.c +64 -134
- data/vendor/libgit2/src/path.h +1 -22
- data/vendor/libgit2/src/posix.h +28 -46
- data/vendor/libgit2/src/refs.h +2 -2
- data/vendor/libgit2/src/refspec.c +2 -14
- data/vendor/libgit2/src/remote.c +26 -29
- data/vendor/libgit2/src/remote.h +1 -3
- data/vendor/libgit2/src/repository.c +14 -54
- data/vendor/libgit2/src/revert.c +6 -4
- data/vendor/libgit2/src/revparse.c +18 -15
- data/vendor/libgit2/src/signature.c +2 -2
- data/vendor/libgit2/src/stash.c +1 -2
- data/vendor/libgit2/src/status.c +2 -11
- data/vendor/libgit2/src/strnlen.h +1 -2
- data/vendor/libgit2/src/submodule.c +33 -73
- data/vendor/libgit2/src/tag.c +3 -2
- data/vendor/libgit2/src/thread-utils.h +7 -0
- data/vendor/libgit2/src/trace.h +1 -9
- data/vendor/libgit2/src/transport.c +90 -93
- data/vendor/libgit2/src/transports/cred.c +0 -58
- data/vendor/libgit2/src/transports/cred_helpers.c +0 -3
- data/vendor/libgit2/src/transports/git.c +0 -1
- data/vendor/libgit2/src/transports/http.c +82 -205
- data/vendor/libgit2/src/transports/smart.c +0 -2
- data/vendor/libgit2/src/transports/smart.h +0 -2
- data/vendor/libgit2/src/transports/smart_protocol.c +5 -7
- data/vendor/libgit2/src/transports/ssh.c +35 -224
- data/vendor/libgit2/src/transports/winhttp.c +34 -140
- data/vendor/libgit2/src/tree.c +60 -64
- data/vendor/libgit2/src/tree.h +3 -2
- data/vendor/libgit2/src/unix/posix.h +9 -23
- data/vendor/libgit2/src/unix/realpath.c +7 -8
- data/vendor/libgit2/src/util.c +1 -2
- data/vendor/libgit2/src/util.h +3 -3
- data/vendor/libgit2/src/win32/mingw-compat.h +12 -5
- data/vendor/libgit2/src/win32/msvc-compat.h +32 -3
- data/vendor/libgit2/src/win32/posix.h +31 -20
- data/vendor/libgit2/src/win32/posix_w32.c +18 -62
- metadata +5 -18
- data/lib/rugged/attributes.rb +0 -41
- data/lib/rugged/blob.rb +0 -28
- data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +0 -324
- data/vendor/libgit2/deps/zlib/infback.c +0 -640
- data/vendor/libgit2/include/git2/oidarray.h +0 -40
- data/vendor/libgit2/include/git2/sys/transport.h +0 -352
- data/vendor/libgit2/src/oidarray.c +0 -21
- data/vendor/libgit2/src/oidarray.h +0 -18
- data/vendor/libgit2/src/transports/auth.c +0 -71
- data/vendor/libgit2/src/transports/auth.h +0 -63
- data/vendor/libgit2/src/transports/auth_negotiate.c +0 -275
- data/vendor/libgit2/src/transports/auth_negotiate.h +0 -27
- data/vendor/libgit2/src/transports/cred.h +0 -14
@@ -177,73 +177,6 @@ static VALUE rb_git_tag_collection_create(int argc, VALUE *argv, VALUE self)
|
|
177
177
|
return rb_git_tag_collection_aref(self, rb_name);
|
178
178
|
}
|
179
179
|
|
180
|
-
/*
|
181
|
-
* call-seq:
|
182
|
-
* tags.create_annotation(name, target, annotation) -> annotation
|
183
|
-
*
|
184
|
-
* Create a new annotated tag object with the specified +name+ on +target+ in
|
185
|
-
* +repo+.
|
186
|
-
*
|
187
|
-
* Unlike the +create+ method, +create_annotation+ simply creates a tag
|
188
|
-
* object. It does not write a tag ref.
|
189
|
-
*
|
190
|
-
* +annotation+ must have the following keys:
|
191
|
-
*
|
192
|
-
* :tagger ::
|
193
|
-
* An optional Hash containing a git signature. Defaults to the signature
|
194
|
-
* from the configuration if only `:message` is given. Will cause the
|
195
|
-
* creation of an annotated tag object if present.
|
196
|
-
*
|
197
|
-
* :message ::
|
198
|
-
* An optional string containing the message for the new tag.
|
199
|
-
*
|
200
|
-
* Returns an instance of Rugged::Tag::Annotation representing the newly
|
201
|
-
* created annotation.
|
202
|
-
*/
|
203
|
-
static VALUE rb_git_tag_collection_create_annotation(VALUE self, VALUE rb_name, VALUE rb_target, VALUE rb_annotation)
|
204
|
-
{
|
205
|
-
git_oid tag_oid;
|
206
|
-
git_repository *repo = NULL;
|
207
|
-
git_object *target = NULL, *tag = NULL;
|
208
|
-
git_signature *tagger = NULL;
|
209
|
-
VALUE rb_message;
|
210
|
-
int error;
|
211
|
-
|
212
|
-
VALUE rb_repo = rugged_owner(self);
|
213
|
-
rugged_check_repo(rb_repo);
|
214
|
-
Data_Get_Struct(rb_repo, git_repository, repo);
|
215
|
-
|
216
|
-
Check_Type(rb_name, T_STRING);
|
217
|
-
|
218
|
-
target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);
|
219
|
-
|
220
|
-
rb_message = rb_hash_aref(rb_annotation, CSTR2SYM("message"));
|
221
|
-
Check_Type(rb_message, T_STRING);
|
222
|
-
|
223
|
-
tagger = rugged_signature_get(
|
224
|
-
rb_hash_aref(rb_annotation, CSTR2SYM("tagger")), repo
|
225
|
-
);
|
226
|
-
|
227
|
-
error = git_tag_annotation_create(
|
228
|
-
&tag_oid,
|
229
|
-
repo,
|
230
|
-
StringValueCStr(rb_name),
|
231
|
-
target,
|
232
|
-
tagger,
|
233
|
-
StringValueCStr(rb_message)
|
234
|
-
);
|
235
|
-
|
236
|
-
git_object_free(target);
|
237
|
-
git_signature_free(tagger);
|
238
|
-
|
239
|
-
rugged_exception_check(error);
|
240
|
-
|
241
|
-
error = git_object_lookup(&tag, repo, &tag_oid, GIT_OBJ_TAG);
|
242
|
-
rugged_exception_check(error);
|
243
|
-
|
244
|
-
return rugged_object_new(rb_repo, tag);
|
245
|
-
}
|
246
|
-
|
247
180
|
static VALUE each_tag(int argc, VALUE *argv, VALUE self, int tag_names_only)
|
248
181
|
{
|
249
182
|
git_repository *repo;
|
@@ -336,9 +269,8 @@ void Init_rugged_tag_collection(void)
|
|
336
269
|
|
337
270
|
rb_define_method(rb_cRuggedTagCollection, "initialize", rb_git_tag_collection_initialize, 1);
|
338
271
|
|
339
|
-
rb_define_method(rb_cRuggedTagCollection, "create",
|
340
|
-
rb_define_method(rb_cRuggedTagCollection, "
|
341
|
-
rb_define_method(rb_cRuggedTagCollection, "[]", rb_git_tag_collection_aref, 1);
|
272
|
+
rb_define_method(rb_cRuggedTagCollection, "create", rb_git_tag_collection_create, -1);
|
273
|
+
rb_define_method(rb_cRuggedTagCollection, "[]", rb_git_tag_collection_aref, 1);
|
342
274
|
|
343
275
|
rb_define_method(rb_cRuggedTagCollection, "each", rb_git_tag_collection_each, -1);
|
344
276
|
rb_define_method(rb_cRuggedTagCollection, "each_name", rb_git_tag_collection_each_name, -1);
|
data/ext/rugged/rugged_tree.c
CHANGED
@@ -188,26 +188,14 @@ static VALUE rb_git_tree_each(VALUE self)
|
|
188
188
|
return Qnil;
|
189
189
|
}
|
190
190
|
|
191
|
-
static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, void *
|
191
|
+
static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, void *proc)
|
192
192
|
{
|
193
|
-
|
193
|
+
rb_funcall((VALUE)proc, rb_intern("call"), 2,
|
194
|
+
rb_str_new_utf8(root),
|
195
|
+
rb_git_treeentry_fromC(entry)
|
196
|
+
);
|
194
197
|
|
195
|
-
|
196
|
-
|
197
|
-
rb_ary_push(rb_args, rb_str_new_utf8(root));
|
198
|
-
rb_ary_push(rb_args, rb_git_treeentry_fromC(entry));
|
199
|
-
|
200
|
-
rb_result = rb_protect(rb_yield_splat, rb_args, exception);
|
201
|
-
|
202
|
-
if (*exception)
|
203
|
-
return -1;
|
204
|
-
|
205
|
-
/* skip entry when 'false' is returned */
|
206
|
-
if (TYPE(rb_result) == T_FALSE)
|
207
|
-
return 1;
|
208
|
-
|
209
|
-
/* otherwise continue normal iteration */
|
210
|
-
return 0;
|
198
|
+
return GIT_OK;
|
211
199
|
}
|
212
200
|
|
213
201
|
/*
|
@@ -220,9 +208,6 @@ static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, vo
|
|
220
208
|
* also takes a +root+, the relative path in the traversal, starting from the root
|
221
209
|
* of the original tree.
|
222
210
|
*
|
223
|
-
* If the +block+ returns a falsy value, that entry and its sub-entries (in the case
|
224
|
-
* of a folder) will be skipped for the iteration.
|
225
|
-
*
|
226
211
|
* If no +block+ is given, an +Iterator+ is returned instead.
|
227
212
|
*
|
228
213
|
* tree.walk(:postorder) { |root, entry| puts "#{root}#{entry[:name]} [#{entry[:oid]}]" }
|
@@ -238,7 +223,7 @@ static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, vo
|
|
238
223
|
static VALUE rb_git_tree_walk(VALUE self, VALUE rb_mode)
|
239
224
|
{
|
240
225
|
git_tree *tree;
|
241
|
-
int error, mode = 0
|
226
|
+
int error, mode = 0;
|
242
227
|
ID id_mode;
|
243
228
|
|
244
229
|
Data_Get_Struct(self, git_tree, tree);
|
@@ -257,11 +242,7 @@ static VALUE rb_git_tree_walk(VALUE self, VALUE rb_mode)
|
|
257
242
|
rb_raise(rb_eTypeError,
|
258
243
|
"Invalid iteration mode. Expected `:preorder` or `:postorder`");
|
259
244
|
|
260
|
-
error = git_tree_walk(tree, mode, &rugged__treewalk_cb, (void *)
|
261
|
-
|
262
|
-
if (exception)
|
263
|
-
rb_jump_tag(exception);
|
264
|
-
|
245
|
+
error = git_tree_walk(tree, mode, &rugged__treewalk_cb, (void *)rb_block_proc());
|
265
246
|
rugged_exception_check(error);
|
266
247
|
|
267
248
|
return Qnil;
|
@@ -473,7 +454,7 @@ static VALUE rb_git_tree_diff_(int argc, VALUE *argv, VALUE self)
|
|
473
454
|
xfree(opts.pathspec.strings);
|
474
455
|
rugged_exception_check(error);
|
475
456
|
|
476
|
-
return rugged_diff_new(rb_cRuggedDiff,
|
457
|
+
return rugged_diff_new(rb_cRuggedDiff, self, diff);
|
477
458
|
}
|
478
459
|
|
479
460
|
/*
|
@@ -508,7 +489,7 @@ static VALUE rb_git_tree_diff_workdir(int argc, VALUE *argv, VALUE self)
|
|
508
489
|
xfree(opts.pathspec.strings);
|
509
490
|
rugged_exception_check(error);
|
510
491
|
|
511
|
-
return rugged_diff_new(rb_cRuggedDiff,
|
492
|
+
return rugged_diff_new(rb_cRuggedDiff, self, diff);
|
512
493
|
}
|
513
494
|
|
514
495
|
void rugged_parse_merge_options(git_merge_options *opts, VALUE rb_options)
|
data/lib/rugged.rb
CHANGED
data/lib/rugged/diff.rb
CHANGED
data/lib/rugged/diff/line.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Rugged
|
2
2
|
class Diff
|
3
3
|
class Line
|
4
|
-
attr_reader :line_origin, :content, :old_lineno, :new_lineno, :content_offset
|
4
|
+
attr_reader :line_origin, :content, :owner, :old_lineno, :new_lineno, :content_offset
|
5
|
+
|
6
|
+
alias hunk owner
|
5
7
|
|
6
8
|
def context?
|
7
9
|
@line_origin == :context
|
data/lib/rugged/patch.rb
CHANGED
@@ -13,19 +13,9 @@ module Rugged
|
|
13
13
|
"#<#{self.class.name}:#{object_id}>"
|
14
14
|
end
|
15
15
|
|
16
|
-
# Returns the number of
|
17
|
-
def additions
|
18
|
-
stat[0]
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns the number of deletions in the patch.
|
22
|
-
def deletions
|
23
|
-
stat[1]
|
24
|
-
end
|
25
|
-
|
26
|
-
# Returns the number of total changes in the patch.
|
16
|
+
# Returns the number of changes in the patch.
|
27
17
|
def changes
|
28
|
-
|
18
|
+
stat.reduce { |t,v| t + v }
|
29
19
|
end
|
30
20
|
|
31
21
|
# Returns an Array containing all hunks of the patch.
|
data/lib/rugged/version.rb
CHANGED
@@ -36,7 +36,6 @@ OPTION( ANDROID "Build for android NDK" OFF )
|
|
36
36
|
|
37
37
|
OPTION( USE_ICONV "Link with and use iconv library" OFF )
|
38
38
|
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
|
39
|
-
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
|
40
39
|
OPTION( VALGRIND "Configure build for valgrind" OFF )
|
41
40
|
|
42
41
|
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
@@ -209,14 +208,6 @@ IF (LIBSSH2_FOUND)
|
|
209
208
|
SET(SSH_LIBRARIES ${LIBSSH2_LIBRARIES})
|
210
209
|
ENDIF()
|
211
210
|
|
212
|
-
# Optional external dependency: libgssapi
|
213
|
-
IF (USE_GSSAPI)
|
214
|
-
FIND_PACKAGE(GSSAPI)
|
215
|
-
ENDIF()
|
216
|
-
IF (GSSAPI_FOUND)
|
217
|
-
ADD_DEFINITIONS(-DGIT_GSSAPI)
|
218
|
-
ENDIF()
|
219
|
-
|
220
211
|
# Optional external dependency: iconv
|
221
212
|
IF (USE_ICONV)
|
222
213
|
FIND_PACKAGE(Iconv)
|
@@ -396,7 +387,6 @@ ENDIF()
|
|
396
387
|
ADD_LIBRARY(git2 ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SHA1} ${WIN_RC})
|
397
388
|
TARGET_LINK_LIBRARIES(git2 ${SSL_LIBRARIES})
|
398
389
|
TARGET_LINK_LIBRARIES(git2 ${SSH_LIBRARIES})
|
399
|
-
TARGET_LINK_LIBRARIES(git2 ${GSSAPI_LIBRARIES})
|
400
390
|
TARGET_LINK_LIBRARIES(git2 ${ICONV_LIBRARIES})
|
401
391
|
TARGET_OS_LIBRARIES(git2)
|
402
392
|
|
@@ -463,7 +453,6 @@ IF (BUILD_CLAR)
|
|
463
453
|
|
464
454
|
TARGET_LINK_LIBRARIES(libgit2_clar ${SSL_LIBRARIES})
|
465
455
|
TARGET_LINK_LIBRARIES(libgit2_clar ${SSH_LIBRARIES})
|
466
|
-
TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES})
|
467
456
|
TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES})
|
468
457
|
TARGET_OS_LIBRARIES(libgit2_clar)
|
469
458
|
MSVC_SPLIT_SOURCES(libgit2_clar)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
2
|
-
* Copyright (C) 1995-
|
2
|
+
* Copyright (C) 1995-2007 Mark Adler
|
3
3
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
4
|
*/
|
5
5
|
|
@@ -9,9 +9,9 @@
|
|
9
9
|
|
10
10
|
#define local static
|
11
11
|
|
12
|
-
local uLong adler32_combine_
|
12
|
+
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
|
13
13
|
|
14
|
-
#define BASE
|
14
|
+
#define BASE 65521UL /* largest prime smaller than 65536 */
|
15
15
|
#define NMAX 5552
|
16
16
|
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
17
17
|
|
@@ -21,44 +21,39 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
|
21
21
|
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
22
22
|
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
23
23
|
|
24
|
-
/* use NO_DIVIDE if your processor does not do division in hardware
|
25
|
-
try it both ways to see which is faster */
|
24
|
+
/* use NO_DIVIDE if your processor does not do division in hardware */
|
26
25
|
#ifdef NO_DIVIDE
|
27
|
-
|
28
|
-
(thank you to John Reiser for pointing this out) */
|
29
|
-
# define CHOP(a) \
|
30
|
-
do { \
|
31
|
-
unsigned long tmp = a >> 16; \
|
32
|
-
a &= 0xffffUL; \
|
33
|
-
a += (tmp << 4) - tmp; \
|
34
|
-
} while (0)
|
35
|
-
# define MOD28(a) \
|
26
|
+
# define MOD(a) \
|
36
27
|
do { \
|
37
|
-
|
28
|
+
if (a >= (BASE << 16)) a -= (BASE << 16); \
|
29
|
+
if (a >= (BASE << 15)) a -= (BASE << 15); \
|
30
|
+
if (a >= (BASE << 14)) a -= (BASE << 14); \
|
31
|
+
if (a >= (BASE << 13)) a -= (BASE << 13); \
|
32
|
+
if (a >= (BASE << 12)) a -= (BASE << 12); \
|
33
|
+
if (a >= (BASE << 11)) a -= (BASE << 11); \
|
34
|
+
if (a >= (BASE << 10)) a -= (BASE << 10); \
|
35
|
+
if (a >= (BASE << 9)) a -= (BASE << 9); \
|
36
|
+
if (a >= (BASE << 8)) a -= (BASE << 8); \
|
37
|
+
if (a >= (BASE << 7)) a -= (BASE << 7); \
|
38
|
+
if (a >= (BASE << 6)) a -= (BASE << 6); \
|
39
|
+
if (a >= (BASE << 5)) a -= (BASE << 5); \
|
40
|
+
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
41
|
+
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
42
|
+
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
43
|
+
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
38
44
|
if (a >= BASE) a -= BASE; \
|
39
45
|
} while (0)
|
40
|
-
# define
|
46
|
+
# define MOD4(a) \
|
41
47
|
do { \
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
do { /* this assumes a is not negative */ \
|
47
|
-
z_off64_t tmp = a >> 32; \
|
48
|
-
a &= 0xffffffffL; \
|
49
|
-
a += (tmp << 8) - (tmp << 5) + tmp; \
|
50
|
-
tmp = a >> 16; \
|
51
|
-
a &= 0xffffL; \
|
52
|
-
a += (tmp << 4) - tmp; \
|
53
|
-
tmp = a >> 16; \
|
54
|
-
a &= 0xffffL; \
|
55
|
-
a += (tmp << 4) - tmp; \
|
48
|
+
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
49
|
+
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
50
|
+
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
51
|
+
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
56
52
|
if (a >= BASE) a -= BASE; \
|
57
53
|
} while (0)
|
58
54
|
#else
|
59
55
|
# define MOD(a) a %= BASE
|
60
|
-
# define
|
61
|
-
# define MOD63(a) a %= BASE
|
56
|
+
# define MOD4(a) a %= BASE
|
62
57
|
#endif
|
63
58
|
|
64
59
|
/* ========================================================================= */
|
@@ -97,7 +92,7 @@ uLong ZEXPORT adler32(adler, buf, len)
|
|
97
92
|
}
|
98
93
|
if (adler >= BASE)
|
99
94
|
adler -= BASE;
|
100
|
-
|
95
|
+
MOD4(sum2); /* only added so many BASE's */
|
101
96
|
return adler | (sum2 << 16);
|
102
97
|
}
|
103
98
|
|
@@ -142,13 +137,8 @@ local uLong adler32_combine_(adler1, adler2, len2)
|
|
142
137
|
unsigned long sum2;
|
143
138
|
unsigned rem;
|
144
139
|
|
145
|
-
/* for negative len, return invalid adler32 as a clue for debugging */
|
146
|
-
if (len2 < 0)
|
147
|
-
return 0xffffffffUL;
|
148
|
-
|
149
140
|
/* the derivation of this formula is left as an exercise for the reader */
|
150
|
-
|
151
|
-
rem = (unsigned)len2;
|
141
|
+
rem = (unsigned)(len2 % BASE);
|
152
142
|
sum1 = adler1 & 0xffff;
|
153
143
|
sum2 = rem * sum1;
|
154
144
|
MOD(sum2);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/* crc32.c -- compute the CRC-32 of a data stream
|
2
|
-
* Copyright (C) 1995-2006, 2010
|
2
|
+
* Copyright (C) 1995-2006, 2010 Mark Adler
|
3
3
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
4
|
*
|
5
5
|
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
@@ -17,8 +17,6 @@
|
|
17
17
|
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
18
18
|
first call get_crc_table() to initialize the tables before allowing more than
|
19
19
|
one thread to use crc32().
|
20
|
-
|
21
|
-
DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
|
22
20
|
*/
|
23
21
|
|
24
22
|
#ifdef MAKECRCH
|
@@ -32,11 +30,31 @@
|
|
32
30
|
|
33
31
|
#define local static
|
34
32
|
|
33
|
+
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
|
34
|
+
#ifndef NOBYFOUR
|
35
|
+
# ifdef STDC /* need ANSI C limits.h to determine sizes */
|
36
|
+
# include <limits.h>
|
37
|
+
# define BYFOUR
|
38
|
+
# if (UINT_MAX == 0xffffffffUL)
|
39
|
+
typedef unsigned int u4;
|
40
|
+
# else
|
41
|
+
# if (ULONG_MAX == 0xffffffffUL)
|
42
|
+
typedef unsigned long u4;
|
43
|
+
# else
|
44
|
+
# if (USHRT_MAX == 0xffffffffUL)
|
45
|
+
typedef unsigned short u4;
|
46
|
+
# else
|
47
|
+
# undef BYFOUR /* can't find a four-byte integer type! */
|
48
|
+
# endif
|
49
|
+
# endif
|
50
|
+
# endif
|
51
|
+
# endif /* STDC */
|
52
|
+
#endif /* !NOBYFOUR */
|
53
|
+
|
35
54
|
/* Definitions for doing the crc four data bytes at a time. */
|
36
|
-
#if !defined(NOBYFOUR) && defined(Z_U4)
|
37
|
-
# define BYFOUR
|
38
|
-
#endif
|
39
55
|
#ifdef BYFOUR
|
56
|
+
# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
|
57
|
+
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
|
40
58
|
local unsigned long crc32_little OF((unsigned long,
|
41
59
|
const unsigned char FAR *, unsigned));
|
42
60
|
local unsigned long crc32_big OF((unsigned long,
|
@@ -50,16 +68,16 @@
|
|
50
68
|
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
51
69
|
unsigned long vec));
|
52
70
|
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
53
|
-
local uLong crc32_combine_
|
71
|
+
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
|
54
72
|
|
55
73
|
|
56
74
|
#ifdef DYNAMIC_CRC_TABLE
|
57
75
|
|
58
76
|
local volatile int crc_table_empty = 1;
|
59
|
-
local
|
77
|
+
local unsigned long FAR crc_table[TBLS][256];
|
60
78
|
local void make_crc_table OF((void));
|
61
79
|
#ifdef MAKECRCH
|
62
|
-
local void write_table OF((FILE *, const
|
80
|
+
local void write_table OF((FILE *, const unsigned long FAR *));
|
63
81
|
#endif /* MAKECRCH */
|
64
82
|
/*
|
65
83
|
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
@@ -89,9 +107,9 @@ local void make_crc_table OF((void));
|
|
89
107
|
*/
|
90
108
|
local void make_crc_table()
|
91
109
|
{
|
92
|
-
|
110
|
+
unsigned long c;
|
93
111
|
int n, k;
|
94
|
-
|
112
|
+
unsigned long poly; /* polynomial exclusive-or pattern */
|
95
113
|
/* terms of polynomial defining this crc (except x^32): */
|
96
114
|
static volatile int first = 1; /* flag to limit concurrent making */
|
97
115
|
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
@@ -103,13 +121,13 @@ local void make_crc_table()
|
|
103
121
|
first = 0;
|
104
122
|
|
105
123
|
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
106
|
-
poly =
|
107
|
-
for (n = 0; n <
|
108
|
-
poly |=
|
124
|
+
poly = 0UL;
|
125
|
+
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
126
|
+
poly |= 1UL << (31 - p[n]);
|
109
127
|
|
110
128
|
/* generate a crc for every 8-bit value */
|
111
129
|
for (n = 0; n < 256; n++) {
|
112
|
-
c = (
|
130
|
+
c = (unsigned long)n;
|
113
131
|
for (k = 0; k < 8; k++)
|
114
132
|
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
115
133
|
crc_table[0][n] = c;
|
@@ -120,11 +138,11 @@ local void make_crc_table()
|
|
120
138
|
and then the byte reversal of those as well as the first table */
|
121
139
|
for (n = 0; n < 256; n++) {
|
122
140
|
c = crc_table[0][n];
|
123
|
-
crc_table[4][n] =
|
141
|
+
crc_table[4][n] = REV(c);
|
124
142
|
for (k = 1; k < 4; k++) {
|
125
143
|
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
126
144
|
crc_table[k][n] = c;
|
127
|
-
crc_table[k + 4][n] =
|
145
|
+
crc_table[k + 4][n] = REV(c);
|
128
146
|
}
|
129
147
|
}
|
130
148
|
#endif /* BYFOUR */
|
@@ -146,7 +164,7 @@ local void make_crc_table()
|
|
146
164
|
if (out == NULL) return;
|
147
165
|
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
148
166
|
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
149
|
-
fprintf(out, "local const
|
167
|
+
fprintf(out, "local const unsigned long FAR ");
|
150
168
|
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
151
169
|
write_table(out, crc_table[0]);
|
152
170
|
# ifdef BYFOUR
|
@@ -166,13 +184,12 @@ local void make_crc_table()
|
|
166
184
|
#ifdef MAKECRCH
|
167
185
|
local void write_table(out, table)
|
168
186
|
FILE *out;
|
169
|
-
const
|
187
|
+
const unsigned long FAR *table;
|
170
188
|
{
|
171
189
|
int n;
|
172
190
|
|
173
191
|
for (n = 0; n < 256; n++)
|
174
|
-
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
|
175
|
-
(unsigned long)(table[n]),
|
192
|
+
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
|
176
193
|
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
177
194
|
}
|
178
195
|
#endif /* MAKECRCH */
|
@@ -187,13 +204,13 @@ local void write_table(out, table)
|
|
187
204
|
/* =========================================================================
|
188
205
|
* This function can be used by asm versions of crc32()
|
189
206
|
*/
|
190
|
-
const
|
207
|
+
const unsigned long FAR * ZEXPORT get_crc_table()
|
191
208
|
{
|
192
209
|
#ifdef DYNAMIC_CRC_TABLE
|
193
210
|
if (crc_table_empty)
|
194
211
|
make_crc_table();
|
195
212
|
#endif /* DYNAMIC_CRC_TABLE */
|
196
|
-
return (const
|
213
|
+
return (const unsigned long FAR *)crc_table;
|
197
214
|
}
|
198
215
|
|
199
216
|
/* ========================================================================= */
|
@@ -215,7 +232,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
|
|
215
232
|
|
216
233
|
#ifdef BYFOUR
|
217
234
|
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
218
|
-
|
235
|
+
u4 endian;
|
219
236
|
|
220
237
|
endian = 1;
|
221
238
|
if (*((unsigned char *)(&endian)))
|
@@ -249,17 +266,17 @@ local unsigned long crc32_little(crc, buf, len)
|
|
249
266
|
const unsigned char FAR *buf;
|
250
267
|
unsigned len;
|
251
268
|
{
|
252
|
-
register
|
253
|
-
register const
|
269
|
+
register u4 c;
|
270
|
+
register const u4 FAR *buf4;
|
254
271
|
|
255
|
-
c = (
|
272
|
+
c = (u4)crc;
|
256
273
|
c = ~c;
|
257
274
|
while (len && ((ptrdiff_t)buf & 3)) {
|
258
275
|
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
259
276
|
len--;
|
260
277
|
}
|
261
278
|
|
262
|
-
buf4 = (const
|
279
|
+
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
263
280
|
while (len >= 32) {
|
264
281
|
DOLIT32;
|
265
282
|
len -= 32;
|
@@ -289,17 +306,17 @@ local unsigned long crc32_big(crc, buf, len)
|
|
289
306
|
const unsigned char FAR *buf;
|
290
307
|
unsigned len;
|
291
308
|
{
|
292
|
-
register
|
293
|
-
register const
|
309
|
+
register u4 c;
|
310
|
+
register const u4 FAR *buf4;
|
294
311
|
|
295
|
-
c =
|
312
|
+
c = REV((u4)crc);
|
296
313
|
c = ~c;
|
297
314
|
while (len && ((ptrdiff_t)buf & 3)) {
|
298
315
|
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
299
316
|
len--;
|
300
317
|
}
|
301
318
|
|
302
|
-
buf4 = (const
|
319
|
+
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
303
320
|
buf4--;
|
304
321
|
while (len >= 32) {
|
305
322
|
DOBIG32;
|
@@ -316,7 +333,7 @@ local unsigned long crc32_big(crc, buf, len)
|
|
316
333
|
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
317
334
|
} while (--len);
|
318
335
|
c = ~c;
|
319
|
-
return (unsigned long)(
|
336
|
+
return (unsigned long)(REV(c));
|
320
337
|
}
|
321
338
|
|
322
339
|
#endif /* BYFOUR */
|