From e843f0e53b56ac49b471e0935bff385de40fcc99 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 9 Feb 2015 10:00:00 -0500 Subject: [PATCH] Workaround segfault when refreshing the status view When refreshing the status view, it will try to readd the HEAD reference. This caused a corruption in the reference DB, which led to a segfault when returning to the main view. The workaround will simply skip any updates to the ID reference list when the ID does not change for an existing ref. More work is needed to properly update the ID reference list when changes occur. References #370. --- src/refdb.c | 10 ++++++---- src/repo.c | 5 +++-- test/regressions/github-370-test | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100755 test/regressions/github-370-test diff --git a/src/refdb.c b/src/refdb.c index 55d7bac..1e29d1f 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -170,12 +170,8 @@ add_to_refs(const char *id, size_t idlen, char *name, size_t namelen, struct ref *ref_slot = ref; } - if (strncmp(ref->id, id, idlen)) - opt->changed |= WATCH_REFS; - ref->valid = TRUE; ref->type = type; - string_ncopy_do(ref->id, SIZEOF_REV, id, idlen); if (type == REFERENCE_HEAD) { if (!refs_head || @@ -187,6 +183,12 @@ add_to_refs(const char *id, size_t idlen, char *name, size_t namelen, struct ref if (type == REFERENCE_TAG) refs_tags++; + if (!strncmp(ref->id, id, idlen)) + return OK; + + opt->changed |= WATCH_REFS; + string_ncopy_do(ref->id, SIZEOF_REV, id, idlen); + ref_lists_slot = string_map_put_to(&refs_by_id, id); if (!ref_lists_slot) return OK; diff --git a/src/repo.c b/src/repo.c index b77b2fa..a073eb0 100644 --- a/src/repo.c +++ b/src/repo.c @@ -64,9 +64,10 @@ read_repo_info(char *name, size_t namelen, char *value, size_t valuelen, void *d } else if (!strcmp(arg, REPO_INFO_SYMBOLIC_HEAD)) { if (!prefixcmp(name, "refs/heads/")) { + const char *head = name + STRING_SIZE("refs/heads/"); + + string_ncopy(repo.head, head, strlen(head) + 1); add_ref(repo.head_id, name, repo.remote, repo.head); - name += STRING_SIZE("refs/heads/"); - string_ncopy(repo.head, name, strlen(name) + 1); } state->argv++; } diff --git a/test/regressions/github-370-test b/test/regressions/github-370-test new file mode 100755 index 0000000..09e66bc --- /dev/null +++ b/test/regressions/github-370-test @@ -0,0 +1,15 @@ +#!/bin/sh + +# Issue #370 + +. libtest.sh +. libgit.sh + +steps ' + s + R + q +' + +in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz" +test_tig -- 2.11.4.GIT