Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add user agent functionality #1334

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

Closed
wants to merge 3 commits into from
Closed

add user agent functionality #1334

wants to merge 3 commits into from

Conversation

txdv
Copy link
Contributor

@txdv txdv commented Jul 4, 2016

the issue is described here #1333

Do I need to write some tests for this? Without being able to get the user agent(there is only set functionality in libgit2), I don't see how it is possible to write some feasible test.

Unless I create my own http server and issue a request and take a look at the the user agent information.

@ethomson
Copy link
Member

ethomson commented Jul 4, 2016

I can see that it would probably be difficult to unit test this (unless we add some functionality to get the user agent in libgit2 - which we probably should do). I can add that, but in the meantime, I think that yes, sniffing in wireshark or fiddler would be good. Or at least stepping through in a debugger to make sure that things land in the native side correctly.

I added a few notes regarding that, but I'm not sure that they're exhaustive, so I think that you should check to see how this is landing in the native side.

/// </param>
public static void SetUserAgent(ConfigurationLevel level, string userAgent)
{
Proxy.git_libgit2_opts_set_user_agent(level, userAgent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no ConfigurationLevel for this call - it doesn't have anything to do with configuration. It only takes a user agent string and is applied to the entirety of the library.

@ethomson
Copy link
Member

ethomson commented Jul 4, 2016

This will be great to have, thanks for tackling this!

@txdv
Copy link
Contributor Author

txdv commented Jul 5, 2016

Didn't know you could just use vargs without __listargs.

The mono tracer is saying that it is entering and leaving the function:

[0x7f1d7a7727c0: 0.00573 0] ENTER: LibGit2Sharp.Core.Proxy:git_libgit2_opts_set_user_agent (string)([STRING:0x7f1d7a6b8130:txdv], )
[0x7f1d7a7727c0: 0.00611 1] ENTER: LibGit2Sharp.Core.NativeMethods:.cctor ()()
[0x7f1d7a7727c0: 0.00612 2] ENTER: LibGit2Sharp.Core.Platform:get_OperatingSystem ()()
[0x7f1d7a7727c0: 0.00613 2] LEAVE: LibGit2Sharp.Core.Platform:get_OperatingSystem ()result=1
[0x7f1d7a7727c0: 0.00630 2] ENTER: (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_libgit2_init ()()
[0x7f1d7a7727c0: 0.00755 2] LEAVE: (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_libgit2_init ()result=1
[0x7f1d7a7727c0: 0.00792 2] ENTER: LibGit2Sharp.Core.Ensure:.cctor ()()
[0x7f1d7a7727c0: 0.00968 2] LEAVE: LibGit2Sharp.Core.Ensure:.cctor ()
[0x7f1d7a7727c0: 0.00969 2] ENTER: LibGit2Sharp.Core.Ensure:Int32Result (int)(1, )
[0x7f1d7a7727c0: 0.00970 2] LEAVE: LibGit2Sharp.Core.Ensure:Int32Result (int)
[0x7f1d7a7727c0: 0.00975 2] ENTER: (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_openssl_set_locking ()()
[0x7f1d7a7727c0: 0.00977 2] LEAVE: (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_openssl_set_locking ()result=0
[0x7f1d7a7727c0: 0.00982 2] ENTER: LibGit2Sharp.Core.NativeMethods:AddHandle ()()
[0x7f1d7a7727c0: 0.00987 2] LEAVE: LibGit2Sharp.Core.NativeMethods:AddHandle ()
[0x7f1d7a7727c0: 0.00988 1] LEAVE: LibGit2Sharp.Core.NativeMethods:.cctor ()
[0x7f1d7a7727c0: 0.00989 1] ENTER: (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_libgit2_opts (int,string)(13, [STRING:0x7f1d7a6b8130:txdv], )
[0x7f1d7a7727c0: 0.01006 2] ENTER: LibGit2Sharp.Core.StrictUtf8Marshaler:.cctor ()()
[0x7f1d7a7727c0: 0.01025 3] ENTER: LibGit2Sharp.Core.StrictUtf8Marshaler:.ctor ()(this:0x7f1d78803000[LibGit2Sharp.Core.StrictUtf8Marshaler test.exe], )
[0x7f1d7a7727c0: 0.01025 3] LEAVE: LibGit2Sharp.Core.StrictUtf8Marshaler:.ctor ()
[0x7f1d7a7727c0: 0.01026 2] LEAVE: LibGit2Sharp.Core.StrictUtf8Marshaler:.cctor ()
[0x7f1d7a7727c0: 0.01027 2] ENTER: LibGit2Sharp.Core.StrictUtf8Marshaler:GetInstance (string)([STRING:0x7f1d78802ea8:40212f0c-5262-4f28-9607-f19e8e3fc16f], )
[0x7f1d7a7727c0: 0.01027 2] LEAVE: LibGit2Sharp.Core.StrictUtf8Marshaler:GetInstance (string)[LibGit2Sharp.Core.StrictUtf8Marshaler:0x7f1d78803000]
[0x7f1d7a7727c0: 0.01041 2] ENTER: LibGit2Sharp.Core.EncodingMarshaler:MarshalManagedToNative (object)(this:0x7f1d78803000[LibGit2Sharp.Core.StrictUtf8Marshaler test.exe], [STRING:0x7f1d7a6b8130:txdv], )
[0x7f1d7a7727c0: 0.01059 3] ENTER: LibGit2Sharp.Core.EncodingMarshaler:FromManaged (System.Text.Encoding,string)([System.Text.UTF8Encoding:0x7f1d78802f08], [STRING:0x7f1d7a6b8130:txdv], )
[0x7f1d7a7727c0: 0.01075 3] LEAVE: LibGit2Sharp.Core.EncodingMarshaler:FromManaged (System.Text.Encoding,string)result=38389920
[0x7f1d7a7727c0: 0.01077 2] LEAVE: LibGit2Sharp.Core.EncodingMarshaler:MarshalManagedToNative (object)result=38389920
[0x7f1d7a7727c0: 0.01078 2] ENTER: LibGit2Sharp.Core.StrictUtf8Marshaler:GetInstance (string)([STRING:0x7f1d788030a8:40212f0c-5262-4f28-9607-f19e8e3fc16f], )
[0x7f1d7a7727c0: 0.01079 2] LEAVE: LibGit2Sharp.Core.StrictUtf8Marshaler:GetInstance (string)[LibGit2Sharp.Core.StrictUtf8Marshaler:0x7f1d78803000]
[0x7f1d7a7727c0: 0.01085 2] ENTER: LibGit2Sharp.Core.EncodingMarshaler:CleanUpNativeData (intptr)(this:0x7f1d78803000[LibGit2Sharp.Core.StrictUtf8Marshaler test.exe], 0x249c8a0, )
[0x7f1d7a7727c0: 0.01093 3] ENTER: LibGit2Sharp.Core.EncodingMarshaler:Cleanup (intptr)(0x249c8a0, )
[0x7f1d7a7727c0: 0.01098 3] LEAVE: LibGit2Sharp.Core.EncodingMarshaler:Cleanup (intptr)
[0x7f1d7a7727c0: 0.01099 2] LEAVE: LibGit2Sharp.Core.EncodingMarshaler:CleanUpNativeData (intptr)
[0x7f1d7a7727c0: 0.01099 1] LEAVE: (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_libgit2_opts (int,string)result=0
[0x7f1d7a7727c0: 0.01101 1] ENTER: LibGit2Sharp.Core.Ensure:ZeroResult (int)(0, )
[0x7f1d7a7727c0: 0.01102 1] LEAVE: LibGit2Sharp.Core.Ensure:ZeroResult (int)
[0x7f1d7a7727c0: 0.01102 0] LEAVE: LibGit2Sharp.Core.Proxy:git_libgit2_opts_set_user_agent (string)

The sample code is:

using LibGit2Sharp;

class MainClass
{
        public static void Main(string[] args)
        {
                GlobalSettings.SetUserAgent("txdv");
        }
}

I stepped with gdb through _opts (although without debugging symbols) and saw that the string "txdv" was duped, so I assume it did the right thing.

Do you want me to implement the get functionality in libgit2?

@txdv
Copy link
Contributor Author

txdv commented Jul 5, 2016

Also, do you want me to squash the whitespace fix into this same commit?

@txdv
Copy link
Contributor Author

txdv commented Jul 5, 2016

Ok, I added OPT_GET_USER_AGENT libgit2 and implemented GetUserAgent in C# and it all works. I think though this should be a self contained commit, no need to add GetUserAgent here yet, since the functionality part of it gets shipped with vNext only anyway.

On another note, how am I supposed to test new libgit2 functionality if all the binaries in the test directories get overwritten everytime I do a build?

@ethomson
Copy link
Member

ethomson commented Jul 5, 2016

Great! 👍

I think though this should be a self contained commit, no need to add GetUserAgent here yet

Sure, I think that's reasonable.

On another note, how am I supposed to test new libgit2 functionality if all the binaries in the test directories get overwritten everytime I do a build?

libgit2 itself is included as part of the LibGit2Sharp.NativeBinaries package. There should be instructions there, but the basics are: clone the LibGit2Sharp.NativeBinaries package, update the libgit2 that you want to use, build that package and then you can set your nuget package to that.

The very quick and dirty way, of course, is to overwrite the libgit2 source that's being copied. Quick and dirty, and mostly effective, but easy to mix oneself up. :)

@txdv
Copy link
Contributor Author

txdv commented Jul 5, 2016

Ok, next question, if we are going to add GetUserAgent as well, shouldn't we use a getter/setter combo for this?

public string UserAgent { get; set; }

?

@ethomson
Copy link
Member

ethomson commented Jul 5, 2016

Ok, next question, if we are going to add GetUserAgent as well, shouldn't we use a getter/setter combo for this

Sure, I think that's probably fits in nicely. :)

@txdv
Copy link
Contributor Author

txdv commented Jul 7, 2016

I get a SIGSEGV running the libgit2sharp tests (master) with the newest libgit2 binary (master).

I did however just overwrite LibGit2Sharp.Tests/bin/Release/lib/linux/x86_64/libgit2-381caf5.so with the newest compiled one.

Don't know what to really do from here. I wrote my test, but can't check if it works correctly. AFAIK it is not really possible to run one specific test with xunit 1.9.2?

@ethomson
Copy link
Member

ethomson commented Jul 7, 2016

I get a SIGSEGV running the libgit2sharp tests (master) with the newest libgit2 binary (master).

That's not unexpected; it's likely that some function changed signatures between the version that LibGit2Sharp uses and the version that you compiled.

AFAIK it is not really possible to run one specific test with xunit 1.9.2?

I don't know the command line. It is possible from Visual Studio Test Explorer.

@txdv
Copy link
Contributor Author

txdv commented Jul 7, 2016

That's not unexpected; it's likely that some function changed signatures between the version that LibGit2Sharp uses and the version that you compiled.

Is there a branch which is kept up to date?

@txdv txdv closed this Jul 13, 2016
@txdv txdv deleted the user-agent branch July 13, 2016 10:12
@mattjohnsonpint
Copy link

What ever happened with this?

@ethomson
Copy link
Member

I'm not sure that I know what you're asking @mj1856 - this should be merged and working in a LibGit2Sharp in the last several years. Is something not working for you?

@mattjohnsonpint
Copy link

It didn't get merged. It's not in the current shipping release anyway.

@mattjohnsonpint
Copy link

@ethomson - to be clear, it appears the native functionality in libgit2 was merged, but this PR to expose it in libgit2sharp was closed without merging the code. There's no functionality in libgit2sharp to set the user agent. I could use that.

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.

3 participants