summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-09-19 18:38:33 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-09-19 18:38:33 (GMT)
commit9ff700ebacffc8fb8cf80daabfb6503cb24dca0b (patch)
tree63213092f97a3522450c6cbea407b80c37f6c3ca /date.c
parentceeacc501bc64dcdff180a9250bf2fcea3582837 (diff)
parentf4ef51739343f80c7cb0467244925b3725d65730 (diff)
downloadgit-9ff700ebacffc8fb8cf80daabfb6503cb24dca0b.zip
git-9ff700ebacffc8fb8cf80daabfb6503cb24dca0b.tar.gz
git-9ff700ebacffc8fb8cf80daabfb6503cb24dca0b.tar.bz2
Merge branch 'jk/commit-author-parsing'
Code clean-up. * jk/commit-author-parsing: determine_author_info(): copy getenv output determine_author_info(): reuse parsing functions date: use strbufs in date-formatting functions record_author_date(): use find_commit_header() record_author_date(): fix memory leak on malformed commit commit: provide a function to find a header in a buffer
Diffstat (limited to 'date.c')
-rw-r--r--date.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/date.c b/date.c
index 5d73d9b..59dfe57 100644
--- a/date.c
+++ b/date.c
@@ -614,7 +614,7 @@ static int match_tz(const char *date, int *offp)
return end - date;
}
-static int date_string(unsigned long date, int offset, char *buf, int len)
+static void date_string(unsigned long date, int offset, struct strbuf *buf)
{
int sign = '+';
@@ -622,7 +622,7 @@ static int date_string(unsigned long date, int offset, char *buf, int len)
offset = -offset;
sign = '-';
}
- return snprintf(buf, len, "%lu %c%02d%02d", date, sign, offset / 60, offset % 60);
+ strbuf_addf(buf, "%lu %c%02d%02d", date, sign, offset / 60, offset % 60);
}
/*
@@ -744,13 +744,14 @@ int parse_expiry_date(const char *date, unsigned long *timestamp)
return errors;
}
-int parse_date(const char *date, char *result, int maxlen)
+int parse_date(const char *date, struct strbuf *result)
{
unsigned long timestamp;
int offset;
if (parse_date_basic(date, &timestamp, &offset))
return -1;
- return date_string(timestamp, offset, result, maxlen);
+ date_string(timestamp, offset, result);
+ return 0;
}
enum date_mode parse_date_format(const char *format)
@@ -778,7 +779,7 @@ enum date_mode parse_date_format(const char *format)
die("unknown date format %s", format);
}
-void datestamp(char *buf, int bufsize)
+void datestamp(struct strbuf *out)
{
time_t now;
int offset;
@@ -788,7 +789,7 @@ void datestamp(char *buf, int bufsize)
offset = tm_to_time_t(localtime(&now)) - now;
offset /= 60;
- date_string(now, offset, buf, bufsize);
+ date_string(now, offset, out);
}
/*