Changeset 206283 in webkit


Ignore:
Timestamp:
Sep 22, 2016 6:14:59 PM (8 years ago)
Author:
matthew_hanson@apple.com
Message:

Add an API for getting the branch identifier from a Git or SVN checkout.
https://bugs.webkit.org/show_bug.cgi?id=151570
rdar://problem/17959831

Reviewed by David Kilzer.

This patch adds a function called svnIdentifierForPath. This function returns either "trunk",
the name of the tag, or the name of the branch, as appropriate. This function is necessary for
a VCSUtils client that is not checked in to the WebKit project.

This patch also breaks up pathRelativeToSVNRepositoryRootForPath into four functions:

  • pathRelativeToSVNRepositoryRootForPath
  • svnInfoForPath
  • svnURLForPath
  • svnRepositoryRootForPath

This allows us to reuse logic from pathRelativeToSVNRepositoryRootForPath in svnIdentifierForPath and
allows clients of VCSUtils to extract what arbitrary information from the svn info command regardless
of SCM.

  • Scripts/VCSUtils.pm:

(svnInfoForPath):
Copied logic that previously lived in pathRelativeToSVNRepositoryRootForPath.
Make code safe to use for a path, and not just for the CWD.

(svnURLForPath):
Calls svnInfoForPath and extracts the URL.

(svnRepositoryRootForPath):
Calls svnInfoForPath and extracts the Repository Root.

(svnIdentifierForPath):
Calls pathRelativeToSVNRepositoryRootForPath and extracts the repository identifier.

(pathRelativeToSVNRepositoryRootForPath):
Now uses svnURLForPath and svnRepositoryRootForPath instead of being responsible for
determining both values.

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r206282 r206283  
     12016-09-22  Matthew Hanson  <matthew_hanson@apple.com>
     2
     3        Add an API for getting the branch identifier from a Git or SVN checkout.
     4        https://bugs.webkit.org/show_bug.cgi?id=151570
     5        rdar://problem/17959831
     6
     7        Reviewed by David Kilzer.
     8
     9        This patch adds a function called svnIdentifierForPath. This function returns either "trunk",
     10        the name of the tag, or the name of the branch, as appropriate. This function is necessary for
     11        a VCSUtils client that is not checked in to the WebKit project.
     12
     13        This patch also breaks up pathRelativeToSVNRepositoryRootForPath into four functions:
     14        - pathRelativeToSVNRepositoryRootForPath
     15        - svnInfoForPath
     16        - svnURLForPath
     17        - svnRepositoryRootForPath
     18
     19        This allows us to reuse logic from pathRelativeToSVNRepositoryRootForPath in svnIdentifierForPath and
     20        allows clients of VCSUtils to extract what arbitrary information from the `svn info` command regardless
     21        of SCM.
     22
     23        * Scripts/VCSUtils.pm:
     24        (svnInfoForPath):
     25        Copied logic that previously lived in pathRelativeToSVNRepositoryRootForPath.
     26        Make code safe to use for a path, and not just for the CWD.
     27
     28        (svnURLForPath):
     29        Calls svnInfoForPath and extracts the URL.
     30
     31        (svnRepositoryRootForPath):
     32        Calls svnInfoForPath and extracts the Repository Root.
     33
     34        (svnIdentifierForPath):
     35        Calls pathRelativeToSVNRepositoryRootForPath and extracts the repository identifier.
     36
     37        (pathRelativeToSVNRepositoryRootForPath):
     38        Now uses svnURLForPath and svnRepositoryRootForPath instead of being responsible for
     39        determining both values.
     40
    1412016-09-22  Megan Gardner  <megan_gardner@apple.com>
    242
  • trunk/Tools/Scripts/VCSUtils.pm

    r204549 r206283  
    8888        &scmToggleExecutableBit
    8989        &setChangeLogDateAndReviewer
     90        &svnIdentifierForPath
     91        &svnInfoForPath
     92        &svnRepositoryRootForPath
    9093        &svnRevisionForDirectory
    9194        &svnStatus
     95        &svnURLForPath
    9296        &toWindowsLineEndings
    9397        &gitCommitForSVNRevision
     
    445449}
    446450
    447 sub pathRelativeToSVNRepositoryRootForPath($)
     451sub svnInfoForPath($)
    448452{
    449453    my ($file) = @_;
     
    451455
    452456    my $svnInfo;
    453     if (isSVN()) {
     457    if (isSVNDirectory($file)) {
    454458        my $escapedRelativePath = escapeSubversionPath($relativePath);
    455459        my $command = "svn info $escapedRelativePath";
    456460        $command = "LC_ALL=C $command" if !isWindows();
    457461        $svnInfo = `$command`;
    458     } elsif (isGit()) {
    459         my $command = "git svn info $relativePath";
     462    } elsif (isGitDirectory($file)) {
     463        my $command = "git svn info";
    460464        $command = "LC_ALL=C $command" if !isWindows();
    461         $svnInfo = `$command`;
    462     }
     465        $svnInfo = `cd $relativePath && $command`;
     466    }
     467
     468    return $svnInfo;
     469}
     470
     471sub svnURLForPath($)
     472{
     473    my ($file) = @_;
     474    my $svnInfo = svnInfoForPath($file);
    463475
    464476    $svnInfo =~ /.*^URL: (.*?)$/m;
    465     my $svnURL = $1;
     477    return $1;
     478}
     479
     480sub svnRepositoryRootForPath($)
     481{
     482    my ($file) = @_;
     483    my $svnInfo = svnInfoForPath($file);
    466484
    467485    $svnInfo =~ /.*^Repository Root: (.*?)$/m;
    468     my $repositoryRoot = $1;
    469 
    470     $svnURL =~ s/$repositoryRoot\///;
     486    return $1;
     487}
     488
     489sub pathRelativeToSVNRepositoryRootForPath($)
     490{
     491    my ($file) = @_;
     492
     493    my $svnURL = svnURLForPath($file);
     494    my $svnRepositoryRoot = svnRepositoryRootForPath($file);
     495
     496    $svnURL =~ s/$svnRepositoryRoot\///;
    471497    return $svnURL;
     498}
     499
     500sub svnIdentifierForPath($)
     501{
     502    my ($file) = @_;
     503    my $path = pathRelativeToSVNRepositoryRootForPath($file);
     504
     505    $path =~ /^(trunk)|tags\/([\w\.\-]*)|branches\/([\w\.\-]*).*$/m;
     506    return $1 || $2 || $3;
    472507}
    473508
Note: See TracChangeset for help on using the changeset viewer.