rugged 0.22.2 → 0.23.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged.c +1 -2
  3. data/ext/rugged/rugged_branch_collection.c +6 -44
  4. data/ext/rugged/rugged_config.c +7 -3
  5. data/ext/rugged/rugged_diff_delta.c +1 -1
  6. data/ext/rugged/rugged_diff_line.c +1 -1
  7. data/ext/rugged/rugged_object.c +2 -2
  8. data/ext/rugged/rugged_reference_collection.c +12 -56
  9. data/ext/rugged/rugged_remote.c +4 -33
  10. data/ext/rugged/rugged_remote_collection.c +1 -1
  11. data/ext/rugged/rugged_repo.c +10 -36
  12. data/ext/rugged/rugged_settings.c +3 -3
  13. data/ext/rugged/rugged_tree.c +1 -1
  14. data/lib/rugged/version.rb +1 -1
  15. data/vendor/libgit2/CMakeLists.txt +10 -3
  16. data/vendor/libgit2/COPYING +15 -21
  17. data/vendor/libgit2/include/git2/annotated_commit.h +20 -3
  18. data/vendor/libgit2/include/git2/branch.h +20 -16
  19. data/vendor/libgit2/include/git2/checkout.h +32 -18
  20. data/vendor/libgit2/include/git2/cherrypick.h +2 -2
  21. data/vendor/libgit2/include/git2/clone.h +4 -10
  22. data/vendor/libgit2/include/git2/config.h +66 -12
  23. data/vendor/libgit2/include/git2/describe.h +3 -2
  24. data/vendor/libgit2/include/git2/diff.h +3 -3
  25. data/vendor/libgit2/include/git2/errors.h +1 -0
  26. data/vendor/libgit2/include/git2/filter.h +21 -5
  27. data/vendor/libgit2/include/git2/index.h +32 -0
  28. data/vendor/libgit2/include/git2/merge.h +20 -3
  29. data/vendor/libgit2/include/git2/oid.h +1 -1
  30. data/vendor/libgit2/include/git2/pack.h +13 -0
  31. data/vendor/libgit2/include/git2/patch.h +3 -6
  32. data/vendor/libgit2/include/git2/rebase.h +8 -12
  33. data/vendor/libgit2/include/git2/refs.h +19 -29
  34. data/vendor/libgit2/include/git2/remote.h +5 -11
  35. data/vendor/libgit2/include/git2/repository.h +44 -15
  36. data/vendor/libgit2/include/git2/reset.h +19 -10
  37. data/vendor/libgit2/include/git2/revert.h +2 -2
  38. data/vendor/libgit2/include/git2/submodule.h +3 -9
  39. data/vendor/libgit2/include/git2/sys/config.h +3 -1
  40. data/vendor/libgit2/include/git2/sys/filter.h +10 -2
  41. data/vendor/libgit2/include/git2/sys/hashsig.h +49 -22
  42. data/vendor/libgit2/include/git2/transport.h +1 -1
  43. data/vendor/libgit2/include/git2/types.h +10 -3
  44. data/vendor/libgit2/include/git2/version.h +3 -2
  45. data/vendor/libgit2/src/annotated_commit.c +28 -0
  46. data/vendor/libgit2/src/array.h +19 -8
  47. data/vendor/libgit2/src/attr.c +95 -35
  48. data/vendor/libgit2/src/attr_file.c +51 -17
  49. data/vendor/libgit2/src/attr_file.h +37 -10
  50. data/vendor/libgit2/src/attrcache.c +13 -7
  51. data/vendor/libgit2/src/attrcache.h +1 -0
  52. data/vendor/libgit2/src/blame.c +26 -2
  53. data/vendor/libgit2/src/blame_git.c +6 -2
  54. data/vendor/libgit2/src/blob.c +6 -8
  55. data/vendor/libgit2/src/branch.c +55 -43
  56. data/vendor/libgit2/src/buf_text.c +13 -6
  57. data/vendor/libgit2/src/buffer.c +110 -25
  58. data/vendor/libgit2/src/buffer.h +18 -0
  59. data/vendor/libgit2/src/checkout.c +164 -92
  60. data/vendor/libgit2/src/checkout.h +0 -7
  61. data/vendor/libgit2/src/cherrypick.c +13 -7
  62. data/vendor/libgit2/src/clone.c +23 -25
  63. data/vendor/libgit2/src/commit.c +3 -3
  64. data/vendor/libgit2/src/common.h +23 -1
  65. data/vendor/libgit2/src/config.c +137 -19
  66. data/vendor/libgit2/src/config.h +2 -2
  67. data/vendor/libgit2/src/config_cache.c +2 -1
  68. data/vendor/libgit2/src/config_file.c +39 -18
  69. data/vendor/libgit2/src/config_file.h +1 -1
  70. data/vendor/libgit2/src/crlf.c +1 -1
  71. data/vendor/libgit2/src/delta-apply.c +3 -2
  72. data/vendor/libgit2/src/delta.c +25 -6
  73. data/vendor/libgit2/src/describe.c +2 -0
  74. data/vendor/libgit2/src/diff.c +8 -5
  75. data/vendor/libgit2/src/diff_driver.c +39 -18
  76. data/vendor/libgit2/src/diff_file.c +1 -1
  77. data/vendor/libgit2/src/diff_patch.c +12 -6
  78. data/vendor/libgit2/src/diff_tform.c +21 -24
  79. data/vendor/libgit2/src/filebuf.c +14 -12
  80. data/vendor/libgit2/src/fileops.c +61 -18
  81. data/vendor/libgit2/src/fileops.h +11 -2
  82. data/vendor/libgit2/src/filter.c +351 -99
  83. data/vendor/libgit2/src/filter.h +17 -0
  84. data/vendor/libgit2/src/global.c +38 -9
  85. data/vendor/libgit2/src/hash/hash_generic.c +1 -1
  86. data/vendor/libgit2/src/hashsig.c +28 -16
  87. data/vendor/libgit2/src/ignore.c +2 -2
  88. data/vendor/libgit2/src/index.c +159 -42
  89. data/vendor/libgit2/src/index.h +29 -0
  90. data/vendor/libgit2/src/indexer.c +11 -2
  91. data/vendor/libgit2/src/integer.h +96 -0
  92. data/vendor/libgit2/src/iterator.c +5 -3
  93. data/vendor/libgit2/src/khash.h +41 -29
  94. data/vendor/libgit2/src/merge.c +48 -35
  95. data/vendor/libgit2/src/merge.h +0 -1
  96. data/vendor/libgit2/src/merge_file.c +13 -0
  97. data/vendor/libgit2/src/mwindow.c +1 -1
  98. data/vendor/libgit2/src/notes.c +1 -1
  99. data/vendor/libgit2/src/odb.c +13 -11
  100. data/vendor/libgit2/src/odb_loose.c +22 -10
  101. data/vendor/libgit2/src/odb_mempack.c +4 -2
  102. data/vendor/libgit2/src/offmap.h +3 -2
  103. data/vendor/libgit2/src/oid.c +1 -1
  104. data/vendor/libgit2/src/oidmap.h +2 -1
  105. data/vendor/libgit2/src/openssl_stream.c +6 -3
  106. data/vendor/libgit2/src/pack-objects.c +273 -12
  107. data/vendor/libgit2/src/pack-objects.h +10 -0
  108. data/vendor/libgit2/src/pack.c +17 -6
  109. data/vendor/libgit2/src/pack.h +1 -3
  110. data/vendor/libgit2/src/path.c +68 -38
  111. data/vendor/libgit2/src/pathspec.c +3 -0
  112. data/vendor/libgit2/src/pool.c +9 -8
  113. data/vendor/libgit2/src/posix.c +11 -1
  114. data/vendor/libgit2/src/push.c +15 -17
  115. data/vendor/libgit2/src/push.h +1 -6
  116. data/vendor/libgit2/src/rebase.c +77 -35
  117. data/vendor/libgit2/src/refdb_fs.c +2 -2
  118. data/vendor/libgit2/src/refs.c +107 -81
  119. data/vendor/libgit2/src/refs.h +2 -2
  120. data/vendor/libgit2/src/refspec.c +3 -0
  121. data/vendor/libgit2/src/remote.c +19 -21
  122. data/vendor/libgit2/src/repository.c +258 -67
  123. data/vendor/libgit2/src/repository.h +31 -16
  124. data/vendor/libgit2/src/reset.c +28 -12
  125. data/vendor/libgit2/src/revert.c +12 -7
  126. data/vendor/libgit2/src/revwalk.c +3 -5
  127. data/vendor/libgit2/src/revwalk.h +1 -1
  128. data/vendor/libgit2/src/sortedcache.c +5 -3
  129. data/vendor/libgit2/src/stash.c +3 -5
  130. data/vendor/libgit2/src/strmap.h +2 -1
  131. data/vendor/libgit2/src/submodule.c +5 -6
  132. data/vendor/libgit2/src/tag.c +7 -5
  133. data/vendor/libgit2/src/transaction.c +1 -1
  134. data/vendor/libgit2/src/transports/cred.c +5 -2
  135. data/vendor/libgit2/src/transports/git.c +2 -3
  136. data/vendor/libgit2/src/transports/local.c +15 -34
  137. data/vendor/libgit2/src/transports/smart.c +1 -1
  138. data/vendor/libgit2/src/transports/smart_pkt.c +58 -18
  139. data/vendor/libgit2/src/transports/smart_protocol.c +2 -2
  140. data/vendor/libgit2/src/transports/winhttp.c +2 -2
  141. data/vendor/libgit2/src/tree.c +7 -5
  142. data/vendor/libgit2/src/tsort.c +3 -1
  143. data/vendor/libgit2/src/util.c +25 -0
  144. data/vendor/libgit2/src/util.h +31 -27
  145. data/vendor/libgit2/src/vector.c +2 -7
  146. data/vendor/libgit2/src/win32/dir.c +5 -3
  147. data/vendor/libgit2/src/win32/git2.rc +8 -4
  148. data/vendor/libgit2/src/win32/mingw-compat.h +7 -0
  149. data/vendor/libgit2/src/win32/msvc-compat.h +3 -0
  150. data/vendor/libgit2/src/win32/posix.h +1 -3
  151. data/vendor/libgit2/src/win32/posix_w32.c +31 -7
  152. data/vendor/libgit2/src/win32/utf-conv.c +1 -3
  153. data/vendor/libgit2/src/zstream.c +1 -1
  154. metadata +5 -5
  155. data/vendor/libgit2/src/bswap.h +0 -97
