Echo
Echo

Reputation: 3029

Fetch the the path of a file at changeset without using the workspace

I am searching for a .txt file that is located at change set. Then I need to create locally over my pc the full path directory of this file.

For example if there a file called"test.txt" that it's located at: Project1-->Folder1-->Folder2-->test.txt

Till now I have managed to search for this file. Now I need to fetch the full directory and create similar one over my pc: Result at my pc: Folder1-->Folder2-->test.txt

That's what I did to search for the file within a changeset and retrieve it:

public IFileItem getTextFileFile(IChangeSet changeSet, ITeamRepository repository) throws TeamRepositoryException{
    IVersionableManager vm = SCMPlatform.getWorkspaceManager(repository).versionableManager();
    List changes = changeSet.changes();
    IFileItem toReturn = null;
    for(int i=0;i<changes.size();i++) {="" <br="">             Change change = (Change) changes.get(i);
        IVersionableHandle after = change.afterState();
        if( after != null && after instanceof IFileItemHandle) {
            IFileItem fileItem = (IFileItem) vm.fetchCompleteState(after, null);
            if(fileItem.getName().contains(".txt")) {
                   toReturn = fileItem;
                   break;
            } else {
               continue;
            }
        }
    }
    if(toReturn == null){
        throw new TeamRepositoryException("Could not find the file");
    }
    return toReturn;
}

I have searched & posted at the forums and most of things I found is that I can use: configuration.determineAncestorsInHistory

However in order to get the IConfiguration,I need for workspaceConnection which is not valid at my case.

Thanks.

I use RTC:4 Win:XP

Thanks in advance.

Upvotes: 1

Views: 642

Answers (1)

Andrew Niefer
Andrew Niefer

Reputation: 4309

Files/Folders have an identity that is independent of their name/path. This allows tracking the file across renames/moves. The name/path of the file can be different depending on the history of changes made to that file (or to the containing folders).

This means that if you don't have a workspace (or a baseline) which points to the specific point in history that you care about, then you can't be sure what the path actually is. The IConfiguration.determineAncestorsInHistory is really the only way to get the path.

There is an algorithm buried deep in the server that makes a guess at a "popular" path for the file but this is not exposed anywhere.

Upvotes: 1

Related Questions