Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-4747

Restore git blame for synchronous files

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.9
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Context

      In PYTHON-4264 we moved some files to nested synchronous and asynchronous folders, without preserving git blame. We should restore the git blame for the synchronous files to point back to the previous files. I wrote a script to do this. (Inlined below).

      Definition of done

      Ensure git blame is working for files that migrated from
      pymongo/

      {x.py} -> pymongo/synchronous/{x.py}

      and for gridfs as well.

      Pitfalls

      Ensure we preserve overall git history.

      set -eux
      
      export branch=fix-pymongo-history
      # Commit prior to PYTHON-4264 
      BASE_COMMIT=da03da34c6498378d6a9a7f5c9c5c19cd579d9b1
      
      pymongo_files=("client_session.py" "encryption.py" "auth_oidc.py" \
             "collection.py" "pool.py" "command_cursor.py" "mongo_client.py" \
             "change_stream.py" "cursor.py" \
             "auth.py" "database.py")
      
      git checkout master
      git branch -D $branch || true
      git checkout -b $branch
      git checkout master
      git branch -D restore-file || true
      git checkout -b restore-file $BASE_COMMIT
      
      function move() {
          local name=$1
          local source=$2
          local target=$3
          echo $target
          # The important rename commit.
          git mv $source $target 
          git add $target
          git commit -m "Rename $source to $target"
          git checkout HEAD~1 $source
          git add $source
          # Sync files with latest state.
          git checkout master $target
          git checkout master $source
          git add $target $source
          git commit -m "Sync $name to master"
      }
      
      for name in "${pymongo_files[@]}"
      do
          mkdir -p pymongo/synchronous
          source="pymongo/$name"
          target="pymongo/synchronous/$name"
          move $name $source $target
      done
      
      mkdir -p gridfs/synchronous
      name="grid_file.py"
      source="gridfs/$name"
      target="gridfs/synchronous/$name"
      move $name $source $target
      
      # # There should not be any conflicts or changes to target file in this commit!
      git merge -X theirs $branch -m "Merge $branch"
      # # The missing "fast-forward merge" feature on GitHub.
      git checkout $branch && git merge --ff-only restore-file
      

            Assignee:
            steve.silvester@mongodb.com Steve Silvester
            Reporter:
            steve.silvester@mongodb.com Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: