Index: vc/p4.py
===================================================================
--- vc/p4.py	(revision 0)
+++ vc/p4.py	(revision 0)
@@ -0,0 +1,143 @@
+### Copyright (C) 2002-2005 Stephen Kennedy <stevek@gnome.org>
+### Copyright (C) 2008 Stephen Warren <s-t-meld@wwwdotorg.org>
+
+### Redistribution and use in source and binary forms, with or without
+### modification, are permitted provided that the following conditions
+### are met:
+### 
+### 1. Redistributions of source code must retain the above copyright
+###    notice, this list of conditions and the following disclaimer.
+### 2. Redistributions in binary form must reproduce the above copyright
+###    notice, this list of conditions and the following disclaimer in the
+###    documentation and/or other materials provided with the distribution.
+
+### THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+### IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+import re
+import errno
+import _vc
+
+class Vc(_vc.Vc):
+
+    CMD = "p4"
+    NAME = "Perforce"
+    PATCH_INDEX_RE = "^--- (.*)\t"
+
+    def __init__(self, location):
+        self.root = location
+        try:
+            # p4 binary looks at this if set, ignoring the real value.
+            # Python's os.chdir doesn't update this.
+            # diff_command() below isn't run with a full file-path.
+            # This make p4 not find the file to diff.
+            del os.environ['PWD']
+        except:
+            pass
+
+    def commit_command(self, message):
+        return [self.CMD, "submit", "-d", message]
+
+    def diff_command(self):
+        return ["meld-p4-diff"]
+
+    def update_command(self):
+        return [self.CMD, "sync"]
+
+    def add_command(self, binary=0):
+        return [self.CMD, "add"]
+
+    def remove_command(self, force=0):
+        return [self.CMD, "delete"]
+
+    def revert_command(self):
+        return [self.CMD, "revert"]
+
+    def _get_dirsandfiles(self, directory, dirs, files):
+        ret_files = {}
+
+        while True:
+            try:
+                entries = os.popen('p4 diff -sd "%s/*"' % directory).read()
+                break
+            except OSError, e:
+                if e.errno != errno.EAGAIN:
+                    raise
+
+        for path in entries.split("\n"):
+            if not path:
+                continue
+            name = os.path.split(path)[1]
+            ret_files[path] = _vc.File(path, name, _vc.STATE_MISSING, "", "", "")
+
+        while True:
+            try:
+                entries = os.popen('p4 diff -se "%s/*"' % directory).read()
+                break
+            except OSError, e:
+                if e.errno != errno.EAGAIN:
+                    raise
+
+        for path in entries.split("\n"):
+            if not path:
+                continue
+            name = os.path.split(path)[1]
+            ret_files[path] = _vc.File(path, name, _vc.STATE_MODIFIED, "", "", "")
+
+        while True:
+            try:
+                entries = os.popen('p4 fstat "%s/*"' % directory).read()
+                break
+            except OSError, e:
+                if e.errno != errno.EAGAIN:
+                    raise
+        entries += '... clientFile sentinel'
+
+        client_file = None
+        state = _vc.STATE_NORMAL
+        for line in entries.split("\n"):
+            if not line:
+                continue
+            if line.startswith('... clientFile '):
+                if client_file:
+                    path = client_file
+                    if not ret_files.has_key(path):
+                        name = os.path.split(path)[1]
+                        ret_files[path] = _vc.File(
+                            path,
+                            name,
+                            state,
+                            "",
+                            "",
+                            ""
+                        )
+
+                client_file = line[15:]
+                state = _vc.STATE_NORMAL
+            elif line.startswith('... action '):
+                action = line[11:]
+                state = {
+                    "add":    _vc.STATE_NEW,
+                    "delete": _vc.STATE_REMOVED,
+                    "edit":   _vc.STATE_MODIFIED
+                }.get(action, _vc.STATE_NORMAL)
+
+        for name, path in files:
+            if not ret_files.has_key(path):
+                ret_files[path] = _vc.File(path, name, _vc.STATE_NONE, "", "", "")
+
+        ret_dirs = {}
+        for name, path in dirs:
+            ret_dirs[path] = _vc.Dir(path, name, _vc.STATE_NORMAL)
+
+        return ret_dirs.values(), ret_files.values()
+
Index: meld-p4-diff
===================================================================
--- meld-p4-diff	(revision 0)
+++ meld-p4-diff	(revision 0)
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+p4 print -q "$1#have" | diff -u - "$1" | sed -e "s:^--- -:--- $1:"
+

Property changes on: meld-p4-diff
___________________________________________________________________
Name: svn:executable
   + *

