Code

Refactor and unify timezone parsing
authorJonas Fonseca <fonseca@diku.dk>
Wed, 4 Feb 2009 16:10:04 +0000 (17:10 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 5 Feb 2009 20:56:50 +0000 (21:56 +0100)
tig.c

diff --git a/tig.c b/tig.c
index 6d0983ca62e8ec64cf83a9f8a6eb4dedc5f42de9..e0d0640b97d73b1b26058724c19a02afea487ff6 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -3308,6 +3308,22 @@ view_driver(struct view *view, enum request request)
  * View backend utilities
  */
 
+static void
+parse_timezone(time_t *time, const char *zone)
+{
+       long tz;
+
+       tz  = ('0' - zone[1]) * 60 * 60 * 10;
+       tz += ('0' - zone[2]) * 60 * 60;
+       tz += ('0' - zone[3]) * 60;
+       tz += ('0' - zone[4]);
+
+       if (zone[0] == '-')
+               tz = -tz;
+
+       *time -= tz;
+}
+
 /* Parse author lines where the name may be empty:
  *     author  <email@address.tld> 1138474660 +0100
  */
@@ -3335,20 +3351,8 @@ parse_author_line(char *ident, char *author, size_t authorsize, struct tm *tm)
                char *zone = strchr(secs, ' ');
                time_t time = (time_t) atol(secs);
 
-               if (zone && strlen(zone) == STRING_SIZE(" +0700")) {
-                       long tz;
-
-                       zone++;
-                       tz  = ('0' - zone[1]) * 60 * 60 * 10;
-                       tz += ('0' - zone[2]) * 60 * 60;
-                       tz += ('0' - zone[3]) * 60;
-                       tz += ('0' - zone[4]) * 60;
-
-                       if (zone[0] == '-')
-                               tz = -tz;
-
-                       time -= tz;
-               }
+               if (zone && strlen(zone) == STRING_SIZE(" +0700"))
+                       parse_timezone(&time, zone + 1);
 
                gmtime_r(&time, tm);
        }
@@ -4337,17 +4341,7 @@ blame_read(struct view *view, char *line)
                author_time = (time_t) atol(line);
 
        } else if (match_blame_header("author-tz ", &line)) {
-               long tz;
-
-               tz  = ('0' - line[1]) * 60 * 60 * 10;
-               tz += ('0' - line[2]) * 60 * 60;
-               tz += ('0' - line[3]) * 60;
-               tz += ('0' - line[4]) * 60;
-
-               if (line[0] == '-')
-                       tz = -tz;
-
-               author_time -= tz;
+               parse_timezone(&author_time, line);
                gmtime_r(&author_time, &commit->time);
 
        } else if (match_blame_header("summary ", &line)) {