jedbrown / git-fat

Simple way to handle fat files without committing them to git, supports synchronization using rsync
BSD 2-Clause "Simplified" License
621 stars 137 forks source link

Python 3.3 incompatibility #6

Closed qwindelzorf closed 11 years ago

qwindelzorf commented 11 years ago

git-fat seems not to work under python 3.3 (at least on x64 windows 7). Most of the issues were around determining string encoding. After a bit of tweaking, it seems to work with the attached changes. They're a bit of a hack, but they seem to get the job done.

diff --git a/git-fat b/git-fat
index 799a05a..bb79874 100755
--- a/git-fat
+++ b/git-fat
@@ -90,13 +90,13 @@ class GitFat(object):
         self.verbose = verbose_stderr if os.environ.get('GIT_FAT_VERBOSE') else verbose_ignore
         self.gitroot = subprocess.check_output('git rev-parse --show-toplevel'.split()).strip()
         self.gitdir = subprocess.check_output('git rev-parse --git-dir'.split()).strip()
-        self.objdir = os.path.join(self.gitdir, 'fat', 'objects')
+        self.objdir = os.path.join(self.gitdir.decode('utf-8'), "fat", "objects")
         if os.environ.get('GIT_FAT_VERSION') == '1':
             self.encode = self.encode_v1
         else:
             self.encode = self.encode_v2
         def magiclen(enc):
-            return len(enc(hashlib.sha1('dummy').hexdigest(), 5))
+            return len(enc(hashlib.sha1("dummy".encode('utf-8')).hexdigest(), 5))
         self.magiclen = magiclen(self.encode) # Current version
         self.magiclens = [magiclen(enc) for enc in [self.encode_v1, self.encode_v2]] # All prior versions
     def setup(self):
@@ -193,7 +193,7 @@ class GitFat(object):
                             ishanging = True              # Working tree version is verbatim from repository (not smudged)
                             outstream = outstreamclean
                         firstblock = False
-                    h.update(block)
+                    h.update(block.encode('utf-8'))
                     bytes += len(block)
                     outstream.write(block)
                 outstream.flush()
@@ -399,7 +399,7 @@ class GitFat(object):
         time1 = time.time()
         self.verbose('Found %d paths in %.3f s' % (len(pathsizes), time1-time0))
         maxlen = max(map(len,pathsizes)) if pathsizes else 0
-        for path, sizes in sorted(pathsizes.items(), cmp=lambda (p1,s1),(p2,s2): cmp(max(s1),max(s2)), reverse=True):
+        for path, sizes in sorted(pathsizes.items(), key=lambda item: item[1], reverse=True):
             print('%-*s filter=fat -text # %10d %d' % (maxlen, path,max(sizes),len(sizes)))
         revlist.wait()
         difftree.wait()
jedbrown commented 11 years ago

Thanks for looking at this. Some comments:

  1. We want the block to be binary all along (never decoded).
  2. You can use b'dummy'.
  3. The last change should use max(item[1]) because a given path could have assumed many different sizes and we want to use the largest as our sorting criteria.

If you can prepare a pull request that takes the above into account, I'll merge it.