Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
Use filename for content filter instead of random name
Browse files Browse the repository at this point in the history
This allows to do different processing based on the filename.
For some files it might be necessary not to do any replacements.
  • Loading branch information
ermshiperete committed Oct 2, 2012
1 parent 768bd5b commit fb425ca
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions git-p4
Expand Up @@ -1430,18 +1430,18 @@ class P4Sync(Command):
# on stdin. It can output a modified path on stdout, or return an empty string to ignore this file.
# The msg filter is a script that gets the commit message on stdin and returns
# a modified commit message.
# The content filter gets called for text files and is passed the name of a temporary file on stdin and can modify that.
# The content filter gets called for text files and is passed the name of the file on stdin and can modify that.
filterProc = subprocess.Popen(filter, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, env=env, cwd=cwd)
output = filterProc.communicate(path)[0]
return output.rstrip()

def applyContentFilter(self, filter, data):
def applyContentFilter(self, filter, path, data):
if not filter:
return data

tmpfile = tempfile.NamedTemporaryFile(dir=self.contentFilterDir, delete=False)
fileName = "%s/%s" % (self.contentFilterDir, os.path.basename(path))
tmpfile = open(fileName, "w+")
try:
fileName = tmpfile.name
tmpfile.write(data)
tmpfile.close()
env = os.environ.copy()
Expand Down Expand Up @@ -1564,7 +1564,7 @@ class P4Sync(Command):

# apply content filter
if f["type"].endswith("text"):
data = self.applyContentFilter(self.contentFilter, data)
data = self.applyContentFilter(self.contentFilter, relPath, data)

if data == None:
errorFile = open("git-p4-errors", "a")
Expand Down

0 comments on commit fb425ca

Please sign in to comment.