diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-18 22:16:58 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-19 15:54:33 +0100 |
commit | 1afe1400433f010734ae4c43bf35dcc94edcc9de (patch) | |
tree | d2a7143551040175da2a5f13948ccc68f260d7ff /src | |
parent | bac95e6e1e99b1e364c5ebd39887a8e24bc1ad9d (diff) | |
download | libgit2-1afe1400433f010734ae4c43bf35dcc94edcc9de.tar.gz |
refdb: don't update when there's no need
If the caller wants to update a ref to point to the same target as it
currently has, we should return early and avoid writing to the reflog.
Diffstat (limited to 'src')
-rw-r--r-- | src/refdb_fs.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 0c3011083..4bcc5fac3 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -1021,6 +1021,8 @@ static int refdb_fs_backend__write( refdb_fs_backend *backend = (refdb_fs_backend *)_backend; git_filebuf file = GIT_FILEBUF_INIT; int error = 0, cmp = 0; + const char *new_target = NULL; + const git_oid *new_id = NULL; assert(backend); @@ -1041,6 +1043,21 @@ static int refdb_fs_backend__write( goto on_error; } + if (ref->type == GIT_REF_SYMBOLIC) + new_target = ref->target.symbolic; + else + new_id = &ref->target.oid; + + error = cmp_old_ref(&cmp, _backend, ref->name, new_id, new_target); + if (error < 0 && error != GIT_ENOTFOUND) + goto on_error; + + /* Don't update if we have the same value */ + if (!error && !cmp) { + error = 0; + goto on_error; /* not really error */ + } + if (should_write_reflog(backend->repo, ref->name)) { if ((error = reflog_append(backend, ref, NULL, NULL, who, message)) < 0) goto on_error; |