mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-10-02 14:13:48 +00:00
Use HASH_BINARY_SIZE (20) and HASH_SHA_SIZE (40) instead of hardcoded numbers
This commit is contained in:
parent
c4eb6d6ad9
commit
940897a2f5
|
@ -660,7 +660,7 @@ write_tree(GitgCommit *commit, gchar **tree, GError **error)
|
|||
gchar const *argv[] = {"write-tree", NULL};
|
||||
gchar **lines = gitg_repository_command_with_output(commit->priv->repository, argv, error);
|
||||
|
||||
if (!lines || strlen(*lines) != 40)
|
||||
if (!lines || strlen(*lines) != HASH_SHA_SIZE)
|
||||
{
|
||||
g_strfreev(lines);
|
||||
return FALSE;
|
||||
|
@ -740,7 +740,7 @@ commit_tree(GitgCommit *commit, gchar const *tree, gchar const *comment, gboolea
|
|||
g_free(head);
|
||||
g_free(fullcomment);
|
||||
|
||||
if (!lines || strlen(*lines) != 40)
|
||||
if (!lines || strlen(*lines) != HASH_SHA_SIZE)
|
||||
{
|
||||
g_strfreev(lines);
|
||||
return FALSE;
|
||||
|
|
|
@ -378,7 +378,7 @@ collapse_lane(GitgLanes *lanes, LaneContainer *container, gint8 index)
|
|||
GitgLaneBoundary *boundary = gitg_lane_convert_boundary((GitgLane *)lstlane->data, GITG_LANE_TYPE_END);
|
||||
|
||||
/* copy parent hash over */
|
||||
memcpy(boundary->hash, container->to, 20);
|
||||
memcpy(boundary->hash, container->to, HASH_BINARY_SIZE);
|
||||
lstlane->data = boundary;
|
||||
}
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ expand_lane(GitgLanes *lanes, CollapsedLane *lane)
|
|||
GitgLaneBoundary *boundary = gitg_lane_convert_boundary(copy, GITG_LANE_TYPE_START);
|
||||
|
||||
/* copy child hash in boundary */
|
||||
memcpy(boundary->hash, lane->from, 20);
|
||||
memcpy(boundary->hash, lane->from, HASH_BINARY_SIZE);
|
||||
copy = (GitgLane *)boundary;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -75,7 +75,7 @@ gitg_ref_copy(GitgRef *ref)
|
|||
ret->shortname = g_strdup(ref->shortname);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 20; ++i)
|
||||
for (i = 0; i < HASH_BINARY_SIZE; ++i)
|
||||
ret->hash[i] = ref->hash[i];
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -138,10 +138,10 @@ gitg_revision_get_hash(GitgRevision *revision)
|
|||
gchar *
|
||||
gitg_revision_get_sha1(GitgRevision *revision)
|
||||
{
|
||||
char res[40];
|
||||
char res[HASH_SHA_SIZE];
|
||||
gitg_utils_hash_to_sha1(revision->hash, res);
|
||||
|
||||
return g_strndup(res, 40);
|
||||
return g_strndup(res, HASH_SHA_SIZE);
|
||||
}
|
||||
|
||||
Hash *
|
||||
|
@ -161,10 +161,10 @@ gitg_revision_get_parents(GitgRevision *revision)
|
|||
int i;
|
||||
for (i = 0; i < revision->num_parents; ++i)
|
||||
{
|
||||
ret[i] = g_new(gchar, 41);
|
||||
ret[i] = g_new(gchar, HASH_SHA_SIZE + 1);
|
||||
gitg_utils_hash_to_sha1(revision->parents[i], ret[i]);
|
||||
|
||||
ret[i][40] = '\0';
|
||||
ret[i][HASH_SHA_SIZE] = '\0';
|
||||
}
|
||||
|
||||
ret[revision->num_parents] = NULL;
|
||||
|
|
|
@ -44,7 +44,7 @@ gitg_utils_sha1_to_hash(gchar const *sha, gchar *hash)
|
|||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 20; ++i)
|
||||
for (i = 0; i < HASH_BINARY_SIZE; ++i)
|
||||
{
|
||||
gchar h = atoh(*(sha++)) << 4;
|
||||
hash[i] = h | atoh(*(sha++));
|
||||
|
@ -58,7 +58,7 @@ gitg_utils_hash_to_sha1(gchar const *hash, gchar *sha)
|
|||
int i;
|
||||
int pos = 0;
|
||||
|
||||
for (i = 0; i < 20; ++i)
|
||||
for (i = 0; i < HASH_BINARY_SIZE; ++i)
|
||||
{
|
||||
sha[pos++] = repr[(hash[i] >> 4) & 0x0f];
|
||||
sha[pos++] = repr[(hash[i] & 0x0f)];
|
||||
|
@ -68,17 +68,17 @@ gitg_utils_hash_to_sha1(gchar const *hash, gchar *sha)
|
|||
gchar *
|
||||
gitg_utils_hash_to_sha1_new(gchar const *hash)
|
||||
{
|
||||
gchar *ret = g_new(gchar, 41);
|
||||
gchar *ret = g_new(gchar, HASH_SHA_SIZE + 1);
|
||||
gitg_utils_hash_to_sha1(hash, ret);
|
||||
|
||||
ret[40] = '\0';
|
||||
ret[HASH_SHA_SIZE] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
gchar *
|
||||
gitg_utils_sha1_to_hash_new(gchar const *sha1)
|
||||
{
|
||||
gchar *ret = g_new(gchar, 20);
|
||||
gchar *ret = g_new(gchar, HASH_BINARY_SIZE);
|
||||
gitg_utils_sha1_to_hash(sha1, ret);
|
||||
|
||||
return ret;
|
||||
|
@ -241,7 +241,7 @@ gitg_utils_hash_hash(gconstpointer v)
|
|||
guint32 h = *p;
|
||||
int i;
|
||||
|
||||
for (i = 1; i < 20; ++i)
|
||||
for (i = 1; i < HASH_BINARY_SIZE; ++i)
|
||||
h = (h << 5) - h + p[i];
|
||||
|
||||
return h;
|
||||
|
@ -250,7 +250,7 @@ gitg_utils_hash_hash(gconstpointer v)
|
|||
gboolean
|
||||
gitg_utils_hash_equal(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return memcmp(a, b, 20) == 0;
|
||||
return memcmp(a, b, HASH_BINARY_SIZE) == 0;
|
||||
}
|
||||
|
||||
gint
|
||||
|
|
Loading…
Reference in a new issue