From e2c733192c951832f46b80bfdd2c2917fca5630b Mon Sep 17 00:00:00 2001 From: Jaime Alfaro Salazar <62313620+jialfaro@users.noreply.github.com> Date: Sun, 6 Sep 2026 12:01:24 -0500 Subject: [PATCH 1/2] Fix redundant conditional in FunctionTagListingMerger.mergeConflicts --- .../listing/FunctionTagListingMerger.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/FunctionTagListingMerger.java b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/FunctionTagListingMerger.java index e877f64fc6..9707a26e65 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/FunctionTagListingMerger.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/FunctionTagListingMerger.java @@ -54,17 +54,17 @@ import ghidra.util.task.TaskMonitor; * - X and Y are tags * - ** indicates a conflict * - * User A | Add X Add Y Delete X Delete Y - * | + * User A |Add X Add Y Delete X Delete Y + * | * User B | * ------------------------------------------------------- - * Add X | X X,Y ** X - * | - * Add Y | X,Y Y Y ** - * | - * Delete X | ** Y - - - * | - * Delete Y | X ** - - + * Add X |X X,Y ** X + * | + * Add Y |X,Y Y Y ** + * | + * Delete X |** Y - - + * | + * Delete Y |X ** - - * * */ @@ -95,7 +95,7 @@ public class FunctionTagListingMerger extends AbstractListingMerger { super(listingMergeMgr); } - /****************************************************************************** + /**************************************************************************** * PUBLIC METHODS ******************************************************************************/ @@ -204,9 +204,9 @@ public class FunctionTagListingMerger extends AbstractListingMerger { // Make sure we're supposed to prompt the user; if not, just use the // previous choice and merge. if (tagChoice != ASK_USER) { - int optionToUse = - (tagChoice == ASK_USER) ? chosenConflictOption : tagChoice; - mergeConflictingTag(addr, optionToUse, monitor); + // tagChoice may have been changed by the user's "Use For All" selection + // in a previous iteration; use it directly. + mergeConflictingTag(addr, tagChoice, monitor); } else { showMergePanel(listingPanel, addr, id, monitor); @@ -228,7 +228,7 @@ public class FunctionTagListingMerger extends AbstractListingMerger { } } - /****************************************************************************** + /**************************************************************************** * PRIVATE METHODS ******************************************************************************/ @@ -249,9 +249,9 @@ public class FunctionTagListingMerger extends AbstractListingMerger { // additions/removals of tags from the address; tag creations/deletions/edits will not be // in these change sets. AddressSetView myChangedAddresses = - listingMergeMgr.diffOriginalMy.getDifferences(new ProgramDiffFilter(diffType), monitor); + listingMergeMgr.diffOriginalMy.getDifferences(new ProgramDiffFilter(diffType), monitor); AddressSetView latestChangedAddresses = listingMergeMgr.diffOriginalLatest - .getDifferences(new ProgramDiffFilter(diffType), monitor); + .getDifferences(new ProgramDiffFilter(diffType), monitor); // Get a list of all deleted tags in My and Latest. Collection myDeletedTags = getDeletedTags(myPgm, monitor); @@ -312,7 +312,7 @@ public class FunctionTagListingMerger extends AbstractListingMerger { * Adds the given tag/address combo to the global conflict list. * * @param addr the conflicting address - * @param tag the conflicting tag + * @param tag the conflicting tag */ private void addToConflicts(Address addr, FunctionTag tag) { if (conflictMap.get(addr) == null) { @@ -484,7 +484,7 @@ public class FunctionTagListingMerger extends AbstractListingMerger { // want to throw away; the keep list is the one we want to keep. // // ie: Original = "Red" - // My = "Red-my" + // My = "Red-my" // Latest = "Red-latest" // // If the decision is KEEP_LATEST, then "Red-my" and "Red" will be added From 50660dffc31e278ee2cf88e966c2a4715b98c5f6 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Tue, 8 Sep 2026 06:19:30 -0400 Subject: [PATCH 2/2] GP-0: Certify and cleanup --- .../listing/FunctionTagListingMerger.java | 80 +++++++++---------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/FunctionTagListingMerger.java b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/FunctionTagListingMerger.java index 9707a26e65..b01d602b82 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/FunctionTagListingMerger.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/FunctionTagListingMerger.java @@ -38,35 +38,35 @@ import ghidra.util.task.TaskMonitor; /** * Handles merging of function tags when they are added/removed from * functions. - * + *

* Most merging can be done automatically; the exception being when a * tag has been added to a function by one user, but deleted from the * program by another. - * + *

* THIS CLASS ONLY DEALS WITH FUNCTION-RELATED ADDS/REMOVES. - * + *

* The specific cases handled by the class are described below: - * - * - X and Y are tags - * - ** indicates a conflict - * - * User A |Add X Add Y Delete X Delete Y - * | - * User B | + *

+ *
+ *      User A  |  Add X   Add Y  Delete X  Delete Y	
+ * 	            |
+ * User B       |
  * -------------------------------------------------------
- * Add X		|X		X,Y		**		X		
- * 		|
- * Add Y		|X,Y	Y		Y		**		
- * 		|
- * Delete X		|**		Y		-		-			
- * 		|
- * Delete Y		|X		**		-		-		
- * 
- * 
+ * Add X        |  X       X,Y      **        X		
+ *              |
+ * Add Y        |  X,Y     Y        Y         **		
+ *              |
+ * Delete X     |  **      Y        -         -			
+ *              |
+ * Delete Y     |  X       **       -         -		
+ * 
*/ public class FunctionTagListingMerger extends AbstractListingMerger { @@ -238,20 +238,19 @@ public class FunctionTagListingMerger extends AbstractListingMerger { * * @param diffType from {@link ProgramDiffFilter} * @param monitor task monitor - * @throws ProgramConflictException - * @throws CancelledException - * @throws IOException + * @throws CancelledException if the user cancelled the operation + * @throws IOException if an IO-related error occurred */ private void autoMerge(int diffType, TaskMonitor monitor) - throws ProgramConflictException, CancelledException, IOException { + throws CancelledException, IOException { // Get the address of all changes in Latest and My. These changes are guaranteed to ONLY be // additions/removals of tags from the address; tag creations/deletions/edits will not be // in these change sets. AddressSetView myChangedAddresses = - listingMergeMgr.diffOriginalMy.getDifferences(new ProgramDiffFilter(diffType), monitor); + listingMergeMgr.diffOriginalMy.getDifferences(new ProgramDiffFilter(diffType), monitor); AddressSetView latestChangedAddresses = listingMergeMgr.diffOriginalLatest - .getDifferences(new ProgramDiffFilter(diffType), monitor); + .getDifferences(new ProgramDiffFilter(diffType), monitor); // Get a list of all deleted tags in My and Latest. Collection myDeletedTags = getDeletedTags(myPgm, monitor); @@ -276,7 +275,7 @@ public class FunctionTagListingMerger extends AbstractListingMerger { * @param changedAddresses list of addresses to inspect * @param deletedTags all tags deleted in the 'other' program * @param programAddedTo the program in which the adds reside - * @throws IOException + * @throws IOException if an IO-related error occurred */ private void processChangedAddresses(AddressSetView changedAddresses, Collection deletedTags, Program programAddedTo) @@ -324,11 +323,10 @@ public class FunctionTagListingMerger extends AbstractListingMerger { } /** - * Returns all tags that were added to the function at the given address. + * {@return all tags that were added to the function at the given address} * * @param program the program where the function resides * @param addr the function entry point - * @return */ private Collection getTagsAddedToFunction(Program program, Address addr) { @@ -363,7 +361,7 @@ public class FunctionTagListingMerger extends AbstractListingMerger { * indicate deletions. * * @param program the program version - * @param monitor + * @param monitor A {@link TaskMonitor} * @return database IDs from the FunctionTagAdapter table that were deleted */ private Collection getDeletedTags(Program program, TaskMonitor monitor) { @@ -391,9 +389,9 @@ public class FunctionTagListingMerger extends AbstractListingMerger { * resolving the conflict will appear at the bottom. * * @param listingPanel the main panel - * @param addr - * @param tagID - * @param changeListener + * @param addr The address + * @param tagID The tag ID + * @param changeListener The {@link ChangeListener} */ private void setupConflictsPanel(ListingMergePanel listingPanel, Address addr, Long tagID, ChangeListener changeListener) { @@ -438,12 +436,12 @@ public class FunctionTagListingMerger extends AbstractListingMerger { } /** - * Returns a string containing the tag and the program version it's associated - * with. This is used when displaying the conflict panel. + * {@return a string containing the tag and the program version it's associated with} + *

+ * This is used when displaying the conflict panel. * - * @param version - * @param tags - * @return + * @param version The program version + * @param tag The associated tag */ private String[] getFunctionTagInfo(int version, String tag) { String[] info = new String[] { "Keep", "", tag }; @@ -471,8 +469,8 @@ public class FunctionTagListingMerger extends AbstractListingMerger { * * @param addr the location of the conflict * @param chosenConflictOption KEEP_ORIGINAL, KEEP_LATEST, KEEP_MY - * @param monitor - * @throws CancelledException + * @param monitor A {@link TaskMonitor} + * @throws CancelledException if the user cancelled the operation */ private void mergeConflictingTag(Address addr, int chosenConflictOption, TaskMonitor monitor) throws CancelledException { @@ -629,7 +627,7 @@ public class FunctionTagListingMerger extends AbstractListingMerger { * @param id the tag ID * @param program the program version * @return null if tag not found for the given id - * @throws IOException + * @throws IOException if an IO-related error occurred */ private FunctionTag getTag(Long id, Program program) throws IOException { FunctionManagerDB functionManagerDB = (FunctionManagerDB) program.getFunctionManager();