Skip to content

Commit

Permalink
stop branch collision
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcmarrow authored and Megan Wilhite committed Aug 3, 2023
1 parent dff6f6c commit e60abda
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
12 changes: 10 additions & 2 deletions salt/utils/gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,22 @@ def __init__(
failhard(self.role)

hash_type = getattr(hashlib, self.opts.get("hash_type", "md5"))
# Generate full id. The full id is made from these parts name-id-env-_root.
# Generate full id.
# Full id helps decrease the chances of collections in the gitfs cache.
try:
target = str(self.get_checkout_target())
except AttributeError:
target = ""
self._full_id = "-".join(
[
getattr(self, "name", ""),
self.id.replace(" ", "-"),
self.id,
getattr(self, "env", ""),
getattr(self, "_root", ""),
self.role,
getattr(self, "base", ""),
getattr(self, "branch", ""),
target
]
)
# We loaded this data from yaml configuration files, so, its safe
Expand Down
3 changes: 2 additions & 1 deletion tests/pytests/unit/utils/test_gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time

import pytest

import salt.config
import salt.fileserver.gitfs
import salt.utils.gitfs
Expand Down Expand Up @@ -245,7 +246,7 @@ def test_checkout_pygit2(_prepare_provider):
)
def test_full_id_pygit2(_prepare_provider):
assert _prepare_provider.full_id().startswith("-")
assert _prepare_provider.full_id().endswith("/pygit2-repo--")
assert _prepare_provider.full_id().endswith("/pygit2-repo---gitfs-master--")


@pytest.mark.skipif(not HAS_PYGIT2, reason="This host lacks proper pygit2 support")
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/utils/test_gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tempfile

import pytest

import salt.ext.tornado.ioloop
import salt.fileserver.gitfs
import salt.utils.files
Expand Down Expand Up @@ -114,23 +115,23 @@ def test_update_by_id_and_name(self):
self.assertFalse(self.main_class.remotes[1].fetched)

def test_full_id(self):
self.assertEqual(self.main_class.remotes[0].full_id(), "-file://repo1.git--")
self.assertEqual(self.main_class.remotes[0].full_id(), "-file://repo1.git---gitfs-master--")

def test_full_id_with_name(self):
self.assertEqual(
self.main_class.remotes[1].full_id(), "repo2-file://repo2.git--"
self.main_class.remotes[1].full_id(), "repo2-file://repo2.git---gitfs-master--"
)

def test_get_cachedir_basename(self):
self.assertEqual(
self.main_class.remotes[0].get_cachedir_basename(),
"-tNy9UbCHQuwj6vltGS0ptBfsE36nygwN4lFc+vbiaGA=",
"-jXhnbGDemchtZwTwaD2s6VOaVvs98a7w+AtiYlmOVb0=",
)

def test_get_cachedir_base_with_name(self):
self.assertEqual(
self.main_class.remotes[1].get_cachedir_basename(),
"repo2-QhjC+OMDxuokzFQdh0jlI9W0Q8MFAXCkOhoAviU7Vqo=",
"repo2-nuezpiDtjQRFC0ZJDByvi+F6Vb8ZhfoH41n_KFxTGsU=",
)

def test_git_provider_mp_lock(self):
Expand Down

0 comments on commit e60abda

Please sign in to comment.