| 6866 | } |
| 6867 | |
| 6868 | int sequencer_get_update_refs_state(const char *wt_dir, |
| 6869 | struct string_list *refs) |
| 6870 | { |
| 6871 | int result = 0; |
| 6872 | FILE *fp = NULL; |
| 6873 | struct strbuf ref = STRBUF_INIT; |
| 6874 | struct strbuf hash = STRBUF_INIT; |
| 6875 | struct update_ref_record *rec = NULL; |
| 6876 | |
| 6877 | char *path = rebase_path_update_refs(wt_dir); |
| 6878 | |
| 6879 | fp = fopen(path, "r"); |
| 6880 | if (!fp) |
| 6881 | goto cleanup; |
| 6882 | |
| 6883 | while (strbuf_getline(&ref, fp) != EOF) { |
| 6884 | struct string_list_item *item; |
| 6885 | |
| 6886 | CALLOC_ARRAY(rec, 1); |
| 6887 | |
| 6888 | if (strbuf_getline(&hash, fp) == EOF || |
| 6889 | get_oid_hex(hash.buf, &rec->before)) { |
| 6890 | warning(_("update-refs file at '%s' is invalid"), |
| 6891 | path); |
| 6892 | result = -1; |
| 6893 | goto cleanup; |
| 6894 | } |
| 6895 | |
| 6896 | if (strbuf_getline(&hash, fp) == EOF || |
| 6897 | get_oid_hex(hash.buf, &rec->after)) { |
| 6898 | warning(_("update-refs file at '%s' is invalid"), |
| 6899 | path); |
| 6900 | result = -1; |
| 6901 | goto cleanup; |
| 6902 | } |
| 6903 | |
| 6904 | item = string_list_insert(refs, ref.buf); |
| 6905 | item->util = rec; |
| 6906 | rec = NULL; |
| 6907 | } |
| 6908 | |
| 6909 | cleanup: |
| 6910 | if (fp) |
| 6911 | fclose(fp); |
| 6912 | free(path); |
| 6913 | free(rec); |
| 6914 | strbuf_release(&ref); |
| 6915 | strbuf_release(&hash); |
| 6916 | return result; |
| 6917 | } |
no test coverage detected