@@ -26,7 +26,7 @@
26
26
  #include <git2/sys/refs.h>
27
27
  #include <git2/sys/reflog.h>
28
28
 
29
- GIT__USE_STRMAP;
29
+ GIT__USE_STRMAP
30
30
 
31
31
  #define DEFAULT_NESTING_LEVEL 5
32
32
  #define MAX_NESTING_LEVEL 10
@@ -1324,7 +1324,7 @@ static int refdb_fs_backend__rename(
1324
1324
  /* Try to rename the refog; it's ok if the old doesn't exist */
1325
1325
  error = refdb_reflog_fs__rename(_backend, old_name, new_name);
1326
1326
  if (((error == 0) || (error == GIT_ENOTFOUND)) &&
1327
- ((error = reflog_append(backend, new, NULL, NULL, who, message)) < 0)) {
1327
+ ((error = reflog_append(backend, new, git_reference_target(new), NULL, who, message)) < 0)) {
1328
1328
  git_reference_free(new);
1329
1329
  git_filebuf_cleanup(&file);
1330
1330
  return error;
@@ -24,7 +24,7 @@
24
24
  #include <git2/signature.h>
25
25
  #include <git2/commit.h>
26
26
 
27
- GIT__USE_STRMAP;
27
+ GIT__USE_STRMAP
28
28
 
29
29
  #define DEFAULT_NESTING_LEVEL 5
30
30
  #define MAX_NESTING_LEVEL 10
@@ -36,13 +36,13 @@ enum {
36
36
 
37
37
  static git_reference *alloc_ref(const char *name)
38
38
  {
39
- git_reference *ref;
40
- size_t namelen = strlen(name);
41
-
42
- if ((ref = git__calloc(1, sizeof(git_reference) + namelen + 1)) == NULL)
43
- return NULL;
39
+ git_reference *ref = NULL;
40
+ size_t namelen = strlen(name), reflen;
44
41
 
45
- memcpy(ref->name, name, namelen + 1);
42
+ if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) &&
43
+ !GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) &&
44
+ (ref = git__calloc(1, reflen)) != NULL)
45
+ memcpy(ref->name, name, namelen + 1);
46
46
 
47
47
  return ref;
48
48
  }
@@ -94,10 +94,14 @@ git_reference *git_reference__set_name(
94
94
  git_reference *ref, const char *name)
95
95
  {
96
96
  size_t namelen = strlen(name);
97
- git_reference *rewrite =
98
- git__realloc(ref, sizeof(git_reference) + namelen + 1);
99
- if (rewrite != NULL)
97
+ size_t reflen;
98
+ git_reference *rewrite = NULL;
99
+
100
+ if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) &&
101
+ !GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) &&
102
+ (rewrite = git__realloc(ref, reflen)) != NULL)
100
103
  memcpy(rewrite->name, name, namelen + 1);
104
+
101
105
  return rewrite;
102
106
  }
103
107
 
@@ -412,12 +416,22 @@ static int reference__create(
412
416
  return 0;
413
417
  }
414
418
 
419
+ int configured_ident(git_signature **out, const git_repository *repo)
420
+ {
421
+ if (repo->ident_name && repo->ident_email)
422
+ return git_signature_now(out, repo->ident_name, repo->ident_email);
423
+
424
+ /* if not configured let us fall-through to the next method */
425
+ return -1;
426
+ }
427
+
415
428
  int git_reference__log_signature(git_signature **out, git_repository *repo)
416
429
  {
417
430
  int error;
418
431
  git_signature *who;
419
432
 
420
- if(((error = git_signature_default(&who, repo)) < 0) &&
433
+ if(((error = configured_ident(&who, repo)) < 0) &&
434
+ ((error = git_signature_default(&who, repo)) < 0) &&
421
435
  ((error = git_signature_now(&who, "unknown", "unknown")) < 0))
422
436
  return error;
423
437
 
@@ -432,7 +446,6 @@ int git_reference_create_matching(
432
446
  const git_oid *id,
433
447
  int force,
434
448
  const git_oid *old_id,
435
- const git_signature *signature,
436
449
  const char *log_message)
437
450
 
438
451
  {
@@ -441,15 +454,11 @@ int git_reference_create_matching(
441
454
 
442
455
  assert(id);
443
456
 
444
- if (!signature) {
445
- if ((error = git_reference__log_signature(&who, repo)) < 0)
446
- return error;
447
- else
448
- signature = who;
449
- }
457
+ if ((error = git_reference__log_signature(&who, repo)) < 0)
458
+ return error;
450
459
 
451
460
  error = reference__create(
452
- ref_out, repo, name, id, NULL, force, signature, log_message, old_id, NULL);
461
+ ref_out, repo, name, id, NULL, force, who, log_message, old_id, NULL);
453
462
 
454
463
  git_signature_free(who);
455
464
  return error;
@@ -461,10 +470,9 @@ int git_reference_create(
461
470
  const char *name,
462
471
  const git_oid *id,
463
472
  int force,
464
- const git_signature *signature,
465
473
  const char *log_message)
466
474
  {
467
- return git_reference_create_matching(ref_out, repo, name, id, force, NULL, signature, log_message);
475
+ return git_reference_create_matching(ref_out, repo, name, id, force, NULL, log_message);
468
476
  }
469
477
 
470
478
  int git_reference_symbolic_create_matching(
@@ -474,7 +482,6 @@ int git_reference_symbolic_create_matching(
474
482
  const char *target,
475
483
  int force,
476
484
  const char *old_target,
477
- const git_signature *signature,
478
485
  const char *log_message)
479
486
  {
480
487
  int error;
@@ -482,15 +489,11 @@ int git_reference_symbolic_create_matching(
482
489
 
483
490
  assert(target);
484
491
 
485
- if (!signature) {
486
- if ((error = git_reference__log_signature(&who, repo)) < 0)
487
- return error;
488
- else
489
- signature = who;
490
- }
492
+ if ((error = git_reference__log_signature(&who, repo)) < 0)
493
+ return error;
491
494
 
492
495
  error = reference__create(
493
- ref_out, repo, name, NULL, target, force, signature, log_message, NULL, old_target);
496
+ ref_out, repo, name, NULL, target, force, who, log_message, NULL, old_target);
494
497
 
495
498
  git_signature_free(who);
496
499
  return error;
@@ -502,10 +505,9 @@ int git_reference_symbolic_create(
502
505
  const char *name,
503
506
  const char *target,
504
507
  int force,
505
- const git_signature *signature,
506
508
  const char *log_message)
507
509
  {
508
- return git_reference_symbolic_create_matching(ref_out, repo, name, target, force, NULL, signature, log_message);
510
+ return git_reference_symbolic_create_matching(ref_out, repo, name, target, force, NULL, log_message);
509
511
  }
510
512
 
511
513
  static int ensure_is_an_updatable_direct_reference(git_reference *ref)
@@ -521,7 +523,6 @@ int git_reference_set_target(
521
523
  git_reference **out,
522
524
  git_reference *ref,
523
525
  const git_oid *id,
524
- const git_signature *signature,
525
526
  const char *log_message)
526
527
  {
527
528
  int error;
@@ -534,7 +535,7 @@ int git_reference_set_target(
534
535
  if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
535
536
  return error;
536
537
 
537
- return git_reference_create_matching(out, repo, ref->name, id, 1, &ref->target.oid, signature, log_message);
538
+ return git_reference_create_matching(out, repo, ref->name, id, 1, &ref->target.oid, log_message);
538
539
  }
539
540
 
540
541
  static int ensure_is_an_updatable_symbolic_reference(git_reference *ref)
@@ -550,7 +551,6 @@ int git_reference_symbolic_set_target(
550
551
  git_reference **out,
551
552
  git_reference *ref,
552
553
  const char *target,
553
- const git_signature *signature,
554
554
  const char *log_message)
555
555
  {
556
556
  int error;
@@ -561,7 +561,7 @@ int git_reference_symbolic_set_target(
561
561
  return error;
562
562
 
563
563
  return git_reference_symbolic_create_matching(
564
- out, ref->db->repo, ref->name, target, 1, ref->target.symbolic, signature, log_message);
564
+ out, ref->db->repo, ref->name, target, 1, ref->target.symbolic, log_message);
565
565
  }
566
566
 
567
567
  static int reference__rename(git_reference **out, git_reference *ref, const char *new_name, int force,
@@ -589,7 +589,7 @@ static int reference__rename(git_reference **out, git_reference *ref, const char
589
589
 
590
590
  /* Update HEAD it was pointing to the reference being renamed */
591
591
  if (should_head_be_updated &&
592
- (error = git_repository_set_head(ref->db->repo, normalized, signature, message)) < 0) {
592
+ (error = git_repository_set_head(ref->db->repo, normalized)) < 0) {
593
593
  giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
594
594
  return error;
595
595
  }
@@ -603,23 +603,16 @@ int git_reference_rename(
603
603
  git_reference *ref,
604
604
  const char *new_name,
605
605
  int force,
606
- const git_signature *signature,
607
606
  const char *log_message)
608
607
  {
609
- git_signature *who = (git_signature*)signature;
608
+ git_signature *who;
610
609
  int error;
611
610
 
612
- /* Should we return an error if there is no default? */
613
- if (!who &&
614
- ((error = git_signature_default(&who, ref->db->repo)) < 0) &&
615
- ((error = git_signature_now(&who, "unknown", "unknown")) < 0)) {
611
+ if ((error = git_reference__log_signature(&who, ref->db->repo)) < 0)
616
612
  return error;
617
- }
618
613
 
619
614
  error = reference__rename(out, ref, new_name, force, who, log_message);
620
-
621
- if (!signature)
622
- git_signature_free(who);
615
+ git_signature_free(who);
623
616
 
624
617
  return error;
625
618
  }
@@ -1034,13 +1027,11 @@ int git_reference_cmp(
1034
1027
  return git_oid__cmp(&ref1->target.oid, &ref2->target.oid);
1035
1028
  }
1036
1029
 
1037
- static int reference__update_terminal(
1038
- git_repository *repo,
1039
- const char *ref_name,
1040
- const git_oid *oid,
1041
- int nesting,
1042
- const git_signature *signature,
1043
- const char *log_message)
1030
+ /**
1031
+ * Get the end of a chain of references. If the final one is not
1032
+ * found, we return the reference just before that.
1033
+ */
1034
+ static int get_terminal(git_reference **out, git_repository *repo, const char *ref_name, int nesting)
1044
1035
  {
1045
1036
  git_reference *ref;
1046
1037
  int error = 0;
@@ -1050,27 +1041,23 @@ static int reference__update_terminal(
1050
1041
  return GIT_ENOTFOUND;
1051
1042
  }
1052
1043
 
1053
- error = git_reference_lookup(&ref, repo, ref_name);
1054
-
1055
- /* If we haven't found the reference at all, create a new reference. */
1056
- if (error == GIT_ENOTFOUND) {
1057
- giterr_clear();
1058
- return git_reference_create(NULL, repo, ref_name, oid, 0, signature, log_message);
1059
- }
1060
-
1061
- if (error < 0)
1044
+ /* set to NULL to let the caller know that they're at the end of the chain */
1045
+ if ((error = git_reference_lookup(&ref, repo, ref_name)) < 0) {
1046
+ *out = NULL;
1062
1047
  return error;
1048
+ }
1063
1049
 
1064
- /* If the ref is a symbolic reference, follow its target. */
1065
- if (git_reference_type(ref) == GIT_REF_SYMBOLIC) {
1066
- error = reference__update_terminal(repo, git_reference_symbolic_target(ref), oid,
1067
- nesting+1, signature, log_message);
1068
- git_reference_free(ref);
1050
+ if (git_reference_type(ref) == GIT_REF_OID) {
1051
+ *out = ref;
1052
+ error = 0;
1069
1053
  } else {
1070
- /* If we're not moving the target, don't recreate the ref */
1071
- if (0 != git_oid_cmp(git_reference_target(ref), oid))
1072
- error = git_reference_create(NULL, repo, ref_name, oid, 1, signature, log_message);
1073
- git_reference_free(ref);
1054
+ error = get_terminal(out, repo, git_reference_symbolic_target(ref), nesting + 1);
1055
+ if (error == GIT_ENOTFOUND) {
1056
+ if (!*out) /* set by the error case in lookup above */
1057
+ *out = ref;
1058
+ } else {
1059
+ git_reference_free(ref);
1060
+ }
1074
1061
  }
1075
1062
 
1076
1063
  return error;
@@ -1085,10 +1072,40 @@ int git_reference__update_terminal(
1085
1072
  git_repository *repo,
1086
1073
  const char *ref_name,
1087
1074
  const git_oid *oid,
1088
- const git_signature *signature,
1075
+ const git_signature *sig,
1089
1076
  const char *log_message)
1090
1077
  {
1091
- return reference__update_terminal(repo, ref_name, oid, 0, signature, log_message);
1078
+ git_reference *ref = NULL, *ref2 = NULL;
1079
+ git_signature *who = NULL;
1080
+ const git_signature *to_use;
1081
+ int error = 0;
1082
+
1083
+ if (!sig && (error = git_reference__log_signature(&who, repo)) < 0)
1084
+ return error;
1085
+
1086
+ to_use = sig ? sig : who;
1087
+ error = get_terminal(&ref, repo, ref_name, 0);
1088
+
1089
+ /* found a dangling symref */
1090
+ if (error == GIT_ENOTFOUND && ref) {
1091
+ assert(git_reference_type(ref) == GIT_REF_SYMBOLIC);
1092
+ giterr_clear();
1093
+ error = reference__create(&ref2, repo, ref->target.symbolic, oid, NULL, 0, to_use,
1094
+ log_message, NULL, NULL);
1095
+ } else if (error == GIT_ENOTFOUND) {
1096
+ giterr_clear();
1097
+ error = reference__create(&ref2, repo, ref_name, oid, NULL, 0, to_use,
1098
+ log_message, NULL, NULL);
1099
+ } else if (error == 0) {
1100
+ assert(git_reference_type(ref) == GIT_REF_OID);
1101
+ error = reference__create(&ref2, repo, ref->name, oid, NULL, 1, to_use,
1102
+ log_message, &ref->target.oid, NULL);
1103
+ }
1104
+
1105
+ git_reference_free(ref2);
1106
+ git_reference_free(ref);
1107
+ git_signature_free(who);
1108
+ return error;
1092
1109
  }
1093
1110
 
1094
1111
  int git_reference__update_for_commit(
@@ -1096,12 +1113,12 @@ int git_reference__update_for_commit(
1096
1113
  git_reference *ref,
1097
1114
  const char *ref_name,
1098
1115
  const git_oid *id,
1099
- const git_signature *committer,
1100
1116
  const char *operation)
1101
1117
  {
1102
1118
  git_reference *ref_new = NULL;
1103
1119
  git_commit *commit = NULL;
1104
1120
  git_buf reflog_msg = GIT_BUF_INIT;
1121
+ const git_signature *who;
1105
1122
  int error;
1106
1123
 
1107
1124
  if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
@@ -1111,12 +1128,18 @@ int git_reference__update_for_commit(
1111
1128
  git_commit_summary(commit))) < 0)
1112
1129
  goto done;
1113
1130
 
1114
- if (ref)
1115
- error = git_reference_set_target(
1116
- &ref_new, ref, id, committer, git_buf_cstr(&reflog_msg));
1131
+ who = git_commit_committer(commit);
1132
+
1133
+ if (ref) {
1134
+ if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
1135
+ return error;
1136
+
1137
+ error = reference__create(&ref_new, repo, ref->name, id, NULL, 1, who,
1138
+ git_buf_cstr(&reflog_msg), &ref->target.oid, NULL);
1139
+ }
1117
1140
  else
1118
1141
  error = git_reference__update_terminal(
1119
- repo, ref_name, id, committer, git_buf_cstr(&reflog_msg));
1142
+ repo, ref_name, id, who, git_buf_cstr(&reflog_msg));
1120
1143
 
1121
1144
  done:
1122
1145
  git_reference_free(ref_new);
@@ -1263,10 +1286,8 @@ int git_reference_is_valid_name(const char *refname)
1263
1286
  return git_reference__is_valid_name(refname, GIT_REF_FORMAT_ALLOW_ONELEVEL);
1264
1287
  }
1265
1288
 
1266
- const char *git_reference_shorthand(const git_reference *ref)
1289
+ const char *git_reference__shorthand(const char *name)
1267
1290
  {
1268
- const char *name = ref->name;
1269
-
1270
1291
  if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR))
1271
1292
  return name + strlen(GIT_REFS_HEADS_DIR);
1272
1293
  else if (!git__prefixcmp(name, GIT_REFS_TAGS_DIR))
@@ -1279,3 +1300,8 @@ const char *git_reference_shorthand(const git_reference *ref)
1279
1300
  /* No shorthands are avaiable, so just return the name */
1280
1301
  return name;
1281
1302
  }
1303
+
1304
+ const char *git_reference_shorthand(const git_reference *ref)
1305
+ {
1306
+ return git_reference__shorthand(ref->name);
1307
+ }
@@ -69,11 +69,12 @@ struct git_reference {
69
69
  git_reference *git_reference__set_name(git_reference *ref, const char *name);
70
70
 
71
71
  int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags);
72
- int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *signature, const char *log_message);
72
+ int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *sig, const char *log_message);
73
73
  int git_reference__is_valid_name(const char *refname, unsigned int flags);
74
74
  int git_reference__is_branch(const char *ref_name);
75
75
  int git_reference__is_remote(const char *ref_name);
76
76
  int git_reference__is_tag(const char *ref_name);
77
+ const char *git_reference__shorthand(const char *name);
77
78
 
78
79
  /**
79
80
  * Lookup a reference by name and try to resolve to an OID.
@@ -106,7 +107,6 @@ int git_reference__update_for_commit(
106
107
  git_reference *ref,
107
108
  const char *ref_name,
108
109
  const git_oid *id,
109
- const git_signature *committer,
110
110
  const char *operation);
111
111
 
112
112
  #endif
@@ -133,6 +133,9 @@ int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
133
133
  return 0;
134
134
 
135
135
  invalid:
136
+ giterr_set(
137
+ GITERR_INVALID,
138
+ "'%s' is not a valid refspec.", input);
136
139
  return -1;
137
140
  }
138
141
 
@@ -52,7 +52,7 @@ static int add_refspec(git_remote *remote, const char *string, bool is_fetch)
52
52
 
53
53
  static int download_tags_value(git_remote *remote, git_config *cfg)
54
54
  {
55
- const git_config_entry *ce;
55
+ git_config_entry *ce;
56
56
  git_buf buf = GIT_BUF_INIT;
57
57
  int error;
58
58
 
@@ -70,6 +70,7 @@ static int download_tags_value(git_remote *remote, git_config *cfg)
70
70
  remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
71
71
  }
72
72
 
73
+ git_config_entry_free(ce);
73
74
  return error;
74
75
  }
75
76
 
@@ -383,10 +384,9 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
383
384
  if ((error = git_repository_config_snapshot(&config, repo)) < 0)
384
385
  return error;
385
386
 
386
- remote = git__malloc(sizeof(git_remote));
387
+ remote = git__calloc(1, sizeof(git_remote));
387
388
  GITERR_CHECK_ALLOC(remote);
388
389
 
389
- memset(remote, 0x0, sizeof(git_remote));
390
390
  remote->update_fetchhead = 1;
391
391
  remote->name = git__strdup(name);
392
392
  GITERR_CHECK_ALLOC(remote->name);
@@ -549,7 +549,7 @@ int git_remote_save(const git_remote *remote)
549
549
  git_config *cfg;
550
550
  const char *tagopt = NULL;
551
551
  git_buf buf = GIT_BUF_INIT;
552
- const git_config_entry *existing;
552
+ git_config_entry *existing = NULL;
553
553
 
554
554
  assert(remote);
555
555
 
@@ -619,6 +619,7 @@ int git_remote_save(const git_remote *remote)
619
619
  cfg, git_buf_cstr(&buf), tagopt, true, false);
620
620
 
621
621
  cleanup:
622
+ git_config_entry_free(existing);
622
623
  git_buf_free(&buf);
623
624
  return error;
624
625
  }
@@ -754,7 +755,7 @@ int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote
754
755
  int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_url)
755
756
  {
756
757
  git_config *cfg;
757
- const git_config_entry *ce;
758
+ git_config_entry *ce = NULL;
758
759
  const char *val = NULL;
759
760
  int error;
760
761
 
@@ -806,6 +807,7 @@ found:
806
807
  *proxy_url = git__strdup(val);
807
808
  GITERR_CHECK_ALLOC(*proxy_url);
808
809
  }
810
+ git_config_entry_free(ce);
809
811
 
810
812
  return 0;
811
813
  }
@@ -925,7 +927,6 @@ on_error:
925
927
  int git_remote_fetch(
926
928
  git_remote *remote,
927
929
  const git_strarray *refspecs,
928
- const git_signature *signature,
929
930
  const char *reflog_message)
930
931
  {
931
932
  int error;
@@ -953,7 +954,7 @@ int git_remote_fetch(
953
954
  }
954
955
 
955
956
  /* Create "remote/foo" branches for all remote branches */
956
- error = git_remote_update_tips(remote, signature, git_buf_cstr(&reflog_msg_buf));
957
+ error = git_remote_update_tips(remote, git_buf_cstr(&reflog_msg_buf));
957
958
  git_buf_free(&reflog_msg_buf);
958
959
  if (error < 0)
959
960
  return error;
@@ -1258,7 +1259,6 @@ static int update_tips_for_spec(
1258
1259
  git_remote *remote,
1259
1260
  git_refspec *spec,
1260
1261
  git_vector *refs,
1261
- const git_signature *signature,
1262
1262
  const char *log_message)
1263
1263
  {
1264
1264
  int error = 0, autotag;
@@ -1333,7 +1333,7 @@ static int update_tips_for_spec(
1333
1333
 
1334
1334
  /* In autotag mode, don't overwrite any locally-existing tags */
1335
1335
  error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, !autotag,
1336
- signature, log_message);
1336
+ log_message);
1337
1337
  if (error < 0 && error != GIT_EEXISTS)
1338
1338
  goto on_error;
1339
1339
 
@@ -1419,7 +1419,7 @@ static int next_head(const git_remote *remote, git_vector *refs,
1419
1419
  return GIT_ITEROVER;
1420
1420
  }
1421
1421
 
1422
- static int opportunistic_updates(const git_remote *remote, git_vector *refs, const git_signature *sig, const char *msg)
1422
+ static int opportunistic_updates(const git_remote *remote, git_vector *refs, const char *msg)
1423
1423
  {
1424
1424
  size_t i, j, k;
1425
1425
  git_refspec *spec;
@@ -1442,7 +1442,7 @@ static int opportunistic_updates(const git_remote *remote, git_vector *refs, con
1442
1442
  if ((error = git_refspec_transform(&refname, spec, head->name)) < 0)
1443
1443
  return error;
1444
1444
 
1445
- error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, true, sig, msg);
1445
+ error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, true, msg);
1446
1446
  git_buf_free(&refname);
1447
1447
  git_reference_free(ref);
1448
1448
 
@@ -1455,7 +1455,6 @@ static int opportunistic_updates(const git_remote *remote, git_vector *refs, con
1455
1455
 
1456
1456
  int git_remote_update_tips(
1457
1457
  git_remote *remote,
1458
- const git_signature *signature,
1459
1458
  const char *reflog_message)
1460
1459
  {
1461
1460
  git_refspec *spec, tagspec;
@@ -1465,7 +1464,7 @@ int git_remote_update_tips(
1465
1464
 
1466
1465
  /* push has its own logic hidden away in the push object */
1467
1466
  if (remote->push) {
1468
- return git_push_update_tips(remote->push, signature, reflog_message);
1467
+ return git_push_update_tips(remote->push);
1469
1468
  }
1470
1469
 
1471
1470
  if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0)
@@ -1476,7 +1475,7 @@ int git_remote_update_tips(
1476
1475
  goto out;
1477
1476
 
1478
1477
  if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
1479
- if ((error = update_tips_for_spec(remote, &tagspec, &refs, signature, reflog_message)) < 0)
1478
+ if ((error = update_tips_for_spec(remote, &tagspec, &refs, reflog_message)) < 0)
1480
1479
  goto out;
1481
1480
  }
1482
1481
 
@@ -1484,13 +1483,13 @@ int git_remote_update_tips(
1484
1483
  if (spec->push)
1485
1484
  continue;
1486
1485
 
1487
- if ((error = update_tips_for_spec(remote, spec, &refs, signature, reflog_message)) < 0)
1486
+ if ((error = update_tips_for_spec(remote, spec, &refs, reflog_message)) < 0)
1488
1487
  goto out;
1489
1488
  }
1490
1489
 
1491
1490
  /* only try to do opportunisitic updates if the refpec lists differ */
1492
1491
  if (remote->passed_refspecs)
1493
- error = opportunistic_updates(remote, &refs, signature, reflog_message);
1492
+ error = opportunistic_updates(remote, &refs, reflog_message);
1494
1493
 
1495
1494
  out:
1496
1495
  git_vector_free(&refs);
@@ -1756,7 +1755,7 @@ static int rename_one_remote_reference(
1756
1755
  goto cleanup;
1757
1756
 
1758
1757
  if ((error = git_reference_rename(&ref, reference_in, git_buf_cstr(&new_name), 1,
1759
- NULL, git_buf_cstr(&log_message))) < 0)
1758
+ git_buf_cstr(&log_message))) < 0)
1760
1759
  goto cleanup;
1761
1760
 
1762
1761
  if (git_reference_type(ref) != GIT_REF_SYMBOLIC)
@@ -1776,7 +1775,7 @@ static int rename_one_remote_reference(
1776
1775
  goto cleanup;
1777
1776
 
1778
1777
  error = git_reference_symbolic_set_target(&dummy, ref, git_buf_cstr(&new_name),
1779
- NULL, git_buf_cstr(&log_message));
1778
+ git_buf_cstr(&log_message));
1780
1779
 
1781
1780
  git_reference_free(dummy);
1782
1781
 
@@ -2378,8 +2377,7 @@ cleanup:
2378
2377
  return error;
2379
2378
  }
2380
2379
 
2381
- int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts,
2382
- const git_signature *signature, const char *reflog_message)
2380
+ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_push_options *opts)
2383
2381
  {
2384
2382
  int error;
2385
2383
 
@@ -2391,7 +2389,7 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_
2391
2389
  if ((error = git_remote_upload(remote, refspecs, opts)) < 0)
2392
2390
  return error;
2393
2391
 
2394
- error = git_remote_update_tips(remote, signature, reflog_message);
2392
+ error = git_remote_update_tips(remote, NULL);
2395
2393
 
2396
2394
  git_remote_disconnect(remote);
2397
2395
  return error;