| 1966 | } |
| 1967 | |
| 1968 | static int packed_fsck_ref_sorted(struct fsck_options *o, |
| 1969 | struct ref_store *ref_store, |
| 1970 | const char *start, const char *eof) |
| 1971 | { |
| 1972 | size_t hexsz = ref_store->repo->hash_algo->hexsz; |
| 1973 | struct strbuf packed_entry = STRBUF_INIT; |
| 1974 | struct fsck_ref_report report = { 0 }; |
| 1975 | struct strbuf refname1 = STRBUF_INIT; |
| 1976 | struct strbuf refname2 = STRBUF_INIT; |
| 1977 | unsigned long line_number = 1; |
| 1978 | const char *former = NULL; |
| 1979 | const char *current; |
| 1980 | const char *eol; |
| 1981 | int ret = 0; |
| 1982 | |
| 1983 | if (*start == '#') { |
| 1984 | eol = memchr(start, '\n', eof - start); |
| 1985 | start = eol + 1; |
| 1986 | line_number++; |
| 1987 | } |
| 1988 | |
| 1989 | for (; start < eof; line_number++, start = eol + 1) { |
| 1990 | eol = memchr(start, '\n', eof - start); |
| 1991 | |
| 1992 | if (*start == '^') |
| 1993 | continue; |
| 1994 | |
| 1995 | if (!former) { |
| 1996 | former = start + hexsz + 1; |
| 1997 | continue; |
| 1998 | } |
| 1999 | |
| 2000 | current = start + hexsz + 1; |
| 2001 | if (cmp_packed_refname(former, current) >= 0) { |
| 2002 | const char *err_fmt = |
| 2003 | "refname '%s' is less than previous refname '%s'"; |
| 2004 | |
| 2005 | eol = memchr(former, '\n', eof - former); |
| 2006 | strbuf_add(&refname1, former, eol - former); |
| 2007 | eol = memchr(current, '\n', eof - current); |
| 2008 | strbuf_add(&refname2, current, eol - current); |
| 2009 | |
| 2010 | strbuf_addf(&packed_entry, "packed-refs line %lu", line_number); |
| 2011 | report.path = packed_entry.buf; |
| 2012 | ret = fsck_report_ref(o, &report, |
| 2013 | FSCK_MSG_PACKED_REF_UNSORTED, |
| 2014 | err_fmt, refname2.buf, refname1.buf); |
| 2015 | goto cleanup; |
| 2016 | } |
| 2017 | former = current; |
| 2018 | } |
| 2019 | |
| 2020 | cleanup: |
| 2021 | strbuf_release(&packed_entry); |
| 2022 | strbuf_release(&refname1); |
| 2023 | strbuf_release(&refname2); |
| 2024 | return ret; |
| 2025 | } |
no test coverage detected