Opened 3 years ago

Closed 3 years ago

#20492 closed defect (fixed)

Tor git version is not generated in git worktrees

Reported by: teor Owned by: jryans
Priority: Medium Milestone: Tor: 0.3.0.x-final
Component: Core Tor/Tor Version: Tor: 0.2.3.9-alpha
Severity: Normal Keywords: log, easy
Cc: jryans@… Actual Points:
Parent ID: Points: 0.5
Reviewer: Sponsor:

Description

When I compile tor on macOS, it doesn't log the git version on startup:

Oct 29 01:27:48.261 [notice] Tor 0.3.0.0-alpha-dev running on Darwin with Libevent 2.0.22-stable, OpenSSL 1.0.2j and Zlib 1.2.8.

This happens regardless of compiler and architecture:
gcc (MacPorts gcc49 4.9.4_0+universal) 4.9.4 (i386/x86_64)
clang version 3.9.0 (tags/RELEASE_390/final) (x86_64)

$ git --version
git version 2.10.1

But when I compile it on Linux, I see a git commit hash:

Oct 28 14:28:15.669 [notice] Tor 0.3.0.0-alpha-dev (git-f3e158edf7d8128d) running on Linux with Libevent 2.0.21-stable, OpenSSL 1.0.2g and Zlib 1.2.8.

Compiler:
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

$ git --version
git version 2.6.3.36.g9a8c740

I'm putting this in 0.3.0 because it makes diagnosing issues much easier if we have the full commit. But feel free to disagree.

Child Tickets

Change History (11)

comment:1 Changed 3 years ago by asn

Hm, is this actually a regression? Did this used to work on Mac OS X?

comment:2 in reply to:  1 Changed 3 years ago by teor

Keywords: regression removed
Milestone: Tor: 0.3.0.x-finalTor: 0.2.???

Replying to asn:

Hm, is this actually a regression? Did this used to work on Mac OS X?

No versions of tor I compiled on macOS / OS X have the git tag.

But the Tor Browser binaries with the same versions have the git tag, probably because they were cross-compiled on Linux. So I think we're ok here.

(And that's why I was confused.)

comment:3 Changed 3 years ago by teor

Milestone: Tor: 0.2.???Tor: 0.3.???

Milestone renamed

comment:4 Changed 3 years ago by jryans

Cc: jryans@… added

Hmm, this seems to be working for me on macOS 10.12.1:

$ ./src/or/tor --version
Tor version 0.3.0.0-alpha-dev (git-8a0ea3ee43da0063).

and

$ ./src/or/tor
Dec 02 23:41:20.688 [notice] Tor 0.3.0.0-alpha-dev (git-8a0ea3ee43da0063) running on Darwin with Libevent 2.0.22-stable, OpenSSL LibreSSL 2.3.2 and Zlib 1.2.8.

I have the following setup:

$ git --version
git version 2.10.0
$ clang --version
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Let me know if there are other details that would help to determine differences.

comment:5 Changed 3 years ago by teor

Interesting.

It looks like the micro-revision.i make script is incompatible with using git worktrees.

In my base git directory, I see:

$ src/or/tor --version
Tor version 0.2.9.4-alpha-dev (git-ff3e08f2af226d96).
$ cat micro-revision.i 
"ff3e08f2af226d96"
$ ls -ld .git
drwxr-xr-x  22 username  staff  748  3 Dec 08:55 .git

In a worktree, I see:

$ src/or/tor --version
Tor version 0.3.0.0-alpha-dev.
$ cat micro-revision.i
""
$ ls -ld .git
-rw-r--r--  1 username  staff  58 26 Nov  2015 .git

The script to create micro-revision.i is in the Makefile:

micro-revision.i: FORCE
        $(AM_V_at)rm -f micro-revision.tmp; \
        if test -d "$(top_srcdir)/.git" && \
                        test -x "`which git 2>&1;true`"; then \
                HASH="`cd "$(top_srcdir)" && git rev-parse --short=16 HEAD`"; \
                echo \"$$HASH\" > micro-revision.tmp; \
        fi; \
        if test ! -f micro-revision.tmp; then \
                if test ! -f micro-revision.i; then \
                        echo '""' > micro-revision.i; \
                fi; \
        elif test ! -f micro-revision.i || \
                        test x"`cat micro-revision.tmp`" != x"`cat micro-revision.i`"; then \
                mv micro-revision.tmp micro-revision.i; \
        fi; \
        rm -f micro-revision.tmp; \
        true

The initial test needs to check if the .git file or directory exists, not that it's a directory. (It could be a symlink, for example.)

comment:6 Changed 3 years ago by teor

Summary: Tor git version displayed on Linux, but not macOSTor git version is not generated in git worktrees

comment:7 Changed 3 years ago by jryans

Owner: set to jryans
Status: newassigned

Okay, I can reproduce after creating a worktree here. I'll check it out.

comment:8 Changed 3 years ago by teor

(To make changes in git, you will need to edit Makefile.am, then run ./autogen.sh .)

comment:9 Changed 3 years ago by jryans

Status: assignedneeds_review

As suggested in comment 5, we only need to check that .git exists. I used -r to check that it's readable, which works for both a regular git repo and a worktree (verified both cases locally).

https://github.com/jryans/tor/commits/git-worktree-rev

comment:10 Changed 3 years ago by teor

Milestone: Tor: 0.3.???Tor: 0.3.0.x-final
Status: needs_reviewmerge_ready
Version: Tor: 0.2.3.9-alpha

Ok, works in my worktrees.

I'd like to put this in 0.2.9, but I think it's too late, because it's at rc stage.
What do you think, nickm?

comment:11 Changed 3 years ago by nickm

Resolution: fixed
Status: merge_readyclosed

I think this is actually okay for 0.2.9, and is important, in order to make sure 0.2.9 stays debuggable. The one-character change seems simple enough to me. Cherry-picking. Thanks!

Note: See TracTickets for help on using tickets.