mercurial/util.py
changeset 23789 94951db84fc0
parent 23543 4dd8a6a1240d
child 23832 62f41f251e52
--- a/mercurial/util.py	Sat Jan 10 21:13:10 2015 -0600
+++ b/mercurial/util.py	Sat Jan 10 21:18:31 2015 -0600
@@ -19,7 +19,7 @@
 import errno, shutil, sys, tempfile, traceback
 import re as remod
 import os, time, datetime, calendar, textwrap, signal, collections
-import imp, socket, urllib
+import imp, socket, urllib, struct
 import gc
 
 if os.name == 'nt':
@@ -229,6 +229,15 @@
 import subprocess
 closefds = os.name == 'posix'
 
+def unpacker(fmt):
+    """create a struct unpacker for the specified format"""
+    try:
+        # 2.5+
+        return struct.Struct(fmt).unpack
+    except NameError:
+        # 2.4
+        return lambda buf: struct.unpack(fmt)
+
 def popen2(cmd, env=None, newlines=False):
     # Setting bufsize to -1 lets the system decide the buffer size.
     # The default for bufsize is 0, meaning unbuffered. This leads to