I am writing a program, where i have the CL ,from which I need to access the previoius revision CL of each file.
How can I get it ?
Code I have written till now is:
IChangelist cl = server.getChangelist(clId);
List<IFileSpec> files = cl.getFiles(true);
for(int i = 0; i < files.size() ; i++) {
IFileSpec fileSpec=files.get(i);
}
Revision specifiers can help you here (see 'p4 help revisions').
In particular, the previous revision of each of those files is the file as of the previous changelist.
So, since clId is the changelist you care about, compute change clPrev = (clId - 1), and then look for 'file#clPrev'.
Related
I am creating a custom renameParticpant to rename an Eclipse project's launch configuration files, and to change the APPNAME variable in the Makefile. The Makefile side works 100% of the time, but attempting to rename the launch configs causes the following error to occur:
<FATALERROR
FATALERROR: No input element provided
Context: <Unspecified context>
code: none
Data: null
>
This error occurs when the changes are being validated at the following line in org.eclipse.ltk.core.refactoring.PerformChangeOperation [line: 248].
fValidationStatus= fChange.isValid(new SubProgressMonitor(monitor, 1));
Below is a screenshot of the variable view. I suspect that my compositeChange is not in the correct format or is missing some information, however; the error dialogue and logs don't give any helpful information.
Debugger variable view of fChanges
The following is relevant code snippets:
// This one sparks joy (it works great, 100% success)
final HashMap<IFile, TextFileChange> textChanges = new HashMap<IFile, TextFileChange>();
// Stuff gets put inside
textChanges.put(makefile, changeAppname);
// This one does not spark joy (it runs, but results in an invalid Change)
final HashMap<IFile, RenameResourceChange> renameChanges = new HashMap<IFile, RenameResourceChange>();
// Stuff gets put inside
RenameResourceChange renameChange = new RenameResourceChange(
launch.getFile().getProjectRelativePath(), newLaunchName);
renameChanges.put(launch.getFile(), renameChange);
// This is where they get added to the hashmap.
CompositeChange result;
if (textChanges.isEmpty() && renameChanges.isEmpty()) {
result = null;
} else {
result = new CompositeChange(
String.format("Rename project references and dependencies for %1$s", proj.getName()));
for (Iterator<TextFileChange> iter = textChanges.values().iterator(); iter.hasNext();) {
result.add(iter.next());
}
for (Iterator<RenameResourceChange> iter = renameChanges.values().iterator(); iter.hasNext();) {
result.add(iter.next());
}
}
return result;
I looked into adding or generating a changeDescriptor, however that seems like the wrong approach.
I'm using this code to create a powerpoint with changed files:
try (Git git = new Git(repo)) {
DiffFormatter df = new DiffFormatter(NullOutputStream.INSTANCE);
df.setRepository( git.getRepository() );
Iterable<RevCommit> commits = git.log().all().call();
for (RevCommit commit : commits) {
if(commit.getParents().length != 0) {
System.out.println("LogCommit: " + commit);
List<DiffEntry> entries = df.scan(commit.getId(), commit.getParent(0).getId());
for( DiffEntry entry : entries ) {
String filename = entry.getPath(DiffEntry.Side.NEW);
if(!filename.equals("/dev/null")) {
Integer currentCount = 0;
if(fileChanges.containsKey(filename)) {
currentCount = fileChanges.get(filename);
}else {
System.out.println(" DiffEntry: " +entry.getPath(DiffEntry.Side.NEW));
}
fileChanges.put(filename, new Integer(currentCount + 1));
}
}
}
}
}
However when I run it on a repo:
org.eclipse.jgit.api.errors.NoHeadException: No HEAD exists and no explicit starting revision was specified
at org.eclipse.jgit.api.LogCommand.call(LogCommand.java:154)
at .GitAccessor.getFilesChanged(GitAccessor.java:47)
at Main.main(Main.java:45)
I've tried to replicate it (since it is on a client's machine) by making this repo without a master:
https://github.com/davidahines/no_master
I've tried deleting the HEAD, ORIG_HEAD, and FETCH_HEAD and still can't seem to get this error.
I think what I need to do is bypass this check somehow, or find another head within the refs folder but I can't find that within jgit.
I don't currently have access to the client's repo because it is closed source.
The problem was that jgit doesn't support the tilde shortcut for /home/username, once that was removed it worked.
Context: My merge ran into conflicts and I have a file like this example:
Foo.txt (merged)
1
<<<<<< HEAD
2-master
======
2-side
>>>>>> df803849788fde47965b3dc8f07f07d48320ea9c
3
Question: In order to get the developers who actually changed the conflicting lines, how to blame result file (above) prior to the commit? It works for git blame Foo.txt
Problem: I tried to do the following, but the blame is null inside the loop.
MergeResult m = runMerge(aScenario);
BlameCommand blamer = new BlameCommand(git.getRepository());
BufferedReader br = new BufferedReader(new FileReader(new File(mergedfilepath)));
BlameResult blame = blamer.setFilePath(mergedfilepath).call();
for (int i = 0; (line= br.readLine())!=null ; i++) {
// the blame at this point is null.
PersonIdent person = blame.getSourceAuthor(i);
System.out.println(person.getName() + ": "+ line);
}
I think the source of the traversal should be the result contents.
Starting from there you can loop over the changed regions and ask for the author. For example:
BlameResult blameResult = git.blame().setFilePath( ... ).call();
int size = blameResult.getResultContents().size();
for( int i = 0; i < size; i++ ) {
System.out.println( blameResult.getSourceAuthor( i ) );
}
At least for lines added to the work directory version of the file, an author named Not Committed Yet is returned.
However, your code should be prepared cope with getSourceAuthor() returning null. The JavaDoc states that the return value may be null.
I'm currently making an app which reads from text files and then does cool stuff with the words inside it. Now I unfortunately have the problem that Eclipse can't seem to find/open the text files. Since this is my first app I am not 100% sure if I did the whole "putting-files-in-eclipse"-thing correctly.
Here are two screenshots that pretty much sum up the whole problem:
Error message when the method is executed
My directories look like this.
I already wrote another program where I used similar pathing and everything worked fine.
Here's the code: (elemArray contains "wi", "wa", "f", "l", "d")
String[] elemArray = elems.toArray(new String[0]);
for(int i = 0; i < 5; ++i){
for(int l = 3; l < 6; ++l){
checkFile = new Scanner(new File("texts/" + elemArray[i] + "monster" + l + ".txt")).useDelimiter(",\\s*");
.
.
. does some other irrelevant stuff here
What am I doing wrong?
From the available information I suspect a working directory mismatch.
Working Directory
Your working directory when launching your Java program is not what you expect. The new File("texts/" [...] will create a relative path.
You can specify the working directory in the Launch Configuration in the Arguments tab near the bottom in the Working directory: section:
Test/Debug
Extract the new File("texts/" [...] to a variable (it is quite a long line as it is). You can add an expression of f.getAbsoluteFile() to ensure it resolves as expected.
i.e. rewrite like this (I would probably extract the string passed to new File() too BTW):
String[] elemArray = elems.toArray(new String[0]);
for(int i = 0; i < 5; ++i){
for(int l = 3; l < 6; ++l){
File f = new File("texts/" + elemArray[i] + "monster" + l + ".txt");
checkFile = new Scanner(f).useDelimiter(",\\s*");
I'm finishing a business card production flow (excel > xml > indesign > single page pdfs) and I would like to insert the employees' names in the filenames.
What I have now:
BusinessCard_01_Blue.pdf
BusinessCard_02_Blue.pdf
BusinessCard_03_Blue.pdf (they are gonna go up to the hundreds)
What I need (I can manipulate the name list with regex easily):
BusinessCard_01_CarlosJorgeSantos_Blue.pdf
BusinessCard_02_TaniaMartins_Blue.pdf
BusinessCard_03_MarciaLima_Blue.pdf
I'm a Java and Python toddler. I've read the related questions, tried this in Automator (Mac) and Name Mangler, but couldn't get it to work.
Thanks in advance,
Gus
Granted you have a map where to look at the right name you could do something like this in Java:
List<Files> originalFiles = ...
for( File f : originalFiles ) {
f.renameTo( new File( getNameFor( f ) ) );
}
And define the getNameFor to something like:
public String getNameFor( File f ) {
Map<String,String> namesMap = ...
return namesMap.get( f.getName() );
}
In the map you'll have the associations:
BusinessCard_01_Blue.pdf => BusinessCard_01_CarlosJorgeSantos_Blue.pdf
Does it make sense?
In Python (tested):
#!/usr/bin/python
import sys, os, shutil, re
try:
pdfpath = sys.argv[1]
except IndexError:
pdfpath = os.curdir
employees = {1:'Bob', 2:'Joe', 3:'Sara'} # emp_id:'name'
files = [f for f in os.listdir(pdfpath) if re.match("BusinessCard_[0-9]+_Blue.pdf", f)]
idnumbers = [int(re.search("[0-9]+", f).group(0)) for f in files]
filenamemap = zip(files, [employees[i] for i in idnumbers])
newfiles = [re.sub('Blue.pdf', e + '_Blue.pdf', f) for f, e in filenamemap]
for old, new in zip(files, newfiles):
shutil.move(os.path.join(pdfpath, old), os.path.join(pdfpath, new))
EDIT: This now alters only those files that have not yet been altered.
Let me know if you want something that will build the the employees dictionary automatically.
If you have a list of names in the same order the files are produced, in Python it goes like this untested fragment:
#!/usr/bin/python
import os
f = open('list.txt', 'r')
for n, name in enumerate(f):
original_name = 'BusinessCard_%02d_Blue.pdf' % (n + 1)
new_name = 'BusinessCard_%02d_%s_Blue.pdf' % (
n, ''.join(name.title().split()))
if os.path.isfile(original_name):
print "Renaming %s to %s" % (original_name, new_name),
os.rename(original_name, new_name)
print "OK!"
else:
print "File %s not found." % original_name
Python:
Assuming you have implemented the naming logic already:
for f in os.listdir(<directory>):
try:
os.rename(f, new_name(f.name))
except OSError:
# fail
You will, of course, need to write a function new_name which takes the string "BusinessCard_01_Blue.pdf" and returns the string "BusinessCard_01_CarlosJorgeSantos_Blue.pdf".