Commit 114f5a6c by Russell Belfer

Reorganize diff and add basic diff driver

This is a significant reorganization of the diff code to break it
into a set of more clearly distinct files and to document the new
organization.  Hopefully this will make the diff code easier to
understand and to extend.

This adds a new `git_diff_driver` object that looks of diff driver
information from the attributes and the config so that things like
function content in diff headers can be provided.  The full driver
spec is not implemented in the commit - this is focused on the
reorganization of the code and putting the driver hooks in place.

This also removes a few #includes from src/repository.h that were
overbroad, but as a result required extra #includes in a variety
of places since including src/repository.h no longer results in
pulling in the whole world.
parent 7000f3fa
Diff is broken into four phases:
1. Building a list of things that have changed. These changes are called
deltas (git_diff_delta objects) and are grouped into a git_diff_list.
2. Applying file similarity measurement for rename and copy detection (and
to potentially split files that have changed radically). This step is
optional.
3. Computing the textual diff for each delta. Not all deltas have a
meaningful textual diff. For those that do, the textual diff can
either be generated on the fly and passed to output callbacks or can be
turned into a git_diff_patch object.
4. Formatting the diff and/or patch into standard text formats (such as
patches, raw lists, etc).
In the source code, step 1 is implemented in `src/diff.c`, step 2 in
`src/diff_tform.c`, step 3 in `src/diff_patch.c`, and step 4 in
`src/diff_print.c`. Additionally, when it comes to accessing file
content, everything goes through diff drivers that are implemented in
`src/diff_driver.c`.
External Objects
----------------
* `git_diff_options` repesents user choices about how a diff should be
performed and is passed to most diff generating functions.
* `git_diff_file` represents an item on one side of a possible delta
* `git_diff_delta` represents a pair of items that have changed in some
way - it contains two `git_diff_file` plus a status and other stuff.
* `git_diff_list` is a list of deltas along with information about how
those particular deltas were found.
* `git_diff_patch` represents the actual diff between a pair of items. In
some cases, a delta may not have a corresponding patch, if the objects
are binary, for example. The content of a patch will be a set of hunks
and lines.
* A `hunk` is range of lines described by a `git_diff_range` (i.e. "lines
10-20 in the old file became lines 12-23 in the new"). It will have a
header that compactly represents that information, and it will have a
number of lines of context surrounding added and deleted lines.
* A `line` is simple a line of data along with a `git_diff_line_t` value
that tells how the data should be interpretted (e.g. context or added).
Internal Objects
----------------
* `git_diff_file_content` is an internal structure that represents the
data on one side of an item to be diffed; it is an augmented
`git_diff_file` with more flags and the actual file data.
** it is created from a repository plus a) a git_diff_file, b) a git_blob,
or c) raw data and size
** there are three main operations on git_diff_file_content:
*** _initialization_ sets up the data structure and does what it can up to,
but not including loading and looking at the actual data
*** _loading_ loads the data, preprocesses it (i.e. applies filters) and
potentially analyzes it (to decide if binary)
*** _free_ releases loaded data and frees any allocated memory
* The internal structure of a `git_diff_patch` stores the actual diff
between a pair of `git_diff_file_content` items
** it may be "unset" if the items are not diffable
** "empty" if the items are the same
** otherwise it will consist of a set of hunks each of which covers some
number of lines of context, additions and deletions
** a patch is created from two git_diff_file_content items
** a patch is fully instantiated in three phases:
*** initial creation and initialization
*** loading of data and preliminary data examination
*** diffing of data and optional storage of diffs
** (TBD) if a patch is asked to store the diffs and the size of the diff
is significantly smaller than the raw data of the two sides, then the
patch may be flattened using a pool of string data
* `git_diff_output` is an internal structure that represents an output
target for a `git_diff_patch`
** It consists of file, hunk, and line callbacks, plus a payload
** There is a standard flattened output that can be used for plain text output
** Typically we use a `git_xdiff_output` which drives the callbacks via the
xdiff code taken from core Git.
* `git_diff_driver` is an internal structure that encapsulates the logic
for a given type of file
** a driver is looked up based on the name and mode of a file.
** the driver can then be used to:
*** determine if a file is binary (by attributes, by git_diff_options
settings, or by examining the content)
*** give you a function pointer that is used to evaluate function context
for hunk headers
** At some point, the logic for getting a filtered version of file content
or calculating the OID of a file may be moved into the driver.
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "git2/odb_backend.h" #include "git2/odb_backend.h"
#include "common.h" #include "common.h"
#include "filebuf.h"
#include "blob.h" #include "blob.h"
#include "filter.h" #include "filter.h"
#include "buf_text.h" #include "buf_text.h"
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "refs.h" #include "refs.h"
#include "repository.h" #include "repository.h"
#include "index.h"
#include "filter.h" #include "filter.h"
#include "blob.h" #include "blob.h"
#include "diff.h" #include "diff.h"
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "fileops.h" #include "fileops.h"
#include "refs.h" #include "refs.h"
#include "path.h" #include "path.h"
#include "repository.h"
static int create_branch( static int create_branch(
git_reference **branch, git_reference **branch,
......
...@@ -5,14 +5,16 @@ ...@@ -5,14 +5,16 @@
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#include "git2/attr.h"
#include "git2/blob.h"
#include "git2/index.h"
#include "common.h" #include "common.h"
#include "fileops.h" #include "fileops.h"
#include "hash.h" #include "hash.h"
#include "filter.h" #include "filter.h"
#include "buf_text.h" #include "buf_text.h"
#include "repository.h" #include "repository.h"
#include "git2/attr.h"
#include "git2/blob.h"
struct crlf_attrs { struct crlf_attrs {
int crlf_action; int crlf_action;
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "attr_file.h" #include "attr_file.h"
#include "filter.h" #include "filter.h"
#include "pathspec.h" #include "pathspec.h"
#include "index.h"
#include "odb.h"
#define DIFF_FLAG_IS_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) != 0) #define DIFF_FLAG_IS_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) != 0)
#define DIFF_FLAG_ISNT_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) == 0) #define DIFF_FLAG_ISNT_SET(DIFF,FLAG) (((DIFF)->opts.flags & (FLAG)) == 0)
...@@ -1170,3 +1172,73 @@ int git_diff_tree_to_workdir( ...@@ -1170,3 +1172,73 @@ int git_diff_tree_to_workdir(
return error; return error;
} }
size_t git_diff_num_deltas(git_diff_list *diff)
{
assert(diff);
return (size_t)diff->deltas.length;
}
size_t git_diff_num_deltas_of_type(git_diff_list *diff, git_delta_t type)
{
size_t i, count = 0;
git_diff_delta *delta;
assert(diff);
git_vector_foreach(&diff->deltas, i, delta) {
count += (delta->status == type);
}
return count;
}
int git_diff__paired_foreach(
git_diff_list *idx2head,
git_diff_list *wd2idx,
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
void *payload)
{
int cmp;
git_diff_delta *i2h, *w2i;
size_t i, j, i_max, j_max;
int (*strcomp)(const char *, const char *);
i_max = idx2head ? idx2head->deltas.length : 0;
j_max = wd2idx ? wd2idx->deltas.length : 0;
/* Get appropriate strcmp function */
strcomp = idx2head ? idx2head->strcomp : wd2idx ? wd2idx->strcomp : NULL;
/* Assert both iterators use matching ignore-case. If this function ever
* supports merging diffs that are not sorted by the same function, then
* it will need to spool and sort on one of the results before merging
*/
if (idx2head && wd2idx) {
assert(idx2head->strcomp == wd2idx->strcomp);
}
for (i = 0, j = 0; i < i_max || j < j_max; ) {
i2h = idx2head ? GIT_VECTOR_GET(&idx2head->deltas,i) : NULL;
w2i = wd2idx ? GIT_VECTOR_GET(&wd2idx->deltas,j) : NULL;
cmp = !w2i ? -1 : !i2h ? 1 :
strcomp(i2h->old_file.path, w2i->old_file.path);
if (cmp < 0) {
if (cb(i2h, NULL, payload))
return GIT_EUSER;
i++;
} else if (cmp > 0) {
if (cb(NULL, w2i, payload))
return GIT_EUSER;
j++;
} else {
if (cb(i2h, w2i, payload))
return GIT_EUSER;
i++; j++;
}
}
return 0;
}
...@@ -29,11 +29,16 @@ enum { ...@@ -29,11 +29,16 @@ enum {
GIT_DIFFCAPS_TRUST_NANOSECS = (1 << 5), /* use stat time nanoseconds */ GIT_DIFFCAPS_TRUST_NANOSECS = (1 << 5), /* use stat time nanoseconds */
}; };
#define DIFF_FLAGS_KNOWN_BINARY (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)
#define DIFF_FLAGS_NOT_BINARY (GIT_DIFF_FLAG_NOT_BINARY|GIT_DIFF_FLAG__NO_DATA)
enum { enum {
GIT_DIFF_FLAG__FREE_PATH = (1 << 7), /* `path` is allocated memory */ GIT_DIFF_FLAG__FREE_PATH = (1 << 7), /* `path` is allocated memory */
GIT_DIFF_FLAG__FREE_DATA = (1 << 8), /* internal file data is allocated */ GIT_DIFF_FLAG__FREE_DATA = (1 << 8), /* internal file data is allocated */
GIT_DIFF_FLAG__UNMAP_DATA = (1 << 9), /* internal file data is mmap'ed */ GIT_DIFF_FLAG__UNMAP_DATA = (1 << 9), /* internal file data is mmap'ed */
GIT_DIFF_FLAG__NO_DATA = (1 << 10), /* file data should not be loaded */ GIT_DIFF_FLAG__NO_DATA = (1 << 10), /* file data should not be loaded */
GIT_DIFF_FLAG__FREE_BLOB = (1 << 11), /* release the blob when done */
GIT_DIFF_FLAG__LOADED = (1 << 12), /* file data has been loaded */
GIT_DIFF_FLAG__TO_DELETE = (1 << 16), /* delete entry during rename det. */ GIT_DIFF_FLAG__TO_DELETE = (1 << 16), /* delete entry during rename det. */
GIT_DIFF_FLAG__TO_SPLIT = (1 << 17), /* split entry during rename det. */ GIT_DIFF_FLAG__TO_SPLIT = (1 << 17), /* split entry during rename det. */
...@@ -83,6 +88,12 @@ extern int git_diff__from_iterators( ...@@ -83,6 +88,12 @@ extern int git_diff__from_iterators(
git_iterator *new_iter, git_iterator *new_iter,
const git_diff_options *opts); const git_diff_options *opts);
extern int git_diff__paired_foreach(
git_diff_list *idx2head,
git_diff_list *wd2idx,
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
void *payload);
int git_diff_find_similar__hashsig_for_file( int git_diff_find_similar__hashsig_for_file(
void **out, const git_diff_file *f, const char *path, void *p); void **out, const git_diff_file *f, const char *path, void *p);
......
/*
* 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.
*/
#include "common.h"
#include "git2/attr.h"
#include "diff.h"
#include "diff_patch.h"
#include "diff_driver.h"
#include "strmap.h"
#include "pool.h"
#include "map.h"
#include "buf_text.h"
typedef enum {
DIFF_DRIVER_AUTO = 0,
DIFF_DRIVER_FALSE = 1,
DIFF_DRIVER_TRUE = 2,
DIFF_DRIVER_NAMED = 3,
} git_diff_driver_t;
enum {
DIFF_CONTEXT_FIND_NORMAL = 0,
DIFF_CONTEXT_FIND_ICASE = (1 << 0),
DIFF_CONTEXT_FIND_EXT = (1 << 1),
};
/* data for finding function context for a given file type */
struct git_diff_driver {
git_diff_driver_t type;
git_strarray fn_patterns;
int binary;
};
struct git_diff_driver_registry {
git_strmap *drivers;
git_pool strings;
};
static git_diff_driver global_drivers[3] = {
{ DIFF_DRIVER_AUTO, { NULL, 0 }, -1 },
{ DIFF_DRIVER_FALSE, { NULL, 0 }, 1 },
{ DIFF_DRIVER_TRUE, { NULL, 0 }, 0 },
};
git_diff_driver_registry *git_diff_driver_registry_new()
{
return git__calloc(1, sizeof(git_diff_driver_registry));
}
void git_diff_driver_registry_free(git_diff_driver_registry *reg)
{
git__free(reg);
}
int git_diff_driver_lookup(
git_diff_driver **out, git_repository *repo, const char *path)
{
const char *value;
assert(out);
if (!repo || !path || !strlen(path))
goto use_auto;
if (git_attr_get(&value, repo, 0, path, "diff") < 0)
return -1;
if (GIT_ATTR_FALSE(value)) {
*out = &global_drivers[DIFF_DRIVER_FALSE];
return 0;
}
else if (GIT_ATTR_TRUE(value)) {
*out = &global_drivers[DIFF_DRIVER_TRUE];
return 0;
}
/* otherwise look for driver information in config and build driver */
use_auto:
*out = &global_drivers[DIFF_DRIVER_AUTO];
return 0;
}
void git_diff_driver_free(git_diff_driver *driver)
{
GIT_UNUSED(driver);
/* do nothing for now */
}
int git_diff_driver_is_binary(git_diff_driver *driver)
{
return driver ? driver->binary : -1;
}
int git_diff_driver_content_is_binary(
git_diff_driver *driver, const char *content, size_t content_len)
{
const git_buf search = { (char *)content, 0, min(content_len, 4000) };
GIT_UNUSED(driver);
/* TODO: provide encoding / binary detection callbacks that can
* be UTF-8 aware, etc. For now, instead of trying to be smart,
* let's just use the simple NUL-byte detection that core git uses.
*/
/* previously was: if (git_buf_text_is_binary(&search)) */
if (git_buf_text_contains_nul(&search))
return 1;
return 0;
}
static long diff_context_find(
const char *line,
long line_len,
char *out,
long out_size,
void *payload)
{
git_diff_driver *driver = payload;
const char *scan;
GIT_UNUSED(driver);
if (line_len > 0 && line[line_len - 1] == '\n')
line_len--;
if (line_len > 0 && line[line_len - 1] == '\r')
line_len--;
if (!line_len)
return -1;
if (!git__isalpha(*line) && *line != '_' && *line != '$')
return -1;
for (scan = &line[line_len-1]; scan > line && git__isspace(*scan); --scan)
/* search backward for non-space */;
line_len = scan - line;
if (line_len >= out_size)
line_len = out_size - 1;
memcpy(out, line, line_len);
out[line_len] = '\0';
return line_len;
}
git_diff_find_context_fn git_diff_driver_find_content_fn(git_diff_driver *driver)
{
GIT_UNUSED(driver);
return diff_context_find;
}
/*
* 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_diff_driver_h__
#define INCLUDE_diff_driver_h__
#include "common.h"
typedef struct git_diff_driver_registry git_diff_driver_registry;
git_diff_driver_registry *git_diff_driver_registry_new();
void git_diff_driver_registry_free(git_diff_driver_registry *);
typedef struct git_diff_driver git_diff_driver;
int git_diff_driver_lookup(git_diff_driver **, git_repository *, const char *);
void git_diff_driver_free(git_diff_driver *);
/* returns -1 meaning "unknown", 0 meaning not binary, 1 meaning binary */
int git_diff_driver_is_binary(git_diff_driver *);
/* returns -1 meaning "unknown", 0 meaning not binary, 1 meaning binary */
int git_diff_driver_content_is_binary(
git_diff_driver *, const char *content, size_t content_len);
typedef long (*git_diff_find_context_fn)(
const char *, long, char *, long, void *);
git_diff_find_context_fn git_diff_driver_find_content_fn(git_diff_driver *);
#endif
This diff is collapsed. Click to expand it.
/*
* 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_diff_file_h__
#define INCLUDE_diff_file_h__
#include "common.h"
#include "diff.h"
#include "diff_driver.h"
#include "map.h"
/* expanded information for one side of a delta */
typedef struct {
git_repository *repo;
const git_diff_options *opts;
git_diff_file file;
git_diff_driver *driver;
git_iterator_type_t src;
const git_blob *blob;
git_map map;
} git_diff_file_content;
extern int diff_file_content_init_from_diff(
git_diff_file_content *fc,
git_diff_list *diff,
size_t delta_index,
bool use_old);
extern int diff_file_content_init_from_blob(
git_diff_file_content *fc,
git_repository *repo,
const git_diff_options *opts,
const git_blob *blob);
extern int diff_file_content_init_from_raw(
git_diff_file_content *fc,
git_repository *repo,
const git_diff_options *opts,
const char *buf,
size_t buflen);
/* this loads the blob/file-on-disk as needed */
extern int diff_file_content_load(git_diff_file_content *fc);
/* this releases the blob/file-in-memory */
extern void diff_file_content_unload(git_diff_file_content *fc);
/* this unloads and also releases any other resources */
extern void diff_file_content_clear(git_diff_file_content *fc);
#endif
/*
* 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_diff_output_h__
#define INCLUDE_diff_output_h__
#include "git2/blob.h"
#include "diff.h"
#include "map.h"
#include "xdiff/xdiff.h"
#define MAX_DIFF_FILESIZE 0x20000000
enum {
GIT_DIFF_PATCH_ALLOCATED = (1 << 0),
GIT_DIFF_PATCH_PREPPED = (1 << 1),
GIT_DIFF_PATCH_LOADED = (1 << 2),
GIT_DIFF_PATCH_DIFFABLE = (1 << 3),
GIT_DIFF_PATCH_DIFFED = (1 << 4),
};
/* context for performing diffs */
typedef struct {
git_repository *repo;
git_diff_list *diff;
const git_diff_options *opts;
git_diff_file_cb file_cb;
git_diff_hunk_cb hunk_cb;
git_diff_data_cb data_cb;
void *payload;
int error;
git_diff_range range;
xdemitconf_t xdiff_config;
xpparam_t xdiff_params;
} diff_context;
/* cached information about a single span in a diff */
typedef struct diff_patch_line diff_patch_line;
struct diff_patch_line {
const char *ptr;
size_t len;
size_t lines, oldno, newno;
char origin;
};
/* cached information about a hunk in a diff */
typedef struct diff_patch_hunk diff_patch_hunk;
struct diff_patch_hunk {
git_diff_range range;
char header[128];
size_t header_len;
size_t line_start;
size_t line_count;
};
struct git_diff_patch {
git_refcount rc;
git_diff_list *diff; /* for refcount purposes, maybe NULL for blob diffs */
git_diff_delta *delta;
diff_context *ctxt; /* only valid while generating patch */
git_iterator_type_t old_src;
git_iterator_type_t new_src;
git_blob *old_blob;
git_blob *new_blob;
git_map old_data;
git_map new_data;
uint32_t flags;
diff_patch_hunk *hunks;
size_t hunks_asize, hunks_size;
diff_patch_line *lines;
size_t lines_asize, lines_size;
size_t oldno, newno;
};
/* context for performing diff on a single delta */
typedef struct {
git_diff_patch *patch;
uint32_t prepped : 1;
uint32_t loaded : 1;
uint32_t diffable : 1;
uint32_t diffed : 1;
} diff_delta_context;
extern int git_diff__paired_foreach(
git_diff_list *idx2head,
git_diff_list *wd2idx,
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
void *payload);
#endif
/*
* 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_diff_patch_h__
#define INCLUDE_diff_patch_h__
#include "common.h"
#include "diff.h"
#include "diff_file.h"
#include "array.h"
/* cached information about a single span in a diff */
typedef struct diff_patch_line diff_patch_line;
struct diff_patch_line {
const char *ptr;
size_t len;
size_t lines, oldno, newno;
char origin;
};
/* cached information about a hunk in a diff */
typedef struct diff_patch_hunk diff_patch_hunk;
struct diff_patch_hunk {
git_diff_range range;
char header[128];
size_t header_len;
size_t line_start;
size_t line_count;
};
struct git_diff_patch {
git_refcount rc;
git_diff_list *diff; /* for refcount purposes, maybe NULL for blob diffs */
git_diff_delta *delta;
size_t delta_index;
git_diff_file_content ofile;
git_diff_file_content nfile;
uint32_t flags;
git_array_t(diff_patch_hunk) hunks;
git_array_t(diff_patch_line) lines;
size_t oldno, newno;
size_t content_size;
git_pool flattened;
};
enum {
GIT_DIFF_PATCH_ALLOCATED = (1 << 0),
GIT_DIFF_PATCH_INITIALIZED = (1 << 1),
GIT_DIFF_PATCH_LOADED = (1 << 2),
GIT_DIFF_PATCH_DIFFABLE = (1 << 3),
GIT_DIFF_PATCH_DIFFED = (1 << 4),
GIT_DIFF_PATCH_FLATTENED = (1 << 5),
};
typedef struct git_diff_output git_diff_output;
struct git_diff_output {
/* these callbacks are issued with the diff data */
git_diff_file_cb file_cb;
git_diff_hunk_cb hunk_cb;
git_diff_data_cb data_cb;
void *payload;
/* this records the actual error in cases where it may be obscured */
int error;
/* this callback is used to do the diff and drive the other callbacks.
* see diff_xdiff.h for how to use this in practice for now.
*/
int (*diff_cb)(git_diff_output *output, git_diff_patch *patch);
};
#endif
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
*/ */
#include "common.h" #include "common.h"
#include "diff.h" #include "diff.h"
#include "diff_output.h" #include "diff_patch.h"
#include "buffer.h"
typedef struct { typedef struct {
git_diff_list *diff; git_diff_list *diff;
...@@ -390,14 +391,15 @@ int git_diff_patch_print( ...@@ -390,14 +391,15 @@ int git_diff_patch_print(
&pi, &temp, patch->diff, print_cb, payload))) &pi, &temp, patch->diff, print_cb, payload)))
error = print_patch_file(patch->delta, 0, &pi); error = print_patch_file(patch->delta, 0, &pi);
for (h = 0; h < patch->hunks_size && !error; ++h) { for (h = 0; h < git_array_size(patch->hunks) && !error; ++h) {
diff_patch_hunk *hunk = &patch->hunks[h]; diff_patch_hunk *hunk = git_array_get(patch->hunks, h);
error = print_patch_hunk( error = print_patch_hunk(
patch->delta, &hunk->range, hunk->header, hunk->header_len, &pi); patch->delta, &hunk->range, hunk->header, hunk->header_len, &pi);
for (l = 0; l < hunk->line_count && !error; ++l) { for (l = 0; l < hunk->line_count && !error; ++l) {
diff_patch_line *line = &patch->lines[hunk->line_start + l]; diff_patch_line *line =
git_array_get(patch->lines, hunk->line_start + l);
error = print_patch_line( error = print_patch_line(
patch->delta, &hunk->range, patch->delta, &hunk->range,
......
...@@ -5,10 +5,14 @@ ...@@ -5,10 +5,14 @@
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#include "common.h" #include "common.h"
#include "diff.h"
#include "git2/config.h" #include "git2/config.h"
#include "git2/blob.h" #include "git2/blob.h"
#include "diff.h"
#include "hashsig.h" #include "hashsig.h"
#include "path.h"
#include "fileops.h"
static git_diff_delta *diff_delta__dup( static git_diff_delta *diff_delta__dup(
const git_diff_delta *d, git_pool *pool) const git_diff_delta *d, git_pool *pool)
......
/*
* 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.
*/
#include "common.h"
#include "diff.h"
#include "diff_driver.h"
#include "diff_patch.h"
#include "diff_xdiff.h"
static int git_xdiff_scan_int(const char **str, int *value)
{
const char *scan = *str;
int v = 0, digits = 0;
/* find next digit */
for (scan = *str; *scan && !git__isdigit(*scan); scan++);
/* parse next number */
for (; git__isdigit(*scan); scan++, digits++)
v = (v * 10) + (*scan - '0');
*str = scan;
*value = v;
return (digits > 0) ? 0 : -1;
}
static int git_xdiff_parse_hunk(git_diff_range *range, const char *header)
{
/* expect something of the form "@@ -%d[,%d] +%d[,%d] @@" */
if (*header != '@')
return -1;
if (git_xdiff_scan_int(&header, &range->old_start) < 0)
return -1;
if (*header == ',') {
if (git_xdiff_scan_int(&header, &range->old_lines) < 0)
return -1;
} else
range->old_lines = 1;
if (git_xdiff_scan_int(&header, &range->new_start) < 0)
return -1;
if (*header == ',') {
if (git_xdiff_scan_int(&header, &range->new_lines) < 0)
return -1;
} else
range->new_lines = 1;
if (range->old_start < 0 || range->new_start < 0)
return -1;
return 0;
}
typedef struct {
git_xdiff_output *xo;
git_diff_patch *patch;
git_diff_range range;
} git_xdiff_info;
static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
{
git_xdiff_info *info = priv;
git_diff_patch *patch = info->patch;
git_diff_output *output = &info->xo->output;
if (len == 1) {
output->error = git_xdiff_parse_hunk(&info->range, bufs[0].ptr);
if (output->error < 0)
return output->error;
if (output->hunk_cb != NULL &&
output->hunk_cb(patch->delta, &info->range,
bufs[0].ptr, bufs[0].size, output->payload))
output->error = GIT_EUSER;
}
if (len == 2 || len == 3) {
/* expect " "/"-"/"+", then data */
char origin =
(*bufs[0].ptr == '+') ? GIT_DIFF_LINE_ADDITION :
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_DELETION :
GIT_DIFF_LINE_CONTEXT;
if (output->data_cb != NULL &&
output->data_cb(patch->delta, &info->range,
origin, bufs[1].ptr, bufs[1].size, output->payload))
output->error = GIT_EUSER;
}
if (len == 3 && !output->error) {
/* If we have a '+' and a third buf, then we have added a line
* without a newline and the old code had one, so DEL_EOFNL.
* If we have a '-' and a third buf, then we have removed a line
* with out a newline but added a blank line, so ADD_EOFNL.
*/
char origin =
(*bufs[0].ptr == '+') ? GIT_DIFF_LINE_DEL_EOFNL :
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_ADD_EOFNL :
GIT_DIFF_LINE_CONTEXT_EOFNL;
if (output->data_cb != NULL &&
output->data_cb(patch->delta, &info->range,
origin, bufs[2].ptr, bufs[2].size, output->payload))
output->error = GIT_EUSER;
}
return output->error;
}
static int git_xdiff(git_diff_output *output, git_diff_patch *patch)
{
git_xdiff_output *xo = (git_xdiff_output *)output;
git_xdiff_info info;
mmfile_t old_xdiff_data, new_xdiff_data;
memset(&info, 0, sizeof(info));
info.patch = patch;
info.xo = xo;
xo->callback.priv = &info;
xo->config.find_func_priv = patch->ofile.driver;
xo->config.find_func = patch->ofile.driver ?
git_diff_driver_find_content_fn(patch->ofile.driver) : NULL;
if (xo->config.find_func != NULL)
xo->config.flags |= XDL_EMIT_FUNCNAMES;
else
xo->config.flags &= ~XDL_EMIT_FUNCNAMES;
old_xdiff_data.ptr = patch->ofile.map.data;
old_xdiff_data.size = patch->ofile.map.len;
new_xdiff_data.ptr = patch->nfile.map.data;
new_xdiff_data.size = patch->nfile.map.len;
xdl_diff(&old_xdiff_data, &new_xdiff_data,
&xo->params, &xo->config, &xo->callback);
return xo->output.error;
}
void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts)
{
uint32_t flags = opts ? opts->flags : GIT_DIFF_NORMAL;
xo->output.diff_cb = git_xdiff;
memset(&xo->config, 0, sizeof(xo->config));
xo->config.ctxlen = opts ? opts->context_lines : 3;
xo->config.interhunkctxlen = opts ? opts->interhunk_lines : 0;
memset(&xo->params, 0, sizeof(xo->params));
if (flags & GIT_DIFF_IGNORE_WHITESPACE)
xo->params.flags |= XDF_WHITESPACE_FLAGS;
if (flags & GIT_DIFF_IGNORE_WHITESPACE_CHANGE)
xo->params.flags |= XDF_IGNORE_WHITESPACE_CHANGE;
if (flags & GIT_DIFF_IGNORE_WHITESPACE_EOL)
xo->params.flags |= XDF_IGNORE_WHITESPACE_AT_EOL;
memset(&xo->callback, 0, sizeof(xo->callback));
xo->callback.outf = git_xdiff_cb;
}
/*
* 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_diff_xdiff_h__
#define INCLUDE_diff_xdiff_h__
#include "diff.h"
#include "diff_patch.h"
#include "xdiff/xdiff.h"
/* A git_xdiff_output is a git_diff_output with extra fields necessary
* to use libxdiff. Calling git_xdiff_init() will set the diff_cb field
* of the output to use xdiff to generate the diffs.
*/
typedef struct {
git_diff_output output;
xdemitconf_t config;
xpparam_t params;
xdemitcb_t callback;
} git_xdiff_output;
void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts);
#endif
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "pack.h" #include "pack.h"
#include "fetch.h" #include "fetch.h"
#include "netops.h" #include "netops.h"
#include "repository.h"
#include "refs.h"
struct filter_payload { struct filter_payload {
git_remote *remote; git_remote *remote;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "iterator.h" #include "iterator.h"
#include "tree.h" #include "tree.h"
#include "index.h"
#include "ignore.h" #include "ignore.h"
#include "buffer.h" #include "buffer.h"
#include "git2/submodule.h" #include "git2/submodule.h"
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "blob.h" #include "blob.h"
#include "hashsig.h" #include "hashsig.h"
#include "oid.h" #include "oid.h"
#include "index.h"
#include "filebuf.h"
#include "git2/types.h" #include "git2/types.h"
#include "git2/repository.h" #include "git2/repository.h"
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "hash.h" #include "hash.h"
#include "repository.h" #include "repository.h"
#include "fileops.h" #include "fileops.h"
#include "filebuf.h"
#include "pack.h" #include "pack.h"
#include "reflog.h" #include "reflog.h"
#include "refdb.h" #include "refdb.h"
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "hash.h" #include "hash.h"
#include "repository.h" #include "repository.h"
#include "fileops.h" #include "fileops.h"
#include "filebuf.h"
#include "pack.h" #include "pack.h"
#include "reflog.h" #include "reflog.h"
#include "refdb.h" #include "refdb.h"
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "git2/transport.h" #include "git2/transport.h"
#include "refspec.h" #include "refspec.h"
#include "repository.h" #include "vector.h"
#define GIT_REMOTE_ORIGIN "origin" #define GIT_REMOTE_ORIGIN "origin"
......
...@@ -17,12 +17,15 @@ ...@@ -17,12 +17,15 @@
#include "tag.h" #include "tag.h"
#include "blob.h" #include "blob.h"
#include "fileops.h" #include "fileops.h"
#include "filebuf.h"
#include "index.h"
#include "config.h" #include "config.h"
#include "refs.h" #include "refs.h"
#include "filter.h" #include "filter.h"
#include "odb.h" #include "odb.h"
#include "remote.h" #include "remote.h"
#include "merge.h" #include "merge.h"
#include "diff_driver.h"
#define GIT_FILE_CONTENT_PREFIX "gitdir:" #define GIT_FILE_CONTENT_PREFIX "gitdir:"
...@@ -108,6 +111,7 @@ void git_repository_free(git_repository *repo) ...@@ -108,6 +111,7 @@ void git_repository_free(git_repository *repo)
git_cache_free(&repo->objects); git_cache_free(&repo->objects);
git_submodule_config_free(repo); git_submodule_config_free(repo);
git_diff_driver_registry_free(repo->diff_drivers);
git__free(repo->path_repository); git__free(repo->path_repository);
git__free(repo->workdir); git__free(repo->workdir);
......
...@@ -14,15 +14,13 @@ ...@@ -14,15 +14,13 @@
#include "git2/object.h" #include "git2/object.h"
#include "git2/config.h" #include "git2/config.h"
#include "index.h"
#include "cache.h" #include "cache.h"
#include "refs.h" #include "refs.h"
#include "buffer.h" #include "buffer.h"
#include "odb.h"
#include "object.h" #include "object.h"
#include "attrcache.h" #include "attrcache.h"
#include "strmap.h" #include "strmap.h"
#include "refdb.h" #include "diff_driver.h"
#define DOT_GIT ".git" #define DOT_GIT ".git"
#define GIT_DIR DOT_GIT "/" #define GIT_DIR DOT_GIT "/"
...@@ -108,6 +106,7 @@ struct git_repository { ...@@ -108,6 +106,7 @@ struct git_repository {
git_cache objects; git_cache objects;
git_attr_cache attrcache; git_attr_cache attrcache;
git_strmap *submodules; git_strmap *submodules;
git_diff_driver_registry *diff_drivers;
char *path_repository; char *path_repository;
char *workdir; char *workdir;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "signature.h" #include "signature.h"
#include "repository.h" #include "repository.h"
#include "git2/common.h" #include "git2/common.h"
#include "posix.h"
void git_signature_free(git_signature *sig) void git_signature_free(git_signature *sig)
{ {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "git2/stash.h" #include "git2/stash.h"
#include "git2/status.h" #include "git2/status.h"
#include "git2/checkout.h" #include "git2/checkout.h"
#include "git2/index.h"
#include "signature.h" #include "signature.h"
static int create_error(int error, const char *msg) static int create_error(int error, const char *msg)
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
#include "git2/status.h" #include "git2/status.h"
#include "repository.h" #include "repository.h"
#include "ignore.h" #include "ignore.h"
#include "index.h"
#include "git2/diff.h" #include "git2/diff.h"
#include "diff.h" #include "diff.h"
#include "diff_output.h"
static unsigned int index_delta2status(git_delta_t index_status) static unsigned int index_delta2status(git_delta_t index_status)
{ {
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include "submodule.h" #include "submodule.h"
#include "tree.h" #include "tree.h"
#include "iterator.h" #include "iterator.h"
#include "path.h"
#include "index.h"
#define GIT_MODULES_FILE ".gitmodules" #define GIT_MODULES_FILE ".gitmodules"
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#ifndef INCLUDE_thread_utils_h__ #ifndef INCLUDE_thread_utils_h__
#define INCLUDE_thread_utils_h__ #define INCLUDE_thread_utils_h__
#include "common.h"
/* Common operations even if threading has been disabled */ /* Common operations even if threading has been disabled */
typedef struct { typedef struct {
#if defined(GIT_WIN32) #if defined(GIT_WIN32)
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include "tree.h" #include "tree.h"
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/object.h" #include "git2/object.h"
#include "path.h"
#include "tree-cache.h"
#include "index.h"
#define DEFAULT_TREE_SIZE 16 #define DEFAULT_TREE_SIZE 16
#define MAX_FILEMODE_BYTES 6 #define MAX_FILEMODE_BYTES 6
......
...@@ -194,6 +194,8 @@ extern int git__strcasecmp(const char *a, const char *b); ...@@ -194,6 +194,8 @@ extern int git__strcasecmp(const char *a, const char *b);
extern int git__strncmp(const char *a, const char *b, size_t sz); extern int git__strncmp(const char *a, const char *b, size_t sz);
extern int git__strncasecmp(const char *a, const char *b, size_t sz); extern int git__strncasecmp(const char *a, const char *b, size_t sz);
#include "thread-utils.h"
typedef struct { typedef struct {
git_atomic refcount; git_atomic refcount;
void *owner; void *owner;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "checkout_helpers.h" #include "checkout_helpers.h"
#include "git2/checkout.h" #include "git2/checkout.h"
#include "fileops.h"
#include "repository.h" #include "repository.h"
static git_repository *g_repo; static git_repository *g_repo;
......
...@@ -183,10 +183,10 @@ clar_run_test( ...@@ -183,10 +183,10 @@ clar_run_test(
} }
static void static void
clar_run_suite(const struct clar_suite *suite) clar_run_suite(const struct clar_suite *suite, const char *name)
{ {
const struct clar_func *test = suite->tests; const struct clar_func *test = suite->tests;
size_t i; size_t i, namelen;
if (!suite->enabled) if (!suite->enabled)
return; return;
...@@ -200,7 +200,23 @@ clar_run_suite(const struct clar_suite *suite) ...@@ -200,7 +200,23 @@ clar_run_suite(const struct clar_suite *suite)
_clar.active_suite = suite->name; _clar.active_suite = suite->name;
_clar.suite_errors = 0; _clar.suite_errors = 0;
if (name) {
size_t suitelen = strlen(suite->name);
namelen = strlen(name);
if (namelen <= suitelen) {
name = NULL;
} else {
name += suitelen;
while (*name == ':')
++name;
namelen = strlen(name);
}
}
for (i = 0; i < suite->test_count; ++i) { for (i = 0; i < suite->test_count; ++i) {
if (name && strncmp(test[i].name, name, namelen))
continue;
_clar.active_test = test[i].name; _clar.active_test = test[i].name;
clar_run_test(&test[i], &suite->initialize, &suite->cleanup); clar_run_test(&test[i], &suite->initialize, &suite->cleanup);
...@@ -240,7 +256,7 @@ clar_parse_args(int argc, char **argv) ...@@ -240,7 +256,7 @@ clar_parse_args(int argc, char **argv)
case 'x': { /* given suite name */ case 'x': { /* given suite name */
int offset = (argument[2] == '=') ? 3 : 2, found = 0; int offset = (argument[2] == '=') ? 3 : 2, found = 0;
char action = argument[1]; char action = argument[1];
size_t j, len; size_t j, len, cmplen;
argument += offset; argument += offset;
len = strlen(argument); len = strlen(argument);
...@@ -249,7 +265,11 @@ clar_parse_args(int argc, char **argv) ...@@ -249,7 +265,11 @@ clar_parse_args(int argc, char **argv)
clar_usage(argv[0]); clar_usage(argv[0]);
for (j = 0; j < _clar_suite_count; ++j) { for (j = 0; j < _clar_suite_count; ++j) {
if (strncmp(argument, _clar_suites[j].name, len) == 0) { cmplen = strlen(_clar_suites[j].name);
if (cmplen > len)
cmplen = len;
if (strncmp(argument, _clar_suites[j].name, cmplen) == 0) {
int exact = !strcmp(argument, _clar_suites[j].name); int exact = !strcmp(argument, _clar_suites[j].name);
++found; ++found;
...@@ -258,9 +278,9 @@ clar_parse_args(int argc, char **argv) ...@@ -258,9 +278,9 @@ clar_parse_args(int argc, char **argv)
_clar.report_suite_names = 1; _clar.report_suite_names = 1;
switch (action) { switch (action) {
case 's': clar_run_suite(&_clar_suites[j]); break; case 's': clar_run_suite(&_clar_suites[j], argument); break;
case 'i': _clar_suites[j].enabled = 1; break; case 'i': _clar_suites[j].enabled = 1; break;
case 'x': _clar_suites[j].enabled = 0; break; case 'x': _clar_suites[j].enabled = 0; break;
} }
if (exact) if (exact)
...@@ -318,7 +338,7 @@ clar_test(int argc, char **argv) ...@@ -318,7 +338,7 @@ clar_test(int argc, char **argv)
if (!_clar.suites_ran) { if (!_clar.suites_ran) {
size_t i; size_t i;
for (i = 0; i < _clar_suite_count; ++i) for (i = 0; i < _clar_suite_count; ++i)
clar_run_suite(&_clar_suites[i]); clar_run_suite(&_clar_suites[i], NULL);
} }
clar_print_shutdown( clar_print_shutdown(
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "git2/clone.h" #include "git2/clone.h"
#include "repository.h"
#include "remote.h" #include "remote.h"
#include "fileops.h"
#include "repository.h"
#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository" #define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
......
...@@ -543,7 +543,7 @@ void test_diff_patch__line_counts_with_eofnl(void) ...@@ -543,7 +543,7 @@ void test_diff_patch__line_counts_with_eofnl(void)
"index 378a7d9..3d0154e 100644\n" "index 378a7d9..3d0154e 100644\n"
"--- a/songof7cities.txt\n" "--- a/songof7cities.txt\n"
"+++ b/songof7cities.txt\n" "+++ b/songof7cities.txt\n"
"@@ -42,7 +42,7 @@\n" "@@ -42,7 +42,7 @@ With peoples undefeated of the dark, enduring blood\n"
" \n" " \n"
" To the sound of trumpets shall their seed restore my Cities\n" " To the sound of trumpets shall their seed restore my Cities\n"
" Wealthy and well-weaponed, that once more may I behold\n" " Wealthy and well-weaponed, that once more may I behold\n"
......
...@@ -558,7 +558,7 @@ void test_diff_rename__patch(void) ...@@ -558,7 +558,7 @@ void test_diff_rename__patch(void)
git_diff_patch *patch; git_diff_patch *patch;
const git_diff_delta *delta; const git_diff_delta *delta;
char *text; char *text;
const char *expected = "diff --git a/sixserving.txt b/ikeepsix.txt\nindex ad0a8e5..36020db 100644\n--- a/sixserving.txt\n+++ b/ikeepsix.txt\n@@ -1,3 +1,6 @@\n+I Keep Six Honest Serving-Men\n+=============================\n+\n I KEEP six honest serving-men\n (They taught me all I knew);\n Their names are What and Why and When\n@@ -21,4 +24,4 @@\n One million Hows, two million Wheres,\n And seven million Whys!\n \n- -- Rudyard Kipling\n+ -- Rudyard Kipling\n"; const char *expected = "diff --git a/sixserving.txt b/ikeepsix.txt\nindex ad0a8e5..36020db 100644\n--- a/sixserving.txt\n+++ b/ikeepsix.txt\n@@ -1,3 +1,6 @@\n+I Keep Six Honest Serving-Men\n+=============================\n+\n I KEEP six honest serving-men\n (They taught me all I knew);\n Their names are What and Why and When\n@@ -21,4 +24,4 @@ She sends'em abroad on her own affairs\n One million Hows, two million Wheres,\n And seven million Whys!\n \n- -- Rudyard Kipling\n+ -- Rudyard Kipling\n";
old_tree = resolve_commit_oid_to_tree(g_repo, sha0); old_tree = resolve_commit_oid_to_tree(g_repo, sha0);
new_tree = resolve_commit_oid_to_tree(g_repo, sha1); new_tree = resolve_commit_oid_to_tree(g_repo, sha1);
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "repository.h" #include "repository.h"
#include "posix.h"
#include "../submodule/submodule_helpers.h" #include "../submodule/submodule_helpers.h"
static git_repository *g_repo = NULL; static git_repository *g_repo = NULL;
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "repository.h" #include "fileops.h"
#include "fetchhead.h" #include "fetchhead.h"
#include "fetchhead_data.h" #include "fetchhead_data.h"
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "buffer.h" #include "fileops.h"
#include "refs.h" #include "refs.h"
#include "tree.h" #include "tree.h"
#include "merge_helpers.h" #include "merge_helpers.h"
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "odb.h" #include "odb.h"
#include "repository.h" #include "filebuf.h"
static git_buf destpath, filepath; static git_buf destpath, filepath;
static const char *paths[] = { static const char *paths[] = {
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
#include "git2/clone.h" #include "git2/clone.h"
#include "git2/cred_helpers.h" #include "git2/cred_helpers.h"
#include "repository.h"
#include "remote.h" #include "remote.h"
#include "fileops.h"
#include "refs.h"
#define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository" #define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
#define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository" #define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "repository.h" #include "fileops.h"
#include "fetchhead.h" #include "fetchhead.h"
#include "../fetchhead/fetchhead_data.h" #include "../fetchhead/fetchhead_data.h"
#include "git2/clone.h" #include "git2/clone.h"
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "repository.h" #include "fileops.h"
#include "git2/reflog.h" #include "git2/reflog.h"
#include "git2/refdb.h"
#include "reflog.h" #include "reflog.h"
#include "ref_helpers.h" #include "ref_helpers.h"
...@@ -31,7 +32,7 @@ void test_refs_delete__packed_loose(void) ...@@ -31,7 +32,7 @@ void test_refs_delete__packed_loose(void)
git_buf temp_path = GIT_BUF_INIT; git_buf temp_path = GIT_BUF_INIT;
/* Ensure the loose reference exists on the file system */ /* Ensure the loose reference exists on the file system */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, packed_test_head_name)); cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
cl_assert(git_path_exists(temp_path.ptr)); cl_assert(git_path_exists(temp_path.ptr));
/* Lookup the reference */ /* Lookup the reference */
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "repository.h" #include "fileops.h"
#include "git2/reflog.h" #include "git2/reflog.h"
#include "git2/refdb.h"
#include "reflog.h" #include "reflog.h"
#include "refs.h"
#include "ref_helpers.h" #include "ref_helpers.h"
static const char *loose_tag_ref_name = "refs/tags/e90810b"; static const char *loose_tag_ref_name = "refs/tags/e90810b";
...@@ -33,7 +35,7 @@ void test_refs_pack__empty(void) ...@@ -33,7 +35,7 @@ void test_refs_pack__empty(void)
// create a packfile for an empty folder // create a packfile for an empty folder
git_buf temp_path = GIT_BUF_INIT; git_buf temp_path = GIT_BUF_INIT;
cl_git_pass(git_buf_join_n(&temp_path, '/', 3, g_repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir")); cl_git_pass(git_buf_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir"));
cl_git_pass(git_futils_mkdir_r(temp_path.ptr, NULL, GIT_REFS_DIR_MODE)); cl_git_pass(git_futils_mkdir_r(temp_path.ptr, NULL, GIT_REFS_DIR_MODE));
git_buf_free(&temp_path); git_buf_free(&temp_path);
...@@ -60,7 +62,7 @@ void test_refs_pack__loose(void) ...@@ -60,7 +62,7 @@ void test_refs_pack__loose(void)
packall(); packall();
/* Ensure the packed-refs file exists */ /* Ensure the packed-refs file exists */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, GIT_PACKEDREFS_FILE)); cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), GIT_PACKEDREFS_FILE));
cl_assert(git_path_exists(temp_path.ptr)); cl_assert(git_path_exists(temp_path.ptr));
/* Ensure the known ref can still be looked up but is now packed */ /* Ensure the known ref can still be looked up but is now packed */
...@@ -69,7 +71,7 @@ void test_refs_pack__loose(void) ...@@ -69,7 +71,7 @@ void test_refs_pack__loose(void)
cl_assert_equal_s(reference->name, loose_tag_ref_name); cl_assert_equal_s(reference->name, loose_tag_ref_name);
/* Ensure the known ref has been removed from the loose folder structure */ /* Ensure the known ref has been removed from the loose folder structure */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, loose_tag_ref_name)); cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), loose_tag_ref_name));
cl_assert(!git_path_exists(temp_path.ptr)); cl_assert(!git_path_exists(temp_path.ptr));
git_reference_free(reference); git_reference_free(reference);
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "repository.h" #include "fileops.h"
#include "git2/reflog.h" #include "git2/reflog.h"
#include "reflog.h" #include "reflog.h"
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "repository.h" #include "fileops.h"
#include "git2/reflog.h" #include "git2/reflog.h"
#include "reflog.h" #include "reflog.h"
#include "refs.h"
#include "ref_helpers.h" #include "ref_helpers.h"
static const char *loose_tag_ref_name = "refs/tags/e90810b"; static const char *loose_tag_ref_name = "refs/tags/e90810b";
...@@ -38,7 +39,7 @@ void test_refs_rename__loose(void) ...@@ -38,7 +39,7 @@ void test_refs_rename__loose(void)
const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu"; const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu";
/* Ensure the ref doesn't exist on the file system */ /* Ensure the ref doesn't exist on the file system */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, new_name)); cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), new_name));
cl_assert(!git_path_exists(temp_path.ptr)); cl_assert(!git_path_exists(temp_path.ptr));
/* Retrieval of the reference to rename */ /* Retrieval of the reference to rename */
...@@ -64,7 +65,7 @@ void test_refs_rename__loose(void) ...@@ -64,7 +65,7 @@ void test_refs_rename__loose(void)
cl_assert(reference_is_packed(new_ref) == 0); cl_assert(reference_is_packed(new_ref) == 0);
/* ...and the ref can be found in the file system */ /* ...and the ref can be found in the file system */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, new_name)); cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), new_name));
cl_assert(git_path_exists(temp_path.ptr)); cl_assert(git_path_exists(temp_path.ptr));
git_reference_free(new_ref); git_reference_free(new_ref);
...@@ -80,7 +81,7 @@ void test_refs_rename__packed(void) ...@@ -80,7 +81,7 @@ void test_refs_rename__packed(void)
const char *brand_new_name = "refs/heads/brand_new_name"; const char *brand_new_name = "refs/heads/brand_new_name";
/* Ensure the ref doesn't exist on the file system */ /* Ensure the ref doesn't exist on the file system */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, packed_head_name)); cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name));
cl_assert(!git_path_exists(temp_path.ptr)); cl_assert(!git_path_exists(temp_path.ptr));
/* The reference can however be looked-up... */ /* The reference can however be looked-up... */
...@@ -106,7 +107,7 @@ void test_refs_rename__packed(void) ...@@ -106,7 +107,7 @@ void test_refs_rename__packed(void)
cl_assert(reference_is_packed(new_ref) == 0); cl_assert(reference_is_packed(new_ref) == 0);
/* ...and the ref now happily lives in the file system */ /* ...and the ref now happily lives in the file system */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, brand_new_name)); cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name));
cl_assert(git_path_exists(temp_path.ptr)); cl_assert(git_path_exists(temp_path.ptr));
git_reference_free(new_ref); git_reference_free(new_ref);
...@@ -122,7 +123,7 @@ void test_refs_rename__packed_doesnt_pack_others(void) ...@@ -122,7 +123,7 @@ void test_refs_rename__packed_doesnt_pack_others(void)
const char *brand_new_name = "refs/heads/brand_new_name"; const char *brand_new_name = "refs/heads/brand_new_name";
/* Ensure the other reference exists on the file system */ /* Ensure the other reference exists on the file system */
cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, packed_test_head_name)); cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
cl_assert(git_path_exists(temp_path.ptr)); cl_assert(git_path_exists(temp_path.ptr));
/* Lookup the other reference */ /* Lookup the other reference */
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "odb.h" #include "odb.h"
#include "fileops.h"
#include "repository.h" #include "repository.h"
#define TEMP_REPO_FOLDER "temprepo/" #define TEMP_REPO_FOLDER "temprepo/"
#define DISCOVER_FOLDER TEMP_REPO_FOLDER "discover.git" #define DISCOVER_FOLDER TEMP_REPO_FOLDER "discover.git"
......
...@@ -169,7 +169,7 @@ void test_status_ignore__ignore_pattern_ignorecase(void) ...@@ -169,7 +169,7 @@ void test_status_ignore__ignore_pattern_ignorecase(void)
cl_git_mkfile("empty_standard_repo/A.txt", "Differs in case"); cl_git_mkfile("empty_standard_repo/A.txt", "Differs in case");
cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_repository_index(&index, g_repo));
ignore_case = index->ignore_case; ignore_case = (git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0;
git_index_free(index); git_index_free(index);
cl_git_pass(git_status_file(&flags, g_repo, "A.txt")); cl_git_pass(git_status_file(&flags, g_repo, "A.txt"));
......
...@@ -105,7 +105,7 @@ void test_status_worktree__swap_subdir_and_file(void) ...@@ -105,7 +105,7 @@ void test_status_worktree__swap_subdir_and_file(void)
bool ignore_case; bool ignore_case;
cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_repository_index(&index, repo));
ignore_case = index->ignore_case; ignore_case = (git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0;
git_index_free(index); git_index_free(index);
/* first alter the contents of the worktree */ /* first alter the contents of the worktree */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment