Skip to content

Commit

Permalink
Rename 'git_person' to 'git_signature'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vmg committed Dec 18, 2010
1 parent 5cccfa8 commit 638c2ca
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 231 deletions.
71 changes: 27 additions & 44 deletions src/commit.c
Expand Up @@ -26,11 +26,12 @@
#include "git2/common.h"
#include "git2/object.h"
#include "git2/repository.h"
#include "git2/signature.h"

#include "common.h"
#include "commit.h"
#include "revwalk.h"
#include "person.h"
#include "signature.h"

#define COMMIT_BASIC_PARSE 0x0
#define COMMIT_FULL_PARSE 0x1
Expand All @@ -50,8 +51,8 @@ void git_commit__free(git_commit *commit)
{
clear_parents(commit);

git_person__free(commit->author);
git_person__free(commit->committer);
git_signature_free(commit->author);
git_signature_free(commit->committer);

free(commit->message);
free(commit->message_short);
Expand Down Expand Up @@ -82,12 +83,12 @@ int git_commit__writeback(git_commit *commit, git_odb_source *src)
if (commit->author == NULL)
return GIT_EMISSINGOBJDATA;

git_person__write(src, "author", commit->author);
git_signature__write(src, "author", commit->author);

if (commit->committer == NULL)
return GIT_EMISSINGOBJDATA;

git_person__write(src, "committer", commit->committer);
git_signature__write(src, "committer", commit->committer);

if (commit->message != NULL)
git__source_printf(src, "\n%s", commit->message);
Expand Down Expand Up @@ -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 (commit->author)
git_person__free(commit->author);
git_signature_free(commit->author);

commit->author = git__malloc(sizeof(git_person));
if ((error = git_person__parse(commit->author, &buffer, buffer_end, "author ")) < GIT_SUCCESS)
commit->author = git__malloc(sizeof(git_signature));
if ((error = git_signature__parse(commit->author, &buffer, buffer_end, "author ")) < GIT_SUCCESS)
return error;

} else {
Expand All @@ -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 */
if (commit->committer)
git_person__free(commit->committer);
git_signature_free(commit->committer);

commit->committer = git__malloc(sizeof(git_person));
if ((error = git_person__parse(commit->committer, &buffer, buffer_end, "committer ")) < GIT_SUCCESS)
commit->committer = git__malloc(sizeof(git_signature));
if ((error = git_signature__parse(commit->committer, &buffer, buffer_end, "committer ")) < GIT_SUCCESS)
return error;

commit->commit_time = commit->committer->time;
commit->commit_timezone_offset = commit->committer->timezone_offset;

/* parse commit message */
while (buffer <= buffer_end && *buffer == '\n')
buffer++;
Expand Down Expand Up @@ -232,35 +230,21 @@ int git_commit__parse_full(git_commit *commit)
git_commit__parse_full(commit);

GIT_COMMIT_GETTER(git_tree *, tree)
GIT_COMMIT_GETTER(git_person *, author)
GIT_COMMIT_GETTER(git_person *, committer)
GIT_COMMIT_GETTER(git_signature *, author)
GIT_COMMIT_GETTER(git_signature *, committer)
GIT_COMMIT_GETTER(char *, message)
GIT_COMMIT_GETTER(char *, message_short)

time_t git_commit_time(git_commit *commit)
{
assert(commit);

if (commit->commit_time)
return commit->commit_time;

if (!commit->object.in_memory)
git_commit__parse_full(commit);

return commit->commit_time;
assert(commit && commit->committer);
return commit->committer->when.time;
}

int git_commit_timezone_offset(git_commit *commit)
int git_commit_time_offset(git_commit *commit)
{
assert(commit);

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;
assert(commit && commit->committer);
return commit->committer->when.offset;
}

unsigned int git_commit_parentcount(git_commit *commit)
Expand All @@ -283,25 +267,24 @@ void git_commit_set_tree(git_commit *commit, git_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;
CHECK_FULL_PARSE();

git_person__free(commit->author);
commit->author = git_person__new(name, email, time, offset);
git_signature_free(commit->author);
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;
CHECK_FULL_PARSE();

git_person__free(commit->committer);
commit->committer = git_person__new(name, email, time, offset);
commit->commit_time = time;
git_signature_free(commit->committer);
commit->committer = git_signature_dup(committer_sig);
}

void git_commit_set_message(git_commit *commit, const char *message)
Expand Down
7 changes: 2 additions & 5 deletions src/commit.h
Expand Up @@ -11,14 +11,11 @@
struct git_commit {
git_object object;

time_t commit_time;
int commit_timezone_offset;

git_vector parents;

git_tree *tree;
git_person *author;
git_person *committer;
git_signature *author;
git_signature *committer;

char *message;
char *message_short;
Expand Down
1 change: 1 addition & 0 deletions src/git2.h
Expand Up @@ -33,6 +33,7 @@
#include "git2/types.h"

#include "git2/oid.h"
#include "git2/signature.h"
#include "git2/odb.h"

#include "git2/repository.h"
Expand Down
18 changes: 6 additions & 12 deletions src/git2/commit.h
Expand Up @@ -104,14 +104,14 @@ GIT_EXTERN(int) git_commit_timezone_offset(git_commit *commit);
* @param commit a previously loaded 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.
* @param commit a previously loaded 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.
Expand Down Expand Up @@ -154,22 +154,16 @@ GIT_EXTERN(void) git_commit_set_message(git_commit *commit, const char *message)
/**
* Set the committer of a commit
* @param commit the commit object
* @param name name of the new 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
* @param author_sig signature of the committer
*/
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
* @param commit the commit object
* @param name name of the new 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
* @param author_sig signature of the author
*/
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
Expand Down
10 changes: 0 additions & 10 deletions src/git2/common.h
Expand Up @@ -134,17 +134,7 @@
/** The index file is not backed up by an existing repository */
#define GIT_EBAREINDEX (GIT_ERROR -14)


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
#endif
70 changes: 70 additions & 0 deletions src/git2/signature.h
@@ -0,0 +1,70 @@
/*
* 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
9 changes: 3 additions & 6 deletions src/git2/tag.h
Expand Up @@ -96,7 +96,7 @@ GIT_EXTERN(const char *) git_tag_name(git_tag *t);
* @param tag a previously loaded tag.
* @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
Expand All @@ -122,12 +122,9 @@ GIT_EXTERN(void) git_tag_set_name(git_tag *tag, const char *name);
/**
* Set the tagger of a tag
* @param tag The tag to modify
* @param name the name of the new tagger
* @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
* @param tagger_sig signature of the tagging action
*/
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
Expand Down
13 changes: 13 additions & 0 deletions src/git2/types.h
Expand Up @@ -82,6 +82,19 @@ typedef struct git_tree git_tree;
/** Memory representation of an index file. */
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

Expand Down
21 changes: 0 additions & 21 deletions src/person.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/revwalk.c
Expand Up @@ -388,8 +388,8 @@ void git_revwalk_list_timesort(git_revwalk_list *list)
e = q, q = q->next, q_size--;

else if (q_size == 0 || q == NULL ||
p->walk_commit->commit_object->commit_time >=
q->walk_commit->commit_object->commit_time)
p->walk_commit->commit_object->committer->when.time >=
q->walk_commit->commit_object->committer->when.time)
e = p, p = p->next, p_size--;

else
Expand Down

0 comments on commit 638c2ca

Please sign in to comment.