Skip to content

Group

Module for semantic grouping of diff chunks.

SemanticGroup

Represents a group of semantically related diff chunks.

Source code in src/codemap/git/semantic_grouping/group.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class SemanticGroup:
	"""Represents a group of semantically related diff chunks."""

	def __init__(self, chunks: list[DiffChunk] | None = None, name: str | None = None) -> None:
		"""
		Initialize a semantic group.

		Args:
		    chunks: List of DiffChunk objects
		    name: Optional name for the group

		"""
		self.chunks = chunks or []
		self.name = name
		self.message: str | None = None
		self.approved = False

	@property
	def files(self) -> list[str]:
		"""Get the set of files affected by this group."""
		files: set[str] = set()
		for chunk in self.chunks:
			files.update(chunk.files)
		return sorted(files)

	@property
	def content(self) -> str:
		"""Get the combined diff content of all chunks."""
		return "\n".join(chunk.content for chunk in self.chunks)

	def merge_with(self, other_group: "SemanticGroup") -> "SemanticGroup":
		"""
		Merge this group with another group.

		Args:
		    other_group: Another SemanticGroup to merge with

		Returns:
		    A new SemanticGroup containing chunks from both groups

		"""
		return SemanticGroup(
			chunks=self.chunks + other_group.chunks, name=f"Merged: {self.name or ''} + {other_group.name or ''}"
		)

	def __repr__(self) -> str:
		"""Return a string representation of the group with file and chunk counts."""
		return f"SemanticGroup(files={len(self.files)}, chunks={len(self.chunks)})"

__init__

__init__(
	chunks: list[DiffChunk] | None = None,
	name: str | None = None,
) -> None

Initialize a semantic group.

Parameters:

Name Type Description Default
chunks list[DiffChunk] | None

List of DiffChunk objects

None
name str | None

Optional name for the group

None
Source code in src/codemap/git/semantic_grouping/group.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
def __init__(self, chunks: list[DiffChunk] | None = None, name: str | None = None) -> None:
	"""
	Initialize a semantic group.

	Args:
	    chunks: List of DiffChunk objects
	    name: Optional name for the group

	"""
	self.chunks = chunks or []
	self.name = name
	self.message: str | None = None
	self.approved = False

chunks instance-attribute

chunks = chunks or []

name instance-attribute

name = name

message instance-attribute

message: str | None = None

approved instance-attribute

approved = False

files property

files: list[str]

Get the set of files affected by this group.

content property

content: str

Get the combined diff content of all chunks.

merge_with

merge_with(other_group: SemanticGroup) -> SemanticGroup

Merge this group with another group.

Parameters:

Name Type Description Default
other_group SemanticGroup

Another SemanticGroup to merge with

required

Returns:

Type Description
SemanticGroup

A new SemanticGroup containing chunks from both groups

Source code in src/codemap/git/semantic_grouping/group.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def merge_with(self, other_group: "SemanticGroup") -> "SemanticGroup":
	"""
	Merge this group with another group.

	Args:
	    other_group: Another SemanticGroup to merge with

	Returns:
	    A new SemanticGroup containing chunks from both groups

	"""
	return SemanticGroup(
		chunks=self.chunks + other_group.chunks, name=f"Merged: {self.name or ''} + {other_group.name or ''}"
	)

__repr__

__repr__() -> str

Return a string representation of the group with file and chunk counts.

Source code in src/codemap/git/semantic_grouping/group.py
51
52
53
def __repr__(self) -> str:
	"""Return a string representation of the group with file and chunk counts."""
	return f"SemanticGroup(files={len(self.files)}, chunks={len(self.chunks)})"