rugged 0.23.0b1 → 0.23.0b2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_note.c +7 -2
  3. data/ext/rugged/rugged_revwalk.c +321 -145
  4. data/lib/rugged/version.rb +1 -1
  5. data/vendor/libgit2/CMakeLists.txt +83 -8
  6. data/vendor/libgit2/cmake/Modules/FindCoreFoundation.cmake +9 -0
  7. data/vendor/libgit2/cmake/Modules/FindIconv.cmake +0 -3
  8. data/vendor/libgit2/cmake/Modules/FindSecurity.cmake +9 -0
  9. data/vendor/libgit2/deps/winhttp/urlmon.h +45 -0
  10. data/vendor/libgit2/deps/winhttp/winhttp.def +29 -0
  11. data/vendor/libgit2/deps/winhttp/winhttp.h +592 -0
  12. data/vendor/libgit2/deps/winhttp/winhttp64.def +29 -0
  13. data/vendor/libgit2/include/git2/diff.h +6 -1
  14. data/vendor/libgit2/include/git2/index.h +1 -1
  15. data/vendor/libgit2/include/git2/merge.h +2 -1
  16. data/vendor/libgit2/include/git2/notes.h +2 -2
  17. data/vendor/libgit2/include/git2/pack.h +12 -0
  18. data/vendor/libgit2/include/git2/push.h +30 -0
  19. data/vendor/libgit2/include/git2/rebase.h +36 -16
  20. data/vendor/libgit2/include/git2/remote.h +6 -0
  21. data/vendor/libgit2/include/git2/reset.h +2 -2
  22. data/vendor/libgit2/include/git2/revwalk.h +10 -8
  23. data/vendor/libgit2/include/git2/submodule.h +16 -0
  24. data/vendor/libgit2/include/git2/sys/transport.h +12 -4
  25. data/vendor/libgit2/include/git2/types.h +1 -0
  26. data/vendor/libgit2/src/attr.c +3 -3
  27. data/vendor/libgit2/src/attr_file.c +24 -3
  28. data/vendor/libgit2/src/attr_file.h +3 -1
  29. data/vendor/libgit2/src/checkout.c +31 -7
  30. data/vendor/libgit2/src/config.c +5 -6
  31. data/vendor/libgit2/src/config_file.c +533 -469
  32. data/vendor/libgit2/src/describe.c +1 -1
  33. data/vendor/libgit2/src/diff.c +20 -10
  34. data/vendor/libgit2/src/diff_driver.c +1 -1
  35. data/vendor/libgit2/src/diff_tform.c +8 -2
  36. data/vendor/libgit2/src/filter.c +6 -3
  37. data/vendor/libgit2/src/global.c +17 -15
  38. data/vendor/libgit2/src/global.h +3 -1
  39. data/vendor/libgit2/src/ignore.c +48 -8
  40. data/vendor/libgit2/src/ignore.h +1 -1
  41. data/vendor/libgit2/src/index.c +12 -8
  42. data/vendor/libgit2/src/iterator.c +133 -12
  43. data/vendor/libgit2/src/netops.h +2 -2
  44. data/vendor/libgit2/src/notes.c +40 -21
  45. data/vendor/libgit2/src/openssl_stream.c +5 -1
  46. data/vendor/libgit2/src/pack-objects.c +36 -0
  47. data/vendor/libgit2/src/path.c +277 -140
  48. data/vendor/libgit2/src/path.h +132 -60
  49. data/vendor/libgit2/src/posix.h +0 -1
  50. data/vendor/libgit2/src/push.c +43 -4
  51. data/vendor/libgit2/src/push.h +8 -1
  52. data/vendor/libgit2/src/rebase.c +139 -119
  53. data/vendor/libgit2/src/reflog.c +1 -1
  54. data/vendor/libgit2/src/refs.c +3 -5
  55. data/vendor/libgit2/src/remote.c +6 -5
  56. data/vendor/libgit2/src/repository.c +7 -3
  57. data/vendor/libgit2/src/reset.c +3 -3
  58. data/vendor/libgit2/src/revwalk.c +26 -2
  59. data/vendor/libgit2/src/settings.c +3 -3
  60. data/vendor/libgit2/src/stransport_stream.c +249 -0
  61. data/vendor/libgit2/src/stransport_stream.h +14 -0
  62. data/vendor/libgit2/src/submodule.c +26 -2
  63. data/vendor/libgit2/src/tls_stream.c +28 -0
  64. data/vendor/libgit2/src/tls_stream.h +21 -0
  65. data/vendor/libgit2/src/transport.c +4 -4
  66. data/vendor/libgit2/src/transports/git.c +4 -1
  67. data/vendor/libgit2/src/transports/http.c +6 -4
  68. data/vendor/libgit2/src/transports/local.c +2 -1
  69. data/vendor/libgit2/src/transports/smart.c +1 -1
  70. data/vendor/libgit2/src/transports/ssh.c +5 -1
  71. data/vendor/libgit2/src/transports/winhttp.c +30 -23
  72. data/vendor/libgit2/src/tree.c +2 -2
  73. data/vendor/libgit2/src/unix/posix.h +1 -0
  74. data/vendor/libgit2/src/util.h +117 -0
  75. data/vendor/libgit2/src/win32/buffer.c +55 -0
  76. data/vendor/libgit2/src/win32/buffer.h +18 -0
  77. data/vendor/libgit2/src/win32/path_w32.c +75 -0
  78. data/vendor/libgit2/src/win32/path_w32.h +3 -0
  79. data/vendor/libgit2/src/win32/posix.h +2 -2
  80. data/vendor/libgit2/src/win32/posix_w32.c +2 -118
  81. data/vendor/libgit2/src/win32/pthread.c +2 -0
  82. data/vendor/libgit2/src/win32/utf-conv.c +0 -4
  83. data/vendor/libgit2/src/win32/utf-conv.h +4 -0
  84. data/vendor/libgit2/src/win32/w32_util.h +72 -0
  85. metadata +14 -2
@@ -57,6 +57,8 @@ typedef enum {
57
57
  struct git_rebase {
58
58
  git_repository *repo;
59
59
 
60
+ git_rebase_options options;
61
+
60
62
  git_rebase_type_t type;
61
63
  char *state_path;
62
64
 
@@ -249,7 +251,43 @@ done:
249
251
  return error;
250
252
  }
251
253
 
252
- int git_rebase_open(git_rebase **out, git_repository *repo)
254
+ static git_rebase *rebase_alloc(const git_rebase_options *rebase_opts)
255
+ {
256
+ git_rebase *rebase = git__calloc(1, sizeof(git_rebase));
257
+
258
+ if (!rebase)
259
+ return NULL;
260
+
261
+ if (rebase_opts)
262
+ memcpy(&rebase->options, rebase_opts, sizeof(git_rebase_options));
263
+ else
264
+ git_rebase_init_options(&rebase->options, GIT_REBASE_OPTIONS_VERSION);
265
+
266
+ if (rebase_opts && rebase_opts->rewrite_notes_ref) {
267
+ if ((rebase->options.rewrite_notes_ref = git__strdup(rebase_opts->rewrite_notes_ref)) == NULL)
268
+ return NULL;
269
+ }
270
+
271
+ if ((rebase->options.checkout_options.checkout_strategy & (GIT_CHECKOUT_SAFE | GIT_CHECKOUT_FORCE)) == 0)
272
+ rebase->options.checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE;
273
+
274
+ return rebase;
275
+ }
276
+
277
+ static int rebase_check_versions(const git_rebase_options *given_opts)
278
+ {
279
+ GITERR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options");
280
+
281
+ if (given_opts)
282
+ GITERR_CHECK_VERSION(&given_opts->checkout_options, GIT_CHECKOUT_OPTIONS_VERSION, "git_checkout_options");
283
+
284
+ return 0;
285
+ }
286
+
287
+ int git_rebase_open(
288
+ git_rebase **out,
289
+ git_repository *repo,
290
+ const git_rebase_options *given_opts)
253
291
  {
254
292
  git_rebase *rebase;
255
293
  git_buf path = GIT_BUF_INIT, orig_head_name = GIT_BUF_INIT,
@@ -258,7 +296,10 @@ int git_rebase_open(git_rebase **out, git_repository *repo)
258
296
 
259
297
  assert(repo);
260
298
 
261
- rebase = git__calloc(1, sizeof(git_rebase));
299
+ if ((error = rebase_check_versions(given_opts)) < 0)
300
+ return error;
301
+
302
+ rebase = rebase_alloc(given_opts);
262
303
  GITERR_CHECK_ALLOC(rebase);
263
304
 
264
305
  rebase->repo = repo;
@@ -446,48 +487,6 @@ int git_rebase_init_options(git_rebase_options *opts, unsigned int version)
446
487
  return 0;
447
488
  }
448
489
 
449
- static int rebase_normalize_opts(
450
- git_repository *repo,
451
- git_rebase_options *opts,
452
- const git_rebase_options *given_opts)
453
- {
454
- git_rebase_options default_opts = GIT_REBASE_OPTIONS_INIT;
455
- git_config *config;
456
-
457
- if (given_opts)
458
- memcpy(opts, given_opts, sizeof(git_rebase_options));
459
- else
460
- memcpy(opts, &default_opts, sizeof(git_rebase_options));
461
-
462
- if (git_repository_config(&config, repo) < 0)
463
- return -1;
464
-
465
- if (given_opts && given_opts->rewrite_notes_ref) {
466
- opts->rewrite_notes_ref = git__strdup(given_opts->rewrite_notes_ref);
467
- GITERR_CHECK_ALLOC(opts->rewrite_notes_ref);
468
- } else if (git_config__get_bool_force(config, "notes.rewrite.rebase", 1)) {
469
- char *rewrite_ref = git_config__get_string_force(
470
- config, "notes.rewriteref", NOTES_DEFAULT_REF);
471
-
472
- if (rewrite_ref) {
473
- opts->rewrite_notes_ref = rewrite_ref;
474
- GITERR_CHECK_ALLOC(opts->rewrite_notes_ref);
475
- }
476
- }
477
-
478
- git_config_free(config);
479
-
480
- return 0;
481
- }
482
-
483
- static void rebase_opts_free(git_rebase_options *opts)
484
- {
485
- if (!opts)
486
- return;
487
-
488
- git__free((char *)opts->rewrite_notes_ref);
489
- }
490
-
491
490
  static int rebase_ensure_not_in_progress(git_repository *repo)
492
491
  {
493
492
  int error;
@@ -504,33 +503,42 @@ static int rebase_ensure_not_in_progress(git_repository *repo)
504
503
  return 0;
505
504
  }
506
505
 
507
- static int rebase_ensure_not_dirty(git_repository *repo)
506
+ static int rebase_ensure_not_dirty(
507
+ git_repository *repo,
508
+ bool check_index,
509
+ bool check_workdir,
510
+ int fail_with)
508
511
  {
509
512
  git_tree *head = NULL;
510
513
  git_index *index = NULL;
511
514
  git_diff *diff = NULL;
512
515
  int error;
513
516
 
514
- if ((error = git_repository_head_tree(&head, repo)) < 0 ||
515
- (error = git_repository_index(&index, repo)) < 0 ||
516
- (error = git_diff_tree_to_index(&diff, repo, head, index, NULL)) < 0)
517
- goto done;
517
+ if (check_index) {
518
+ if ((error = git_repository_head_tree(&head, repo)) < 0 ||
519
+ (error = git_repository_index(&index, repo)) < 0 ||
520
+ (error = git_diff_tree_to_index(&diff, repo, head, index, NULL)) < 0)
521
+ goto done;
518
522
 
519
- if (git_diff_num_deltas(diff) > 0) {
520
- giterr_set(GITERR_REBASE, "Uncommitted changes exist in index");
521
- error = -1;
522
- goto done;
523
- }
523
+ if (git_diff_num_deltas(diff) > 0) {
524
+ giterr_set(GITERR_REBASE, "Uncommitted changes exist in index");
525
+ error = fail_with;
526
+ goto done;
527
+ }
524
528
 
525
- git_diff_free(diff);
526
- diff = NULL;
529
+ git_diff_free(diff);
530
+ diff = NULL;
531
+ }
527
532
 
528
- if ((error = git_diff_index_to_workdir(&diff, repo, index, NULL)) < 0)
529
- goto done;
533
+ if (check_workdir) {
534
+ if ((error = git_diff_index_to_workdir(&diff, repo, index, NULL)) < 0)
535
+ goto done;
530
536
 
531
- if (git_diff_num_deltas(diff) > 0) {
532
- giterr_set(GITERR_REBASE, "Unstaged changes exist in workdir");
533
- error = -1;
537
+ if (git_diff_num_deltas(diff) > 0) {
538
+ giterr_set(GITERR_REBASE, "Unstaged changes exist in workdir");
539
+ error = fail_with;
540
+ goto done;
541
+ }
534
542
  }
535
543
 
536
544
  done:
@@ -607,8 +615,7 @@ static int rebase_init(
607
615
  git_repository *repo,
608
616
  const git_annotated_commit *branch,
609
617
  const git_annotated_commit *upstream,
610
- const git_annotated_commit *onto,
611
- const git_rebase_options *opts)
618
+ const git_annotated_commit *onto)
612
619
  {
613
620
  git_reference *head_ref = NULL;
614
621
  git_annotated_commit *head_branch = NULL;
@@ -630,7 +637,7 @@ static int rebase_init(
630
637
  rebase->type = GIT_REBASE_TYPE_MERGE;
631
638
  rebase->state_path = git_buf_detach(&state_path);
632
639
  rebase->orig_head_name = git__strdup(branch->ref_name ? branch->ref_name : ORIG_DETACHED_HEAD);
633
- rebase->quiet = opts->quiet;
640
+ rebase->quiet = rebase->options.quiet;
634
641
 
635
642
  git_oid_cpy(&rebase->orig_head_id, git_annotated_commit_id(branch));
636
643
  git_oid_cpy(&rebase->onto_id, git_annotated_commit_id(onto));
@@ -658,10 +665,8 @@ int git_rebase_init(
658
665
  const git_rebase_options *given_opts)
659
666
  {
660
667
  git_rebase *rebase = NULL;
661
- git_rebase_options opts;
662
668
  git_buf reflog = GIT_BUF_INIT;
663
669
  git_commit *onto_commit = NULL;
664
- git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
665
670
  git_reference *head_ref = NULL;
666
671
  int error;
667
672
 
@@ -669,31 +674,26 @@ int git_rebase_init(
669
674
 
670
675
  *out = NULL;
671
676
 
672
- GITERR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options");
673
-
674
677
  if (!onto)
675
678
  onto = upstream;
676
679
 
677
- checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
678
-
679
- if ((error = rebase_normalize_opts(repo, &opts, given_opts)) < 0 ||
680
+ if ((error = rebase_check_versions(given_opts)) < 0 ||
680
681
  (error = git_repository__ensure_not_bare(repo, "rebase")) < 0 ||
681
682
  (error = rebase_ensure_not_in_progress(repo)) < 0 ||
682
- (error = rebase_ensure_not_dirty(repo)) < 0 ||
683
+ (error = rebase_ensure_not_dirty(repo, true, true, GIT_ERROR)) < 0 ||
683
684
  (error = git_commit_lookup(
684
685
  &onto_commit, repo, git_annotated_commit_id(onto))) < 0)
685
686
  return error;
686
687
 
687
- rebase = git__calloc(1, sizeof(git_rebase));
688
- GITERR_CHECK_ALLOC(rebase);
688
+ rebase = rebase_alloc(given_opts);
689
689
 
690
690
  if ((error = rebase_init(
691
- rebase, repo, branch, upstream, onto, &opts)) < 0 ||
691
+ rebase, repo, branch, upstream, onto)) < 0 ||
692
692
  (error = rebase_setupfiles(rebase)) < 0 ||
693
693
  (error = git_buf_printf(&reflog,
694
694
  "rebase: checkout %s", rebase_onto_name(onto))) < 0 ||
695
695
  (error = git_checkout_tree(
696
- repo, (git_object *)onto_commit, &checkout_opts)) < 0 ||
696
+ repo, (git_object *)onto_commit, &rebase->options.checkout_options)) < 0 ||
697
697
  (error = git_reference_create(&head_ref, repo, GIT_HEAD_FILE,
698
698
  git_annotated_commit_id(onto), 1, reflog.ptr)) < 0)
699
699
  goto done;
@@ -709,25 +709,16 @@ done:
709
709
 
710
710
  git_commit_free(onto_commit);
711
711
  git_buf_free(&reflog);
712
- rebase_opts_free(&opts);
713
712
 
714
713
  return error;
715
714
  }
716
715
 
717
- static void normalize_checkout_opts(
718
- git_rebase *rebase,
719
- git_commit *current_commit,
716
+ static void normalize_checkout_options_for_apply(
720
717
  git_checkout_options *checkout_opts,
721
- const git_checkout_options *given_checkout_opts)
718
+ git_rebase *rebase,
719
+ git_commit *current_commit)
722
720
  {
723
- if (given_checkout_opts != NULL)
724
- memcpy(checkout_opts, given_checkout_opts, sizeof(git_checkout_options));
725
- else {
726
- git_checkout_options default_checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
727
- default_checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
728
-
729
- memcpy(checkout_opts, &default_checkout_opts, sizeof(git_checkout_options));
730
- }
721
+ memcpy(checkout_opts, &rebase->options.checkout_options, sizeof(git_checkout_options));
731
722
 
732
723
  if (!checkout_opts->ancestor_label)
733
724
  checkout_opts->ancestor_label = "ancestor";
@@ -758,16 +749,15 @@ GIT_INLINE(int) rebase_movenext(git_rebase *rebase)
758
749
 
759
750
  static int rebase_next_merge(
760
751
  git_rebase_operation **out,
761
- git_rebase *rebase,
762
- git_checkout_options *given_checkout_opts)
752
+ git_rebase *rebase)
763
753
  {
764
754
  git_buf path = GIT_BUF_INIT;
765
- git_checkout_options checkout_opts = {0};
766
755
  git_commit *current_commit = NULL, *parent_commit = NULL;
767
756
  git_tree *current_tree = NULL, *head_tree = NULL, *parent_tree = NULL;
768
757
  git_index *index = NULL;
769
758
  git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
770
759
  git_rebase_operation *operation;
760
+ git_checkout_options checkout_opts;
771
761
  char current_idstr[GIT_OID_HEXSZ];
772
762
  unsigned int parent_count;
773
763
  int error;
@@ -796,7 +786,7 @@ static int rebase_next_merge(
796
786
 
797
787
  git_oid_fmt(current_idstr, &operation->id);
798
788
 
799
- normalize_checkout_opts(rebase, current_commit, &checkout_opts, given_checkout_opts);
789
+ normalize_checkout_options_for_apply(&checkout_opts, rebase, current_commit);
800
790
 
801
791
  if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 ||
802
792
  (error = rebase_setupfile(rebase, MSGNUM_FILE, -1, "%d\n", rebase->current+1)) < 0 ||
@@ -824,8 +814,7 @@ done:
824
814
 
825
815
  int git_rebase_next(
826
816
  git_rebase_operation **out,
827
- git_rebase *rebase,
828
- git_checkout_options *checkout_opts)
817
+ git_rebase *rebase)
829
818
  {
830
819
  int error;
831
820
 
@@ -833,7 +822,7 @@ int git_rebase_next(
833
822
 
834
823
  switch (rebase->type) {
835
824
  case GIT_REBASE_TYPE_MERGE:
836
- error = rebase_next_merge(out, rebase, checkout_opts);
825
+ error = rebase_next_merge(out, rebase);
837
826
  break;
838
827
  default:
839
828
  abort();
@@ -869,11 +858,12 @@ static int rebase_commit_merge(
869
858
 
870
859
  if (git_index_has_conflicts(index)) {
871
860
  giterr_set(GITERR_REBASE, "Conflicts have not been resolved");
872
- error = GIT_EMERGECONFLICT;
861
+ error = GIT_EUNMERGED;
873
862
  goto done;
874
863
  }
875
864
 
876
- if ((error = git_commit_lookup(&current_commit, rebase->repo, &operation->id)) < 0 ||
865
+ if ((error = rebase_ensure_not_dirty(rebase->repo, false, true, GIT_EUNMERGED)) < 0 ||
866
+ (error = git_commit_lookup(&current_commit, rebase->repo, &operation->id)) < 0 ||
877
867
  (error = git_repository_head(&head, rebase->repo)) < 0 ||
878
868
  (error = git_reference_peel((git_object **)&head_commit, head, GIT_OBJ_COMMIT)) < 0 ||
879
869
  (error = git_commit_tree(&head_tree, head_commit)) < 0 ||
@@ -971,7 +961,7 @@ int git_rebase_abort(git_rebase *rebase)
971
961
  if ((error = git_commit_lookup(
972
962
  &orig_head_commit, rebase->repo, &rebase->orig_head_id)) < 0 ||
973
963
  (error = git_reset(rebase->repo, (git_object *)orig_head_commit,
974
- GIT_RESET_HARD, NULL)) < 0)
964
+ GIT_RESET_HARD, &rebase->options.checkout_options)) < 0)
975
965
  goto done;
976
966
 
977
967
  error = rebase_cleanup(rebase);
@@ -983,19 +973,50 @@ done:
983
973
  return error;
984
974
  }
985
975
 
976
+ static int notes_ref_lookup(git_buf *out, git_rebase *rebase)
977
+ {
978
+ git_config *config = NULL;
979
+ int do_rewrite, error;
980
+
981
+ if (rebase->options.rewrite_notes_ref) {
982
+ git_buf_attach_notowned(out,
983
+ rebase->options.rewrite_notes_ref,
984
+ strlen(rebase->options.rewrite_notes_ref));
985
+ return 0;
986
+ }
987
+
988
+ if ((error = git_repository_config(&config, rebase->repo)) < 0 ||
989
+ (error = git_config_get_bool(&do_rewrite, config, "notes.rewrite.rebase")) < 0) {
990
+
991
+ if (error != GIT_ENOTFOUND)
992
+ goto done;
993
+
994
+ giterr_clear();
995
+ do_rewrite = 1;
996
+ }
997
+
998
+ error = do_rewrite ?
999
+ git_config_get_string_buf(out, config, "notes.rewriteref") :
1000
+ GIT_ENOTFOUND;
1001
+
1002
+ done:
1003
+ git_config_free(config);
1004
+ return error;
1005
+ }
1006
+
986
1007
  static int rebase_copy_note(
987
1008
  git_rebase *rebase,
1009
+ const char *notes_ref,
988
1010
  git_oid *from,
989
1011
  git_oid *to,
990
- const git_signature *committer,
991
- const git_rebase_options *opts)
1012
+ const git_signature *committer)
992
1013
  {
993
1014
  git_note *note = NULL;
994
1015
  git_oid note_id;
995
1016
  git_signature *who = NULL;
996
1017
  int error;
997
1018
 
998
- if ((error = git_note_read(&note, rebase->repo, opts->rewrite_notes_ref, from)) < 0) {
1019
+ if ((error = git_note_read(&note, rebase->repo, notes_ref, from)) < 0) {
999
1020
  if (error == GIT_ENOTFOUND) {
1000
1021
  giterr_clear();
1001
1022
  error = 0;
@@ -1016,7 +1037,7 @@ static int rebase_copy_note(
1016
1037
  committer = who;
1017
1038
  }
1018
1039
 
1019
- error = git_note_create(&note_id, rebase->repo, opts->rewrite_notes_ref,
1040
+ error = git_note_create(&note_id, rebase->repo, notes_ref,
1020
1041
  git_note_author(note), committer, to, git_note_message(note), 0);
1021
1042
 
1022
1043
  done:
@@ -1028,17 +1049,22 @@ done:
1028
1049
 
1029
1050
  static int rebase_copy_notes(
1030
1051
  git_rebase *rebase,
1031
- const git_signature *committer,
1032
- const git_rebase_options *opts)
1052
+ const git_signature *committer)
1033
1053
  {
1034
- git_buf path = GIT_BUF_INIT, rewritten = GIT_BUF_INIT;
1054
+ git_buf path = GIT_BUF_INIT, rewritten = GIT_BUF_INIT, notes_ref = GIT_BUF_INIT;
1035
1055
  char *pair_list, *fromstr, *tostr, *end;
1036
1056
  git_oid from, to;
1037
1057
  unsigned int linenum = 1;
1038
1058
  int error = 0;
1039
1059
 
1040
- if (!opts->rewrite_notes_ref)
1060
+ if ((error = notes_ref_lookup(&notes_ref, rebase)) < 0) {
1061
+ if (error == GIT_ENOTFOUND) {
1062
+ giterr_clear();
1063
+ error = 0;
1064
+ }
1065
+
1041
1066
  goto done;
1067
+ }
1042
1068
 
1043
1069
  if ((error = git_buf_joinpath(&path, rebase->state_path, REWRITTEN_FILE)) < 0 ||
1044
1070
  (error = git_futils_readbuffer(&rewritten, path.ptr)) < 0)
@@ -1067,7 +1093,7 @@ static int rebase_copy_notes(
1067
1093
  git_oid_fromstr(&to, tostr) < 0)
1068
1094
  goto on_error;
1069
1095
 
1070
- if ((error = rebase_copy_note(rebase, &from, &to, committer, opts)) < 0)
1096
+ if ((error = rebase_copy_note(rebase, notes_ref.ptr, &from, &to, committer)) < 0)
1071
1097
  goto done;
1072
1098
 
1073
1099
  linenum++;
@@ -1082,16 +1108,15 @@ on_error:
1082
1108
  done:
1083
1109
  git_buf_free(&rewritten);
1084
1110
  git_buf_free(&path);
1111
+ git_buf_free(&notes_ref);
1085
1112
 
1086
1113
  return error;
1087
1114
  }
1088
1115
 
1089
1116
  int git_rebase_finish(
1090
1117
  git_rebase *rebase,
1091
- const git_signature *signature,
1092
- const git_rebase_options *given_opts)
1118
+ const git_signature *signature)
1093
1119
  {
1094
- git_rebase_options opts;
1095
1120
  git_reference *terminal_ref = NULL, *branch_ref = NULL, *head_ref = NULL;
1096
1121
  git_commit *terminal_commit = NULL;
1097
1122
  git_buf branch_msg = GIT_BUF_INIT, head_msg = GIT_BUF_INIT;
@@ -1100,11 +1125,6 @@ int git_rebase_finish(
1100
1125
 
1101
1126
  assert(rebase);
1102
1127
 
1103
- GITERR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options");
1104
-
1105
- if ((error = rebase_normalize_opts(rebase->repo, &opts, given_opts)) < 0)
1106
- goto done;
1107
-
1108
1128
  git_oid_fmt(onto, &rebase->onto_id);
1109
1129
 
1110
1130
  if ((error = git_buf_printf(&branch_msg, "rebase finished: %s onto %.*s",
@@ -1120,7 +1140,7 @@ int git_rebase_finish(
1120
1140
  (error = git_reference_symbolic_create(&head_ref,
1121
1141
  rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
1122
1142
  head_msg.ptr)) < 0 ||
1123
- (error = rebase_copy_notes(rebase, signature, &opts)) < 0)
1143
+ (error = rebase_copy_notes(rebase, signature)) < 0)
1124
1144
  goto done;
1125
1145
 
1126
1146
  error = rebase_cleanup(rebase);
@@ -1132,7 +1152,6 @@ done:
1132
1152
  git_reference_free(head_ref);
1133
1153
  git_reference_free(branch_ref);
1134
1154
  git_reference_free(terminal_ref);
1135
- rebase_opts_free(&opts);
1136
1155
 
1137
1156
  return error;
1138
1157
  }
@@ -1148,7 +1167,7 @@ size_t git_rebase_operation_current(git_rebase *rebase)
1148
1167
  {
1149
1168
  assert(rebase);
1150
1169
 
1151
- return rebase->current;
1170
+ return rebase->started ? rebase->current : GIT_REBASE_NO_OPERATION;
1152
1171
  }
1153
1172
 
1154
1173
  git_rebase_operation *git_rebase_operation_byindex(git_rebase *rebase, size_t idx)
@@ -1167,5 +1186,6 @@ void git_rebase_free(git_rebase *rebase)
1167
1186
  git__free(rebase->orig_head_name);
1168
1187
  git__free(rebase->state_path);
1169
1188
  git_array_clear(rebase->operations);
1189
+ git__free((char *)rebase->options.rewrite_notes_ref);
1170
1190
  git__free(rebase);
1171
1191
  }
@@ -193,7 +193,7 @@ int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry)
193
193
  entry = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx);
194
194
 
195
195
  if (entry == NULL) {
196
- giterr_set(GITERR_REFERENCE, "No reflog entry at index "PRIuZ, idx);
196
+ giterr_set(GITERR_REFERENCE, "No reflog entry at index %"PRIuZ, idx);
197
197
  return GIT_ENOTFOUND;
198
198
  }
199
199
 
@@ -1052,12 +1052,10 @@ static int get_terminal(git_reference **out, git_repository *repo, const char *r
1052
1052
  error = 0;
1053
1053
  } else {
1054
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 {
1055
+ if (error == GIT_ENOTFOUND && !*out)
1056
+ *out = ref;
1057
+ else
1059
1058
  git_reference_free(ref);
1060
- }
1061
1059
  }
1062
1060
 
1063
1061
  return error;
@@ -171,11 +171,11 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
171
171
  if ((error = git_repository_config_snapshot(&config, repo)) < 0)
172
172
  goto on_error;
173
173
 
174
- if (lookup_remote_prune_config(remote, config, name) < 0)
174
+ if ((error = lookup_remote_prune_config(remote, config, name)) < 0)
175
175
  goto on_error;
176
176
 
177
177
  /* Move the data over to where the matching functions can find them */
178
- if (dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs) < 0)
178
+ if ((error = dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs)) < 0)
179
179
  goto on_error;
180
180
  }
181
181
 
@@ -457,7 +457,7 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
457
457
  goto cleanup;
458
458
 
459
459
  /* Move the data over to where the matching functions can find them */
460
- if (dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs) < 0)
460
+ if ((error = dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs)) < 0)
461
461
  goto cleanup;
462
462
 
463
463
  *out = remote;
@@ -2330,7 +2330,7 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
2330
2330
  goto cleanup;
2331
2331
 
2332
2332
  free_refspecs(&remote->active_refspecs);
2333
- if (dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs) < 0)
2333
+ if ((error = dwim_refspecs(&remote->active_refspecs, &remote->refspecs, &remote->refs)) < 0)
2334
2334
  goto cleanup;
2335
2335
 
2336
2336
  if (remote->push) {
@@ -2363,7 +2363,8 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
2363
2363
  cbs = &remote->callbacks;
2364
2364
  if ((error = git_push_set_callbacks(push,
2365
2365
  cbs->pack_progress, cbs->payload,
2366
- cbs->push_transfer_progress, cbs->payload)) < 0)
2366
+ cbs->push_transfer_progress, cbs->payload,
2367
+ cbs->push_negotiation, cbs->payload)) < 0)
2367
2368
  goto cleanup;
