aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/diff_delta.go
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/format/packfile/diff_delta.go')
-rw-r--r--plumbing/format/packfile/diff_delta.go44
1 files changed, 13 insertions, 31 deletions
diff --git a/plumbing/format/packfile/diff_delta.go b/plumbing/format/packfile/diff_delta.go
index 7a32d5d..fb05a79 100644
--- a/plumbing/format/packfile/diff_delta.go
+++ b/plumbing/format/packfile/diff_delta.go
@@ -134,39 +134,21 @@ func encodeCopyOperation(offset, length int) []byte {
code := 0x80
var opcodes []byte
- if offset&0xff != 0 {
- opcodes = append(opcodes, byte(offset&0xff))
- code |= 0x01
- }
-
- if offset&0xff00 != 0 {
- opcodes = append(opcodes, byte((offset&0xff00)>>8))
- code |= 0x02
- }
-
- if offset&0xff0000 != 0 {
- opcodes = append(opcodes, byte((offset&0xff0000)>>16))
- code |= 0x04
- }
-
- if offset&0xff000000 != 0 {
- opcodes = append(opcodes, byte((offset&0xff000000)>>24))
- code |= 0x08
- }
-
- if length&0xff != 0 {
- opcodes = append(opcodes, byte(length&0xff))
- code |= 0x10
- }
-
- if length&0xff00 != 0 {
- opcodes = append(opcodes, byte((length&0xff00)>>8))
- code |= 0x20
+ var i uint
+ for i = 0; i < 4; i++ {
+ f := 0xff << (i * 8)
+ if offset&f != 0 {
+ opcodes = append(opcodes, byte(offset&f>>(i*8)))
+ code |= 0x01 << i
+ }
}
- if length&0xff0000 != 0 {
- opcodes = append(opcodes, byte((length&0xff0000)>>16))
- code |= 0x40
+ for i = 0; i < 3; i++ {
+ f := 0xff << (i * 8)
+ if length&f != 0 {
+ opcodes = append(opcodes, byte(length&f>>(i*8)))
+ code |= 0x10 << i
+ }
}
return append([]byte{byte(code)}, opcodes...)