[ostree] refs: Don't try searching for input strings that can't be objects
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] refs: Don't try searching for input strings that can't be objects
- Date: Wed, 23 Jul 2014 19:14:28 +0000 (UTC)
commit d5e813c52c324157c51ac96b1c162d167a5d48fb
Author: Colin Walters <walters verbum org>
Date: Wed Jul 23 15:09:24 2014 -0400
refs: Don't try searching for input strings that can't be objects
I noticed OSTree was a bit slower, did some investigation
and saw we were enumerating all objects for things like
$ ostree rev-parse blah
Since "blah" can never be an object (because of the 'l' and 'h'), just
return no matches.
src/libostree/ostree-repo-refs.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c
index 978c5e0..ca584b6 100644
--- a/src/libostree/ostree-repo-refs.c
+++ b/src/libostree/ostree-repo-refs.c
@@ -364,6 +364,8 @@ ostree_repo_resolve_partial_checksum (OstreeRepo *self,
GError **error)
{
gboolean ret = FALSE;
+ static const char hexchars[] = "0123456789abcdef";
+ gsize off;
gs_unref_hashtable GHashTable *ref_list = NULL;
gs_free char *ret_rev = NULL;
guint length;
@@ -375,6 +377,12 @@ ostree_repo_resolve_partial_checksum (OstreeRepo *self,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ /* If the input is longer than 64 chars or contains non-hex chars,
+ don't bother looking for it as an object */
+ off = strspn (refspec, hexchars);
+ if (off > 64 || refspec[off] != '\0')
+ return TRUE;
+
/* this looks through all objects and adds them to the ref_list if:
a) they are a commit object AND
b) the obj checksum starts with the partual checksum defined by "refspec" */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]