File Coverage

deps/libgit2/src/diff_generate.h
Criterion Covered Total %
statement 8 9 88.8
branch 2 4 50.0
condition n/a
subroutine n/a
pod n/a
total 10 13 76.9


line stmt bran cond sub pod time code
1             /*
2             * Copyright (C) the libgit2 contributors. All rights reserved.
3             *
4             * This file is part of libgit2, distributed under the GNU GPL v2 with
5             * a Linking Exception. For full terms see the included COPYING file.
6             */
7             #ifndef INCLUDE_diff_generate_h__
8             #define INCLUDE_diff_generate_h__
9              
10             #include "common.h"
11              
12             #include "diff.h"
13             #include "pool.h"
14             #include "index.h"
15              
16             enum {
17             GIT_DIFFCAPS_HAS_SYMLINKS = (1 << 0), /* symlinks on platform? */
18             GIT_DIFFCAPS_IGNORE_STAT = (1 << 1), /* use stat? */
19             GIT_DIFFCAPS_TRUST_MODE_BITS = (1 << 2), /* use st_mode? */
20             GIT_DIFFCAPS_TRUST_CTIME = (1 << 3), /* use st_ctime? */
21             GIT_DIFFCAPS_USE_DEV = (1 << 4), /* use st_dev? */
22             };
23              
24             #define DIFF_FLAGS_KNOWN_BINARY (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)
25             #define DIFF_FLAGS_NOT_BINARY (GIT_DIFF_FLAG_NOT_BINARY|GIT_DIFF_FLAG__NO_DATA)
26              
27             enum {
28             GIT_DIFF_FLAG__FREE_PATH = (1 << 7), /* `path` is allocated memory */
29             GIT_DIFF_FLAG__FREE_DATA = (1 << 8), /* internal file data is allocated */
30             GIT_DIFF_FLAG__UNMAP_DATA = (1 << 9), /* internal file data is mmap'ed */
31             GIT_DIFF_FLAG__NO_DATA = (1 << 10), /* file data should not be loaded */
32             GIT_DIFF_FLAG__FREE_BLOB = (1 << 11), /* release the blob when done */
33             GIT_DIFF_FLAG__LOADED = (1 << 12), /* file data has been loaded */
34              
35             GIT_DIFF_FLAG__TO_DELETE = (1 << 16), /* delete entry during rename det. */
36             GIT_DIFF_FLAG__TO_SPLIT = (1 << 17), /* split entry during rename det. */
37             GIT_DIFF_FLAG__IS_RENAME_TARGET = (1 << 18),
38             GIT_DIFF_FLAG__IS_RENAME_SOURCE = (1 << 19),
39             GIT_DIFF_FLAG__HAS_SELF_SIMILARITY = (1 << 20),
40             };
41              
42             #define GIT_DIFF_FLAG__CLEAR_INTERNAL(F) (F) = ((F) & 0x00FFFF)
43              
44             #define GIT_DIFF__VERBOSE (1 << 30)
45              
46             extern void git_diff_addref(git_diff *diff);
47              
48             extern bool git_diff_delta__should_skip(
49             const git_diff_options *opts, const git_diff_delta *delta);
50              
51             extern int git_diff__from_iterators(
52             git_diff **diff_ptr,
53             git_repository *repo,
54             git_iterator *old_iter,
55             git_iterator *new_iter,
56             const git_diff_options *opts);
57              
58             extern int git_diff__commit(
59             git_diff **diff, git_repository *repo, const git_commit *commit, const git_diff_options *opts);
60              
61             extern int git_diff__paired_foreach(
62             git_diff *idx2head,
63             git_diff *wd2idx,
64             int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
65             void *payload);
66              
67             /* Merge two `git_diff`s according to the callback given by `cb`. */
68              
69             typedef git_diff_delta *(*git_diff__merge_cb)(
70             const git_diff_delta *left,
71             const git_diff_delta *right,
72             git_pool *pool);
73              
74             extern int git_diff__merge(
75             git_diff *onto, const git_diff *from, git_diff__merge_cb cb);
76              
77             extern git_diff_delta *git_diff__merge_like_cgit(
78             const git_diff_delta *a,
79             const git_diff_delta *b,
80             git_pool *pool);
81              
82             /* Duplicate a `git_diff_delta` out of the `git_pool` */
83             extern git_diff_delta *git_diff__delta_dup(
84             const git_diff_delta *d, git_pool *pool);
85              
86             extern int git_diff__oid_for_file(
87             git_oid *out,
88             git_diff *diff,
89             const char *path,
90             uint16_t mode,
91             git_object_size_t size);
92              
93             extern int git_diff__oid_for_entry(
94             git_oid *out,
95             git_diff *diff,
96             const git_index_entry *src,
97             uint16_t mode,
98             const git_oid *update_match);
99              
100             /*
101             * Sometimes a git_diff_file will have a zero size; this attempts to
102             * fill in the size without loading the blob if possible. If that is
103             * not possible, then it will return the git_odb_object that had to be
104             * loaded and the caller can use it or dispose of it as needed.
105             */
106 13           GIT_INLINE(int) git_diff_file__resolve_zero_size(
107             git_diff_file *file, git_odb_object **odb_obj, git_repository *repo)
108             {
109             int error;
110             git_odb *odb;
111             size_t len;
112             git_object_t type;
113              
114 13 50         if ((error = git_repository_odb(&odb, repo)) < 0)
115 0           return error;
116              
117 13           error = git_odb__read_header_or_object(
118 13           odb_obj, &len, &type, odb, &file->id);
119              
120 13           git_odb_free(odb);
121              
122 13 50         if (!error)
123 13           file->size = (git_object_size_t)len;
124              
125 13           return error;
126             }
127              
128             #endif