Hash :
37b25ac5
Author :
Date :
2018-07-08T16:12:58
apply: move location to an argument, not the opts Move the location option to an argument, out of the options structure. This allows the options structure to be re-used for functions that don't need to know the location, since it's implicit in their functionality. For example, `git_apply_tree` should not take a location, but is expected to take all the other options.
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
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_apply_h__
#define INCLUDE_git_apply_h__
#include "common.h"
#include "types.h"
#include "oid.h"
#include "diff.h"
/**
* @file git2/apply.h
* @brief Git patch application routines
* @defgroup git_apply Git patch application routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Apply options structure
*
* Initialize with `GIT_APPLY_OPTIONS_INIT`. Alternatively, you can
* use `git_apply_init_options`.
*
* @see git_apply_to_tree, git_apply
*/
typedef struct {
unsigned int version;
} git_apply_options;
#define GIT_APPLY_OPTIONS_VERSION 1
#define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION}
/**
* Apply a `git_diff` to a `git_tree`, and return the resulting image
* as an index.
*
* @param out the postimage of the application
* @param repo the repository to apply
* @param preimage the tree to apply the diff to
* @param diff the diff to apply
* @param options the options for the apply (or null for defaults)
*/
GIT_EXTERN(int) git_apply_to_tree(
git_index **out,
git_repository *repo,
git_tree *preimage,
git_diff *diff,
const git_apply_options *options);
typedef enum {
/**
* Apply the patch to the workdir, leaving the index untouched.
* This is the equivalent of `git apply` with no location argument.
*/
GIT_APPLY_LOCATION_WORKDIR = 0,
/**
* Apply the patch to the index, leaving the working directory
* untouched. This is the equivalent of `git apply --cached`.
*/
GIT_APPLY_LOCATION_INDEX = 1,
/**
* Apply the patch to both the working directory and the index.
* This is the equivalent of `git apply --index`.
*/
GIT_APPLY_LOCATION_BOTH = 2,
} git_apply_location_t;
/**
* Apply a `git_diff` to the given repository, making changes directly
* in the working directory, the index, or both.
*
* @param repo the repository to apply to
* @param diff the diff to apply
* @param location the location to apply (workdir, index or both)
* @param options the options for the apply (or null for defaults)
*/
GIT_EXTERN(int) git_apply(
git_repository *repo,
git_diff *diff,
git_apply_location_t location,
const git_apply_options *options);
/** @} */
GIT_END_DECL
#endif