view hgext/inotify/common.py @ 19967:e92c6524a76d stable

largefiles: use 'remote'/'local' in merge prompts like in other merge prompts Prompts like foo has been turned into a largefile use (l)argefile or keep as (n)ormal file? was not as clear as the usual prompts that use 'remote' or 'local' to explain what happened on which side ... especially not when used to the normal prompts. "as" could also indicate that it would be possible to take the content of the largefile and somehow put it into the normal file. It could make it more clear that it was a choice between one side or the other. For consistency we will now phrase it like: remote turned local normal file f into a largefile use (l)argefile or keep (n)ormal file?
author Mads Kiilerich <madski@unity3d.com>
date Mon, 28 Oct 2013 22:34:07 +0100
parents 25e572394f5c
children
line wrap: on
line source

# server.py - inotify common protocol code
#
# Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com>
# Copyright 2007, 2008 Brendan Cully <brendan@kublai.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

import cStringIO, socket, struct

"""
  Protocol between inotify clients and server:

  Client sending query:
  1) send protocol version number
  2) send query type (string, 4 letters long)
  3) send query parameters:
     - For STAT, N+1 \0-separated strings:
        1) N different names that need checking
        2) 1 string containing all the status types to match
     - No parameter needed for DBUG

  Server sending query answer:
  1) send protocol version number
  2) send query type
  3) send struct.pack'ed headers describing the length of the content:
      e.g. for STAT, receive 9 integers describing the length of the
      9 \0-separated string lists to be read:
       * one file list for each lmar!?ic status type
       * one list containing the directories visited during lookup

"""

version = 3

resphdrfmts = {
    'STAT': '>lllllllll', # status requests
    'DBUG': '>l'          # debugging queries
}
resphdrsizes = dict((k, struct.calcsize(v))
                    for k, v in resphdrfmts.iteritems())

def recvcs(sock):
    cs = cStringIO.StringIO()
    s = True
    try:
        while s:
            s = sock.recv(65536)
            cs.write(s)
    finally:
        sock.shutdown(socket.SHUT_RD)
    cs.seek(0)
    return cs