Skip to content

Instantly share code, notes, and snippets.

@villadora
Last active December 10, 2015 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save villadora/4379565 to your computer and use it in GitHub Desktop.
Save villadora/4379565 to your computer and use it in GitHub Desktop.
git-p4 source code

git-p4.py

  • p4_build_cmd: 执行p4 commands时,用户可能并不希望在当前默认的环境下执行,而希望指定user, client等信息,而为了统一,并且省去每次都要输入一大堆p4参数的困扰,git-p4在对所有的p4 command ...调用都用p4_build_cmd进行包装,加上-u|-c|-p等参数。而这些参数又都是从gitConfig中获得的

  • gitConfig:这个方法很简单,只是利用git config命令获取属性的值并缓存到_gitConfig这个hash map中。git-p4利用了git自己的config设置来储存相关属性,如:'git-p4.user','git-p4.port','git-p4.client'等,这些属性都是以git-p4开头,方便进行管理。

  • main: 这个是程序的主入口,他的工作是分析命令行,获得要执行的命令,之后把控制转移到相关的类中。main里面用comands这样一个hash map来进行控制的跳转。

    commands = {
    "debug" : P4Debug,
    "submit" : P4Submit,
    "commit" : P4Submit,
    "sync" : P4Sync,
    "rebase" : P4Rebase,
    "clone" : P4Clone,
    "rollback" : P4RollBack, "branches" : P4Branches }

    所有的命令都被转换成了相应的task,而每个task都有一个run方法,而main则在分析完参数,设置好环境之后就调用合适的command的 run方法。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment