MCPcopy Create free account
hub / github.com/git/git / has_epoch_timestamp

Function has_epoch_timestamp

apply.c:782–847  ·  view source on GitHub ↗

* Does the ---/+++ line have the POSIX timestamp after the last HT? * GNU diff puts epoch there to signal a creation/deletion event. Is * this such a timestamp? */

Source from the content-addressed store, hash-verified

780 * this such a timestamp?
781 */
782static int has_epoch_timestamp(const char *nameline)
783{
784 /*
785 * We are only interested in epoch timestamp; any non-zero
786 * fraction cannot be one, hence "(\.0+)?" in the regexp below.
787 * For the same reason, the date must be either 1969-12-31 or
788 * 1970-01-01, and the seconds part must be "00".
789 */
790 const char stamp_regexp[] =
791 "^[0-2][0-9]:([0-5][0-9]):00(\\.0+)?"
792 " "
793 "([-+][0-2][0-9]:?[0-5][0-9])\n";
794 const char *timestamp = NULL, *cp, *colon;
795 static regex_t *stamp;
796 regmatch_t m[10];
797 int zoneoffset, epoch_hour, hour, minute;
798 int status;
799
800 for (cp = nameline; *cp != '\n'; cp++) {
801 if (*cp == '\t')
802 timestamp = cp + 1;
803 }
804 if (!timestamp)
805 return 0;
806
807 /*
808 * YYYY-MM-DD hh:mm:ss must be from either 1969-12-31
809 * (west of GMT) or 1970-01-01 (east of GMT)
810 */
811 if (skip_prefix(timestamp, "1969-12-31 ", &timestamp))
812 epoch_hour = 24;
813 else if (skip_prefix(timestamp, "1970-01-01 ", &timestamp))
814 epoch_hour = 0;
815 else
816 return 0;
817
818 if (!stamp) {
819 stamp = xmalloc(sizeof(*stamp));
820 if (regcomp(stamp, stamp_regexp, REG_EXTENDED)) {
821 warning(_("Cannot prepare timestamp regexp %s"),
822 stamp_regexp);
823 return 0;
824 }
825 }
826
827 status = regexec(stamp, timestamp, ARRAY_SIZE(m), m, 0);
828 if (status) {
829 if (status != REG_NOMATCH)
830 warning(_("regexec returned %d for input: %s"),
831 status, timestamp);
832 return 0;
833 }
834
835 hour = strtol(timestamp, NULL, 10);
836 minute = strtol(timestamp + m[1].rm_so, NULL, 10);
837
838 zoneoffset = strtol(timestamp + m[3].rm_so + 1, (char **) &colon, 10);
839 if (*colon == ':')

Callers 1

parse_traditional_patchFunction · 0.85

Calls 3

regcompFunction · 0.85
warningFunction · 0.85
xmallocFunction · 0.70

Tested by

no test coverage detected