-
Notifications
You must be signed in to change notification settings - Fork 534
Conversation
|
||
func validateHeader(r io.Reader) (version uint32, err error) { | ||
var s = make([]byte, 4) | ||
if _, err := r.Read(s); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be a ReadFull.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, fixing it
return nil, err | ||
} | ||
|
||
read := 62 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a magic number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, fixing it
e.Stage = Stage(e.Flags>>12) & 0x3 | ||
|
||
if e.Flags&EntryExtended != 0 { | ||
read += 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this and all other magic numbers by making readBinary return the number of bytes read.
|
||
if err := d.readEntryName(idx, e); err != nil { | ||
return nil, err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, fixing it
name, err = d.doReadEntryName(e) | ||
case 4: | ||
name, err = d.doReadEntryNameV4() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version is a public field, there should be a default in this switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, fixing it
var buf [1]byte | ||
value := make([]byte, 0, 16) | ||
for { | ||
if _, err := r.Read(buf[:]); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadFull or check n!=0 then continue with a sleep or something.
|
||
func readUntil(r io.Reader, delim byte) ([]byte, error) { | ||
var buf [1]byte | ||
value := make([]byte, 0, 16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you choose 16 as a good initial size?
|
||
e.Entries = i | ||
|
||
trees, err := readUntil(d.r, 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NO WAY, use \n
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hahaha
return nil, err | ||
} | ||
|
||
return e, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you replace all this function with fmt.Fscanf(d.r, "%s\x00%d %s\n%s" &e.Path, &e.Entries, &e.Tree, &e.Hash)
? or some other one-liner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic now is a bit more complex, so... I prefer not
} | ||
} | ||
|
||
// dheader[pos] = ofs & 127; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last 30 lines look familiar, didn't we have code this before?
This comment must be explained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep don't worry I am making another PR creating a package for binary reads
func (d *TreeExtensionDecoder) readEntry() (*TreeEntry, error) { | ||
e := &TreeEntry{} | ||
|
||
path, err := readUntil(d.r, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason using an integer here sounds weird, I think it will be much better if you use \x00
here as the delimiter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solved
* utils: fs generic TestSuite * fs: fs.TempFile * utils: fs small changes requested * utils: fs, test fs.Create overwriting files * formats: index, basic v2 reader * formats: index, tree extension support * formats: index, stage decoding * formats: index, extended flags, v3 support * formats: index, v4 support * formats: index, Resolve undo support * formats: index, fix error when decoding invalidated entries * formats: index, fix style issues
This is a basic implementation of the Index format
The index format contains the information about which objects are currently checked out in the worktree, having information about the working files. Changes in worktree are detected using this Index. The Index is also used during merge.
Three types of version are available 2, 3 and 4, this implementation only supports 2, and I am planning to add support for version 3 and 4, in this same PR
This format also have several extensions, this implementation only have the cache Tree extension.
So the pending stuff is:
Flags
andMode
Resolve undo
extensionUntracked cache
extensionI must say that this is one of the most complex format in git
UPDATE: I am not implementing
Split Index
andUntracked cache
extensions because are not supported by libgit or jgit, also because are optional and arcane extension. The reader is ready for review