本文整理汇总了C++中xstrfmt函数的典型用法代码示例。如果您正苦于以下问题:C++ xstrfmt函数的具体用法?C++ xstrfmt怎么用?C++ xstrfmt使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xstrfmt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xcalloc
static struct complete_reflogs *read_complete_reflog(const char *ref)
{
struct complete_reflogs *reflogs =
xcalloc(1, sizeof(struct complete_reflogs));
reflogs->ref = xstrdup(ref);
for_each_reflog_ent(ref, read_one_reflog, reflogs);
if (reflogs->nr == 0) {
struct object_id oid;
const char *name;
void *name_to_free;
name = name_to_free = resolve_refdup(ref, RESOLVE_REF_READING,
oid.hash, NULL);
if (name) {
for_each_reflog_ent(name, read_one_reflog, reflogs);
free(name_to_free);
}
}
if (reflogs->nr == 0) {
char *refname = xstrfmt("refs/%s", ref);
for_each_reflog_ent(refname, read_one_reflog, reflogs);
if (reflogs->nr == 0) {
free(refname);
refname = xstrfmt("refs/heads/%s", ref);
for_each_reflog_ent(refname, read_one_reflog, reflogs);
}
free(refname);
}
return reflogs;
}
示例2: name_rev
static void name_rev(struct commit *commit,
const char *tip_name, int generation, int distance,
int deref)
{
struct rev_name *name = (struct rev_name *)commit->util;
struct commit_list *parents;
int parent_number = 1;
parse_commit(commit);
if (commit->date < cutoff)
return;
if (deref) {
tip_name = xstrfmt("%s^0", tip_name);
if (generation)
die("generation: %d, but deref?", generation);
}
if (name == NULL) {
name = xmalloc(sizeof(rev_name));
commit->util = name;
goto copy_data;
} else if (name->distance > distance) {
copy_data:
name->tip_name = tip_name;
name->generation = generation;
name->distance = distance;
} else
return;
for (parents = commit->parents;
parents;
parents = parents->next, parent_number++) {
if (parent_number > 1) {
size_t len;
char *new_name;
strip_suffix(tip_name, "^0", &len);
if (generation > 0)
new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name,
generation, parent_number);
else
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
parent_number);
name_rev(parents->item, new_name, 0,
distance + MERGE_TRAVERSAL_WEIGHT, 0);
} else {
name_rev(parents->item, tip_name, generation + 1,
distance + 1, 0);
}
}
}
示例3: bisect_next_check
static int bisect_next_check(const struct bisect_terms *terms,
const char *current_term)
{
int missing_good = 1, missing_bad = 1, retval = 0;
const char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
const char *good_glob = xstrfmt("%s-*", terms->term_good);
if (ref_exists(bad_ref))
missing_bad = 0;
for_each_glob_ref_in(mark_good, good_glob, "refs/bisect/",
(void *) &missing_good);
if (!missing_good && !missing_bad)
goto finish;
if (!current_term) {
retval = -1;
goto finish;
}
if (missing_good && !missing_bad &&
!strcmp(current_term, terms->term_good)) {
char *yesno;
/*
* have bad (or new) but not good (or old). We could bisect
* although this is less optimum.
*/
warning(_("bisecting only with a %s commit"), terms->term_bad);
if (!isatty(0))
goto finish;
/*
* TRANSLATORS: Make sure to include [Y] and [n] in your
* translation. The program will only accept English input
* at this point.
*/
yesno = git_prompt(_("Are you sure [Y/n]? "), PROMPT_ECHO);
if (starts_with(yesno, "N") || starts_with(yesno, "n"))
retval = -1;
goto finish;
}
if (!is_empty_or_missing_file(git_path_bisect_start())) {
retval = error(_(need_bad_and_good_revision_warning),
vocab_bad, vocab_good, vocab_bad, vocab_good);
} else {
retval = error(_(need_bisect_start_warning),
vocab_good, vocab_bad, vocab_good, vocab_bad);
}
finish:
free((void *) good_glob);
free((void *) bad_ref);
return retval;
}
示例4: check_term_format
static int check_term_format(const char *term, const char *orig_term)
{
int res;
char *new_term = xstrfmt("refs/bisect/%s", term);
res = check_refname_format(new_term, 0);
free(new_term);
if (res)
return error(_("'%s' is not a valid term"), term);
if (one_of(term, "help", "start", "skip", "next", "reset",
"visualize", "view", "replay", "log", "run", "terms", NULL))
return error(_("can't use the builtin command '%s' as a term"), term);
/*
* In theory, nothing prevents swapping completely good and bad,
* but this situation could be confusing and hasn't been tested
* enough. Forbid it for now.
*/
if ((strcmp(orig_term, "bad") && one_of(term, "bad", "new", NULL)) ||
(strcmp(orig_term, "good") && one_of(term, "good", "old", NULL)))
return error(_("can't change the meaning of the term '%s'"), term);
return 0;
}
示例5: xmalloc
/*
* Normalize "path", prepending the "prefix" for relative paths. If
* remaining_prefix is not NULL, return the actual prefix still
* remains in the path. For example, prefix = sub1/sub2/ and path is
*
* foo -> sub1/sub2/foo (full prefix)
* ../foo -> sub1/foo (remaining prefix is sub1/)
* ../../bar -> bar (no remaining prefix)
* ../../sub1/sub2/foo -> sub1/sub2/foo (but no remaining prefix)
* `pwd`/../bar -> sub1/bar (no remaining prefix)
*/
char *prefix_path_gently(const char *prefix, int len,
int *remaining_prefix, const char *path)
{
const char *orig = path;
char *sanitized;
if (is_absolute_path(orig)) {
sanitized = xmalloc(strlen(path) + 1);
if (remaining_prefix)
*remaining_prefix = 0;
if (normalize_path_copy_len(sanitized, path, remaining_prefix)) {
free(sanitized);
return NULL;
}
if (abspath_part_inside_repo(sanitized)) {
free(sanitized);
return NULL;
}
} else {
sanitized = xstrfmt("%.*s%s", len, prefix, path);
if (remaining_prefix)
*remaining_prefix = len;
if (normalize_path_copy_len(sanitized, sanitized, remaining_prefix)) {
free(sanitized);
return NULL;
}
}
return sanitized;
}
示例6: list_tags
static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)
{
struct ref_array array;
char *to_free = NULL;
int i;
memset(&array, 0, sizeof(array));
if (filter->lines == -1)
filter->lines = 0;
if (!format) {
if (filter->lines) {
to_free = xstrfmt("%s %%(contents:lines=%d)",
"%(align:15)%(refname:strip=2)%(end)",
filter->lines);
format = to_free;
} else
format = "%(refname:strip=2)";
}
verify_ref_format(format);
filter->with_commit_tag_algo = 1;
filter_refs(&array, filter, FILTER_REFS_TAGS);
ref_array_sort(sorting, &array);
for (i = 0; i < array.nr; i++)
show_ref_array_item(array.items[i], format, 0);
ref_array_clear(&array);
free(to_free);
return 0;
}
示例7: get_message
static int get_message(struct commit *commit, struct commit_message *out)
{
const char *abbrev, *subject;
int subject_len;
out->message = logmsg_reencode(commit, NULL, get_commit_output_encoding());
abbrev = find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV);
subject_len = find_commit_subject(out->message, &subject);
out->subject = xmemdupz(subject, subject_len);
out->label = xstrfmt("%s... %s", abbrev, out->subject);
out->parent_label = xstrfmt("parent of %s", out->label);
return 0;
}
示例8: fetch_symref
static void fetch_symref(const char *path, char **symref, struct object_id *oid)
{
char *url = xstrfmt("%s%s", repo->url, path);
struct strbuf buffer = STRBUF_INIT;
const char *name;
if (http_get_strbuf(url, &buffer, NULL) != HTTP_OK)
die("Couldn't get %s for remote symref\n%s", url,
curl_errorstr);
free(url);
FREE_AND_NULL(*symref);
oidclr(oid);
if (buffer.len == 0)
return;
/* Cut off trailing newline. */
strbuf_rtrim(&buffer);
/* If it's a symref, set the refname; otherwise try for a sha1 */
if (skip_prefix(buffer.buf, "ref: ", &name)) {
*symref = xmemdupz(name, buffer.len - (name - buffer.buf));
} else {
get_oid_hex(buffer.buf, oid);
}
strbuf_release(&buffer);
}
示例9: name_rev
static void name_rev(struct commit *commit,
const char *tip_name, int generation, int distance,
int deref)
{
struct rev_name *name = (struct rev_name *)commit->util;
struct commit_list *parents;
int parent_number = 1;
parse_commit(commit);
if (commit->date < cutoff)
return;
if (deref) {
tip_name = xstrfmt("%s^0", tip_name);
if (generation)
die("generation: %d, but deref?", generation);
}
if (name == NULL) {
name = xmalloc(sizeof(rev_name));
commit->util = name;
goto copy_data;
} else if (name->distance > distance) {
copy_data:
name->tip_name = tip_name;
name->generation = generation;
name->distance = distance;
} else
return;
for (parents = commit->parents;
parents;
parents = parents->next, parent_number++) {
if (parent_number > 1) {
int len = strlen(tip_name);
char *new_name = xmalloc(len +
1 + decimal_length(generation) + /* ~<n> */
1 + 2 + /* ^NN */
1);
if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
len -= 2;
if (generation > 0)
sprintf(new_name, "%.*s~%d^%d", len, tip_name,
generation, parent_number);
else
sprintf(new_name, "%.*s^%d", len, tip_name,
parent_number);
name_rev(parents->item, new_name, 0,
distance + MERGE_TRAVERSAL_WEIGHT, 0);
} else {
name_rev(parents->item, tip_name, generation + 1,
distance + 1, 0);
}
}
}
示例10: setup_unpack_trees_porcelain
void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
const char *cmd)
{
int i;
const char **msgs = opts->msgs;
const char *msg;
const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
if (advice_commit_before_merge)
msg = "Your local changes to the following files would be overwritten by %s:\n%%s"
"Please, commit your changes or stash them before you can %s.";
else
msg = "Your local changes to the following files would be overwritten by %s:\n%%s";
msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] =
xstrfmt(msg, cmd, cmd2);
msgs[ERROR_NOT_UPTODATE_DIR] =
"Updating the following directories would lose untracked files in it:\n%s";
if (advice_commit_before_merge)
msg = "The following untracked working tree files would be %s by %s:\n%%s"
"Please move or remove them before you can %s.";
else
msg = "The following untracked working tree files would be %s by %s:\n%%s";
msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = xstrfmt(msg, "removed", cmd, cmd2);
msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = xstrfmt(msg, "overwritten", cmd, cmd2);
/*
* Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
* cannot easily display it as a list.
*/
msgs[ERROR_BIND_OVERLAP] = "Entry '%s' overlaps with '%s'. Cannot bind.";
msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] =
"Cannot update sparse checkout: the following entries are not up-to-date:\n%s";
msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] =
"The following Working tree files would be overwritten by sparse checkout update:\n%s";
msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] =
"The following Working tree files would be removed by sparse checkout update:\n%s";
opts->show_all_errors = 1;
/* rejected paths may not have a static buffer */
for (i = 0; i < ARRAY_SIZE(opts->unpack_rejects); i++)
opts->unpack_rejects[i].strdup_strings = 1;
}
示例11: expand_base_dir
static void expand_base_dir(char **out, const char *in,
const char *base_dir, const char *def_in)
{
free(*out);
if (in)
*out = xstrdup(in);
else
*out = xstrfmt("%s/%s", base_dir, def_in);
}
示例12: getenv
static char *git_path_from_env(const char *envvar, const char *git_dir,
const char *path, int fromenv)
{
if (fromenv) {
const char *value = getenv(envvar);
if (value)
return xstrdup(value);
}
return xstrfmt("%s/%s", git_dir, path);
}
示例13: show_datestring
static void show_datestring(const char *flag, const char *datestr)
{
char *buffer;
/* date handling requires both flags and revs */
if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS))
return;
buffer = xstrfmt("%s%"PRItime, flag, approxidate(datestr));
show(buffer);
free(buffer);
}
示例14: xstrfmt
const char *unique_tracking_name(const char *name, struct object_id *oid)
{
struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };
cb_data.src_ref = xstrfmt("refs/heads/%s", name);
cb_data.dst_oid = oid;
for_each_remote(check_tracking_name, &cb_data);
free(cb_data.src_ref);
if (cb_data.unique)
return cb_data.dst_ref;
free(cb_data.dst_ref);
return NULL;
}
示例15: expand_user_path
static char *get_socket_path(void)
{
struct stat sb;
char *old_dir, *socket;
old_dir = expand_user_path("~/.git-credential-cache", 0);
if (old_dir && !stat(old_dir, &sb) && S_ISDIR(sb.st_mode))
socket = xstrfmt("%s/socket", old_dir);
else
socket = xdg_cache_home("credential/socket");
free(old_dir);
return socket;
}