2368
2369
 
2369
2370
  if ((error = git_push_finish(push)) < 0)
@@ -133,7 +133,9 @@ void git_repository_free(git_repository *repo)
133
133
 
134
134
  for (i = 0; i < repo->reserved_names.size; i++)
135
135
  git_buf_free(git_array_get(repo->reserved_names, i));
136
+ git_array_clear(repo->reserved_names);
136
137
 
138
+ git__free(repo->path_gitlink);
137
139
  git__free(repo->path_repository);
138
140
  git__free(repo->workdir);
139
141
  git__free(repo->namespace);
@@ -1606,6 +1608,7 @@ int git_repository_init_ext(
1606
1608
  {
1607
1609
  int error;
1608
1610
  git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT;
1611
+ const char *wd;
1609
1612
 
1610
1613
  assert(out && given_repo && opts);
1611
1614
 
@@ -1615,6 +1618,7 @@ int git_repository_init_ext(
1615
1618
  if (error < 0)
1616
1619
  goto cleanup;
1617
1620
 
1621
+ wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_buf_cstr(&wd_path);
1618
1622
  if (valid_repository_path(&repo_path)) {
1619
1623
 
1620
1624
  if ((opts->flags & GIT_REPOSITORY_INIT_NO_REINIT) != 0) {
@@ -1627,15 +1631,15 @@ int git_repository_init_ext(
1627
1631
  opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT;
1628
1632
 
1629
1633
  error = repo_init_config(
1630
- repo_path.ptr, wd_path.ptr, opts->flags, opts->mode);
1634
+ repo_path.ptr, wd, opts->flags, opts->mode);
1631
1635
 
1632
1636
  /* TODO: reinitialize the templates */
1633
1637
  }
1634
1638
  else {
1635
1639
  if (!(error = repo_init_structure(
1636
- repo_path.ptr, wd_path.ptr, opts)) &&
1640
+ repo_path.ptr, wd, opts)) &&
1637
1641
  !(error = repo_init_config(
1638
- repo_path.ptr, wd_path.ptr, opts->flags, opts->mode)))
1642
+ repo_path.ptr, wd, opts->flags, opts->mode)))
1639
1643
  error = repo_init_create_head(
1640
1644
  repo_path.ptr, opts->initial_head);
