0

I have a repo where it looks like there is a cherry-picked commit (C) in an arrangement something like this:

      A---B---C topic
     /
D---E---F---G---C'---H master

The commit messages of C and C' were identical, and the resulting diffs from git show C and git show C' were also identical (contents, timestamp, author, etc.) other than the hash.

Surprisingly git diff C C' results in a huge diff. Not surprisingly, diff <(git show C) <(git show C') shows no difference. Under what circumstances can this occur? I was under the impression that git diff C C' should return empty.

Below I've copied the actual outputs (but removed any potentially sensitive info with XXX or XXX... Also note that C in the example above is hash 37a78fd9 below and C' is 5b5aa9b5:

git show C

~/foo$ git show 37a78fd9
commit 37a78fd9XXX...
Author: XXX XXX <XXX+XXX@users.noreply.github.com>
Date:   Thu Jun 9 15:05:14 2022 +0900

    May have fixed synchronization issue

diff --git a/Trial.java b/Trial.java
index 3e662af7..5dedcf37 100644
--- a/Trial.java
+++ b/Trial.java
@@ -11,6 +11,8 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
 import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -138,15 +140,17 @@ public class Trial implements Runnable, ActionSelector, SocketListener {
         Log.d("Episode", "End of episode:" + getEpisodeCount());
         // Waits for all image compression to finish prior to finishing flatbuffer
         long start = System.nanoTime();
-        for (Collection<Future<?>> timestepFutures: timeStepDataBuffer.imgCompFuturesEpisode){
-            for (Future<?> future:timestepFutures){
+        synchronized (timeStepDataBuffer.imgCompFuturesTimeStep){
+            for (Collection<Future<?>> timestepFutures: timeStepDataBuffer.imgCompFuturesEpisode){
+                for (Future<?> future:timestepFutures){
+                    future.get();
+                }
+            }
+            // Waits for all timestep flatbuffer writes to finish prior to finishing flatbuffer
+            for (Future<?> future:flatbufferAssembler.flatbufferWriteFutures){
                 future.get();
             }
         }
-        // Waits for all timestep flatbuffer writes to finish prior to finishing flatbuffer
-        for (Future<?> future:flatbufferAssembler.flatbufferWriteFutures){
-            future.get();
-        }
         long stop = System.nanoTime();
         long timediff = stop - start;
         flatbufferAssembler.endEpisode();

git show C'

~/foo$ git show 5b5aa9b5
commit 5b5aa9b5XXX... (threadingIssue)
Author: XXX XXX <XXX+XXX@users.noreply.github.com>
Date:   Thu Jun 9 15:05:14 2022 +0900

    May have fixed synchronization issue

diff --git a/Trial.java b/Trial.java
index 3e662af7..5dedcf37 100644
--- a/Trial.java
+++ b/Trial.java
@@ -11,6 +11,8 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
 import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -138,15 +140,17 @@ public class Trial implements Runnable, ActionSelector, SocketListener {
         Log.d("Episode", "End of episode:" + getEpisodeCount());
         // Waits for all image compression to finish prior to finishing flatbuffer
         long start = System.nanoTime();
-        for (Collection<Future<?>> timestepFutures: timeStepDataBuffer.imgCompFuturesEpisode){
-            for (Future<?> future:timestepFutures){
+        synchronized (timeStepDataBuffer.imgCompFuturesTimeStep){
+            for (Collection<Future<?>> timestepFutures: timeStepDataBuffer.imgCompFuturesEpisode){
+                for (Future<?> future:timestepFutures){
+                    future.get();
+                }
+            }
+            // Waits for all timestep flatbuffer writes to finish prior to finishing flatbuffer
+            for (Future<?> future:flatbufferAssembler.flatbufferWriteFutures){
                 future.get();
             }
         }
-        // Waits for all timestep flatbuffer writes to finish prior to finishing flatbuffer
-        for (Future<?> future:flatbufferAssembler.flatbufferWriteFutures){
-            future.get();
-        }
         long stop = System.nanoTime();
         long timediff = stop - start;
         flatbufferAssembler.endEpisode();

diff <(git show C) <(git show C')

~/foo$ diff <(git show 37a78fd9) <(git show 5b5aa9b5)
1c1
< commit 37a78fd9XXX...
---
> commit 5b5aa9b5XXX...

git diff 37a78fd9 5b5aa9b5

diff --git a/MainActivity.java b/MainActivity.java
index a72a91f4..aa83e306 100644
--- a/MainActivity.java
+++ b/MainActivity.java
@@ -49,9 +49,9 @@ public class MainActivity extends AbcvlibActivity implements IOReadyListener {
         ------------------------------ Set MetaParameters ------------------------------
         --------------------------------------------------------------------------------
          */
-        TimeStepDataBuffer timeStepDataBuffer = new TimeStepDataBuffer(2);
-        MetaParameters metaParameters = new MetaParameters(this, 50, 1,
-                100000, 10000, inetSocketAddress, timeStepDataBuffer, getOutputs(), 1);
+        TimeStepDataBuffer timeStepDataBuffer = new TimeStepDataBuffer(200);
+        MetaParameters metaParameters = new MetaParameters(this, 50, 200,
+                100000, 1000, inetSocketAddress, timeStepDataBuffer, getOutputs(), 1);
 
         /*------------------------------------------------------------------------------
         ------------------------------ Define Action Space -----------------------------
diff --git a/MyTrial.java b/MyTrial.java
index b21efc73..148669b3 100644
--- a/MyTrial.java
+++ b/MyTrial.java
@@ -2,13 +2,7 @@ package xxx.serverlearning;
 
 import android.util.Log;
 
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
 import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
 import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.ExecutionException;
 
...

Note the above is truncated for brevity, as I believe the rest should be irrelevant to this question.

topher217
  • 1,188
  • 12
  • 35
  • "I was under the impression that git diff C C' should return empty." Not at all. A cherry pick is a _merge_. It makes a commit that can be very different from the original. – matt Mar 08 '23 at 04:17
  • I've provided as a duplicate link an explanation of the mechanism of cherry pick that exemplifies perfectly that a cherry picked commit is not identical to the original and why. I could find you many other existing explanations on Stack Overflow. – matt Mar 08 '23 at 04:23
  • 1
    See also for instance https://stackoverflow.com/questions/73137965/unable-to-understand-merge-common-ancestor-output-and-reason-of-conflict – matt Mar 08 '23 at 04:25
  • with `diff <(git show C) <(git show C')` you are comparing *the patches*, while `git diff C C'` will compare *the complete contents* of C and C'. On top of that, it so happens that C and C' both apply to a single file, which is identical in both branches (shown by th e`index 3e662af7..5dedcf37 100644` line). This part is very specific to the case you display, in the general case you can expect a larger diff (not a single line which mentions the commit hash). – LeGEC Mar 08 '23 at 05:06
  • Since we know that `Trial.java` are the exact same in C and C', `git diff C C'` will show you the same thing as `git diff B G`. Would you expect this diff to be empty ? – LeGEC Mar 08 '23 at 05:08
  • Thank you. The discussion in the link helped clarify my misunderstanding. I understand why the two commands are different now, but is there a `git` way (as opposed to using `diff`) to do the same as `diff <(git show C) <(git show C')`? In the event I actually want to compare the diffs/patches introduced by the commits? – topher217 Mar 08 '23 at 05:55
  • Not sure who closed the question, but I'd say the linked "duplicate" is not a duplicate at all. Not sure what it has to do with this question at all actually. It might be more helpful to use the link in the comments here as it is much more relevant. I'd be curious if there is a more specific question asking something along the lines of "why diff not empty" and providing explanations like those given in the comments here. – topher217 Mar 08 '23 at 06:03
  • 2
    *is there a git way (as opposed to using diff) to do the same as diff <(git show C) <(git show C')* yes, there is: `git range-diff C~..C C'~..C'` – j6t Mar 08 '23 at 06:46

0 Answers0