{"thread":{"id":"13302","subject":"Dumb idea on git library for script languages","startedAt":"2008-04-28T07:03:36Z","lastAt":"2008-04-29T04:25:51Z","messageCount":5,"participants":["tsgates","Jakub Narebski","Johannes Schindelin","Eric Hanchrow","Govind Salinas"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"75348","messageId":"1209366216.17090.4.camel@prosumer","threadId":"13302","inReplyTo":null,"subject":"Dumb idea on git library for script languages","fromName":"tsgates","fromEmail":"tsgatesv@gmail.com","sentAt":"2008-04-28T07:03:36Z","receivedAt":"2008-04-28T07:03:36Z","isPatch":false,"sender":{"key":"tsgatesv@gmail.com","avatar":null},"body":"Please comment on my naive idea.\n\nWhen I try to use git in python, there are no fancy ways not to fork any\nprocesses.  (except not active git library) I know it is design policy\nof git, one job for one process.\n\nAnyhow, I need to call git in python and perl, so I try to think.\n\nI assumed that \n 1. all cmd_*() is designed in a process basis,\n    so it is ok to free all memories which invoked after calling cmd_*()\n    \n 2. result of cmd_*() is output only\n    so parse it in order to use in script language\n    right before call cmd_*() -> redirect stdout to anything\n\n 3. 'die()' can be escaped by using \"setjmp/longjmp\"\n\n 4. actually I need only cmd_*() or little low level functions from\nscript\n \nhere is snippets of naive pseudo codes\n\n------------------------------------------------------------\n# will be called from the python/perl code\n------------------------------------------------------------\n\nlib_git_do() {\n\n  if ( setjmp( exterend here ) ) {\n    start_trace()\n    cmd_do()\n    stop_trace()\n  } else {\n    # called from die (from longjmp)\n    return error occured\n  }\n  \n  return parse_do();\n}\n\n------------------------------------------------------------\nstart_trace() {\n  init_mem()\n  \n  start_malloc_trace()\n  start_stdout_trace()\n}\n\nstop_trace() {\n  stop_stdout_trace()\n  stop_malloc_trace()\n\n  clean_mem()\n}\n\nstart_malloc_trace() {\n  hook __malloc_hook\n  hook __realloc_hook\n  hook __free_hook\n}\n\nmalloc_hook( size ) {\n  void * rtn = malloc( size )\n  if ( rtn ) {\n     add_to_mem_record( thread_id, rtn )\n  }\n}\n\nfree_hook( ptr ) {\n  if ( free( ptr ) ) {\n     del_mem_record( thread_id, ptr )\n  }\n}\n\nclean_mem() {\n  for_each ( mem_records ) \n    free( ptr )\n}\n------------------------------------------------------------\n\npros\n 0. easy to implement\n 1. guarantee thread safety\n 2. no memory leak\n 3. not depend on git source\n 4. able to take advantage of script codes, no forking overhead\n\ncons\n 0. not fancy\n 1. need dumb parsing\n 2. just temporary solution\n\n but, I want to use it in review board or track like system, right now.\n\nIf there are any other good suggestions or recommendations on it, please\nrecommend it.\n\nBest regards\n"},{"id":"75349","messageId":"m38wyyphai.fsf@localhost.localdomain","threadId":"13302","inReplyTo":"1209366216.17090.4.camel@prosumer","subject":"Re: Dumb idea on git library for script languages","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-04-28T07:31:02Z","receivedAt":"2008-04-28T07:31:02Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"tsgates <tsgatesv@gmail.com> writes:\n\n> When I try to use git in python, there are no fancy ways not to fork any\n> processes.  (except not active git library) I know it is design policy\n> of git, one job for one process.\n> \n> Anyhow, I need to call git in python and perl, so I try to think.\n[...]\n> If there are any other good suggestions or recommendations on it, please\n> recommend it.\n\nPlease take a look at libgit-thin project, which was Google Summer of\nCode 2007 project; it was meant to create PyGit, git bindings for\nPython.  I don't know how far it is/got advanced.\n\nInterfacesFrontendsAndTools page on Git Wiki mentions it.\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"75366","messageId":"alpine.DEB.1.00.0804281125330.5399@eeepc-johanness","threadId":"13302","inReplyTo":"1209366216.17090.4.camel@prosumer","subject":"Re: Dumb idea on git library for script languages","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-04-28T10:28:48Z","receivedAt":"2008-04-28T10:28:48Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 28 Apr 2008, tsgates wrote:\n\n> malloc_hook( size ) {\n>   void * rtn = malloc( size )\n>   if ( rtn ) {\n>      add_to_mem_record( thread_id, rtn )\n>   }\n> }\n> \n> free_hook( ptr ) {\n>   if ( free( ptr ) ) {\n>      del_mem_record( thread_id, ptr )\n>   }\n> }\n> \n> clean_mem() {\n>   for_each ( mem_records ) \n>     free( ptr )\n> }\n\nThis is not enough.  We have quite some static variables which point \ndirectly or indirectly to these allocated regions.\n\nI think you'd need to implement some resetter functions if you were to \nlibify libgit.a.  The easier way would definitely be to go with \nlibgit-thin, as Jakub suggested.\n\nCiao,\nDscho\n"},{"id":"75485","messageId":"873ap5484n.fsf@offby1.atm01.sea.blarg.net","threadId":"13302","inReplyTo":"1209366216.17090.4.camel@prosumer","subject":"Re: Dumb idea on git library for script languages","fromName":"Eric Hanchrow","fromEmail":"offby1@blarg.net","sentAt":"2008-04-29T04:06:48Z","receivedAt":"2008-04-29T04:06:48Z","isPatch":false,"sender":{"key":"eric.hanchrow@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3145?v=4"},"body":"Look into Python's \"subprocess\" module; it has all you need to cleanly\ninvoke subprocesses, capture their output, and check their return\nstatus.\n-- \nIt has been suggested that this article or section be merged\ninto Fried dough. (Discuss)\n        -- Seen on Wikipedia\n"},{"id":"75486","messageId":"5d46db230804282125g41be08a1v1d41155fe2305dac@mail.gmail.com","threadId":"13302","inReplyTo":"1209366216.17090.4.camel@prosumer","subject":"Re: Dumb idea on git library for script languages","fromName":"Govind Salinas","fromEmail":"govind@sophiasuchtig.com","sentAt":"2008-04-29T04:25:51Z","receivedAt":"2008-04-29T04:25:51Z","isPatch":false,"sender":{"key":"govind@sophiasuchtig.com","avatar":null},"body":"On Mon, Apr 28, 2008 at 2:03 AM, tsgates <tsgatesv@gmail.com> wrote:\n> Please comment on my naive idea.\n>\n>  When I try to use git in python, there are no fancy ways not to fork any\n>  processes.  (except not active git library) I know it is design policy\n>  of git, one job for one process.\n>\n>  Anyhow, I need to call git in python and perl, so I try to think.\n>\n\nYou may be interested in Pyrite, which has a Repo class that you may find\nhelpful.  It is a work in progress, so there are probably bugs, but I would\nbe interested in fixing them.  You can find it here\n\nhttp://gitorious.org/projects/pyrite\n\nEventually, I plan to use libgit (or libgit-thin depending on what is\nappropriate) instead of subprocesses, but that is in the future.\n\n-Govind\n"}]}