Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move "ImGui's files" from right in the middle, to a dear-imgui/ git subtree #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

folays
Copy link

@folays folays commented Dec 24, 2021

Hello,

In this pull request, I have moved the Dear ImGui's files form "in the middle of all AllenDang's files" to a new completely independent and self-contained dear-imgui/ directory.

(this is a step in addition to the split you already done this year, by splitting this repo from https://github.com/AllenDang/giu)

This new dear-imgui/ directory is a git subtree directory, which means that :

  • you can super easily pull latest "Dear ImGui" into your dear-imgui/ subdirectory (git subtree pull)
  • you can super easily "extract" local modification to "Dear ImGui" code, if you were to propose changes to (C++) Dear ImGui, and thus super easily create a pull request to "Dear ImGui" code.

Hint : I needed that because, indeed, I have some bug in "Dear ImGui" base code (ocornut/imgui#3795) that:

  • occurs in a Go program, which uses https://github.com/AllenDang/giu
  • I was willing to identify the bug and fix it in "Dear ImGui" imgui.cpp
  • I do not wanted to re-create a sample app in C++
  • I wanted to fix https://github.com/AllenDang/giu (or rather fix it's dependency), which meant fixing the imgui.cpp code (official "Dear ImGui") in https://github.com/AllenDang/imgui-go
  • I wanted to be able to "push upstream" the modification to imgui.cpp, to Dear ImGui (git subtree push)
    • (which mean "git subptree push" the dear-imgui/ folder to my own ocornut/imgui's fork, and create a pull request from there)

So I forked your github.com/AllenDang/imgui-go repo, and created a folays.imgui-v1.85 branch.
Here are the commands that I did to create it :

grep IMGUI_VERSION imgui.h
-> 1.85

git checkout -b folays.imgui-v1.85 # because you are currently based on v1.85

git subtree add  --prefix=dear-imgui https://github.com/ocornut/imgui.git v1.85 --squash
git subtree pull --prefix=dear-imgui https://github.com/ocornut/imgui.git v1.85 --squash # no-op
-> # From ssh://github.com/ocornut/imgui
   #  * tag                 v1.85      -> FETCH_HEAD
   # Subtree is already at commit 55d35d8387c15bf0cfd71861df67af8cfbda7456.

diff -ru dear-imgui/ ./ | grep -r 'Only in dear-imgui/'
-> (standard input):Only in dear-imgui/: .editorconfig
   (standard input):Only in dear-imgui/: .gitattributes
   (standard input):Only in dear-imgui/: .github
   (standard input):Only in dear-imgui/: backends
   (standard input):Only in dear-imgui/: docs
   (standard input):Only in dear-imgui/: examples

diff -ru dear-imgui/ ./ | grep -- ---
-> --- dear-imgui/.gitignore	2021-12-23 08:30:27.000000000 +0100
   --- dear-imgui/imgui.cpp	2021-12-23 08:30:27.000000000 +0100
   --- dear-imgui/imgui.h	2021-12-23 08:30:27.000000000 +0100
   --- dear-imgui/imgui_internal.h	2021-12-23 08:30:27.000000000 +0100
   --- dear-imgui/imgui_widgets.cpp	2021-12-23 08:30:27.000000000 +0100

diff -ru dear-imgui/ ./ | grep -v ^Only > ../PATCH_imgui-go_diff_to_imgui_v1.85.patch

# remove all ROOT/ files which are already in dear-imgui/
( cd dear-imgui/ && find . -type f -print0 ) | xargs -0 -n1 -- git rm

git checkout HEAD LICENSE.txt .gitignore # restore some stuff

# below : do not "symlink" but rather "#include", because Go Modules (go mod download) IGNORE symlinks.
for name in $(cd dear-imgui/ && ls -1f *.{cpp,h}); do printf '#include "dear-imgui/%s"\n' $name > $name ; done
for name in $(cd dear-imgui/ && ls -1f *.{cpp,h}); do git add $name ; done

# re-add local modifications to dear-imgui/ (modifications exclusives to imgui-go)
patch -d ./dear-imgui/ -p1 < ../PATCH_imgui-go_diff_to_imgui_v1.85.patch

git checkout dear-imgui/.gitignore # restore probably no-more-wanted local modifications
git add dear-imgui/

git commit # ...

I also git add a a new file, /git_pull_dear-imgui.sh which you can use to "pull" new Dear ImGui version from upstream.

Here is what I could do if I wanted to update to Dear ImGui v1.86 (released... yesterday?)

git checkout folays.imgui-v1.85 # fetch this very branch from this pull request

git checkout -b folays.imgui-v1.86
sh ./git_pull_dear-imgui.sh v1.86 # "git subtree pull" from Dear ImGui v1.86
    
go clean -cache
go build ./ # check if it compiles

# Hint 1) It does not compile, there is some SMALL changes in ImGui's (`imgui.h`) ImGuiListClipper struct,
#  (1 struct field removed, 2 or 3 added) which need to be reflected in the wrapper ListClipper.{cpp,h},
#  and while I could update those manually, I feel that you have some sort of procedure to update them automatically?

# Hint 2) For whatever reason, it works even if it SHOULD NOT, if you did not "go clean -cache". Dunno why...

# ... Fix ListClipper.{cpp,h} so that it compiles
    
git commit
git push origin folays.imgui-v1.86
# or git tag whatever tagname you use to be compliant w.r.t. Go Modules.

Also, I think that you are substantially derived from inkyblackness/imgui-go, but I could not figure your thought process.
I'm somewhat curious :

  • I guess that you expose an API (the Go API thus exposed) probably adapted to https://github.com/AllenDang/giu needs
  • Way more curious : You adopted a different way to generate the pure "C++ to C" wrappers ?
    • Full Swig automation ?
    • Swig was used only as a "working base", and then from now on, you do all updates to those wrappers manually ?

Hope you understand that the purpose of this change is to ease :

  • pulling from Dear ImGui upstream (which was not really an hassle)
  • more importantly : being able to fork your github.com/AllenDang/imgui-go repo, fix imgui.cpp directly, while being able to still track and pull upstream changes, and independently also being able to "extract" local changes (with "git subtree push") to propose patches (via a pull request) to Dear ImGui (ocornut).

Regards,

folays added 3 commits December 23, 2021 08:30
git-subtree-dir: dear-imgui
git-subtree-split: 55d35d8387c15bf0cfd71861df67af8cfbda7456
… #include to those in dear-imgui/ git subtree

- re-apply imgui-go local modifications to dear-imgui/
- add ./git_pull_dear-imgui.sh , a convenient shell script to `git subtree pull` newer releases of github.com/ocornut/imgui.git
@folays folays changed the title Folays.imgui v1.85 Move "ImGui's files" from right in the middle, to a dear-imgui/ git subtree Dec 24, 2021
@folays
Copy link
Author

folays commented Dec 24, 2021

Another example, after that, you could :

git remote add upstream_imgui https://github.com/ocornut/imgui.git

# don't fetch tags (--no-tags), but yes, fetch them, but in a specifc refspec
# (to not clutter your own repos tags, with the tags of a 3rd party repos)
git fetch --no-tags upstream_imgui '+refs/tags/*:refs/tags_upstream_imgui/*'

$ cat .git/refs/tags_upstream_imgui/v1.85
55d35d8387c15bf0cfd71861df67af8cfbda7456 # <- commit of Dear ImGui v1.85

git diff refs/tags_upstream_imgui/v1.85 folays.imgui-v1.85:dear-imgui/
# OR :
# - git diff refs/tags_upstream_imgui/v1.85 HEAD:dear-imgui/ # if your HEAD is "near" v1.85

Which would display ONLY you local changes to officlal Dear ImGui sources.

In this case, the git diff would reveal :

$ git diff refs/tags_upstream_imgui/v1.85 folays.imgui-v1.85:dear-imgui/ |grep -vE '^(---|\+\+\+) ' | cut -c1 | sort | uniq -c
  48
  55 +
   2 -
   8 @
   4 d
   4 i

Your 55 lines added, 2 removed, on 4 files (8 sections) compared from Dear ImGui sources.

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant