Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F12661519
ArcanistRepositoryAPI.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
ArcanistRepositoryAPI.php
View Options
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Interfaces with the VCS in the working copy.
*
* @group workingcopy
*/
abstract
class
ArcanistRepositoryAPI
{
const
FLAG_MODIFIED
=
1
;
const
FLAG_ADDED
=
2
;
const
FLAG_DELETED
=
4
;
const
FLAG_UNTRACKED
=
8
;
const
FLAG_CONFLICT
=
16
;
const
FLAG_MISSING
=
32
;
const
FLAG_UNSTAGED
=
64
;
const
FLAG_UNCOMMITTED
=
128
;
const
FLAG_EXTERNALS
=
256
;
// Occurs in SVN when you replace a file with a directory without telling
// SVN about it.
const
FLAG_OBSTRUCTED
=
512
;
// Occurs in SVN when an update was interrupted or failed, e.g. you ^C'd it.
const
FLAG_INCOMPLETE
=
1024
;
protected
$path
;
protected
$diffLinesOfContext
=
0x7FFF
;
abstract
public
function
getSourceControlSystemName
();
public
function
getDiffLinesOfContext
()
{
return
$this
->
diffLinesOfContext
;
}
public
function
setDiffLinesOfContext
(
$lines
)
{
$this
->
diffLinesOfContext
=
$lines
;
return
$this
;
}
public
static
function
newAPIFromWorkingCopyIdentity
(
ArcanistWorkingCopyIdentity
$working_copy
)
{
$root
=
$working_copy
->
getProjectRoot
();
if
(!
$root
)
{
throw
new
ArcanistUsageException
(
"There is no readable '.arcconfig' file in the working directory or "
.
"any parent directory. Create an '.arcconfig' file to configure arc."
);
}
// check if we're in an svn working copy
list
(
$err
)
=
exec_manual
(
'svn info'
);
if
(!
$err
)
{
return
newv
(
'ArcanistSubversionAPI'
,
array
(
$root
));
}
if
(
Filesystem
::
pathExists
(
$root
.
'/.hg'
))
{
return
newv
(
'ArcanistMercurialAPI'
,
array
(
$root
));
}
$git_root
=
self
::
discoverGitBaseDirectory
(
$root
);
if
(
$git_root
)
{
if
(!
Filesystem
::
pathsAreEquivalent
(
$root
,
$git_root
))
{
throw
new
ArcanistUsageException
(
"'.arcconfig' file is located at '{$root}', but working copy root "
.
"is '{$git_root}'. Move '.arcconfig' file to the working copy root."
);
}
return
newv
(
'ArcanistGitAPI'
,
array
(
$root
));
}
throw
new
ArcanistUsageException
(
"The current working directory is not part of a working copy for a "
.
"supported version control system (svn, git or mercurial)."
);
}
public
function
__construct
(
$path
)
{
$this
->
path
=
$path
;
}
public
function
getPath
(
$to_file
=
null
)
{
if
(
$to_file
!==
null
)
{
return
$this
->
path
.
'/'
.
ltrim
(
$to_file
,
'/'
);
}
else
{
return
$this
->
path
.
'/'
;
}
}
public
function
getUntrackedChanges
()
{
return
$this
->
getWorkingCopyFilesWithMask
(
self
::
FLAG_UNTRACKED
);
}
public
function
getUnstagedChanges
()
{
return
$this
->
getWorkingCopyFilesWithMask
(
self
::
FLAG_UNSTAGED
);
}
public
function
getUncommittedChanges
()
{
return
$this
->
getWorkingCopyFilesWithMask
(
self
::
FLAG_UNCOMMITTED
);
}
public
function
getMergeConflicts
()
{
return
$this
->
getWorkingCopyFilesWithMask
(
self
::
FLAG_CONFLICT
);
}
public
function
getIncompleteChanges
()
{
return
$this
->
getWorkingCopyFilesWithMask
(
self
::
FLAG_INCOMPLETE
);
}
private
function
getWorkingCopyFilesWithMask
(
$mask
)
{
$match
=
array
();
foreach
(
$this
->
getWorkingCopyStatus
()
as
$file
=>
$flags
)
{
if
(
$flags
&
$mask
)
{
$match
[]
=
$file
;
}
}
return
$match
;
}
private
static
function
discoverGitBaseDirectory
(
$root
)
{
try
{
// NOTE: This awkward construction is to make sure things work on Windows.
$future
=
new
ExecFuture
(
'git rev-parse --show-cdup'
);
$future
->
setCWD
(
$root
);
list
(
$stdout
)
=
$future
->
resolvex
();
return
Filesystem
::
resolvePath
(
rtrim
(
$stdout
,
"
\n
"
),
$root
);
}
catch
(
CommandException
$ex
)
{
if
(
preg_match
(
'/^fatal: Not a git repository/'
,
$ex
->
getStdErr
()))
{
return
null
;
}
throw
$ex
;
}
}
abstract
public
function
getBlame
(
$path
);
abstract
public
function
getWorkingCopyStatus
();
abstract
public
function
getRawDiffText
(
$path
);
abstract
public
function
getOriginalFileData
(
$path
);
abstract
public
function
getCurrentFileData
(
$path
);
abstract
public
function
getLocalCommitInformation
();
abstract
public
function
getSourceControlBaseRevision
();
abstract
public
function
getCanonicalRevisionName
(
$string
);
abstract
public
function
supportsRelativeLocalCommits
();
abstract
public
function
getWorkingCopyRevision
();
abstract
public
function
loadWorkingCopyDifferentialRevisions
(
ConduitClient
$conduit
,
array
$query
);
public
function
hasLocalCommit
(
$commit
)
{
throw
new
ArcanistCapabilityNotSupportedException
(
$this
);
}
public
function
getCommitMessageForRevision
(
$revision
)
{
throw
new
ArcanistCapabilityNotSupportedException
(
$this
);
}
public
function
parseRelativeLocalCommit
(
array
$argv
)
{
throw
new
ArcanistCapabilityNotSupportedException
(
$this
);
}
public
function
getAllLocalChanges
()
{
throw
new
ArcanistCapabilityNotSupportedException
(
$this
);
}
abstract
public
function
supportsLocalBranchMerge
();
public
function
performLocalBranchMerge
(
$branch
,
$message
)
{
throw
new
ArcanistCapabilityNotSupportedException
(
$this
);
}
public
function
getFinalizedRevisionMessage
()
{
throw
new
ArcanistCapabilityNotSupportedException
(
$this
);
}
public
function
execxLocal
(
$pattern
/*, ... */
)
{
$args
=
func_get_args
();
return
$this
->
buildLocalFuture
(
$args
)->
resolvex
();
}
public
function
execManualLocal
(
$pattern
/*, ... */
)
{
$args
=
func_get_args
();
return
$this
->
buildLocalFuture
(
$args
)->
resolve
();
}
abstract
protected
function
buildLocalFuture
(
array
$argv
);
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 28, 15:46 (23 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1083410
Default Alt Text
ArcanistRepositoryAPI.php (6 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment