/
GitRepository.cs
718 lines (623 loc) · 26.8 KB
/
GitRepository.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace Nerdbank.GitVersioning.ManagedGit
{
/// <summary>
/// Provides access to a Git repository.
/// </summary>
public class GitRepository : IDisposable
{
private const string HeadFileName = "HEAD";
private const string GitDirectoryName = ".git";
private readonly Lazy<GitPack[]> packs;
/// <summary>
/// UTF-16 encoded string.
/// </summary>
private readonly char[] objectPathBuffer;
private readonly List<GitRepository> alternates = new List<GitRepository>();
#if DEBUG && !NETSTANDARD
private Dictionary<GitObjectId, int> histogram = new Dictionary<GitObjectId, int>();
#endif
/// <summary>
/// Creates a new instance of the <see cref="GitRepository"/> class.
/// </summary>
/// <param name="workingDirectory"><inheritdoc cref="GitRepository(string, string, string, string)" path="/param[@name='workingDirectory']" /></param>
/// <returns>
/// A <see cref="GitRepository"/> which represents the git repository, or <see langword="null"/>
/// if no git repository was found.
/// </returns>
public static GitRepository? Create(string? workingDirectory)
{
if (!GitContext.TryFindGitPaths(workingDirectory, out string? gitDirectory, out string? workingTreeDirectory, out string? workingTreeRelativePath))
{
return null;
}
string commonDirectory = gitDirectory;
string commonDirFile = Path.Combine(gitDirectory, "commondir");
if (File.Exists(commonDirFile))
{
var commonDirectoryRelativePath = File.ReadAllText(commonDirFile).Trim('\n');
commonDirectory = Path.Combine(gitDirectory, commonDirectoryRelativePath);
}
string objectDirectory = Path.Combine(commonDirectory, "objects");
return new GitRepository(workingDirectory!, gitDirectory, commonDirectory, objectDirectory);
}
/// <summary>
/// Creates a new instance of the <see cref="GitRepository"/> class.
/// </summary>
/// <param name="workingDirectory"><inheritdoc cref="GitRepository(string, string, string, string)" path="/param[@name='workingDirectory']" /></param>
/// <param name="gitDirectory"><inheritdoc cref="GitRepository(string, string, string, string)" path="/param[@name='gitDirectory']" /> </param>
/// <param name="commonDirectory"><inheritdoc cref="GitRepository(string, string, string, string)" path="/param[@name='commonDirectory']" /></param>
/// <param name="objectDirectory"><inheritdoc cref="GitRepository(string, string, string, string)" path="/param[@name='objectDirectory']" /></param>
public static GitRepository Create(string workingDirectory, string gitDirectory, string commonDirectory, string objectDirectory)
{
return new GitRepository(workingDirectory, gitDirectory, commonDirectory, objectDirectory);
}
/// <summary>
/// Initializes a new instance of the <see cref="GitRepository"/> class.
/// </summary>
/// <param name="workingDirectory">
/// The current working directory. This can be a subdirectory of the Git repository.
/// </param>
/// <param name="gitDirectory">
/// The directory in which the git HEAD file is stored. This is the .git directory unless the working directory is a worktree.
/// </param>
/// <param name="commonDirectory">
/// The common Git directory, which is parent to the objects, refs, and other directories.
/// </param>
/// <param name="objectDirectory">
/// The object directory in which Git objects are stored.
/// </param>
public GitRepository(string workingDirectory, string gitDirectory, string commonDirectory, string objectDirectory)
{
this.WorkingDirectory = workingDirectory ?? throw new ArgumentNullException(nameof(workingDirectory));
this.GitDirectory = gitDirectory ?? throw new ArgumentNullException(nameof(gitDirectory));
this.CommonDirectory = commonDirectory ?? throw new ArgumentNullException(nameof(commonDirectory));
this.ObjectDirectory = objectDirectory ?? throw new ArgumentNullException(nameof(objectDirectory));
// Normalize paths
this.WorkingDirectory = TrimEndingDirectorySeparator(Path.GetFullPath(this.WorkingDirectory));
this.GitDirectory = TrimEndingDirectorySeparator(Path.GetFullPath(this.GitDirectory));
this.CommonDirectory = TrimEndingDirectorySeparator(Path.GetFullPath(this.CommonDirectory));
this.ObjectDirectory = TrimEndingDirectorySeparator(Path.GetFullPath(this.ObjectDirectory));
if (FileHelpers.TryOpen(
Path.Combine(this.ObjectDirectory, "info", "alternates"),
out var alternateStream))
{
// There's not a lot of documentation on git alternates; but this StackOverflow question
// https://stackoverflow.com/questions/36123655/what-is-the-git-alternates-mechanism
// provides a good starting point.
Span<byte> alternates = stackalloc byte[4096];
var length = alternateStream!.Read(alternates);
alternates = alternates.Slice(0, length);
int index = 0;
while ((index = alternates.IndexOf((byte)':')) > 0)
{
var alternate = GetString(alternates.Slice(0, index));
alternate = Path.GetFullPath(Path.Combine(this.ObjectDirectory, alternate));
this.alternates.Add(GitRepository.Create(workingDirectory, gitDirectory, commonDirectory, alternate));
alternates = alternates.Slice(index + 1);
}
}
int pathLengthInChars = this.ObjectDirectory.Length
+ 1 // '/'
+ 2 // 'xy' is first byte as 2 hex characters.
+ 1 // '/'
+ 38 // 19 bytes * 2 hex chars each
+ 1; // Trailing null character
this.objectPathBuffer = new char[pathLengthInChars];
this.ObjectDirectory.CopyTo(0, this.objectPathBuffer, 0, this.ObjectDirectory.Length);
this.objectPathBuffer[this.ObjectDirectory.Length] = '/';
this.objectPathBuffer[this.ObjectDirectory.Length + 3] = '/';
this.objectPathBuffer[pathLengthInChars - 1] = '\0'; // Make sure to initialize with zeros
this.packs = new Lazy<GitPack[]>(this.LoadPacks);
}
// TODO: read from Git settings
/// <summary>
/// Gets a value indicating whether this Git repository is case-insensitive.
/// </summary>
public bool IgnoreCase { get; private set; } = false;
/// <summary>
/// Gets the path to the current working directory.
/// </summary>
public string WorkingDirectory { get; private set; }
/// <summary>
/// Gets the path to the Git directory, in which at minimum HEAD is stored.
/// Use <see cref="CommonDirectory"/> for all other metadata (e.g. references, configuration).
/// </summary>
public string GitDirectory { get; private set; }
/// <summary>
/// Gets the path to the common directory, in which shared Git data (e.g. objects) are stored.
/// </summary>
public string CommonDirectory { get; private set; }
/// <summary>
/// Gets the path to the Git object directory. It is a subdirectory of <see cref="CommonDirectory"/>.
/// </summary>
public string ObjectDirectory { get; private set; }
/// <summary>
/// Gets the encoding used by this Git repository.
/// </summary>
public static Encoding Encoding => Encoding.UTF8;
/// <summary>
/// Shortens the object id
/// </summary>
/// <param name="objectId">
/// The object Id to shorten.
/// </param>
/// <param name="minimum">
/// The minimum string length.
/// </param>
/// <returns>
/// The short object id.
/// </returns>
public string ShortenObjectId(GitObjectId objectId, int minimum)
{
var sha = objectId.ToString();
for (int length = minimum; length < sha.Length; length += 2)
{
var objectish = sha.Substring(0, length);
if (this.Lookup(objectish) != null)
{
return objectish;
}
}
return sha;
}
/// <summary>
/// Returns the current HEAD as a reference (if available) or a Git object id.
/// </summary>
/// <returns>
/// The current HEAD as a reference (if available) or a Git object id.
/// </returns>
public object GetHeadAsReferenceOrSha()
{
using (var stream = File.OpenRead(Path.Combine(this.GitDirectory, HeadFileName)))
{
return GitReferenceReader.ReadReference(stream);
}
}
/// <summary>
/// Gets the object ID of the current HEAD.
/// </summary>
/// <returns>
/// The object ID of the current HEAD.
/// </returns>
public GitObjectId GetHeadCommitSha()
{
var reference = this.GetHeadAsReferenceOrSha();
var objectId = this.ResolveReference(reference);
return objectId;
}
/// <summary>
/// Gets the current HEAD commit, if available.
/// </summary>
/// <param name="readAuthor">
/// A value indicating whether to populate the <see cref="GitCommit.Author"/> field.
/// </param>
/// <returns>
/// The current HEAD commit, or <see langword="null"/> if not available.
/// </returns>
public GitCommit? GetHeadCommit(bool readAuthor = false)
{
var headCommitId = this.GetHeadCommitSha();
if (headCommitId == GitObjectId.Empty)
{
return null;
}
return this.GetCommit(headCommitId, readAuthor);
}
/// <summary>
/// Gets a commit by its Git object Id.
/// </summary>
/// <param name="sha">
/// The Git object Id of the commit.
/// </param>
/// <param name="readAuthor">
/// A value indicating whether to populate the <see cref="GitCommit.Author"/> field.
/// </param>
/// <returns>
/// The requested commit.
/// </returns>
public GitCommit GetCommit(GitObjectId sha, bool readAuthor = false)
{
using (Stream? stream = this.GetObjectBySha(sha, "commit"))
{
if (stream == null)
{
throw new GitException($"The commit {sha} was not found in this repository.") { ErrorCode = GitException.ErrorCodes.ObjectNotFound };
}
return GitCommitReader.Read(stream, sha, readAuthor);
}
}
/// <summary>
/// Parses any committish to an object id.
/// </summary>
/// <param name="objectish">Any "objectish" string (e.g. commit ID (partial or full), branch name, tag name, or "HEAD").</param>
/// <returns>The object ID referenced by <paramref name="objectish"/> if found; otherwise <see langword="null"/>.</returns>
public GitObjectId? Lookup(string objectish)
{
if (objectish == "HEAD")
{
return this.GetHeadCommitSha();
}
var possibleLooseFileMatches = new List<string>();
if (objectish.StartsWith("refs/", StringComparison.Ordinal))
{
// Match on loose ref files by their canonical name.
possibleLooseFileMatches.Add(Path.Combine(this.GitDirectory, objectish));
}
else
{
// Look for simple names for branch or tag.
possibleLooseFileMatches.Add(Path.Combine(this.CommonDirectory, "refs", "heads", objectish));
possibleLooseFileMatches.Add(Path.Combine(this.CommonDirectory, "refs", "tags", objectish));
possibleLooseFileMatches.Add(Path.Combine(this.CommonDirectory, "refs", "remotes", objectish));
}
if (possibleLooseFileMatches.FirstOrDefault(File.Exists) is string existingPath)
{
return GitObjectId.Parse(File.ReadAllText(existingPath).TrimEnd());
}
// Match in packed-refs file.
string packedRefPath = Path.Combine(this.CommonDirectory, "packed-refs");
if (File.Exists(packedRefPath))
{
using var refReader = File.OpenText(packedRefPath);
string? line;
while ((line = refReader.ReadLine()) is object)
{
if (line.StartsWith("#", StringComparison.Ordinal))
{
continue;
}
string refName = line.Substring(41);
if (string.Equals(refName, objectish, StringComparison.Ordinal))
{
return GitObjectId.Parse(line.Substring(0, 40));
}
else if (!objectish.StartsWith("refs/", StringComparison.Ordinal))
{
// Not a canonical ref, so try heads and tags
if (string.Equals(refName, "refs/heads/" + objectish, StringComparison.Ordinal))
{
return GitObjectId.Parse(line.Substring(0, 40));
}
else if (string.Equals(refName, "refs/tags/" + objectish, StringComparison.Ordinal))
{
return GitObjectId.Parse(line.Substring(0, 40));
}
else if (string.Equals(refName, "refs/remotes/" + objectish, StringComparison.Ordinal))
{
return GitObjectId.Parse(line.Substring(0, 40));
}
}
}
}
if (objectish.Length == 40)
{
return GitObjectId.Parse(objectish);
}
var possibleObjectIds = new List<GitObjectId>();
if (objectish.Length > 2 && objectish.Length < 40)
{
// Search for _any_ object whose id starts with objectish in the object database
var directory = Path.Combine(this.ObjectDirectory, objectish.Substring(0, 2));
if (Directory.Exists(directory))
{
var files = Directory.GetFiles(directory, $"{objectish.Substring(2)}*");
foreach (var file in files)
{
var objectId = $"{objectish.Substring(0, 2)}{Path.GetFileName(file)}";
possibleObjectIds.Add(GitObjectId.Parse(objectId));
}
}
// Search for _any_ object whose id starts with objectish in the packfile
bool endsWithHalfByte = objectish.Length % 2 == 1;
if (endsWithHalfByte)
{
// Add one more character so hex can be converted to bytes.
// The bit length to be compared will not consider the last four bits.
objectish += "0";
}
var hex = ConvertHexStringToByteArray(objectish);
foreach (var pack in this.packs.Value)
{
var objectId = pack.Lookup(hex, endsWithHalfByte);
// It's possible for the same object to be present in both the object database and the pack files,
// or in multiple pack files.
if (objectId != null && !possibleObjectIds.Contains(objectId.Value))
{
if (possibleObjectIds.Count > 0)
{
// If objectish already resolved to at least one object which is different from the current
// object id, objectish is not well-defined; so stop resolving and return null instead.
return null;
}
else
{
possibleObjectIds.Add(objectId.Value);
}
}
}
}
if (possibleObjectIds.Count == 1)
{
return possibleObjectIds[0];
}
return null;
}
/// <summary>
/// Gets a tree object by its Git object Id.
/// </summary>
/// <param name="sha">
/// The Git object Id of the tree.
/// </param>
/// <returns>
/// The requested tree.
/// </returns>
public GitTree GetTree(GitObjectId sha)
{
using (Stream? stream = this.GetObjectBySha(sha, "tree"))
{
if (stream == null)
{
throw new GitException($"The tree {sha} was not found in this repository.") { ErrorCode = GitException.ErrorCodes.ObjectNotFound };
}
return GitTreeReader.Read(stream, sha);
}
}
/// <summary>
/// Gets an entry in a git tree.
/// </summary>
/// <param name="treeId">
/// The Git object Id of the Git tree.
/// </param>
/// <param name="nodeName">
/// The name of the node in the Git tree.
/// </param>
/// <returns>
/// The object Id of the requested entry. Returns <see cref="GitObjectId.Empty"/> if the entry
/// could not be found.
/// </returns>
public GitObjectId GetTreeEntry(GitObjectId treeId, ReadOnlySpan<byte> nodeName)
{
using (Stream? treeStream = this.GetObjectBySha(treeId, "tree"))
{
if (treeStream == null)
{
throw new GitException($"The tree {treeId} was not found in this repository.") { ErrorCode = GitException.ErrorCodes.ObjectNotFound };
}
return GitTreeStreamingReader.FindNode(treeStream, nodeName);
}
}
/// <summary>
/// Gets a Git object by its Git object Id.
/// </summary>
/// <param name="sha">
/// The Git object id of the object to retrieve.
/// </param>
/// <param name="objectType">
/// The type of object to retrieve.
/// </param>
/// <returns>
/// A <see cref="Stream"/> which represents the requested object.
/// </returns>
/// <exception cref="GitException">
/// The requested object could not be found.
/// </exception>
/// <remarks>
/// As a special case, a <see langword="null"/> value will be returned for
/// <see cref="GitObjectId.Empty"/>.
/// </remarks>
public Stream? GetObjectBySha(GitObjectId sha, string objectType)
{
if (sha == GitObjectId.Empty)
{
return null;
}
if (this.TryGetObjectBySha(sha, objectType, out Stream? value))
{
return value;
}
else
{
throw new GitException($"An {objectType} object with SHA {sha} could not be found.") { ErrorCode = GitException.ErrorCodes.ObjectNotFound };
}
}
/// <summary>
/// Gets a Git object by its Git object Id.
/// </summary>
/// <param name="sha">
/// The Git object id of the object to retrieve.
/// </param>
/// <param name="objectType">
/// The type of object to retrieve.
/// </param>
/// <param name="value">
/// An output parameter which retrieves the requested Git object.
/// </param>
/// <returns>
/// <see langword="true"/> if the object could be found; otherwise,
/// <see langword="false"/>.
/// </returns>
public bool TryGetObjectBySha(GitObjectId sha, string objectType, out Stream? value)
{
#if DEBUG && !NETSTANDARD
if (!this.histogram.TryAdd(sha, 1))
{
this.histogram[sha] += 1;
}
#endif
foreach (var pack in this.packs.Value)
{
if (pack.TryGetObject(sha, objectType, out value))
{
return true;
}
}
if (this.TryGetObjectByPath(sha, objectType, out value))
{
return true;
}
foreach (var alternate in this.alternates)
{
if (alternate.TryGetObjectBySha(sha, objectType, out value))
{
return true;
}
}
value = null;
return false;
}
/// <summary>
/// Gets cache usage statistics.
/// </summary>
/// <returns>
/// A <see cref="string"/> which represents the cache usage statistics.
/// </returns>
public string GetCacheStatistics()
{
StringBuilder builder = new StringBuilder();
#if DEBUG && !NETSTANDARD
int histogramCount = 25;
builder.AppendLine("Overall repository:");
builder.AppendLine($"Top {histogramCount} / {this.histogram.Count} items:");
foreach (var item in this.histogram.OrderByDescending(v => v.Value).Take(25))
{
builder.AppendLine($" {item.Key}: {item.Value}");
}
builder.AppendLine();
#endif
foreach (var pack in this.packs.Value)
{
pack.GetCacheStatistics(builder);
}
return builder.ToString();
}
/// <inheritdoc/>
public override string ToString()
{
return $"Git Repository: {this.WorkingDirectory}";
}
/// <inheritdoc/>
public void Dispose()
{
if (this.packs.IsValueCreated)
{
foreach (var pack in this.packs.Value)
{
pack.Dispose();
}
}
}
private bool TryGetObjectByPath(GitObjectId sha, string objectType, [NotNullWhen(true)] out Stream? value)
{
sha.CopyAsHex(0, 1, this.objectPathBuffer.AsSpan(this.ObjectDirectory.Length + 1, 2));
sha.CopyAsHex(1, 19, this.objectPathBuffer.AsSpan(this.ObjectDirectory.Length + 1 + 2 + 1));
if (!FileHelpers.TryOpen(this.objectPathBuffer, out var compressedFile))
{
value = null;
return false;
}
var objectStream = new GitObjectStream(compressedFile!, objectType);
if (string.CompareOrdinal(objectStream.ObjectType, objectType) != 0)
{
throw new GitException($"Got a {objectStream.ObjectType} instead of a {objectType} when opening object {sha}");
}
value = objectStream;
return true;
}
private GitObjectId ResolveReference(object reference)
{
if (reference is string)
{
if (!FileHelpers.TryOpen(Path.Combine(this.CommonDirectory, (string)reference), out FileStream? stream))
{
return GitObjectId.Empty;
}
using (stream)
{
Span<byte> objectId = stackalloc byte[40];
stream!.Read(objectId);
return GitObjectId.ParseHex(objectId);
}
}
else if (reference is GitObjectId)
{
return (GitObjectId)reference;
}
else
{
throw new GitException();
}
}
private GitPack[] LoadPacks()
{
var packDirectory = Path.Combine(this.ObjectDirectory, "pack/");
if (!Directory.Exists(packDirectory))
{
return Array.Empty<GitPack>();
}
var indexFiles = Directory.GetFiles(packDirectory, "*.idx");
GitPack[] packs = new GitPack[indexFiles.Length];
for (int i = 0; i < indexFiles.Length; i++)
{
var name = Path.GetFileNameWithoutExtension(indexFiles[i]);
packs[i] = new GitPack(this, name);
}
return packs;
}
private static string TrimEndingDirectorySeparator(string path)
{
#if NETSTANDARD
if (string.IsNullOrEmpty(path) || path.Length == 1)
{
return path;
}
var last = path[path.Length - 1];
if (last == Path.DirectorySeparatorChar || last == Path.AltDirectorySeparatorChar)
{
return path.Substring(0, path.Length - 1);
}
return path;
#else
return Path.TrimEndingDirectorySeparator(path);
#endif
}
private static byte[] ConvertHexStringToByteArray(string hexString)
{
// https://stackoverflow.com/questions/321370/how-can-i-convert-a-hex-string-to-a-byte-array
if (hexString.Length % 2 != 0)
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The binary key cannot have an odd number of digits: {0}", hexString));
}
byte[] data = new byte[hexString.Length / 2];
for (int index = 0; index < data.Length; index++)
{
string byteValue = hexString.Substring(index * 2, 2);
data[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
}
return data;
}
/// <summary>
/// Decodes a sequence of bytes from the specified byte array into a <see cref="string"/>.
/// </summary>
/// <param name="bytes">
/// The span containing the sequence of UTF-8 bytes to decode.
/// </param>
/// <returns>
/// A <see cref="string"/> that contains the results of decoding the specified sequence of bytes.
/// </returns>
public static unsafe string GetString(ReadOnlySpan<byte> bytes)
{
fixed (byte* pBytes = bytes)
{
return Encoding.GetString(pBytes, bytes.Length);
}
}
}
}