Commit 638c2ca4 by Vicent Marti

Rename 'git_person' to 'git_signature'

The new signature struct is public, and contains information about the
timezone offset. Must be free'd manually by the user.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent 5cccfa89
...@@ -26,11 +26,12 @@ ...@@ -26,11 +26,12 @@
#include "git2/common.h" #include "git2/common.h"
#include "git2/object.h" #include "git2/object.h"
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/signature.h"
#include "common.h" #include "common.h"
#include "commit.h" #include "commit.h"
#include "revwalk.h" #include "revwalk.h"
#include "person.h" #include "signature.h"
#define COMMIT_BASIC_PARSE 0x0 #define COMMIT_BASIC_PARSE 0x0
#define COMMIT_FULL_PARSE 0x1 #define COMMIT_FULL_PARSE 0x1
...@@ -50,8 +51,8 @@ void git_commit__free(git_commit *commit) ...@@ -50,8 +51,8 @@ void git_commit__free(git_commit *commit)
{ {
clear_parents(commit); clear_parents(commit);
git_person__free(commit->author); git_signature_free(commit->author);
git_person__free(commit->committer); git_signature_free(commit->committer);
free(commit->message); free(commit->message);
free(commit->message_short); free(commit->message_short);
...@@ -82,12 +83,12 @@ int git_commit__writeback(git_commit *commit, git_odb_source *src) ...@@ -82,12 +83,12 @@ int git_commit__writeback(git_commit *commit, git_odb_source *src)
if (commit->author == NULL) if (commit->author == NULL)
return GIT_EMISSINGOBJDATA; return GIT_EMISSINGOBJDATA;
git_person__write(src, "author", commit->author); git_signature__write(src, "author", commit->author);
if (commit->committer == NULL) if (commit->committer == NULL)
return GIT_EMISSINGOBJDATA; return GIT_EMISSINGOBJDATA;
git_person__write(src, "committer", commit->committer); git_signature__write(src, "committer", commit->committer);
if (commit->message != NULL) if (commit->message != NULL)
git__source_printf(src, "\n%s", commit->message); git__source_printf(src, "\n%s", commit->message);
...@@ -137,10 +138,10 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int ...@@ -137,10 +138,10 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int
if (parse_flags & COMMIT_FULL_PARSE) { if (parse_flags & COMMIT_FULL_PARSE) {
if (commit->author) if (commit->author)
git_person__free(commit->author); git_signature_free(commit->author);
commit->author = git__malloc(sizeof(git_person)); commit->author = git__malloc(sizeof(git_signature));
if ((error = git_person__parse(commit->author, &buffer, buffer_end, "author ")) < GIT_SUCCESS) if ((error = git_signature__parse(commit->author, &buffer, buffer_end, "author ")) < GIT_SUCCESS)
return error; return error;
} else { } else {
...@@ -152,15 +153,12 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int ...@@ -152,15 +153,12 @@ int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int
/* Always parse the committer; we need the commit time */ /* Always parse the committer; we need the commit time */
if (commit->committer) if (commit->committer)
git_person__free(commit->committer); git_signature_free(commit->committer);
commit->committer = git__malloc(sizeof(git_person)); commit->committer = git__malloc(sizeof(git_signature));
if ((error = git_person__parse(commit->committer, &buffer, buffer_end, "committer ")) < GIT_SUCCESS) if ((error = git_signature__parse(commit->committer, &buffer, buffer_end, "committer ")) < GIT_SUCCESS)
return error; return error;
commit->commit_time = commit->committer->time;
commit->commit_timezone_offset = commit->committer->timezone_offset;
/* parse commit message */ /* parse commit message */
while (buffer <= buffer_end && *buffer == '\n') while (buffer <= buffer_end && *buffer == '\n')
buffer++; buffer++;
...@@ -232,35 +230,21 @@ int git_commit__parse_full(git_commit *commit) ...@@ -232,35 +230,21 @@ int git_commit__parse_full(git_commit *commit)
git_commit__parse_full(commit); git_commit__parse_full(commit);
GIT_COMMIT_GETTER(git_tree *, tree) GIT_COMMIT_GETTER(git_tree *, tree)
GIT_COMMIT_GETTER(git_person *, author) GIT_COMMIT_GETTER(git_signature *, author)
GIT_COMMIT_GETTER(git_person *, committer) GIT_COMMIT_GETTER(git_signature *, committer)
GIT_COMMIT_GETTER(char *, message) GIT_COMMIT_GETTER(char *, message)
GIT_COMMIT_GETTER(char *, message_short) GIT_COMMIT_GETTER(char *, message_short)
time_t git_commit_time(git_commit *commit) time_t git_commit_time(git_commit *commit)
{ {
assert(commit); assert(commit && commit->committer);
return commit->committer->when.time;
if (commit->commit_time)
return commit->commit_time;
if (!commit->object.in_memory)
git_commit__parse_full(commit);
return commit->commit_time;
} }
int git_commit_timezone_offset(git_commit *commit) int git_commit_time_offset(git_commit *commit)
{ {
assert(commit); assert(commit && commit->committer);
return commit->committer->when.offset;
if (commit->commit_timezone_offset)
return commit->commit_timezone_offset;
if (!commit->object.in_memory)
git_commit__parse_full(commit);
return commit->commit_timezone_offset;
} }
unsigned int git_commit_parentcount(git_commit *commit) unsigned int git_commit_parentcount(git_commit *commit)
...@@ -283,25 +267,24 @@ void git_commit_set_tree(git_commit *commit, git_tree *tree) ...@@ -283,25 +267,24 @@ void git_commit_set_tree(git_commit *commit, git_tree *tree)
commit->tree = tree; commit->tree = tree;
} }
void git_commit_set_author(git_commit *commit, const char *name, const char *email, time_t time, int offset) void git_commit_set_author(git_commit *commit, const git_signature *author_sig)
{ {
assert(commit && name && email); assert(commit && author_sig);
commit->object.modified = 1; commit->object.modified = 1;
CHECK_FULL_PARSE(); CHECK_FULL_PARSE();
git_person__free(commit->author); git_signature_free(commit->author);
commit->author = git_person__new(name, email, time, offset); commit->author = git_signature_dup(author_sig);
} }
void git_commit_set_committer(git_commit *commit, const char *name, const char *email, time_t time, int offset) void git_commit_set_committer(git_commit *commit, const git_signature *committer_sig)
{ {
assert(commit && name && email); assert(commit && committer_sig);
commit->object.modified = 1; commit->object.modified = 1;
CHECK_FULL_PARSE(); CHECK_FULL_PARSE();
git_person__free(commit->committer); git_signature_free(commit->committer);
commit->committer = git_person__new(name, email, time, offset); commit->committer = git_signature_dup(committer_sig);
commit->commit_time = time;
} }
void git_commit_set_message(git_commit *commit, const char *message) void git_commit_set_message(git_commit *commit, const char *message)
......
...@@ -11,14 +11,11 @@ ...@@ -11,14 +11,11 @@
struct git_commit { struct git_commit {
git_object object; git_object object;
time_t commit_time;
int commit_timezone_offset;
git_vector parents; git_vector parents;
git_tree *tree; git_tree *tree;
git_person *author; git_signature *author;
git_person *committer; git_signature *committer;
char *message; char *message;
char *message_short; char *message_short;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "git2/types.h" #include "git2/types.h"
#include "git2/oid.h" #include "git2/oid.h"
#include "git2/signature.h"
#include "git2/odb.h" #include "git2/odb.h"
#include "git2/repository.h" #include "git2/repository.h"
......
...@@ -104,14 +104,14 @@ GIT_EXTERN(int) git_commit_timezone_offset(git_commit *commit); ...@@ -104,14 +104,14 @@ GIT_EXTERN(int) git_commit_timezone_offset(git_commit *commit);
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return the committer of a commit * @return the committer of a commit
*/ */
GIT_EXTERN(const git_person *) git_commit_committer(git_commit *commit); GIT_EXTERN(const git_signature *) git_commit_committer(git_commit *commit);
/** /**
* Get the author of a commit. * Get the author of a commit.
* @param commit a previously loaded commit. * @param commit a previously loaded commit.
* @return the author of a commit * @return the author of a commit
*/ */
GIT_EXTERN(const git_person *) git_commit_author(git_commit *commit); GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit);
/** /**
* Get the tree pointed to by a commit. * Get the tree pointed to by a commit.
...@@ -154,22 +154,16 @@ GIT_EXTERN(void) git_commit_set_message(git_commit *commit, const char *message) ...@@ -154,22 +154,16 @@ GIT_EXTERN(void) git_commit_set_message(git_commit *commit, const char *message)
/** /**
* Set the committer of a commit * Set the committer of a commit
* @param commit the commit object * @param commit the commit object
* @param name name of the new committer * @param author_sig signature of the committer
* @param email email of the new committer
* @param time time when the committer committed the commit
* @param offset committer positive or negative timezone offset, in minutes from UTC
*/ */
GIT_EXTERN(void) git_commit_set_committer(git_commit *commit, const char *name, const char *email, time_t time, int offset); GIT_EXTERN(void) git_commit_set_committer(git_commit *commit, const git_signature *committer_sig);
/** /**
* Set the author of a commit * Set the author of a commit
* @param commit the commit object * @param commit the commit object
* @param name name of the new author * @param author_sig signature of the author
* @param email email of the new author
* @param time time when the author created the commit
* @param offset author positive or negative timezone offset, in minutes from UTC
*/ */
GIT_EXTERN(void) git_commit_set_author(git_commit *commit, const char *name, const char *email, time_t time, int offset); GIT_EXTERN(void) git_commit_set_author(git_commit *commit, const git_signature *author_sig);
/** /**
* Set the tree which is pointed to by a commit * Set the tree which is pointed to by a commit
......
...@@ -134,17 +134,7 @@ ...@@ -134,17 +134,7 @@
/** The index file is not backed up by an existing repository */ /** The index file is not backed up by an existing repository */
#define GIT_EBAREINDEX (GIT_ERROR -14) #define GIT_EBAREINDEX (GIT_ERROR -14)
GIT_BEGIN_DECL GIT_BEGIN_DECL
/** Parsed representation of a person */
typedef struct git_person git_person;
const char *git_person_name(git_person *person);
const char *git_person_email(git_person *person);
time_t git_person_time(git_person *person);
int git_person_timezone_offset(git_person *person);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDE_git_signature_h__
#define INCLUDE_git_signature_h__
#include "common.h"
#include "types.h"
/**
* @file git2/signature.h
* @brief Git signature creation
* @defgroup git_signature Git signature creation
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Create a new action signature. The signature must be freed
* manually or using git_signature_free
*
* @name name of the person
* @email email of the person
* @time time when the action happened
* @offset timezone offset in minutes for the time
* @return the new sig, NULl on out of memory
*/
GIT_EXTERN(git_signature *) git_signature_new(const char *name, const char *email, time_t time, int offset);
/**
* Create a copy of an existing signature.
*
* All internal strings are also duplicated.
* @sig signature to duplicated
* @return a copy of sig, NULL on out of memory
*/
GIT_EXTERN(git_signature *) git_signature_dup(const git_signature *sig);
/**
* Free an existing signature
*
* @sig signature to free
*/
GIT_EXTERN(void) git_signature_free(git_signature *sig);
/** @} */
GIT_END_DECL
#endif
...@@ -96,7 +96,7 @@ GIT_EXTERN(const char *) git_tag_name(git_tag *t); ...@@ -96,7 +96,7 @@ GIT_EXTERN(const char *) git_tag_name(git_tag *t);
* @param tag a previously loaded tag. * @param tag a previously loaded tag.
* @return reference to the tag's author * @return reference to the tag's author
*/ */
GIT_EXTERN(const git_person *) git_tag_tagger(git_tag *t); GIT_EXTERN(const git_signature *) git_tag_tagger(git_tag *t);
/** /**
* Get the message of a tag * Get the message of a tag
...@@ -122,12 +122,9 @@ GIT_EXTERN(void) git_tag_set_name(git_tag *tag, const char *name); ...@@ -122,12 +122,9 @@ GIT_EXTERN(void) git_tag_set_name(git_tag *tag, const char *name);
/** /**
* Set the tagger of a tag * Set the tagger of a tag
* @param tag The tag to modify * @param tag The tag to modify
* @param name the name of the new tagger * @param tagger_sig signature of the tagging action
* @param email the email of the new tagger
* @param time the time when the tag was created
* @param offset tagger positive or negative timezone offset, in minutes from UTC
*/ */
GIT_EXTERN(void) git_tag_set_tagger(git_tag *tag, const char *name, const char *email, time_t time, int offset); GIT_EXTERN(void) git_tag_set_tagger(git_tag *tag, const git_signature *tagger_sig);
/** /**
* Set the message of a tag * Set the message of a tag
......
...@@ -82,6 +82,19 @@ typedef struct git_tree git_tree; ...@@ -82,6 +82,19 @@ typedef struct git_tree git_tree;
/** Memory representation of an index file. */ /** Memory representation of an index file. */
typedef struct git_index git_index; typedef struct git_index git_index;
/** Time in a signature */
typedef struct git_time {
time_t time; /** time in seconds from epoch */
int offset; /** timezone offset, in minutes */
} git_time;
/** An action signature (e.g. for committers, taggers, etc) */
typedef struct git_signature {
char *name; /** full name of the author */
char *email; /** email of the author */
git_time when; /** time when the action happened */
} git_signature;
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
#ifndef INCLUDE_person_h__
#define INCLUDE_person_h__
#include "git2/common.h"
#include "repository.h"
#include <time.h>
/** Parsed representation of a person */
struct git_person {
char *name; /**< Full name */
char *email; /**< Email address */
time_t time; /**< Time when this person committed the change */
int timezone_offset; /**< Time zone offset in minutes. Can be either positive or negative. */
};
void git_person__free(git_person *person);
git_person *git_person__new(const char *name, const char *email, time_t time, int offset);
int git_person__parse(git_person *person, char **buffer_out, const char *buffer_end, const char *header);
int git_person__write(git_odb_source *src, const char *header, const git_person *person);
#endif
...@@ -388,8 +388,8 @@ void git_revwalk_list_timesort(git_revwalk_list *list) ...@@ -388,8 +388,8 @@ void git_revwalk_list_timesort(git_revwalk_list *list)
e = q, q = q->next, q_size--; e = q, q = q->next, q_size--;
else if (q_size == 0 || q == NULL || else if (q_size == 0 || q == NULL ||
p->walk_commit->commit_object->commit_time >= p->walk_commit->commit_object->committer->when.time >=
q->walk_commit->commit_object->commit_time) q->walk_commit->commit_object->committer->when.time)
e = p, p = p->next, p_size--; e = p, p = p->next, p_size--;
else else
......
...@@ -24,31 +24,37 @@ ...@@ -24,31 +24,37 @@
*/ */
#include "common.h" #include "common.h"
#include "person.h" #include "signature.h"
#include "repository.h" #include "repository.h"
#include "git2/common.h" #include "git2/common.h"
void git_person__free(git_person *person) void git_signature_free(git_signature *sig)
{ {
if (person == NULL) if (sig == NULL)
return; return;
free(person->name); free(sig->name);
free(person->email); free(sig->email);
free(person); free(sig);
} }
git_person *git_person__new(const char *name, const char *email, time_t time, int offset) git_signature *git_signature_new(const char *name, const char *email, time_t time, int offset)
{ {
git_person *p; git_signature *p = NULL;
if ((p = git__malloc(sizeof(git_person))) == NULL) if ((p = git__malloc(sizeof(git_signature))) == NULL)
goto cleanup; goto cleanup;
p->name = git__strdup(name); p->name = git__strdup(name);
if (p->name == NULL)
goto cleanup;
p->email = git__strdup(email); p->email = git__strdup(email);
p->time = time; if (p->email == NULL)
p->timezone_offset = offset; goto cleanup;
p->when.time = time;
p->when.offset = offset;
if (p->name == NULL || p->email == NULL) if (p->name == NULL || p->email == NULL)
goto cleanup; goto cleanup;
...@@ -56,31 +62,17 @@ git_person *git_person__new(const char *name, const char *email, time_t time, in ...@@ -56,31 +62,17 @@ git_person *git_person__new(const char *name, const char *email, time_t time, in
return p; return p;
cleanup: cleanup:
git_person__free(p); git_signature_free(p);
return NULL; return NULL;
} }
const char *git_person_name(git_person *person) git_signature *git_signature_dup(const git_signature *sig)
{ {
return person->name; return git_signature_new(sig->name, sig->email, sig->when.time, sig->when.offset);
} }
const char *git_person_email(git_person *person)
{
return person->email;
}
time_t git_person_time(git_person *person) static int parse_timezone_offset(const char *buffer, int *offset_out)
{
return person->time;
}
int git_person_timezone_offset(git_person *person)
{
return person->timezone_offset;
}
int git_person__parse_timezone_offset(const char *buffer, int *offset_out)
{ {
int offset, dec_offset; int offset, dec_offset;
int mins, hours; int mins, hours;
...@@ -90,8 +82,7 @@ int git_person__parse_timezone_offset(const char *buffer, int *offset_out) ...@@ -90,8 +82,7 @@ int git_person__parse_timezone_offset(const char *buffer, int *offset_out)
offset_start = buffer + 1; offset_start = buffer + 1;
if (*offset_start == '\n') if (*offset_start == '\n') {
{
*offset_out = 0; *offset_out = 0;
return GIT_SUCCESS; return GIT_SUCCESS;
} }
...@@ -107,18 +98,16 @@ int git_person__parse_timezone_offset(const char *buffer, int *offset_out) ...@@ -107,18 +98,16 @@ int git_person__parse_timezone_offset(const char *buffer, int *offset_out)
hours = dec_offset / 100; hours = dec_offset / 100;
mins = dec_offset % 100; mins = dec_offset % 100;
if (hours > 14) // see http://www.worldtimezone.com/faq.html if (hours > 14) // see http://www.worldtimezone.com/faq.html
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
if (mins > 59) if (mins > 59)
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
offset = (hours * 60) + mins; offset = (hours * 60) + mins;
if (offset_start[0] == '-') if (offset_start[0] == '-')
{
offset *= -1; offset *= -1;
}
*offset_out = offset; *offset_out = offset;
...@@ -126,7 +115,7 @@ int git_person__parse_timezone_offset(const char *buffer, int *offset_out) ...@@ -126,7 +115,7 @@ int git_person__parse_timezone_offset(const char *buffer, int *offset_out)
} }
int git_person__parse(git_person *person, char **buffer_out, int git_signature__parse(git_signature *sig, char **buffer_out,
const char *buffer_end, const char *header) const char *buffer_end, const char *header)
{ {
const size_t header_len = strlen(header); const size_t header_len = strlen(header);
...@@ -136,7 +125,7 @@ int git_person__parse(git_person *person, char **buffer_out, ...@@ -136,7 +125,7 @@ int git_person__parse(git_person *person, char **buffer_out,
char *line_end, *name_end, *email_end; char *line_end, *name_end, *email_end;
int offset = 0; int offset = 0;
memset(person, 0x0, sizeof(git_person)); memset(sig, 0x0, sizeof(git_signature));
line_end = memchr(buffer, '\n', buffer_end - buffer); line_end = memchr(buffer, '\n', buffer_end - buffer);
if (!line_end) if (!line_end)
...@@ -155,9 +144,9 @@ int git_person__parse(git_person *person, char **buffer_out, ...@@ -155,9 +144,9 @@ int git_person__parse(git_person *person, char **buffer_out,
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
name_length = name_end - buffer - 1; name_length = name_end - buffer - 1;
person->name = git__malloc(name_length + 1); sig->name = git__malloc(name_length + 1);
memcpy(person->name, buffer, name_length); memcpy(sig->name, buffer, name_length);
person->name[name_length] = 0; sig->name[name_length] = 0;
buffer = name_end + 1; buffer = name_end + 1;
if (buffer >= line_end) if (buffer >= line_end)
...@@ -168,35 +157,35 @@ int git_person__parse(git_person *person, char **buffer_out, ...@@ -168,35 +157,35 @@ int git_person__parse(git_person *person, char **buffer_out,
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
email_length = email_end - buffer; email_length = email_end - buffer;
person->email = git__malloc(email_length + 1); sig->email = git__malloc(email_length + 1);
memcpy(person->email, buffer, email_length); memcpy(sig->email, buffer, email_length);
person->email[email_length] = 0; sig->email[email_length] = 0;
buffer = email_end + 1; buffer = email_end + 1;
if (buffer >= line_end) if (buffer >= line_end)
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
person->time = strtol(buffer, &buffer, 10); sig->when.time = strtol(buffer, &buffer, 10);
if (person->time == 0) if (sig->when.time == 0)
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
if (git_person__parse_timezone_offset(buffer, &offset) < GIT_SUCCESS) if (parse_timezone_offset(buffer, &offset) < GIT_SUCCESS)
return GIT_EOBJCORRUPTED; return GIT_EOBJCORRUPTED;
person->timezone_offset = offset; sig->when.offset = offset;
*buffer_out = (line_end + 1); *buffer_out = (line_end + 1);
return GIT_SUCCESS; return GIT_SUCCESS;
} }
int git_person__write(git_odb_source *src, const char *header, const git_person *person) int git_signature__write(git_odb_source *src, const char *header, const git_signature *sig)
{ {
char *sign; char sign;
int offset, hours, mins; int offset, hours, mins;
offset = person->timezone_offset; offset = sig->when.offset;
sign = (person->timezone_offset < 0) ? "-" : "+"; sign = (sig->when.offset < 0) ? '-' : '+';
if (offset < 0) if (offset < 0)
offset = -offset; offset = -offset;
...@@ -204,7 +193,7 @@ int git_person__write(git_odb_source *src, const char *header, const git_person ...@@ -204,7 +193,7 @@ int git_person__write(git_odb_source *src, const char *header, const git_person
hours = offset / 60; hours = offset / 60;
mins = offset % 60; mins = offset % 60;
return git__source_printf(src, "%s %s <%s> %u %s%02d%02d\n", header, person->name, person->email, person->time, sign, hours, mins); return git__source_printf(src, "%s %s <%s> %u %c%02d%02d\n", header, sig->name, sig->email, sig->when.time, sign, hours, mins);
} }
#ifndef INCLUDE_signature_h__
#define INCLUDE_signature_h__
#include "git2/common.h"
#include "git2/signature.h"
#include "repository.h"
#include <time.h>
int git_signature__parse(git_signature *sig, char **buffer_out, const char *buffer_end, const char *header);
int git_signature__write(git_odb_source *src, const char *header, const git_signature *sig);
#endif
...@@ -26,14 +26,15 @@ ...@@ -26,14 +26,15 @@
#include "common.h" #include "common.h"
#include "commit.h" #include "commit.h"
#include "tag.h" #include "tag.h"
#include "person.h" #include "signature.h"
#include "revwalk.h" #include "revwalk.h"
#include "git2/object.h" #include "git2/object.h"
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/signature.h"
void git_tag__free(git_tag *tag) void git_tag__free(git_tag *tag)
{ {
git_person__free(tag->tagger); git_signature_free(tag->tagger);
free(tag->message); free(tag->message);
free(tag->tag_name); free(tag->tag_name);
free(tag); free(tag);
...@@ -92,18 +93,18 @@ void git_tag_set_name(git_tag *tag, const char *name) ...@@ -92,18 +93,18 @@ void git_tag_set_name(git_tag *tag, const char *name)
tag->tag_name = git__strdup(name); tag->tag_name = git__strdup(name);
} }
const git_person *git_tag_tagger(git_tag *t) const git_signature *git_tag_tagger(git_tag *t)
{ {
return t->tagger; return t->tagger;
} }
void git_tag_set_tagger(git_tag *tag, const char *name, const char *email, time_t time, int offset) void git_tag_set_tagger(git_tag *tag, const git_signature *tagger_sig)
{ {
assert(tag && name && email); assert(tag && tagger_sig);
tag->object.modified = 1; tag->object.modified = 1;
git_person__free(tag->tagger); git_signature_free(tag->tagger);
tag->tagger = git_person__new(name, email, time, offset); tag->tagger = git_signature_dup(tagger_sig);
} }
const char *git_tag_message(git_tag *t) const char *git_tag_message(git_tag *t)
...@@ -190,11 +191,11 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end) ...@@ -190,11 +191,11 @@ static int parse_tag_buffer(git_tag *tag, char *buffer, const char *buffer_end)
buffer = search + 1; buffer = search + 1;
if (tag->tagger != NULL) if (tag->tagger != NULL)
git_person__free(tag->tagger); git_signature_free(tag->tagger);
tag->tagger = git__malloc(sizeof(git_person)); tag->tagger = git__malloc(sizeof(git_signature));
if ((error = git_person__parse(tag->tagger, &buffer, buffer_end, "tagger ")) != 0) if ((error = git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ")) != 0)
return error; return error;
text_len = buffer_end - ++buffer; text_len = buffer_end - ++buffer;
...@@ -217,7 +218,7 @@ int git_tag__writeback(git_tag *tag, git_odb_source *src) ...@@ -217,7 +218,7 @@ int git_tag__writeback(git_tag *tag, git_odb_source *src)
git__write_oid(src, "object", git_object_id(tag->target)); git__write_oid(src, "object", git_object_id(tag->target));
git__source_printf(src, "type %s\n", git_object_type2string(tag->type)); git__source_printf(src, "type %s\n", git_object_type2string(tag->type));
git__source_printf(src, "tag %s\n", tag->tag_name); git__source_printf(src, "tag %s\n", tag->tag_name);
git_person__write(src, "tagger", tag->tagger); git_signature__write(src, "tagger", tag->tagger);
if (tag->message != NULL) if (tag->message != NULL)
git__source_printf(src, "\n%s", tag->message); git__source_printf(src, "\n%s", tag->message);
......
...@@ -10,7 +10,7 @@ struct git_tag { ...@@ -10,7 +10,7 @@ struct git_tag {
git_object *target; git_object *target;
git_otype type; git_otype type;
char *tag_name; char *tag_name;
git_person *tagger; git_signature *tagger;
char *message; char *message;
}; };
......
#include "test_lib.h" #include "test_lib.h"
#include "test_helpers.h" #include "test_helpers.h"
#include "commit.h" #include "commit.h"
#include "person.h" #include "signature.h"
#include <git2/odb.h> #include <git2/odb.h>
#include <git2/commit.h> #include <git2/commit.h>
#include <git2/revwalk.h> #include <git2/revwalk.h>
...@@ -129,29 +129,29 @@ BEGIN_TEST(parse_oid_test) ...@@ -129,29 +129,29 @@ BEGIN_TEST(parse_oid_test)
END_TEST END_TEST
BEGIN_TEST(parse_person_test) BEGIN_TEST(parse_sig_test)
#define TEST_PERSON_PASS(_string, _header, _name, _email, _time, _offset) { \ #define TEST_SIGNATURE_PASS(_string, _header, _name, _email, _time, _offset) { \
char *ptr = _string; \ char *ptr = _string; \
size_t len = strlen(_string);\ size_t len = strlen(_string);\
git_person person = {NULL, NULL, 0}; \ git_signature person = {NULL, NULL, {0, 0}}; \
must_pass(git_person__parse(&person, &ptr, ptr + len, _header));\ must_pass(git_signature__parse(&person, &ptr, ptr + len, _header));\
must_be_true(strcmp(_name, person.name) == 0);\ must_be_true(strcmp(_name, person.name) == 0);\
must_be_true(strcmp(_email, person.email) == 0);\ must_be_true(strcmp(_email, person.email) == 0);\
must_be_true(_time == person.time);\ must_be_true(_time == person.when.time);\
must_be_true(_offset == person.timezone_offset);\ must_be_true(_offset == person.when.offset);\
free(person.name); free(person.email);\ free(person.name); free(person.email);\
} }
#define TEST_PERSON_FAIL(_string, _header) { \ #define TEST_SIGNATURE_FAIL(_string, _header) { \
char *ptr = _string; \ char *ptr = _string; \
size_t len = strlen(_string);\ size_t len = strlen(_string);\
git_person person = {NULL, NULL, 0}; \ git_signature person = {NULL, NULL, {0, 0}}; \
must_fail(git_person__parse(&person, &ptr, ptr + len, _header));\ must_fail(git_signature__parse(&person, &ptr, ptr + len, _header));\
free(person.name); free(person.email);\ free(person.name); free(person.email);\
} }
TEST_PERSON_PASS( TEST_SIGNATURE_PASS(
"author Vicent Marti <tanoku@gmail.com> 12345 \n", "author Vicent Marti <tanoku@gmail.com> 12345 \n",
"author ", "author ",
"Vicent Marti", "Vicent Marti",
...@@ -159,7 +159,7 @@ BEGIN_TEST(parse_person_test) ...@@ -159,7 +159,7 @@ BEGIN_TEST(parse_person_test)
12345, 12345,
0); 0);
TEST_PERSON_PASS( TEST_SIGNATURE_PASS(
"author Vicent Marti <> 12345 \n", "author Vicent Marti <> 12345 \n",
"author ", "author ",
"Vicent Marti", "Vicent Marti",
...@@ -167,7 +167,7 @@ BEGIN_TEST(parse_person_test) ...@@ -167,7 +167,7 @@ BEGIN_TEST(parse_person_test)
12345, 12345,
0); 0);
TEST_PERSON_PASS( TEST_SIGNATURE_PASS(
"author Vicent Marti <tanoku@gmail.com> 231301 +1020\n", "author Vicent Marti <tanoku@gmail.com> 231301 +1020\n",
"author ", "author ",
"Vicent Marti", "Vicent Marti",
...@@ -175,7 +175,7 @@ BEGIN_TEST(parse_person_test) ...@@ -175,7 +175,7 @@ BEGIN_TEST(parse_person_test)
231301, 231301,
620); 620);
TEST_PERSON_PASS( TEST_SIGNATURE_PASS(
"author Vicent Marti with an outrageously long name \ "author Vicent Marti with an outrageously long name \
which will probably overflow the buffer <tanoku@gmail.com> 12345 \n", which will probably overflow the buffer <tanoku@gmail.com> 12345 \n",
"author ", "author ",
...@@ -185,7 +185,7 @@ BEGIN_TEST(parse_person_test) ...@@ -185,7 +185,7 @@ BEGIN_TEST(parse_person_test)
12345, 12345,
0); 0);
TEST_PERSON_PASS( TEST_SIGNATURE_PASS(
"author Vicent Marti <tanokuwithaveryveryverylongemail\ "author Vicent Marti <tanokuwithaveryveryverylongemail\
whichwillprobablyvoverflowtheemailbuffer@gmail.com> 12345 \n", whichwillprobablyvoverflowtheemailbuffer@gmail.com> 12345 \n",
"author ", "author ",
...@@ -195,7 +195,7 @@ BEGIN_TEST(parse_person_test) ...@@ -195,7 +195,7 @@ BEGIN_TEST(parse_person_test)
12345, 12345,
0); 0);
TEST_PERSON_PASS( TEST_SIGNATURE_PASS(
"committer Vicent Marti <tanoku@gmail.com> 123456 +0000 \n", "committer Vicent Marti <tanoku@gmail.com> 123456 +0000 \n",
"committer ", "committer ",
"Vicent Marti", "Vicent Marti",
...@@ -203,7 +203,7 @@ BEGIN_TEST(parse_person_test) ...@@ -203,7 +203,7 @@ BEGIN_TEST(parse_person_test)
123456, 123456,
0); 0);
TEST_PERSON_PASS( TEST_SIGNATURE_PASS(
"committer Vicent Marti <tanoku@gmail.com> 123456 +0100 \n", "committer Vicent Marti <tanoku@gmail.com> 123456 +0100 \n",
"committer ", "committer ",
"Vicent Marti", "Vicent Marti",
...@@ -211,7 +211,7 @@ BEGIN_TEST(parse_person_test) ...@@ -211,7 +211,7 @@ BEGIN_TEST(parse_person_test)
123456, 123456,
60); 60);
TEST_PERSON_PASS( TEST_SIGNATURE_PASS(
"committer Vicent Marti <tanoku@gmail.com> 123456 -0100 \n", "committer Vicent Marti <tanoku@gmail.com> 123456 -0100 \n",
"committer ", "committer ",
"Vicent Marti", "Vicent Marti",
...@@ -219,44 +219,44 @@ BEGIN_TEST(parse_person_test) ...@@ -219,44 +219,44 @@ BEGIN_TEST(parse_person_test)
123456, 123456,
-60); -60);
TEST_PERSON_FAIL( TEST_SIGNATURE_FAIL(
"committer Vicent Marti <tanoku@gmail.com> 123456 -1500 \n", "committer Vicent Marti <tanoku@gmail.com> 123456 -1500 \n",
"committer "); "committer ");
TEST_PERSON_FAIL( TEST_SIGNATURE_FAIL(
"committer Vicent Marti <tanoku@gmail.com> 123456 +0163 \n", "committer Vicent Marti <tanoku@gmail.com> 123456 +0163 \n",
"committer "); "committer ");
TEST_PERSON_FAIL( TEST_SIGNATURE_FAIL(
"author Vicent Marti <tanoku@gmail.com> 12345 \n", "author Vicent Marti <tanoku@gmail.com> 12345 \n",
"author "); "author ");
TEST_PERSON_FAIL( TEST_SIGNATURE_FAIL(
"author Vicent Marti <tanoku@gmail.com> 12345 \n", "author Vicent Marti <tanoku@gmail.com> 12345 \n",
"committer "); "committer ");
TEST_PERSON_FAIL( TEST_SIGNATURE_FAIL(
"author Vicent Marti 12345 \n", "author Vicent Marti 12345 \n",
"author "); "author ");
TEST_PERSON_FAIL( TEST_SIGNATURE_FAIL(
"author Vicent Marti <broken@email 12345 \n", "author Vicent Marti <broken@email 12345 \n",
"author "); "author ");
TEST_PERSON_FAIL( TEST_SIGNATURE_FAIL(
"author Vicent Marti <tanoku@gmail.com> notime \n", "author Vicent Marti <tanoku@gmail.com> notime \n",
"author "); "author ");
TEST_PERSON_FAIL( TEST_SIGNATURE_FAIL(
"author Vicent Marti <tanoku@gmail.com>\n", "author Vicent Marti <tanoku@gmail.com>\n",
"author "); "author ");
TEST_PERSON_FAIL( TEST_SIGNATURE_FAIL(
"author ", "author ",
"author "); "author ");
#undef TEST_PERSON_PASS #undef TEST_SIGNATURE_PASS
#undef TEST_PERSON_FAIL #undef TEST_SIGNATURE_FAIL
END_TEST END_TEST
......
#include "test_lib.h" #include "test_lib.h"
#include "test_helpers.h" #include "test_helpers.h"
#include "commit.h" #include "commit.h"
#include "person.h" #include "signature.h"
#include <git2/odb.h> #include <git2/odb.h>
#include <git2/commit.h> #include <git2/commit.h>
...@@ -28,7 +28,7 @@ BEGIN_TEST(query_details_test) ...@@ -28,7 +28,7 @@ BEGIN_TEST(query_details_test)
git_oid id; git_oid id;
git_commit *commit; git_commit *commit;
const git_person *author, *committer; const git_signature *author, *committer;
const char *message, *message_short; const char *message, *message_short;
time_t commit_time; time_t commit_time;
unsigned int parents, p; unsigned int parents, p;
......
#include "test_lib.h" #include "test_lib.h"
#include "test_helpers.h" #include "test_helpers.h"
#include "commit.h" #include "commit.h"
#include "person.h" #include "signature.h"
#include <git2/odb.h> #include <git2/odb.h>
#include <git2/commit.h> #include <git2/commit.h>
#include <git2/revwalk.h> #include <git2/revwalk.h>
#include <git2/signature.h>
static const char *commit_ids[] = { static const char *commit_ids[] = {
"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
...@@ -27,7 +28,7 @@ BEGIN_TEST(writenew_test) ...@@ -27,7 +28,7 @@ BEGIN_TEST(writenew_test)
git_commit *commit, *parent; git_commit *commit, *parent;
git_tree *tree; git_tree *tree;
git_oid id; git_oid id;
const git_person *author, *committer; const git_signature *author, *committer;
/* char hex_oid[41]; */ /* char hex_oid[41]; */
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
...@@ -42,26 +43,33 @@ BEGIN_TEST(writenew_test) ...@@ -42,26 +43,33 @@ BEGIN_TEST(writenew_test)
git_commit_add_parent(commit, parent); git_commit_add_parent(commit, parent);
/* Set other attributes */ /* Set other attributes */
git_commit_set_committer(commit, COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60); committer = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60);
git_commit_set_author(commit, COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90); must_be_true(committer != NULL);
author = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90);
must_be_true(author != NULL);
git_commit_set_committer(commit, committer);
git_commit_set_author(commit, author);
git_commit_set_message(commit, COMMIT_MESSAGE); git_commit_set_message(commit, COMMIT_MESSAGE);
git_signature_free((git_signature *)committer);
git_signature_free((git_signature *)author);
/* Check attributes were set correctly */ /* Check attributes were set correctly */
author = git_commit_author(commit); author = git_commit_author(commit);
must_be_true(author != NULL); must_be_true(author != NULL);
must_be_true(strcmp(author->name, COMMITTER_NAME) == 0); must_be_true(strcmp(author->name, COMMITTER_NAME) == 0);
must_be_true(strcmp(author->email, COMMITTER_EMAIL) == 0); must_be_true(strcmp(author->email, COMMITTER_EMAIL) == 0);
must_be_true(author->time == 987654321); must_be_true(author->when.time == 987654321);
must_be_true(author->time_offset == 90); must_be_true(author->when.offset == 90);
committer = git_commit_committer(commit); committer = git_commit_committer(commit);
must_be_true(committer != NULL); must_be_true(committer != NULL);
must_be_true(strcmp(committer->name, COMMITTER_NAME) == 0); must_be_true(strcmp(committer->name, COMMITTER_NAME) == 0);
must_be_true(strcmp(committer->email, COMMITTER_EMAIL) == 0); must_be_true(strcmp(committer->email, COMMITTER_EMAIL) == 0);
must_be_true(committer->time == 123456789); must_be_true(committer->when.time == 123456789);
must_be_true(committer->time_offset == 60); must_be_true(committer->when.offset == 60);
must_be_true(git_commit_time(commit) == 123456789);
must_be_true(git_commit_time_offset(commit) == 60);
must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0); must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0);
...@@ -77,18 +85,8 @@ BEGIN_TEST(writenew_test) ...@@ -77,18 +85,8 @@ BEGIN_TEST(writenew_test)
/* Write to disk */ /* Write to disk */
must_pass(git_object_write((git_object *)commit)); must_pass(git_object_write((git_object *)commit));
/* Show new SHA1 */
/*
git_oid_fmt(hex_oid, git_commit_id(commit));
hex_oid[40] = 0;
printf("Written new commit, SHA1: %s\n", hex_oid);
*/
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
//git_person_free(&author);
//git_person_free(&committer);
git_repository_free(repo); git_repository_free(repo);
END_TEST END_TEST
...@@ -107,12 +105,6 @@ BEGIN_TEST(writeback_test) ...@@ -107,12 +105,6 @@ BEGIN_TEST(writeback_test)
message = git_commit_message(commit); message = git_commit_message(commit);
/*
git_oid_fmt(hex_oid, git_commit_id(commit));
hex_oid[40] = 0;
printf("Old SHA1: %s\n", hex_oid);
*/
git_commit_set_message(commit, "This is a new test message. Cool!\n"); git_commit_set_message(commit, "This is a new test message. Cool!\n");
git_oid_mkstr(&id, commit_ids[4]); git_oid_mkstr(&id, commit_ids[4]);
...@@ -122,12 +114,6 @@ BEGIN_TEST(writeback_test) ...@@ -122,12 +114,6 @@ BEGIN_TEST(writeback_test)
must_pass(git_object_write((git_object *)commit)); must_pass(git_object_write((git_object *)commit));
/*
git_oid_fmt(hex_oid, git_commit_id(commit));
hex_oid[40] = 0;
printf("New SHA1: %s\n", hex_oid);
*/
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
git_repository_free(repo); git_repository_free(repo);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "revwalk.h" #include "revwalk.h"
#include <git2/odb.h> #include <git2/odb.h>
#include <git2/commit.h> #include <git2/commit.h>
#include <git2/signature.h>
BEGIN_TEST(list_timesort_test) BEGIN_TEST(list_timesort_test)
...@@ -15,12 +16,13 @@ BEGIN_TEST(list_timesort_test) ...@@ -15,12 +16,13 @@ BEGIN_TEST(list_timesort_test)
#define TEST_SORTED() \ #define TEST_SORTED() \
previous_time = INT_MAX;\ previous_time = INT_MAX;\
for (n = list.head; n != NULL; n = n->next) {\ for (n = list.head; n != NULL; n = n->next) {\
must_be_true(n->walk_commit->commit_object->commit_time <= previous_time);\ must_be_true(n->walk_commit->commit_object->committer->when.time <= previous_time);\
previous_time = n->walk_commit->commit_object->commit_time;\ previous_time = n->walk_commit->commit_object->committer->when.time;\
} }
#define CLEAR_LIST() \ #define CLEAR_LIST() \
for (n = list.head; n != NULL; n = n->next) {\ for (n = list.head; n != NULL; n = n->next) {\
git_signature_free(n->walk_commit->commit_object->committer);\
free(n->walk_commit->commit_object);\ free(n->walk_commit->commit_object);\
free(n->walk_commit);\ free(n->walk_commit);\
}\ }\
...@@ -37,7 +39,7 @@ BEGIN_TEST(list_timesort_test) ...@@ -37,7 +39,7 @@ BEGIN_TEST(list_timesort_test)
git_commit *c = git__malloc(sizeof(git_commit)); git_commit *c = git__malloc(sizeof(git_commit));
git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit)); git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit));
c->commit_time = (time_t)rand(); c->committer = git_signature_new("", "", (time_t)rand(), 0);
rc->commit_object = c; rc->commit_object = c;
git_revwalk_list_push_back(&list, rc); git_revwalk_list_push_back(&list, rc);
...@@ -53,7 +55,7 @@ BEGIN_TEST(list_timesort_test) ...@@ -53,7 +55,7 @@ BEGIN_TEST(list_timesort_test)
git_commit *c = git__malloc(sizeof(git_commit)); git_commit *c = git__malloc(sizeof(git_commit));
git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit)); git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit));
c->commit_time = 0; c->committer = git_signature_new("", "", 0, 0);
rc->commit_object = c; rc->commit_object = c;
git_revwalk_list_push_back(&list, rc); git_revwalk_list_push_back(&list, rc);
......
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