Skip to content

User: Pattern

ccc edited this page Sep 29, 2018 · 3 revisions

krep handles different cases on the heads and tags of git repositories. If there's a simply used implementation, it'll satisfy the tool and the framework with the elemental requirements including:

  1. Function match and non-match
  2. Function replacement

The two functions can be supported with Python regex. Thus, something called pattern is implemented.

Expression

krep supports lots of actions. The actions should be categorized with the actual behaviours. Several characters are defined with specified delimiters:

Ch Function
: Category delimiter
, Pattern delimiter
! Opposite delimiter
@ Name delimiter
~ Replacement delimiter
= Continuuous replacement delimiter

Effective patterns could be:

# Matching pattern(s)
p:git-repo
p:git-repo,tools/repo
# Replacement pattern
p:git-repo@~aosp~~
# Continuuous replacement patterns
p:LineageOS/.+@=LineageOS/android=android=,=android/device=device=

Here, p ahead of : of each line is defined as the category. Generally, the category project here is used by the sub-command git-p and repo for project name match and repository name replacement. The sub-commands would define their own categories and handle only the matched patterns.

The part after : is the name, which could be used in the process to narrow the matched projects - It can be set to match exactly project names. For exmaple p:git-repo@~aosp~~ will match the project with the name containing git-repo. And p:^git-repo$@~aosp~~ will match the project with the name is git-repo. If it's dismissed, it means to try matching for all projects generally.

The replacement rule define how to replace a matched string. The difference is how and when to stop processing rules. Thus, two delimiters are defined. With non-continuuous delimeter, once it's matched, the replacement process will be stopped and next patterns will be ignored at all.

Some interesting usages for the patterns applying to project can refer to the file lineage.xml, in which complicated pattern rules are used. For example, the pattern for projects leading with LineageOS/android_vendor_qcom_opensource_ will be reanmed.

<pattern
 name="LineageOS/android_vendor_qcom_opensource_"
 value="=LineageOS/android_=platform/=,=_=/=,=/qcom/opensource/=/qcom-opensource/=,~cryptfs/hw~cryptfs_hw~" />

Here it's tricky to use both continuuous replacement and non-continuuous replacement. Normally it's effective to convert all the gits like LineageOS/android_vendor_qcom_opensource_ to platform/vendor/qcom-opensource/ except the one LineageOS/android_vendor_qcom_opensource_cryptfs_hw to platform/vendor/qcom-opensource/cryptfs_hw, which has an extra underscore no to be changed.