Repository navigation
Expand file tree
/
Copy pathCodeMeshFingerprint.cs
More file actions
64 lines (58 loc) · 1.79 KB
/
Copy pathCodeMeshFingerprint.cs
File metadata and controls
64 lines (58 loc) · 1.79 KB
1
2
3
4
5
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
54
55
56
57
58
59
60
61
62
63
64
using CodeMesh.Domain.Graph;
namespace CodeMesh.Domain.Utilities;
public static class CodeMeshFingerprint
{
private static readonly HashSet<string> RuntimeMetadataKeys = new(StringComparer.Ordinal)
{
"repositoryId",
"repositoryRoot",
"repositoryRemoteUrl",
"repositoryBranch",
"repositoryCommit",
"projectId",
"checkoutId",
"snapshotId",
"ingestionRunId",
"lastSeenAt"
};
public static string ForNode(CodeNode node)
{
return CodeMeshHash.StableId(
node.Id,
node.StableKey,
node.Kind.ToString(),
node.Name,
node.Language,
node.Project,
node.Span.FilePath,
node.Span.StartLine.ToString(),
node.Span.StartColumn.ToString(),
node.Span.EndLine.ToString(),
node.Span.EndColumn.ToString(),
node.ContentHash,
StableMetadata(node.Metadata));
}
public static string ForRelationship(CodeRelationship relationship)
{
return CodeMeshHash.StableId(
relationship.Id,
relationship.SourceNodeId,
relationship.TargetNodeId,
relationship.Kind.ToString(),
relationship.Label,
StableMetadata(relationship.Metadata));
}
private static string StableMetadata(IReadOnlyDictionary<string, string> metadata)
{
if (metadata.Count == 0)
{
return string.Empty;
}
return string.Join(
'\u001e',
metadata
.Where(item => !RuntimeMetadataKeys.Contains(item.Key))
.OrderBy(item => item.Key, StringComparer.Ordinal)
.Select(item => $"{item.Key}\u001d{item.Value}"));
}
}