触发以自动删除EOL空格? [英] Trigger to automatically remove EOL whitespace?

查看:109
本文介绍了触发以自动删除EOL空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以编写一个perforce触发器来在提交时自动删除空格吗?最好在python中?那会是什么样?还是不能在提交文件时对其进行修改?

Can one write a perforce trigger to automatically remove whitespace at submission time? Preferably in python? What would that look like? Or can you not modify files as they're being submitted?

推荐答案

据我所知,这无法完成,因为您不能放修改后的文件内容返回给服务器。仅有的两个触发类型可让您查看带有 p4打印的文件内容是更改内容更改提交。对于后者,文件已经在服务器上提交了,对于前者,虽然您可以看到(未提交的)文件内容,但是无法修改它并将其放回到服务器上。

To my knowledge this cannot be done, since you cannot put the modified file-content back to the server. The only two trigger types that allow you to see the file-content with p4 print are change-content and change-commit. For the latter, the files are already submitted on the server and for the former, while you can see the (unsubmitted) file content, there is no way to modify it and put it back on the server.

唯一可能的触发条件是拒绝要提交的带有EOL空格的文件,以便提交者可以自己修复文件。这是检查文件中选项卡的类似摘录的一部分,请阅读有关触发器的文档,并查看Perforce网站上的示例:

The only trigger that is possible is to reject files with EOL whitespace to be submitted, so that the submitters can fix the files on their own. Here is an excerpt of a similar one that checks for tabs in files, please read the docu on triggers and look at the Perforce site for examples:

def fail(sComment):
  print sComment
  sys.exit(1)
  return

sCmd = "p4 -G files //sw/...@=%s" % sChangeNr

stream = os.popen(sCmd, 'rb')
dictResult = []
try:
  while 1:
   dictResult.append(marshal.load(stream))
except EOFError:
  pass

stream.close()


failures = []
# check all files for tabs
for element in dictResult:
  depotFile =  element['depotFile']

sCmd = "p4 print -q %s@=%s" % (depotFile,sChangeNr)
content = os.popen(sCmd, 'rb').read()
if content.find('\t') != -1:
  failures.append(depotFile)

if len(failures) != 0:
  error = "Files contain tabulators (instead of spaces):\n"
  for i in failures:
    error = error + str(i) + "\n"
  fail(error)

这篇关于触发以自动删除EOL空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