Commit 46e7fc18 by Vicent Marti

Merge pull request #2077 from libgit2/cmn/buf-out

Buff up returning strings
parents c90ea3de bf522e08
...@@ -200,25 +200,20 @@ GIT_EXTERN(int) git_branch_set_upstream(git_reference *branch, const char *upstr ...@@ -200,25 +200,20 @@ GIT_EXTERN(int) git_branch_set_upstream(git_reference *branch, const char *upstr
* Return the name of the reference supporting the remote tracking branch, * Return the name of the reference supporting the remote tracking branch,
* given the name of a local branch reference. * given the name of a local branch reference.
* *
* @param tracking_branch_name_out The user-allocated buffer which will be * @param out Pointer to the user-allocated git_buf which will be
* filled with the name of the reference. Pass NULL if you just want to * filled with the name of the reference.
* get the needed size of the name of the reference as the output value.
*
* @param buffer_size Size of the `out` buffer in bytes.
* *
* @param repo the repository where the branches live * @param repo the repository where the branches live
* *
* @param canonical_branch_name name of the local branch. * @param refname reference name of the local branch.
* *
* @return number of characters in the reference name * @return 0, GIT_ENOTFOUND when no remote tracking reference exists,
* including the trailing NUL byte; GIT_ENOTFOUND when no remote tracking * otherwise an error code.
* reference exists, otherwise an error code.
*/ */
GIT_EXTERN(int) git_branch_upstream_name( GIT_EXTERN(int) git_branch_upstream_name(
char *tracking_branch_name_out, git_buf *out,
size_t buffer_size,
git_repository *repo, git_repository *repo,
const char *canonical_branch_name); const char *refname);
/** /**
* Determine if the current local branch is pointed at by HEAD. * Determine if the current local branch is pointed at by HEAD.
...@@ -234,25 +229,19 @@ GIT_EXTERN(int) git_branch_is_head( ...@@ -234,25 +229,19 @@ GIT_EXTERN(int) git_branch_is_head(
/** /**
* Return the name of remote that the remote tracking branch belongs to. * Return the name of remote that the remote tracking branch belongs to.
* *
* @param remote_name_out The user-allocated buffer which will be * @param out Pointer to the user-allocated git_buf which will be filled iwth the name of the remote.
* filled with the name of the remote. Pass NULL if you just want to
* get the needed size of the name of the remote as the output value.
*
* @param buffer_size Size of the `out` buffer in bytes.
* *
* @param repo The repository where the branch lives. * @param repo The repository where the branch lives.
* *
* @param canonical_branch_name name of the remote tracking branch. * @param canonical_branch_name name of the remote tracking branch.
* *
* @return Number of characters in the reference name * @return 0, GIT_ENOTFOUND
* including the trailing NUL byte; GIT_ENOTFOUND
* when no remote matching remote was found, * when no remote matching remote was found,
* GIT_EAMBIGUOUS when the branch maps to several remotes, * GIT_EAMBIGUOUS when the branch maps to several remotes,
* otherwise an error code. * otherwise an error code.
*/ */
GIT_EXTERN(int) git_branch_remote_name( GIT_EXTERN(int) git_branch_remote_name(
char *remote_name_out, git_buf *out,
size_t buffer_size,
git_repository *repo, git_repository *repo,
const char *canonical_branch_name); const char *canonical_branch_name);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "common.h" #include "common.h"
#include "types.h" #include "types.h"
#include "buffer.h"
/** /**
* @file git2/config.h * @file git2/config.h
...@@ -90,11 +91,10 @@ typedef struct { ...@@ -90,11 +91,10 @@ typedef struct {
* This method will not guess the path to the xdg compatible * This method will not guess the path to the xdg compatible
* config file (.config/git/config). * config file (.config/git/config).
* *
* @param out Buffer to store the path in * @param out Pointer to a user-allocated git_buf in which to store the path
* @param length size of the buffer in bytes * @return 0 if a global configuration file has been found. Its path will be stored in `out`.
* @return 0 if a global configuration file has been found. Its path will be stored in `buffer`.
*/ */
GIT_EXTERN(int) git_config_find_global(char *out, size_t length); GIT_EXTERN(int) git_config_find_global(git_buf *out);
/** /**
* Locate the path to the global xdg compatible configuration file * Locate the path to the global xdg compatible configuration file
...@@ -107,25 +107,23 @@ GIT_EXTERN(int) git_config_find_global(char *out, size_t length); ...@@ -107,25 +107,23 @@ GIT_EXTERN(int) git_config_find_global(char *out, size_t length);
* may be used on any `git_config` call to load the * may be used on any `git_config` call to load the
* xdg compatible configuration file. * xdg compatible configuration file.
* *
* @param out Buffer to store the path in * @param out Pointer to a user-allocated git_buf in which to store the path
* @param length size of the buffer in bytes
* @return 0 if a xdg compatible configuration file has been * @return 0 if a xdg compatible configuration file has been
* found. Its path will be stored in `buffer`. * found. Its path will be stored in `out`.
*/ */
GIT_EXTERN(int) git_config_find_xdg(char *out, size_t length); GIT_EXTERN(int) git_config_find_xdg(git_buf *out);
/** /**
* Locate the path to the system configuration file * Locate the path to the system configuration file
* *
* If /etc/gitconfig doesn't exist, it will look for * If /etc/gitconfig doesn't exist, it will look for
* %PROGRAMFILES%\Git\etc\gitconfig. * %PROGRAMFILES%\Git\etc\gitconfig.
*
* @param out Buffer to store the path in * @param out Pointer to a user-allocated git_buf in which to store the path
* @param length size of the buffer in bytes
* @return 0 if a system configuration file has been * @return 0 if a system configuration file has been
* found. Its path will be stored in `buffer`. * found. Its path will be stored in `out`.
*/ */
GIT_EXTERN(int) git_config_find_system(char *out, size_t length); GIT_EXTERN(int) git_config_find_system(git_buf *out);
/** /**
* Open the global, XDG and system configuration files * Open the global, XDG and system configuration files
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#define INCLUDE_git_message_h__ #define INCLUDE_git_message_h__
#include "common.h" #include "common.h"
#include "buffer.h"
/** /**
* @file git2/message.h * @file git2/message.h
...@@ -23,25 +24,17 @@ GIT_BEGIN_DECL ...@@ -23,25 +24,17 @@ GIT_BEGIN_DECL
* *
* Optionally, can remove lines starting with a "#". * Optionally, can remove lines starting with a "#".
* *
* @param out The user-allocated buffer which will be filled with the * @param out The user-allocated git_buf which will be filled with the
* cleaned up message. Pass NULL if you just want to get the needed * cleaned up message.
* size of the prettified message as the output value.
*
* @param out_size Size of the `out` buffer in bytes.
* *
* @param message The message to be prettified. * @param message The message to be prettified.
* *
* @param strip_comments Non-zero to remove lines starting with "#", 0 to * @param strip_comments Non-zero to remove lines starting with "#", 0 to
* leave them in. * leave them in.
* *
* @return -1 on error, else number of characters in prettified message * @return 0 or an error code.
* including the trailing NUL byte
*/ */
GIT_EXTERN(int) git_message_prettify( GIT_EXTERN(int) git_message_prettify(git_buf *out, const char *message, int strip_comments);
char *out,
size_t out_size,
const char *message,
int strip_comments);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "common.h" #include "common.h"
#include "types.h" #include "types.h"
#include "net.h" #include "net.h"
#include "buffer.h"
/** /**
* @file git2/refspec.h * @file git2/refspec.h
...@@ -82,23 +83,21 @@ GIT_EXTERN(int) git_refspec_dst_matches(const git_refspec *refspec, const char * ...@@ -82,23 +83,21 @@ GIT_EXTERN(int) git_refspec_dst_matches(const git_refspec *refspec, const char *
* Transform a reference to its target following the refspec's rules * Transform a reference to its target following the refspec's rules
* *
* @param out where to store the target name * @param out where to store the target name
* @param outlen the size of the `out` buffer
* @param spec the refspec * @param spec the refspec
* @param name the name of the reference to transform * @param name the name of the reference to transform
* @return 0, GIT_EBUFS or another error * @return 0, GIT_EBUFS or another error
*/ */
GIT_EXTERN(int) git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name); GIT_EXTERN(int) git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name);
/** /**
* Transform a target reference to its source reference following the refspec's rules * Transform a target reference to its source reference following the refspec's rules
* *
* @param out where to store the source reference name * @param out where to store the source reference name
* @param outlen the size of the `out` buffer
* @param spec the refspec * @param spec the refspec
* @param name the name of the reference to transform * @param name the name of the reference to transform
* @return 0, GIT_EBUFS or another error * @return 0, GIT_EBUFS or another error
*/ */
GIT_EXTERN(int) git_refspec_rtransform(char *out, size_t outlen, const git_refspec *spec, const char *name); GIT_EXTERN(int) git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name);
GIT_END_DECL GIT_END_DECL
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "common.h" #include "common.h"
#include "types.h" #include "types.h"
#include "oid.h" #include "oid.h"
#include "buffer.h"
/** /**
* @file git2/repository.h * @file git2/repository.h
...@@ -58,10 +59,8 @@ GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb); ...@@ -58,10 +59,8 @@ GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb);
* The method will automatically detect if the repository is bare * The method will automatically detect if the repository is bare
* (if there is a repository). * (if there is a repository).
* *
* @param path_out The user allocated buffer which will * @param out A pointer to a user-allocated git_buf which will contain
* contain the found path. * the found path.
*
* @param path_size repository_path size
* *
* @param start_path The base path where the lookup starts. * @param start_path The base path where the lookup starts.
* *
...@@ -77,8 +76,7 @@ GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb); ...@@ -77,8 +76,7 @@ GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb);
* @return 0 or an error code * @return 0 or an error code
*/ */
GIT_EXTERN(int) git_repository_discover( GIT_EXTERN(int) git_repository_discover(
char *path_out, git_buf *out,
size_t path_size,
const char *start_path, const char *start_path,
int across_fs, int across_fs,
const char *ceiling_dirs); const char *ceiling_dirs);
...@@ -464,21 +462,11 @@ GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo); ...@@ -464,21 +462,11 @@ GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo);
* Use this function to get the contents of this file. Don't forget to * Use this function to get the contents of this file. Don't forget to
* remove the file after you create the commit. * remove the file after you create the commit.
* *
* If the repository message exists and there are no errors reading it, this * @param out git_buf to write data into
* returns the bytes needed to store the message in memory (i.e. message
* file size plus one terminating NUL byte). That value is returned even if
* `out` is NULL or `len` is shorter than the necessary size.
*
* The `out` buffer will *always* be NUL terminated, even if truncation
* occurs.
*
* @param out Buffer to write data into or NULL to just read required size
* @param len Length of `out` buffer in bytes
* @param repo Repository to read prepared message from * @param repo Repository to read prepared message from
* @return GIT_ENOTFOUND if no message exists, other value < 0 for other * @return 0, GIT_ENOTFOUND if no message exists or an error code
* errors, or total bytes in message (may be > `len`) on success
*/ */
GIT_EXTERN(int) git_repository_message(char *out, size_t len, git_repository *repo); GIT_EXTERN(int) git_repository_message(git_buf *out, git_repository *repo);
/** /**
* Remove git's prepared message. * Remove git's prepared message.
......
...@@ -286,10 +286,10 @@ static int retrieve_upstream_configuration( ...@@ -286,10 +286,10 @@ static int retrieve_upstream_configuration(
return error; return error;
} }
int git_branch_upstream__name( int git_branch_upstream_name(
git_buf *tracking_name, git_buf *out,
git_repository *repo, git_repository *repo,
const char *canonical_branch_name) const char *refname)
{ {
const char *remote_name, *merge_name; const char *remote_name, *merge_name;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
...@@ -297,22 +297,24 @@ int git_branch_upstream__name( ...@@ -297,22 +297,24 @@ int git_branch_upstream__name(
git_remote *remote = NULL; git_remote *remote = NULL;
const git_refspec *refspec; const git_refspec *refspec;
assert(tracking_name && canonical_branch_name); assert(out && refname);
git_buf_sanitize(out);
if (!git_reference__is_branch(canonical_branch_name)) if (!git_reference__is_branch(refname))
return not_a_local_branch(canonical_branch_name); return not_a_local_branch(refname);
if ((error = retrieve_upstream_configuration( if ((error = retrieve_upstream_configuration(
&remote_name, repo, canonical_branch_name, "branch.%s.remote")) < 0) &remote_name, repo, refname, "branch.%s.remote")) < 0)
goto cleanup; goto cleanup;
if ((error = retrieve_upstream_configuration( if ((error = retrieve_upstream_configuration(
&merge_name, repo, canonical_branch_name, "branch.%s.merge")) < 0) &merge_name, repo, refname, "branch.%s.merge")) < 0)
goto cleanup; goto cleanup;
if (!*remote_name || !*merge_name) { if (!*remote_name || !*merge_name) {
giterr_set(GITERR_REFERENCE, giterr_set(GITERR_REFERENCE,
"branch '%s' does not have an upstream", canonical_branch_name); "branch '%s' does not have an upstream", refname);
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
goto cleanup; goto cleanup;
} }
...@@ -327,13 +329,13 @@ int git_branch_upstream__name( ...@@ -327,13 +329,13 @@ int git_branch_upstream__name(
goto cleanup; goto cleanup;
} }
if (git_refspec_transform_r(&buf, refspec, merge_name) < 0) if (git_refspec_transform(&buf, refspec, merge_name) < 0)
goto cleanup; goto cleanup;
} else } else
if (git_buf_sets(&buf, merge_name) < 0) if (git_buf_sets(&buf, merge_name) < 0)
goto cleanup; goto cleanup;
error = git_buf_set(tracking_name, git_buf_cstr(&buf), git_buf_len(&buf)); error = git_buf_set(out, git_buf_cstr(&buf), git_buf_len(&buf));
cleanup: cleanup:
git_remote_free(remote); git_remote_free(remote);
...@@ -341,7 +343,7 @@ cleanup: ...@@ -341,7 +343,7 @@ cleanup:
return error; return error;
} }
static int remote_name(git_buf *buf, git_repository *repo, const char *canonical_branch_name) int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refname)
{ {
git_strarray remote_list = {0}; git_strarray remote_list = {0};
size_t i; size_t i;
...@@ -350,12 +352,14 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical ...@@ -350,12 +352,14 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
int error = 0; int error = 0;
char *remote_name = NULL; char *remote_name = NULL;
assert(buf && repo && canonical_branch_name); assert(buf && repo && refname);
git_buf_sanitize(buf);
/* Verify that this is a remote branch */ /* Verify that this is a remote branch */
if (!git_reference__is_remote(canonical_branch_name)) { if (!git_reference__is_remote(refname)) {
giterr_set(GITERR_INVALID, "Reference '%s' is not a remote branch.", giterr_set(GITERR_INVALID, "Reference '%s' is not a remote branch.",
canonical_branch_name); refname);
error = GIT_ERROR; error = GIT_ERROR;
goto cleanup; goto cleanup;
} }
...@@ -369,7 +373,7 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical ...@@ -369,7 +373,7 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
if ((error = git_remote_load(&remote, repo, remote_list.strings[i])) < 0) if ((error = git_remote_load(&remote, repo, remote_list.strings[i])) < 0)
continue; continue;
fetchspec = git_remote__matching_dst_refspec(remote, canonical_branch_name); fetchspec = git_remote__matching_dst_refspec(remote, refname);
if (fetchspec) { if (fetchspec) {
/* If we have not already set out yet, then set /* If we have not already set out yet, then set
* it to the matching remote name. Otherwise * it to the matching remote name. Otherwise
...@@ -381,7 +385,7 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical ...@@ -381,7 +385,7 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
git_remote_free(remote); git_remote_free(remote);
giterr_set(GITERR_REFERENCE, giterr_set(GITERR_REFERENCE,
"Reference '%s' is ambiguous", canonical_branch_name); "Reference '%s' is ambiguous", refname);
error = GIT_EAMBIGUOUS; error = GIT_EAMBIGUOUS;
goto cleanup; goto cleanup;
} }
...@@ -395,68 +399,18 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical ...@@ -395,68 +399,18 @@ static int remote_name(git_buf *buf, git_repository *repo, const char *canonical
error = git_buf_puts(buf, remote_name); error = git_buf_puts(buf, remote_name);
} else { } else {
giterr_set(GITERR_REFERENCE, giterr_set(GITERR_REFERENCE,
"Could not determine remote for '%s'", canonical_branch_name); "Could not determine remote for '%s'", refname);
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
} }
cleanup: cleanup:
if (error < 0)
git_buf_free(buf);
git_strarray_free(&remote_list); git_strarray_free(&remote_list);
return error; return error;
} }
int git_branch_remote_name(char *buffer, size_t buffer_len, git_repository *repo, const char *refname)
{
int ret;
git_buf buf = GIT_BUF_INIT;
if ((ret = remote_name(&buf, repo, refname)) < 0)
return ret;
if (buffer)
git_buf_copy_cstr(buffer, buffer_len, &buf);
ret = (int)git_buf_len(&buf) + 1;
git_buf_free(&buf);
return ret;
}
int git_branch_upstream_name(
char *tracking_branch_name_out,
size_t buffer_size,
git_repository *repo,
const char *canonical_branch_name)
{
git_buf buf = GIT_BUF_INIT;
int error;
assert(canonical_branch_name);
if (tracking_branch_name_out && buffer_size)
*tracking_branch_name_out = '\0';
if ((error = git_branch_upstream__name(
&buf, repo, canonical_branch_name)) < 0)
goto cleanup;
if (tracking_branch_name_out && buf.size + 1 > buffer_size) { /* +1 for NUL byte */
giterr_set(
GITERR_INVALID,
"Buffer too short to hold the tracked reference name.");
error = -1;
goto cleanup;
}
if (tracking_branch_name_out)
git_buf_copy_cstr(tracking_branch_name_out, buffer_size, &buf);
error = (int)buf.size + 1;
cleanup:
git_buf_free(&buf);
return (int)error;
}
int git_branch_upstream( int git_branch_upstream(
git_reference **tracking_out, git_reference **tracking_out,
git_reference *branch) git_reference *branch)
...@@ -464,7 +418,7 @@ int git_branch_upstream( ...@@ -464,7 +418,7 @@ int git_branch_upstream(
int error; int error;
git_buf tracking_name = GIT_BUF_INIT; git_buf tracking_name = GIT_BUF_INIT;
if ((error = git_branch_upstream__name(&tracking_name, if ((error = git_branch_upstream_name(&tracking_name,
git_reference_owner(branch), git_reference_name(branch))) < 0) git_reference_owner(branch), git_reference_name(branch))) < 0)
return error; return error;
...@@ -547,7 +501,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name) ...@@ -547,7 +501,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
if (local) if (local)
git_buf_puts(&value, "."); git_buf_puts(&value, ".");
else else
remote_name(&value, repo, git_reference_name(upstream)); git_branch_remote_name(&value, repo, git_reference_name(upstream));
if (git_buf_printf(&key, "branch.%s.remote", shortname) < 0) if (git_buf_printf(&key, "branch.%s.remote", shortname) < 0)
goto on_error; goto on_error;
...@@ -566,7 +520,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name) ...@@ -566,7 +520,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
fetchspec = git_remote__matching_dst_refspec(remote, git_reference_name(upstream)); fetchspec = git_remote__matching_dst_refspec(remote, git_reference_name(upstream));
git_buf_clear(&value); git_buf_clear(&value);
if (!fetchspec || git_refspec_transform_l(&value, fetchspec, git_reference_name(upstream)) < 0) if (!fetchspec || git_refspec_rtransform(&value, fetchspec, git_reference_name(upstream)) < 0)
goto on_error; goto on_error;
git_remote_free(remote); git_remote_free(remote);
......
...@@ -131,7 +131,7 @@ static int reference_matches_remote_head( ...@@ -131,7 +131,7 @@ static int reference_matches_remote_head(
if (!error && !git_oid__cmp(&head_info->remote_head_oid, &oid)) { if (!error && !git_oid__cmp(&head_info->remote_head_oid, &oid)) {
/* Determine the local reference name from the remote tracking one */ /* Determine the local reference name from the remote tracking one */
error = git_refspec_transform_l( error = git_refspec_rtransform(
&head_info->branchname, head_info->refspec, reference_name); &head_info->branchname, head_info->refspec, reference_name);
if (!error && if (!error &&
...@@ -199,7 +199,7 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote) ...@@ -199,7 +199,7 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote)
} }
/* Determine the remote tracking reference name from the local master */ /* Determine the remote tracking reference name from the local master */
if ((error = git_refspec_transform_r( if ((error = git_refspec_transform(
&remote_master_name, &remote_master_name,
head_info.refspec, head_info.refspec,
GIT_REFS_HEADS_MASTER_FILE)) < 0) GIT_REFS_HEADS_MASTER_FILE)) < 0)
......
...@@ -935,61 +935,21 @@ void git_config_iterator_free(git_config_iterator *iter) ...@@ -935,61 +935,21 @@ void git_config_iterator_free(git_config_iterator *iter)
iter->free(iter); iter->free(iter);
} }
static int git_config__find_file_to_path( int git_config_find_global(git_buf *path)
char *out, size_t outlen, int (*find)(git_buf *buf))
{
int error = 0;
git_buf path = GIT_BUF_INIT;
if ((error = find(&path)) < 0)
goto done;
if (path.size >= outlen) {
giterr_set(GITERR_NOMEMORY, "Buffer is too short for the path");
error = GIT_EBUFS;
goto done;
}
git_buf_copy_cstr(out, outlen, &path);
done:
git_buf_free(&path);
return error;
}
int git_config_find_global_r(git_buf *path)
{ {
return git_futils_find_global_file(path, GIT_CONFIG_FILENAME_GLOBAL); return git_futils_find_global_file(path, GIT_CONFIG_FILENAME_GLOBAL);
} }
int git_config_find_global(char *global_config_path, size_t length) int git_config_find_xdg(git_buf *path)
{
return git_config__find_file_to_path(
global_config_path, length, git_config_find_global_r);
}
int git_config_find_xdg_r(git_buf *path)
{ {
return git_futils_find_xdg_file(path, GIT_CONFIG_FILENAME_XDG); return git_futils_find_xdg_file(path, GIT_CONFIG_FILENAME_XDG);
} }
int git_config_find_xdg(char *xdg_config_path, size_t length) int git_config_find_system(git_buf *path)
{
return git_config__find_file_to_path(
xdg_config_path, length, git_config_find_xdg_r);
}
int git_config_find_system_r(git_buf *path)
{ {
return git_futils_find_system_file(path, GIT_CONFIG_FILENAME_SYSTEM); return git_futils_find_system_file(path, GIT_CONFIG_FILENAME_SYSTEM);
} }
int git_config_find_system(char *system_config_path, size_t length)
{
return git_config__find_file_to_path(
system_config_path, length, git_config_find_system_r);
}
int git_config__global_location(git_buf *buf) int git_config__global_location(git_buf *buf)
{ {
const git_buf *paths; const git_buf *paths;
...@@ -1026,16 +986,16 @@ int git_config_open_default(git_config **out) ...@@ -1026,16 +986,16 @@ int git_config_open_default(git_config **out)
if ((error = git_config_new(&cfg)) < 0) if ((error = git_config_new(&cfg)) < 0)
return error; return error;
if (!git_config_find_global_r(&buf) || !git_config__global_location(&buf)) { if (!git_config_find_global(&buf) || !git_config__global_location(&buf)) {
error = git_config_add_file_ondisk(cfg, buf.ptr, error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_GLOBAL, 0); GIT_CONFIG_LEVEL_GLOBAL, 0);
} }
if (!error && !git_config_find_xdg_r(&buf)) if (!error && !git_config_find_xdg(&buf))
error = git_config_add_file_ondisk(cfg, buf.ptr, error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_XDG, 0); GIT_CONFIG_LEVEL_XDG, 0);
if (!error && !git_config_find_system_r(&buf)) if (!error && !git_config_find_system(&buf))
error = git_config_add_file_ondisk(cfg, buf.ptr, error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_SYSTEM, 0); GIT_CONFIG_LEVEL_SYSTEM, 0);
......
...@@ -24,11 +24,6 @@ struct git_config { ...@@ -24,11 +24,6 @@ struct git_config {
git_vector files; git_vector files;
}; };
extern int git_config_find_global_r(git_buf *global_config_path);
extern int git_config_find_xdg_r(git_buf *system_config_path);
extern int git_config_find_system_r(git_buf *system_config_path);
extern int git_config__global_location(git_buf *buf); extern int git_config__global_location(git_buf *buf);
extern int git_config_rename_section( extern int git_config_rename_section(
......
...@@ -21,7 +21,7 @@ static size_t line_length_without_trailing_spaces(const char *line, size_t len) ...@@ -21,7 +21,7 @@ static size_t line_length_without_trailing_spaces(const char *line, size_t len)
/* Greatly inspired from git.git "stripspace" */ /* Greatly inspired from git.git "stripspace" */
/* see https://github.com/git/git/blob/497215d8811ac7b8955693ceaad0899ecd894ed2/builtin/stripspace.c#L4-67 */ /* see https://github.com/git/git/blob/497215d8811ac7b8955693ceaad0899ecd894ed2/builtin/stripspace.c#L4-67 */
int git_message__prettify(git_buf *message_out, const char *message, int strip_comments) int git_message_prettify(git_buf *message_out, const char *message, int strip_comments)
{ {
const size_t message_len = strlen(message); const size_t message_len = strlen(message);
...@@ -29,6 +29,8 @@ int git_message__prettify(git_buf *message_out, const char *message, int strip_c ...@@ -29,6 +29,8 @@ int git_message__prettify(git_buf *message_out, const char *message, int strip_c
size_t i, line_length, rtrimmed_line_length; size_t i, line_length, rtrimmed_line_length;
char *next_newline; char *next_newline;
git_buf_sanitize(message_out);
for (i = 0; i < strlen(message); i += line_length) { for (i = 0; i < strlen(message); i += line_length) {
next_newline = memchr(message + i, '\n', message_len - i); next_newline = memchr(message + i, '\n', message_len - i);
...@@ -58,29 +60,3 @@ int git_message__prettify(git_buf *message_out, const char *message, int strip_c ...@@ -58,29 +60,3 @@ int git_message__prettify(git_buf *message_out, const char *message, int strip_c
return git_buf_oom(message_out) ? -1 : 0; return git_buf_oom(message_out) ? -1 : 0;
} }
int git_message_prettify(char *message_out, size_t buffer_size, const char *message, int strip_comments)
{
git_buf buf = GIT_BUF_INIT;
ssize_t out_size = -1;
if (message_out && buffer_size)
*message_out = '\0';
if (git_message__prettify(&buf, message, strip_comments) < 0)
goto done;
if (message_out && buf.size + 1 > buffer_size) { /* +1 for NUL byte */
giterr_set(GITERR_INVALID, "Buffer too short to hold the cleaned message");
goto done;
}
if (message_out)
git_buf_copy_cstr(message_out, buffer_size, &buf);
out_size = buf.size + 1;
done:
git_buf_free(&buf);
return (int)out_size;
}
...@@ -214,7 +214,7 @@ int git_push_update_tips(git_push *push) ...@@ -214,7 +214,7 @@ int git_push_update_tips(git_push *push)
if (!fetch_spec) if (!fetch_spec)
continue; continue;
if ((error = git_refspec_transform_r(&remote_ref_name, fetch_spec, status->ref)) < 0) if ((error = git_refspec_transform(&remote_ref_name, fetch_spec, status->ref)) < 0)
goto on_error; goto on_error;
/* Find matching push ref spec */ /* Find matching push ref spec */
......
...@@ -178,54 +178,6 @@ int git_refspec_dst_matches(const git_refspec *refspec, const char *refname) ...@@ -178,54 +178,6 @@ int git_refspec_dst_matches(const git_refspec *refspec, const char *refname)
return (p_fnmatch(refspec->dst, refname, 0) == 0); return (p_fnmatch(refspec->dst, refname, 0) == 0);
} }
static int refspec_transform_internal(char *out, size_t outlen, const char *from, const char *to, const char *name)
{
size_t baselen, namelen;
baselen = strlen(to);
if (outlen <= baselen) {
giterr_set(GITERR_INVALID, "Reference name too long");
return GIT_EBUFS;
}
/*
* No '*' at the end means that it's mapped to one specific local
* branch, so no actual transformation is needed.
*/
if (to[baselen - 1] != '*') {
memcpy(out, to, baselen + 1); /* include '\0' */
return 0;
}
/* There's a '*' at the end, so remove its length */
baselen--;
/* skip the prefix, -1 is for the '*' */
name += strlen(from) - 1;
namelen = strlen(name);
if (outlen <= baselen + namelen) {
giterr_set(GITERR_INVALID, "Reference name too long");
return GIT_EBUFS;
}
memcpy(out, to, baselen);
memcpy(out + baselen, name, namelen + 1);
return 0;
}
int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name)
{
return refspec_transform_internal(out, outlen, spec->src, spec->dst, name);
}
int git_refspec_rtransform(char *out, size_t outlen, const git_refspec *spec, const char *name)
{
return refspec_transform_internal(out, outlen, spec->dst, spec->src, name);
}
static int refspec_transform( static int refspec_transform(
git_buf *out, const char *from, const char *to, const char *name) git_buf *out, const char *from, const char *to, const char *name)
{ {
...@@ -233,6 +185,8 @@ static int refspec_transform( ...@@ -233,6 +185,8 @@ static int refspec_transform(
size_t from_len = from ? strlen(from) : 0; size_t from_len = from ? strlen(from) : 0;
size_t name_len = name ? strlen(name) : 0; size_t name_len = name ? strlen(name) : 0;
git_buf_sanitize(out);
if (git_buf_set(out, to, to_len) < 0) if (git_buf_set(out, to, to_len) < 0)
return -1; return -1;
...@@ -253,12 +207,12 @@ static int refspec_transform( ...@@ -253,12 +207,12 @@ static int refspec_transform(
return git_buf_put(out, name + from_len, name_len - from_len); return git_buf_put(out, name + from_len, name_len - from_len);
} }
int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *name) int git_refspec_transform(git_buf *out, const git_refspec *spec, const char *name)
{ {
return refspec_transform(out, spec->src, spec->dst, name); return refspec_transform(out, spec->src, spec->dst, name);
} }
int git_refspec_transform_l(git_buf *out, const git_refspec *spec, const char *name) int git_refspec_rtransform(git_buf *out, const git_refspec *spec, const char *name)
{ {
return refspec_transform(out, spec->dst, spec->src, name); return refspec_transform(out, spec->dst, spec->src, name);
} }
......
...@@ -31,28 +31,6 @@ int git_refspec__parse( ...@@ -31,28 +31,6 @@ int git_refspec__parse(
void git_refspec__free(git_refspec *refspec); void git_refspec__free(git_refspec *refspec);
/**
* Transform a reference to its target following the refspec's rules,
* and writes the results into a git_buf.
*
* @param out where to store the target name
* @param spec the refspec
* @param name the name of the reference to transform
* @return 0 or error if buffer allocation fails
*/
int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *name);
/**
* Transform a reference from its target following the refspec's rules,
* and writes the results into a git_buf.
*
* @param out where to store the source name
* @param spec the refspec
* @param name the name of the reference to transform
* @return 0 or error if buffer allocation fails
*/
int git_refspec_transform_l(git_buf *out, const git_refspec *spec, const char *name);
int git_refspec__serialize(git_buf *out, const git_refspec *refspec); int git_refspec__serialize(git_buf *out, const git_refspec *refspec);
/** /**
......
...@@ -896,7 +896,7 @@ static int remote_head_for_ref(git_remote_head **out, git_refspec *spec, git_vec ...@@ -896,7 +896,7 @@ static int remote_head_for_ref(git_remote_head **out, git_refspec *spec, git_vec
if ((error = git_reference_resolve(&resolved_ref, ref)) < 0 || if ((error = git_reference_resolve(&resolved_ref, ref)) < 0 ||
(!git_reference_is_branch(resolved_ref)) || (!git_reference_is_branch(resolved_ref)) ||
(error = git_branch_upstream(&tracking_ref, resolved_ref)) < 0 || (error = git_branch_upstream(&tracking_ref, resolved_ref)) < 0 ||
(error = git_refspec_transform_l(&remote_name, spec, git_reference_name(tracking_ref))) < 0) { (error = git_refspec_rtransform(&remote_name, spec, git_reference_name(tracking_ref))) < 0) {
/* Not an error if HEAD is unborn or no tracking branch */ /* Not an error if HEAD is unborn or no tracking branch */
if (error == GIT_ENOTFOUND) if (error == GIT_ENOTFOUND)
error = 0; error = 0;
...@@ -1011,7 +1011,7 @@ static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vecto ...@@ -1011,7 +1011,7 @@ static int update_tips_for_spec(git_remote *remote, git_refspec *spec, git_vecto
continue; continue;
if (git_refspec_src_matches(spec, head->name) && spec->dst) { if (git_refspec_src_matches(spec, head->name) && spec->dst) {
if (git_refspec_transform_r(&refname, spec, head->name) < 0) if (git_refspec_transform(&refname, spec, head->name) < 0)
goto on_error; goto on_error;
} else if (remote->download_tags != GIT_REMOTE_DOWNLOAD_TAGS_NONE) { } else if (remote->download_tags != GIT_REMOTE_DOWNLOAD_TAGS_NONE) {
......
...@@ -495,34 +495,18 @@ int git_repository_wrap_odb(git_repository **repo_out, git_odb *odb) ...@@ -495,34 +495,18 @@ int git_repository_wrap_odb(git_repository **repo_out, git_odb *odb)
} }
int git_repository_discover( int git_repository_discover(
char *repository_path, git_buf *out,
size_t size,
const char *start_path, const char *start_path,
int across_fs, int across_fs,
const char *ceiling_dirs) const char *ceiling_dirs)
{ {
git_buf path = GIT_BUF_INIT;
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0; uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
int error;
assert(start_path && repository_path && size > 0);
*repository_path = '\0';
if ((error = find_repo(&path, NULL, start_path, flags, ceiling_dirs)) < 0) assert(start_path);
return error != GIT_ENOTFOUND ? -1 : error;
if (size < (size_t)(path.size + 1)) { git_buf_sanitize(out);
giterr_set(GITERR_REPOSITORY,
"The given buffer is too small to store the discovered path");
git_buf_free(&path);
return -1;
}
/* success: we discovered a repository */ return find_repo(out, NULL, start_path, flags, ceiling_dirs);
git_buf_copy_cstr(repository_path, size, &path);
git_buf_free(&path);
return 0;
} }
static int load_config( static int load_config(
...@@ -598,9 +582,9 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo) ...@@ -598,9 +582,9 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
git_buf system_buf = GIT_BUF_INIT; git_buf system_buf = GIT_BUF_INIT;
git_config *config; git_config *config;
git_config_find_global_r(&global_buf); git_config_find_global(&global_buf);
git_config_find_xdg_r(&xdg_buf); git_config_find_xdg(&xdg_buf);
git_config_find_system_r(&system_buf); git_config_find_system(&system_buf);
/* If there is no global file, open a backend for it anyway */ /* If there is no global file, open a backend for it anyway */
if (git_buf_len(&global_buf) == 0) if (git_buf_len(&global_buf) == 0)
...@@ -1732,14 +1716,13 @@ cleanup: ...@@ -1732,14 +1716,13 @@ cleanup:
return error; return error;
} }
int git_repository_message(char *buffer, size_t len, git_repository *repo) int git_repository_message(git_buf *out, git_repository *repo)
{ {
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
struct stat st; struct stat st;
int error; int error;
if (buffer != NULL) git_buf_sanitize(out);
*buffer = '\0';
if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0) if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
return -1; return -1;
...@@ -1749,16 +1732,10 @@ int git_repository_message(char *buffer, size_t len, git_repository *repo) ...@@ -1749,16 +1732,10 @@ int git_repository_message(char *buffer, size_t len, git_repository *repo)
error = GIT_ENOTFOUND; error = GIT_ENOTFOUND;
giterr_set(GITERR_OS, "Could not access message file"); giterr_set(GITERR_OS, "Could not access message file");
} }
else if (buffer != NULL) {
error = git_futils_readbuffer(&buf, git_buf_cstr(&path));
git_buf_copy_cstr(buffer, len, &buf);
}
git_buf_free(&path); error = git_futils_readbuffer(out, git_buf_cstr(&path));
git_buf_free(&buf);
if (!error) git_buf_free(&path);
error = (int)st.st_size + 1; /* add 1 for NUL byte */
return error; return error;
} }
......
...@@ -38,7 +38,7 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void) ...@@ -38,7 +38,7 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
char *local_name = "refs/heads/master"; char *local_name = "refs/heads/master";
const char *expected_tracked_branch_name = "refs/remotes/origin/master"; const char *expected_tracked_branch_name = "refs/remotes/origin/master";
const char *expected_remote_name = "origin"; const char *expected_remote_name = "origin";
char buffer[1024]; git_buf buf = GIT_BUF_INIT;
git_reference *ref; git_reference *ref;
cl_set_cleanup(&cleanup_repository, "./empty"); cl_set_cleanup(&cleanup_repository, "./empty");
...@@ -50,16 +50,14 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void) ...@@ -50,16 +50,14 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, local_name)); cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, local_name));
/* ...one can still retrieve the name of the remote tracking reference */ /* ...one can still retrieve the name of the remote tracking reference */
cl_assert_equal_i((int)strlen(expected_tracked_branch_name) + 1, cl_git_pass(git_branch_upstream_name(&buf, g_repo_cloned, local_name));
git_branch_upstream_name(buffer, 1024, g_repo_cloned, local_name));
cl_assert_equal_s(expected_tracked_branch_name, buffer); cl_assert_equal_s(expected_tracked_branch_name, buf.ptr);
/* ...and the name of the remote... */ /* ...and the name of the remote... */
cl_assert_equal_i((int)strlen(expected_remote_name) + 1, cl_git_pass(git_branch_remote_name(&buf, g_repo_cloned, expected_tracked_branch_name));
git_branch_remote_name(buffer, 1024, g_repo_cloned, expected_tracked_branch_name));
cl_assert_equal_s(expected_remote_name, buffer); cl_assert_equal_s(expected_remote_name, buf.ptr);
/* ...even when the remote HEAD is unborn as well */ /* ...even when the remote HEAD is unborn as well */
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned,
......
...@@ -230,27 +230,20 @@ void test_network_remote_remotes__fnmatch(void) ...@@ -230,27 +230,20 @@ void test_network_remote_remotes__fnmatch(void)
void test_network_remote_remotes__transform(void) void test_network_remote_remotes__transform(void)
{ {
char ref[1024] = {0}; git_buf ref = GIT_BUF_INIT;
cl_git_pass(git_refspec_transform(ref, sizeof(ref), _refspec, "refs/heads/master")); cl_git_pass(git_refspec_transform(&ref, _refspec, "refs/heads/master"));
cl_assert_equal_s(ref, "refs/remotes/test/master"); cl_assert_equal_s(ref, "refs/remotes/test/master");
git_buf_free(&ref);
} }
void test_network_remote_remotes__transform_destination_to_source(void) void test_network_remote_remotes__transform_destination_to_source(void)
{ {
char ref[1024] = {0}; git_buf ref = GIT_BUF_INIT;
cl_git_pass(git_refspec_rtransform(ref, sizeof(ref), _refspec, "refs/remotes/test/master")); cl_git_pass(git_refspec_rtransform(&ref, _refspec, "refs/remotes/test/master"));
cl_assert_equal_s(ref, "refs/heads/master"); cl_assert_equal_s(ref.ptr, "refs/heads/master");
} git_buf_free(&ref);
void test_network_remote_remotes__transform_r(void)
{
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_refspec_transform_r(&buf, _refspec, "refs/heads/master"));
cl_assert_equal_s(git_buf_cstr(&buf), "refs/remotes/test/master");
git_buf_free(&buf);
} }
void test_network_remote_remotes__missing_refspecs(void) void test_network_remote_remotes__missing_refspecs(void)
......
...@@ -25,7 +25,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void) ...@@ -25,7 +25,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid; git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid;
git_signature *signature; git_signature *signature;
git_tree *tree; git_tree *tree;
char buffer[128]; git_buf buffer;
/* /*
* The test below replicates the following git scenario * The test below replicates the following git scenario
...@@ -111,7 +111,8 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void) ...@@ -111,7 +111,8 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid)); cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
cl_assert_equal_i(16, git_message_prettify(buffer, 128, "Initial commit", 0)); memset(&buffer, 0, sizeof(git_buf));
cl_git_pass(git_message_prettify(&buffer, "Initial commit", 0));
cl_git_pass(git_commit_create_v( cl_git_pass(git_commit_create_v(
&commit_oid, &commit_oid,
...@@ -120,12 +121,13 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void) ...@@ -120,12 +121,13 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
signature, signature,
signature, signature,
NULL, NULL,
buffer, buffer.ptr,
tree, tree,
0)); 0));
cl_assert(git_oid_cmp(&expected_commit_oid, &commit_oid) == 0); cl_assert(git_oid_cmp(&expected_commit_oid, &commit_oid) == 0);
git_buf_free(&buffer);
git_signature_free(signature); git_signature_free(signature);
git_tree_free(tree); git_tree_free(tree);
git_index_free(index); git_index_free(index);
......
...@@ -6,7 +6,7 @@ static void assert_message_prettifying(char *expected_output, char *input, int s ...@@ -6,7 +6,7 @@ static void assert_message_prettifying(char *expected_output, char *input, int s
{ {
git_buf prettified_message = GIT_BUF_INIT; git_buf prettified_message = GIT_BUF_INIT;
git_message__prettify(&prettified_message, input, strip_comments); git_message_prettify(&prettified_message, input, strip_comments);
cl_assert_equal_s(expected_output, git_buf_cstr(&prettified_message)); cl_assert_equal_s(expected_output, git_buf_cstr(&prettified_message));
git_buf_free(&prettified_message); git_buf_free(&prettified_message);
...@@ -172,65 +172,28 @@ void test_object_message__keep_comments(void) ...@@ -172,65 +172,28 @@ void test_object_message__keep_comments(void)
void test_object_message__message_prettify(void) void test_object_message__message_prettify(void)
{ {
char buffer[100]; git_buf buffer;
cl_assert(git_message_prettify(buffer, sizeof(buffer), "", 0) == 1); memset(&buffer, 0, sizeof(buffer));
cl_assert_equal_s(buffer, ""); cl_git_pass(git_message_prettify(&buffer, "", 0));
cl_assert(git_message_prettify(buffer, sizeof(buffer), "", 1) == 1); cl_assert_equal_s(buffer.ptr, "");
cl_assert_equal_s(buffer, ""); git_buf_free(&buffer);
cl_git_pass(git_message_prettify(&buffer, "", 1));
cl_assert_equal_i(7, git_message_prettify(buffer, sizeof(buffer), "Short", 0)); cl_assert_equal_s(buffer.ptr, "");
cl_assert_equal_s("Short\n", buffer); git_buf_free(&buffer);
cl_assert_equal_i(7, git_message_prettify(buffer, sizeof(buffer), "Short", 1));
cl_assert_equal_s("Short\n", buffer); cl_git_pass(git_message_prettify(&buffer, "Short", 0));
cl_assert_equal_s("Short\n", buffer.ptr);
cl_assert(git_message_prettify(buffer, sizeof(buffer), "This is longer\nAnd multiline\n# with some comments still in\n", 0) > 0); git_buf_free(&buffer);
cl_assert_equal_s(buffer, "This is longer\nAnd multiline\n# with some comments still in\n"); cl_git_pass(git_message_prettify(&buffer, "Short", 1));
cl_assert_equal_s("Short\n", buffer.ptr);
cl_assert(git_message_prettify(buffer, sizeof(buffer), "This is longer\nAnd multiline\n# with some comments still in\n", 1) > 0); git_buf_free(&buffer);
cl_assert_equal_s(buffer, "This is longer\nAnd multiline\n");
cl_git_pass(git_message_prettify(&buffer, "This is longer\nAnd multiline\n# with some comments still in\n", 0));
/* try out overflow */ cl_assert_equal_s(buffer.ptr, "This is longer\nAnd multiline\n# with some comments still in\n");
cl_assert(git_message_prettify(buffer, sizeof(buffer), git_buf_free(&buffer);
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678", cl_git_pass(git_message_prettify(&buffer, "This is longer\nAnd multiline\n# with some comments still in\n", 1));
0) > 0); cl_assert_equal_s(buffer.ptr, "This is longer\nAnd multiline\n");
cl_assert_equal_s(buffer, git_buf_free(&buffer);
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678\n");
cl_assert(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678\n",
0) > 0);
cl_assert_equal_s(buffer,
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678\n");
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "123456789",
0));
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "123456789\n",
0));
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890",
0));
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890""x",
0));
cl_assert(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890\n"
"# 1234567890" "1234567890" "1234567890" "1234567890" "1234567890\n"
"1234567890",
1) > 0);
cl_assert(git_message_prettify(NULL, 0, "", 0) == 1);
cl_assert(git_message_prettify(NULL, 0, "Short test", 0) == 12);
cl_assert(git_message_prettify(NULL, 0, "Test\n# with\nComments", 1) == 15);
} }
...@@ -219,7 +219,7 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r ...@@ -219,7 +219,7 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
if (!fetch_spec) if (!fetch_spec)
continue; continue;
cl_git_pass(git_refspec_transform_r(&ref_name, fetch_spec, expected_refs[i].name)); cl_git_pass(git_refspec_transform(&ref_name, fetch_spec, expected_refs[i].name));
/* Find matching remote branch */ /* Find matching remote branch */
git_vector_foreach(&actual_refs, j, actual_ref) { git_vector_foreach(&actual_refs, j, actual_ref) {
......
...@@ -21,53 +21,40 @@ void test_refs_branches_remote__cleanup(void) ...@@ -21,53 +21,40 @@ void test_refs_branches_remote__cleanup(void)
void test_refs_branches_remote__can_get_remote_for_branch(void) void test_refs_branches_remote__can_get_remote_for_branch(void)
{ {
char remotename[1024] = {0}; git_buf remotename = {0};
cl_assert_equal_i(expected_remote_name_length, cl_git_pass(git_branch_remote_name(&remotename, g_repo, remote_tracking_branch_name));
git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name));
cl_assert_equal_i(expected_remote_name_length, cl_assert_equal_s("test", remotename.ptr);
git_branch_remote_name(remotename, expected_remote_name_length, g_repo, git_buf_free(&remotename);
remote_tracking_branch_name));
cl_assert_equal_s("test", remotename);
}
void test_refs_branches_remote__insufficient_buffer_returns_error(void)
{
char remotename[1024] = {0};
cl_assert_equal_i(expected_remote_name_length,
git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name));
cl_git_fail_with(git_branch_remote_name(remotename,
expected_remote_name_length - 1, g_repo, remote_tracking_branch_name),
expected_remote_name_length);
} }
void test_refs_branches_remote__no_matching_remote_returns_error(void) void test_refs_branches_remote__no_matching_remote_returns_error(void)
{ {
const char *unknown = "refs/remotes/nonexistent/master"; const char *unknown = "refs/remotes/nonexistent/master";
git_buf buf;
giterr_clear(); giterr_clear();
cl_git_fail_with(git_branch_remote_name( memset(&buf, 0, sizeof(git_buf));
NULL, 0, g_repo, unknown), GIT_ENOTFOUND); cl_git_fail_with(git_branch_remote_name(&buf, g_repo, unknown), GIT_ENOTFOUND);
cl_assert(giterr_last() != NULL); cl_assert(giterr_last() != NULL);
} }
void test_refs_branches_remote__local_remote_returns_error(void) void test_refs_branches_remote__local_remote_returns_error(void)
{ {
const char *local = "refs/heads/master"; const char *local = "refs/heads/master";
git_buf buf;
giterr_clear(); giterr_clear();
cl_git_fail_with(git_branch_remote_name( memset(&buf, 0, sizeof(git_buf));
NULL, 0, g_repo, local), GIT_ERROR); cl_git_fail_with(git_branch_remote_name(&buf, g_repo, local), GIT_ERROR);
cl_assert(giterr_last() != NULL); cl_assert(giterr_last() != NULL);
} }
void test_refs_branches_remote__ambiguous_remote_returns_error(void) void test_refs_branches_remote__ambiguous_remote_returns_error(void)
{ {
git_remote *remote; git_remote *remote;
git_buf buf;
/* Create the remote */ /* Create the remote */
cl_git_pass(git_remote_create(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2")); cl_git_pass(git_remote_create(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2"));
...@@ -80,7 +67,7 @@ void test_refs_branches_remote__ambiguous_remote_returns_error(void) ...@@ -80,7 +67,7 @@ void test_refs_branches_remote__ambiguous_remote_returns_error(void)
git_remote_free(remote); git_remote_free(remote);
giterr_clear(); giterr_clear();
cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo, memset(&buf, 0, sizeof(git_buf));
remote_tracking_branch_name), GIT_EAMBIGUOUS); cl_git_fail_with(git_branch_remote_name(&buf, g_repo, remote_tracking_branch_name), GIT_EAMBIGUOUS);
cl_assert(giterr_last() != NULL); cl_assert(giterr_last() != NULL);
} }
...@@ -21,7 +21,7 @@ void test_refs_branches_upstreamname__cleanup(void) ...@@ -21,7 +21,7 @@ void test_refs_branches_upstreamname__cleanup(void)
void test_refs_branches_upstreamname__can_retrieve_the_remote_tracking_reference_name_of_a_local_branch(void) void test_refs_branches_upstreamname__can_retrieve_the_remote_tracking_reference_name_of_a_local_branch(void)
{ {
cl_git_pass(git_branch_upstream__name( cl_git_pass(git_branch_upstream_name(
&upstream_name, repo, "refs/heads/master")); &upstream_name, repo, "refs/heads/master"));
cl_assert_equal_s("refs/remotes/test/master", git_buf_cstr(&upstream_name)); cl_assert_equal_s("refs/remotes/test/master", git_buf_cstr(&upstream_name));
...@@ -29,14 +29,8 @@ void test_refs_branches_upstreamname__can_retrieve_the_remote_tracking_reference ...@@ -29,14 +29,8 @@ void test_refs_branches_upstreamname__can_retrieve_the_remote_tracking_reference
void test_refs_branches_upstreamname__can_retrieve_the_local_upstream_reference_name_of_a_local_branch(void) void test_refs_branches_upstreamname__can_retrieve_the_local_upstream_reference_name_of_a_local_branch(void)
{ {
cl_git_pass(git_branch_upstream__name( cl_git_pass(git_branch_upstream_name(
&upstream_name, repo, "refs/heads/track-local")); &upstream_name, repo, "refs/heads/track-local"));
cl_assert_equal_s("refs/heads/master", git_buf_cstr(&upstream_name)); cl_assert_equal_s("refs/heads/master", git_buf_cstr(&upstream_name));
} }
void test_refs_branches_upstreamname__can_return_the_size_of_thelocal_upstream_reference_name_of_a_local_branch(void)
{
cl_assert_equal_i((int)strlen("refs/heads/master") + 1,
git_branch_upstream_name(NULL, 0, repo, "refs/heads/track-local"));
}
...@@ -25,12 +25,13 @@ ...@@ -25,12 +25,13 @@
static void ensure_repository_discover(const char *start_path, static void ensure_repository_discover(const char *start_path,
const char *ceiling_dirs, const char *ceiling_dirs,
const char *expected_path) git_buf *expected_path)
{ {
char found_path[GIT_PATH_MAX]; git_buf found_path = GIT_BUF_INIT;
cl_git_pass(git_repository_discover(found_path, sizeof(found_path), start_path, 0, ceiling_dirs)); cl_git_pass(git_repository_discover(&found_path, start_path, 0, ceiling_dirs));
//across_fs is always 0 as we can't automate the filesystem change tests //across_fs is always 0 as we can't automate the filesystem change tests
cl_assert_equal_s(found_path, expected_path); cl_assert_equal_s(found_path.ptr, expected_path->ptr);
git_buf_free(&found_path);
} }
static void write_file(const char *path, const char *content) static void write_file(const char *path, const char *content)
...@@ -69,42 +70,40 @@ static void append_ceiling_dir(git_buf *ceiling_dirs, const char *path) ...@@ -69,42 +70,40 @@ static void append_ceiling_dir(git_buf *ceiling_dirs, const char *path)
void test_repo_discover__0(void) void test_repo_discover__0(void)
{ {
// test discover // test discover
git_repository *repo; git_repository *repo;
git_buf ceiling_dirs_buf = GIT_BUF_INIT; git_buf ceiling_dirs_buf = GIT_BUF_INIT, repository_path = GIT_BUF_INIT,
sub_repository_path = GIT_BUF_INIT, found_path = GIT_BUF_INIT;
const char *ceiling_dirs; const char *ceiling_dirs;
char repository_path[GIT_PATH_MAX];
char sub_repository_path[GIT_PATH_MAX];
char found_path[GIT_PATH_MAX];
const mode_t mode = 0777; const mode_t mode = 0777;
git_futils_mkdir_r(DISCOVER_FOLDER, NULL, mode); git_futils_mkdir_r(DISCOVER_FOLDER, NULL, mode);
append_ceiling_dir(&ceiling_dirs_buf, TEMP_REPO_FOLDER); append_ceiling_dir(&ceiling_dirs_buf, TEMP_REPO_FOLDER);
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf); ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs)); cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&repository_path, DISCOVER_FOLDER, 0, ceiling_dirs));
cl_git_pass(git_repository_init(&repo, DISCOVER_FOLDER, 1)); cl_git_pass(git_repository_init(&repo, DISCOVER_FOLDER, 1));
cl_git_pass(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs)); cl_git_pass(git_repository_discover(&repository_path, DISCOVER_FOLDER, 0, ceiling_dirs));
git_repository_free(repo); git_repository_free(repo);
cl_git_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0)); cl_git_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0));
cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode)); cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode));
cl_git_pass(git_repository_discover(sub_repository_path, sizeof(sub_repository_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs)); cl_git_pass(git_repository_discover(&sub_repository_path, SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode)); cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode));
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, sub_repository_path); ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path); ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, sub_repository_path); ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, &sub_repository_path);
cl_git_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, NULL, mode)); cl_git_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, NULL, mode));
write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT); write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT);
write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT); write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT);
write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../"); write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../");
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, &repository_path);
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, NULL, mode));
write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:"); write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:");
...@@ -114,29 +113,31 @@ void test_repo_discover__0(void) ...@@ -114,29 +113,31 @@ void test_repo_discover__0(void)
write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n"); write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, NULL, mode));
write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist"); write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist");
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(&found_path, ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs));
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(&found_path, ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs));
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(&found_path, ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(found_path, sizeof(found_path), ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs)); cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs));
append_ceiling_dir(&ceiling_dirs_buf, SUB_REPOSITORY_FOLDER); append_ceiling_dir(&ceiling_dirs_buf, SUB_REPOSITORY_FOLDER);
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf); ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
//this must pass as ceiling_directories cannot predent the current //this must pass as ceiling_directories cannot predent the current
//working directory to be checked //working directory to be checked
cl_git_pass(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs)); cl_git_pass(git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs)); cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs)); cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs)); cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&found_path, SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs));
//.gitfile redirection should not be affected by ceiling directories //.gitfile redirection should not be affected by ceiling directories
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, &repository_path);
cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, NULL, GIT_RMDIR_REMOVE_FILES)); cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, NULL, GIT_RMDIR_REMOVE_FILES));
git_repository_free(repo); git_repository_free(repo);
git_buf_free(&ceiling_dirs_buf); git_buf_free(&ceiling_dirs_buf);
git_buf_free(&repository_path);
git_buf_free(&sub_repository_path);
} }
...@@ -5,48 +5,37 @@ ...@@ -5,48 +5,37 @@
static git_repository *_repo; static git_repository *_repo;
static git_buf _path; static git_buf _path;
static char *_actual; static git_buf _actual;
void test_repo_message__initialize(void) void test_repo_message__initialize(void)
{ {
_repo = cl_git_sandbox_init("testrepo.git"); _repo = cl_git_sandbox_init("testrepo.git");
git_buf_init(&_actual, 0);
} }
void test_repo_message__cleanup(void) void test_repo_message__cleanup(void)
{ {
cl_git_sandbox_cleanup(); cl_git_sandbox_cleanup();
git_buf_free(&_path); git_buf_free(&_path);
git__free(_actual); git_buf_free(&_actual);
_actual = NULL;
} }
void test_repo_message__none(void) void test_repo_message__none(void)
{ {
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(NULL, 0, _repo)); cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&_actual, _repo));
} }
void test_repo_message__message(void) void test_repo_message__message(void)
{ {
const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n"; const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";
ssize_t len;
cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), "MERGE_MSG")); cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), "MERGE_MSG"));
cl_git_mkfile(git_buf_cstr(&_path), expected); cl_git_mkfile(git_buf_cstr(&_path), expected);
len = git_repository_message(NULL, 0, _repo); cl_git_pass(git_repository_message(&_actual, _repo));
cl_assert(len > 0);
_actual = git__malloc(len + 1);
cl_assert(_actual != NULL);
/* Test non truncation */
cl_assert(git_repository_message(_actual, len, _repo) > 0);
cl_assert_equal_s(expected, _actual); cl_assert_equal_s(expected, _actual);
git_buf_free(&_actual);
/* Test truncation and that trailing NUL is inserted */
cl_assert(git_repository_message(_actual, 6, _repo) > 0);
cl_assert_equal_s("Test\n", _actual);
cl_git_pass(p_unlink(git_buf_cstr(&_path))); cl_git_pass(p_unlink(git_buf_cstr(&_path)));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(NULL, 0, _repo)); cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&_actual, _repo));
} }
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