rebase: updates based on PR comments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
diff --git a/include/git2.h b/include/git2.h
index 5e032b2..41adbba 100644
--- a/include/git2.h
+++ b/include/git2.h
@@ -40,6 +40,7 @@
#include "git2/patch.h"
#include "git2/pathspec.h"
#include "git2/push.h"
+#include "git2/rebase.h"
#include "git2/refdb.h"
#include "git2/reflog.h"
#include "git2/refs.h"
diff --git a/include/git2/rebase.h b/include/git2/rebase.h
index 24d8fcf..095975e 100644
--- a/include/git2/rebase.h
+++ b/include/git2/rebase.h
@@ -84,21 +84,19 @@ typedef enum {
typedef struct {
/** The type of rebase operation. */
- unsigned int type;
+ git_rebase_operation_t type;
- union {
- /**
- * The commit ID being cherry-picked. This will be populated for
- * all operations except those of type `GIT_REBASE_OPERATION_EXEC`.
- */
- const git_oid id;
+ /**
+ * The commit ID being cherry-picked. This will be populated for
+ * all operations except those of type `GIT_REBASE_OPERATION_EXEC`.
+ */
+ const git_oid id;
- /**
- * The executable the user has requested be run. This will only
- * be populated for operations of type `GIT_REBASE_OPERATION_EXEC`.
- */
- const char *exec;
- };
+ /**
+ * The executable the user has requested be run. This will only
+ * be populated for operations of type `GIT_REBASE_OPERATION_EXEC`.
+ */
+ const char *exec;
} git_rebase_operation;
/**
@@ -115,7 +113,7 @@ GIT_EXTERN(int) git_rebase_init_options(
unsigned int version);
/**
- * Initializes a rebase operation to rebase the changes in `ours`
+ * Initializes a rebase operation to rebase the changes in `branch`
* relative to `upstream` onto another branch. To begin the rebase
* process, call `git_rebase_next`. When you have finished with this
* object, call `git_rebase_free`.
@@ -127,7 +125,7 @@ GIT_EXTERN(int) git_rebase_init_options(
* reachable commits
* @param onto The branch to rebase onto, or NULL to rebase onto the given
* upstream
- * @param signature The signature of the rebaser
+ * @param signature The signature of the rebaser (optional)
* @param opts Options to specify how rebase is performed
* @return Zero on success; -1 on failure.
*/
@@ -242,7 +240,7 @@ GIT_EXTERN(int) git_rebase_abort(
* been applied.
*
* @param rebase The rebase that is in-progress
- * @param signature The identity that is finishing the rebase
+ * @param signature The identity that is finishing the rebase (optional)
* @param opts Options to specify how rebase is finished
* @param Zero on success; -1 on error
*/
@@ -254,7 +252,7 @@ GIT_EXTERN(int) git_rebase_finish(
/**
* Frees the `git_rebase` object.
*
- * @param rebase The rebase that is in-progress
+ * @param rebase The rebase object
*/
GIT_EXTERN(void) git_rebase_free(git_rebase *rebase);
diff --git a/src/rebase.c b/src/rebase.c
index 6905d17..6453ecc 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -23,28 +23,28 @@
#include <git2/revwalk.h>
#include <git2/notes.h>
-#define REBASE_APPLY_DIR "rebase-apply"
-#define REBASE_MERGE_DIR "rebase-merge"
+#define REBASE_APPLY_DIR "rebase-apply"
+#define REBASE_MERGE_DIR "rebase-merge"
-#define HEAD_NAME_FILE "head-name"
-#define ORIG_HEAD_FILE "orig-head"
-#define HEAD_FILE "head"
-#define ONTO_FILE "onto"
-#define ONTO_NAME_FILE "onto_name"
-#define QUIET_FILE "quiet"
+#define HEAD_NAME_FILE "head-name"
+#define ORIG_HEAD_FILE "orig-head"
+#define HEAD_FILE "head"
+#define ONTO_FILE "onto"
+#define ONTO_NAME_FILE "onto_name"
+#define QUIET_FILE "quiet"
-#define MSGNUM_FILE "msgnum"
-#define END_FILE "end"
-#define CMT_FILE_FMT "cmt.%" PRIuZ
-#define CURRENT_FILE "current"
-#define REWRITTEN_FILE "rewritten"
+#define MSGNUM_FILE "msgnum"
+#define END_FILE "end"
+#define CMT_FILE_FMT "cmt.%" PRIuZ
+#define CURRENT_FILE "current"
+#define REWRITTEN_FILE "rewritten"
-#define ORIG_DETACHED_HEAD "detached HEAD"
+#define ORIG_DETACHED_HEAD "detached HEAD"
-#define NOTES_DEFAULT_REF NULL
+#define NOTES_DEFAULT_REF NULL
-#define REBASE_DIR_MODE 0777
-#define REBASE_FILE_MODE 0666
+#define REBASE_DIR_MODE 0777
+#define REBASE_FILE_MODE 0666
typedef enum {
GIT_REBASE_TYPE_NONE = 0,
@@ -948,6 +948,7 @@ static int rebase_copy_note(
{
git_note *note = NULL;
git_oid note_id;
+ git_signature *who = NULL;
int error;
if ((error = git_note_read(¬e, rebase->repo, opts->rewrite_notes_ref, from)) < 0) {
@@ -959,11 +960,24 @@ static int rebase_copy_note(
goto done;
}
+ if (!committer) {
+ if((error = git_signature_default(&who, rebase->repo)) < 0) {
+ if (error != GIT_ENOTFOUND ||
+ (error = git_signature_now(&who, "unknown", "unknown")) < 0)
+ goto done;
+
+ giterr_clear();
+ }
+
+ committer = who;
+ }
+
error = git_note_create(¬e_id, rebase->repo, git_note_author(note),
committer, opts->rewrite_notes_ref, to, git_note_message(note), 0);
done:
git_note_free(note);
+ git_signature_free(who);
return error;
}