Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:38

0001 /*
0002  * Copyright (C) the libgit2 contributors. All rights reserved.
0003  *
0004  * This file is part of libgit2, distributed under the GNU GPL v2 with
0005  * a Linking Exception. For full terms see the included COPYING file.
0006  */
0007 #ifndef INCLUDE_git_rebase_h__
0008 #define INCLUDE_git_rebase_h__
0009 
0010 #include "common.h"
0011 #include "types.h"
0012 #include "oid.h"
0013 #include "annotated_commit.h"
0014 #include "merge.h"
0015 #include "checkout.h"
0016 #include "commit.h"
0017 
0018 /**
0019  * @file git2/rebase.h
0020  * @brief Git rebase routines
0021  * @defgroup git_rebase Git merge routines
0022  * @ingroup Git
0023  * @{
0024  */
0025 GIT_BEGIN_DECL
0026 
0027 /**
0028  * Rebase options
0029  *
0030  * Use to tell the rebase machinery how to operate.
0031  */
0032 typedef struct {
0033     unsigned int version;
0034 
0035     /**
0036      * Used by `git_rebase_init`, this will instruct other clients working
0037      * on this rebase that you want a quiet rebase experience, which they
0038      * may choose to provide in an application-specific manner.  This has no
0039      * effect upon libgit2 directly, but is provided for interoperability
0040      * between Git tools.
0041      */
0042     int quiet;
0043 
0044     /**
0045      * Used by `git_rebase_init`, this will begin an in-memory rebase,
0046      * which will allow callers to step through the rebase operations and
0047      * commit the rebased changes, but will not rewind HEAD or update the
0048      * repository to be in a rebasing state.  This will not interfere with
0049      * the working directory (if there is one).
0050      */
0051     int inmemory;
0052 
0053     /**
0054      * Used by `git_rebase_finish`, this is the name of the notes reference
0055      * used to rewrite notes for rebased commits when finishing the rebase;
0056      * if NULL, the contents of the configuration option `notes.rewriteRef`
0057      * is examined, unless the configuration option `notes.rewrite.rebase`
0058      * is set to false.  If `notes.rewriteRef` is also NULL, notes will
0059      * not be rewritten.
0060      */
0061     const char *rewrite_notes_ref;
0062 
0063     /**
0064      * Options to control how trees are merged during `git_rebase_next`.
0065      */
0066     git_merge_options merge_options;
0067 
0068     /**
0069      * Options to control how files are written during `git_rebase_init`,
0070      * `git_rebase_next` and `git_rebase_abort`.  Note that a minimum
0071      * strategy of `GIT_CHECKOUT_SAFE` is defaulted in `init` and `next`,
0072      * and a minimum strategy of `GIT_CHECKOUT_FORCE` is defaulted in
0073      * `abort` to match git semantics.
0074      */
0075     git_checkout_options checkout_options;
0076 
0077     /**
0078      * Optional callback that allows users to override commit
0079      * creation in `git_rebase_commit`.  If specified, users can
0080      * create their own commit and provide the commit ID, which
0081      * may be useful for signing commits or otherwise customizing
0082      * the commit creation.
0083      *
0084      * If this callback returns `GIT_PASSTHROUGH`, then
0085      * `git_rebase_commit` will continue to create the commit.
0086      */
0087     git_commit_create_cb commit_create_cb;
0088 
0089 #ifdef GIT_DEPRECATE_HARD
0090     void *reserved;
0091 #else
0092     /**
0093      * If provided, this will be called with the commit content, allowing
0094      * a signature to be added to the rebase commit. Can be skipped with
0095      * GIT_PASSTHROUGH. If GIT_PASSTHROUGH is returned, a commit will be made
0096      * without a signature.
0097      *
0098      * This field is only used when performing git_rebase_commit.
0099      *
0100      * This callback is not invoked if a `git_commit_create_cb` is
0101      * specified.
0102      *
0103      * This callback is deprecated; users should provide a
0104      * creation callback as `commit_create_cb` that produces a
0105      * commit buffer, signs it, and commits it.
0106      */
0107     int (*signing_cb)(git_buf *, git_buf *, const char *, void *);
0108 #endif
0109 
0110     /**
0111      * This will be passed to each of the callbacks in this struct
0112      * as the last parameter.
0113      */
0114     void *payload;
0115 } git_rebase_options;
0116 
0117 /**
0118  * Type of rebase operation in-progress after calling `git_rebase_next`.
0119  */
0120 typedef enum {
0121     /**
0122      * The given commit is to be cherry-picked.  The client should commit
0123      * the changes and continue if there are no conflicts.
0124      */
0125     GIT_REBASE_OPERATION_PICK = 0,
0126 
0127     /**
0128      * The given commit is to be cherry-picked, but the client should prompt
0129      * the user to provide an updated commit message.
0130      */
0131     GIT_REBASE_OPERATION_REWORD,
0132 
0133     /**
0134      * The given commit is to be cherry-picked, but the client should stop
0135      * to allow the user to edit the changes before committing them.
0136      */
0137     GIT_REBASE_OPERATION_EDIT,
0138 
0139     /**
0140      * The given commit is to be squashed into the previous commit.  The
0141      * commit message will be merged with the previous message.
0142      */
0143     GIT_REBASE_OPERATION_SQUASH,
0144 
0145     /**
0146      * The given commit is to be squashed into the previous commit.  The
0147      * commit message from this commit will be discarded.
0148      */
0149     GIT_REBASE_OPERATION_FIXUP,
0150 
0151     /**
0152      * No commit will be cherry-picked.  The client should run the given
0153      * command and (if successful) continue.
0154      */
0155     GIT_REBASE_OPERATION_EXEC
0156 } git_rebase_operation_t;
0157 
0158 #define GIT_REBASE_OPTIONS_VERSION 1
0159 #define GIT_REBASE_OPTIONS_INIT \
0160     { GIT_REBASE_OPTIONS_VERSION, 0, 0, NULL, GIT_MERGE_OPTIONS_INIT, \
0161       GIT_CHECKOUT_OPTIONS_INIT, NULL, NULL }
0162 
0163 /** Indicates that a rebase operation is not (yet) in progress. */
0164 #define GIT_REBASE_NO_OPERATION SIZE_MAX
0165 
0166 /**
0167  * A rebase operation
0168  *
0169  * Describes a single instruction/operation to be performed during the
0170  * rebase.
0171  */
0172 typedef struct {
0173     /** The type of rebase operation. */
0174     git_rebase_operation_t type;
0175 
0176     /**
0177      * The commit ID being cherry-picked.  This will be populated for
0178      * all operations except those of type `GIT_REBASE_OPERATION_EXEC`.
0179      */
0180     const git_oid id;
0181 
0182     /**
0183      * The executable the user has requested be run.  This will only
0184      * be populated for operations of type `GIT_REBASE_OPERATION_EXEC`.
0185      */
0186     const char *exec;
0187 } git_rebase_operation;
0188 
0189 /**
0190  * Initialize git_rebase_options structure
0191  *
0192  * Initializes a `git_rebase_options` with default values. Equivalent to
0193  * creating an instance with `GIT_REBASE_OPTIONS_INIT`.
0194  *
0195  * @param opts The `git_rebase_options` struct to initialize.
0196  * @param version The struct version; pass `GIT_REBASE_OPTIONS_VERSION`.
0197  * @return Zero on success; -1 on failure.
0198  */
0199 GIT_EXTERN(int) git_rebase_options_init(
0200     git_rebase_options *opts,
0201     unsigned int version);
0202 
0203 /**
0204  * Initializes a rebase operation to rebase the changes in `branch`
0205  * relative to `upstream` onto another branch.  To begin the rebase
0206  * process, call `git_rebase_next`.  When you have finished with this
0207  * object, call `git_rebase_free`.
0208  *
0209  * @param out Pointer to store the rebase object
0210  * @param repo The repository to perform the rebase
0211  * @param branch The terminal commit to rebase, or NULL to rebase the
0212  *               current branch
0213  * @param upstream The commit to begin rebasing from, or NULL to rebase all
0214  *                 reachable commits
0215  * @param onto The branch to rebase onto, or NULL to rebase onto the given
0216  *             upstream
0217  * @param opts Options to specify how rebase is performed, or NULL
0218  * @return Zero on success; -1 on failure.
0219  */
0220 GIT_EXTERN(int) git_rebase_init(
0221     git_rebase **out,
0222     git_repository *repo,
0223     const git_annotated_commit *branch,
0224     const git_annotated_commit *upstream,
0225     const git_annotated_commit *onto,
0226     const git_rebase_options *opts);
0227 
0228 /**
0229  * Opens an existing rebase that was previously started by either an
0230  * invocation of `git_rebase_init` or by another client.
0231  *
0232  * @param out Pointer to store the rebase object
0233  * @param repo The repository that has a rebase in-progress
0234  * @param opts Options to specify how rebase is performed
0235  * @return Zero on success; -1 on failure.
0236  */
0237 GIT_EXTERN(int) git_rebase_open(
0238     git_rebase **out,
0239     git_repository *repo,
0240     const git_rebase_options *opts);
0241 
0242 /**
0243  * Gets the original `HEAD` ref name for merge rebases.
0244  *
0245  * @param rebase The in-progress rebase.
0246  * @return The original `HEAD` ref name
0247  */
0248 GIT_EXTERN(const char *) git_rebase_orig_head_name(git_rebase *rebase);
0249 
0250 /**
0251  * Gets the original `HEAD` id for merge rebases.
0252  *
0253  * @param rebase The in-progress rebase.
0254  * @return The original `HEAD` id
0255  */
0256 GIT_EXTERN(const git_oid *) git_rebase_orig_head_id(git_rebase *rebase);
0257 
0258 /**
0259  * Gets the `onto` ref name for merge rebases.
0260  *
0261  * @param rebase The in-progress rebase.
0262  * @return The `onto` ref name
0263  */
0264 GIT_EXTERN(const char *) git_rebase_onto_name(git_rebase *rebase);
0265 
0266 /**
0267  * Gets the `onto` id for merge rebases.
0268  *
0269  * @param rebase The in-progress rebase.
0270  * @return The `onto` id
0271  */
0272 GIT_EXTERN(const git_oid *) git_rebase_onto_id(git_rebase *rebase);
0273 
0274 /**
0275  * Gets the count of rebase operations that are to be applied.
0276  *
0277  * @param rebase The in-progress rebase
0278  * @return The number of rebase operations in total
0279  */
0280 GIT_EXTERN(size_t) git_rebase_operation_entrycount(git_rebase *rebase);
0281 
0282 /**
0283  * Gets the index of the rebase operation that is currently being applied.
0284  * If the first operation has not yet been applied (because you have
0285  * called `init` but not yet `next`) then this returns
0286  * `GIT_REBASE_NO_OPERATION`.
0287  *
0288  * @param rebase The in-progress rebase
0289  * @return The index of the rebase operation currently being applied.
0290  */
0291 GIT_EXTERN(size_t) git_rebase_operation_current(git_rebase *rebase);
0292 
0293 /**
0294  * Gets the rebase operation specified by the given index.
0295  *
0296  * @param rebase The in-progress rebase
0297  * @param idx The index of the rebase operation to retrieve
0298  * @return The rebase operation or NULL if `idx` was out of bounds
0299  */
0300 GIT_EXTERN(git_rebase_operation *) git_rebase_operation_byindex(
0301     git_rebase *rebase,
0302     size_t idx);
0303 
0304 /**
0305  * Performs the next rebase operation and returns the information about it.
0306  * If the operation is one that applies a patch (which is any operation except
0307  * GIT_REBASE_OPERATION_EXEC) then the patch will be applied and the index and
0308  * working directory will be updated with the changes.  If there are conflicts,
0309  * you will need to address those before committing the changes.
0310  *
0311  * @param operation Pointer to store the rebase operation that is to be performed next
0312  * @param rebase The rebase in progress
0313  * @return Zero on success; -1 on failure.
0314  */
0315 GIT_EXTERN(int) git_rebase_next(
0316     git_rebase_operation **operation,
0317     git_rebase *rebase);
0318 
0319 /**
0320  * Gets the index produced by the last operation, which is the result
0321  * of `git_rebase_next` and which will be committed by the next
0322  * invocation of `git_rebase_commit`.  This is useful for resolving
0323  * conflicts in an in-memory rebase before committing them.  You must
0324  * call `git_index_free` when you are finished with this.
0325  *
0326  * This is only applicable for in-memory rebases; for rebases within
0327  * a working directory, the changes were applied to the repository's
0328  * index.
0329  *
0330  * @param index The result index of the last operation.
0331  * @param rebase The in-progress rebase.
0332  * @return 0 or an error code
0333  */
0334 GIT_EXTERN(int) git_rebase_inmemory_index(
0335     git_index **index,
0336     git_rebase *rebase);
0337 
0338 /**
0339  * Commits the current patch.  You must have resolved any conflicts that
0340  * were introduced during the patch application from the `git_rebase_next`
0341  * invocation.
0342  *
0343  * @param id Pointer in which to store the OID of the newly created commit
0344  * @param rebase The rebase that is in-progress
0345  * @param author The author of the updated commit, or NULL to keep the
0346  *        author from the original commit
0347  * @param committer The committer of the rebase
0348  * @param message_encoding The encoding for the message in the commit,
0349  *        represented with a standard encoding name.  If message is NULL,
0350  *        this should also be NULL, and the encoding from the original
0351  *        commit will be maintained.  If message is specified, this may be
0352  *        NULL to indicate that "UTF-8" is to be used.
0353  * @param message The message for this commit, or NULL to use the message
0354  *        from the original commit.
0355  * @return Zero on success, GIT_EUNMERGED if there are unmerged changes in
0356  *        the index, GIT_EAPPLIED if the current commit has already
0357  *        been applied to the upstream and there is nothing to commit,
0358  *        -1 on failure.
0359  */
0360 GIT_EXTERN(int) git_rebase_commit(
0361     git_oid *id,
0362     git_rebase *rebase,
0363     const git_signature *author,
0364     const git_signature *committer,
0365     const char *message_encoding,
0366     const char *message);
0367 
0368 /**
0369  * Aborts a rebase that is currently in progress, resetting the repository
0370  * and working directory to their state before rebase began.
0371  *
0372  * @param rebase The rebase that is in-progress
0373  * @return Zero on success; GIT_ENOTFOUND if a rebase is not in progress,
0374  *         -1 on other errors.
0375  */
0376 GIT_EXTERN(int) git_rebase_abort(git_rebase *rebase);
0377 
0378 /**
0379  * Finishes a rebase that is currently in progress once all patches have
0380  * been applied.
0381  *
0382  * @param rebase The rebase that is in-progress
0383  * @param signature The identity that is finishing the rebase (optional)
0384  * @return Zero on success; -1 on error
0385  */
0386 GIT_EXTERN(int) git_rebase_finish(
0387     git_rebase *rebase,
0388     const git_signature *signature);
0389 
0390 /**
0391  * Frees the `git_rebase` object.
0392  *
0393  * @param rebase The rebase object
0394  */
0395 GIT_EXTERN(void) git_rebase_free(git_rebase *rebase);
0396 
0397 /** @} */
0398 GIT_END_DECL
0399 #endif