Hash :
f0e693b1
Author :
Date :
2021-09-07T17:53:49
str: introduce `git_str` for internal, `git_buf` is external libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
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
/*
* 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_refspec_h__
#define INCLUDE_refspec_h__
#include "common.h"
#include "git2/refspec.h"
#include "str.h"
#include "vector.h"
struct git_refspec {
char *string;
char *src;
char *dst;
unsigned int force :1,
push : 1,
pattern :1,
matching :1;
};
#define GIT_REFSPEC_TAGS "refs/tags/*:refs/tags/*"
int git_refspec__transform(git_str *out, const git_refspec *spec, const char *name);
int git_refspec__rtransform(git_str *out, const git_refspec *spec, const char *name);
int git_refspec__parse(
struct git_refspec *refspec,
const char *str,
bool is_fetch);
void git_refspec__dispose(git_refspec *refspec);
int git_refspec__serialize(git_str *out, const git_refspec *refspec);
/**
* Determines if a refspec is a wildcard refspec.
*
* @param spec the refspec
* @return 1 if the refspec is a wildcard, 0 otherwise
*/
int git_refspec_is_wildcard(const git_refspec *spec);
/**
* DWIM `spec` with `refs` existing on the remote, append the dwim'ed
* result in `out`.
*/
int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs);
#endif