1641
1645
  }
@@ -102,7 +102,7 @@ static int reset(
102
102
  git_object *target,
103
103
  const char *to,
104
104
  git_reset_t reset_type,
105
- git_checkout_options *checkout_opts)
105
+ const git_checkout_options *checkout_opts)
106
106
  {
107
107
  git_object *commit = NULL;
108
108
  git_index *index = NULL;
@@ -183,7 +183,7 @@ int git_reset(
183
183
  git_repository *repo,
184
184
  git_object *target,
185
185
  git_reset_t reset_type,
186
- git_checkout_options *checkout_opts)
186
+ const git_checkout_options *checkout_opts)
187
187
  {
188
188
  return reset(repo, target, git_oid_tostr_s(git_object_id(target)), reset_type, checkout_opts);
189
189
  }
@@ -192,7 +192,7 @@ int git_reset_from_annotated(
192
192
  git_repository *repo,
193
193
  git_annotated_commit *commit,
194
194
  git_reset_t reset_type,
195
- git_checkout_options *checkout_opts)
195
+ const git_checkout_options *checkout_opts)
196
196
  {
197
197
  return reset(repo, (git_object *) commit->commit, commit->ref_name, reset_type, checkout_opts);
198
198
  }
@@ -41,11 +41,31 @@ git_commit_list_node *git_revwalk__commit_lookup(
41
41
  return commit;
42
42
  }
43
43
 
44
+ typedef git_array_t(git_commit_list_node*) commit_list_node_array;
45
+
46
+ static bool interesting_arr(commit_list_node_array arr)
47
+ {
48
+ git_commit_list_node **n;
49
+ size_t i = 0, size;
50
+
51
+ size = git_array_size(arr);
52
+ for (i = 0; i < size; i++) {
53
+ n = git_array_get(arr, i);
54
+ if (!*n)
55
+ break;
56
+
57
+ if (!(*n)->uninteresting)
58
+ return true;
59
+ }
60
+
61
+ return false;
62
+ }
63
+
44
64
  static int mark_uninteresting(git_revwalk *walk, git_commit_list_node *commit)
45
65
  {
46
66
  int error;
47
67
  unsigned short i;
48
- git_array_t(git_commit_list_node *) pending = GIT_ARRAY_INIT;
68
+ commit_list_node_array pending = GIT_ARRAY_INIT;
49
69
  git_commit_list_node **tmp;
50
70
 
51
71
  assert(commit);
@@ -66,7 +86,7 @@ static int mark_uninteresting(git_revwalk *walk, git_commit_list_node *commit)
66
86
  tmp = git_array_pop(pending);
67
87
  commit = tmp ? *tmp : NULL;
68
88
 
69
- } while (commit != NULL);
89
+ } while (commit != NULL && !interesting_arr(pending));
70
90
 
71
91
  git_array_clear(pending);
72
92
 
@@ -144,6 +164,10 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting,
144
164
  if (commit == NULL)
145
165
  return -1; /* error already reported by failed lookup */
146
166
 
167
+ /* A previous hide already told us we don't want this commit */
168
+ if (commit->uninteresting)
169
+ return 0;
170
+
147
171
  if (uninteresting)
148
172
  walk->did_hide = 1;
149
173
  else